Library API
envpkt is available as a TypeScript library with a functional programming API built on functype. All functions return Either<Error, Result> or Option<T> — no thrown exceptions.
import { boot, loadConfig, computeAudit, scanFleet } from "envpkt"Boot API
Section titled “Boot API”High-level API that loads config, resolves catalog, audits, and optionally injects secrets.
boot(options)
Section titled “boot(options)”const result = boot({ configPath: "envpkt.toml", inject: true })console.log(result.audit.status) // "healthy" | "degraded" | "critical"Throws EnvpktBootError on failure.
bootSafe(options)
Section titled “bootSafe(options)”const safe = bootSafe({ configPath: "envpkt.toml" })safe.fold( (err) => console.error("Boot failed:", err._tag), (result) => console.log(`${result.injected.length} secrets injected`),)Returns Either<BootError, BootResult>.
BootOptions
Section titled “BootOptions”type BootOptions = { readonly configPath?: string readonly profile?: string readonly inject?: boolean readonly failOnExpired?: boolean readonly warnOnly?: boolean}BootResult
Section titled “BootResult”type BootResult = { readonly audit: AuditResult readonly injected: ReadonlyArray<string> readonly skipped: ReadonlyArray<string> readonly secrets: Readonly<Record<string, string>> readonly warnings: ReadonlyArray<string>}Config Operations
Section titled “Config Operations”loadConfig(path)
Section titled “loadConfig(path)”Load and validate an envpkt.toml file. Returns Either<ConfigError, EnvpktConfig>.
const config = loadConfig("envpkt.toml")config.fold( (err) => console.error("Failed:", err._tag), (config) => console.log(config),)loadConfigFromCwd()
Section titled “loadConfigFromCwd()”Load config from the current working directory.
findConfigPath(startDir?)
Section titled “findConfigPath(startDir?)”Search for envpkt.toml starting from a directory, walking upward.
parseToml(content)
Section titled “parseToml(content)”Parse raw TOML string. Returns Either<ConfigError, unknown>.
validateConfig(data)
Section titled “validateConfig(data)”Validate parsed data against the schema. Returns Either<ConfigError, EnvpktConfig>.
Catalog Resolution
Section titled “Catalog Resolution”resolveConfig(config, baseDir)
Section titled “resolveConfig(config, baseDir)”Resolve catalog references. Returns Either<CatalogError, ResolveResult>.
import { loadConfig, resolveConfig } from "envpkt"import { dirname } from "node:path"
const configPath = "agents/pipeline/envpkt.toml"loadConfig(configPath).fold( (err) => console.error(err), (config) => { resolveConfig(config, dirname(configPath)).fold( (err) => console.error("Catalog error:", err._tag), (result) => { console.log("Resolved keys:", result.merged) console.log("Overridden:", result.overridden) }, ) },)ResolveResult
Section titled “ResolveResult”type ResolveResult = { readonly config: EnvpktConfig readonly catalogPath?: string readonly merged: ReadonlyArray<string> readonly overridden: ReadonlyArray<string> readonly warnings: ReadonlyArray<string>}Audit Engine
Section titled “Audit Engine”computeAudit(config)
Section titled “computeAudit(config)”Compute audit results for a config. Returns AuditResult.
const audit = computeAudit(config)console.log(audit.status) // "healthy" | "degraded" | "critical"audit.secrets.forEach((s) => { console.log(`${s.key}: ${s.status}`)})Fleet Scanner
Section titled “Fleet Scanner”scanFleet(dir, options?)
Section titled “scanFleet(dir, options?)”Scan a directory tree for envpkt.toml files. Returns FleetHealth.
const fleet = scanFleet("/opt/agents", { maxDepth: 3 })console.log(`${fleet.total_agents} agents, ${fleet.total_secrets} secrets`)Environment Scanning
Section titled “Environment Scanning”envScan(env)
Section titled “envScan(env)”Scan an environment object for credentials. Returns ScanResult.
const scan = envScan(process.env)console.log(`Found ${scan.discovered.size} credentials`)envCheck(config, env)
Section titled “envCheck(config, env)”Bidirectional drift detection. Returns CheckResult.
const check = envCheck(config, process.env)if (!check.is_clean) { console.log(`${check.missing_from_env} missing, ${check.untracked_credentials} untracked`)}generateTomlFromScan(matches)
Section titled “generateTomlFromScan(matches)”Generate TOML [meta.*] blocks from scan results.
matchEnvVar(name, value)
Section titled “matchEnvVar(name, value)”Match a single env var against all patterns. Returns Option<MatchResult>.
matchEnvVar("OPENAI_API_KEY", "sk-test123").fold( () => console.log("Not a credential"), (m) => console.log(`Matched: ${m.confidence} confidence`),)Packet Formatting
Section titled “Packet Formatting”formatPacket(resolveResult, options?)
Section titled “formatPacket(resolveResult, options?)”Produce a human-readable text summary of a resolved config.
import { formatPacket } from "envpkt"
// Without secretsconst text = formatPacket(resolveResult)
// With masked secretsconst masked = formatPacket(resolveResult, { secrets: { DATABASE_URL: "postgres://user:pass@host/db" },})
// With plaintext secretsconst plain = formatPacket(resolveResult, { secrets: { DATABASE_URL: "postgres://user:pass@host/db" }, secretDisplay: "plaintext",})maskValue(value)
Section titled “maskValue(value)”Mask a secret value for display (e.g., postgres://user:pass@host/db → pos•••••t/db).
fnox Integration
Section titled “fnox Integration”detectFnox() / fnoxAvailable()
Section titled “detectFnox() / fnoxAvailable()”Check for fnox availability.
readFnoxConfig(path) / extractFnoxKeys(config)
Section titled “readFnoxConfig(path) / extractFnoxKeys(config)”Read and parse fnox configuration.
compareFnoxAndEnvpkt(fnoxConfig, envpktConfig)
Section titled “compareFnoxAndEnvpkt(fnoxConfig, envpktConfig)”Compare keys between fnox and envpkt for orphan detection.
fnoxGet(key, profile?) / fnoxExport(keys, profile?)
Section titled “fnoxGet(key, profile?) / fnoxExport(keys, profile?)”Retrieve secret values from fnox.
ageAvailable() / unwrapAgentKey(identityPath)
Section titled “ageAvailable() / unwrapAgentKey(identityPath)”Check for age encryption support and decrypt agent keys.
MCP Server
Section titled “MCP Server”createServer() / startServer()
Section titled “createServer() / startServer()”Create and start the MCP server programmatically.
toolDefinitions / callTool(name, args, config, audit)
Section titled “toolDefinitions / callTool(name, args, config, audit)”MCP tool definitions and invocation.
resourceDefinitions / readResource(uri, config, audit)
Section titled “resourceDefinitions / readResource(uri, config, audit)”MCP resource definitions and reading.