Help us shape the future of Go! Take the 2026 Go Developer Survey

approval

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package approval 实现 Golem 的人工审批流程,用于对敏感工具执行进行准入控制。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	ToolName string        // 工具名称
	ArgsJSON string        // 参数 JSON
	Reason   string        // 申请原因
	TTL      time.Duration // 有效期时长
}

CreateInput 包含了创建新审批请求所需的输入字段。

type DecisionInput

type DecisionInput struct {
	DecidedBy string // 决策者
	Note      string // 决策备注
}

DecisionInput 包含了对请求进行批准或拒绝所需的输入字段。

type Query

type Query struct {
	ID       string        // 按 ID 过滤
	Status   RequestStatus // 按状态过滤
	ToolName string        // 按工具名过滤
}

Query 包含了用于列表过滤的查询字段。

type Request

type Request struct {
	ID           string        `json:"id"`                      // 唯一的请求 ID
	ToolName     string        `json:"tool_name"`               // 待执行工具的名称
	ArgsJSON     string        `json:"args_json"`               // 工具执行的参数(JSON 格式)
	Reason       string        `json:"reason,omitempty"`        // 触发审批的原因
	DecisionNote string        `json:"decision_note,omitempty"` // 审批决策时的备注说明
	Status       RequestStatus `json:"status"`                  // 当前审批状态
	RequestedAt  time.Time     `json:"requested_at"`            // 请求发起时间
	ExpiresAt    time.Time     `json:"expires_at,omitempty"`    // 请求过期时间
	DecidedAt    time.Time     `json:"decided_at,omitempty"`    // 决策完成时间
	DecidedBy    string        `json:"decided_by,omitempty"`    // 决策者标识(用户名或系统)
}

Request 表示一条持久化的审批请求记录。

type RequestStatus

type RequestStatus string

RequestStatus 表示审批请求在生命周期中的不同状态。

const (
	StatusPending  RequestStatus = "pending"  // 待处理:请求已发起,正等待人工决策
	StatusApproved RequestStatus = "approved" // 已通过:人工已批准该工具执行
	StatusRejected RequestStatus = "rejected" // 已拒绝:人工已显式拒绝该工具执行
	StatusExpired  RequestStatus = "expired"  // 已过期:请求在有效期(TTL)内未获得决策
)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 负责管理审批请求的整个生命周期,包括创建、查询、决策及过期处理。

func NewService

func NewService(workspace string) *Service

NewService 在指定的 <workspace>/state/approvals.json 路径下创建一个审批服务。

func (*Service) Approve

func (s *Service) Approve(id string, decision DecisionInput) (Request, error)

Approve 将一个待审批请求标记为已通过。

func (*Service) Create

func (s *Service) Create(input CreateInput) (Request, error)

Create 插入一个新的待审批请求。

func (*Service) ExpirePending

func (s *Service) ExpirePending() ([]Request, error)

ExpirePending 检查并标记所有超出有效期 (TTL) 的待审批请求为已过期。

func (*Service) List

func (s *Service) List(query Query) ([]Request, error)

List 根据查询条件(如 ID、状态、工具名)过滤并返回请求列表。

func (*Service) Reject

func (s *Service) Reject(id string, decision DecisionInput) (Request, error)

Reject 将一个待审批请求标记为已拒绝。

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 负责将审批请求持久化到磁盘中的 JSON 文件。

func NewStore

func NewStore(workspace string) *Store

NewStore 在 <workspace>/state/approvals.json 创建一个审批存储实例。

func (*Store) Load

func (s *Store) Load() (fileData, error)

Load 从磁盘读取持久化的审批数据。

func (*Store) Save

func (s *Store) Save(data fileData) error

Save 将审批数据写入磁盘。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL