envpkt 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +76 -65
  2. package/dist/cli.js +114 -43
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,43 +5,38 @@
5
5
 
6
6
  **Credentials your agents actually understand.**
7
7
 
8
- Structured metadata for every secret capabilities, constraints, expiration, and fleet healthso agents operate within their boundaries instead of flying blind.
8
+ envpkt gives every credential an `envpkt.toml` entry describing _what service it authenticates to_, _what it's allowed to do_, _when it expires_, and _how to rotate it_ while the secret values stay in your secrets manager, encrypted at rest, or injected at runtime, never committed in plaintext.
9
9
 
10
- Every credential in your system gets an `envpkt.toml` entry describing _what service it authenticates to_, _what it's allowed to do_, _when it expires_, and _how to rotate it_. Your agents query this metadata via MCP to understand their operating constraints. Your operators audit credential health across entire agent fleets. The secrets themselves stay where they belong — in your secrets manager, encrypted at rest, or injected at runtime never in the agent's conversation context.
10
+ **Day one, with zero agents,** it's an encrypted-at-rest `.env` replacement with scoped loading: scan the credentials already in your shell, seal them into a file that's safe to commit, and load them automatically on `cd`, into a single command, or as a plain `.env` for any tool that wants one.
11
11
 
12
- ## MCP Integration
12
+ **As you add agents,** the same metadata gives them structured awareness of their own credentials over [MCP](#for-agents-and-fleets) — capabilities, expiry, drift, fleet health — without any secret value ever entering the model's context window.
13
13
 
14
- envpkt ships an [MCP](https://modelcontextprotocol.io/) server that gives AI agents structured awareness of their credentials. Add it to Claude, Cursor, VS Code, or any MCP-compatible client:
14
+ ## Quick Start
15
15
 
16
- ```json
17
- {
18
- "mcpServers": {
19
- "envpkt": {
20
- "command": "envpkt",
21
- "args": ["mcp"]
22
- }
23
- }
24
- }
25
- ```
16
+ The whole loop for a single project — discover, seal, load — with zero agents involved:
26
17
 
27
- ### Tools
18
+ ```bash
19
+ npm install -g envpkt
28
20
 
29
- | Tool | Description |
30
- | ------------------ | ------------------------------------------------------- |
31
- | `getPacketHealth` | Get overall health status with per-secret audit results |
32
- | `listCapabilities` | List agent and per-secret capabilities |
33
- | `getSecretMeta` | Get metadata for a specific secret by key |
34
- | `checkExpiration` | Check expiration status and days remaining |
35
- | `getEnvMeta` | Get metadata for environment defaults and drift status |
21
+ # 1. Discover the credentials already in your shell, and scaffold envpkt.toml from them
22
+ envpkt env scan
23
+ envpkt env scan --write
36
24
 
37
- ### Resources
25
+ # 2. Generate an age key and seal the secret values into envpkt.toml (the file is safe to commit)
26
+ envpkt keygen
27
+ envpkt seal
38
28
 
39
- | URI | Description |
40
- | ----------------------- | --------------------------------- |
41
- | `envpkt://health` | Current credential health summary |
42
- | `envpkt://capabilities` | Agent and secret capabilities |
29
+ # 3. Load them — pick whatever fits the moment:
30
+ envpkt exec -- your-tool # run one command with the secrets injected, scoped to it
31
+ eval "$(envpkt shell-hook zsh)" # add to ~/.zshrc: auto-load on cd into a project, restore on leave
32
+ envpkt env dotenv -o .env # materialize a .env for Docker / Wrangler / Vite / …
33
+
34
+ # Anytime: check health and drift
35
+ envpkt audit
36
+ envpkt env check
37
+ ```
43
38
 
44
- The MCP server exposes metadata onlyit does not have access to secret values. See [Security Model](#security-model) for details.
39
+ Encrypted secrets committed to git, loaded where you need them, with health you can audit and not an agent in sight. Scaling the same metadata to agents and fleets is [act two](#for-agents-and-fleets).
45
40
 
46
41
  ## Security Model
47
42
 
@@ -53,30 +48,6 @@ envpkt operates a three-tier trust model. Each tier has different guarantees, an
53
48
 
54
49
  **Tier 3: Shell-level agents** — Agents with shell access (Claude Code, Devin, etc.) can read environment variables directly. Prevention isn't possible at this tier. envpkt provides encrypted storage, scoped access, and audit trails — because when prevention isn't possible, visibility is what matters.
55
50
 
56
- ## Quick Start
57
-
58
- Start where your credentials already are — environment variables — and graduate to encrypted, per-agent-scoped metadata.
59
-
60
- ```bash
61
- # Install
62
- npm install -g envpkt
63
-
64
- # Auto-discover credentials from your shell environment
65
- envpkt env scan
66
-
67
- # Scaffold envpkt.toml from discovered credentials
68
- envpkt env scan --write
69
-
70
- # Audit credential health
71
- envpkt audit
72
-
73
- # Check for drift between envpkt.toml and live environment
74
- envpkt env check
75
-
76
- # Scan a directory tree of agents
77
- envpkt fleet
78
- ```
79
-
80
51
  ## The envpkt.toml File
81
52
 
82
53
  Every project gets one `envpkt.toml` that describes its credentials. Here's a minimal example:
@@ -236,6 +207,44 @@ A composite action resolves the credentials in `envpkt.toml` into the CI job —
236
207
 
237
208
  > Decrypting sealed packets requires the [`age`](https://github.com/FiloSottile/age) CLI on the runner (install it first, as above) — not needed if you only inject plaintext `[env.*]` defaults or resolve via fnox. Pin to a released tag (e.g. `@v0.12.0`); no moving major tag (`@v1`) is published yet. Node is assumed present; add `actions/setup-node` first to pin a version.
238
209
 
210
+ ## For agents and fleets
211
+
212
+ Everything above stands on its own with no agents involved. Once you _do_ have them, the same `envpkt.toml` metadata powers three more capabilities: agents reading their own constraints over MCP, fleet-wide health monitoring, and shared catalogs across many agents.
213
+
214
+ ### MCP server
215
+
216
+ envpkt ships an [MCP](https://modelcontextprotocol.io/) server that gives AI agents structured awareness of their credentials. Add it to Claude, Cursor, VS Code, or any MCP-compatible client:
217
+
218
+ ```json
219
+ {
220
+ "mcpServers": {
221
+ "envpkt": {
222
+ "command": "envpkt",
223
+ "args": ["mcp"]
224
+ }
225
+ }
226
+ }
227
+ ```
228
+
229
+ **Tools**
230
+
231
+ | Tool | Description |
232
+ | ------------------ | ------------------------------------------------------- |
233
+ | `getPacketHealth` | Get overall health status with per-secret audit results |
234
+ | `listCapabilities` | List agent and per-secret capabilities |
235
+ | `getSecretMeta` | Get metadata for a specific secret by key |
236
+ | `checkExpiration` | Check expiration status and days remaining |
237
+ | `getEnvMeta` | Get metadata for environment defaults and drift status |
238
+
239
+ **Resources**
240
+
241
+ | URI | Description |
242
+ | ----------------------- | --------------------------------- |
243
+ | `envpkt://health` | Current credential health summary |
244
+ | `envpkt://capabilities` | Agent and secret capabilities |
245
+
246
+ The MCP server exposes metadata only — it reads `envpkt.toml` and strips any `encrypted_value` ciphertext from responses, so prompt injection cannot leak what isn't there. See [Security Model](#security-model) for the full trust model.
247
+
239
248
  ## Fleet Management
240
249
 
241
250
  When you're running multiple agents, `envpkt fleet` scans a directory tree for `envpkt.toml` files and aggregates credential health across your entire fleet.
@@ -355,6 +364,19 @@ envpkt audit -c path/to/envpkt.toml # Specify config path
355
364
 
356
365
  Exit codes: `0` = healthy, `1` = degraded, `2` = critical.
357
366
 
367
+ ### `envpkt doctor`
368
+
369
+ One-shot environment check: is the `age` CLI installed, is a config resolvable here, and do its sealed secrets decrypt with an available key?
370
+
371
+ ```bash
372
+ envpkt doctor
373
+ # ✓ age v1.2.0
374
+ # ✓ config /path/to/envpkt.toml
375
+ # ✓ secrets 5 resolved, 0 skipped
376
+ ```
377
+
378
+ If `age` is missing it prints the platform-specific install command; if a sealed packet has no key, it lists the paths it searched. Exits non-zero when a check fails.
379
+
358
380
  ### `envpkt resolve`
359
381
 
360
382
  Resolve catalog references and output a flat, self-contained config.
@@ -470,7 +492,8 @@ Secret values are emitted **only when the package sets top-level `scope = "shell
470
492
  Generate a `cd` hook (zsh/bash) that loads a project's credentials when you enter its directory tree and restores your environment when you leave:
471
493
 
472
494
  ```bash
473
- eval "$(envpkt shell-hook zsh)" # add to ~/.zshrc (or: shell-hook bash)
495
+ eval "$(envpkt shell-hook zsh)" # add to ~/.zshrc (or: shell-hook bash)
496
+ eval "$(envpkt shell-hook zsh --no-audit)" # …without the per-cd health-check line
474
497
  ```
475
498
 
476
499
  On each directory change it resolves the **nearest `envpkt.toml`, walking up from the current directory** (like `git`/`direnv` — so it works from any subdirectory, not just the project root), injects that package via `env export --track`, and restores the previous package on leave (prior values, not a blind unset). Env defaults always load; secret values load only for `scope = "shell"` packages. Backed by `envpkt config-path` — a resolve-only command that prints the active config path (no decryption).
@@ -486,18 +509,6 @@ Inject resolved secrets into a GitHub Actions job. Emits `::add-mask::` for each
486
509
  npx envpkt env github --strict
487
510
  ```
488
511
 
489
- ### `envpkt shell-hook`
490
-
491
- Output a shell function that runs `envpkt audit --format minimal` whenever you `cd` into a directory. envpkt's config discovery chain automatically finds config files beyond CWD (see [Config Resolution](#config-resolution)), so the hook works even in directories without a local `envpkt.toml`.
492
-
493
- ```bash
494
- # Add to your .zshrc
495
- eval "$(envpkt shell-hook zsh)"
496
-
497
- # Add to your .bashrc
498
- eval "$(envpkt shell-hook bash)"
499
- ```
500
-
501
512
  ### `envpkt mcp`
502
513
 
503
514
  Start the envpkt MCP server (stdio transport) for AI agent integration.
package/dist/cli.js CHANGED
@@ -8,10 +8,10 @@ import { TypeCompiler } from "@sinclair/typebox/compiler";
8
8
  import { Env, Fs, Path, Platform } from "functype-os";
9
9
  import { TomlDate, parse, stringify } from "smol-toml";
10
10
  import { FormatRegistry, Type } from "@sinclair/typebox";
11
- import { randomBytes } from "node:crypto";
11
+ import { execFileSync } from "node:child_process";
12
12
  import { homedir, tmpdir } from "node:os";
13
13
  import { directSilentLogger } from "functype-log/direct";
14
- import { execFileSync } from "node:child_process";
14
+ import { randomBytes } from "node:crypto";
15
15
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
16
16
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
17
  import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema } from "@modelcontextprotocol/sdk/types.js";
@@ -557,6 +557,63 @@ const resolveConfig = (agentConfig, agentConfigDir) => {
557
557
  }));
558
558
  };
559
559
  //#endregion
560
+ //#region src/fnox/identity.ts
561
+ /** Check if the age CLI is available on PATH */
562
+ const ageAvailable = () => Try(() => {
563
+ execFileSync("age", ["--version"], { stdio: "pipe" });
564
+ return true;
565
+ }).fold(() => false, (v) => v);
566
+ /** The age CLI version string (e.g. "v1.2.0"), or None if age isn't on PATH. */
567
+ const ageVersion = () => Try(() => execFileSync("age", ["--version"], {
568
+ stdio: [
569
+ "pipe",
570
+ "pipe",
571
+ "pipe"
572
+ ],
573
+ encoding: "utf-8"
574
+ }).trim()).fold(() => Option.none(), (v) => Option(v));
575
+ /** Platform-aware instructions for installing the age CLI. */
576
+ const ageInstallHint = () => {
577
+ return `Install age:\n ${{
578
+ darwin: "brew install age",
579
+ linux: "apt install age (or: apk add age · dnf install age · nix-env -iA nixpkgs.age)",
580
+ win32: "scoop install age (or: winget install FiloSottile.age)"
581
+ }[process.platform] ?? "see the install guide"}\n https://github.com/FiloSottile/age#installation`;
582
+ };
583
+ /**
584
+ * Extract the secret key from an age identity file (plain or encrypted).
585
+ * - Plain identity files (from `age-keygen`) contain `AGE-SECRET-KEY-*` lines directly
586
+ * - Encrypted identity files need `age --decrypt` to unwrap
587
+ */
588
+ const unwrapAgentKey = (identityPath) => {
589
+ if (!existsSync(identityPath)) return Left({
590
+ _tag: "IdentityNotFound",
591
+ path: identityPath
592
+ });
593
+ return Try(() => readFileSync(identityPath, "utf-8")).fold((err) => Left({
594
+ _tag: "DecryptFailed",
595
+ message: `Failed to read identity file: ${err}`
596
+ }), (content) => {
597
+ const secretKeyLine = content.split("\n").find((l) => l.startsWith("AGE-SECRET-KEY-"));
598
+ if (secretKeyLine) return Right(secretKeyLine.trim());
599
+ if (!ageAvailable()) return Left({
600
+ _tag: "AgeNotFound",
601
+ message: "age CLI not found on PATH"
602
+ });
603
+ return Try(() => execFileSync("age", ["--decrypt", identityPath], {
604
+ stdio: [
605
+ "pipe",
606
+ "pipe",
607
+ "pipe"
608
+ ],
609
+ encoding: "utf-8"
610
+ })).fold((err) => Left({
611
+ _tag: "DecryptFailed",
612
+ message: `age decrypt failed: ${err}`
613
+ }), (output) => Right(output.trim()));
614
+ });
615
+ };
616
+ //#endregion
560
617
  //#region src/cli/output.ts
561
618
  const RESET = "\x1B[0m";
562
619
  const BOLD = "\x1B[1m";
@@ -659,7 +716,7 @@ const formatError = (error) => {
659
716
  case "ParseError": return `${RED}Error:${RESET} Failed to parse TOML: ${error.message}`;
660
717
  case "ValidationError": return `${RED}Error:${RESET} Config validation failed:\n${String(error.errors)}`;
661
718
  case "ReadError": return `${RED}Error:${RESET} Could not read file: ${error.message}`;
662
- case "AgeNotFound": return `${RED}Error:${RESET} age CLI not found: ${error.message}`;
719
+ case "AgeNotFound": return `${RED}Error:${RESET} age is required for this operation but was not found on PATH.\n${DIM}${ageInstallHint()}${RESET}`;
663
720
  case "DecryptFailed": return `${RED}Error:${RESET} Decrypt failed: ${error.message}`;
664
721
  case "IdentityNotFound": return `${RED}Error:${RESET} Identity file not found: ${error.path}`;
665
722
  case "SealKeyUnavailable": {
@@ -918,46 +975,6 @@ const fnoxAvailable = () => Try(() => {
918
975
  return true;
919
976
  }).fold(() => false, (v) => v);
920
977
  //#endregion
921
- //#region src/fnox/identity.ts
922
- /** Check if the age CLI is available on PATH */
923
- const ageAvailable = () => Try(() => {
924
- execFileSync("age", ["--version"], { stdio: "pipe" });
925
- return true;
926
- }).fold(() => false, (v) => v);
927
- /**
928
- * Extract the secret key from an age identity file (plain or encrypted).
929
- * - Plain identity files (from `age-keygen`) contain `AGE-SECRET-KEY-*` lines directly
930
- * - Encrypted identity files need `age --decrypt` to unwrap
931
- */
932
- const unwrapAgentKey = (identityPath) => {
933
- if (!existsSync(identityPath)) return Left({
934
- _tag: "IdentityNotFound",
935
- path: identityPath
936
- });
937
- return Try(() => readFileSync(identityPath, "utf-8")).fold((err) => Left({
938
- _tag: "DecryptFailed",
939
- message: `Failed to read identity file: ${err}`
940
- }), (content) => {
941
- const secretKeyLine = content.split("\n").find((l) => l.startsWith("AGE-SECRET-KEY-"));
942
- if (secretKeyLine) return Right(secretKeyLine.trim());
943
- if (!ageAvailable()) return Left({
944
- _tag: "AgeNotFound",
945
- message: "age CLI not found on PATH"
946
- });
947
- return Try(() => execFileSync("age", ["--decrypt", identityPath], {
948
- stdio: [
949
- "pipe",
950
- "pipe",
951
- "pipe"
952
- ],
953
- encoding: "utf-8"
954
- })).fold((err) => Left({
955
- _tag: "DecryptFailed",
956
- message: `age decrypt failed: ${err}`
957
- }), (output) => Right(output.trim()));
958
- });
959
- };
960
- //#endregion
961
978
  //#region src/fnox/parse.ts
962
979
  /** Read and parse fnox.toml, extracting secret keys and profiles */
963
980
  const readFnoxConfig = (path) => Try(() => readFileSync(path, "utf-8")).fold((err) => Left({
@@ -1594,6 +1611,57 @@ const bootSafe = (options) => {
1594
1611
  }));
1595
1612
  };
1596
1613
  //#endregion
1614
+ //#region src/cli/commands/doctor.ts
1615
+ const ok = (label, detail) => console.log(` ${GREEN}✓${RESET} ${label} ${DIM}${detail}${RESET}`);
1616
+ const warn = (label, detail) => console.log(` ${YELLOW}—${RESET} ${label} ${detail}`);
1617
+ const bad = (label, detail) => console.log(` ${RED}✗${RESET} ${label} ${detail}`);
1618
+ /** Print the resolution/key check, returning whether it passed. */
1619
+ const reportResolution = (configPath) => bootSafe({
1620
+ configPath,
1621
+ inject: false,
1622
+ warnOnly: true
1623
+ }).fold((err) => {
1624
+ if (err._tag === "SealKeyUnavailable") {
1625
+ bad("key ", `${err.sealedKeys.length} sealed secret(s) but no decryption key`);
1626
+ err.searched.forEach((line) => console.log(`${DIM} ${line}${RESET}`));
1627
+ } else bad("config", `${err._tag}`);
1628
+ return false;
1629
+ }, (boot) => {
1630
+ const resolved = Object.keys(boot.secrets).length;
1631
+ ok("secrets", `${resolved} resolved, ${boot.skipped.length} skipped`);
1632
+ const auditColor = boot.audit.status === "healthy" ? GREEN : YELLOW;
1633
+ console.log(` ${auditColor}•${RESET} audit ${DIM}${boot.audit.status}${RESET}`);
1634
+ return true;
1635
+ });
1636
+ /**
1637
+ * One-shot environment check: is age installed, is a config resolvable, and do its sealed
1638
+ * secrets decrypt with an available key? Read-only; exits non-zero if any check fails.
1639
+ */
1640
+ const runDoctor = (options) => {
1641
+ console.log(`${BOLD}envpkt doctor${RESET}\n`);
1642
+ const ageOk = ageVersion().fold(() => {
1643
+ bad("age ", "not found on PATH");
1644
+ console.log(`${DIM} ${ageInstallHint().split("\n").join("\n ")}${RESET}`);
1645
+ return false;
1646
+ }, (version) => {
1647
+ ok("age ", version);
1648
+ return true;
1649
+ });
1650
+ const resolveOk = resolveConfigPath(options.config).fold(() => {
1651
+ warn("config", "no envpkt.toml found for this directory");
1652
+ return true;
1653
+ }, ({ path }) => {
1654
+ ok("config", path);
1655
+ return reportResolution(path);
1656
+ });
1657
+ console.log("");
1658
+ if (ageOk && resolveOk) console.log(`${GREEN}✓ no issues${RESET}`);
1659
+ else {
1660
+ console.log(`${RED}✗ ${[!ageOk, !resolveOk].filter(Boolean).length} issue(s) found${RESET} ${CYAN}(see above)${RESET}`);
1661
+ process.exit(1);
1662
+ }
1663
+ };
1664
+ //#endregion
1597
1665
  //#region src/core/dotenv.ts
1598
1666
  const BARE_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
1599
1667
  /**
@@ -5078,6 +5146,9 @@ program.command("sort").description("Group [env.*] and [secret.*] sections and a
5078
5146
  program.command("upgrade").description("Upgrade envpkt to the latest version (npm install -g envpkt@latest)").action(() => {
5079
5147
  runUpgrade();
5080
5148
  });
5149
+ program.command("doctor").description("Check that age is installed and that the resolved config's sealed secrets can be decrypted").option("-c, --config <path>", "Path to envpkt.toml").action((options) => {
5150
+ runDoctor(options);
5151
+ });
5081
5152
  program.command("config-path").description("Print the envpkt.toml path resolved for the current directory (empty if none). Resolve-only — no decryption.").option("-c, --config <path>", "Path to envpkt.toml").action((options) => {
5082
5153
  runConfigPath(options);
5083
5154
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envpkt",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Credential lifecycle and fleet management for AI agents",
5
5
  "keywords": [
6
6
  "credentials",