Skip to content

Commit 23b6c63

Browse files
committed
Release v0.5.1
1 parent 8db1816 commit 23b6c63

File tree

5 files changed

+390
-26
lines changed

5 files changed

+390
-26
lines changed

AGENTS.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ OpenCode plugin that loads `.env` files at startup. This is a Bun runtime plugin
1010
**Type**: OpenCode plugin
1111
**Language**: TypeScript (ESM)
1212

13+
### Critical Architectural Limitation
14+
15+
This plugin **cannot** set environment variables for use in OpenCode's config file. OpenCode parses `opencode.jsonc` (including `{env:VAR}` resolution) **before** loading plugins. Therefore:
16+
17+
- Variables set by this plugin are available to chat sessions and tool executions
18+
- Variables set by this plugin are **NOT** available to `{env:VAR}` references in `opencode.jsonc`
19+
- For config variables (API keys, etc.), users must set them in shell profile before starting OpenCode
20+
21+
See `docs/ARCHITECTURE.md` for detailed startup sequence diagrams.
22+
1323
## Essential Commands
1424

1525
### Build & Install
@@ -78,14 +88,17 @@ bun run src/index.ts
7888
```
7989
opencode-dotenv/
8090
├── src/
81-
│ ├── index.ts # Main plugin entry point
82-
│ ├── index.test.ts # Unit tests
91+
│ ├── index.ts # Entry point, re-exports
92+
│ ├── plugin.ts # Main plugin implementation
93+
│ ├── test-utils.ts # Internal test utilities
8394
│ └── profiler/
8495
│ ├── index.ts # Profiler exports
8596
│ └── profiler.ts # Performance profiler
8697
├── bench/
8798
│ ├── utils.ts # Benchmark utilities
8899
│ └── init.bench.ts # Initialization benchmarks
100+
├── docs/
101+
│ └── ARCHITECTURE.md # Plugin architecture and startup sequence
89102
├── dist/ # Built output (generated, not in git)
90103
├── package.json
91104
├── Makefile
@@ -99,6 +112,7 @@ opencode-dotenv/
99112
- Tests co-located with source code
100113
- Only `dist/` directory is published to npm (see `package.json` `files` field)
101114
- Source files are excluded from npm package via `.npmignore`
115+
- Architecture docs in `docs/` directory
102116

103117
## Naming Conventions & Style
104118

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.1] - 2026-01-08
9+
10+
### Added
11+
- New `docs/ARCHITECTURE.md` with comprehensive startup sequence diagrams
12+
- Prominent limitation warning at top of README
13+
14+
### Fixed
15+
- README: config file name corrected to `dotenv.jsonc` (was `opencode-dotenv.jsonc`)
16+
- README: config search order corrected to local-first, then global
17+
- README: log file path corrected to `~/.local/share/opencode/dotenv.log`
18+
- README: logging default corrected to disabled (was incorrectly stated as enabled)
19+
20+
### Changed
21+
- AGENTS.md: added critical architectural limitation section
22+
- AGENTS.md: updated code organization to reflect current structure
23+
824
## [0.5.0] - 2026-01-08
925

1026
### Changed

README.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22

33
OpenCode plugin to load `.env` files at startup.
44

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+
515
## Features
616

717
- Load multiple `.env` files in order via config file
818
- Load `.env` from current working directory (optional)
919
- Override existing environment variables (later files override earlier ones)
10-
- Configurable logging to `/tmp/opencode-dotenv.log` (enabled by default)
20+
- Configurable logging to `~/.local/share/opencode/dotenv.log` (disabled by default)
1121
- Prevents double loading with load guard
1222
- JSONC config file format (supports comments and trailing commas)
1323
- **Requires Bun runtime**
14-
15-
## Limitations
1624

17-
**Important:** This plugin loads AFTER OpenCode configuration is already parsed. Therefore:
25+
## Limitations
1826

1927
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.
2028

@@ -45,12 +53,12 @@ After publishing to npm, you can use:
4553

4654
## Configuration
4755

48-
Create `opencode-dotenv.jsonc` in one of these locations:
56+
Create `dotenv.jsonc` in one of these locations (searched in order, first found wins):
4957

50-
1. `~/.config/opencode/opencode-dotenv.jsonc` (recommended, global config)
51-
2. `./opencode-dotenv.jsonc` in current working directory (project-specific)
58+
1. `./dotenv.jsonc` in current working directory (project-specific)
59+
2. `~/.config/opencode/dotenv.jsonc` (global config)
5260

53-
**Note:** Config files are loaded in the order above; the first found file is used.
61+
**Note:** Only the first found config file is used; configs are not merged.
5462

5563
### Config Schema
5664

@@ -68,21 +76,21 @@ Config file uses **JSONC format** (JSON with Comments), which supports:
6876
],
6977
"load_cwd_env": true,
7078
"logging": {
71-
"enabled": true
79+
"enabled": false
7280
}
7381
}
7482
```
7583

7684
**Fields:**
7785
- `files` (array, optional): List of `.env` file paths to load in order. Later files override earlier ones.
7886
- `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 `/tmp/opencode-dotenv.log`. Defaults to `true`.
87+
- `logging.enabled` (boolean, optional): Enable/disable logging to `~/.local/share/opencode/dotenv.log`. Defaults to `false`.
8088

8189
**Notes:**
8290
- Use `~` for home directory (automatically expanded)
8391
- Paths are expanded before loading
8492
- If no config file exists, only loads `./.env` from cwd (if present)
85-
- Logging writes to `/tmp/opencode-dotenv.log` for debugging
93+
- Logging writes to `~/.local/share/opencode/dotenv.log` for debugging
8694

8795
### Load Order
8896

@@ -95,7 +103,7 @@ This ensures project-specific env vars have the highest precedence.
95103

96104
### Load global and project-specific .env files
97105

98-
Config (`~/.config/opencode/opencode-dotenv.jsonc`):
106+
Config (`~/.config/opencode/dotenv.jsonc`):
99107

100108
```jsonc
101109
{
@@ -112,11 +120,11 @@ Config (`~/.config/opencode/opencode-dotenv.jsonc`):
112120
Result:
113121
1. Loads `~/.config/opencode/.env`
114122
2. Loads `./.env` from cwd (overrides any conflicts)
115-
3. Logs all activity to `/tmp/opencode-dotenv.log`
123+
3. Logs all activity to `~/.local/share/opencode/dotenv.log`
116124

117125
### Load multiple global files without cwd .env
118126

119-
Config (`~/.config/opencode/opencode-dotenv.jsonc`):
127+
Config (`~/.config/opencode/dotenv.jsonc`):
120128

121129
```jsonc
122130
{
@@ -143,12 +151,12 @@ Result:
143151

144152
```bash
145153
# OpenCode Dotenv Configuration
146-
OPENCODE_API_KEY=your_api_key_here
147-
OPENCODE_DEBUG=true
148-
OPENCODE_MAX_TOKENS=100000
154+
OPENCODE_DEBUG=true
155+
OPENCODE_MAX_TOKENS=100000
156+
MY_PROJECT_KEY=secret123
149157
```
150158

151-
**Note:** This plugin cannot inject these variables into OpenCode's configuration loading process. To use `OPENCODE_API_KEY` in `opencode.jsonc`, set it in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting OpenCode.
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.
152160

153161
`./.env` (project-specific):
154162
```bash
@@ -157,23 +165,23 @@ OPENCODE_DEBUG=false
157165
PROJECT_API_KEY=project_specific_key
158166
```
159167

160-
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `OPENCODE_API_KEY` from global, `PROJECT_API_KEY` from cwd.
168+
Result: `OPENCODE_DEBUG` will be `false` (from cwd), `MY_PROJECT_KEY` from global, `PROJECT_API_KEY` from cwd.
161169

162170
### Logging
163171

164172
View plugin activity logs:
165173

166174
```bash
167-
tail -f /tmp/opencode-dotenv.log
175+
tail -f ~/.local/share/opencode/dotenv.log
168176
```
169177

170-
Disable logging in config:
178+
Enable logging in config:
171179

172180
```jsonc
173181
{
174182
"files": ["~/.config/opencode/.env"],
175183
"logging": {
176-
"enabled": false
184+
"enabled": true
177185
}
178186
}
179187
```
@@ -186,7 +194,10 @@ Disable logging in config:
186194
opencode-dotenv/
187195
├── package.json
188196
├── src/
189-
│ └── index.ts
197+
│ ├── index.ts
198+
│ └── plugin.ts
199+
├── docs/
200+
│ └── ARCHITECTURE.md
190201
└── dist/
191202
└── index.js (built)
192203
```

0 commit comments

Comments
 (0)