Eve
permdock/eve turns PermDock decisions into Eve tool approval policies and approval response policies, takes principal and actor from the durable session's auth, and stores pending approvals in a pluggable ApprovalStore.
permdock/eve connects the Decision model to Eve's approval hook on defineTool. Eve already pauses a session durably and renders the approval on every channel; what it asks the application for is the policy that decides whether a call may run, must wait for a person, or is refused, and a second policy that decides who may press Approve. Both come out of one createPermDock call, typed against your permissions, fail-closed.
Purpose
Eve's human-in-the-loop hook receives the session context plus { abortSignal, callId, toolAnnotations?, toolInput?, toolName } and returns an approval status: "not-applicable" to continue, "user-approval" to pause, "approved" or "denied" (optionally { type, reason }) to decide in code. It offers always(), auto(), never() and once() helpers from eve/tools/approval and leaves anything input- or caller-dependent to a custom function. Its response policy receives the request (callId, interactionId, the requesting principal, toolInput, toolName), the submitted response (decision of approve or deny plus the authenticated principal), the session and auth, and decides whether that person may approve this call, and the docs note that a shared request stays pending when a responder is rejected so another eligible approver can act. That is a policy decision point with an approval store missing in the middle; permdock/eve supplies both from the application's PermDock policy and an ApprovalStore. It needs eve 1.2.0 or later (eve peer >=1.2.0), which needs Node.js 24.
API
import { defineTool } from "eve/tools";
import { defineOperations } from "permdock";
import { createPermDock } from "permdock/eve";
const DeleteInput = z.object({ id: z.string() });
const RefundInput = z.object({ chargeId: z.string(), amount: z.number() });
const { approval, approvalFor, getPermDock } = createPermDock(policy, {
operations: defineOperations(permissions, {
delete_post: {
permission: permissions.post.delete,
data: (input) => loadPost(DeleteInput.parse(input).id),
},
refund: {
permission: permissions.charge.refund,
data: (input) => loadCharge(RefundInput.parse(input).chargeId),
},
}),
store, // ApprovalStore; memoryApprovalStore() when omitted
approvers: { roles: ["finance-admin"] }, // who may resolve; see below
delegation: () => ({
scopes: [permissions.post.delete.scope, permissions.charge.refund.scope],
}),
});
export default defineTool({
description: "Refund a charge.",
inputSchema: RefundInput,
approval, // { request, response } built from `operations`
async execute(input, ctx) {
// getPermDock(ctx) is the request-scoped PermDock for checks inside the tool
(await getPermDock(ctx)).assert(
permissions.charge.refund,
await loadCharge(input.chargeId),
);
return refund(input);
},
});
// Or gate a single tool without the map:
approval: approvalFor(permissions.charge.refund, (input) =>
loadCharge(RefundInput.parse(input).chargeId),
);approvalis an Eve{ request, response }pair, each taking the one context object Eve passes (EveApprovalContextforrequest,EveResponseContextforresponse; both are structural, so the adapter never imports eve).requestlooks the tool name up inoperations(own keys only), resolves the resource, callsdecideand maps the outcome.responsechecks the responder against the approval record and theapproversrule.approvalFor(permission, data?)builds the same pair for one tool inline.unmapped: 'allow'answersnot-applicablefor a tooloperationsdoes not name, so Eve runs it without asking; the default'deny'denies it.context,otel,wrapanddeniedTextbehave as onpermdock/ai-sdk.datareceives the tool input asunknown; parse it with the tool's schema before loading the resource.getPermDock(ctx)returns a request-scopedPermDockfromctx.sessionfor checks insideexecuteor in other Eve code. It builds a fresh frozen instance on every call, so a replayed step never sees state from an earlier one.tenantresolves the active tenant from the same context on every call;operationshas no tenant dimension, because the tenant is part of the subject, not of the tool.storeis the ApprovalStore.approversis either{ roles }(approver must hold one of these roles in the PermDock policy) or a function(responder, request) => boolean. It is an extra restriction on top ofgrant.approval.by; both must pass. The actor rule (an agent never approves its own call) is enforced regardless.
Subject from the session
Eve exposes two authenticated principals on ctx.session.auth: initiator, who created the session, and current, who sent this turn. Each has principalId, principalType, authenticator and attributes. permdock/eve maps them:
| PermDock subject part | Eve source | Notes |
|---|---|---|
principal | session.auth.current, or session.auth.initiator when the turn has no caller | The caller of this turn; roles come from policy.subject or attributes you declare as server-set |
actor | The Eve app, { id: 'eve:app', kind: 'eve' } | Every turn, whoever sent it |
delegation | The delegation option, resolved from the same context | No default. Every eve turn has an actor, so without delegation every tool is denied with reason no-delegation (delegation) |
In a shared session, eve replaces current when another person sends a follow-up, so each turn is decided with the grants of the person who sent it, never with the initiator's. A schedule-dispatched turn has the app as its caller (authenticator: 'app', principalId: 'eve:app'), which holds no role, so its tools deny until subject maps it to a principal.
Up to 0.30.0, the principal was always the initiator and a different current became the actor. An app whose policy names actor.id of an eve turn reads the caller from principal now.
The subject and actor options override these defaults when an application encodes identity differently. Model output, toolInput and attributes that Eve marks as user-supplied never build a subject (authentication).
Request lifecycle
- Eve is about to execute a tool and calls
approval.requestwith the session andtoolInput. - The adapter validates
toolInputagainst the resource schema when adataresolver exists, loads the resource and callsdecide. - The outcome maps to Eve's vocabulary:
| Decision outcome | approval.request returns | Eve behaviour |
|---|---|---|
granted | "not-applicable" | Tool runs without a prompt |
approval-required | "user-approval" | Eve opens an interaction.opened event of kind approval and parks the session; an ApprovalRequest with token is written to the store |
denied | { type: "denied", reason } | Tool does not run; the model receives reason built from denials and alternatives |
| unmapped tool, invalid input, thrown resolver | { type: "denied", reason } | Fail closed |
- A person presses Approve or Cancel on a channel. Eve calls
approval.responsewithresponse.decision(approveordeny) and the authenticatedresponse.principal(the responder). The adapter finds the record for the call (from this instance's bounded session cache, or by recomputing the token fromrequest.principal, the caller of the turn that made the call, so any replica can answer), refuses a responder whoseprincipalIdis the request's actor, appliesapprovers, maps the responder through the samesubjectas a caller sogrant.approval.bysees their roles, memberships and tenant, and callsresolveApproval(approvedforapprove,rejectedfordeny, so the re-check denies), returning{ status: "allowed" }. Otherwise it returns{ status: "rejected", reason }and Eve keeps the request pending for another responder. The caller who made the call cannot approve their own request unless the grant setsapproval: { mode: "confirm" }. - Eve re-runs
approval.requestfor the same call beforeexecute(the AI SDK re-check) and runs the tool unless the answer is a denial. The adapter recomputes the token: an approved record is consumed and the answer is"not-applicable", so the tool runs once; a record still pending means nobody approved and the answer is a denial withapproval-pending; a consumed, rejected or expired record is a denial too. - Every step emits
on('decision'); the ask, the answer and the resumed decision sharetoken.
"not-applicable" is used only for granted. It is Eve's word for "continue", and the adapter never reaches it without a positive decision, so the fail-open path @ai-sdk/policy-opa has does not exist here.
What it validates
toolInputagainst the resource's Standard Schema whendatais declared; Eve'stoolInputmay beundefined, which is a validation failure and therefore a denial.- The subject comes from
session.auth, never fromtoolInputor the model. - The responder in
approval.responseis Eve's authenticated principal; it must not be the actor, must satisfyapprovers, and its verdict is recorded in the store. - Replays: the token is recomputed on resume. Eve's remembered decisions (
once()) are never consulted; each call has its own request, which is also what Eve's docs recommend for non-idempotent side effects across replays.
How denials surface
{ type: "denied", reason }withreasonbuilt from the Decision: the failing roles, the reason kind and thealternativeslist, phrased for the model ("charge.refund denied: member (condition). Alternatives: charge.read.").- A rejected responder gets
{ status: "rejected", reason: "approver is the actor of this request" }(or theapproversreason); the request stays pending, matching Eve's semantics. - Expired or mismatched approvals on resume are denials with
detailapproval-expiredorapproval-mismatch.
Connections, agent-wide gates, subagents and schedules
Connection tools. A connection's approval takes the same { request, response } pair as a tool. Eve names each connection tool <connection>__<tool>, so key operations by that name and put the pair on the connection:
import { defineMcpClientConnection } from "eve/connections";
const { approval } = createPermDock(policy, {
operations: defineOperations(permissions, {
linear__create_issue: { permission: permissions.issue.create },
linear__delete_comment: { permission: permissions.comment.delete },
}),
delegation,
});
export default defineMcpClientConnection({
url: "https://mcp.linear.app/mcp",
description: "Linear workspace.",
approval,
});A tool the map does not name is denied; unmapped: 'allow' lets the connection's read tools through. Approval never changes who the call runs as: the connection token stays the requester's.
Agent-wide policy. approval in agent.ts runs on every call, including connection tools and subagents, and eve keeps the stricter of it and the tool's own answer. An agent-wide rule can add a gate on top of a PermDock decision but never turn a PermDock denial into a run. Keep PermDock's pair on the tools and connections, where its response policy checks the approver; when only the agent-wide policy asks, eve has no tool-level response to apply.
Subagents. Eve runs each message to a subagent with the sender's auth, so the principal is the same person, and local subagents run under the root agent's policy. session.parent (sessionId, rootSessionId, callId) marks a subagent's session. Give it its own actor id and a narrower delegation, so audit tells the agents apart and a research child cannot delete:
createPermDock(policy, {
operations,
actor: (ctx) =>
ctx.session?.parent === undefined
? { id: "eve:app", kind: "eve" }
: { id: `eve:session:${ctx.session.id ?? ""}`, kind: "eve" },
delegation: (ctx) =>
ctx.session?.parent === undefined
? { scopes: [permissions.post.list.scope, permissions.post.delete.scope] }
: { scopes: [permissions.post.list.scope] },
});Approvals from a child appear on the parent session, and the child's response policy decides who may answer. Parallel agents covers the pattern outside eve.
Schedules. A defineSchedule handler sends with appAuth (principalId: 'eve:app'), which holds no role, so its tools deny until subject maps it; pass a user's auth instead when the work needs that user's grants. Eve's experimental dynamic schedules call their auth callback on each occurrence to turn the stored creator into current access; look the creator up there and return null for a removed member, and that occurrence fails without running. For a recurring job that PermDock decides at fire time, see Automations.
Use with better-supabase
better-supabase 0.81.0 or later exports strictestApproval, approvalPolicy, tenantToolApproval, supabaseTool and eveContext from better-supabase/eve. strictestApproval combines approvals for one tool: the strictest request answer wins (denied, then user-approval, then approved, then not-applicable) and every response must allow the answer. approvalFor returns an approval of that shape, so PermDock's decision, the approvals block and the tenant's tool policies all apply to one call.
import { defineTool } from "eve/tools";
import {
approvalPolicy,
strictestApproval,
supabaseTool,
tenantToolApproval,
} from "better-supabase/eve";
const { approvalFor } = createPermDock(policy, { operations });
export default defineTool(
supabaseTool({
agent: "support",
server,
description: "Refund a charge.",
inputSchema: RefundInput,
permission: permissions.charge.refund.key,
approval: strictestApproval(
approvalFor(permissions.charge.refund, (input) =>
loadCharge(RefundInput.parse(input).chargeId),
),
approvalPolicy({
agent: "support",
server,
permission: permissions.charge.refund.key,
}),
tenantToolApproval(policies),
),
execute: (input, { db }) => refund(db, input),
}),
);permissions.charge.refund.keyis the permission'skey. Pass the same permission toapprovalForand topermission:supabaseTooladds the key to the agent'sscopes, andeveContextderives thescopeclaim from them.approvalForruns the PermDock decision.approvalPolicyfiles the request in the approvals block, andtenantToolApprovalapplies the tenant'sdeny,askandautopolicies.- The pair type-checks against
strictestApprovalintests/better-supabase/eve.test-d.ts.permdock/evereads onlysession.idandsession.initiatorfrom the response context, so better-supabase's narrowerEveApprovalResponseContextis accepted. - Needs
better-supabase0.81.0 or later andeve1.3.0 or later.
Example app
apps/examples/eve-agent: HTTP harness on 127.0.0.1:3474 with GET /health, driving the pair with Eve's session shapes. GET /list_posts returns not-applicable. GET /delete_post?call=… returns user-approval; POST /approve?call=… answers as an admin reviewer; the next GET /delete_post for that call is the re-check and returns not-applicable once, and a further one is denied. No model API key. tests/integration also drives the pair with eve 1.2.0's ApprovalContext and ApprovalResponseContext (gate, responder check, re-check) against a Postgres ApprovalStore; eve exports no function that evaluates an approval outside a running session, so the test follows its three steps. This example is also the deploy template for the PermDock Cloud listing on the Vercel Marketplace. src/cloud.ts uses cloud() when PERMDOCK_CLOUD_URL and PERMDOCK_CLOUD_KEY are set and memoryApprovalStore() otherwise: store is cloud().approvals, sink is cloud().sink, POST /webhooks/permdock is a cloudApprovalWaiter endpoint, /approvals/* mounts approvalsHandler, GET /delete_post links the inbox, and policies is hostedPolicies(cloud().policies), refreshed at start and every minute, for hosted grants on the hostable post.publish (Cloud adapter).
Related standards
- Approvals and approvals: the token, the store, the approver rules.
- Delegation: the actor half of the subject for agent turns.
- OWASP Agentic Top 10: ASI02 tool misuse via per-tool permissions and input validation.
- AI SDK adapter: Eve's approval status vocabulary is the AI SDK 7 one.
Last updated on
Claude Agent SDK
permdock/claude-agent answers Claude Agent SDK canUseTool callbacks and PermissionRequest hooks from PermDock decisions, mapping built-in tools such as Bash to typed permissions.
OpenAI Agents SDK
permdock/openai turns PermDock decisions into OpenAI Agents SDK needsApproval predicates, guards tool lists per caller, resolves interruptions against a pluggable ApprovalStore, and binds the replay-safe token to the serialised RunState.