approval

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package approval coordinates app-control grants and revocation. File-backed stores share current authority across cooperating processes using a stable sidecar lock and atomic replacement. All writers sharing a file must use this format; older writers do not honor its locks or revocations.

Session grants remain local but are invalidated by shared revocation records. Read errors deny access. A write error after replacement can mean a decision is visible but its durability is uncertain; callers must inspect current state rather than automatically repeating the decision. App approval is separate from operating-system permissions and target identity.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/axmcp/internal/computeruse/approval"
)

func main() {
	store := approval.NewMemory()
	state, err := store.Approve(context.Background(), "com.example.editor", false)
	fmt.Println(state.Approved, err)
}
Output:
true <nil>

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrBundleIDRequired reports a missing bundle ID.
	ErrBundleIDRequired = errors.New("bundle id required")
	// ErrDenied reports an explicit denial.
	ErrDenied = errors.New("approval denied")
	// ErrCanceled reports a canceled approval request.
	ErrCanceled = errors.New("approval canceled")
	// ErrPersistenceFailed reports a failed or unconfirmed write. It does
	// not imply a session grant. A failure after rename may leave the change visible.
	ErrPersistenceFailed = errors.New("approval persistence failed")
)

Functions

This section is empty.

Types

type Store

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

Store manages app-control approvals. A Store is safe for concurrent use. Its zero value is unusable; use Open, NewStore, or NewMemory.

func New

func New() (*Store, error)

New returns a store backed by the default application-support path.

func NewMemory

func NewMemory() *Store

NewMemory returns a local session-only store.

func Open

func Open(path string) (*Store, error)

Open returns a store backed by path. An empty path disables persistence. Existing version 1 records are preserved when the first decision migrates them.

func (*Store) Approve

func (s *Store) Approve(ctx context.Context, bundleID string, persistent bool) (computeruse.ApprovalState, error)

Approve records a persistent or session-only grant. File-backed session grants require a writable revision journal. Failed writes never create implicit grants.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/axmcp/internal/computeruse/approval"
)

func main() {
	state, err := approval.NewMemory().Approve(context.Background(), "com.example.editor", false)
	fmt.Println(state.Approved, state.Persistent, err)
}
Output:
true false <nil>

func (*Store) Path

func (s *Store) Path() string

Path reports the configured persistence path, or empty for memory-only stores.

func (*Store) Resolve

func (s *Store) Resolve(ctx context.Context, bundleID string, decision computeruse.ApprovalDecision) (computeruse.ApprovalState, error)

Resolve applies an approval decision. Deny and cancel are not revocation. Context bounds waiting for the local gate and file lock, not regular-file I/O.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/axmcp/internal/computeruse"
	"github.com/tmc/axmcp/internal/computeruse/approval"
)

func main() {
	state, err := approval.NewMemory().Resolve(context.Background(), "com.example.editor", computeruse.ApprovalDecisionRequire)
	fmt.Println(state.Approved, err)
}
Output:
false <nil>

func (*Store) Revoke added in v0.3.0

func (s *Store) Revoke(ctx context.Context, bundleID string) error

Revoke withdraws an app's grants in the shared authority. Failure blocks the app locally but cannot claim global revocation. Explicit local reapproval or successful revocation clears that failure override.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/axmcp/internal/computeruse/approval"
)

func main() {
	ctx := context.Background()
	store := approval.NewMemory()
	store.Approve(ctx, "com.example.editor", false)
	err := store.Revoke(ctx, "com.example.editor")
	state, statusErr := store.Status(ctx, "com.example.editor")
	fmt.Println(state.Approved, err, statusErr)
}
Output:
false <nil> <nil>

func (*Store) Status

func (s *Store) Status(ctx context.Context, bundleID string) (computeruse.ApprovalState, error)

Status reads current authority. Errors return an unapproved state; cached grants never substitute for unreadable or unavailable authority.

Example
package main

import (
	"context"
	"fmt"

	"github.com/tmc/axmcp/internal/computeruse/approval"
)

func main() {
	state, err := approval.NewMemory().Status(context.Background(), "com.example.editor")
	fmt.Println(state.Required, err)
}
Output:
true <nil>

Jump to

Keyboard shortcuts

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