opencode-dotenv 0.5.0 → 0.5.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.
- package/README.md +34 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,19 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
OpenCode plugin to load `.env` files at startup.
|
|
4
4
|
|
|
5
|
+
> **Important Limitation**
|
|
6
|
+
>
|
|
7
|
+
> This plugin **cannot** set environment variables for use in OpenCode's config file (`opencode.jsonc`). The plugin loads *after* OpenCode parses its configuration, so `{env:VARNAME}` references in config are resolved before this plugin runs.
|
|
8
|
+
>
|
|
9
|
+
> **Use this plugin for:** Managing environment variables available during chat sessions, tool executions, and bash commands.
|
|
10
|
+
>
|
|
11
|
+
> **Do not use this plugin for:** Setting API keys or other config values referenced via `{env:VAR}` syntax in `opencode.jsonc`. For those, set variables in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
|
|
12
|
+
>
|
|
13
|
+
> See [Architecture](docs/ARCHITECTURE.md) for details on the OpenCode startup sequence.
|
|
14
|
+
|
|
5
15
|
## Features
|
|
6
16
|
|
|
7
17
|
- Load multiple `.env` files in order via config file
|
|
8
18
|
- Load `.env` from current working directory (optional)
|
|
9
19
|
- Override existing environment variables (later files override earlier ones)
|
|
10
|
-
- Configurable logging to
|
|
20
|
+
- Configurable logging to `~/.local/share/opencode/dotenv.log` (disabled by default)
|
|
11
21
|
- Prevents double loading with load guard
|
|
12
22
|
- JSONC config file format (supports comments and trailing commas)
|
|
13
23
|
- **Requires Bun runtime**
|
|
14
|
-
|
|
15
|
-
## Limitations
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
## Limitations
|
|
18
26
|
|
|
19
27
|
1. **Cannot modify existing OpenCode config** - Variables loaded by this plugin cannot be referenced in `opencode.jsonc` using `{env:VAR}` syntax. OpenCode reads its config before plugins initialize.
|
|
20
28
|
|
|
@@ -45,12 +53,12 @@ After publishing to npm, you can use:
|
|
|
45
53
|
|
|
46
54
|
## Configuration
|
|
47
55
|
|
|
48
|
-
Create `
|
|
56
|
+
Create `dotenv.jsonc` in one of these locations (searched in order, first found wins):
|
|
49
57
|
|
|
50
|
-
1.
|
|
51
|
-
2.
|
|
58
|
+
1. `./dotenv.jsonc` in current working directory (project-specific)
|
|
59
|
+
2. `~/.config/opencode/dotenv.jsonc` (global config)
|
|
52
60
|
|
|
53
|
-
**Note:**
|
|
61
|
+
**Note:** Only the first found config file is used; configs are not merged.
|
|
54
62
|
|
|
55
63
|
### Config Schema
|
|
56
64
|
|
|
@@ -68,7 +76,7 @@ Config file uses **JSONC format** (JSON with Comments), which supports:
|
|
|
68
76
|
],
|
|
69
77
|
"load_cwd_env": true,
|
|
70
78
|
"logging": {
|
|
71
|
-
"enabled":
|
|
79
|
+
"enabled": false
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
```
|
|
@@ -76,13 +84,13 @@ Config file uses **JSONC format** (JSON with Comments), which supports:
|
|
|
76
84
|
**Fields:**
|
|
77
85
|
- `files` (array, optional): List of `.env` file paths to load in order. Later files override earlier ones.
|
|
78
86
|
- `load_cwd_env` (boolean, optional): Whether to load `.env` from the directory where OpenCode is opened. Defaults to `true`.
|
|
79
|
-
- `logging.enabled` (boolean, optional): Enable/disable logging to
|
|
87
|
+
- `logging.enabled` (boolean, optional): Enable/disable logging to `~/.local/share/opencode/dotenv.log`. Defaults to `false`.
|
|
80
88
|
|
|
81
89
|
**Notes:**
|
|
82
90
|
- Use `~` for home directory (automatically expanded)
|
|
83
91
|
- Paths are expanded before loading
|
|
84
92
|
- If no config file exists, only loads `./.env` from cwd (if present)
|
|
85
|
-
- Logging writes to
|
|
93
|
+
- Logging writes to `~/.local/share/opencode/dotenv.log` for debugging
|
|
86
94
|
|
|
87
95
|
### Load Order
|
|
88
96
|
|
|
@@ -95,7 +103,7 @@ This ensures project-specific env vars have the highest precedence.
|
|
|
95
103
|
|
|
96
104
|
### Load global and project-specific .env files
|
|
97
105
|
|
|
98
|
-
Config (`~/.config/opencode/
|
|
106
|
+
Config (`~/.config/opencode/dotenv.jsonc`):
|
|
99
107
|
|
|
100
108
|
```jsonc
|
|
101
109
|
{
|
|
@@ -112,11 +120,11 @@ Config (`~/.config/opencode/opencode-dotenv.jsonc`):
|
|
|
112
120
|
Result:
|
|
113
121
|
1. Loads `~/.config/opencode/.env`
|
|
114
122
|
2. Loads `./.env` from cwd (overrides any conflicts)
|
|
115
|
-
3. Logs all activity to
|
|
123
|
+
3. Logs all activity to `~/.local/share/opencode/dotenv.log`
|
|
116
124
|
|
|
117
125
|
### Load multiple global files without cwd .env
|
|
118
126
|
|
|
119
|
-
Config (`~/.config/opencode/
|
|
127
|
+
Config (`~/.config/opencode/dotenv.jsonc`):
|
|
120
128
|
|
|
121
129
|
```jsonc
|
|
122
130
|
{
|
|
@@ -143,12 +151,12 @@ Result:
|
|
|
143
151
|
|
|
144
152
|
```bash
|
|
145
153
|
# OpenCode Dotenv Configuration
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
OPENCODE_DEBUG=true
|
|
155
|
+
OPENCODE_MAX_TOKENS=100000
|
|
156
|
+
MY_PROJECT_KEY=secret123
|
|
149
157
|
```
|
|
150
158
|
|
|
151
|
-
**Note:** This plugin cannot inject
|
|
159
|
+
**Note:** This plugin cannot inject variables into OpenCode's configuration loading process. To set `ANTHROPIC_API_KEY` or other provider API keys, set them in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
|
|
152
160
|
|
|
153
161
|
`./.env` (project-specific):
|
|
154
162
|
```bash
|
|
@@ -157,23 +165,23 @@ OPENCODE_DEBUG=false
|
|
|
157
165
|
PROJECT_API_KEY=project_specific_key
|
|
158
166
|
```
|
|
159
167
|
|
|
160
|
-
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `
|
|
168
|
+
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `MY_PROJECT_KEY` from global, `PROJECT_API_KEY` from cwd.
|
|
161
169
|
|
|
162
170
|
### Logging
|
|
163
171
|
|
|
164
172
|
View plugin activity logs:
|
|
165
173
|
|
|
166
174
|
```bash
|
|
167
|
-
tail -f /
|
|
175
|
+
tail -f ~/.local/share/opencode/dotenv.log
|
|
168
176
|
```
|
|
169
177
|
|
|
170
|
-
|
|
178
|
+
Enable logging in config:
|
|
171
179
|
|
|
172
180
|
```jsonc
|
|
173
181
|
{
|
|
174
182
|
"files": ["~/.config/opencode/.env"],
|
|
175
183
|
"logging": {
|
|
176
|
-
"enabled":
|
|
184
|
+
"enabled": true
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
187
|
```
|
|
@@ -186,7 +194,10 @@ Disable logging in config:
|
|
|
186
194
|
opencode-dotenv/
|
|
187
195
|
├── package.json
|
|
188
196
|
├── src/
|
|
189
|
-
│
|
|
197
|
+
│ ├── index.ts
|
|
198
|
+
│ └── plugin.ts
|
|
199
|
+
├── docs/
|
|
200
|
+
│ └── ARCHITECTURE.md
|
|
190
201
|
└── dist/
|
|
191
202
|
└── index.js (built)
|
|
192
203
|
```
|