opencode2-direnv 2026.907.1 → 2026.908.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 +36 -2
- package/dist/index.d.ts +54 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +171 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +180 -11
package/README.md
CHANGED
|
@@ -72,7 +72,39 @@ direnv: .envrc is blocked. Run `direnv allow` to enable.
|
|
|
72
72
|
|
|
73
73
|
### Local development
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
To dogfood this repository's working tree instead of the published package
|
|
76
|
+
(this repo's own setup), disable the published plugin and load a local dev
|
|
77
|
+
instance with a **distinct plugin id**:
|
|
78
|
+
|
|
79
|
+
```jsonc
|
|
80
|
+
// opencode.json (project)
|
|
81
|
+
{
|
|
82
|
+
"plugins": ["-opencode2-direnv"]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// .opencode/plugins/dev/index.ts — auto-discovered, not published
|
|
88
|
+
const plugin = (await import(`../../../src/index.js?dev=${Date.now()}`)).default
|
|
89
|
+
|
|
90
|
+
export default { ...plugin, id: "opencode2-direnv-dev" }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Three details matter:
|
|
94
|
+
|
|
95
|
+
- **Distinct id** — without it the local instance's own `opencode2-direnv` id
|
|
96
|
+
re-enables the disabled package ("a later id re-enables a disabled plugin")
|
|
97
|
+
and then fails with `Duplicate plugin ID`.
|
|
98
|
+
- **Cache-busted dynamic import** — OpenCode cache-busts only the entrypoint
|
|
99
|
+
file (`index.ts?mtime=…`); a static import of `src/index.js` is served from
|
|
100
|
+
the module cache for the server's lifetime, so `src/` edits would silently
|
|
101
|
+
run stale code until a service restart. The per-evaluation query makes every
|
|
102
|
+
wrapper reload import the current working tree.
|
|
103
|
+
- **`.opencode/plugins/`** — configured path entries must be *directories* on
|
|
104
|
+
current betas; direct files load only from `.opencode/plugins/`.
|
|
105
|
+
|
|
106
|
+
In other projects (without a globally installed copy), a plain directory entry
|
|
107
|
+
also works and needs no disable or distinct id:
|
|
76
108
|
|
|
77
109
|
```json
|
|
78
110
|
{
|
|
@@ -80,11 +112,13 @@ Local plugins load from a directory containing an `index.ts` entrypoint:
|
|
|
80
112
|
}
|
|
81
113
|
```
|
|
82
114
|
|
|
83
|
-
The root `index.ts` re-exports `src/index.ts
|
|
115
|
+
The root `index.ts` re-exports `src/index.ts`; with the plain entry, edits are
|
|
116
|
+
picked up on restart. Typecheck, test, and build with:
|
|
84
117
|
|
|
85
118
|
```bash
|
|
86
119
|
npm ci
|
|
87
120
|
npx tsc --noEmit
|
|
121
|
+
npm test
|
|
88
122
|
npm run build
|
|
89
123
|
```
|
|
90
124
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,32 @@ export declare const sanePath: () => string;
|
|
|
6
6
|
export declare const direnvCandidates: () => string[];
|
|
7
7
|
/** Strip known poison from process.env; returns the removed keys. */
|
|
8
8
|
export declare const stripPoison: () => string[];
|
|
9
|
+
/**
|
|
10
|
+
* The environment `direnv export json` is invoked with.
|
|
11
|
+
*
|
|
12
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
13
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
14
|
+
* previously applied:
|
|
15
|
+
*
|
|
16
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
17
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
18
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
19
|
+
* `-N`) on every no-op reload.
|
|
20
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
21
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
22
|
+
* exporting a PATH with no system/profile entries at all.
|
|
23
|
+
*
|
|
24
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
25
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
26
|
+
* entering the project directory.
|
|
27
|
+
*/
|
|
9
28
|
/**
|
|
10
29
|
* Filter a `direnv export json` payload down to variables that are safe to
|
|
11
|
-
* apply: valid POSIX names only (drops phantom entries like `export PATH`)
|
|
12
|
-
*
|
|
30
|
+
* apply: valid POSIX names only (drops phantom entries like `export PATH`),
|
|
31
|
+
* no script-valued vars (drops nix's `shellHook` and friends), and no direnv
|
|
32
|
+
* bookkeeping vars (`DIRENV_DIFF`, `DIRENV_WATCHES`, … churn on every
|
|
33
|
+
* evaluation and exist for the wrapping shell's eval, not for consumers —
|
|
34
|
+
* applying them makes reloads oscillate and pollutes spawned shells).
|
|
13
35
|
*/
|
|
14
36
|
export declare const filterVars: (vars: Record<string, string | null | undefined>) => Record<string, string>;
|
|
15
37
|
/**
|
|
@@ -18,6 +40,36 @@ export declare const filterVars: (vars: Record<string, string | null | undefined
|
|
|
18
40
|
* every other subprocess this plugin could help) unlaunchable.
|
|
19
41
|
*/
|
|
20
42
|
export declare const repairPath: () => string;
|
|
43
|
+
/**
|
|
44
|
+
* The PATH used in the direnv baseline. Deliberately does NOT read
|
|
45
|
+
* process.env.PATH or HOST_PATH: the plugin applies the devshell PATH (and
|
|
46
|
+
* the devshell exports HOST_PATH) into process.env, so reading either back
|
|
47
|
+
* would feed the plugin's own output into the next baseline and oscillate.
|
|
48
|
+
* Built from stable per-machine locations only, so the export stays a pure
|
|
49
|
+
* function of the devshell. Custom interactive-shell PATH entries are not
|
|
50
|
+
* part of it by design; the devshell's own paths are prepended by the export.
|
|
51
|
+
*/
|
|
52
|
+
export declare const baselinePath: () => string;
|
|
53
|
+
/**
|
|
54
|
+
* The environment `direnv export json` is invoked with.
|
|
55
|
+
*
|
|
56
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
57
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
58
|
+
* previously applied:
|
|
59
|
+
*
|
|
60
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
61
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
62
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
63
|
+
* `-N`) on every no-op reload.
|
|
64
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
65
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
66
|
+
* exporting a PATH with no system/profile entries at all.
|
|
67
|
+
*
|
|
68
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
69
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
70
|
+
* entering the project directory.
|
|
71
|
+
*/
|
|
72
|
+
export declare const exportBaseline: () => NodeJS.ProcessEnv;
|
|
21
73
|
/**
|
|
22
74
|
* Return the first direnv candidate that responds to `direnv version`, or
|
|
23
75
|
* null. Pure w.r.t. module state so it stays testable.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAwF5C,0DAA0D;AAC1D,eAAO,MAAM,QAAQ,cAapB,CAAA;AAED;+DAC+D;AAC/D,eAAO,MAAM,gBAAgB,gBASR,CAAA;AAErB,qEAAqE;AACrE,eAAO,MAAM,WAAW,QAAO,MAAM,EASpC,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CASjG,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAO,MAO7B,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,QAAO,MAY/B,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,QAAO,MAAM,CAAC,UAiBxC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,MAAM,EAAE,EACpB,OAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAyD,KAC/G,OAAO,CAAC,MAAM,GAAG,IAAI,CAUvB,CAAA;AAUD,8EAA8E;AAC9E,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAW5E,CAAA;;AAgCD,wBAkVE"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,11 @@ import { promisify } from "node:util";
|
|
|
14
14
|
* - On plugin setup: load env once (awaited, so the first command is ready)
|
|
15
15
|
* - On session.created: re-sync per new session (e.g. after `direnv allow`)
|
|
16
16
|
* - On filesystem.changed for .envrc/flake.nix/flake.lock: debounced reload
|
|
17
|
+
* (NOTE: as of server beta-19151 the server declares but never emits
|
|
18
|
+
* filesystem.changed, so this trigger is dormant; use the direnv_reload
|
|
19
|
+
* tool until an fs watcher or server-side emission exists)
|
|
20
|
+
* - Exposes a `direnv_reload` tool so the agent can force a re-sync manually
|
|
21
|
+
* (e.g. after the user edits the flake in their own editor/terminal)
|
|
17
22
|
* - Injects the latest direnv export into every spawned shell via the
|
|
18
23
|
* `shell.create.before` hook (primary mechanism)
|
|
19
24
|
* - Reconciles process.env as a fallback for other subprocesses (LSP, MCP) and
|
|
@@ -82,10 +87,32 @@ export const stripPoison = () => {
|
|
|
82
87
|
}
|
|
83
88
|
return removed;
|
|
84
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* The environment `direnv export json` is invoked with.
|
|
92
|
+
*
|
|
93
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
94
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
95
|
+
* previously applied:
|
|
96
|
+
*
|
|
97
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
98
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
99
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
100
|
+
* `-N`) on every no-op reload.
|
|
101
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
102
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
103
|
+
* exporting a PATH with no system/profile entries at all.
|
|
104
|
+
*
|
|
105
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
106
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
107
|
+
* entering the project directory.
|
|
108
|
+
*/
|
|
85
109
|
/**
|
|
86
110
|
* Filter a `direnv export json` payload down to variables that are safe to
|
|
87
|
-
* apply: valid POSIX names only (drops phantom entries like `export PATH`)
|
|
88
|
-
*
|
|
111
|
+
* apply: valid POSIX names only (drops phantom entries like `export PATH`),
|
|
112
|
+
* no script-valued vars (drops nix's `shellHook` and friends), and no direnv
|
|
113
|
+
* bookkeeping vars (`DIRENV_DIFF`, `DIRENV_WATCHES`, … churn on every
|
|
114
|
+
* evaluation and exist for the wrapping shell's eval, not for consumers —
|
|
115
|
+
* applying them makes reloads oscillate and pollutes spawned shells).
|
|
89
116
|
*/
|
|
90
117
|
export const filterVars = (vars) => {
|
|
91
118
|
const safe = {};
|
|
@@ -94,6 +121,8 @@ export const filterVars = (vars) => {
|
|
|
94
121
|
continue;
|
|
95
122
|
if (!VALID_NAME.test(key) || SCRIPT_VARS.has(key))
|
|
96
123
|
continue;
|
|
124
|
+
if (key.startsWith("DIRENV_"))
|
|
125
|
+
continue;
|
|
97
126
|
safe[key] = value;
|
|
98
127
|
}
|
|
99
128
|
return safe;
|
|
@@ -112,6 +141,62 @@ export const repairPath = () => {
|
|
|
112
141
|
console.warn(`direnv: repaired corrupted PATH (was ${JSON.stringify(current)})`);
|
|
113
142
|
return fallback;
|
|
114
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* The PATH used in the direnv baseline. Deliberately does NOT read
|
|
146
|
+
* process.env.PATH or HOST_PATH: the plugin applies the devshell PATH (and
|
|
147
|
+
* the devshell exports HOST_PATH) into process.env, so reading either back
|
|
148
|
+
* would feed the plugin's own output into the next baseline and oscillate.
|
|
149
|
+
* Built from stable per-machine locations only, so the export stays a pure
|
|
150
|
+
* function of the devshell. Custom interactive-shell PATH entries are not
|
|
151
|
+
* part of it by design; the devshell's own paths are prepended by the export.
|
|
152
|
+
*/
|
|
153
|
+
export const baselinePath = () => {
|
|
154
|
+
const parts = [];
|
|
155
|
+
if (process.env.HOME)
|
|
156
|
+
parts.push(`${process.env.HOME}/.nix-profile/bin`);
|
|
157
|
+
if (process.env.USER)
|
|
158
|
+
parts.push(`/etc/profiles/per-user/${process.env.USER}/bin`);
|
|
159
|
+
parts.push("/nix/var/nix/profiles/default/bin", "/run/current-system/sw/bin", "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin:/bin:/usr/sbin:/sbin");
|
|
160
|
+
return parts.join(":");
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The environment `direnv export json` is invoked with.
|
|
164
|
+
*
|
|
165
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
166
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
167
|
+
* previously applied:
|
|
168
|
+
*
|
|
169
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
170
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
171
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
172
|
+
* `-N`) on every no-op reload.
|
|
173
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
174
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
175
|
+
* exporting a PATH with no system/profile entries at all.
|
|
176
|
+
*
|
|
177
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
178
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
179
|
+
* entering the project directory.
|
|
180
|
+
*/
|
|
181
|
+
export const exportBaseline = () => {
|
|
182
|
+
const wanted = [
|
|
183
|
+
"HOME",
|
|
184
|
+
"USER",
|
|
185
|
+
"TERM",
|
|
186
|
+
"TMPDIR",
|
|
187
|
+
"SHELL",
|
|
188
|
+
"LANG",
|
|
189
|
+
];
|
|
190
|
+
const baseline = {};
|
|
191
|
+
for (const key of wanted) {
|
|
192
|
+
const value = process.env[key];
|
|
193
|
+
if (value !== undefined)
|
|
194
|
+
baseline[key] = value;
|
|
195
|
+
}
|
|
196
|
+
// never derived from (possibly corrupted or plugin-applied) process.env.PATH
|
|
197
|
+
baseline.PATH = baselinePath();
|
|
198
|
+
return baseline;
|
|
199
|
+
};
|
|
115
200
|
/**
|
|
116
201
|
* Return the first direnv candidate that responds to `direnv version`, or
|
|
117
202
|
* null. Pure w.r.t. module state so it stays testable.
|
|
@@ -166,11 +251,12 @@ const sanitize = () => {
|
|
|
166
251
|
repairPath();
|
|
167
252
|
return stripped.length > 0 || process.env.PATH !== before;
|
|
168
253
|
};
|
|
169
|
-
const runText = async (file, args, cwd) => {
|
|
254
|
+
const runText = async (file, args, cwd, env) => {
|
|
170
255
|
const { stdout } = await run(file, args, {
|
|
171
256
|
cwd,
|
|
172
257
|
encoding: "utf8",
|
|
173
258
|
maxBuffer: 10 * 1024 * 1024,
|
|
259
|
+
...(env ? { env } : {}),
|
|
174
260
|
});
|
|
175
261
|
return stdout;
|
|
176
262
|
};
|
|
@@ -263,7 +349,9 @@ export default Plugin.define({
|
|
|
263
349
|
}
|
|
264
350
|
let jsonText;
|
|
265
351
|
try {
|
|
266
|
-
|
|
352
|
+
// See exportBaseline: a fixed baseline keeps the direnv diff stable
|
|
353
|
+
// (no oscillation) and the exported PATH well-formed.
|
|
354
|
+
jsonText = await runText(direnv, ["export", "json"], dir, exportBaseline());
|
|
267
355
|
}
|
|
268
356
|
catch (error) {
|
|
269
357
|
const stderr = error && typeof error === "object" && "stderr" in error
|
|
@@ -279,10 +367,14 @@ export default Plugin.define({
|
|
|
279
367
|
}
|
|
280
368
|
const parsed = jsonText.trim() ? JSON.parse(jsonText) : {};
|
|
281
369
|
const newVars = parsed && typeof parsed === "object" ? parsed : {};
|
|
282
|
-
|
|
283
|
-
//
|
|
370
|
+
const filteredVars = filterVars(newVars);
|
|
371
|
+
// 1. Remove vars we previously applied that the devshell no longer
|
|
372
|
+
// exports (or that are no longer safe to apply). Checked against
|
|
373
|
+
// the *filtered* set so previously-applied keys that filtering now
|
|
374
|
+
// drops (e.g. direnv bookkeeping) are cleaned from process.env.
|
|
375
|
+
// direnv's explicit `null` unset signals land here too.
|
|
284
376
|
for (const key of appliedKeys) {
|
|
285
|
-
const keep = key in
|
|
377
|
+
const keep = key in filteredVars;
|
|
286
378
|
if (!keep && key in process.env) {
|
|
287
379
|
delete process.env[key];
|
|
288
380
|
outcome.removed++;
|
|
@@ -293,7 +385,7 @@ export default Plugin.define({
|
|
|
293
385
|
// entry) and script-valued vars (e.g. nix's `shellHook`) — they
|
|
294
386
|
// corrupt subprocess environments instead of configuring them.
|
|
295
387
|
const nextApplied = new Set();
|
|
296
|
-
for (const [key, value] of Object.entries(
|
|
388
|
+
for (const [key, value] of Object.entries(filteredVars)) {
|
|
297
389
|
const current = process.env[key];
|
|
298
390
|
if (current === undefined)
|
|
299
391
|
outcome.added++;
|
|
@@ -305,7 +397,10 @@ export default Plugin.define({
|
|
|
305
397
|
appliedKeys.clear();
|
|
306
398
|
for (const key of nextApplied)
|
|
307
399
|
appliedKeys.add(key);
|
|
308
|
-
|
|
400
|
+
// Inject only the filtered set: the raw payload can carry null
|
|
401
|
+
// unset-signals, and the shell hook writes values verbatim into
|
|
402
|
+
// spawned shell environments (which must be strings).
|
|
403
|
+
currentVars = filterVars(newVars);
|
|
309
404
|
return outcome;
|
|
310
405
|
}
|
|
311
406
|
catch {
|
|
@@ -364,6 +459,31 @@ export default Plugin.define({
|
|
|
364
459
|
};
|
|
365
460
|
// Initial load: awaited so the first command of any session sees the env.
|
|
366
461
|
logOutcome(await reloadEnv(), { initial: true });
|
|
462
|
+
/**
|
|
463
|
+
* Human/agent-readable one-liner for a reload outcome, used by the
|
|
464
|
+
* direnv_reload tool result.
|
|
465
|
+
*/
|
|
466
|
+
const describeOutcome = (outcome) => {
|
|
467
|
+
if (outcome.blocked) {
|
|
468
|
+
return "direnv: .envrc is blocked. Run `direnv allow` and retry.";
|
|
469
|
+
}
|
|
470
|
+
if (outcome.unavailable) {
|
|
471
|
+
return "direnv: unavailable (direnv not installed or no .envrc found).";
|
|
472
|
+
}
|
|
473
|
+
if (outcome.error) {
|
|
474
|
+
return "direnv: `direnv export json` failed; see server logs for details.";
|
|
475
|
+
}
|
|
476
|
+
const parts = [];
|
|
477
|
+
if (outcome.added)
|
|
478
|
+
parts.push(`+${outcome.added}`);
|
|
479
|
+
if (outcome.changed)
|
|
480
|
+
parts.push(`~${outcome.changed}`);
|
|
481
|
+
if (outcome.removed)
|
|
482
|
+
parts.push(`-${outcome.removed}`);
|
|
483
|
+
return parts.length
|
|
484
|
+
? `direnv: reloaded (${parts.join(" ")}); new shells use the updated environment.`
|
|
485
|
+
: "direnv: reloaded, nothing changed.";
|
|
486
|
+
};
|
|
367
487
|
// Primary mechanism: inject the latest direnv export into every shell the
|
|
368
488
|
// server spawns for a working copy inside the devshell. The cached payload
|
|
369
489
|
// keeps the hook synchronous and non-blocking.
|
|
@@ -376,6 +496,39 @@ export default Plugin.define({
|
|
|
376
496
|
event.env[key] = value;
|
|
377
497
|
}
|
|
378
498
|
});
|
|
499
|
+
/**
|
|
500
|
+
* Agent-facing manual reload. The filesystem.changed event the background
|
|
501
|
+
* reload depends on is declared but not emitted by current OpenCode 2
|
|
502
|
+
* servers, so after the user edits .envrc/flake.nix in their own editor
|
|
503
|
+
* the environment would silently go stale. This tool lets the agent force
|
|
504
|
+
* a re-sync on demand (works regardless of server-side event support).
|
|
505
|
+
*/
|
|
506
|
+
const toolRegistration = await ctx.tool.transform((editor) => {
|
|
507
|
+
editor.namespace({
|
|
508
|
+
name: "direnv",
|
|
509
|
+
description: "Devshell (direnv) environment tools",
|
|
510
|
+
});
|
|
511
|
+
editor.add({
|
|
512
|
+
name: "reload",
|
|
513
|
+
description: "Re-export the direnv devshell and apply it to OpenCode, so subsequently spawned shells " +
|
|
514
|
+
"see the updated environment. Call this after .envrc, flake.nix, or flake.lock were changed " +
|
|
515
|
+
"outside OpenCode (user edited them mid-session), or when devshell-provided tools are missing " +
|
|
516
|
+
"from PATH / resolve to stale /nix/store paths.",
|
|
517
|
+
input: {
|
|
518
|
+
type: "object",
|
|
519
|
+
properties: {},
|
|
520
|
+
additionalProperties: false,
|
|
521
|
+
},
|
|
522
|
+
// without this the tool registers as a top-level `reload` instead of
|
|
523
|
+
// joining the `direnv` namespace registered above
|
|
524
|
+
options: { namespace: "direnv" },
|
|
525
|
+
execute: async () => {
|
|
526
|
+
const outcome = await reloadEnv();
|
|
527
|
+
logOutcome(outcome, { initial: false });
|
|
528
|
+
return { content: describeOutcome(outcome) };
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
});
|
|
379
532
|
const isRelevantLocation = (location) => !location?.directory || location.directory === directory;
|
|
380
533
|
// Event stream: per-session sync and devshell-file watch. Runs detached so
|
|
381
534
|
// plugin setup is never blocked; aborted on cleanup.
|
|
@@ -410,8 +563,14 @@ export default Plugin.define({
|
|
|
410
563
|
}
|
|
411
564
|
}
|
|
412
565
|
}
|
|
413
|
-
catch {
|
|
414
|
-
//
|
|
566
|
+
catch (error) {
|
|
567
|
+
// Abort is the normal cleanup path (controller aborted in teardown);
|
|
568
|
+
// anything else means we silently lost session.created/filesystem.changed
|
|
569
|
+
// triggers and the environment will go stale without anyone knowing.
|
|
570
|
+
if (controller.signal.aborted)
|
|
571
|
+
return;
|
|
572
|
+
const detail = error instanceof Error ? `${error.message}` : String(error);
|
|
573
|
+
console.warn(`direnv: event stream failed, devshell reload triggers are dead: ${detail}`);
|
|
415
574
|
}
|
|
416
575
|
})();
|
|
417
576
|
return () => {
|
|
@@ -419,6 +578,7 @@ export default Plugin.define({
|
|
|
419
578
|
if (reloadTimer)
|
|
420
579
|
clearTimeout(reloadTimer);
|
|
421
580
|
void shellRegistration.dispose();
|
|
581
|
+
void toolRegistration.dispose();
|
|
422
582
|
};
|
|
423
583
|
},
|
|
424
584
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AA2B/B,gEAAgE;AAChE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAA;AAErE,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAE/B,qEAAqE;AACrE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAA;AAE7F,0DAA0D;AAC1D,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,aAAa,CAAC,CAAA;AAEhE,6CAA6C;AAC7C,MAAM,UAAU,GAAG,0BAA0B,CAAA;AAE7C,0DAA0D;A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 import { promisify } from "node:util"
|
|
|
15
15
|
* - On plugin setup: load env once (awaited, so the first command is ready)
|
|
16
16
|
* - On session.created: re-sync per new session (e.g. after `direnv allow`)
|
|
17
17
|
* - On filesystem.changed for .envrc/flake.nix/flake.lock: debounced reload
|
|
18
|
+
* (NOTE: as of server beta-19151 the server declares but never emits
|
|
19
|
+
* filesystem.changed, so this trigger is dormant; use the direnv_reload
|
|
20
|
+
* tool until an fs watcher or server-side emission exists)
|
|
21
|
+
* - Exposes a `direnv_reload` tool so the agent can force a re-sync manually
|
|
22
|
+
* (e.g. after the user edits the flake in their own editor/terminal)
|
|
18
23
|
* - Injects the latest direnv export into every spawned shell via the
|
|
19
24
|
* `shell.create.before` hook (primary mechanism)
|
|
20
25
|
* - Reconciles process.env as a fallback for other subprocesses (LSP, MCP) and
|
|
@@ -122,16 +127,39 @@ export const stripPoison = (): string[] => {
|
|
|
122
127
|
return removed
|
|
123
128
|
}
|
|
124
129
|
|
|
130
|
+
/**
|
|
131
|
+
* The environment `direnv export json` is invoked with.
|
|
132
|
+
*
|
|
133
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
134
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
135
|
+
* previously applied:
|
|
136
|
+
*
|
|
137
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
138
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
139
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
140
|
+
* `-N`) on every no-op reload.
|
|
141
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
142
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
143
|
+
* exporting a PATH with no system/profile entries at all.
|
|
144
|
+
*
|
|
145
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
146
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
147
|
+
* entering the project directory.
|
|
148
|
+
*/
|
|
125
149
|
/**
|
|
126
150
|
* Filter a `direnv export json` payload down to variables that are safe to
|
|
127
|
-
* apply: valid POSIX names only (drops phantom entries like `export PATH`)
|
|
128
|
-
*
|
|
151
|
+
* apply: valid POSIX names only (drops phantom entries like `export PATH`),
|
|
152
|
+
* no script-valued vars (drops nix's `shellHook` and friends), and no direnv
|
|
153
|
+
* bookkeeping vars (`DIRENV_DIFF`, `DIRENV_WATCHES`, … churn on every
|
|
154
|
+
* evaluation and exist for the wrapping shell's eval, not for consumers —
|
|
155
|
+
* applying them makes reloads oscillate and pollutes spawned shells).
|
|
129
156
|
*/
|
|
130
157
|
export const filterVars = (vars: Record<string, string | null | undefined>): Record<string, string> => {
|
|
131
158
|
const safe: Record<string, string> = {}
|
|
132
159
|
for (const [key, value] of Object.entries(vars)) {
|
|
133
160
|
if (value == null) continue
|
|
134
161
|
if (!VALID_NAME.test(key) || SCRIPT_VARS.has(key)) continue
|
|
162
|
+
if (key.startsWith("DIRENV_")) continue
|
|
135
163
|
safe[key] = value
|
|
136
164
|
}
|
|
137
165
|
return safe
|
|
@@ -151,6 +179,67 @@ export const repairPath = (): string => {
|
|
|
151
179
|
return fallback
|
|
152
180
|
}
|
|
153
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The PATH used in the direnv baseline. Deliberately does NOT read
|
|
184
|
+
* process.env.PATH or HOST_PATH: the plugin applies the devshell PATH (and
|
|
185
|
+
* the devshell exports HOST_PATH) into process.env, so reading either back
|
|
186
|
+
* would feed the plugin's own output into the next baseline and oscillate.
|
|
187
|
+
* Built from stable per-machine locations only, so the export stays a pure
|
|
188
|
+
* function of the devshell. Custom interactive-shell PATH entries are not
|
|
189
|
+
* part of it by design; the devshell's own paths are prepended by the export.
|
|
190
|
+
*/
|
|
191
|
+
export const baselinePath = (): string => {
|
|
192
|
+
const parts: string[] = []
|
|
193
|
+
if (process.env.HOME) parts.push(`${process.env.HOME}/.nix-profile/bin`)
|
|
194
|
+
if (process.env.USER) parts.push(`/etc/profiles/per-user/${process.env.USER}/bin`)
|
|
195
|
+
parts.push(
|
|
196
|
+
"/nix/var/nix/profiles/default/bin",
|
|
197
|
+
"/run/current-system/sw/bin",
|
|
198
|
+
"/opt/homebrew/bin",
|
|
199
|
+
"/usr/local/bin",
|
|
200
|
+
"/usr/bin:/bin:/usr/sbin:/sbin",
|
|
201
|
+
)
|
|
202
|
+
return parts.join(":")
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The environment `direnv export json` is invoked with.
|
|
207
|
+
*
|
|
208
|
+
* direnv computes its export as a *diff against the invoking environment*, so
|
|
209
|
+
* the invoking environment must be STABLE and independent of what this plugin
|
|
210
|
+
* previously applied:
|
|
211
|
+
*
|
|
212
|
+
* - Invoking direnv with vars we applied on an earlier reload makes direnv
|
|
213
|
+
* omit them from the export; the plugin would read that as "dropped",
|
|
214
|
+
* delete them, and the next export would re-add them — oscillating (`+N` /
|
|
215
|
+
* `-N`) on every no-op reload.
|
|
216
|
+
* - Conversely, stripping applied vars from the real environment is wrong
|
|
217
|
+
* too: removing `PATH` makes the devshell evaluate against an empty PATH,
|
|
218
|
+
* exporting a PATH with no system/profile entries at all.
|
|
219
|
+
*
|
|
220
|
+
* So direnv always runs against this fixed, minimal baseline — the export
|
|
221
|
+
* becomes a pure function of the devshell itself, like a fresh login shell
|
|
222
|
+
* entering the project directory.
|
|
223
|
+
*/
|
|
224
|
+
export const exportBaseline = (): NodeJS.ProcessEnv => {
|
|
225
|
+
const wanted: Array<keyof NodeJS.ProcessEnv> = [
|
|
226
|
+
"HOME",
|
|
227
|
+
"USER",
|
|
228
|
+
"TERM",
|
|
229
|
+
"TMPDIR",
|
|
230
|
+
"SHELL",
|
|
231
|
+
"LANG",
|
|
232
|
+
]
|
|
233
|
+
const baseline: NodeJS.ProcessEnv = {}
|
|
234
|
+
for (const key of wanted) {
|
|
235
|
+
const value = process.env[key]
|
|
236
|
+
if (value !== undefined) baseline[key] = value
|
|
237
|
+
}
|
|
238
|
+
// never derived from (possibly corrupted or plugin-applied) process.env.PATH
|
|
239
|
+
baseline.PATH = baselinePath()
|
|
240
|
+
return baseline
|
|
241
|
+
}
|
|
242
|
+
|
|
154
243
|
/**
|
|
155
244
|
* Return the first direnv candidate that responds to `direnv version`, or
|
|
156
245
|
* null. Pure w.r.t. module state so it stays testable.
|
|
@@ -207,11 +296,17 @@ const sanitize = (): boolean => {
|
|
|
207
296
|
return stripped.length > 0 || process.env.PATH !== before
|
|
208
297
|
}
|
|
209
298
|
|
|
210
|
-
const runText = async (
|
|
299
|
+
const runText = async (
|
|
300
|
+
file: string,
|
|
301
|
+
args: string[],
|
|
302
|
+
cwd: string,
|
|
303
|
+
env?: NodeJS.ProcessEnv,
|
|
304
|
+
) => {
|
|
211
305
|
const { stdout } = await run(file, args, {
|
|
212
306
|
cwd,
|
|
213
307
|
encoding: "utf8",
|
|
214
308
|
maxBuffer: 10 * 1024 * 1024,
|
|
309
|
+
...(env ? { env } : {}),
|
|
215
310
|
})
|
|
216
311
|
return stdout
|
|
217
312
|
}
|
|
@@ -321,7 +416,9 @@ export default Plugin.define({
|
|
|
321
416
|
|
|
322
417
|
let jsonText: string
|
|
323
418
|
try {
|
|
324
|
-
|
|
419
|
+
// See exportBaseline: a fixed baseline keeps the direnv diff stable
|
|
420
|
+
// (no oscillation) and the exported PATH well-formed.
|
|
421
|
+
jsonText = await runText(direnv, ["export", "json"], dir, exportBaseline())
|
|
325
422
|
} catch (error: unknown) {
|
|
326
423
|
const stderr =
|
|
327
424
|
error && typeof error === "object" && "stderr" in error
|
|
@@ -339,10 +436,15 @@ export default Plugin.define({
|
|
|
339
436
|
const newVars: Record<string, string> =
|
|
340
437
|
parsed && typeof parsed === "object" ? parsed : {}
|
|
341
438
|
|
|
342
|
-
|
|
343
|
-
|
|
439
|
+
const filteredVars = filterVars(newVars)
|
|
440
|
+
|
|
441
|
+
// 1. Remove vars we previously applied that the devshell no longer
|
|
442
|
+
// exports (or that are no longer safe to apply). Checked against
|
|
443
|
+
// the *filtered* set so previously-applied keys that filtering now
|
|
444
|
+
// drops (e.g. direnv bookkeeping) are cleaned from process.env.
|
|
445
|
+
// direnv's explicit `null` unset signals land here too.
|
|
344
446
|
for (const key of appliedKeys) {
|
|
345
|
-
const keep = key in
|
|
447
|
+
const keep = key in filteredVars
|
|
346
448
|
if (!keep && key in process.env) {
|
|
347
449
|
delete process.env[key]
|
|
348
450
|
outcome.removed++
|
|
@@ -354,7 +456,7 @@ export default Plugin.define({
|
|
|
354
456
|
// entry) and script-valued vars (e.g. nix's `shellHook`) — they
|
|
355
457
|
// corrupt subprocess environments instead of configuring them.
|
|
356
458
|
const nextApplied = new Set<string>()
|
|
357
|
-
for (const [key, value] of Object.entries(
|
|
459
|
+
for (const [key, value] of Object.entries(filteredVars)) {
|
|
358
460
|
const current = process.env[key]
|
|
359
461
|
if (current === undefined) outcome.added++
|
|
360
462
|
else if (current !== value) outcome.changed++
|
|
@@ -364,7 +466,10 @@ export default Plugin.define({
|
|
|
364
466
|
|
|
365
467
|
appliedKeys.clear()
|
|
366
468
|
for (const key of nextApplied) appliedKeys.add(key)
|
|
367
|
-
|
|
469
|
+
// Inject only the filtered set: the raw payload can carry null
|
|
470
|
+
// unset-signals, and the shell hook writes values verbatim into
|
|
471
|
+
// spawned shell environments (which must be strings).
|
|
472
|
+
currentVars = filterVars(newVars)
|
|
368
473
|
|
|
369
474
|
return outcome
|
|
370
475
|
} catch {
|
|
@@ -424,6 +529,29 @@ export default Plugin.define({
|
|
|
424
529
|
// Initial load: awaited so the first command of any session sees the env.
|
|
425
530
|
logOutcome(await reloadEnv(), { initial: true })
|
|
426
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Human/agent-readable one-liner for a reload outcome, used by the
|
|
534
|
+
* direnv_reload tool result.
|
|
535
|
+
*/
|
|
536
|
+
const describeOutcome = (outcome: ReloadOutcome): string => {
|
|
537
|
+
if (outcome.blocked) {
|
|
538
|
+
return "direnv: .envrc is blocked. Run `direnv allow` and retry."
|
|
539
|
+
}
|
|
540
|
+
if (outcome.unavailable) {
|
|
541
|
+
return "direnv: unavailable (direnv not installed or no .envrc found)."
|
|
542
|
+
}
|
|
543
|
+
if (outcome.error) {
|
|
544
|
+
return "direnv: `direnv export json` failed; see server logs for details."
|
|
545
|
+
}
|
|
546
|
+
const parts: string[] = []
|
|
547
|
+
if (outcome.added) parts.push(`+${outcome.added}`)
|
|
548
|
+
if (outcome.changed) parts.push(`~${outcome.changed}`)
|
|
549
|
+
if (outcome.removed) parts.push(`-${outcome.removed}`)
|
|
550
|
+
return parts.length
|
|
551
|
+
? `direnv: reloaded (${parts.join(" ")}); new shells use the updated environment.`
|
|
552
|
+
: "direnv: reloaded, nothing changed."
|
|
553
|
+
}
|
|
554
|
+
|
|
427
555
|
// Primary mechanism: inject the latest direnv export into every shell the
|
|
428
556
|
// server spawns for a working copy inside the devshell. The cached payload
|
|
429
557
|
// keeps the hook synchronous and non-blocking.
|
|
@@ -435,6 +563,41 @@ export default Plugin.define({
|
|
|
435
563
|
}
|
|
436
564
|
})
|
|
437
565
|
|
|
566
|
+
/**
|
|
567
|
+
* Agent-facing manual reload. The filesystem.changed event the background
|
|
568
|
+
* reload depends on is declared but not emitted by current OpenCode 2
|
|
569
|
+
* servers, so after the user edits .envrc/flake.nix in their own editor
|
|
570
|
+
* the environment would silently go stale. This tool lets the agent force
|
|
571
|
+
* a re-sync on demand (works regardless of server-side event support).
|
|
572
|
+
*/
|
|
573
|
+
const toolRegistration = await ctx.tool.transform((editor) => {
|
|
574
|
+
editor.namespace({
|
|
575
|
+
name: "direnv",
|
|
576
|
+
description: "Devshell (direnv) environment tools",
|
|
577
|
+
})
|
|
578
|
+
editor.add({
|
|
579
|
+
name: "reload",
|
|
580
|
+
description:
|
|
581
|
+
"Re-export the direnv devshell and apply it to OpenCode, so subsequently spawned shells " +
|
|
582
|
+
"see the updated environment. Call this after .envrc, flake.nix, or flake.lock were changed " +
|
|
583
|
+
"outside OpenCode (user edited them mid-session), or when devshell-provided tools are missing " +
|
|
584
|
+
"from PATH / resolve to stale /nix/store paths.",
|
|
585
|
+
input: {
|
|
586
|
+
type: "object",
|
|
587
|
+
properties: {},
|
|
588
|
+
additionalProperties: false,
|
|
589
|
+
},
|
|
590
|
+
// without this the tool registers as a top-level `reload` instead of
|
|
591
|
+
// joining the `direnv` namespace registered above
|
|
592
|
+
options: { namespace: "direnv" },
|
|
593
|
+
execute: async () => {
|
|
594
|
+
const outcome = await reloadEnv()
|
|
595
|
+
logOutcome(outcome, { initial: false })
|
|
596
|
+
return { content: describeOutcome(outcome) }
|
|
597
|
+
},
|
|
598
|
+
})
|
|
599
|
+
})
|
|
600
|
+
|
|
438
601
|
const isRelevantLocation = (location: EncodedEvent["location"]) =>
|
|
439
602
|
!location?.directory || location.directory === directory
|
|
440
603
|
|
|
@@ -469,8 +632,13 @@ export default Plugin.define({
|
|
|
469
632
|
}
|
|
470
633
|
}
|
|
471
634
|
}
|
|
472
|
-
} catch {
|
|
473
|
-
//
|
|
635
|
+
} catch (error) {
|
|
636
|
+
// Abort is the normal cleanup path (controller aborted in teardown);
|
|
637
|
+
// anything else means we silently lost session.created/filesystem.changed
|
|
638
|
+
// triggers and the environment will go stale without anyone knowing.
|
|
639
|
+
if (controller.signal.aborted) return
|
|
640
|
+
const detail = error instanceof Error ? `${error.message}` : String(error)
|
|
641
|
+
console.warn(`direnv: event stream failed, devshell reload triggers are dead: ${detail}`)
|
|
474
642
|
}
|
|
475
643
|
})()
|
|
476
644
|
|
|
@@ -478,6 +646,7 @@ export default Plugin.define({
|
|
|
478
646
|
controller.abort()
|
|
479
647
|
if (reloadTimer) clearTimeout(reloadTimer)
|
|
480
648
|
void shellRegistration.dispose()
|
|
649
|
+
void toolRegistration.dispose()
|
|
481
650
|
}
|
|
482
651
|
},
|
|
483
652
|
})
|