@neuralnomads/codenomad-dev 0.20.0-dev-20260922-0a31a8b3 → 0.20.0-dev-20260924-70aae0b1

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 (155) hide show
  1. package/README.md +1 -0
  2. package/dist/api-types.js.map +1 -1
  3. package/dist/opencode/runtime-support.js +1 -1
  4. package/dist/opencode/runtime-support.js.map +1 -1
  5. package/dist/opencode/runtime-support.test.js +2 -2
  6. package/dist/opencode/runtime-support.test.js.map +1 -1
  7. package/dist/opencode-update/installation-lock.js +43 -0
  8. package/dist/opencode-update/installation-lock.js.map +1 -0
  9. package/dist/opencode-update/npm-runtime.js +22 -0
  10. package/dist/opencode-update/npm-runtime.js.map +1 -0
  11. package/dist/opencode-update/retired-installation.js +41 -0
  12. package/dist/opencode-update/retired-installation.js.map +1 -0
  13. package/dist/opencode-update/retired-installation.test.js +39 -0
  14. package/dist/opencode-update/retired-installation.test.js.map +1 -0
  15. package/dist/opencode-update/service.js +18 -10
  16. package/dist/opencode-update/service.js.map +1 -1
  17. package/dist/opencode-update/service.test.js +29 -7
  18. package/dist/opencode-update/service.test.js.map +1 -1
  19. package/dist/opencode-update/shared-installation.js +189 -0
  20. package/dist/opencode-update/shared-installation.js.map +1 -0
  21. package/dist/opencode-update/shared-installation.test.js +270 -0
  22. package/dist/opencode-update/shared-installation.test.js.map +1 -0
  23. package/dist/opencode-update/user-path.js +85 -0
  24. package/dist/opencode-update/user-path.js.map +1 -0
  25. package/dist/plugins/session-pruning/plugin.mjs +15 -3
  26. package/dist/server/__tests__/session-environment.test.js +21 -1
  27. package/dist/server/__tests__/session-environment.test.js.map +1 -1
  28. package/dist/server/http-server.js +52 -16
  29. package/dist/server/http-server.js.map +1 -1
  30. package/dist/server/routes/opencode-update.js +3 -0
  31. package/dist/server/routes/opencode-update.js.map +1 -1
  32. package/dist/server/routes/opencode-update.test.js +18 -0
  33. package/dist/server/routes/opencode-update.test.js.map +1 -1
  34. package/dist/server/routes/settings.js +2 -1
  35. package/dist/server/routes/settings.js.map +1 -1
  36. package/dist/server/routes/workspaces.js +5 -2
  37. package/dist/server/routes/workspaces.js.map +1 -1
  38. package/dist/server/routes/worktrees.js +3 -0
  39. package/dist/server/routes/worktrees.js.map +1 -1
  40. package/dist/settings/binaries.js +9 -5
  41. package/dist/settings/binaries.js.map +1 -1
  42. package/dist/settings/binaries.test.js +2 -2
  43. package/dist/settings/binaries.test.js.map +1 -1
  44. package/dist/workspaces/git-requirement.js +34 -0
  45. package/dist/workspaces/git-requirement.js.map +1 -0
  46. package/dist/workspaces/git-requirement.test.js +139 -0
  47. package/dist/workspaces/git-requirement.test.js.map +1 -0
  48. package/dist/workspaces/git-worktrees.js +2 -1
  49. package/dist/workspaces/git-worktrees.js.map +1 -1
  50. package/dist/workspaces/manager.js +15 -2
  51. package/dist/workspaces/manager.js.map +1 -1
  52. package/dist/workspaces/native-worktrees.js +12 -1
  53. package/dist/workspaces/native-worktrees.js.map +1 -1
  54. package/dist/workspaces/session-git-context.js +41 -0
  55. package/dist/workspaces/session-git-context.js.map +1 -0
  56. package/dist/workspaces/spawn.js +7 -2
  57. package/dist/workspaces/spawn.js.map +1 -1
  58. package/dist/workspaces/worktree-directory.js +2 -1
  59. package/dist/workspaces/worktree-directory.js.map +1 -1
  60. package/dist/workspaces/worktree-session-evacuation.js +11 -3
  61. package/dist/workspaces/worktree-session-evacuation.js.map +1 -1
  62. package/dist/workspaces/worktree-session-evacuation.test.js +18 -0
  63. package/dist/workspaces/worktree-session-evacuation.test.js.map +1 -1
  64. package/package.json +3 -3
  65. package/public/assets/{App-CkXPZUpS.js → App-DXfroBn-.js} +25 -25
  66. package/public/assets/App-DXfroBn-.js.map +1 -0
  67. package/public/assets/{FilesTab-C4o3_OHJ.js → FilesTab-JN0c2Op2.js} +2 -2
  68. package/public/assets/{FilesTab-C4o3_OHJ.js.map → FilesTab-JN0c2Op2.js.map} +1 -1
  69. package/public/assets/{GitChangesTab-ClsL5QrZ.js → GitChangesTab-8MxRVYHz.js} +2 -2
  70. package/public/assets/{GitChangesTab-ClsL5QrZ.js.map → GitChangesTab-8MxRVYHz.js.map} +1 -1
  71. package/public/assets/{SplitFilePanel-C_dI-kjb.js → SplitFilePanel-VXkE7jgT.js} +2 -2
  72. package/public/assets/{SplitFilePanel-C_dI-kjb.js.map → SplitFilePanel-VXkE7jgT.js.map} +1 -1
  73. package/public/assets/{StatusTab-_gvxV-qq.js → StatusTab-DljyzM07.js} +2 -2
  74. package/public/assets/{StatusTab-_gvxV-qq.js.map → StatusTab-DljyzM07.js.map} +1 -1
  75. package/public/assets/{align-justify-CboH-c3n.js → align-justify-BMi4r2XK.js} +2 -2
  76. package/public/assets/{align-justify-CboH-c3n.js.map → align-justify-BMi4r2XK.js.map} +1 -1
  77. package/public/assets/{bundle-full-CL2fEEcE.js → bundle-full-LgLNZmib.js} +2 -2
  78. package/public/assets/{bundle-full-CL2fEEcE.js.map → bundle-full-LgLNZmib.js.map} +1 -1
  79. package/public/assets/{client-state-BB0go4Xe.js → client-state-DTQzqBPJ.js} +2 -2
  80. package/public/assets/{client-state-BB0go4Xe.js.map → client-state-DTQzqBPJ.js.map} +1 -1
  81. package/public/assets/{diff-viewer-C-B3vwne.js → diff-viewer-Dxjea-rB.js} +2 -2
  82. package/public/assets/{diff-viewer-C-B3vwne.js.map → diff-viewer-Dxjea-rB.js.map} +1 -1
  83. package/public/assets/index-9bba6B1A.js +2 -0
  84. package/public/assets/index-9bba6B1A.js.map +1 -0
  85. package/public/assets/index-C5i7ut9u.js +2 -0
  86. package/public/assets/index-C5i7ut9u.js.map +1 -0
  87. package/public/assets/index-CLtLzsWy.js +2 -0
  88. package/public/assets/index-CLtLzsWy.js.map +1 -0
  89. package/public/assets/index-CTVIWXHZ.js +2 -0
  90. package/public/assets/index-CTVIWXHZ.js.map +1 -0
  91. package/public/assets/{index-DrTKEExa.js → index-Cgp1TEtC.js} +2 -2
  92. package/public/assets/{index-DrTKEExa.js.map → index-Cgp1TEtC.js.map} +1 -1
  93. package/public/assets/index-Cqd_P8c4.js +2 -0
  94. package/public/assets/index-Cqd_P8c4.js.map +1 -0
  95. package/public/assets/{index-CheaKG9m.js → index-DTGOXoDH.js} +2 -2
  96. package/public/assets/{index-CheaKG9m.js.map → index-DTGOXoDH.js.map} +1 -1
  97. package/public/assets/index-D_H_gYdX.js +2 -0
  98. package/public/assets/index-D_H_gYdX.js.map +1 -0
  99. package/public/assets/index-Dsd7n295.js +2 -0
  100. package/public/assets/index-Dsd7n295.js.map +1 -0
  101. package/public/assets/index-DwKq8v48.js +3 -0
  102. package/public/assets/index-DwKq8v48.js.map +1 -0
  103. package/public/assets/index-TnTncRlr.js +2 -0
  104. package/public/assets/index-TnTncRlr.js.map +1 -0
  105. package/public/assets/index-eb2qu-xk.js +2 -0
  106. package/public/assets/index-eb2qu-xk.js.map +1 -0
  107. package/public/assets/{loading-Cs2CSqHx.js → loading-j5J_ghLL.js} +2 -2
  108. package/public/assets/{loading-Cs2CSqHx.js.map → loading-j5J_ghLL.js.map} +1 -1
  109. package/public/assets/main-Cv7E0c7r.js +42 -0
  110. package/public/assets/main-Cv7E0c7r.js.map +1 -0
  111. package/public/assets/{markdown-DheZTu4V.js → markdown-Cg65SCwC.js} +4 -4
  112. package/public/assets/{markdown-DheZTu4V.js.map → markdown-Cg65SCwC.js.map} +1 -1
  113. package/public/assets/{startup-state-settings-card-CmMXcnR-.js → startup-state-settings-card-DMFtdRoa.js} +2 -2
  114. package/public/assets/{startup-state-settings-card-CmMXcnR-.js.map → startup-state-settings-card-DMFtdRoa.js.map} +1 -1
  115. package/public/assets/{terminal-square-ypyAq6Ni.js → terminal-square-DCn_Ac2k.js} +2 -2
  116. package/public/assets/{terminal-square-ypyAq6Ni.js.map → terminal-square-DCn_Ac2k.js.map} +1 -1
  117. package/public/assets/{todo-Cgy3-kyM.js → todo-DyaFCX9E.js} +2 -2
  118. package/public/assets/{todo-Cgy3-kyM.js.map → todo-DyaFCX9E.js.map} +1 -1
  119. package/public/assets/{tool-call-0UMa6igS.js → tool-call-DlJUX9AW.js} +21 -21
  120. package/public/assets/{tool-call-0UMa6igS.js.map → tool-call-DlJUX9AW.js.map} +1 -1
  121. package/public/assets/{unified-picker-C-lhbMQ0.js → unified-picker-CrW1bp1Y.js} +2 -2
  122. package/public/assets/{unified-picker-C-lhbMQ0.js.map → unified-picker-CrW1bp1Y.js.map} +1 -1
  123. package/public/assets/{wrap-text-BjODGwnM.js → wrap-text-DLR5jp4s.js} +2 -2
  124. package/public/assets/{wrap-text-BjODGwnM.js.map → wrap-text-DLR5jp4s.js.map} +1 -1
  125. package/public/index.html +2 -2
  126. package/public/loading.html +2 -2
  127. package/public/sw.js +1 -1
  128. package/public/sw.js.map +1 -1
  129. package/dist/opencode-update/managed-installation.js +0 -102
  130. package/dist/opencode-update/managed-installation.js.map +0 -1
  131. package/dist/opencode-update/managed-installation.test.js +0 -102
  132. package/dist/opencode-update/managed-installation.test.js.map +0 -1
  133. package/public/assets/App-CkXPZUpS.js.map +0 -1
  134. package/public/assets/index-4LEntpq0.js +0 -2
  135. package/public/assets/index-4LEntpq0.js.map +0 -1
  136. package/public/assets/index-B2wje_CF.js +0 -2
  137. package/public/assets/index-B2wje_CF.js.map +0 -1
  138. package/public/assets/index-BDbkD8FO.js +0 -2
  139. package/public/assets/index-BDbkD8FO.js.map +0 -1
  140. package/public/assets/index-BbUJLdzG.js +0 -2
  141. package/public/assets/index-BbUJLdzG.js.map +0 -1
  142. package/public/assets/index-Bdh_-CtJ.js +0 -2
  143. package/public/assets/index-Bdh_-CtJ.js.map +0 -1
  144. package/public/assets/index-C9Jqb-tF.js +0 -2
  145. package/public/assets/index-C9Jqb-tF.js.map +0 -1
  146. package/public/assets/index-CIT8ANJK.js +0 -3
  147. package/public/assets/index-CIT8ANJK.js.map +0 -1
  148. package/public/assets/index-DbnGqvtc.js +0 -2
  149. package/public/assets/index-DbnGqvtc.js.map +0 -1
  150. package/public/assets/index-DhOvQD1j.js +0 -2
  151. package/public/assets/index-DhOvQD1j.js.map +0 -1
  152. package/public/assets/index-Gk3Kwcb2.js +0 -2
  153. package/public/assets/index-Gk3Kwcb2.js.map +0 -1
  154. package/public/assets/main-DAwgVcRN.js +0 -42
  155. package/public/assets/main-DAwgVcRN.js.map +0 -1
@@ -0,0 +1,270 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { mkdtemp, mkdir, writeFile, readFile, rm, symlink } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { findPathOpenCode, installSharedOpenCode, npmCommandDirectory, npmExecutable, resolveDefaultInstallation, sharedInstallPrefix, userNpmPrefix } from "./shared-installation";
7
+ import { registerUserPath } from "./user-path";
8
+ import { withInstallationLock } from "./installation-lock";
9
+ import { execFile } from "node:child_process";
10
+ import { promisify } from "node:util";
11
+ async function npmFixture(prefix, version) {
12
+ const binary = npmExecutable(prefix);
13
+ await mkdir(path.dirname(binary), { recursive: true });
14
+ await writeFile(binary, version, { mode: 0o755 });
15
+ await writeFile(path.join(path.dirname(binary), "..", "package.json"), JSON.stringify({ name: "@opencode/cli", bin: { opencode2: "./bin/opencode.exe" } }));
16
+ const bin = npmCommandDirectory(prefix);
17
+ await mkdir(bin, { recursive: true });
18
+ const command = path.join(bin, process.platform === "win32" ? "opencode2.cmd" : "opencode2");
19
+ if (process.platform === "win32")
20
+ await writeFile(command, '@echo off\r\n"%~dp0\\node_modules\\@opencode\\cli\\bin\\opencode.exe" %*\r\n');
21
+ else
22
+ await symlink(binary, command).catch(error => { if (error.code !== "EEXIST")
23
+ throw error; });
24
+ return command;
25
+ }
26
+ test("private copies and their receipts are ignored; PATH wins over the user npm installation", async () => {
27
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-"));
28
+ const env = { PATH: "", APPDATA: path.join(home, "AppData") };
29
+ const host = { home, env };
30
+ try {
31
+ const root = path.join(home, ".local/share/codenomad/opencode");
32
+ const legacy = path.join(root, "2.0.99/node_modules/@opencode/cli/bin/opencode.exe");
33
+ await mkdir(path.dirname(legacy), { recursive: true });
34
+ await writeFile(legacy, "legacy");
35
+ await mkdir(path.join(root, "selected"));
36
+ await writeFile(path.join(root, "selected/2.0.99"), "");
37
+ await writeFile(path.join(root, "current"), "2.0.99");
38
+ assert.deepEqual(resolveDefaultInstallation(host), { path: "opencode2" });
39
+ assert.equal(sharedInstallPrefix(host), userNpmPrefix(host));
40
+ const prefix = userNpmPrefix(host);
41
+ await npmFixture(prefix, "2.0.11");
42
+ assert.deepEqual(resolveDefaultInstallation(host), { path: npmExecutable(prefix), source: "user" });
43
+ const existing = path.join(home, "existing npm");
44
+ const command = await npmFixture(existing, "2.0.12");
45
+ env.PATH = npmCommandDirectory(existing);
46
+ assert.deepEqual(resolveDefaultInstallation(host), { path: command, source: "path" });
47
+ assert.equal(sharedInstallPrefix(host), existing);
48
+ assert.equal(await readFile(legacy, "utf8"), "legacy", "discovery never removes private installations");
49
+ }
50
+ finally {
51
+ await rm(home, { recursive: true, force: true });
52
+ }
53
+ });
54
+ test("normal global-user npm install publishes terminal command and retries PATH registration without reinstalling", async () => {
55
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-install-"));
56
+ const env = { PATH: "", APPDATA: path.join(home, "AppData"), SHELL: "/bin/bash" };
57
+ let installs = 0, registrations = 0;
58
+ const prefix = userNpmPrefix({ home, env });
59
+ const options = { home, env, node: process.execPath, npm: "fixture-npm.js",
60
+ execute: async (_file, args) => {
61
+ installs++;
62
+ assert.ok(args.includes("--global"));
63
+ assert.equal(args[args.indexOf("--prefix") + 1], prefix);
64
+ await npmFixture(prefix, args.at(-1).split("@").at(-1));
65
+ },
66
+ probe: async (binary) => {
67
+ try {
68
+ return { valid: true, version: await readFile(binary, "utf8") };
69
+ }
70
+ catch {
71
+ return { valid: false, missing: true };
72
+ }
73
+ },
74
+ registerPath: async (directory) => {
75
+ if (++registrations === 1)
76
+ throw new Error("PATH write failed");
77
+ await registerUserPath(directory, { home, env, registerWindowsPath: async () => { } });
78
+ },
79
+ };
80
+ try {
81
+ await assert.rejects(installSharedOpenCode("2.0.11", options), /PATH write failed/);
82
+ assert.equal((await options.probe(npmExecutable(prefix))).version, "2.0.11", "installation survives PATH failure");
83
+ assert.equal((resolveDefaultInstallation(options)).source, "user", "repair remains discoverable");
84
+ assert.equal(await installSharedOpenCode("2.0.11", options), npmExecutable(prefix));
85
+ assert.equal(installs, 1);
86
+ assert.equal(resolveDefaultInstallation(options).path, findPathOpenCode(options));
87
+ assert.equal(resolveDefaultInstallation(options).source, "path");
88
+ await installSharedOpenCode("2.0.12", options);
89
+ assert.equal(installs, 2);
90
+ await installSharedOpenCode("2.0.11", options);
91
+ assert.equal(installs, 2, "never downgrade a newer common installation");
92
+ assert.equal((await options.probe(npmExecutable(prefix))).version, "2.0.12");
93
+ await rm(findPathOpenCode(options));
94
+ await installSharedOpenCode("2.0.11", options);
95
+ assert.equal(installs, 3, "missing command is repaired at the newer installed version");
96
+ assert.equal((await options.probe(npmExecutable(prefix))).version, "2.0.12");
97
+ }
98
+ finally {
99
+ await rm(home, { recursive: true, force: true });
100
+ }
101
+ });
102
+ test("independent backends cannot replace a shared installation concurrently; failures release the lock", async () => {
103
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-lock-"));
104
+ try {
105
+ await withInstallationLock(home, async () => {
106
+ const module = new URL("./installation-lock.ts", import.meta.url).href;
107
+ const script = `import { withInstallationLock } from ${JSON.stringify(module)};
108
+ try { await withInstallationLock(${JSON.stringify(home)}, async () => { throw new Error('entered'); }); process.exit(2); }
109
+ catch (error) { if (error.code !== 'installation_busy') throw error; }`;
110
+ await promisify(execFile)(process.execPath, ["--import", "tsx", "--input-type=module", "-e", script]);
111
+ });
112
+ await assert.rejects(withInstallationLock(home, async () => { throw new Error("fixture failure"); }), /fixture failure/);
113
+ assert.equal(await withInstallationLock(home, async () => "released"), "released");
114
+ }
115
+ finally {
116
+ await rm(home, { recursive: true, force: true });
117
+ }
118
+ });
119
+ test("standalone opencode commands and custom npm prefixes are discovered without mutation", async () => {
120
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-prefix-"));
121
+ try {
122
+ const prefix = path.join(home, "custom npm");
123
+ const host = { home, env: { PATH: "", NPM_CONFIG_PREFIX: prefix } };
124
+ assert.equal(userNpmPrefix(host), prefix);
125
+ await npmFixture(prefix, "2.0.12");
126
+ assert.equal(resolveDefaultInstallation(host).path, npmExecutable(prefix));
127
+ const command = path.join(home, process.platform === "win32" ? "opencode.exe" : "opencode");
128
+ await writeFile(command, "standalone", { mode: 0o755 });
129
+ host.env.PATH = home;
130
+ assert.equal(resolveDefaultInstallation(host).path, command);
131
+ assert.equal(sharedInstallPrefix(host), undefined);
132
+ }
133
+ finally {
134
+ await rm(home, { recursive: true, force: true });
135
+ }
136
+ });
137
+ test("historical npm launchers select the real executable and allow stable migration", async () => {
138
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-history-"));
139
+ try {
140
+ for (const [version, name, oldBinary] of [["0.0.0-beta-19275", "opencode2", "opencode2.exe"], ["2.0.0", "opencode", "opencode.exe"]]) {
141
+ const prefix = path.join(home, version);
142
+ const binary = path.join(path.dirname(npmExecutable(prefix)), oldBinary);
143
+ await mkdir(path.dirname(binary), { recursive: true });
144
+ await writeFile(binary, version, { mode: 0o755 });
145
+ await writeFile(path.join(path.dirname(binary), "..", "package.json"), JSON.stringify({ name: "@opencode/cli", bin: {
146
+ opencode2: name === "opencode2" ? `./bin/${oldBinary}` : "./bin/opencode2.cjs", opencode: "./bin/opencode.exe",
147
+ } }));
148
+ const directory = npmCommandDirectory(prefix);
149
+ await mkdir(directory, { recursive: true });
150
+ const command = path.join(directory, process.platform === "win32" ? `${name}.cmd` : name);
151
+ if (process.platform === "win32") {
152
+ await writeFile(command, `@echo off\r\n"%~dp0\\node_modules\\@opencode\\cli\\bin\\${oldBinary}" %*\r\n`);
153
+ if (name === "opencode") {
154
+ await writeFile(path.join(path.dirname(binary), "opencode2.cjs"), "retired");
155
+ await writeFile(path.join(directory, "opencode2.cmd"), '@echo off\r\nnode "%~dp0\\node_modules\\@opencode\\cli\\bin\\opencode2.cjs" %*\r\n');
156
+ }
157
+ }
158
+ else {
159
+ await symlink(binary, command);
160
+ if (name === "opencode") {
161
+ const retired = path.join(path.dirname(binary), "opencode2.cjs");
162
+ await writeFile(retired, "retired", { mode: 0o755 });
163
+ await symlink(retired, path.join(directory, "opencode2"));
164
+ }
165
+ }
166
+ const host = { home, env: { PATH: directory, APPDATA: home } };
167
+ assert.equal(resolveDefaultInstallation(host).path, command);
168
+ assert.equal(sharedInstallPrefix(host), prefix);
169
+ }
170
+ }
171
+ finally {
172
+ await rm(home, { recursive: true, force: true });
173
+ }
174
+ });
175
+ test("PATH executable precedence wins over npm shims in the same prefix", async () => {
176
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-precedence-"));
177
+ try {
178
+ const prefix = path.join(home, "npm");
179
+ const directory = npmCommandDirectory(prefix);
180
+ await npmFixture(prefix, "2.0.3");
181
+ const standalone = path.join(directory, process.platform === "win32" ? "opencode2.exe" : "opencode2");
182
+ if (process.platform === "win32")
183
+ await writeFile(standalone, "standalone");
184
+ else {
185
+ await rm(standalone, { force: true });
186
+ await writeFile(standalone, "standalone", { mode: 0o755 });
187
+ await symlink(npmExecutable(prefix), path.join(directory, "opencode"));
188
+ }
189
+ const host = { home, env: { PATH: directory } };
190
+ assert.equal(resolveDefaultInstallation(host).path, standalone);
191
+ assert.equal(sharedInstallPrefix(host), undefined);
192
+ if (process.platform !== "win32") {
193
+ const sibling = path.join(prefix, "sibling");
194
+ await mkdir(sibling);
195
+ const unrelated = path.join(sibling, "opencode2");
196
+ await writeFile(unrelated, "standalone", { mode: 0o755 });
197
+ assert.equal(resolveDefaultInstallation({ home, env: { PATH: sibling } }).path, unrelated);
198
+ assert.equal(sharedInstallPrefix({ home, env: { PATH: sibling } }), undefined);
199
+ }
200
+ }
201
+ finally {
202
+ await rm(home, { recursive: true, force: true });
203
+ }
204
+ });
205
+ test("custom Windows command wrapper in an npm prefix wins over the package alias", async () => {
206
+ if (process.platform !== "win32")
207
+ return;
208
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-wrapper-"));
209
+ try {
210
+ const prefix = path.join(home, "npm");
211
+ await npmFixture(prefix, "2.0.3");
212
+ await writeFile(path.join(path.dirname(npmExecutable(prefix)), "..", "package.json"), JSON.stringify({
213
+ name: "@opencode/cli", bin: { opencode2: "./bin/opencode.exe", opencode: "./bin/opencode.exe" },
214
+ }));
215
+ await writeFile(path.join(prefix, "opencode.cmd"), '@echo off\r\n"%~dp0\\node_modules\\@opencode\\cli\\bin\\opencode.exe" %*\r\n');
216
+ const standalone = path.join(home, "standalone.exe");
217
+ await writeFile(standalone, "standalone");
218
+ const command = path.join(prefix, "opencode2.cmd");
219
+ await writeFile(command, `@echo off\r\n"${standalone}" %*\r\n`);
220
+ const host = { home, env: { PATH: prefix } };
221
+ assert.equal(resolveDefaultInstallation(host).path, command);
222
+ assert.equal(sharedInstallPrefix(host), undefined);
223
+ }
224
+ finally {
225
+ await rm(home, { recursive: true, force: true });
226
+ }
227
+ });
228
+ test("non-npm PATH executables are reused without allowing npm to shadow them", async () => {
229
+ const home = await mkdtemp(path.join(os.tmpdir(), "shared-opencode-custom-"));
230
+ try {
231
+ const binary = path.join(home, process.platform === "win32" ? "opencode2.exe" : "opencode2");
232
+ await writeFile(binary, "custom", { mode: 0o755 });
233
+ const options = { home, env: { PATH: home }, npm: "fixture-npm.js" };
234
+ assert.equal(resolveDefaultInstallation(options).path, binary);
235
+ assert.equal(sharedInstallPrefix(options), undefined);
236
+ await assert.rejects(installSharedOpenCode("2.0.11", options), /not a writable npm installation/);
237
+ }
238
+ finally {
239
+ await rm(home, { recursive: true, force: true });
240
+ }
241
+ });
242
+ test("shell PATH registration preserves profiles and is idempotent for bash, zsh, fish and Windows", async () => {
243
+ const home = await mkdtemp(path.join(os.tmpdir(), "opencode-shells-"));
244
+ try {
245
+ for (const shell of ["bash", "zsh", "fish"]) {
246
+ const user = path.join(home, shell);
247
+ const bin = `/users/example/${shell}/bin with spaces`;
248
+ await mkdir(user);
249
+ const env = { PATH: "/existing", SHELL: `/bin/${shell}` };
250
+ await writeFile(path.join(user, ".profile"), "# user settings\n");
251
+ const options = { home: user, env, platform: "linux" };
252
+ await registerUserPath(bin, options);
253
+ const file = shell === "bash" ? ".bashrc" : shell === "zsh" ? ".zshrc" : ".config/fish/conf.d/opencode-path.fish";
254
+ const first = await readFile(path.join(user, file), "utf8");
255
+ await registerUserPath(bin, options);
256
+ assert.equal(await readFile(path.join(user, file), "utf8"), first);
257
+ assert.ok((await readFile(path.join(user, ".profile"), "utf8")).startsWith("# user settings\n"));
258
+ assert.equal(env.PATH, `/existing:${bin}`);
259
+ }
260
+ const env = { Path: "C:\\existing" };
261
+ let registered = "";
262
+ await registerUserPath("C:\\user\\npm", { home, platform: "win32", env, registerWindowsPath: async (bin) => { registered = bin; } });
263
+ assert.equal(registered, "C:\\user\\npm");
264
+ assert.equal(env.Path, "C:\\existing;C:\\user\\npm");
265
+ }
266
+ finally {
267
+ await rm(home, { recursive: true, force: true });
268
+ }
269
+ });
270
+ //# sourceMappingURL=shared-installation.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-installation.test.js","sourceRoot":"","sources":["../../src/opencode-update/shared-installation.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACnF,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,aAAa,EAAE,0BAA0B,E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C;YAAS,CAAC;QAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAAC,CAAC;AAChE,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport test from \"node:test\"\nimport { mkdtemp, mkdir, writeFile, readFile, rm, symlink } from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport { findPathOpenCode, installSharedOpenCode, npmCommandDirectory, npmExecutable, resolveDefaultInstallation, sharedInstallPrefix, userNpmPrefix } from \"./shared-installation\"\nimport { registerUserPath } from \"./user-path\"\nimport { withInstallationLock } from \"./installation-lock\"\nimport { execFile } from \"node:child_process\"\nimport { promisify } from \"node:util\"\n\nasync function npmFixture(prefix: string, version: string) {\n const binary = npmExecutable(prefix)\n await mkdir(path.dirname(binary), { recursive: true })\n await writeFile(binary, version, { mode: 0o755 })\n await writeFile(path.join(path.dirname(binary), \"..\", \"package.json\"), JSON.stringify({ name: \"@opencode/cli\", bin: { opencode2: \"./bin/opencode.exe\" } }))\n const bin = npmCommandDirectory(prefix)\n await mkdir(bin, { recursive: true })\n const command = path.join(bin, process.platform === \"win32\" ? \"opencode2.cmd\" : \"opencode2\")\n if (process.platform === \"win32\") await writeFile(command, '@echo off\\r\\n\"%~dp0\\\\node_modules\\\\@opencode\\\\cli\\\\bin\\\\opencode.exe\" %*\\r\\n')\n else await symlink(binary, command).catch(error => { if (error.code !== \"EEXIST\") throw error })\n return command\n}\n\ntest(\"private copies and their receipts are ignored; PATH wins over the user npm installation\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-\"))\n const env = { PATH: \"\", APPDATA: path.join(home, \"AppData\") }\n const host = { home, env }\n try {\n const root = path.join(home, \".local/share/codenomad/opencode\")\n const legacy = path.join(root, \"2.0.99/node_modules/@opencode/cli/bin/opencode.exe\")\n await mkdir(path.dirname(legacy), { recursive: true }); await writeFile(legacy, \"legacy\")\n await mkdir(path.join(root, \"selected\")); await writeFile(path.join(root, \"selected/2.0.99\"), \"\")\n await writeFile(path.join(root, \"current\"), \"2.0.99\")\n assert.deepEqual(resolveDefaultInstallation(host), { path: \"opencode2\" })\n assert.equal(sharedInstallPrefix(host), userNpmPrefix(host))\n const prefix = userNpmPrefix(host)\n await npmFixture(prefix, \"2.0.11\")\n assert.deepEqual(resolveDefaultInstallation(host), { path: npmExecutable(prefix), source: \"user\" })\n const existing = path.join(home, \"existing npm\")\n const command = await npmFixture(existing, \"2.0.12\")\n env.PATH = npmCommandDirectory(existing)\n assert.deepEqual(resolveDefaultInstallation(host), { path: command, source: \"path\" })\n assert.equal(sharedInstallPrefix(host), existing)\n assert.equal(await readFile(legacy, \"utf8\"), \"legacy\", \"discovery never removes private installations\")\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"normal global-user npm install publishes terminal command and retries PATH registration without reinstalling\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-install-\"))\n const env = { PATH: \"\", APPDATA: path.join(home, \"AppData\"), SHELL: \"/bin/bash\" }\n let installs = 0, registrations = 0\n const prefix = userNpmPrefix({ home, env })\n const options = { home, env, node: process.execPath, npm: \"fixture-npm.js\",\n execute: async (_file: string, args: string[]) => {\n installs++\n assert.ok(args.includes(\"--global\"))\n assert.equal(args[args.indexOf(\"--prefix\") + 1], prefix)\n await npmFixture(prefix, args.at(-1)!.split(\"@\").at(-1)!)\n },\n probe: async (binary: string) => {\n try { return { valid: true, version: await readFile(binary, \"utf8\") } } catch { return { valid: false, missing: true } }\n },\n registerPath: async (directory: string) => {\n if (++registrations === 1) throw new Error(\"PATH write failed\")\n await registerUserPath(directory, { home, env, registerWindowsPath: async () => {} })\n },\n }\n try {\n await assert.rejects(installSharedOpenCode(\"2.0.11\", options), /PATH write failed/)\n assert.equal((await options.probe(npmExecutable(prefix))).version, \"2.0.11\", \"installation survives PATH failure\")\n assert.equal((resolveDefaultInstallation(options)).source, \"user\", \"repair remains discoverable\")\n assert.equal(await installSharedOpenCode(\"2.0.11\", options), npmExecutable(prefix))\n assert.equal(installs, 1)\n assert.equal(resolveDefaultInstallation(options).path, findPathOpenCode(options))\n assert.equal(resolveDefaultInstallation(options).source, \"path\")\n await installSharedOpenCode(\"2.0.12\", options)\n assert.equal(installs, 2)\n await installSharedOpenCode(\"2.0.11\", options)\n assert.equal(installs, 2, \"never downgrade a newer common installation\")\n assert.equal((await options.probe(npmExecutable(prefix))).version, \"2.0.12\")\n await rm(findPathOpenCode(options)!)\n await installSharedOpenCode(\"2.0.11\", options)\n assert.equal(installs, 3, \"missing command is repaired at the newer installed version\")\n assert.equal((await options.probe(npmExecutable(prefix))).version, \"2.0.12\")\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"independent backends cannot replace a shared installation concurrently; failures release the lock\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-lock-\"))\n try {\n await withInstallationLock(home, async () => {\n const module = new URL(\"./installation-lock.ts\", import.meta.url).href\n const script = `import { withInstallationLock } from ${JSON.stringify(module)};\n try { await withInstallationLock(${JSON.stringify(home)}, async () => { throw new Error('entered'); }); process.exit(2); }\n catch (error) { if (error.code !== 'installation_busy') throw error; }`\n await promisify(execFile)(process.execPath, [\"--import\", \"tsx\", \"--input-type=module\", \"-e\", script])\n })\n await assert.rejects(withInstallationLock(home, async () => { throw new Error(\"fixture failure\") }), /fixture failure/)\n assert.equal(await withInstallationLock(home, async () => \"released\"), \"released\")\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"standalone opencode commands and custom npm prefixes are discovered without mutation\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-prefix-\"))\n try {\n const prefix = path.join(home, \"custom npm\")\n const host = { home, env: { PATH: \"\", NPM_CONFIG_PREFIX: prefix } }\n assert.equal(userNpmPrefix(host), prefix)\n await npmFixture(prefix, \"2.0.12\")\n assert.equal(resolveDefaultInstallation(host).path, npmExecutable(prefix))\n const command = path.join(home, process.platform === \"win32\" ? \"opencode.exe\" : \"opencode\")\n await writeFile(command, \"standalone\", { mode: 0o755 })\n host.env.PATH = home\n assert.equal(resolveDefaultInstallation(host).path, command)\n assert.equal(sharedInstallPrefix(host), undefined)\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"historical npm launchers select the real executable and allow stable migration\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-history-\"))\n try {\n for (const [version, name, oldBinary] of [[\"0.0.0-beta-19275\", \"opencode2\", \"opencode2.exe\"], [\"2.0.0\", \"opencode\", \"opencode.exe\"]]) {\n const prefix = path.join(home, version)\n const binary = path.join(path.dirname(npmExecutable(prefix)), oldBinary)\n await mkdir(path.dirname(binary), { recursive: true })\n await writeFile(binary, version, { mode: 0o755 })\n await writeFile(path.join(path.dirname(binary), \"..\", \"package.json\"), JSON.stringify({ name: \"@opencode/cli\", bin: {\n opencode2: name === \"opencode2\" ? `./bin/${oldBinary}` : \"./bin/opencode2.cjs\", opencode: \"./bin/opencode.exe\",\n } }))\n const directory = npmCommandDirectory(prefix)\n await mkdir(directory, { recursive: true })\n const command = path.join(directory, process.platform === \"win32\" ? `${name}.cmd` : name)\n if (process.platform === \"win32\") {\n await writeFile(command, `@echo off\\r\\n\"%~dp0\\\\node_modules\\\\@opencode\\\\cli\\\\bin\\\\${oldBinary}\" %*\\r\\n`)\n if (name === \"opencode\") {\n await writeFile(path.join(path.dirname(binary), \"opencode2.cjs\"), \"retired\")\n await writeFile(path.join(directory, \"opencode2.cmd\"), '@echo off\\r\\nnode \"%~dp0\\\\node_modules\\\\@opencode\\\\cli\\\\bin\\\\opencode2.cjs\" %*\\r\\n')\n }\n } else {\n await symlink(binary, command)\n if (name === \"opencode\") {\n const retired = path.join(path.dirname(binary), \"opencode2.cjs\")\n await writeFile(retired, \"retired\", { mode: 0o755 })\n await symlink(retired, path.join(directory, \"opencode2\"))\n }\n }\n const host = { home, env: { PATH: directory, APPDATA: home } }\n assert.equal(resolveDefaultInstallation(host).path, command)\n assert.equal(sharedInstallPrefix(host), prefix)\n }\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"PATH executable precedence wins over npm shims in the same prefix\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-precedence-\"))\n try {\n const prefix = path.join(home, \"npm\")\n const directory = npmCommandDirectory(prefix)\n await npmFixture(prefix, \"2.0.3\")\n const standalone = path.join(directory, process.platform === \"win32\" ? \"opencode2.exe\" : \"opencode2\")\n if (process.platform === \"win32\") await writeFile(standalone, \"standalone\")\n else {\n await rm(standalone, { force: true })\n await writeFile(standalone, \"standalone\", { mode: 0o755 })\n await symlink(npmExecutable(prefix), path.join(directory, \"opencode\"))\n }\n const host = { home, env: { PATH: directory } }\n assert.equal(resolveDefaultInstallation(host).path, standalone)\n assert.equal(sharedInstallPrefix(host), undefined)\n if (process.platform !== \"win32\") {\n const sibling = path.join(prefix, \"sibling\")\n await mkdir(sibling)\n const unrelated = path.join(sibling, \"opencode2\")\n await writeFile(unrelated, \"standalone\", { mode: 0o755 })\n assert.equal(resolveDefaultInstallation({ home, env: { PATH: sibling } }).path, unrelated)\n assert.equal(sharedInstallPrefix({ home, env: { PATH: sibling } }), undefined)\n }\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"custom Windows command wrapper in an npm prefix wins over the package alias\", async () => {\n if (process.platform !== \"win32\") return\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-wrapper-\"))\n try {\n const prefix = path.join(home, \"npm\")\n await npmFixture(prefix, \"2.0.3\")\n await writeFile(path.join(path.dirname(npmExecutable(prefix)), \"..\", \"package.json\"), JSON.stringify({\n name: \"@opencode/cli\", bin: { opencode2: \"./bin/opencode.exe\", opencode: \"./bin/opencode.exe\" },\n }))\n await writeFile(path.join(prefix, \"opencode.cmd\"), '@echo off\\r\\n\"%~dp0\\\\node_modules\\\\@opencode\\\\cli\\\\bin\\\\opencode.exe\" %*\\r\\n')\n const standalone = path.join(home, \"standalone.exe\")\n await writeFile(standalone, \"standalone\")\n const command = path.join(prefix, \"opencode2.cmd\")\n await writeFile(command, `@echo off\\r\\n\"${standalone}\" %*\\r\\n`)\n const host = { home, env: { PATH: prefix } }\n assert.equal(resolveDefaultInstallation(host).path, command)\n assert.equal(sharedInstallPrefix(host), undefined)\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"non-npm PATH executables are reused without allowing npm to shadow them\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"shared-opencode-custom-\"))\n try {\n const binary = path.join(home, process.platform === \"win32\" ? \"opencode2.exe\" : \"opencode2\")\n await writeFile(binary, \"custom\", { mode: 0o755 })\n const options = { home, env: { PATH: home }, npm: \"fixture-npm.js\" }\n assert.equal(resolveDefaultInstallation(options).path, binary)\n assert.equal(sharedInstallPrefix(options), undefined)\n await assert.rejects(installSharedOpenCode(\"2.0.11\", options), /not a writable npm installation/)\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n\ntest(\"shell PATH registration preserves profiles and is idempotent for bash, zsh, fish and Windows\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"opencode-shells-\"))\n try {\n for (const shell of [\"bash\", \"zsh\", \"fish\"]) {\n const user = path.join(home, shell)\n const bin = `/users/example/${shell}/bin with spaces`\n await mkdir(user)\n const env = { PATH: \"/existing\", SHELL: `/bin/${shell}` }\n await writeFile(path.join(user, \".profile\"), \"# user settings\\n\")\n const options = { home: user, env, platform: \"linux\" as const }\n await registerUserPath(bin, options)\n const file = shell === \"bash\" ? \".bashrc\" : shell === \"zsh\" ? \".zshrc\" : \".config/fish/conf.d/opencode-path.fish\"\n const first = await readFile(path.join(user, file), \"utf8\")\n await registerUserPath(bin, options)\n assert.equal(await readFile(path.join(user, file), \"utf8\"), first)\n assert.ok((await readFile(path.join(user, \".profile\"), \"utf8\")).startsWith(\"# user settings\\n\"))\n assert.equal(env.PATH, `/existing:${bin}`)\n }\n const env = { Path: \"C:\\\\existing\" }\n let registered = \"\"\n await registerUserPath(\"C:\\\\user\\\\npm\", { home, platform: \"win32\", env, registerWindowsPath: async bin => { registered = bin } })\n assert.equal(registered, \"C:\\\\user\\\\npm\")\n assert.equal(env.Path, \"C:\\\\existing;C:\\\\user\\\\npm\")\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n"]}
@@ -0,0 +1,85 @@
1
+ import { execFile } from "node:child_process";
2
+ import { mkdir, readFile, appendFile } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ const quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
6
+ async function addProfileLine(file, line) {
7
+ let existing = "";
8
+ try {
9
+ existing = await readFile(file, "utf8");
10
+ }
11
+ catch (error) {
12
+ if (error.code !== "ENOENT")
13
+ throw error;
14
+ }
15
+ if (existing.split(/\r?\n/).includes(line))
16
+ return;
17
+ await mkdir(path.dirname(file), { recursive: true });
18
+ await appendFile(file, `\n# OpenCode user installation PATH (CodeNomad)\n${line}\n`, { mode: 0o600 });
19
+ }
20
+ export async function registerWindowsUserPath(bin) {
21
+ // Preserve unexpanded %VARIABLE% entries and their registry value type.
22
+ const script = `$ErrorActionPreference = 'Stop'
23
+ $bin = '${bin.replaceAll("'", "''")}'
24
+ $key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')
25
+ try {
26
+ $raw = $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
27
+ $kind = if ($key.GetValueNames() -contains 'Path') { $key.GetValueKind('Path') } else { [Microsoft.Win32.RegistryValueKind]::ExpandString }
28
+ $found = @($raw -split ';' | Where-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\\') -ieq $bin.TrimEnd('\\') }).Count -gt 0
29
+ if (-not $found) { $key.SetValue('Path', (($raw.TrimEnd(';') + ';' + $bin).TrimStart(';')), $kind) }
30
+ } finally { $key.Dispose() }
31
+ Add-Type -Namespace CodeNomad -Name EnvironmentBroadcast -MemberDefinition '[System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Unicode)] public static extern System.IntPtr SendMessageTimeout(System.IntPtr h, uint m, System.UIntPtr w, string l, uint f, uint t, out System.UIntPtr r);'
32
+ $result = [UIntPtr]::Zero
33
+ [void][CodeNomad.EnvironmentBroadcast]::SendMessageTimeout([IntPtr]0xffff, 0x1a, [UIntPtr]::Zero, 'Environment', 2, 2000, [ref]$result)
34
+ `;
35
+ const executable = path.join(process.env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
36
+ await new Promise((resolve, reject) => execFile(executable, ["-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")], { windowsHide: true, timeout: 15_000, maxBuffer: 64 * 1024 }, error => error ? reject(new Error("Could not register the user terminal PATH")) : resolve()));
37
+ }
38
+ /** Called only by an explicit installation, never by discovery/status reads. */
39
+ export async function registerUserPath(bin, options = {}) {
40
+ const home = options.home ?? os.homedir();
41
+ const platform = options.platform ?? process.platform;
42
+ const env = options.env ?? process.env;
43
+ const shell = path.basename(env.SHELL || (platform === "darwin" ? "/bin/zsh" : "/bin/bash"));
44
+ if (platform === "win32") {
45
+ await (options.registerWindowsPath ?? registerWindowsUserPath)(bin);
46
+ }
47
+ else {
48
+ const line = `case ":$PATH:" in *:${quote(bin)}:*) ;; *) export PATH="$PATH":${quote(bin)} ;; esac`;
49
+ if (shell === "fish") {
50
+ const config = env.XDG_CONFIG_HOME || path.join(home, ".config");
51
+ // Fish single-quoted strings only interpret escaped quote/backslash.
52
+ const fishBin = `'${bin.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
53
+ await addProfileLine(path.join(config, "fish", "conf.d", "opencode-path.fish"), `if not contains -- ${fishBin} $PATH; set -gx PATH $PATH ${fishBin}; end`);
54
+ }
55
+ else if (shell === "zsh") {
56
+ for (const name of [".zprofile", ".zshrc"])
57
+ await addProfileLine(path.join(env.ZDOTDIR || home, name), line);
58
+ }
59
+ else if (shell === "bash" || shell === "sh") {
60
+ await addProfileLine(path.join(home, ".profile"), line);
61
+ if (shell === "bash") {
62
+ await addProfileLine(path.join(home, ".bashrc"), line);
63
+ for (const name of [".bash_profile", ".bash_login"]) {
64
+ try {
65
+ await readFile(path.join(home, name));
66
+ await addProfileLine(path.join(home, name), line);
67
+ }
68
+ catch (error) {
69
+ if (error.code !== "ENOENT")
70
+ throw error;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ else
76
+ throw new Error("Register the OpenCode installation directory in this shell's PATH manually");
77
+ }
78
+ const key = Object.keys(env).find(key => key.toLowerCase() === "path") ?? "PATH";
79
+ const delimiter = platform === "win32" ? ";" : ":";
80
+ const normalize = (value) => platform === "win32" ? value.toLowerCase().replace(/[\\/]+$/, "") : value;
81
+ if (!(env[key] || "").split(delimiter).some(value => normalize(value) === normalize(bin))) {
82
+ env[key] = [env[key], bin].filter(Boolean).join(delimiter);
83
+ }
84
+ }
85
+ //# sourceMappingURL=user-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-path.js","sourceRoot":"","sources":["../../src/opencode-update/user-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAS5B,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAA;AAEtE,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,IAAY;IACtD,IAAI,QAAQ,GAAG,EAAE,CAAA;IACjB,IAAI,CAAC;QAAC,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MA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,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IAClD,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC9G,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC1F,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC5D,CAAC;AACH,CAAC","sourcesContent":["import { execFile } from \"node:child_process\"\nimport { mkdir, readFile, appendFile } from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\nexport interface UserPathOptions {\n home?: string\n platform?: NodeJS.Platform\n env?: NodeJS.ProcessEnv\n registerWindowsPath?: (bin: string) => Promise<void>\n}\n\nconst quote = (value: string) => `'${value.replaceAll(\"'\", \"'\\\\''\")}'`\n\nasync function addProfileLine(file: string, line: string) {\n let existing = \"\"\n try { existing = await readFile(file, \"utf8\") } catch (error) { if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error }\n if (existing.split(/\\r?\\n/).includes(line)) return\n await mkdir(path.dirname(file), { recursive: true })\n await appendFile(file, `\\n# OpenCode user installation PATH (CodeNomad)\\n${line}\\n`, { mode: 0o600 })\n}\n\nexport async function registerWindowsUserPath(bin: string): Promise<void> {\n // Preserve unexpanded %VARIABLE% entries and their registry value type.\n const script = `$ErrorActionPreference = 'Stop'\n$bin = '${bin.replaceAll(\"'\", \"''\")}'\n$key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')\ntry {\n $raw = $key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)\n $kind = if ($key.GetValueNames() -contains 'Path') { $key.GetValueKind('Path') } else { [Microsoft.Win32.RegistryValueKind]::ExpandString }\n $found = @($raw -split ';' | Where-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\\\\') -ieq $bin.TrimEnd('\\\\') }).Count -gt 0\n if (-not $found) { $key.SetValue('Path', (($raw.TrimEnd(';') + ';' + $bin).TrimStart(';')), $kind) }\n} finally { $key.Dispose() }\nAdd-Type -Namespace CodeNomad -Name EnvironmentBroadcast -MemberDefinition '[System.Runtime.InteropServices.DllImport(\"user32.dll\", CharSet=System.Runtime.InteropServices.CharSet.Unicode)] public static extern System.IntPtr SendMessageTimeout(System.IntPtr h, uint m, System.UIntPtr w, string l, uint f, uint t, out System.UIntPtr r);'\n$result = [UIntPtr]::Zero\n[void][CodeNomad.EnvironmentBroadcast]::SendMessageTimeout([IntPtr]0xffff, 0x1a, [UIntPtr]::Zero, 'Environment', 2, 2000, [ref]$result)\n`\n const executable = path.join(process.env.SystemRoot || \"C:\\\\Windows\", \"System32\", \"WindowsPowerShell\", \"v1.0\", \"powershell.exe\")\n await new Promise<void>((resolve, reject) => execFile(executable,\n [\"-NoProfile\", \"-NonInteractive\", \"-EncodedCommand\", Buffer.from(script, \"utf16le\").toString(\"base64\")],\n { windowsHide: true, timeout: 15_000, maxBuffer: 64 * 1024 }, error => error ? reject(new Error(\"Could not register the user terminal PATH\")) : resolve()))\n}\n\n/** Called only by an explicit installation, never by discovery/status reads. */\nexport async function registerUserPath(bin: string, options: UserPathOptions = {}): Promise<void> {\n const home = options.home ?? os.homedir()\n const platform = options.platform ?? process.platform\n const env = options.env ?? process.env\n const shell = path.basename(env.SHELL || (platform === \"darwin\" ? \"/bin/zsh\" : \"/bin/bash\"))\n if (platform === \"win32\") {\n await (options.registerWindowsPath ?? registerWindowsUserPath)(bin)\n } else {\n const line = `case \":$PATH:\" in *:${quote(bin)}:*) ;; *) export PATH=\"$PATH\":${quote(bin)} ;; esac`\n if (shell === \"fish\") {\n const config = env.XDG_CONFIG_HOME || path.join(home, \".config\")\n // Fish single-quoted strings only interpret escaped quote/backslash.\n const fishBin = `'${bin.replaceAll(\"\\\\\", \"\\\\\\\\\").replaceAll(\"'\", \"\\\\'\")}'`\n await addProfileLine(path.join(config, \"fish\", \"conf.d\", \"opencode-path.fish\"),\n `if not contains -- ${fishBin} $PATH; set -gx PATH $PATH ${fishBin}; end`)\n } else if (shell === \"zsh\") {\n for (const name of [\".zprofile\", \".zshrc\"]) await addProfileLine(path.join(env.ZDOTDIR || home, name), line)\n } else if (shell === \"bash\" || shell === \"sh\") {\n await addProfileLine(path.join(home, \".profile\"), line)\n if (shell === \"bash\") {\n await addProfileLine(path.join(home, \".bashrc\"), line)\n for (const name of [\".bash_profile\", \".bash_login\"]) {\n try { await readFile(path.join(home, name)); await addProfileLine(path.join(home, name), line) }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error }\n }\n }\n } else throw new Error(\"Register the OpenCode installation directory in this shell's PATH manually\")\n }\n const key = Object.keys(env).find(key => key.toLowerCase() === \"path\") ?? \"PATH\"\n const delimiter = platform === \"win32\" ? \";\" : \":\"\n const normalize = (value: string) => platform === \"win32\" ? value.toLowerCase().replace(/[\\\\/]+$/, \"\") : value\n if (!(env[key] || \"\").split(delimiter).some(value => normalize(value) === normalize(bin))) {\n env[key] = [env[key], bin].filter(Boolean).join(delimiter)\n }\n}\n"]}
@@ -20245,7 +20245,9 @@ var Value2 = Schema_exports.Union([OAuth, Key]).pipe(Schema_exports.toTaggedUnio
20245
20245
  var CredentialInfo = Schema_exports.Struct({
20246
20246
  type: Schema_exports.Literal("credential"),
20247
20247
  id: credential_exports.ID,
20248
- label: Schema_exports.String
20248
+ label: Schema_exports.String,
20249
+ /** How the credential was obtained: a stored key or an OAuth grant. */
20250
+ method: Schema_exports.Literals(["key", "oauth"])
20249
20251
  }).annotate({ identifier: "Connection.CredentialInfo" });
20250
20252
  var EnvInfo = Schema_exports.Struct({
20251
20253
  type: Schema_exports.Literal("env"),
@@ -20829,7 +20831,8 @@ var Commands = Schema_exports.Struct({
20829
20831
  }).annotate({ identifier: "Project.Commands" });
20830
20832
  var Time = Schema_exports.Struct({
20831
20833
  created: NonNegativeInt,
20832
- updated: NonNegativeInt
20834
+ updated: NonNegativeInt,
20835
+ active: NonNegativeInt
20833
20836
  }).annotate({ identifier: "Project.Time" });
20834
20837
  var Info10 = Schema_exports.Struct({
20835
20838
  id: ID10,
@@ -20872,6 +20875,7 @@ __export(session_event_exports, {
20872
20875
  InboxEnqueued: () => InboxEnqueued,
20873
20876
  InstructionsUpdated: () => InstructionsUpdated,
20874
20877
  MessageContentUpdated: () => MessageContentUpdated,
20878
+ MetadataUpdated: () => MetadataUpdated,
20875
20879
  ModelSelected: () => ModelSelected2,
20876
20880
  Moved: () => Moved,
20877
20881
  Permissions: () => Permissions,
@@ -21668,6 +21672,14 @@ var Renamed = event_exports.durable({
21668
21672
  title: Schema_exports.String
21669
21673
  }
21670
21674
  });
21675
+ var MetadataUpdated = event_exports.durable({
21676
+ type: "session.metadata.updated",
21677
+ ...options,
21678
+ schema: {
21679
+ ...Base4,
21680
+ metadata: SessionMetadata
21681
+ }
21682
+ });
21671
21683
  var Permissions = event_exports.durable({
21672
21684
  type: "session.permissions",
21673
21685
  ...options,
@@ -22110,7 +22122,7 @@ var RevertEvent;
22110
22122
  schema: { ...Base4, to: session_message_exports.ID }
22111
22123
  });
22112
22124
  })(RevertEvent || (RevertEvent = {}));
22113
- var Definitions = event_exports.inventory(Created4, AgentSelected2, ModelSelected2, Moved, Renamed, Permissions, Viewed, UsageUpdated, Deleted3, Forked, InboxDelivered, InboxEnqueued, InboxCancelled, InboxDeliveryChanged, Execution.Started, Execution.Succeeded, Execution.Failed, Execution.Interrupted, InstructionsUpdated, Synthetic3, Skill2.Activated, Shell2.Started, Shell2.Ended, Step.Started, Step.Streamed, Step.Ended, Step.Failed, Text.Started, Text.Delta, Text.Ended, Reasoning.Started, Reasoning.Delta, Reasoning.Ended, Tool.Input.Started, Tool.Input.Delta, Tool.Input.Ended, Tool.Called, Tool.Progress, Tool.Success, Tool.Failed, RetryScheduled, Compaction4.Started, Compaction4.Delta, Compaction4.Ended, Compaction4.Failed, RevertEvent.Staged, RevertEvent.Cleared, RevertEvent.Committed);
22125
+ var Definitions = event_exports.inventory(Created4, AgentSelected2, ModelSelected2, Moved, Renamed, MetadataUpdated, Permissions, Viewed, UsageUpdated, Deleted3, Forked, InboxDelivered, InboxEnqueued, InboxCancelled, InboxDeliveryChanged, Execution.Started, Execution.Succeeded, Execution.Failed, Execution.Interrupted, InstructionsUpdated, Synthetic3, Skill2.Activated, Shell2.Started, Shell2.Ended, Step.Started, Step.Streamed, Step.Ended, Step.Failed, Text.Started, Text.Delta, Text.Ended, Reasoning.Started, Reasoning.Delta, Reasoning.Ended, Tool.Input.Started, Tool.Input.Delta, Tool.Input.Ended, Tool.Called, Tool.Progress, Tool.Success, Tool.Failed, RetryScheduled, Compaction4.Started, Compaction4.Delta, Compaction4.Ended, Compaction4.Failed, RevertEvent.Staged, RevertEvent.Cleared, RevertEvent.Committed);
22114
22126
  var DurableDefinitions = event_exports.inventory(...Definitions.filter((definition) => definition.durability === "durable"), UsageRecorded, MessageContentUpdated);
22115
22127
  var EphemeralDefinitions = event_exports.inventory(...Definitions.filter((definition) => definition.durability === "ephemeral"));
22116
22128
  var Durable = Schema_exports.Union(DurableDefinitions, { mode: "oneOf" }).pipe(Schema_exports.toTaggedUnion("type")).annotate({ identifier: "Session.Event.Durable" });
@@ -18,9 +18,10 @@ async function harness() {
18
18
  environmentStatus: 204,
19
19
  beforeEnvironment: async () => { },
20
20
  afterEnvironment: () => { },
21
+ beforeInstructions: async () => { },
21
22
  current: true,
22
23
  };
23
- const upstream = Fastify();
24
+ const upstream = Fastify({ forceCloseConnections: true });
24
25
  apps.push(upstream);
25
26
  upstream.get("/api/session/:id", async (request) => {
26
27
  const { id } = request.params;
@@ -42,6 +43,9 @@ async function harness() {
42
43
  sends.push({ sessionID: id, variables: snapshots.get(id), body: request.body });
43
44
  return { data: [] };
44
45
  });
46
+ upstream.route({ method: ["PUT", "DELETE"], url: "/api/experimental/session/:id/instructions/entries/:key",
47
+ handler: async (_request, reply) => { await control.beforeInstructions(); return reply.code(204).send(); },
48
+ });
45
49
  await upstream.listen({ host: "127.0.0.1", port: 0 });
46
50
  const endpoint = { url: `http://127.0.0.1:${upstream.server.address().port}` };
47
51
  const assertCurrent = () => { if (!control.current)
@@ -110,6 +114,22 @@ test("waits for the environment acknowledgement before admitting a prompt", asyn
110
114
  assert.equal((await pending).statusCode, 200);
111
115
  assert.equal(sends.length, 1);
112
116
  });
117
+ test("advisory Git context timeout permits the send after successful environment synchronization", async () => {
118
+ const { app, control, sends, logs } = await harness();
119
+ let release;
120
+ control.beforeInstructions = () => new Promise(resolve => { release = resolve; });
121
+ try {
122
+ const started = Date.now();
123
+ const response = await app.inject({ method: "POST", url: `${prefix}one/prompt`, payload: { text: "hello" } });
124
+ assert.equal(response.statusCode, 200, response.body);
125
+ assert.ok(Date.now() - started < 10_000, "advisory deadline must not consume the environment timeout");
126
+ assert.equal(sends.length, 1);
127
+ assert.equal(logs.length, 0, "advisory timeout is not an environment failure");
128
+ }
129
+ finally {
130
+ release?.();
131
+ }
132
+ });
113
133
  test("unauthorized sessions and direct environment writes never set an environment", async () => {
114
134
  const { app, calls } = await harness();
115
135
  assert.equal((await app.inject({ method: "POST", url: `${prefix}foreign/prompt`, payload: { text: "no" } })).statusCode, 403);