feat(chat): per-chat permission modes for Claude, Codex and OpenCode
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package opencode
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// chatModes are OpenCode's two primary agents. What each may do without asking
|
||||
// is the agent's own permission configuration; Pipelines only picks the agent.
|
||||
var chatModes = []protocol.ChatMode{
|
||||
{ID: "build", Name: "Build", Description: "OpenCode's default agent: edits and runs commands under its permission settings."},
|
||||
{ID: "plan", Name: "Plan", Description: "Analyse and plan; edits and commands are restricted."},
|
||||
}
|
||||
|
||||
// Modes lists the agents an OpenCode chat can switch to.
|
||||
func (c *Chat) Modes(context.Context, string) ([]protocol.ChatMode, error) {
|
||||
return append([]protocol.ChatMode(nil), chatModes...), nil
|
||||
}
|
||||
|
||||
// SetMode records the session's agent; every later prompt names it.
|
||||
func (c *Chat) SetMode(_ context.Context, id, mode string) error {
|
||||
known := false
|
||||
for _, candidate := range chatModes {
|
||||
known = known || candidate.ID == mode
|
||||
}
|
||||
if !known {
|
||||
return fmt.Errorf("unknown OpenCode agent %q", mode)
|
||||
}
|
||||
c.modeMu.Lock()
|
||||
defer c.modeMu.Unlock()
|
||||
if c.agents == nil {
|
||||
c.agents = map[string]string{}
|
||||
}
|
||||
c.agents[id] = mode
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Chat) agentFor(id string) string {
|
||||
c.modeMu.Lock()
|
||||
defer c.modeMu.Unlock()
|
||||
return c.agents[id]
|
||||
}
|
||||
Reference in New Issue
Block a user