copilotperm

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMode = ModeAsk

DefaultMode is the safe default for interactive Copilot sessions.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(cliFlag string, commandDefault Mode, in io.Reader, out io.Writer) copilot.PermissionHandlerFunc

BuildHandler resolves mode and returns a Copilot OnPermissionRequest handler.

func HasPermissionModeFlag

func HasPermissionModeFlag(args []string) bool

HasPermissionModeFlag reports whether argv already contains permission-mode.

func InjectPermissionMode

func InjectPermissionMode(args []string, mode Mode) []string

InjectPermissionMode prepends --permission-mode when the flag is not already set.

func NewHandler

func NewHandler(opts Options) copilot.PermissionHandlerFunc

NewHandler returns a Copilot OnPermissionRequest handler for the given mode.

func ParseCopilotRequestArg

func ParseCopilotRequestArg(pending []PendingItem, arg string) (string, error)

ParseCopilotRequestArg resolves arg as cperm_ID or numeric index.

func ParseCopilotRequestIndex

func ParseCopilotRequestIndex(pending []PendingItem, oneBased int) (string, error)

ParseCopilotRequestIndex resolves 1-based index to request ID.

func SetGlobalBroker

func SetGlobalBroker(b *Broker)

SetGlobalBroker registers the active Copilot permission broker (e.g. from agentline TUI).

Types

type AuditEntry

type AuditEntry struct {
	Time      time.Time `json:"time"`
	SessionID string    `json:"session_id,omitempty"`
	Kind      string    `json:"kind,omitempty"`
	ToolName  string    `json:"tool_name,omitempty"`
	Decision  string    `json:"decision"`
	Mode      Mode      `json:"mode"`
	Summary   string    `json:"summary,omitempty"`
}

AuditEntry records one permission decision.

type Auditor

type Auditor interface {
	Log(entry AuditEntry)
}

Auditor persists permission audit events.

type Broker

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

Broker queues Copilot permission requests for interactive approval.

func GlobalBroker

func GlobalBroker() *Broker

GlobalBroker returns the active broker, if any.

func NewBroker

func NewBroker() *Broker

NewBroker creates a Copilot permission broker.

func (*Broker) Pending

func (b *Broker) Pending() []PendingItem

Pending returns unresolved Copilot permission requests.

func (*Broker) Prompter

func (b *Broker) Prompter() Prompter

Prompter returns a Prompter that blocks until the request is resolved.

func (*Broker) Resolve

func (b *Broker) Resolve(requestID string, allow bool) error

Resolve approves or denies a pending request by ID.

func (*Broker) ResolveLatest

func (b *Broker) ResolveLatest(allow bool) error

ResolveLatest resolves the most recent pending request.

type FileAuditor

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

FileAuditor appends JSON lines to a local audit log.

func NewFileAuditor

func NewFileAuditor() (*FileAuditor, error)

NewFileAuditor creates an auditor writing to the default XDG path.

func (*FileAuditor) Log

func (a *FileAuditor) Log(entry AuditEntry)

Log appends one audit entry as a JSON line.

type Mode

type Mode string

Mode controls how Copilot permission requests are handled.

const (
	ModeAsk   Mode = "ask"
	ModeAllow Mode = "allow"
	ModeDeny  Mode = "deny"
)

func ParseMode

func ParseMode(raw string) (Mode, error)

ParseMode normalizes and validates a permission mode string.

func ResolveMode

func ResolveMode(cliFlag string, commandDefault Mode) (Mode, error)

ResolveMode picks Copilot permission mode. Priority: CLI flag > FASTGIT_COPILOT_PERMISSION_MODE > ~/.config/fastgit/config.yaml > commandDefault.

type Options

type Options struct {
	Mode      Mode
	SessionID string
	Auditor   Auditor
	Prompter  Prompter
}

Options configures a permission handler.

type PendingItem

type PendingItem struct {
	RequestID string
	SessionID string
	Summary   string
	Kind      string
	ToolName  string
	CreatedAt time.Time
}

PendingItem is a Copilot permission request waiting for user decision.

type Prompter

type Prompter func(ctx context.Context, request copilot.PermissionRequest, summary string) (bool, error)

Prompter decides whether to approve an interactive permission request.

func DefaultTerminalPrompter

func DefaultTerminalPrompter(in io.Reader, out io.Writer) Prompter

DefaultTerminalPrompter asks y/N on stdin.

func PrompterForMode

func PrompterForMode(mode Mode, fallback Prompter) Prompter

PrompterForMode returns the best prompter for ask mode.

Jump to

Keyboard shortcuts

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