context-mode 1.0.41 → 1.0.42

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
@@ -56,71 +56,14 @@ if (!process.env.CLAUDE_PROJECT_DIR) {
56
56
  process.env.CLAUDE_PROJECT_DIR = originalCwd;
57
57
  }
58
58
 
59
- // Auto-write routing instructions file for NON-hook-capable platforms only.
60
- // Hook-capable platforms (Claude Code, Gemini CLI, VS Code Copilot, OpenCode, OpenClaw)
61
- // inject routing via SessionStart hook writing to disk dirties the git tree (#158).
62
- // server.ts also guards this with adapter.capabilities.sessionStart.
63
- try {
64
- // Hook-capable platforms set these env vars — skip file write for them.
65
- // Uses verified env vars from src/adapters/detect.ts (not invented session IDs).
66
- const hookCapableSessionVars = [
67
- "CLAUDE_SESSION_ID", // Claude Code
68
- "GEMINI_PROJECT_DIR", // Gemini CLI (GEMINI_CLI also valid)
69
- "OPENCODE", // OpenCode (OPENCODE_PID also valid)
70
- "OPENCLAW_HOME", // OpenClaw (user-set home dir)
71
- "OPENCLAW_CLI", // OpenClaw (set at runtime by openclaw CLI)
72
- // VS Code Copilot: VSCODE_PID is too broad (set for ALL VS Code extensions).
73
- // Accept occasional harmless write rather than false-positive suppression.
74
- ];
75
- const hasHookSupport = hookCapableSessionVars.some((e) => process.env[e]);
76
-
77
- if (!hasHookSupport) {
78
- const projectDir =
79
- process.env.CLAUDE_PROJECT_DIR ||
80
- process.env.GEMINI_PROJECT_DIR ||
81
- process.env.VSCODE_CWD ||
82
- process.cwd();
83
-
84
- const configsDir = resolve(__dirname, "configs");
85
-
86
- // Detect platform and determine instruction file
87
- const platformConfigs = [
88
- { env: ["CLAUDE_PROJECT_DIR"], dir: "claude-code", file: "CLAUDE.md", target: "CLAUDE.md" },
89
- { env: ["GEMINI_PROJECT_DIR"], dir: "gemini-cli", file: "GEMINI.md", target: "GEMINI.md" },
90
- { env: ["VSCODE_CWD"], dir: "vscode-copilot", file: "copilot-instructions.md", target: ".github/copilot-instructions.md" },
91
- { env: ["OPENCODE_PROJECT_DIR"], dir: "opencode", file: "AGENTS.md", target: "AGENTS.md" },
92
- { env: ["OPENCLAW_HOME"], dir: "openclaw", file: "AGENTS.md", target: "AGENTS.md" },
93
- { env: ["CODEX_HOME"], dir: "codex", file: "AGENTS.md", target: "AGENTS.md" },
94
- ];
95
-
96
- const detected = platformConfigs.find((p) => p.env.some((e) => process.env[e]));
97
- if (detected) {
98
- const targetPath = resolve(projectDir, detected.target);
99
- const sourcePath = resolve(configsDir, detected.dir, detected.file);
100
-
101
- // Ensure parent dir exists (for .github/copilot-instructions.md)
102
- const targetDir = resolve(targetPath, "..");
103
- if (!existsSync(targetDir)) {
104
- const { mkdirSync } = await import("node:fs");
105
- mkdirSync(targetDir, { recursive: true });
106
- }
107
-
108
- if (existsSync(sourcePath)) {
109
- const content = readFileSync(sourcePath, "utf-8");
110
- if (existsSync(targetPath)) {
111
- const existing = readFileSync(targetPath, "utf-8");
112
- if (!existing.includes("context-mode")) {
113
- writeFileSync(targetPath, existing.trimEnd() + "\n\n" + content, "utf-8");
114
- }
115
- } else {
116
- writeFileSync(targetPath, content, "utf-8");
117
- }
118
- }
119
- }
120
- }
121
- } catch {
122
- /* best effort — don't block server startup */
123
- }
59
+ // Routing instructions file auto-write DISABLED for all platforms (#158, #164).
60
+ // Env vars like CLAUDE_SESSION_ID may not be set at MCP startup time, making
61
+ // the hook-capability guard unreliable. Writing to project dirs dirties git trees
62
+ // and causes double context injection on hook-capable platforms.
63
+ // Routing is handled by:
64
+ // - Hook-capable platforms: SessionStart hook injects ROUTING_BLOCK
65
+ // - Non-hook platforms: server.ts writeRoutingInstructions() on MCP connect
66
+ // - Future: explicit `context-mode init` command
124
67
 
125
68
  // Self-heal: if a newer version dir exists, update registry so next session uses it
126
69
  const cacheMatch = __dirname.match(