Skip to content
3 changes: 3 additions & 0 deletions desktop/app_session_dedup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ func TestEnsureBlankTabOpensExistingProjectSidebarBlankTopic(t *testing.T) {

func TestEnsureBlankTabDoesNotReuseProjectTopicWithSession(t *testing.T) {
app, root, refs := canonicalOrganizationFixture(t, "existing")
// This case creates a live Controller in addition to the fixture's store.
// Join runtime teardown before the fixture shuts down its session service.
t.Cleanup(func() { app.shutdown(context.Background()) })
before := refs["existing"]
installNoopRuntimeEvents(app)
app.readyHook = func() {}
Expand Down
12 changes: 8 additions & 4 deletions docs/TEAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

The Team port targets local macOS, Linux and Windows Desktop. Its implementation
is tracked in [the delivery ledger](TEAM_PORT_STATUS.md). The current increment
provides the storage and orchestration foundation; it has no production caller
and does not enable a desktop Team feature yet.
provides storage, orchestration and an optional Controller/boot seat adapter.
The Desktop host and interface are not enabled yet.

## Ownership

Expand Down Expand Up @@ -51,7 +51,11 @@ canonical permissions, idempotency, handoff cycles, consumed replies, group
timers, approval contracts and restart recovery. Windows cross-compilation is
only compilation evidence; native runtime acceptance remains a separate gate.

This increment changes no existing provider request, tool registry, session,
preset, credential or desktop RPC format. The copied MIT license is retained
Ordinary boots keep their existing provider request and tool registry. Team
boots add the same Team tools and append current identity at the turn tail.
Incoming Team work has host provenance and a scoped execution ceiling; it cannot
rewrite the member's persistent permission. Fresh configuration approvals compare
the reviewed roster revision before committing. Existing session, preset,
credential and desktop RPC formats are unchanged. The copied MIT license is retained
in `internal/team/UPSTREAM_LICENSE` and also covers the extracted roster and
host-framing packages.
6 changes: 4 additions & 2 deletions docs/TEAM.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[English](TEAM.md)

Team 移植面向本机 macOS、Linux、Windows Desktop,进度见[交付清单](TEAM_PORT_STATUS.md)。
当前增量提供存储与编排基础,尚无生产调用方,桌面端尚未启用团队功能。
当前增量提供存储、编排和可选的 Controller/boot 席位适配,桌面宿主和界面尚未启用。

## 状态归属

Expand Down Expand Up @@ -39,6 +39,8 @@ Shell 继续遵守 Deepzora 现有的当前系统账户执行约定。
规范权限、幂等、交办循环、回复消费、群计时、审批契约及重启恢复。Windows 交叉编译
只证明可编译,原生运行仍是独立验收项。

本增量不改变现有模型请求、工具目录、会话、预设、凭据或 Desktop RPC 格式。
普通 boot 保持既有模型请求与工具目录。团队 boot 注册一致的团队工具,将当前身份追加
到回合尾部。团队输入带有宿主来源及临时执行上限,不覆盖成员的长期权限;持久配置审批
提交时校验用户审阅的名册 revision。既有会话、预设、凭据和 Desktop RPC 格式不变。
提取代码的 MIT 许可证保留在 `internal/team/UPSTREAM_LICENSE`,同时覆盖名册与宿主
framing 包。
31 changes: 29 additions & 2 deletions docs/TEAM_PORT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ preset definitions instead of following later preset edits.
| Layer | Owner | Status |
| --- | --- | --- |
| 1 | Versioned roster, exchanges, group orchestration | Implemented; focused/race/static checks and full root Go suite passed; PR #146 |
| 2 | Controller seat, tools, approvals and delegation ceilings | Pending |
| 2 | Controller seat, tools, approvals and delegation ceilings | Implemented; Controller/Agent/boot/Team/builtin/evidence suites, focused race and static gates passed |
| 3 | Desktop runtime, lease and browser isolation | Pending |
| 4 | Desktop Team UI and generated contract | Pending |
| 5 | Memory, opt-in review and schedules | Pending |
Expand Down Expand Up @@ -60,4 +60,31 @@ Studio HTTP plumbing, terminal outbox, unrelated fixes or release infrastructure

本层已实现名册、交换账本、群轮次与宿主 framing,定向测试、race、vet、repolint
通过;Windows amd64 测试二进制已交叉编译,尚无 Windows 原生运行证据。
本层没有接入 Controller、Desktop、模型或界面入口,其余六层仍待完成。
第一层单独不启用 Controller 或桌面入口;后续层状态见上表。

## Seat/controller increment

- Added an optional host-owned boot seat and a fixed Team tool set, preserved
across controller rebuild. Ordinary boots do not register Team tools.
- Identity and roster ride the turn tail; provider-boundary tests compare the
unchanged ordinary system prefix and stable Team schemas across turns.
- Team input uses the existing durable inbox and explicit host message origin.
Admission validates pending work; replay of interrupted exchanges is refused.
The admitted envelope owns immutable turn metadata instead of rereading a
mutable sidecar to discover authority during execution.
- Scoped execution ceilings preserve the user's persistent permission and also
reach child execution and resolved proxy targets. A compiler-overlay negative
control executes the forbidden writer when enforcement is removed.
- Fresh Team configuration approvals cannot reuse session grants or Full access.
Writes compare the reviewed roster revision and recheck target authority.
- Queue prose editors cannot rewrite a host-authored Team delivery. Task children
cannot borrow their parent's Team identity. Coordination is classified as host
state, not a work-product mutation.
- Focused regressions and race checks passed. The broad Controller suite exposed
an approved-plan fallback regression; the repair limits the restriction to an
actual active Team ceiling. The complete Controller, Agent, boot, Team,
builtin, host-frame and evidence suites passed after that repair.

第二层已接入可选席位、固定工具目录、持久 inbox、宿主来源、回合结算和临时执行上限,
并验证系统前缀稳定、只读代理执行、陈旧审批拒绝及已结算任务不重放。普通已批准计划的
回归已修复,全套相关包已通过。桌面 TeamHost 与界面尚未接入。
28 changes: 24 additions & 4 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,15 @@ func completedMCPConnect(reg *tool.Registry, name string) (string, bool) {
return "", false
}

func (a *Agent) readOnlyExecutionBlock(visible tool.Tool, resolved *tool.ResolvedCall) (toolOutcome, bool) {
if a == nil || !a.readOnlyExecution {
func (a *Agent) enforcesReadOnly(ctx context.Context) bool {
if a == nil {
return false
}
return a.readOnlyExecution || tool.ExecutionCeiling(ctx) == "read-only"
}

func (a *Agent) readOnlyExecutionBlock(ctx context.Context, visible tool.Tool, resolved *tool.ResolvedCall) (toolOutcome, bool) {
if !a.enforcesReadOnly(ctx) {
return toolOutcome{}, false
}
block := func(reason string) (toolOutcome, bool) {
Expand Down Expand Up @@ -1678,7 +1685,7 @@ func (a *Agent) readOnlyExecutionBlock(visible tool.Tool, resolved *tool.Resolve
if readOnlyExecutionMCPDestructive(visible) {
return block("execute a destructive MCP capability")
}
if h, ok := visible.(tool.ReadOnlyExecutionHostMutation); ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(visible) {
if a.blocksReadOnlyHostMutation(ctx, visible) {
return block("start or mutate a host capability")
}
return toolOutcome{}, false
Expand Down Expand Up @@ -1730,7 +1737,7 @@ func (a *Agent) readOnlyExecutionBlock(visible tool.Tool, resolved *tool.Resolve
if readOnlyExecutionMCPDestructive(resolved.Target) {
return block("execute a destructive MCP capability")
}
if h, ok := resolved.Target.(tool.ReadOnlyExecutionHostMutation); ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(resolved.Target) {
if a.blocksReadOnlyHostMutation(ctx, resolved.Target) {
return block("start or mutate a host capability")
}
return toolOutcome{}, false
Expand All @@ -1739,6 +1746,19 @@ func (a *Agent) readOnlyExecutionBlock(visible tool.Tool, resolved *tool.Resolve
}
}

func (a *Agent) blocksReadOnlyHostMutation(ctx context.Context, t tool.Tool) bool {
h, ok := t.(tool.ReadOnlyExecutionHostMutation)
return ok && h.ReadOnlyExecutionHostMutation() && !readOnlyExecutionAllowsMCPStartup(t) && !a.readOnlyCeilingAllowsTeamCoordination(ctx, t)
}

func (a *Agent) readOnlyCeilingAllowsTeamCoordination(ctx context.Context, t tool.Tool) bool {
if a.readOnlyExecution || SubagentDepth(ctx) > 0 || tool.ExecutionCeiling(ctx) != "read-only" || !t.ReadOnly() {
return false
}
coordination, ok := t.(tool.ReadOnlyTeamCoordination)
return ok && coordination.ReadOnlyTeamCoordination()
}

func readOnlyExecutionMCPDestructive(t tool.Tool) bool {
return mcpDestructiveHint(t)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/execute_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ func (a *Agent) applyPlanModeAndProxy(ctx context.Context, plan *toolCallPlan) (
}
plan.readOnly = rc.ReadOnly
plan.classifyEffects()
if outcome, blocked := a.readOnlyExecutionBlock(t, &rc); blocked {
if outcome, blocked := a.readOnlyExecutionBlock(ctx, t, &rc); blocked {
return blockedShellOutcome(outcome, plan), true
}
} else if outcome, blocked := a.readOnlyExecutionBlock(t, nil); blocked {
} else if outcome, blocked := a.readOnlyExecutionBlock(ctx, t, nil); blocked {
return blockedShellOutcome(outcome, plan), true
}

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/spawn_readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type forceReadOnlySpawnKey struct{}

func forceReadOnlySpawn(ctx context.Context) bool {
forced, _ := ctx.Value(forceReadOnlySpawnKey{}).(bool)
return forced || PlanModeFromContext(ctx) || planmode.Active(ctx)
return forced || PlanModeFromContext(ctx) || planmode.Active(ctx) || tool.ExecutionCeiling(ctx) == "read-only"
}

// A resolved read-only invocation carries its own restriction through Execute.
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (t *SubagentRunner) RunProfileSpec(ctx context.Context, spec ProfileExecSpe
if spec.Sched.RunInBackground || spec.Context.ContinueFrom != "" {
return "", fmt.Errorf("background and continuation are retired; use spawn_agents")
}
spec.Grant.ReadOnly = spec.Grant.ReadOnly || PlanModeFromContext(ctx)
spec.Grant.ReadOnly = spec.Grant.ReadOnly || forceReadOnlySpawn(ctx)
// One progress owner publishes each child terminal after resource cleanup.
trk := newSubagentProgressTracker(ctx, subSink(ctx))
parentCtx := ctx
Expand Down
51 changes: 51 additions & 0 deletions internal/agent/team_ceiling_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package agent

import (
"encoding/json"
"testing"

"deepzora/internal/event"
"deepzora/internal/provider"
"deepzora/internal/tool"
)

type escalatingTeamWriter struct{ readOnlyBoundaryTarget }

func (escalatingTeamWriter) DeclareWriteAccess(json.RawMessage) (tool.WriteAccessDeclaration, error) {
return tool.WriteAccessDeclaration{RequestedPreset: "danger-full-access"}, nil
}

func TestDelegatedWorkspaceCeilingBlocksChildShellEscalation(t *testing.T) {
reg := tool.NewRegistry()
calls := 0
reg.Add(escalatingTeamWriter{readOnlyBoundaryTarget{name: "writer", calls: &calls}})
a := New(nil, reg, NewSession("sys"), Options{}, event.Discard)
out := a.executeOne(tool.WithExecutionCeiling(t.Context(), "workspace-write"), &a.turn, provider.ToolCall{ID: "escalation", Name: "writer", Arguments: `{}`})
if !out.blocked || calls != 0 {
t.Fatalf("headless child escalated its preset: %+v calls=%d", out, calls)
}
}

func TestDelegatedReadOnlyCeilingBlocksDirectAndDeferredWriters(t *testing.T) {
for _, proxy := range []bool{false, true} {
reg := tool.NewRegistry()
calls := 0
writer := readOnlyBoundaryTarget{name: "writer", calls: &calls}
reg.Add(writer)
call := provider.ToolCall{ID: "team-write", Name: "writer", Arguments: `{}`}
if proxy {
reg.Add(readOnlyBoundaryProxy{resolved: tool.ResolvedCall{ProxyAction: "call", Target: writer, TargetName: "writer"}})
call.Name = "use_capability"
}
a := New(nil, reg, NewSession("sys"), Options{}, event.Discard)
ctx := tool.WithExecutionCeiling(t.Context(), "read-only")
out := a.executeOne(ctx, &a.turn, call)
if !out.blocked || calls != 0 {
t.Fatalf("proxy=%v: inherited ceiling escaped: %+v, calls=%d", proxy, out, calls)
}
out = a.executeOne(t.Context(), &a.turn, call)
if out.blocked || calls != 1 {
t.Fatalf("proxy=%v: cap leaked into ordinary execution: %+v calls=%d", proxy, out, calls)
}
}
}
90 changes: 90 additions & 0 deletions internal/agent/team_coordination_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package agent

import (
"context"
"testing"

"deepzora/internal/event"
"deepzora/internal/provider"
"deepzora/internal/tool"
"deepzora/internal/tool/builtin"
)

type ceilingTeamDirectory struct {
tool.TeamDirectory
calls int
ceiling string
}

func (d *ceilingTeamDirectory) record(ctx context.Context) {
d.calls++
d.ceiling = tool.ExecutionCeiling(ctx)
}
func (d *ceilingTeamDirectory) MessageAgent(ctx context.Context, _ tool.TeamMessage) (tool.TeamReceipt, error) {
d.record(ctx)
return tool.TeamReceipt{Exchange: "reply", ToName: "Ben"}, nil
}
func (d *ceilingTeamDirectory) PassTurn(ctx context.Context) error { d.record(ctx); return nil }
func (d *ceilingTeamDirectory) HandTurn(ctx context.Context, _ []string) error {
d.record(ctx)
return nil
}
func (d *ceilingTeamDirectory) PostToGroup(ctx context.Context, _, _ string, _ []string) error {
d.record(ctx)
return nil
}

func TestReadOnlyTeamCeilingAllowsOnlyTopLevelCoordination(t *testing.T) {
for _, tc := range []struct {
name, args string
allowed bool
}{
{"message_agent", `{"to":"ben","message":"read this"}`, true},
{"pass_turn", `{}`, true},
{"hand_turn", `{"to":["ben"]}`, true},
{"post_to_group", `{"group":"launch","message":"read this"}`, true},
{"create_agent", `{"name":"new"}`, false},
{"update_agent", `{"agent":"ben","instructions":"change"}`, false},
{"stop_agent", `{"agent":"ben"}`, false},
} {
for _, proxy := range []bool{false, true} {
for _, identity := range []string{"member", "child", "strict-reader"} {
t.Run(tc.name+"/"+identity+map[bool]string{false: "/direct", true: "/proxy"}[proxy], func(t *testing.T) {
d := &ceilingTeamDirectory{}
link := &tool.TeamLink{}
link.Bind(d)
reg := tool.NewRegistry()
var target tool.Tool
for _, v := range builtin.TeamTools(link) {
reg.Add(v)
if v.Name() == tc.name {
target = v
}
}
if target == nil {
t.Fatal("tool missing")
}
call := provider.ToolCall{ID: "coordination", Name: tc.name, Arguments: tc.args}
if proxy {
reg.Add(readOnlyBoundaryProxy{resolved: tool.ResolvedCall{ProxyAction: "call", Target: target, TargetName: tc.name, Args: []byte(tc.args), ReadOnly: target.ReadOnly()}})
call.Name = "use_capability"
}
a := New(nil, reg, NewSession("sys"), Options{ReadOnlyExecution: identity == "strict-reader"}, event.Discard)
ctx := tool.WithExecutionCeiling(t.Context(), "read-only")
if identity == "child" {
ctx = WithSubagentDepth(ctx, 1)
}
out := a.executeOne(ctx, &a.turn, call)
allowed := identity == "member" && tc.allowed
if allowed {
if out.blocked || d.calls != 1 || d.ceiling != "read-only" {
t.Fatalf("coordination blocked or widened: %+v calls=%d ceiling=%s", out, d.calls, d.ceiling)
}
} else if !out.blocked || d.calls != 0 {
t.Fatalf("restricted tool executed: %+v calls=%d", out, d.calls)
}
})
}
}
}
}
53 changes: 53 additions & 0 deletions internal/agent/team_spawn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package agent

import (
"context"
"testing"

"deepzora/internal/capability"
"deepzora/internal/event"
"deepzora/internal/provider"
"deepzora/internal/tool"
)

func TestTeamCeilingForcesReadOnlySpawnAcrossEntrances(t *testing.T) {
for _, entrance := range []string{"direct", "capability", "runner"} {
t.Run(entrance, func(t *testing.T) {
p := &spawnProvider{run: func(ctx context.Context, req provider.Request) error {
if tool.ExecutionCeiling(ctx) != "read-only" {
t.Error("child lost delegated ceiling")
}
for _, schema := range req.Tools {
if schema.Name == "write_file" {
t.Error("delegated child received writer schema")
}
}
return nil
}}
spawner := spawnFixture(t, p)
ctx := tool.WithExecutionCeiling(testTaskContext(), "read-only")
if entrance == "runner" {
if _, err := spawner.runner.RunProfileSpec(ctx, ProfileExecSpec{Task: TaskSpec{Objective: "inspect"}}); err != nil {
t.Fatal(err)
}
} else {
reg := tool.NewRegistry()
reg.Add(spawner)
call := provider.ToolCall{ID: "team-spawn", Name: SpawnToolName, Arguments: `{"tasks":[{"title":"read","task":"inspect"}]}`}
if entrance == "capability" {
reg.Add(NewUseCapabilityTool(context.Background(), nil, nil, reg, capability.NewLedger(), nil, nil))
call.Name = "use_capability"
call.Arguments = `{"action":"call","capability_id":"tool:spawn_agents","arguments":` + call.Arguments + `}`
}
a := New(nil, reg, NewSession(""), Options{}, event.Discard)
out := a.executeOne(ctx, &a.turn, call)
if out.blocked || out.errMsg != "" {
t.Fatalf("delegated spawn failed: %+v", out)
}
}
if p.calls != 1 {
t.Fatalf("child calls = %d", p.calls)
}
})
}
}
3 changes: 3 additions & 0 deletions internal/agent/workspace_mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func workspaceMutationForCall(toolID, toolName string, args json.RawMessage, rea
}

func workspaceHostStateOnlyTool(toolName string) bool {
if evidence.IsTeamStateTool(toolName) {
return true
}
if strings.HasPrefix(toolName, "mcp_connect__") {
return true
}
Expand Down
3 changes: 3 additions & 0 deletions internal/agent/write_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (a *Agent) applyWriteAccess(ctx context.Context, plan *toolCallPlan) (toolO
blocked: true,
}, true
}
if !tool.ExecutionPresetAllowed(ctx, declaration.RequestedPreset) {
return writeAccessBlocked("the requested execution preset exceeds the delegated turn's ceiling"), true
}
if a.svc.writeAccess == nil {
if a.svc.writeRoots == nil || len(declaration.Directories) == 0 {
return toolOutcome{}, false
Expand Down
Loading
Loading