Golem permission card go

From golemcloud/golem · View interactive version

Golem permission card go is an AI agent skill from the GitHub repository golemcloud/golem. Passes, derives, inspects, installs and revokes permission cards, and lends scope cards to agent calls, in a Go Golem project. Use when delegated authority must cross an RPC or tool boundary, or when an agent manages the cards in its wallet.

How to use this skill

Skill file

Permission cards in Go

A permission card is delegated authority. An agent holds cards in its wallet. The golem package lets it hand cards on, derive narrower cards, inspect them, install them on other agents, revoke them, and lend a scope card to an awaited call.

Passing a card

Use golem.PermissionCard as a field of an agent method's or tool command's input, or as a result:

type ForwardIn struct{ Card golem.PermissionCard }

var Forward = Agent.Method[ForwardIn, golem.PermissionCard]("forward")

var _ = agent.Handle(Forward, func(_ *golem.Context[state], in ForwardIn) golem.PermissionCard {
	return receiver.Accept.MustCall(receiver.Agent.Upsert(receiver.ID{Name: "target"}), receiver.AcceptIn{Card: in.Card})
})

In a tool, bind it like any other argument (s.Positional(&a.Card)) or return it. Use golem.PolymorphicPermissionCard when the card's grants contain owner slot variables (a template card). The card types do not convert into each other. A receiver decodes a card as the type its parameter declares. The host refuses an agent call input or output whose card does not match the declared kind.

Managing cards

What an agent may do with cards is granted by cards: the card:derive, card:inspect, card:install and card:revoke verbs. A refused call returns a *golem.PermissionError; its Kind is the host's case (golem.PermissionNotPermitted, golem.PermissionInstallRecipientMismatch, …).

grant := golem.PatternGrant{Class: "kv", Owner: "*", Recipient: "*", Verb: "read", ResourceID: "orders.*"}

// Derive from whichever wallet card covers the request.
card, err := golem.DeriveFromWallet(golem.Bounds{LowerPositive: []golem.PatternGrant{grant}}, golem.None[golem.Lifespan]())
if err != nil {
	var pe *golem.PermissionError
	if errors.As(err, &pe) && pe.Kind == golem.PermissionNotPermitted { … }
}

// Inspect it, and derive a child that expires in an hour.
view := card.MustInspect() // view.LowerPositive, LowerNegative, UpperPositive, UpperNegative
child := card.MustDerive(golem.Bounds{LowerPositive: view.LowerPositive}, golem.Some(golem.LifespanOf(time.Hour)))

// Install the child on another agent, then revoke the card and everything derived from it.
err = child.Install(golem.AgentHolder(client.MustAgentID()))
n, err := card.Revoke() // n counts the revoked cards
for _, w := range golem.Wallet() {
    switch w.Kind() {
    case golem.WalletCardConcrete:
        card, _ := w.Concrete() // golem.PermissionCard: send, install, revoke or derive
        _ = card
    case golem.WalletCardTemplate:
        card, _ := w.Template() // golem.PolymorphicPermissionCard
        _ = card
    case golem.WalletCardScope:
        scope, _ := w.Scope() // golem.ScopeCard: attach to awaited calls
        _ = scope
    }
}

Lending a scope card to a call

golem.DeriveScope returns a golem.ScopeCard. Attached to an awaited call, it lends the callee its grants for that invocation only:

scope := golem.MustDeriveScope(golem.Bounds{LowerPositive: []golem.PatternGrant{grant}}, parent)
defer scope.Release()

// One call:
out, err := Lookup.WithScopeCard(scope).Call(client, LookupIn{Key: "k"})

// Every awaited call through a copy of the client:
scoped := client.WithScopeCard(scope)
out, err = Lookup.Call(scoped, LookupIn{Key: "k"})

Moves

A card is affine. Sending it as an argument or result, Revoke and Install move it — even when the call fails — and every later use panics with golem.ErrPermissionCardMoved. Do not keep, log or send the same card twice. A card cannot be built from data or serialized: json.Marshal of a card fails. A golem.TypedValue that holds a card is sent once too. Decoding it with golem.DecodeTypedValue takes the card out, and so does sending or returning it: handing an input on with a universal tool middleware's Next or Start, sending it with a dynamic tool client, or returning it as a middleware result. After that, decoding or sending the same value fails with golem.ErrPermissionCardTaken, and a middleware result or passed-on tool error that holds such a value fails as an invalid result. Build the value you pass on from the decoded one instead. A tool error's Match decodes its payload once and returns the same card on every match.

Related Skills

| Skill | When to Load |

|-------|--------------|

| golem-call-another-agent-go | Passing a card to another agent, or lending a scope card |

| golem-define-tool-go | Taking or returning a card in a tool command |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.