fix(worktree): bind publication to dispatch grants

Worktree RPC used to accept repository coordinates from the sandbox. It now accepts only an opaque per-dispatch grant, and the daemon derives the repository path and branch from grant-owned state.

Repository worktree paths also move from an ambiguous flattened key to encoded owner/repo components. Origin-matched legacy clones migrate safely; mismatched legacy paths are preserved.
This commit is contained in:
sam committed 2026-08-22 22:06:54 +10:00
1 parent 7df2ae3626
commit dbb6550ab3
19 files changed
+494 -175

No files matched your search

+7
View File
@@ -29,6 +29,10 @@ type Request struct {
// transports, discover tools, and register them locally. Absent/empty
// means no MCP servers (backward compatible).
MCPServers []config.MCPServer `json:"mcp_servers,omitempty"`
// WorktreeGrant is an opaque, per-dispatch capability authorizing the
// daemon to publish this task's already-prepared branch. Repository
// coordinates never cross back from the sandbox as authority.
WorktreeGrant string `json:"worktree_grant,omitempty"`
}
// Validate rejects a full-task request that cannot be correlated to a real
@@ -40,6 +44,9 @@ func (r Request) Validate() error {
if r.Task.ID <= 0 {
return fmt.Errorf("task ID must be positive, got %d", r.Task.ID)
}
if r.WorktreeGrant == "" {
return errors.New("worktree grant is required")
}
return nil
}
+6 -1
View File
@@ -24,6 +24,7 @@ func TestRequestJSONRoundTrip(t *testing.T) {
Providers: map[string]agentexec.Provider{
"anthropic": {Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY"},
},
WorktreeGrant: "grant",
}
data, err := json.Marshal(req)
@@ -48,6 +49,9 @@ func TestRequestJSONRoundTrip(t *testing.T) {
if got.Providers["anthropic"].APIKeyEnv != "ANTHROPIC_API_KEY" {
t.Fatalf("Providers did not round-trip: %+v", got.Providers)
}
if got.WorktreeGrant != "grant" {
t.Fatalf("WorktreeGrant did not round-trip: %q", got.WorktreeGrant)
}
}
func TestRequestValidateRequiresPositiveTaskID(t *testing.T) {
@@ -59,7 +63,8 @@ func TestRequestValidateRequiresPositiveTaskID(t *testing.T) {
{name: "missing task", wantErr: true},
{name: "zero ID", request: Request{Task: &store.Task{}}, wantErr: true},
{name: "negative ID", request: Request{Task: &store.Task{ID: -1}}, wantErr: true},
{name: "positive ID", request: Request{Task: &store.Task{ID: 1}}},
{name: "missing worktree grant", request: Request{Task: &store.Task{ID: 1}}, wantErr: true},
{name: "valid request", request: Request{Task: &store.Task{ID: 1}, WorktreeGrant: "grant"}},
} {
t.Run(test.name, func(t *testing.T) {
err := test.request.Validate()