context-mode 1.0.122 → 1.0.124

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.
@@ -1,5 +1,32 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
+ import { workspaceEnvVarsFor } from "../adapters/detect.js";
4
+ /**
5
+ * Universal escape hatch. NEVER appears in any platform's foreignWorkspaceEnv()
6
+ * (because it isn't registered in PLATFORM_ENV_VARS), so it survives strict
7
+ * mode and bridge env scrubs. Documented as the cross-strict user override
8
+ * for every adapter (set in `~/.<host>/mcp.json` env when nothing else works).
9
+ */
10
+ const UNIVERSAL_WORKSPACE_ENV = ["CONTEXT_MODE_PROJECT_DIR"];
11
+ /**
12
+ * Frozen legacy candidate list — preserves bit-for-bit behavior of every
13
+ * non-strict caller (`start.mjs` and any caller that doesn't pass
14
+ * `strictPlatform`). Order is locked for semver compatibility.
15
+ *
16
+ * If a new adapter is added, DO NOT add its workspace var here — register it
17
+ * in `PLATFORM_ENV_VARS` and let strict callers pick it up via
18
+ * `workspaceEnvVarsFor(platform)`. Strict mode is the default forward path.
19
+ */
20
+ const LEGACY_NON_STRICT_CANDIDATES = [
21
+ "CLAUDE_PROJECT_DIR",
22
+ "GEMINI_PROJECT_DIR",
23
+ "VSCODE_CWD",
24
+ "OPENCODE_PROJECT_DIR",
25
+ "PI_PROJECT_DIR",
26
+ "IDEA_INITIAL_DIRECTORY",
27
+ "CURSOR_CWD",
28
+ "CONTEXT_MODE_PROJECT_DIR",
29
+ ];
3
30
  /**
4
31
  * Project-dir resolution helpers — shared between `start.mjs` (the MCP entry
5
32
  * point) and `src/server.ts getProjectDir()` (the consumer).
@@ -145,26 +172,17 @@ export function resolveProjectDirFromTranscript(opts) {
145
172
  * operation of project-independent tools (sandbox execute, fetch).
146
173
  */
147
174
  export function resolveProjectDir(opts) {
148
- const { env, cwd, pwd, transcriptsRoot } = opts;
149
- const candidates = [
150
- env.CLAUDE_PROJECT_DIR,
151
- env.GEMINI_PROJECT_DIR,
152
- env.VSCODE_CWD,
153
- env.OPENCODE_PROJECT_DIR,
154
- env.PI_PROJECT_DIR,
155
- env.IDEA_INITIAL_DIRECTORY,
156
- // Issue #521: Cursor MCP env override. The cursor adapter already
157
- // trusts CURSOR_CWD for hook input resolution (adapters/cursor/index.ts:581);
158
- // mirror that trust here so ctx_stats / SessionDB / hash see the workspace
159
- // path on Cursor. Whether Cursor itself sets this on MCP child spawn is
160
- // unconfirmed — but documenting it as a supported override gives users a
161
- // documented escape hatch (`~/.cursor/mcp.json` env: { CURSOR_CWD: "..." }).
162
- env.CURSOR_CWD,
163
- env.CONTEXT_MODE_PROJECT_DIR,
164
- ];
165
- for (const c of candidates) {
166
- if (c && !isPluginInstallPath(c))
167
- return c;
175
+ const { env, cwd, pwd, transcriptsRoot, strictPlatform } = opts;
176
+ // Build candidate list. Strict path: own workspace vars + universal escape
177
+ // hatch — NO foreign workspace vars, in any order, can win. Non-strict
178
+ // path: frozen legacy literal order for backwards compatibility.
179
+ const candidateVars = strictPlatform
180
+ ? [...workspaceEnvVarsFor(strictPlatform), ...UNIVERSAL_WORKSPACE_ENV]
181
+ : LEGACY_NON_STRICT_CANDIDATES;
182
+ for (const name of candidateVars) {
183
+ const v = env[name];
184
+ if (v && !isPluginInstallPath(v))
185
+ return v;
168
186
  }
169
187
  if (transcriptsRoot) {
170
188
  const fromTranscript = resolveProjectDirFromTranscript({ projectsRoot: transcriptsRoot });