context-mode 1.0.26 → 1.0.28
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/README.md +19 -8
- package/build/cli.js +6 -6
- package/build/db-base.d.ts +15 -3
- package/build/db-base.js +96 -4
- package/build/server.js +2 -2
- package/cli.bundle.mjs +95 -95
- package/hooks/session-db.bundle.mjs +12 -12
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +85 -85
|
@@ -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.28"
|
|
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.28",
|
|
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.28",
|
|
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.28",
|
|
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.28",
|
|
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/README.md
CHANGED
|
@@ -484,7 +484,9 @@ The extension handles session continuity (event capture, resume snapshots, compa
|
|
|
484
484
|
<details>
|
|
485
485
|
<summary><strong>Build Prerequisites</strong> <sup>(CentOS, RHEL, Alpine)</sup></summary>
|
|
486
486
|
|
|
487
|
-
Context Mode uses [better-sqlite3](https://github.com/WiseLibs/better-sqlite3), which ships prebuilt native binaries for most platforms. On glibc >= 2.31 systems (Ubuntu 20.04+, Debian 11+, Fedora 34+, macOS, Windows), `npm install` works without any build tools.
|
|
487
|
+
Context Mode uses [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) on Node.js, which ships prebuilt native binaries for most platforms. On glibc >= 2.31 systems (Ubuntu 20.04+, Debian 11+, Fedora 34+, macOS, Windows), `npm install` works without any build tools.
|
|
488
|
+
|
|
489
|
+
**Bun users:** No native compilation needed. Context Mode automatically detects Bun and uses the built-in `bun:sqlite` module via a compatibility adapter. `better-sqlite3` and all its build dependencies are skipped entirely.
|
|
488
490
|
|
|
489
491
|
On older glibc systems (CentOS 7/8, RHEL 8, Debian 10), prebuilt binaries don't load and better-sqlite3 **automatically falls back to compiling from source** via `prebuild-install || node-gyp rebuild --release`. This requires a C++20 compiler (GCC 10+), Make, and Python with setuptools.
|
|
490
492
|
|
|
@@ -541,17 +543,26 @@ When output exceeds 5 KB and an `intent` is provided, Context Mode switches to i
|
|
|
541
543
|
|
|
542
544
|
## How the Knowledge Base Works
|
|
543
545
|
|
|
544
|
-
The `ctx_index` tool chunks markdown content by headings while keeping code blocks intact, then stores them in a **SQLite FTS5** (Full-Text Search 5) virtual table. Search uses **BM25 ranking** — a probabilistic relevance algorithm that scores documents based on term frequency, inverse document frequency, and document length normalization. **Porter stemming** is applied at index time so "running", "runs", and "ran" match the same stem.
|
|
546
|
+
The `ctx_index` tool chunks markdown content by headings while keeping code blocks intact, then stores them in a **SQLite FTS5** (Full-Text Search 5) virtual table. Search uses **BM25 ranking** — a probabilistic relevance algorithm that scores documents based on term frequency, inverse document frequency, and document length normalization. **Porter stemming** is applied at index time so "running", "runs", and "ran" match the same stem. Titles and headings are weighted **5x** in BM25 scoring for precise navigational queries.
|
|
547
|
+
|
|
548
|
+
When you call `ctx_search`, it returns relevant content snippets focused around matching query terms — not full documents, not approximations, the actual indexed content with smart extraction around what you're looking for. `ctx_fetch_and_index` extends this to URLs: fetch, convert HTML to markdown, chunk, index. The raw page never enters context. Use the `contentType` parameter to filter results by type (e.g. `code` or `prose`).
|
|
549
|
+
|
|
550
|
+
### Ranking: Reciprocal Rank Fusion
|
|
551
|
+
|
|
552
|
+
Search runs two parallel strategies and merges them with **Reciprocal Rank Fusion (RRF)**:
|
|
553
|
+
|
|
554
|
+
- **Porter stemming** — FTS5 MATCH with porter tokenizer. "caching" matches "cached", "caches", "cach".
|
|
555
|
+
- **Trigram substring** — FTS5 trigram tokenizer matches partial strings. "useEff" finds "useEffect", "authenticat" finds "authentication".
|
|
556
|
+
|
|
557
|
+
RRF merges both ranked lists into a single result set, so a document that ranks well in both strategies surfaces higher than one that ranks well in only one. This replaces the old cascading fallback approach where trigram results were only used if porter returned nothing.
|
|
545
558
|
|
|
546
|
-
|
|
559
|
+
### Proximity Reranking
|
|
547
560
|
|
|
548
|
-
|
|
561
|
+
Multi-term queries get an additional reranking pass. Results where query terms appear close together are boosted — `"session continuity"` ranks passages with adjacent terms higher than pages where "session" and "continuity" appear paragraphs apart.
|
|
549
562
|
|
|
550
|
-
|
|
563
|
+
### Fuzzy Correction
|
|
551
564
|
|
|
552
|
-
|
|
553
|
-
- **Layer 2 — Trigram substring**: FTS5 trigram tokenizer matches partial strings. "useEff" finds "useEffect", "authenticat" finds "authentication".
|
|
554
|
-
- **Layer 3 — Fuzzy correction**: Levenshtein distance corrects typos before re-searching. "kuberntes" → "kubernetes", "autentication" → "authentication".
|
|
565
|
+
Levenshtein distance corrects typos before re-searching. "kuberntes" becomes "kubernetes", "autentication" becomes "authentication".
|
|
555
566
|
|
|
556
567
|
### Smart Snippets
|
|
557
568
|
|
package/build/cli.js
CHANGED
|
@@ -256,21 +256,21 @@ async function doctor() {
|
|
|
256
256
|
p.log.warn(color.yellow("Plugin enabled: WARN") +
|
|
257
257
|
` — ${pluginCheck.message}`);
|
|
258
258
|
}
|
|
259
|
-
// FTS5 /
|
|
260
|
-
p.log.step("Checking FTS5 /
|
|
259
|
+
// FTS5 / SQLite
|
|
260
|
+
p.log.step("Checking FTS5 / SQLite...");
|
|
261
261
|
try {
|
|
262
|
-
const Database = (await import("
|
|
262
|
+
const Database = (await import("./db-base.js")).loadDatabase();
|
|
263
263
|
const db = new Database(":memory:");
|
|
264
264
|
db.exec("CREATE VIRTUAL TABLE fts_test USING fts5(content)");
|
|
265
265
|
db.exec("INSERT INTO fts_test(content) VALUES ('hello world')");
|
|
266
266
|
const row = db.prepare("SELECT * FROM fts_test WHERE fts_test MATCH 'hello'").get();
|
|
267
267
|
db.close();
|
|
268
268
|
if (row && row.content === "hello world") {
|
|
269
|
-
p.log.success(color.green("FTS5 /
|
|
269
|
+
p.log.success(color.green("FTS5 / SQLite: PASS") + " — native module works");
|
|
270
270
|
}
|
|
271
271
|
else {
|
|
272
272
|
criticalFails++;
|
|
273
|
-
p.log.error(color.red("FTS5 /
|
|
273
|
+
p.log.error(color.red("FTS5 / SQLite: FAIL") + " — query returned unexpected result");
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
catch (err) {
|
|
@@ -397,7 +397,7 @@ async function upgrade() {
|
|
|
397
397
|
}
|
|
398
398
|
const items = [
|
|
399
399
|
"build", "src", "hooks", "skills", ".claude-plugin",
|
|
400
|
-
"start.mjs", "server.bundle.mjs", "cli.bundle.mjs", "package.json",
|
|
400
|
+
"start.mjs", "native-abi.mjs", "server.bundle.mjs", "cli.bundle.mjs", "package.json",
|
|
401
401
|
];
|
|
402
402
|
for (const item of items) {
|
|
403
403
|
try {
|
package/build/db-base.d.ts
CHANGED
|
@@ -22,9 +22,21 @@ export interface PreparedStatement {
|
|
|
22
22
|
iterate(...params: unknown[]): IterableIterator<unknown>;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
25
|
+
* Wraps a bun:sqlite Database to provide better-sqlite3-compatible API.
|
|
26
|
+
* Bridges: .pragma(), multi-statement .exec(), .get() null→undefined.
|
|
27
|
+
*/
|
|
28
|
+
export declare class BunSQLiteAdapter {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(rawDb: any);
|
|
31
|
+
pragma(source: string): any;
|
|
32
|
+
exec(sql: string): any;
|
|
33
|
+
prepare(sql: string): any;
|
|
34
|
+
transaction(fn: (...args: any[]) => any): any;
|
|
35
|
+
close(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Lazy-load better-sqlite3. Falls back to bun:sqlite via BunSQLiteAdapter
|
|
39
|
+
* when better-sqlite3 is unavailable (Bun runtime, issue #45).
|
|
28
40
|
*/
|
|
29
41
|
export declare function loadDatabase(): typeof DatabaseConstructor;
|
|
30
42
|
/**
|
package/build/db-base.js
CHANGED
|
@@ -10,18 +10,110 @@ import { unlinkSync } from "node:fs";
|
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
// ─────────────────────────────────────────────────────────
|
|
13
|
+
// bun:sqlite adapter (#45)
|
|
14
|
+
// ─────────────────────────────────────────────────────────
|
|
15
|
+
/**
|
|
16
|
+
* Wraps a bun:sqlite Database to provide better-sqlite3-compatible API.
|
|
17
|
+
* Bridges: .pragma(), multi-statement .exec(), .get() null→undefined.
|
|
18
|
+
*/
|
|
19
|
+
export class BunSQLiteAdapter {
|
|
20
|
+
#raw;
|
|
21
|
+
constructor(rawDb) {
|
|
22
|
+
this.#raw = rawDb;
|
|
23
|
+
}
|
|
24
|
+
pragma(source) {
|
|
25
|
+
const stmt = this.#raw.prepare(`PRAGMA ${source}`);
|
|
26
|
+
const rows = stmt.all();
|
|
27
|
+
if (!rows || rows.length === 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
// Multi-row pragmas (table_xinfo, etc.) → return array
|
|
30
|
+
if (rows.length > 1)
|
|
31
|
+
return rows;
|
|
32
|
+
// Single-row: extract scalar value (e.g. journal_mode = "wal")
|
|
33
|
+
const values = Object.values(rows[0]);
|
|
34
|
+
return values.length === 1 ? values[0] : rows[0];
|
|
35
|
+
}
|
|
36
|
+
exec(sql) {
|
|
37
|
+
// bun:sqlite .exec() is single-statement only.
|
|
38
|
+
// Split multi-statement SQL respecting string literals (don't split on ; inside quotes).
|
|
39
|
+
let current = "";
|
|
40
|
+
let inString = null;
|
|
41
|
+
for (let i = 0; i < sql.length; i++) {
|
|
42
|
+
const ch = sql[i];
|
|
43
|
+
if (inString) {
|
|
44
|
+
current += ch;
|
|
45
|
+
if (ch === inString)
|
|
46
|
+
inString = null;
|
|
47
|
+
}
|
|
48
|
+
else if (ch === "'" || ch === '"') {
|
|
49
|
+
current += ch;
|
|
50
|
+
inString = ch;
|
|
51
|
+
}
|
|
52
|
+
else if (ch === ";") {
|
|
53
|
+
const trimmed = current.trim();
|
|
54
|
+
if (trimmed)
|
|
55
|
+
this.#raw.prepare(trimmed).run();
|
|
56
|
+
current = "";
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
current += ch;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const trimmed = current.trim();
|
|
63
|
+
if (trimmed)
|
|
64
|
+
this.#raw.prepare(trimmed).run();
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
prepare(sql) {
|
|
68
|
+
const stmt = this.#raw.prepare(sql);
|
|
69
|
+
return {
|
|
70
|
+
run: (...args) => stmt.run(...args),
|
|
71
|
+
get: (...args) => {
|
|
72
|
+
const r = stmt.get(...args);
|
|
73
|
+
return r === null ? undefined : r;
|
|
74
|
+
},
|
|
75
|
+
all: (...args) => stmt.all(...args),
|
|
76
|
+
iterate: (...args) => stmt.iterate(...args),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
transaction(fn) {
|
|
80
|
+
return this.#raw.transaction(fn);
|
|
81
|
+
}
|
|
82
|
+
close() {
|
|
83
|
+
this.#raw.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// ─────────────────────────────────────────────────────────
|
|
13
87
|
// Lazy loader
|
|
14
88
|
// ─────────────────────────────────────────────────────────
|
|
15
89
|
let _Database = null;
|
|
16
90
|
/**
|
|
17
|
-
* Lazy-load better-sqlite3.
|
|
18
|
-
*
|
|
19
|
-
* is not yet installed (marketplace first-run scenario).
|
|
91
|
+
* Lazy-load better-sqlite3. Falls back to bun:sqlite via BunSQLiteAdapter
|
|
92
|
+
* when better-sqlite3 is unavailable (Bun runtime, issue #45).
|
|
20
93
|
*/
|
|
21
94
|
export function loadDatabase() {
|
|
22
95
|
if (!_Database) {
|
|
23
96
|
const require = createRequire(import.meta.url);
|
|
24
|
-
|
|
97
|
+
try {
|
|
98
|
+
_Database = require("better-sqlite3");
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// better-sqlite3 unavailable (Bun runtime) — wrap bun:sqlite
|
|
102
|
+
if (!globalThis.Bun) {
|
|
103
|
+
throw new Error("better-sqlite3 failed to load and Bun runtime not detected");
|
|
104
|
+
}
|
|
105
|
+
// Compute module name at runtime to prevent esbuild from resolving at bundle time.
|
|
106
|
+
// esbuild constant-folds string concat but NOT Array.join().
|
|
107
|
+
const bunSqliteMod = ["bun", "sqlite"].join(":");
|
|
108
|
+
const BunDB = require(bunSqliteMod).Database;
|
|
109
|
+
_Database = function BunDatabaseFactory(path, opts) {
|
|
110
|
+
const raw = new BunDB(path, {
|
|
111
|
+
readonly: opts?.readonly,
|
|
112
|
+
create: true,
|
|
113
|
+
});
|
|
114
|
+
return new BunSQLiteAdapter(raw);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
25
117
|
}
|
|
26
118
|
return _Database;
|
|
27
119
|
}
|
package/build/server.js
CHANGED
|
@@ -15,6 +15,7 @@ import { detectRuntimes, getRuntimeSummary, getAvailableLanguages, hasBunRuntime
|
|
|
15
15
|
import { classifyNonZeroExit } from "./exit-classify.js";
|
|
16
16
|
import { startLifecycleGuard } from "./lifecycle.js";
|
|
17
17
|
import { getWorktreeSuffix } from "./session/db.js";
|
|
18
|
+
import { loadDatabase } from "./db-base.js";
|
|
18
19
|
const __pkg_dir = dirname(fileURLToPath(import.meta.url));
|
|
19
20
|
const VERSION = (() => {
|
|
20
21
|
for (const rel of ["../package.json", "./package.json"]) {
|
|
@@ -1318,8 +1319,7 @@ server.registerTool("ctx_stats", {
|
|
|
1318
1319
|
const worktreeSuffix = getWorktreeSuffix();
|
|
1319
1320
|
const sessionDbPath = join(homedir(), ".claude", "context-mode", "sessions", `${dbHash}${worktreeSuffix}.db`);
|
|
1320
1321
|
if (existsSync(sessionDbPath)) {
|
|
1321
|
-
const
|
|
1322
|
-
const Database = require("better-sqlite3");
|
|
1322
|
+
const Database = loadDatabase();
|
|
1323
1323
|
const sdb = new Database(sessionDbPath, { readonly: true });
|
|
1324
1324
|
const eventTotal = sdb.prepare("SELECT COUNT(*) as cnt FROM session_events").get();
|
|
1325
1325
|
const byCategory = sdb.prepare("SELECT category, COUNT(*) as cnt FROM session_events GROUP BY category ORDER BY cnt DESC").all();
|