Skip to content

Entry points ​

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

Six import paths. The root has what most apps need: govern, the types, and the adapter interfaces. Implementations live on subpaths so the root stays small.

ImportContents
flue-guardgovern, createGovernedToolkit, caller, trusted, always, never, ContextStore, the errors, 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/jevOptional createJevGuard, JevGuardOptions, JevHazard, JevThreshold; requires optional peer @typesafe-ai/sdk 0.6 or 0.7. Guide
flue-guard/replayreplay, ReplayOptions, ReplayReport, ReplayChange, ReplayToolSpec. Also the flue-guard replay command. Guide
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; same as passing check itself. Reference
trusted(source, check)Authorization anchored to a registered trusted source. Reference
always(reason?) / never()Shortcuts for "always ask" and "never ask" approval policies. 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, withSignal, run, current, peek
GovernedToolSpec, GovernedFlueToolSpecThe tool spec (explicit-generic and schema-inferred forms)
ToolGuard, GuardRequest, GuardAssessmentProvider-neutral semantic guard interfaces
AuthorizeSpec, CallerCheck, TrustedSourceAuthorization gate shapes
SignalDeliveryThe part of Flue's useDelivery() result that withSignal reads
PendingApprovalOutputWhat the model sees when a call waits for approval under Flue
ToolCallInfoThe host's call id, passed to a governed tool's execute
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 tool before and after it becomes a Flue tool
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/replay ​

ExportDescription
replay(options)Run recorded calls against tool specs; resolves to a ReplayReport. Verifies the chain first and throws GovernanceConfigError when it does not hold
ReplayOptionsentries, tools, and optional authorize (default false), hmacKey, rbac, trustedSources
ReplayReporttotal, unchanged, newlyDenied, newlyAllowed, notReplayed, noSpec
ReplayChangeOne changed call: seq, tool, actorId, was, now, checked
ReplayCheck"roles" | "scope" | "authorize"
ReplayToolSpecAny tool spec, whatever its argument and result types

notReplayed reasons: recorded before replay support, no caller was recorded, arguments were invalid, a check crashed when recorded, inputs not fully recorded.

The package also installs the command flue-guard replay <audit.jsonl> --tools <module> [--authorize]. It reads the key of a keyed log from FLUE_GUARD_AUDIT_HMAC_KEY. Exit codes: 0 no call is newly denied, 1 at least one is, 2 the replay could not run.

How to use it: Replay a rule change.

flue-guard/testing ​

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