Skip to content

Entry points

flue-guard is ESM-only, requires Node >= 22.19, and declares peer dependencies @flue/runtime >=1.0.0-beta.9 <1.0.0 and valibot ^1.0.0.

Four import paths. The root carries the golden path, the types, and the adapter interfaces; implementations live on subpaths so they don't crowd it.

ImportContents
flue-guardgovern, createGovernedToolkit, caller, trusted, always, never, ContextStore, the error taxonomy, core types, adapter interfaces
flue-guard/auditHashChainAuditLog, InMemoryAuditLog, hashEntry, verifyChain, GENESIS_HASH
flue-guard/adaptersBuilt-in adapter implementations and helpers: defaultRbac, autoApprove, redactors, InMemoryIdempotencyStore, scope matchers, toFlueTool, hostContextResolver
flue-guard/testingInMemoryAuditLog, InMemoryIdempotencyStore (re-exported test doubles)

flue-guard (root)

Functions & classes

ExportDescription
govern(options)Create a toolkit with Flue's defineTool wired in; the way in. Reference
createGovernedToolkit(options)The explicit form: same toolkit, you inject defineTool. Reference
caller(check)Authorization anchored to the authenticated caller. Reference
trusted(source, check)Authorization anchored to a registered trusted source. Reference
always(reason?) / never()Approval policy sugar. Reference
ContextStoreAsyncLocalStorage-backed trusted-context holder. Reference
Error classes & guardsGovernanceError and subclasses, isGovernanceError, isGovernanceDenial, isApprovalPending. Reference

Types

ExportDescription
GovernOptions, GovernedToolkitOptionsOptions for govern / createGovernedToolkit
GovernedToolkitThe toolkit: tool, defineGovernedTool, withContext, run, current, peek
GovernedToolSpec, GovernedFlueToolSpecThe tool spec (explicit-generic and schema-inferred forms)
AuthorizeSpec, TrustedSourceAuthorization gate shapes
TrustedContext, ExecutionContextThe context your app binds / the one handlers receive
ContextResolver(hostContext?) => TrustedContext | Promise<TrustedContext>
Decision, OutcomeAudit vocabulary: allow|deny|defer, executing|success|error|denied|replayed|pending
ArgValidator, ParseValidator, FnValidator, StandardSchemaV1, InferArgsParameter-schema typing
FlueCompatibleTool, FlueToolDefinition, FlueDefineToolThe governed intermediate and Flue-facing shapes
GovernanceErrorCodeUnion of every machine-readable error code
Adapter interfacesAuditLog, AuditEntry, AuditEntryBody, AuditInput, IdempotencyStore, IdempotencyRecord, IdempotencyStatus, BeginResult, RbacAdapter, RbacRequest, ApprovalAdapter, ApprovalPolicy, ApprovalRequest, ApprovalDecision, Redactor. Reference

flue-guard/audit

ExportDescription
HashChainAuditLogAppend-only hash-chained JSONL file log (single-writer)
InMemoryAuditLogFull hash-chained in-memory log
hashEntry(body, hmacKey?)Compute an entry's chain hash (Web Crypto)
verifyChain(entries, hmacKey?)Walk a chain; report the first inconsistency
GENESIS_HASHThe 64-zero hash the first entry chains from

Details: Audit log reference.

flue-guard/adapters

ExportDescription
defaultRbacAny-of role match against ctx.actor.roles
autoApproveApproval adapter that approves everything (local dev)
defaultRedactorMasks common sensitive field names + PII-like strings
redactFields(fields?, options?)Build a structural field-masking redactor
textRedactor(transform, options?)Adapt a string-based PII library into a Redactor
composeRedactors(...redactors)Run redactors left to right
identityRedactorChanges nothing
InMemoryIdempotencyStoreProcess-local idempotency store (the default)
scopeAllowed(requested, allowed)Does any allowed pattern match this scope?
normalizeScopes(scopes)Scope declaration -> string[]
deniedScopes(requested, allowed)The requested scopes not covered by allowed
toFlueTool(governed)Governed tool -> Flue ToolDefinition (manual wiring path)
hostContextResolver(extract)Context resolver for non-Flue hosts that pass a context object

Details: Adapters reference.

flue-guard/testing

ExportDescription
InMemoryAuditLogSame class as flue-guard/audit exports; here for discoverability in tests
InMemoryIdempotencyStoreSame class as flue-guard/adapters exports