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 ¶
- Variables
- type Store
- func (s *Store) Approve(ctx context.Context, bundleID string, persistent bool) (computeruse.ApprovalState, error)
- func (s *Store) Path() string
- func (s *Store) Resolve(ctx context.Context, bundleID string, decision computeruse.ApprovalDecision) (computeruse.ApprovalState, error)
- func (s *Store) Revoke(ctx context.Context, bundleID string) error
- func (s *Store) Status(ctx context.Context, bundleID string) (computeruse.ApprovalState, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 NewStore ¶
NewStore returns a store backed by the default application-support path. One optional path overrides the default; an empty path disables persistence.
func Open ¶
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) 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
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>