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/.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/cli.js +66 -0
- 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 +137 -137
- package/openclaw.plugin.json +1 -1
- package/package.json +2 -1
- package/scripts/heal-installed-plugins.mjs +129 -0
- package/scripts/postinstall.mjs +58 -0
- package/server.bundle.mjs +73 -73
- package/start.mjs +42 -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.114"
|
|
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.114",
|
|
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.114",
|
|
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.114",
|
|
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.114",
|
|
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/cli.js
CHANGED
|
@@ -679,9 +679,75 @@ async function upgrade() {
|
|
|
679
679
|
};
|
|
680
680
|
writeFileSync(resolve(pluginRoot, ".mcp.json"), JSON.stringify(mcpConfig, null, 2) + "\n");
|
|
681
681
|
s.stop(color.green(`Updated in-place to v${newVersion}`));
|
|
682
|
+
// v1.0.114 hotfix — pre-flight: verify the in-place copy actually
|
|
683
|
+
// wrote a plugin.json carrying newVersion BEFORE we tell the
|
|
684
|
+
// registry that's the install path. If the manifest still reports
|
|
685
|
+
// the old version (rsync race, partial write, files-array drift),
|
|
686
|
+
// updating the registry would create the silent v1.0.113-class
|
|
687
|
+
// drift Mert hit. Bail out — the next /ctx-upgrade gets to retry.
|
|
688
|
+
const pluginManifest = resolve(pluginRoot, ".claude-plugin", "plugin.json");
|
|
689
|
+
let onDiskVersion = null;
|
|
690
|
+
try {
|
|
691
|
+
const pj = JSON.parse(readFileSync(pluginManifest, "utf-8"));
|
|
692
|
+
if (pj && typeof pj.version === "string")
|
|
693
|
+
onDiskVersion = pj.version;
|
|
694
|
+
}
|
|
695
|
+
catch { /* parse error → onDiskVersion stays null */ }
|
|
696
|
+
if (onDiskVersion !== newVersion) {
|
|
697
|
+
throw new Error(`pluginRoot manifest version mismatch — disk says "${onDiskVersion ?? "<missing>"}" but newVersion is "${newVersion}". Refusing to bump registry.`);
|
|
698
|
+
}
|
|
682
699
|
// Fix registry — adapter-aware
|
|
683
700
|
adapter.updatePluginRegistry(pluginRoot, newVersion);
|
|
684
701
|
p.log.info(color.dim(" Registry synced to " + pluginRoot));
|
|
702
|
+
// v1.0.114 hotfix — post-write assertion: re-read installed_plugins.json
|
|
703
|
+
// and verify installPath/.claude-plugin/plugin.json's version matches
|
|
704
|
+
// the registry entry. Throws on mismatch — fails loudly so a future
|
|
705
|
+
// adapter regression surfaces here, not weeks later in user reports.
|
|
706
|
+
try {
|
|
707
|
+
const ipPath = resolve(resolveClaudeConfigDir(), "plugins", "installed_plugins.json");
|
|
708
|
+
if (existsSync(ipPath)) {
|
|
709
|
+
const ip = JSON.parse(readFileSync(ipPath, "utf-8"));
|
|
710
|
+
const entries = ip?.plugins?.["context-mode@context-mode"];
|
|
711
|
+
if (Array.isArray(entries)) {
|
|
712
|
+
for (const entry of entries) {
|
|
713
|
+
const ip2 = entry?.installPath;
|
|
714
|
+
if (typeof ip2 !== "string" || !ip2)
|
|
715
|
+
continue;
|
|
716
|
+
if (!existsSync(ip2)) {
|
|
717
|
+
throw new Error(`installPath does not exist on disk: ${ip2}`);
|
|
718
|
+
}
|
|
719
|
+
const pjPath = resolve(ip2, ".claude-plugin", "plugin.json");
|
|
720
|
+
if (!existsSync(pjPath)) {
|
|
721
|
+
throw new Error(`missing plugin.json manifest at ${pjPath}`);
|
|
722
|
+
}
|
|
723
|
+
const pj = JSON.parse(readFileSync(pjPath, "utf-8"));
|
|
724
|
+
if (pj?.version !== entry.version) {
|
|
725
|
+
throw new Error(`version mismatch — registry says "${entry.version}" but ${pjPath} says "${pj?.version}"`);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
catch (err) {
|
|
732
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
733
|
+
throw new Error(`Registry consistency check failed: ${message}`);
|
|
734
|
+
}
|
|
735
|
+
// v1.0.114 hotfix — marketplace post-pull assertion: clone (if
|
|
736
|
+
// present) MUST be on newVersion. Mert's case showed marketplace
|
|
737
|
+
// stuck at v1.0.89 — the sync block above swallowed that silently.
|
|
738
|
+
// Warn (don't throw) — npm-only users have no marketplace clone.
|
|
739
|
+
try {
|
|
740
|
+
const marketplaceManifest = resolve(marketplaceDir, ".claude-plugin", "plugin.json");
|
|
741
|
+
if (existsSync(marketplaceManifest)) {
|
|
742
|
+
const mpj = JSON.parse(readFileSync(marketplaceManifest, "utf-8"));
|
|
743
|
+
if (mpj?.version !== newVersion) {
|
|
744
|
+
p.log.warn(color.yellow("Marketplace clone version mismatch") +
|
|
745
|
+
` — ${marketplaceDir} reports "${mpj?.version}" but expected "${newVersion}"`);
|
|
746
|
+
p.log.info(color.dim(` Run manually: git -C "${marketplaceDir}" fetch --tags origin && git -C "${marketplaceDir}" reset --hard origin/HEAD`));
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
catch { /* best effort */ }
|
|
685
751
|
// Install production deps
|
|
686
752
|
s.start("Installing production dependencies");
|
|
687
753
|
npmExecFile(["install", "--production", "--no-audit", "--no-fund"], {
|
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
|
+
}
|