context-mode 1.0.112 → 1.0.113
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/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/build/server.js +10 -8
- package/build/util/project-dir.d.ts +49 -0
- package/build/util/project-dir.js +67 -0
- package/cli.bundle.mjs +90 -90
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +73 -73
- package/start.mjs +16 -4
|
@@ -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.113"
|
|
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.113",
|
|
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.113",
|
|
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.113",
|
|
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.113",
|
|
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",
|
package/build/server.js
CHANGED
|
@@ -27,6 +27,7 @@ import { detectPlatform, getSessionDirSegments } from "./adapters/detect.js";
|
|
|
27
27
|
import { resolveCodexConfigDir } from "./adapters/codex/paths.js";
|
|
28
28
|
import { getHookScriptPaths } from "./util/hook-config.js";
|
|
29
29
|
import { resolveClaudeConfigDir } from "./util/claude-config.js";
|
|
30
|
+
import { resolveProjectDir } from "./util/project-dir.js";
|
|
30
31
|
import { loadDatabase } from "./db-base.js";
|
|
31
32
|
import { AnalyticsEngine, formatReport, getConversationStats, getLifetimeStats, getMultiAdapterLifetimeStats, getRealBytesStats, OPUS_INPUT_PRICE_PER_TOKEN } from "./session/analytics.js";
|
|
32
33
|
const __pkg_dir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -181,14 +182,15 @@ function getSessionDir() {
|
|
|
181
182
|
* that don't set their own env var (Cursor, OpenClaw, Codex, Kiro, Zed).
|
|
182
183
|
*/
|
|
183
184
|
function getProjectDir() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
// Delegated to the shared resolver so the env-var chain rejects plugin
|
|
186
|
+
// install paths (set by a prior MCP boot's start.mjs after `/ctx-upgrade`)
|
|
187
|
+
// and prefers the shell-set PWD before the chdir'd cwd. See
|
|
188
|
+
// src/util/project-dir.ts for the rationale + safety rules.
|
|
189
|
+
return resolveProjectDir({
|
|
190
|
+
env: process.env,
|
|
191
|
+
cwd: process.cwd(),
|
|
192
|
+
pwd: process.env.PWD,
|
|
193
|
+
});
|
|
192
194
|
}
|
|
193
195
|
/**
|
|
194
196
|
* Resolve a possibly-relative path against the project directory (full env cascade),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-dir resolution helpers — shared between `start.mjs` (the MCP entry
|
|
3
|
+
* point) and `src/server.ts getProjectDir()` (the consumer).
|
|
4
|
+
*
|
|
5
|
+
* Background: when Claude Code runs `/ctx-upgrade`, it kills + respawns the
|
|
6
|
+
* MCP server. The respawn happens with `cwd` set to the plugin install
|
|
7
|
+
* directory (`~/.claude/plugins/cache/context-mode/context-mode/<version>/`).
|
|
8
|
+
* The legacy `start.mjs` then set `CLAUDE_PROJECT_DIR = originalCwd`, which
|
|
9
|
+
* poisoned every downstream `ctx_stats` / SessionDB / hash computation —
|
|
10
|
+
* sessions silently re-rooted under the plugin install path.
|
|
11
|
+
*
|
|
12
|
+
* Defense-in-depth fix (v1.0.113):
|
|
13
|
+
* - `start.mjs` calls `isPluginInstallPath(originalCwd)` and skips the env
|
|
14
|
+
* auto-set when true (no poisoning at the source).
|
|
15
|
+
* - `getProjectDir()` calls `resolveProjectDir(...)` which rejects plugin-
|
|
16
|
+
* pathed env vars and the plugin cwd, preferring `process.env.PWD`
|
|
17
|
+
* (shell-set, survives `process.chdir`) before falling back.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Detect whether a path lives inside the Claude Code plugin install tree —
|
|
21
|
+
* specifically `<home>/.claude/plugins/cache/<plugin>/<plugin>/<version>/`
|
|
22
|
+
* or the marketplace mirror `<home>/.claude/plugins/marketplaces/...`.
|
|
23
|
+
*
|
|
24
|
+
* Cross-OS: matches both POSIX (`/`) and Windows (`\`) path separators.
|
|
25
|
+
* Independent of `home` location — we only care about the `.claude/plugins/`
|
|
26
|
+
* suffix pattern.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isPluginInstallPath(p: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Pure project-dir resolver. Mirror of the env-var chain inside
|
|
31
|
+
* `src/server.ts getProjectDir()`, but takes its inputs explicitly so the
|
|
32
|
+
* resolver can be exercised under test without process-level mutation.
|
|
33
|
+
*
|
|
34
|
+
* Resolution order:
|
|
35
|
+
* 1. Adapter-priority env vars (CLAUDE / GEMINI / VSCODE / OPENCODE / PI /
|
|
36
|
+
* IDEA / CONTEXT_MODE) — first non-empty AND non-plugin-path wins.
|
|
37
|
+
* 2. `process.env.PWD` — shell-set, NOT updated by `process.chdir()`, so
|
|
38
|
+
* it survives the `start.mjs` chdir into the plugin dir. Skipped if
|
|
39
|
+
* it too points at a plugin install path.
|
|
40
|
+
* 3. `cwd` — last resort. Returned even if it is a plugin path; the
|
|
41
|
+
* caller is responsible for rendering a graceful "no project context"
|
|
42
|
+
* message rather than panicking. Keeping the function total preserves
|
|
43
|
+
* operation of project-independent tools (sandbox execute, fetch).
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveProjectDir(opts: {
|
|
46
|
+
env: Record<string, string | undefined>;
|
|
47
|
+
cwd: string;
|
|
48
|
+
pwd: string | undefined;
|
|
49
|
+
}): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-dir resolution helpers — shared between `start.mjs` (the MCP entry
|
|
3
|
+
* point) and `src/server.ts getProjectDir()` (the consumer).
|
|
4
|
+
*
|
|
5
|
+
* Background: when Claude Code runs `/ctx-upgrade`, it kills + respawns the
|
|
6
|
+
* MCP server. The respawn happens with `cwd` set to the plugin install
|
|
7
|
+
* directory (`~/.claude/plugins/cache/context-mode/context-mode/<version>/`).
|
|
8
|
+
* The legacy `start.mjs` then set `CLAUDE_PROJECT_DIR = originalCwd`, which
|
|
9
|
+
* poisoned every downstream `ctx_stats` / SessionDB / hash computation —
|
|
10
|
+
* sessions silently re-rooted under the plugin install path.
|
|
11
|
+
*
|
|
12
|
+
* Defense-in-depth fix (v1.0.113):
|
|
13
|
+
* - `start.mjs` calls `isPluginInstallPath(originalCwd)` and skips the env
|
|
14
|
+
* auto-set when true (no poisoning at the source).
|
|
15
|
+
* - `getProjectDir()` calls `resolveProjectDir(...)` which rejects plugin-
|
|
16
|
+
* pathed env vars and the plugin cwd, preferring `process.env.PWD`
|
|
17
|
+
* (shell-set, survives `process.chdir`) before falling back.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Detect whether a path lives inside the Claude Code plugin install tree —
|
|
21
|
+
* specifically `<home>/.claude/plugins/cache/<plugin>/<plugin>/<version>/`
|
|
22
|
+
* or the marketplace mirror `<home>/.claude/plugins/marketplaces/...`.
|
|
23
|
+
*
|
|
24
|
+
* Cross-OS: matches both POSIX (`/`) and Windows (`\`) path separators.
|
|
25
|
+
* Independent of `home` location — we only care about the `.claude/plugins/`
|
|
26
|
+
* suffix pattern.
|
|
27
|
+
*/
|
|
28
|
+
export function isPluginInstallPath(p) {
|
|
29
|
+
if (!p)
|
|
30
|
+
return false;
|
|
31
|
+
return /[/\\]\.claude[/\\]plugins[/\\](cache|marketplaces)[/\\]/.test(p);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Pure project-dir resolver. Mirror of the env-var chain inside
|
|
35
|
+
* `src/server.ts getProjectDir()`, but takes its inputs explicitly so the
|
|
36
|
+
* resolver can be exercised under test without process-level mutation.
|
|
37
|
+
*
|
|
38
|
+
* Resolution order:
|
|
39
|
+
* 1. Adapter-priority env vars (CLAUDE / GEMINI / VSCODE / OPENCODE / PI /
|
|
40
|
+
* IDEA / CONTEXT_MODE) — first non-empty AND non-plugin-path wins.
|
|
41
|
+
* 2. `process.env.PWD` — shell-set, NOT updated by `process.chdir()`, so
|
|
42
|
+
* it survives the `start.mjs` chdir into the plugin dir. Skipped if
|
|
43
|
+
* it too points at a plugin install path.
|
|
44
|
+
* 3. `cwd` — last resort. Returned even if it is a plugin path; the
|
|
45
|
+
* caller is responsible for rendering a graceful "no project context"
|
|
46
|
+
* message rather than panicking. Keeping the function total preserves
|
|
47
|
+
* operation of project-independent tools (sandbox execute, fetch).
|
|
48
|
+
*/
|
|
49
|
+
export function resolveProjectDir(opts) {
|
|
50
|
+
const { env, cwd, pwd } = opts;
|
|
51
|
+
const candidates = [
|
|
52
|
+
env.CLAUDE_PROJECT_DIR,
|
|
53
|
+
env.GEMINI_PROJECT_DIR,
|
|
54
|
+
env.VSCODE_CWD,
|
|
55
|
+
env.OPENCODE_PROJECT_DIR,
|
|
56
|
+
env.PI_PROJECT_DIR,
|
|
57
|
+
env.IDEA_INITIAL_DIRECTORY,
|
|
58
|
+
env.CONTEXT_MODE_PROJECT_DIR,
|
|
59
|
+
];
|
|
60
|
+
for (const c of candidates) {
|
|
61
|
+
if (c && !isPluginInstallPath(c))
|
|
62
|
+
return c;
|
|
63
|
+
}
|
|
64
|
+
if (pwd && !isPluginInstallPath(pwd))
|
|
65
|
+
return pwd;
|
|
66
|
+
return cwd;
|
|
67
|
+
}
|