context-mode 1.0.112 → 1.0.114

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/start.mjs CHANGED
@@ -9,15 +9,27 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
9
9
  const originalCwd = process.cwd();
10
10
  process.chdir(__dirname);
11
11
 
12
- if (!process.env.CLAUDE_PROJECT_DIR) {
13
- process.env.CLAUDE_PROJECT_DIR = originalCwd;
12
+ // Plugin-install-path guard (mirror of src/util/project-dir.ts isPluginInstallPath
13
+ // — duplicated here because start.mjs ships as raw JS and cannot import TS).
14
+ // When Claude Code runs `/ctx-upgrade` it kills + respawns the MCP server with
15
+ // `cwd` pointing at the plugin install dir. Setting CLAUDE_PROJECT_DIR from
16
+ // that path then poisons every downstream ctx_stats / SessionDB / hash
17
+ // computation — sessions silently re-root under the plugin install dir. Skip
18
+ // the env auto-set in that case; getProjectDir() defends a second time inside
19
+ // server.ts via resolveProjectDir(). See src/util/project-dir.ts.
20
+ const isPluginInstallPath = (p) =>
21
+ /[/\\]\.claude[/\\]plugins[/\\](cache|marketplaces)[/\\]/.test(p);
22
+ const safeOriginalCwd = isPluginInstallPath(originalCwd) ? null : originalCwd;
23
+
24
+ if (!process.env.CLAUDE_PROJECT_DIR && safeOriginalCwd) {
25
+ process.env.CLAUDE_PROJECT_DIR = safeOriginalCwd;
14
26
  }
15
27
 
16
28
  // Platform-agnostic project dir — guaranteed to be set for ALL platforms.
17
29
  // Adapters may set their own env var (GEMINI_PROJECT_DIR, etc.) but this
18
30
  // is the universal fallback so server.ts getProjectDir() never relies on cwd().
19
- if (!process.env.CONTEXT_MODE_PROJECT_DIR) {
20
- process.env.CONTEXT_MODE_PROJECT_DIR = originalCwd;
31
+ if (!process.env.CONTEXT_MODE_PROJECT_DIR && safeOriginalCwd) {
32
+ process.env.CONTEXT_MODE_PROJECT_DIR = safeOriginalCwd;
21
33
  }
22
34
 
23
35
  // Routing instructions file auto-write DISABLED for all platforms (#158, #164).
@@ -96,6 +108,32 @@ if (cacheMatch) {
96
108
  }
97
109
  }
98
110
 
111
+ // ── Self-heal Layer 3 + 4: installed_plugins.json registry repair ──
112
+ // v1.0.113 hotfix follow-up. /ctx-upgrade can leave installed_plugins.json
113
+ // with two distinct kinds of poison:
114
+ // HEAL 3: per-entry `version` drifts away from the actual cache dir's
115
+ // plugin.json `version` field. Claude Code's plugin loader then
116
+ // rejects the entry as a manifest mismatch and silently
117
+ // disconnects context-mode.
118
+ // HEAL 4: top-level `enabledPlugins[<key>]` is missing or emptied.
119
+ // Claude Code skips disabled plugins, so MCP never starts and
120
+ // the user has no /ctx-upgrade escape hatch.
121
+ // Logic is shared verbatim with scripts/postinstall.mjs (single source of
122
+ // truth) so users who fix themselves via `npm install -g context-mode`
123
+ // follow the exact same code path. Best-effort, never blocks MCP boot.
124
+ try {
125
+ const { healInstalledPlugins } = await import("./scripts/heal-installed-plugins.mjs");
126
+ const registryPath = resolve(homedir(), ".claude", "plugins", "installed_plugins.json");
127
+ const pluginCacheRoot = resolve(homedir(), ".claude", "plugins", "cache");
128
+ try {
129
+ healInstalledPlugins({
130
+ registryPath,
131
+ pluginCacheRoot,
132
+ pluginKey: "context-mode@context-mode",
133
+ });
134
+ } catch { /* best effort — never block MCP boot */ }
135
+ } catch { /* best effort — never block MCP boot */ }
136
+
99
137
  // ── Self-heal Layer 4: Deploy global SessionStart hook + register in settings.json ──
100
138
  // This hook lives outside the plugin directory (~/.claude/hooks/) so it works
101
139
  // even when the plugin cache is completely broken. It creates symlinks for any