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

approval

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 15 Imported by: 0

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")
	// ErrApprovalDenied reports an explicit denial.
	ErrApprovalDenied = errors.New("approval denied")
	// ErrApprovalCanceled reports a canceled approval request.
	ErrApprovalCanceled = errors.New("approval canceled")
	// ErrApprovalPersistenceFailed reports a failed or unconfirmed write. It does
	// not imply a session grant. A failure after rename may leave the change visible.
	ErrApprovalPersistenceFailed = 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 NewStore

func NewStore(path ...string) (*Store, error)

NewStore returns a store backed by the default application-support path. One optional path overrides the default; an empty path disables persistence.

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