diff --git a/docs/contract.md b/docs/contract.md index 18b0b05..fc22912 100644 --- a/docs/contract.md +++ b/docs/contract.md @@ -45,9 +45,12 @@ Ids are time-ordered (UUIDv7) so they sort and page without a second index. ### Named agent definitions A named agent has one permanent session on its home machine. On the encrypted host -connection, `agents.saveProfile` accepts `id`, `name`, `job`, `iconUrl`, `harness` and -`prompt`. The browser generates the ID once at creation. The host starts the chat in -the user's home directory with Ask permissions. It returns the session, including +connection, `agents.saveProfile` accepts `id`, `name`, `job`, `iconUrl`, `harness`, +`prompt` and the optional session settings `mode`, `plan` and `model`. An empty model +selects the harness default. Omitted settings keep their current values on edit. +The browser generates the ID once at creation and offers the account's default permissions. +The host starts the chat in the user's home directory, using Ask when no mode was supplied. +It returns the session, including `agent: { job, iconUrl, revision }`. Agents appear in the existing session watch. The name is the session title. Renaming through the profile editor preserves the chat ID. diff --git a/internal/e2e/mcp_test.go b/internal/e2e/mcp_test.go index 9fc131a..66ed129 100644 --- a/internal/e2e/mcp_test.go +++ b/internal/e2e/mcp_test.go @@ -16,6 +16,7 @@ import ( "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/andyjmorgan/outpost/internal/host/peer" + "github.com/andyjmorgan/outpost/internal/host/wire" "github.com/andyjmorgan/outpost/internal/mcpserver" ) @@ -169,6 +170,9 @@ func TestTheMCPServiceNeedsABrowsersGrant(t *testing.T) { if err := delegated.Call(r.ctx, "agents.create", map[string]string{"id": created.SessionID, "revision": "spoof"}, nil); err == nil { t.Fatal("create accepted a target ID and revision") } + if err := delegated.Call(r.ctx, "agents.create", map[string]string{"requestKey": "other", "name": "Other", "job": "Review", "harness": "codex", "prompt": "Review changes", "mode": "full-access"}, nil); code(err) != wire.CodeBadParams { + t.Fatalf("delegated creation accepted owner run settings: %v", err) + } delegated.Close() // Another OAuth client in the same sign-in session is a different key, not yet approved. diff --git a/internal/host/agent/definition.go b/internal/host/agent/definition.go index 5e36c51..ed0d83e 100644 --- a/internal/host/agent/definition.go +++ b/internal/host/agent/definition.go @@ -187,6 +187,9 @@ func registerDefinitions(router *rpc.Router, root, endpoint, home string, svc *s router.Handle("agents.saveDefinition", rpc.Typed(func(c *rpc.Call, p *profileRequest) (any, error) { return save(c, p, false) }), false) if svc != nil { router.Handle("agents.create", rpc.Typed(func(c *rpc.Call, p *profileRequest) (any, error) { + if p.Mode != "" || p.Model != nil || p.Plan != nil { + return nil, wire.Errorf(wire.CodeBadParams, "agent run settings belong to the profile editor") + } if p.ID != "" || p.Revision != "" { return nil, wire.Errorf(wire.CodeBadParams, "agents.create cannot target an existing profile") } @@ -213,7 +216,7 @@ func registerDefinitions(router *rpc.Router, root, endpoint, home string, svc *s } if sess != nil { _, prompt, _ := strings.Cut(doc, promptDivider) - return &profileRequest{definitionRequest: definitionRequest{ID: p.ID, Prompt: prompt}, AgentSettings: session.AgentSettings{Name: *sess.Title, Job: sess.Agent.Job, IconURL: sess.Agent.IconURL, Harness: sess.Harness, Revision: sess.Agent.Revision}}, nil + return &profileRequest{definitionRequest: definitionRequest{ID: p.ID, Prompt: prompt}, AgentSettings: session.AgentSettings{Name: *sess.Title, Job: sess.Agent.Job, IconURL: sess.Agent.IconURL, Harness: sess.Harness, Revision: sess.Agent.Revision, Mode: sess.Mode, Plan: &sess.Plan, Model: sess.Model}}, nil } } data, err := os.ReadFile(path) diff --git a/internal/host/session/named_agent.go b/internal/host/session/named_agent.go index 9ed46b6..2f7cab0 100644 --- a/internal/host/session/named_agent.go +++ b/internal/host/session/named_agent.go @@ -7,11 +7,14 @@ import ( ) type AgentSettings struct { - Name string `json:"name"` - Job string `json:"job"` - IconURL string `json:"iconUrl"` - Harness string `json:"harness"` - Revision string `json:"revision"` + Name string `json:"name"` + Job string `json:"job"` + IconURL string `json:"iconUrl"` + Harness string `json:"harness"` + Revision string `json:"revision"` + Mode string `json:"mode,omitempty"` + Plan *bool `json:"plan,omitempty"` + Model *string `json:"model,omitempty"` } type AgentDocument struct { @@ -69,7 +72,28 @@ func (s *Service) SaveAgent(ctx context.Context, id, cwd string, settings AgentS if sess.Agent == nil || sess.Harness != settings.Harness { return nil, errf("conflict", "this identity already belongs to another conversation") } - if *sess.Title == settings.Name && sess.Agent.Job == settings.Job && sess.Agent.IconURL == settings.IconURL { + } + currentModel := "" + if sess.Model != nil { + currentModel = *sess.Model + } + mode := pick(settings.Mode, sess.Mode) + if !validMode(mode) { + return nil, errf("invalid", "unknown permission mode %q", mode) + } + plan := sess.Plan + if settings.Plan != nil { + plan = *settings.Plan + if plan && settings.Harness != "claude" { + return nil, errf("invalid", "Plan is only available for Claude Code") + } + } + model := currentModel + if settings.Model != nil { + model = *settings.Model + } + if sess.Agent != nil { + if mode == sess.Mode && plan == sess.Plan && model == currentModel && *sess.Title == settings.Name && sess.Agent.Job == settings.Job && sess.Agent.IconURL == settings.IconURL { current, err := s.store.agentDocument(ctx, id) if err != nil { return nil, err @@ -82,6 +106,11 @@ func (s *Service) SaveAgent(ctx context.Context, id, cwd string, settings AgentS return nil, errf("conflict", "the profile changed; reopen the editor to load the latest version") } } + sess.Mode, sess.Plan = mode, plan + sess.Model = nil + if model != "" { + sess.Model = &model + } sess.Agent = &AgentProfile{Job: settings.Job, IconURL: settings.IconURL, Revision: newID("rev")} sess.Title, sess.TitleBy = &settings.Name, "user" w.Changes = []any{touch(sess)} diff --git a/internal/host/session/service.go b/internal/host/session/service.go index 58875cb..d4da244 100644 --- a/internal/host/session/service.go +++ b/internal/host/session/service.go @@ -348,6 +348,10 @@ func (s *Service) ExecuteAs(ctx context.Context, cmd Command, may Allowed) (int6 Effort *string `json:"effort"` } _ = json.Unmarshal(cmd.Args, &a) + if sess.Agent != nil && ((a.Mode != nil && *a.Mode != sess.Mode) || + (a.Plan != nil && *a.Plan != sess.Plan) || (a.Model != nil && (sess.Model == nil || *a.Model != *sess.Model))) { + sess.Agent.Revision = newID("rev") + } if a.Mode != nil { if !validMode(*a.Mode) { return 0, errf("invalid", "unknown permission mode %q", *a.Mode) @@ -1112,7 +1116,8 @@ func (s *Service) apply(ctx context.Context, sessionID string, rt Runtime, ev Ad if ev.Title != nil && strings.TrimSpace(*ev.Title) != "" && sess.TitleBy != "user" && (sess.TitleBy != "" || sess.Title == nil) { sess.Title, sess.TitleBy = ptr(clipTitle(*ev.Title)), "harness" } - if ev.Model != nil { + // A named agent keeps the model selected by its owner, including a harness default or alias. + if ev.Model != nil && sess.Agent == nil { sess.Model = ev.Model } if ev.ContextUsage != nil { diff --git a/internal/mcpserver/agents.go b/internal/mcpserver/agents.go index 9a333ed..9eab837 100644 --- a/internal/mcpserver/agents.go +++ b/internal/mcpserver/agents.go @@ -19,7 +19,7 @@ type AgentCreateInput struct { Job string `json:"job" jsonschema:"short description of the agent's job"` Harness string `json:"harness" jsonschema:"claude or codex"` Prompt string `json:"prompt" jsonschema:"standing instructions for the agent, preserved verbatim"` - IconURL string `json:"iconUrl,omitempty" jsonschema:"optional HTTP or HTTPS icon URL; the web UI displays same-origin icons"` + IconURL string `json:"iconUrl,omitempty" jsonschema:"optional icon URL (HTTPS or a URL on the Outpost site)"` RequestKey string `json:"requestKey,omitempty" jsonschema:"stable creation key for this connection on this machine; defaults to the name. Reuse it for retries, or choose another to create a second agent with the same name"` } diff --git a/internal/server/web.go b/internal/server/web.go index 52f5ab8..7e9fa14 100644 --- a/internal/server/web.go +++ b/internal/server/web.go @@ -17,7 +17,7 @@ func WebApp(dir string) http.Handler { files := http.FileServer(http.Dir(dir)) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { h := w.Header() - h.Set("Content-Security-Policy", "default-src 'self'; script-src 'self' 'sha256-"+themeScriptHash+"'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'") + h.Set("Content-Security-Policy", "default-src 'self'; script-src 'self' 'sha256-"+themeScriptHash+"'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https:; font-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'") h.Set("Referrer-Policy", "no-referrer") h.Set("X-Content-Type-Options", "nosniff") h.Set("X-Frame-Options", "DENY") diff --git a/web/src/agents/AgentIcon.tsx b/web/src/agents/AgentIcon.tsx index 9502e6e..8f62ad5 100644 --- a/web/src/agents/AgentIcon.tsx +++ b/web/src/agents/AgentIcon.tsx @@ -2,15 +2,16 @@ import { useState } from 'react' const graphemes = new Intl.Segmenter() -export function AgentIcon({ name, iconUrl, small }: { name: string; iconUrl: string; small?: boolean }) { +export function AgentIcon({ name, iconUrl, px = 18 }: { name: string; iconUrl: string; px?: number }) { const [failedUrl, setFailedUrl] = useState('') - const size = small ? 'size-6 rounded-md text-xs' : 'size-8 rounded-lg text-sm' - const localIcon = URL.canParse(iconUrl) && new URL(iconUrl).origin === window.location.origin - if (localIcon && iconUrl !== failedUrl) { - return setFailedUrl(iconUrl)} /> + const style = { width: px, height: px, fontSize: Math.round(px * 0.68) } + const url = URL.canParse(iconUrl) ? new URL(iconUrl) : null + const allowed = url && (url.protocol === 'https:' || (url.protocol === 'http:' && url.origin === location.origin)) + if (allowed && iconUrl !== failedUrl) { + return setFailedUrl(iconUrl)} /> } return ( -