context-mode 1.0.149 → 1.0.151
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/build/adapters/vscode-copilot/index.js +13 -1
- package/build/cache-heal.d.ts +48 -0
- package/build/cache-heal.js +150 -0
- package/build/opencode-plugin.js +5 -2
- package/build/routing-block.d.ts +8 -0
- package/build/routing-block.js +86 -0
- package/build/tool-naming.d.ts +4 -0
- package/build/tool-naming.js +24 -0
- package/build/util/plugin-cache-integrity.d.ts +14 -0
- package/build/util/plugin-cache-integrity.js +41 -0
- package/cli.bundle.mjs +126 -126
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +93 -93
- package/build/util/db-lock.d.ts +0 -65
- package/build/util/db-lock.js +0 -166
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "Claude Code plugins by Mert Koseoğlu",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.151"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "context-mode",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Claude Code MCP plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
16
|
-
"version": "1.0.
|
|
16
|
+
"version": "1.0.151",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Mert Koseoğlu"
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.151",
|
|
4
4
|
"description": "MCP server that saves 98% of your context window with session continuity. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and automatic state restore across compactions.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mert Koseoğlu",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.151",
|
|
4
4
|
"description": "MCP server that saves 98% of your context window with session continuity. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and automatic state restore across compactions.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mert Koseoğlu",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "Context Mode",
|
|
4
4
|
"kind": "tool",
|
|
5
5
|
"description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.151",
|
|
7
7
|
"sandbox": {
|
|
8
8
|
"mode": "permissive",
|
|
9
9
|
"filesystem_access": "full",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.151",
|
|
4
4
|
"description": "OpenClaw plugin that saves 98% of your context window. Sandboxed code execution in 11 languages, FTS5 knowledge base with BM25 ranking, and intent-driven search.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mert Koseoğlu",
|
|
@@ -43,7 +43,19 @@ export class VSCodeCopilotAdapter extends CopilotBaseAdapter {
|
|
|
43
43
|
return `pid-${process.ppid}`;
|
|
44
44
|
}
|
|
45
45
|
getProjectDir() {
|
|
46
|
-
|
|
46
|
+
// Cascade order (locked by tests/adapters/vscode-copilot.test.ts):
|
|
47
|
+
// 1. CLAUDE_PROJECT_DIR — top priority for users running VS Code under
|
|
48
|
+
// Claude Code CLI.
|
|
49
|
+
// 2. VSCODE_CWD — exported by VS Code's bootstrap into every child it
|
|
50
|
+
// spawns (refs/platforms/vscode-copilot/src/util/vs/base/common/
|
|
51
|
+
// process.ts:31). The MCP child inherits it. Was previously missing
|
|
52
|
+
// from this cascade — every direct VS Code Copilot session silently
|
|
53
|
+
// lost its workspace folder. PR #689 5-agent EM audit (Phase A
|
|
54
|
+
// claim verification) confirmed the gap; this is the minimal fix.
|
|
55
|
+
// 3. process.cwd() — last resort.
|
|
56
|
+
return (process.env.CLAUDE_PROJECT_DIR
|
|
57
|
+
|| process.env.VSCODE_CWD
|
|
58
|
+
|| process.cwd());
|
|
47
59
|
}
|
|
48
60
|
getSessionDir() {
|
|
49
61
|
// Issue #649: CONTEXT_MODE_DATA_DIR wins over both the .github project
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin cache self-heal — fixes broken CLAUDE_PLUGIN_ROOT references.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code's plugin auto-update can leave installed_plugins.json pointing
|
|
5
|
+
* to a non-existent directory (anthropics/claude-code#46915). This module
|
|
6
|
+
* detects and repairs the mismatch by creating symlinks.
|
|
7
|
+
*
|
|
8
|
+
* 4-layer defense:
|
|
9
|
+
* 1. start.mjs startup — reverse heal (registry → symlink to us)
|
|
10
|
+
* 2. server.ts first tool call — mid-session heal
|
|
11
|
+
* 3. postinstall.mjs — backward symlink on new install
|
|
12
|
+
* 4. global hook auto-deploy — survives total plugin cache breakage
|
|
13
|
+
*/
|
|
14
|
+
export interface HealResult {
|
|
15
|
+
healed: boolean;
|
|
16
|
+
action?: "symlink" | "global-hook" | "none";
|
|
17
|
+
from?: string;
|
|
18
|
+
to?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Core heal: if installed_plugins.json points to a non-existent directory,
|
|
22
|
+
* create a symlink from that path to our actual directory.
|
|
23
|
+
*
|
|
24
|
+
* @param currentDir - The directory we're actually running from
|
|
25
|
+
* @param installedPluginsPath - Path to installed_plugins.json (injectable for testing)
|
|
26
|
+
*/
|
|
27
|
+
export declare function healRegistryMismatch(currentDir: string, installedPluginsPath?: string): HealResult;
|
|
28
|
+
/**
|
|
29
|
+
* Deploy a global SessionStart hook that heals plugin cache mismatches.
|
|
30
|
+
* This hook lives outside the plugin directory, so it survives cache breakage.
|
|
31
|
+
*
|
|
32
|
+
* Written to ~/.claude/hooks/context-mode-cache-heal.sh
|
|
33
|
+
*/
|
|
34
|
+
export declare function deployGlobalHealHook(): HealResult;
|
|
35
|
+
/**
|
|
36
|
+
* Backward symlink: during postinstall, if the registry points to a
|
|
37
|
+
* non-existent OLD path, create a symlink from old → new (our directory).
|
|
38
|
+
* Same as healRegistryMismatch but called from postinstall context.
|
|
39
|
+
*/
|
|
40
|
+
export { healRegistryMismatch as healBackwardCompat };
|
|
41
|
+
/**
|
|
42
|
+
* Mid-session heal — call on first MCP tool invocation.
|
|
43
|
+
* Checks if registry path differs from our running directory.
|
|
44
|
+
* Creates symlink if needed. Runs only once per process.
|
|
45
|
+
*/
|
|
46
|
+
export declare function healMidSession(currentDir: string): HealResult;
|
|
47
|
+
/** Reset mid-session flag (for testing only) */
|
|
48
|
+
export declare function _resetMidSession(): void;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin cache self-heal — fixes broken CLAUDE_PLUGIN_ROOT references.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code's plugin auto-update can leave installed_plugins.json pointing
|
|
5
|
+
* to a non-existent directory (anthropics/claude-code#46915). This module
|
|
6
|
+
* detects and repairs the mismatch by creating symlinks.
|
|
7
|
+
*
|
|
8
|
+
* 4-layer defense:
|
|
9
|
+
* 1. start.mjs startup — reverse heal (registry → symlink to us)
|
|
10
|
+
* 2. server.ts first tool call — mid-session heal
|
|
11
|
+
* 3. postinstall.mjs — backward symlink on new install
|
|
12
|
+
* 4. global hook auto-deploy — survives total plugin cache breakage
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync, readFileSync, symlinkSync, mkdirSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { resolve, dirname } from "node:path";
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
/**
|
|
18
|
+
* Core heal: if installed_plugins.json points to a non-existent directory,
|
|
19
|
+
* create a symlink from that path to our actual directory.
|
|
20
|
+
*
|
|
21
|
+
* @param currentDir - The directory we're actually running from
|
|
22
|
+
* @param installedPluginsPath - Path to installed_plugins.json (injectable for testing)
|
|
23
|
+
*/
|
|
24
|
+
export function healRegistryMismatch(currentDir, installedPluginsPath) {
|
|
25
|
+
const ipPath = installedPluginsPath ?? resolve(homedir(), ".claude", "plugins", "installed_plugins.json");
|
|
26
|
+
if (!existsSync(ipPath))
|
|
27
|
+
return { healed: false, action: "none" };
|
|
28
|
+
if (!existsSync(currentDir))
|
|
29
|
+
return { healed: false, action: "none" };
|
|
30
|
+
let ip;
|
|
31
|
+
try {
|
|
32
|
+
ip = JSON.parse(readFileSync(ipPath, "utf-8"));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { healed: false, action: "none" };
|
|
36
|
+
}
|
|
37
|
+
for (const [key, entries] of Object.entries(ip.plugins ?? {})) {
|
|
38
|
+
if (!key.toLowerCase().includes("context-mode"))
|
|
39
|
+
continue;
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
const registryPath = entry.installPath;
|
|
42
|
+
if (!registryPath)
|
|
43
|
+
continue;
|
|
44
|
+
// Registry path exists — no healing needed
|
|
45
|
+
if (existsSync(registryPath))
|
|
46
|
+
continue;
|
|
47
|
+
// Registry path doesn't exist — create symlink to our directory
|
|
48
|
+
try {
|
|
49
|
+
const parent = dirname(registryPath);
|
|
50
|
+
if (!existsSync(parent))
|
|
51
|
+
mkdirSync(parent, { recursive: true });
|
|
52
|
+
if (process.platform === "win32") {
|
|
53
|
+
// Windows: use junction (no admin required)
|
|
54
|
+
symlinkSync(currentDir, registryPath, "junction");
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
symlinkSync(currentDir, registryPath);
|
|
58
|
+
}
|
|
59
|
+
return { healed: true, action: "symlink", from: registryPath, to: currentDir };
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return { healed: false, action: "none" };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { healed: false, action: "none" };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Deploy a global SessionStart hook that heals plugin cache mismatches.
|
|
70
|
+
* This hook lives outside the plugin directory, so it survives cache breakage.
|
|
71
|
+
*
|
|
72
|
+
* Written to ~/.claude/hooks/context-mode-cache-heal.sh
|
|
73
|
+
*/
|
|
74
|
+
export function deployGlobalHealHook() {
|
|
75
|
+
const hooksDir = resolve(homedir(), ".claude", "hooks");
|
|
76
|
+
const hookPath = resolve(hooksDir, "context-mode-cache-heal.sh");
|
|
77
|
+
// Already deployed
|
|
78
|
+
if (existsSync(hookPath))
|
|
79
|
+
return { healed: false, action: "none" };
|
|
80
|
+
try {
|
|
81
|
+
if (!existsSync(hooksDir))
|
|
82
|
+
mkdirSync(hooksDir, { recursive: true });
|
|
83
|
+
const script = `#!/usr/bin/env bash
|
|
84
|
+
# context-mode plugin cache self-heal — auto-deployed by context-mode MCP server
|
|
85
|
+
# Fixes anthropics/claude-code#46915: auto-update breaks CLAUDE_PLUGIN_ROOT
|
|
86
|
+
# This hook runs at SessionStart (global, not plugin-level) so it works even
|
|
87
|
+
# when the plugin cache is broken.
|
|
88
|
+
|
|
89
|
+
set -euo pipefail
|
|
90
|
+
|
|
91
|
+
PLUGINS_FILE="$HOME/.claude/plugins/installed_plugins.json"
|
|
92
|
+
[[ -f "$PLUGINS_FILE" ]] || exit 0
|
|
93
|
+
|
|
94
|
+
# Find context-mode entries and heal missing directories
|
|
95
|
+
node -e '
|
|
96
|
+
const fs = require("fs");
|
|
97
|
+
const path = require("path");
|
|
98
|
+
try {
|
|
99
|
+
const ip = JSON.parse(fs.readFileSync(process.argv[1], "utf-8"));
|
|
100
|
+
for (const [key, entries] of Object.entries(ip.plugins || {})) {
|
|
101
|
+
if (!key.toLowerCase().includes("context-mode")) continue;
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
const p = entry.installPath;
|
|
104
|
+
if (!p || fs.existsSync(p)) continue;
|
|
105
|
+
const parent = path.dirname(p);
|
|
106
|
+
if (!fs.existsSync(parent)) continue;
|
|
107
|
+
const dirs = fs.readdirSync(parent).filter(d => /^\\d+\\.\\d+/.test(d) && fs.statSync(path.join(parent, d)).isDirectory());
|
|
108
|
+
if (dirs.length === 0) continue;
|
|
109
|
+
dirs.sort((a, b) => {
|
|
110
|
+
const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
|
|
111
|
+
for (let i = 0; i < 3; i++) { if ((pa[i]||0) !== (pb[i]||0)) return (pa[i]||0) - (pb[i]||0); }
|
|
112
|
+
return 0;
|
|
113
|
+
});
|
|
114
|
+
const target = path.join(parent, dirs[dirs.length - 1]);
|
|
115
|
+
try { fs.symlinkSync(target, p); } catch {}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch {}
|
|
119
|
+
' "$PLUGINS_FILE" 2>/dev/null || true
|
|
120
|
+
`;
|
|
121
|
+
writeFileSync(hookPath, script, { mode: 0o755 });
|
|
122
|
+
return { healed: true, action: "global-hook", from: hookPath };
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return { healed: false, action: "none" };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Backward symlink: during postinstall, if the registry points to a
|
|
130
|
+
* non-existent OLD path, create a symlink from old → new (our directory).
|
|
131
|
+
* Same as healRegistryMismatch but called from postinstall context.
|
|
132
|
+
*/
|
|
133
|
+
export { healRegistryMismatch as healBackwardCompat };
|
|
134
|
+
/** One-shot flag for mid-session heal in server.ts */
|
|
135
|
+
let _midSessionHealed = false;
|
|
136
|
+
/**
|
|
137
|
+
* Mid-session heal — call on first MCP tool invocation.
|
|
138
|
+
* Checks if registry path differs from our running directory.
|
|
139
|
+
* Creates symlink if needed. Runs only once per process.
|
|
140
|
+
*/
|
|
141
|
+
export function healMidSession(currentDir) {
|
|
142
|
+
if (_midSessionHealed)
|
|
143
|
+
return { healed: false, action: "none" };
|
|
144
|
+
_midSessionHealed = true;
|
|
145
|
+
return healRegistryMismatch(currentDir);
|
|
146
|
+
}
|
|
147
|
+
/** Reset mid-session flag (for testing only) */
|
|
148
|
+
export function _resetMidSession() {
|
|
149
|
+
_midSessionHealed = false;
|
|
150
|
+
}
|
package/build/opencode-plugin.js
CHANGED
|
@@ -179,7 +179,7 @@ async function createContextModePlugin(ctx) {
|
|
|
179
179
|
const toolInput = output.args ?? {};
|
|
180
180
|
let decision;
|
|
181
181
|
try {
|
|
182
|
-
decision = routing.routePreToolUse(toolName, toolInput, projectDir,
|
|
182
|
+
decision = routing.routePreToolUse(toolName, toolInput, projectDir, platform);
|
|
183
183
|
}
|
|
184
184
|
catch {
|
|
185
185
|
return; // Routing failure → allow passthrough
|
|
@@ -194,7 +194,10 @@ async function createContextModePlugin(ctx) {
|
|
|
194
194
|
// Mutate output.args — OpenCode reads the mutated output object
|
|
195
195
|
Object.assign(output.args, decision.updatedInput);
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
if (decision.action === "context" && decision.additionalContext) {
|
|
198
|
+
// Mutate output.args — OpenCode reads the mutated output object
|
|
199
|
+
output.args.additionalContext = decision.additionalContext;
|
|
200
|
+
}
|
|
198
201
|
},
|
|
199
202
|
// ── PostToolUse: Session event capture ──────────────
|
|
200
203
|
"tool.execute.after": async (input, output) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolNamer } from "./tool-naming.js";
|
|
2
|
+
export interface RoutingBlockOptions {
|
|
3
|
+
includeCommands?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function createRoutingBlock(t: ToolNamer, options?: RoutingBlockOptions): string;
|
|
6
|
+
export declare function createReadGuidance(t: ToolNamer): string;
|
|
7
|
+
export declare function createGrepGuidance(t: ToolNamer): string;
|
|
8
|
+
export declare function createBashGuidance(t: ToolNamer): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export function createRoutingBlock(t, options = {}) {
|
|
2
|
+
const { includeCommands = true } = options;
|
|
3
|
+
return `
|
|
4
|
+
<context_window_protection>
|
|
5
|
+
<priority_instructions>
|
|
6
|
+
Raw tool output floods context window. MUST use context-mode MCP tools. Keep raw data in sandbox.
|
|
7
|
+
</priority_instructions>
|
|
8
|
+
|
|
9
|
+
<tool_selection_hierarchy>
|
|
10
|
+
0. MEMORY: ${t("ctx_search")}(sort: "timeline")
|
|
11
|
+
- After resume, check prior context before asking user.
|
|
12
|
+
1. GATHER: ${t("ctx_batch_execute")}(commands, queries)
|
|
13
|
+
- Primary research tool. Runs commands, auto-indexes, searches. ONE call replaces many steps.
|
|
14
|
+
- Each command: {label: "section header", command: "shell command"}
|
|
15
|
+
- label becomes FTS5 chunk title — descriptive labels improve search.
|
|
16
|
+
2. FOLLOW-UP: ${t("ctx_search")}(queries: ["q1", "q2", ...])
|
|
17
|
+
- All follow-up questions. ONE call, many queries (default relevance mode).
|
|
18
|
+
3. PROCESSING: ${t("ctx_execute")}(language, code) | ${t("ctx_execute_file")}(path, language, code)
|
|
19
|
+
- API calls, log analysis, data processing.
|
|
20
|
+
</tool_selection_hierarchy>
|
|
21
|
+
|
|
22
|
+
<forbidden_actions>
|
|
23
|
+
- NO Bash for commands producing >20 lines output.
|
|
24
|
+
- NO Read for analysis — use execute_file. Read IS correct for files you intend to Edit.
|
|
25
|
+
- NO WebFetch — use ${t("ctx_fetch_and_index")}.
|
|
26
|
+
- Bash ONLY for git/mkdir/rm/mv/navigation.
|
|
27
|
+
- NO ${t("ctx_execute")} or ${t("ctx_execute_file")} for file creation/modification.
|
|
28
|
+
ctx_execute is for analysis, processing, computation only.
|
|
29
|
+
</forbidden_actions>
|
|
30
|
+
|
|
31
|
+
<file_writing_policy>
|
|
32
|
+
ALWAYS use native Write/Edit tools for file creation/modification.
|
|
33
|
+
NEVER use ${t("ctx_execute")}, ${t("ctx_execute_file")}, or Bash to write files.
|
|
34
|
+
Applies to all file types: code, configs, plans, specs, YAML, JSON, markdown.
|
|
35
|
+
</file_writing_policy>
|
|
36
|
+
|
|
37
|
+
<output_constraints>
|
|
38
|
+
<communication_style>
|
|
39
|
+
Terse like caveman. Technical substance exact. Only fluff die.
|
|
40
|
+
Use fragments when clear. Short synonyms (fix not "implement a solution for").
|
|
41
|
+
Technical terms exact. Code blocks unchanged.
|
|
42
|
+
Auto-expand for: security warnings, irreversible actions, user confusion.
|
|
43
|
+
</communication_style>
|
|
44
|
+
<artifact_policy>
|
|
45
|
+
Write artifacts (code, configs, PRDs) to FILES. NEVER inline.
|
|
46
|
+
Return only: file path + 1-line description.
|
|
47
|
+
</artifact_policy>
|
|
48
|
+
<response_format>
|
|
49
|
+
Concise summary:
|
|
50
|
+
- Actions taken (2-3 bullets)
|
|
51
|
+
- File paths created/modified
|
|
52
|
+
- Key findings
|
|
53
|
+
</response_format>
|
|
54
|
+
</output_constraints>
|
|
55
|
+
<session_continuity>
|
|
56
|
+
Skills, roles, and decisions set during this session remain active until the user revokes them.
|
|
57
|
+
Do not drop behavioral directives as context grows.
|
|
58
|
+
</session_continuity>
|
|
59
|
+
${includeCommands ? `
|
|
60
|
+
<ctx_commands>
|
|
61
|
+
"ctx stats" | "ctx-stats" | "/ctx-stats" | context savings question
|
|
62
|
+
→ Call stats MCP tool, display full output verbatim.
|
|
63
|
+
|
|
64
|
+
"ctx doctor" | "ctx-doctor" | "/ctx-doctor" | diagnose context-mode
|
|
65
|
+
→ Call doctor MCP tool, run returned shell command, display as checklist.
|
|
66
|
+
|
|
67
|
+
"ctx upgrade" | "ctx-upgrade" | "/ctx-upgrade" | update context-mode
|
|
68
|
+
→ Call upgrade MCP tool, run returned shell command, display as checklist.
|
|
69
|
+
|
|
70
|
+
"ctx purge" | "ctx-purge" | "/ctx-purge" | wipe/reset knowledge base
|
|
71
|
+
→ Call purge MCP tool with confirm: true. Warn: irreversible.
|
|
72
|
+
|
|
73
|
+
After /clear or /compact: knowledge base preserved. Tell user: "context-mode knowledge base preserved. Use \`ctx purge\` to start fresh."
|
|
74
|
+
</ctx_commands>
|
|
75
|
+
` : ''}
|
|
76
|
+
</context_window_protection>`;
|
|
77
|
+
}
|
|
78
|
+
export function createReadGuidance(t) {
|
|
79
|
+
return '<context_guidance>\n <tip>\n Reading to Edit? Read is correct — Edit needs content in context.\n Reading to analyze/explore? Use ' + t("ctx_execute_file") + '(path, language, code) — only printed summary enters context.\n </tip>\n</context_guidance>';
|
|
80
|
+
}
|
|
81
|
+
export function createGrepGuidance(t) {
|
|
82
|
+
return '<context_guidance>\n <tip>\n May flood context. Use ' + t("ctx_execute") + '(language: "shell", code: "...") to run searches in sandbox. Only printed summary enters context.\n </tip>\n</context_guidance>';
|
|
83
|
+
}
|
|
84
|
+
export function createBashGuidance(t) {
|
|
85
|
+
return '<context_guidance>\n <tip>\n May produce large output. Use ' + t("ctx_batch_execute") + '(commands, queries) for multiple commands, ' + t("ctx_execute") + '(language: "shell", code: "...") for single. Only printed summary enters context. Bash only for: git, mkdir, rm, mv, navigation.\n </tip>\n</context_guidance>';
|
|
86
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const TOOL_PREFIXES = {
|
|
2
|
+
"claude-code": (tool) => `mcp__plugin_context-mode_context-mode__${tool}`,
|
|
3
|
+
"gemini-cli": (tool) => `mcp__context-mode__${tool}`,
|
|
4
|
+
"antigravity": (tool) => `mcp__context-mode__${tool}`,
|
|
5
|
+
"opencode": (tool) => `context-mode_${tool}`,
|
|
6
|
+
"kilo": (tool) => `context-mode_${tool}`,
|
|
7
|
+
"vscode-copilot": (tool) => `context-mode_${tool}`,
|
|
8
|
+
"jetbrains-copilot": (tool) => `context-mode_${tool}`,
|
|
9
|
+
"kiro": (tool) => `@context-mode/${tool}`,
|
|
10
|
+
"zed": (tool) => `mcp:context-mode:${tool}`,
|
|
11
|
+
"cursor": (tool) => tool,
|
|
12
|
+
"codex": (tool) => tool,
|
|
13
|
+
"openclaw": (tool) => tool,
|
|
14
|
+
"pi": (tool) => tool,
|
|
15
|
+
"qwen-code": (tool) => `mcp__context-mode__${tool}`,
|
|
16
|
+
};
|
|
17
|
+
export function getToolName(platform, bareTool) {
|
|
18
|
+
const fn = TOOL_PREFIXES[platform] || TOOL_PREFIXES["claude-code"];
|
|
19
|
+
return fn(bareTool);
|
|
20
|
+
}
|
|
21
|
+
export function createToolNamer(platform) {
|
|
22
|
+
return (bareTool) => getToolName(platform, bareTool);
|
|
23
|
+
}
|
|
24
|
+
export const KNOWN_PLATFORMS = Object.keys(TOOL_PREFIXES);
|
|
@@ -22,6 +22,20 @@
|
|
|
22
22
|
* (package.json files[]); a missing helper means the install is
|
|
23
23
|
* fundamentally broken.
|
|
24
24
|
*/
|
|
25
|
+
/**
|
|
26
|
+
* Files `start.mjs` needs to launch the MCP server, checked dependency-free
|
|
27
|
+
* (fs only) so this works even when the integrity helper
|
|
28
|
+
* (`scripts/plugin-cache-integrity.mjs`) is itself missing — a missing helper
|
|
29
|
+
* is itself a partial-install symptom, and the operator most needs to know
|
|
30
|
+
* whether the launch entrypoint survived.
|
|
31
|
+
*
|
|
32
|
+
* - `start.mjs` is the plugin `command` target (`.claude-plugin/plugin.json`)
|
|
33
|
+
* and has NO fallback: if absent, `node ${CLAUDE_PLUGIN_ROOT}/start.mjs`
|
|
34
|
+
* fails immediately and the MCP server never starts.
|
|
35
|
+
* - The server is loaded by start.mjs from `server.bundle.mjs`, falling back
|
|
36
|
+
* to `build/server.js`; it is only "missing" when BOTH are absent.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findMissingLaunchFiles(pluginRoot: string): string[];
|
|
25
39
|
/**
|
|
26
40
|
* Run the integrity check synchronously. If the helper module is
|
|
27
41
|
* still loading (not yet cached) returns a FAIL with detail
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* (package.json files[]); a missing helper means the install is
|
|
23
23
|
* fundamentally broken.
|
|
24
24
|
*/
|
|
25
|
+
import { existsSync } from "node:fs";
|
|
26
|
+
import { join } from "node:path";
|
|
25
27
|
let cached = null;
|
|
26
28
|
let cachedError = null;
|
|
27
29
|
async function loadHelper() {
|
|
@@ -67,6 +69,30 @@ async function loadHelper() {
|
|
|
67
69
|
// intentionally — by the time any HealthCheck.check() runs (doctor
|
|
68
70
|
// command, well after MCP server boot), the import has resolved.
|
|
69
71
|
void loadHelper();
|
|
72
|
+
/**
|
|
73
|
+
* Files `start.mjs` needs to launch the MCP server, checked dependency-free
|
|
74
|
+
* (fs only) so this works even when the integrity helper
|
|
75
|
+
* (`scripts/plugin-cache-integrity.mjs`) is itself missing — a missing helper
|
|
76
|
+
* is itself a partial-install symptom, and the operator most needs to know
|
|
77
|
+
* whether the launch entrypoint survived.
|
|
78
|
+
*
|
|
79
|
+
* - `start.mjs` is the plugin `command` target (`.claude-plugin/plugin.json`)
|
|
80
|
+
* and has NO fallback: if absent, `node ${CLAUDE_PLUGIN_ROOT}/start.mjs`
|
|
81
|
+
* fails immediately and the MCP server never starts.
|
|
82
|
+
* - The server is loaded by start.mjs from `server.bundle.mjs`, falling back
|
|
83
|
+
* to `build/server.js`; it is only "missing" when BOTH are absent.
|
|
84
|
+
*/
|
|
85
|
+
export function findMissingLaunchFiles(pluginRoot) {
|
|
86
|
+
const missing = [];
|
|
87
|
+
if (!existsSync(join(pluginRoot, "start.mjs"))) {
|
|
88
|
+
missing.push("start.mjs");
|
|
89
|
+
}
|
|
90
|
+
if (!existsSync(join(pluginRoot, "server.bundle.mjs")) &&
|
|
91
|
+
!existsSync(join(pluginRoot, "build", "server.js"))) {
|
|
92
|
+
missing.push("server.bundle.mjs (or build/server.js)");
|
|
93
|
+
}
|
|
94
|
+
return missing;
|
|
95
|
+
}
|
|
70
96
|
/**
|
|
71
97
|
* Run the integrity check synchronously. If the helper module is
|
|
72
98
|
* still loading (not yet cached) returns a FAIL with detail
|
|
@@ -89,6 +115,21 @@ export function checkPluginCacheIntegritySync(pluginRoot) {
|
|
|
89
115
|
};
|
|
90
116
|
}
|
|
91
117
|
if (cachedError) {
|
|
118
|
+
// The integrity helper (scripts/plugin-cache-integrity.mjs) ships in
|
|
119
|
+
// package.json files[]; if it failed to load, the install is already
|
|
120
|
+
// partial. Don't stop at "helper unavailable" — directly surface whether
|
|
121
|
+
// the launch entrypoint survived, because a missing start.mjs / server
|
|
122
|
+
// bundle is exactly what stops the MCP server from starting (and is what
|
|
123
|
+
// an interrupted /ctx-upgrade swap leaves behind).
|
|
124
|
+
const launchMissing = findMissingLaunchFiles(pluginRoot);
|
|
125
|
+
if (launchMissing.length > 0) {
|
|
126
|
+
return {
|
|
127
|
+
status: "FAIL",
|
|
128
|
+
detail: `partial install — critical launch files missing: ${launchMissing.join(", ")} ` +
|
|
129
|
+
`(integrity helper also missing: ${cachedError}); the MCP server cannot start. ` +
|
|
130
|
+
`Reinstall: npm install -g context-mode@latest`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
92
133
|
return {
|
|
93
134
|
status: "FAIL",
|
|
94
135
|
detail: `integrity helper unavailable: ${cachedError}`,
|