{"modulePath":"github.com/GoCodeAlone/workflow-plugin-agent","version":"v0.12.11","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package policy\n\nPackage policy implements a unified trust rules engine for agent tool access control. It supports both Claude Code (settings.json) and ratchet (config.yaml) rule formats, mode presets, scoped rules, and integrates with the existing ToolPolicyEngine.\n\n## Variables\n\n```go\nvar ModePresets = map[string][]TrustRule{\n\t\"conservative\": {\n\t\t{Pattern: \"file_read\", Action: Allow},\n\t\t{Pattern: \"blackboard_*\", Action: Allow},\n\t\t{Pattern: \"send_message\", Action: Allow},\n\t\t{Pattern: \"bash:git *\", Action: Allow},\n\t\t{Pattern: \"bash:go *\", Action: Allow},\n\t\t{Pattern: \"file_write\", Action: Ask},\n\t\t{Pattern: \"bash:*\", Action: Ask},\n\t\t{Pattern: \"path:~/.ssh/*\", Action: Deny},\n\t\t{Pattern: \"path:~/.aws/*\", Action: Deny},\n\t},\n\t\"permissive\": {\n\t\t{Pattern: \"*\", Action: Allow},\n\t\t{Pattern: \"bash:rm -rf /*\", Action: Deny},\n\t\t{Pattern: \"bash:sudo *\", Action: Deny},\n\t\t{Pattern: \"path:~/.ssh/*\", Action: Deny},\n\t},\n\t\"locked\": {\n\t\t{Pattern: \"file_read\", Action: Allow},\n\t\t{Pattern: \"blackboard_*\", Action: Allow},\n\t\t{Pattern: \"*\", Action: Ask},\n\t},\n\t\"sandbox\": {\n\t\t{Pattern: \"*\", Action: Allow},\n\t},\n}\n```\nModePresets defines the built-in trust modes.\n\n## Types\n\n```go\ntype Action string\n```\nAction defines the trust decision for a tool/path/command.\n\n```go\nconst (\n\tAllow Action = \"allow\"\n\tDeny  Action = \"deny\"\n\tAsk   Action = \"ask\"\n)\n```\n\n```go\ntype GlobMatcher struct {\n\t// contains filtered or unexported fields\n}\n```\nGlobMatcher evaluates file paths against allow/deny glob patterns. Deny patterns are checked first (deny wins). Unmatched paths return Ask. Supports standard glob wildcards (\\*) and doublestar (\\*\\*) for recursive matching. Patterns starting with ~/ are expanded to the user's home directory.\n\n```go\nfunc NewGlobMatcher(allow, deny []string) *GlobMatcher\n```\nNewGlobMatcher creates a GlobMatcher from allow and deny glob lists. Tilde (~) in patterns is expanded to the user's home directory at construction time.\n\n```go\nfunc (gm *GlobMatcher) Check(path string) Action\n```\nCheck returns Allow, Deny, or Ask for the given path. Deny patterns are evaluated first so deny wins over allow. An unmatched path returns Ask (not Deny), allowing the caller to prompt the user.\n\n```go\ntype PermissionGrant struct {\n\tID        int64\n\tPattern   string\n\tAction    Action\n\tScope     string\n\tGrantedBy string\n\tCreatedAt time.Time\n}\n```\nPermissionGrant is a persisted trust decision.\n\n```go\ntype PermissionStore struct {\n\t// contains filtered or unexported fields\n}\n```\nPermissionStore persists \"always allow/deny\" trust decisions in SQLite.\n\n```go\nfunc NewPermissionStore(db *sql.DB) (*PermissionStore, error)\n```\nNewPermissionStore creates a PermissionStore and initializes the table.\n\n```go\nfunc (ps *PermissionStore) Check(toolName, scope string) (Action, bool)\n```\nCheck returns the persisted action for a toolName+scope using glob matching. Stored patterns (e.g. \"blackboard\\_\\*\") are matched against the incoming toolName using the same logic as TrustEngine rule evaluation. Deny wins across all matches. Scope-specific grants are checked alongside global grants.\n\n```go\nfunc (ps *PermissionStore) Grant(pattern string, action Action, scope, grantedBy string) error\n```\nGrant persists an allow/deny decision. Upserts by pattern+scope atomically.\n\n```go\nfunc (ps *PermissionStore) List() ([]PermissionGrant, error)\n```\nList returns all persisted grants.\n\n```go\nfunc (ps *PermissionStore) Revoke(pattern, scope string) error\n```\nRevoke removes a persisted grant.\n\n```go\ntype PolicyEngine interface {\n\tIsAllowed(ctx context.Context, toolName, agentID, teamID string) (bool, string)\n}\n```\nPolicyEngine is an optional backing store for SQL-based policies. Matches the existing orchestrator.ToolPolicyEngine.IsAllowed signature.\n\n```go\ntype RatchetPromptPattern struct {\n\tName   string `yaml:\"name\" json:\"name\"`\n\tMatch  string `yaml:\"match\" json:\"match\"`\n\tAction string `yaml:\"action\" json:\"action\"`\n}\n```\nRatchetPromptPattern is a user-defined screen prompt auto-response pattern.\n\n```go\ntype RatchetTrustConfig struct {\n\tMode         string                 `yaml:\"mode\" json:\"mode\"`\n\tRules        []RatchetTrustRule     `yaml:\"rules\" json:\"rules\"`\n\tProviderArgs map[string][]string    `yaml:\"provider_args\" json:\"provider_args\"`\n\tPrompts      []RatchetPromptPattern `yaml:\"prompts\" json:\"prompts\"`\n}\n```\nRatchetTrustConfig is the trust section from ~/.ratchet/config.yaml.\n\n```go\ntype RatchetTrustRule struct {\n\tPattern string `yaml:\"pattern\" json:\"pattern\"`\n\tAction  string `yaml:\"action\" json:\"action\"`\n}\n```\nRatchetTrustRule is a single rule in ratchet format.\n\n```go\ntype TrustEngine struct {\n\t// contains filtered or unexported fields\n}\n```\nTrustEngine evaluates trust rules for tool calls, paths, and commands.\n\n```go\nfunc NewTrustEngine(mode string, rules []TrustRule, policyDB PolicyEngine) *TrustEngine\n```\nNewTrustEngine creates a TrustEngine with the given mode and explicit rules. If mode is a known preset, the preset rules are loaded into presetRules. policyDB is optional (may be nil).\n\n```go\nfunc (te *TrustEngine) AddRule(rule TrustRule)\n```\nAddRule appends an explicit rule dynamically. These are preserved across SetMode calls.\n\n```go\nfunc (te *TrustEngine) Evaluate(ctx context.Context, toolName string, args map[string]any) Action\n```\nEvaluate checks whether a tool call is allowed. Scope defaults to \"global\".\n\n```go\nfunc (te *TrustEngine) EvaluateCommand(cmd string) Action\n```\nEvaluateCommand checks whether a bash command is allowed. Matches rules with \"bash:\" prefix patterns.\n\n```go\nfunc (te *TrustEngine) EvaluatePath(path string) Action\n```\nEvaluatePath checks whether a file path is accessible. Matches rules with \"path:\" prefix patterns.\n\n```go\nfunc (te *TrustEngine) EvaluateScoped(ctx context.Context, toolName string, args map[string]any, scope string) Action\n```\nEvaluateScoped checks whether a tool call is allowed in the given scope. Resolution order: deny-wins across all matching rules.\n\n 1. Per-scope rules matching the tool name\n 2. Global rules matching the tool name\n 3. PermissionStore persistent grants\n 4. ToolPolicyEngine (SQL)\n 5. Default: Deny\n\n```go\nfunc (te *TrustEngine) GrantPersistent(pattern string, action Action, scope, grantedBy string) error\n```\nGrantPersistent stores an \"always allow/deny\" decision for future sessions.\n\n```go\nfunc (te *TrustEngine) Mode() string\n```\nMode returns the current operating mode.\n\n```go\nfunc (te *TrustEngine) Rules() []TrustRule\n```\nRules returns a copy of all active rules (preset + explicit).\n\n```go\nfunc (te *TrustEngine) SetMode(mode string) []TrustRule\n```\nSetMode switches the active mode preset. Returns the new preset rules that were loaded. Explicit rules added via AddRule or the constructor are preserved. If mode is unknown, returns nil and mode is unchanged.\n\n```go\nfunc (te *TrustEngine) SetPermissionStore(ps *PermissionStore)\n```\nSetPermissionStore attaches a persistent permission store for \"always\" grants.\n\n```go\ntype TrustRule struct {\n\tPattern string // \"file_read\", \"bash:git *\", \"path:~/.ssh/*\", \"Bash(rm:*)\"\n\tAction  Action\n\tScope   string // \"global\", \"provider:claude_code\", \"agent:coder\"\n}\n```\nTrustRule is a single trust policy entry.\n\n```go\nfunc ParseClaudeCodeSettings(data []byte) ([]TrustRule, error)\n```\nParseClaudeCodeSettings parses a .claude/settings.json file into TrustRules. allowedTools → Allow, disallowedTools → Deny. Bash(cmd:\\*) is normalized to bash:cmd \\*.\n\n```go\nfunc ParseRatchetTrustConfig(cfg RatchetTrustConfig) []TrustRule\n```\nParseRatchetTrustConfig converts ratchet YAML trust config into TrustRules.\n\n","path":"github.com/GoCodeAlone/workflow-plugin-agent/policy","name":"policy","synopsis":"Package policy implements a unified trust rules engine for agent tool access control.","isRedistributable":true}
