opencode.env 0.0.0 → 0.0.1

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 +53 -55
  2. package/dist/index.mjs +19 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,16 @@
1
- # opencode-armor
1
+ # opencode.env
2
2
 
3
- OpenCode plugin that blocks bash commands for long-running dev servers, injects
4
- project `.env` variables into the shell, and prepends/appends arbitrary commands
5
- to every bash invocation.
3
+ OpenCode plugin that loads `.env` files and direnv environment variables into
4
+ every shell invocation.
5
+
6
+ ## Features
7
+
8
+ - **`.env` file loading** — Load one or more `.env` files and inject them into every shell invocation.
9
+ - **Direnv integration** — Automatically pulls environment variables from [direnv](https://direnv.net/).
10
+ - **Inline variable definitions** — Define `KEY: "value"` pairs directly in config.
11
+ - **Multi-layer config** — Global (`~/.opencode.env.json`), project (`.opencode.env.json`), and opencode (`.opencode/env.json`) layers merged together.
12
+ - **CWD support** — Automatically loads `.env` files from the current working directory when different from the project root.
13
+ - **Selective disabling** — Independently disable global config, CWD loading, or direnv.
6
14
 
7
15
  ## Usage
8
16
 
@@ -10,7 +18,7 @@ Add to your OpenCode config (`opencode.json`):
10
18
 
11
19
  ```json
12
20
  {
13
- "plugin": ["opencode-armor"]
21
+ "plugin": ["opencode.env"]
14
22
  }
15
23
  ```
16
24
 
@@ -19,72 +27,62 @@ Add to your OpenCode config (`opencode.json`):
19
27
  Create a config file in any of these locations. Layers are merged in this order
20
28
  (later wins and merged instead of replacing):
21
29
 
22
- 1. `~/.opencode-armor.json` — global
23
- 2. `./.opencode-armor.json` — project root
24
- 3. `./.opencode/armor.json` — project root
30
+ 1. `~/.opencode.env.json` — global
31
+ 2. `./.opencode.env.json` — project root
32
+ 3. `./.opencode/env.json` — project root
25
33
 
26
34
  ```json
27
35
  {
28
- "$schema": "https://github.com/NazmusSayad/opencode-armor/raw/refs/heads/schema/schema.json",
29
- "armor": {
30
- "priority": "whitelist",
31
- "message": "Blocked: `{{COMMAND}}` (matched `{{PATTERN}}`)",
32
- "blacklist": {
33
- "commands": ["custom-pattern"],
34
- "disableDefaults": false,
35
- "disableGlobal": false
36
- },
37
- "whitelist": {
38
- "commands": ["vitest"],
39
- "disableDefaults": false,
40
- "disableGlobal": false
41
- }
36
+ "files": [".env", ".env.local"],
37
+ "define": {
38
+ "NODE_ENV": "development"
42
39
  },
43
- "dotenv": {
44
- "define": { "MY_VAR": "value" },
45
- "files": [".env"],
46
- "disableDefaults": false,
47
- "disableGlobal": false,
48
- "disableCwd": false
49
- },
50
- "command": {
51
- "before": { "command": "set -e", "comment": "Fail fast" },
52
- "after": { "command": "echo done", "comment": "Notify" }
53
- }
40
+ "disableDirenv": false,
41
+ "disableGlobal": false,
42
+ "disableCwd": false
54
43
  }
55
44
  ```
56
45
 
57
- ### `armor`
46
+ ### `files`
47
+
48
+ Array of `.env`-style file paths to load (resolved relative to the project root,
49
+ or `~/` for home directory). Variables are merged in order — later files
50
+ override earlier ones.
51
+
52
+ ### `define`
53
+
54
+ Inline `KEY: "value"` map of environment variables. These are merged over
55
+ file-based variables, so they take precedence.
56
+
57
+ ### `disableDirenv`
58
58
 
59
- Controls which bash commands are blocked. Patterns are case-insensitive and
60
- whitespace-normalized.
59
+ Set to `true` to skip loading environment variables from [direnv](https://direnv.net/).
61
60
 
62
- - `priority` — `"whitelist"` (default) or `"blacklist"`.
63
- - `blacklist` / `whitelist` — `commands` are substring patterns. `disableDefaults` skips the built-in list; `disableGlobal` skips the global config's list.
64
- - `message` — custom block error. Placeholders: `{{COMMAND}}`, `{{PATTERN}}`.
61
+ ### `disableGlobal`
65
62
 
66
- By default, dev servers and watchers are blocked e.g. `npm run dev`,
67
- `yarn start`, `npx vite`, `npx next`, `npx nodemon`, `npx tsx watch`,
68
- `node --watch`, `pm2 start`. `npx next lint` is allowed by default.
63
+ Set to `true` to ignore the global config's `files` and `define` settings.
69
64
 
70
- ### `dotenv`
65
+ ### `disableCwd`
71
66
 
72
- Injects environment variables into every shell via the `shell.env` hook.
67
+ By default, `.env` files from the current working directory are also loaded
68
+ (if different from the project root). Set to `true` to load only from the
69
+ project root.
73
70
 
74
- - `define` inline `KEY: "value"` map merged over file-based vars.
75
- - `files` — additional `.env`-style files to load (resolved relative to project root, or `~/` for home).
76
- - `disableDefaults` — skip the built-in `.env` file list.
77
- - `disableGlobal` — skip the global config's `define` and `files`.
78
- - `disableCwd` — by default, `.env` files from the current working directory are also loaded. Set to `true` to load only from the project root.
71
+ ## How it works
79
72
 
80
- ### `command`
73
+ The plugin hooks into OpenCode's `shell.env` lifecycle. Before every bash
74
+ invocation, it resolves environment variables from:
81
75
 
82
- Inject a command at the start or end of every bash invocation. Skipped when the
83
- command already starts/ends with the injected string.
76
+ 1. Inline `define` values from config (global project opencode)
77
+ 2. `.env` files listed in config
78
+ 3. Current working directory `.env` files (unless `disableCwd`)
79
+ 4. [direnv](https://direnv.net/) output (unless `disableDirenv`)
84
80
 
85
- - `before` / `after` `{ command, comment }`. `comment` is appended after `#`.
81
+ All resolved variables are injected into the shell environment so they are
82
+ available to your commands.
86
83
 
87
84
  ## Debugging
88
85
 
89
- Set `OPENCODE_ARMOR_ENABLE_LOG=true` to write logs to
90
- `os.tmpdir()/.opencode-armor-logs/`.
86
+ Set `OPENCODE_ENV_LOG_ENABLED=true` to write logs to
87
+ `os.tmpdir()/.opencode.env-logs/`. Use `OPENCODE_ENV_LOG_PATH` to specify a
88
+ custom log directory.