permstore

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package permstore is the in-memory, per-session store of LEARNED permission rules — the rules an ACP "allow always" verdict records (issue #3).

It is deliberately the SMALLEST possible mutable seam around the otherwise immutable, session-free governance.Evaluator: the Evaluator never learns; the agent loop, on an allow-always verdict, asks the permission policy to Learn, which derives a narrow tool+exact-pattern rule (governance.LearnableRule) and Records it here, keyed by session. On every subsequent evaluation the policy reads this session's rules back and merges them in at the LOWEST scope.

Scope of the store (by design, conservative slice):

  • PER-SESSION: a rule learned in session A is invisible to session B.
  • IN-MEMORY / NON-DURABLE: rules are lost on process restart and on Forget(sessionID) (wired into Service.CloseSession). Durable cross-restart persistence is a tracked follow-up, not this slice.
  • EVICTION runs from Service.CloseSession, reachable over all three surfaces: the ACP adapter (on editor disconnect) and now the gRPC CloseSession RPC / HTTP DELETE /v1/sessions/{id} session-end entries (issue #10). A well-behaved client therefore reclaims a session's rules at session end. As a client-independent backstop, the per-session learned-rule slice is also CAPPED (maxRulesPerSession) so a pathological long-lived session that never signals end cannot grow it without bound; each rule still requires a human allow-always approval. TTL/idle eviction remains a tracked follow-up.

It implements port.PermissionStore and is safe for concurrent use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memory

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

Memory is the in-memory per-session learned-rule store. The zero value is NOT usable; construct it with New.

func New

func New() *Memory

New constructs an empty Memory store.

func (*Memory) Forget

func (m *Memory) Forget(sessionID session.SessionID)

Forget evicts all learned rules for sessionID. The composition layer wires it into Service.CloseSession so a session's learned rules do not outlive it (they are non-durable by design). It is idempotent: an unknown session is a no-op.

func (*Memory) Record

func (m *Memory) Record(sessionID session.SessionID, rule governance.Rule)

Record appends rule to sessionID's learned set, deduping identical rules so a repeated "allow always" for the same call does not grow the slice unbounded. Distinct rules are capped at maxRulesPerSession: at the cap a new distinct rule is dropped (the session keeps asking for it). It is concurrency-safe.

func (*Memory) Rules

func (m *Memory) Rules(sessionID session.SessionID) []governance.Rule

Rules returns a COPY of sessionID's learned rules, so the caller can read it without holding the lock and a later Record cannot mutate the returned slice. An unknown session yields nil.

Jump to

Keyboard shortcuts

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