opencode-workspace-env 0.1.0 → 0.1.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 +12 -11
- package/dist/filter.d.ts.map +1 -1
- package/dist/filter.js +5 -0
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Per-workspace environment injection for OpenCode.
|
|
4
4
|
|
|
5
|
-
`opencode-workspace-env` is an OpenCode plugin that injects per-workspace env vars into every shell execution via the `shell.env` hook. It lets one OpenCode server work across multiple repos, each with its own
|
|
5
|
+
`opencode-workspace-env` is an OpenCode plugin that injects per-workspace env vars into every shell execution via the `shell.env` hook. It lets one OpenCode server work across multiple repos, each with its own direnv or nix environment.
|
|
6
6
|
|
|
7
7
|
## What This Does
|
|
8
8
|
|
|
9
|
-
OpenCode agents often need different toolchains per workspace — different Node, Python, or
|
|
9
|
+
OpenCode agents often need different toolchains per workspace — different Node, Python, or system packages. This plugin resolves the nearest env source from the current working directory, loads env vars, and injects them into the shell command that is about to run.
|
|
10
10
|
|
|
11
11
|
Two env source paths are supported:
|
|
12
12
|
|
|
13
|
-
1. **`.envrc`** (primary) —
|
|
14
|
-
2. **`flake.nix`** (fallback) —
|
|
13
|
+
1. **`.envrc`** (primary) — runs `direnv export json`. The `.envrc` can contain anything direnv supports (`use flake`, `layout python`, plain exports, etc.).
|
|
14
|
+
2. **`flake.nix`** (fallback) — runs `nix print-dev-env --json` directly. No direnv needed.
|
|
15
15
|
|
|
16
16
|
```text
|
|
17
17
|
Agent runs shell command
|
|
@@ -38,8 +38,8 @@ Add it to `opencode.json`:
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Prerequisites:
|
|
41
|
-
- **direnv**
|
|
42
|
-
- **nix**
|
|
41
|
+
- **direnv** — Required for the `.envrc` path. Must be installed globally on the host, not inside the devShell.
|
|
42
|
+
- **nix** — Required for the `flake.nix` fallback path. Also needed if your `.envrc` uses `use flake`.
|
|
43
43
|
|
|
44
44
|
## Usage
|
|
45
45
|
|
|
@@ -51,14 +51,14 @@ printf 'use flake\n' > .envrc
|
|
|
51
51
|
direnv allow
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
### With `flake.nix` only (no
|
|
54
|
+
### With `flake.nix` only (no direnv needed)
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
# just have a flake.nix with devShells.default — plugin detects it automatically
|
|
58
58
|
git add flake.nix
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
With the plugin enabled, any OpenCode shell command run inside that repo gets the exported environment for that workspace. Resolution stops at the git root, so a parent directory outside the repo is never used.
|
|
61
|
+
With the plugin enabled, any OpenCode shell command run inside that repo gets the exported environment for that workspace. Resolution walks up from cwd and stops at the git root, so a parent directory outside the repo is never used.
|
|
62
62
|
|
|
63
63
|
## Architecture
|
|
64
64
|
|
|
@@ -66,10 +66,10 @@ With the plugin enabled, any OpenCode shell command run inside that repo gets th
|
|
|
66
66
|
src/
|
|
67
67
|
├── index.ts # Plugin entry. shell.env hook, dispatches envrc vs flake
|
|
68
68
|
├── resolve.ts # cwd → ResolvedEnvSource (.envrc first, flake.nix fallback)
|
|
69
|
-
├── direnv.ts # `direnv export json` →
|
|
70
|
-
├── nix.ts # `nix print-dev-env --json` →
|
|
69
|
+
├── direnv.ts # `direnv export json` → EnvExportResult
|
|
70
|
+
├── nix.ts # `nix print-dev-env --json` → EnvExportResult
|
|
71
71
|
├── filter.ts # Shared env key filter (DIRENV_*, NIX_BUILD_*, nix internals)
|
|
72
|
-
└── cache.ts # In-memory cache keyed by source path + SHA-256 fingerprint
|
|
72
|
+
└── cache.ts # In-memory cache keyed by source path + SHA-256 fingerprint (max 50 entries, FIFO eviction)
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
- Writes only to `output.env`, never `process.env`
|
|
@@ -84,6 +84,7 @@ src/
|
|
|
84
84
|
- `flake.nix` must be `git add`ed for nix to see it
|
|
85
85
|
- `direnv` must be globally installed, not inside the devShell
|
|
86
86
|
- `nix print-dev-env` can be slow on first eval (~10s+), cached after
|
|
87
|
+
- In-memory cache holds up to 50 workspaces; oldest entries are evicted first (FIFO)
|
|
87
88
|
|
|
88
89
|
## License
|
|
89
90
|
|
package/dist/filter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAyDA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAKrD"}
|
package/dist/filter.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
const EXCLUDED_PREFIXES = ["DIRENV_", "NIX_BUILD_", "__"];
|
|
3
3
|
/** Known nix build-system variables that should not leak into shell env */
|
|
4
4
|
const EXCLUDED_VARS = new Set([
|
|
5
|
+
"HOME",
|
|
6
|
+
"USER",
|
|
7
|
+
"LOGNAME",
|
|
8
|
+
"SHELL",
|
|
9
|
+
"HOSTNAME",
|
|
5
10
|
"name",
|
|
6
11
|
"system",
|
|
7
12
|
"builder",
|
package/dist/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;AAE1D,2EAA2E;AAC3E,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,MAAM;IACN,QAAQ;IACR,SAAS;IACT,KAAK;IACL,KAAK;IACL,SAAS;IACT,QAAQ;IACR,WAAW;IACX,oBAAoB;IACpB,gBAAgB;IAChB,kBAA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W;IACX,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,mBAAmB;IACnB,uBAAuB;IACvB,6BAA6B;IAC7B,gBAAgB;IAChB,0BAA0B;IAC1B,eAAe;IACf,yBAAyB;IACzB,iBAAiB;IACjB,2BAA2B;IAC3B,cAAc;IACd,wBAAwB;IACxB,kBAAkB;IAClB,4BAA4B;IAC5B,QAAQ;IACR,YAAY;IACZ,OAAO;IACP,wBAAwB;IACxB,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,qBAAqB;IACrB,mBAAmB;CACpB,CAAC,CAAC;AAEH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin";
|
|
2
2
|
export declare const name = "opencode-workspace-env";
|
|
3
|
-
export declare const version = "0.1.
|
|
3
|
+
export declare const version = "0.1.1";
|
|
4
4
|
export declare const description = "OpenCode plugin for per-workspace env injection via shell.env hook";
|
|
5
5
|
declare const plugin: Plugin;
|
|
6
6
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { exportEnv } from "./direnv.js";
|
|
|
3
3
|
import { exportNixEnv } from "./nix.js";
|
|
4
4
|
import { resolveEnvSource } from "./resolve.js";
|
|
5
5
|
export const name = "opencode-workspace-env";
|
|
6
|
-
export const version = "0.1.
|
|
6
|
+
export const version = "0.1.1";
|
|
7
7
|
export const description = "OpenCode plugin for per-workspace env injection via shell.env hook";
|
|
8
8
|
const cache = new EnvCache();
|
|
9
9
|
const plugin = async (_input) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-workspace-env",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "OpenCode plugin for per-workspace env injection via shell.env hook",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"repository": "github:yimsk/opencode-workspace-env",
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@changesets/changelog-github": "^0.6.0",
|
|
35
|
+
"@changesets/cli": "^2.30.0",
|
|
34
36
|
"@nkzw/oxlint-config": "^1.0.1",
|
|
35
37
|
"@types/bun": "latest",
|
|
36
38
|
"@types/node": "^24.5.2",
|