context-mode 1.0.45 → 1.0.46
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/db-base.d.ts +3 -2
- package/build/db-base.js +11 -22
- package/cli.bundle.mjs +1 -1
- package/hooks/session-db.bundle.mjs +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server.bundle.mjs +1 -1
|
@@ -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.46"
|
|
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.46",
|
|
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.46",
|
|
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.46",
|
|
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.46",
|
|
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/db-base.d.ts
CHANGED
|
@@ -35,8 +35,9 @@ export declare class BunSQLiteAdapter {
|
|
|
35
35
|
close(): void;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Lazy-load
|
|
39
|
-
*
|
|
38
|
+
* Lazy-load the SQLite driver for the current runtime.
|
|
39
|
+
* Bun → bun:sqlite via BunSQLiteAdapter (issue #45).
|
|
40
|
+
* Node → better-sqlite3 (native addon).
|
|
40
41
|
*/
|
|
41
42
|
export declare function loadDatabase(): typeof DatabaseConstructor;
|
|
42
43
|
/**
|
package/build/db-base.js
CHANGED
|
@@ -88,32 +88,17 @@ export class BunSQLiteAdapter {
|
|
|
88
88
|
// ─────────────────────────────────────────────────────────
|
|
89
89
|
let _Database = null;
|
|
90
90
|
/**
|
|
91
|
-
* Lazy-load
|
|
92
|
-
*
|
|
91
|
+
* Lazy-load the SQLite driver for the current runtime.
|
|
92
|
+
* Bun → bun:sqlite via BunSQLiteAdapter (issue #45).
|
|
93
|
+
* Node → better-sqlite3 (native addon).
|
|
93
94
|
*/
|
|
94
95
|
export function loadDatabase() {
|
|
95
96
|
if (!_Database) {
|
|
96
97
|
const require = createRequire(import.meta.url);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
if (!mod || typeof mod !== "function") {
|
|
102
|
-
throw new Error("better-sqlite3 loaded but not usable");
|
|
103
|
-
}
|
|
104
|
-
const testDb = new mod(":memory:");
|
|
105
|
-
testDb.close();
|
|
106
|
-
_Database = mod;
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
// better-sqlite3 unavailable (Bun runtime) — wrap bun:sqlite
|
|
110
|
-
if (!globalThis.Bun) {
|
|
111
|
-
throw new Error("better-sqlite3 failed to load and Bun runtime not detected");
|
|
112
|
-
}
|
|
113
|
-
// Compute module name at runtime to prevent esbuild from resolving at bundle time.
|
|
114
|
-
// esbuild constant-folds string concat but NOT Array.join().
|
|
115
|
-
const bunSqliteMod = ["bun", "sqlite"].join(":");
|
|
116
|
-
const BunDB = require(bunSqliteMod).Database;
|
|
98
|
+
if (globalThis.Bun) {
|
|
99
|
+
// Bun runtime — use bun:sqlite directly.
|
|
100
|
+
// Array.join() prevents esbuild from resolving the specifier at bundle time.
|
|
101
|
+
const BunDB = require(["bun", "sqlite"].join(":")).Database;
|
|
117
102
|
_Database = function BunDatabaseFactory(path, opts) {
|
|
118
103
|
const raw = new BunDB(path, {
|
|
119
104
|
readonly: opts?.readonly,
|
|
@@ -122,6 +107,10 @@ export function loadDatabase() {
|
|
|
122
107
|
return new BunSQLiteAdapter(raw);
|
|
123
108
|
};
|
|
124
109
|
}
|
|
110
|
+
else {
|
|
111
|
+
// Node.js — use better-sqlite3.
|
|
112
|
+
_Database = require("better-sqlite3");
|
|
113
|
+
}
|
|
125
114
|
}
|
|
126
115
|
return _Database;
|
|
127
116
|
}
|
package/cli.bundle.mjs
CHANGED
|
@@ -150,7 +150,7 @@ FILE_CONTENT <- paste(FILE_CONTENT, collapse="\\n")
|
|
|
150
150
|
${n}`;case"elixir":return`file_content_path = ${o}
|
|
151
151
|
file_path = file_content_path
|
|
152
152
|
file_content = File.read!(file_content_path)
|
|
153
|
-
${n}`}}}});var Pk={};je(Pk,{BunSQLiteAdapter:()=>Mc,SQLiteBase:()=>Lc,applyWALPragmas:()=>Dc,closeDB:()=>ii,defaultDBPath:()=>Tk,deleteDBFiles:()=>Ek,loadDatabase:()=>Cn});import{createRequire as QN}from"node:module";import{unlinkSync as eA}from"node:fs";import{tmpdir as tA}from"node:os";import{join as rA}from"node:path";function Cn(){if(!jc){let t=QN(import.meta.url);try{let e=t("better-sqlite3");if(!e||typeof e!="function")throw new Error("better-sqlite3 loaded but not usable (
|
|
153
|
+
${n}`}}}});var Pk={};je(Pk,{BunSQLiteAdapter:()=>Mc,SQLiteBase:()=>Lc,applyWALPragmas:()=>Dc,closeDB:()=>ii,defaultDBPath:()=>Tk,deleteDBFiles:()=>Ek,loadDatabase:()=>Cn});import{createRequire as QN}from"node:module";import{unlinkSync as eA}from"node:fs";import{tmpdir as tA}from"node:os";import{join as rA}from"node:path";function Cn(){if(!jc){let t=QN(import.meta.url);try{let e=t("better-sqlite3");if(!e||typeof e!="function")throw new Error("better-sqlite3 loaded but not usable");new e(":memory:").close(),jc=e}catch{if(!globalThis.Bun)throw new Error("better-sqlite3 failed to load and Bun runtime not detected");let e=["bun","sqlite"].join(":"),r=t(e).Database;jc=function(o,s){let i=new r(o,{readonly:s?.readonly,create:!0});return new Mc(i)}}}return jc}function Dc(t){t.pragma("journal_mode = WAL"),t.pragma("synchronous = NORMAL")}function Ek(t){for(let e of["","-wal","-shm"])try{eA(t+e)}catch{}}function ii(t){try{t.pragma("wal_checkpoint(TRUNCATE)")}catch{}try{t.close()}catch{}}function Tk(t="context-mode"){return rA(tA(),`${t}-${process.pid}.db`)}var Mc,jc,Lc,ai=x(()=>{"use strict";Mc=class{#e;constructor(e){this.#e=e}pragma(e){let n=this.#e.prepare(`PRAGMA ${e}`).all();if(!n||n.length===0)return;if(n.length>1)return n;let o=Object.values(n[0]);return o.length===1?o[0]:n[0]}exec(e){let r="",n=null;for(let s=0;s<e.length;s++){let i=e[s];if(n)r+=i,i===n&&(n=null);else if(i==="'"||i==='"')r+=i,n=i;else if(i===";"){let a=r.trim();a&&this.#e.prepare(a).run(),r=""}else r+=i}let o=r.trim();return o&&this.#e.prepare(o).run(),this}prepare(e){let r=this.#e.prepare(e);return{run:(...n)=>r.run(...n),get:(...n)=>{let o=r.get(...n);return o===null?void 0:o},all:(...n)=>r.all(...n),iterate:(...n)=>r.iterate(...n)}}transaction(e){return this.#e.transaction(e)}close(){this.#e.close()}},jc=null;Lc=class{#e;#t;constructor(e){let r=Cn();this.#e=e,this.#t=new r(e,{timeout:5e3}),Dc(this.#t),this.initSchema(),this.prepareStatements()}get db(){return this.#t}get dbPath(){return this.#e}close(){ii(this.#t)}cleanup(){ii(this.#t),Ek(this.#e)}}});import{readFileSync as nA,readdirSync as Ck,unlinkSync as ph,existsSync as oA,statSync as Ik}from"node:fs";import{tmpdir as zk}from"node:os";import{join as mh}from"node:path";function sA(t,e="AND"){let r=t.replace(/['"(){}[\]*:^~]/g," ").split(/\s+/).filter(n=>n.length>0&&!["AND","OR","NOT","NEAR"].includes(n.toUpperCase()));return r.length===0?'""':r.map(n=>`"${n}"`).join(e==="OR"?" OR ":" ")}function iA(t,e="AND"){let r=t.replace(/["'(){}[\]*:^~]/g,"").trim();if(r.length<3)return"";let n=r.split(/\s+/).filter(o=>o.length>=3);return n.length===0?"":n.map(o=>`"${o}"`).join(e==="OR"?" OR ":" ")}function aA(t,e){if(t.length===0)return e.length;if(e.length===0)return t.length;let r=Array.from({length:e.length+1},(n,o)=>o);for(let n=1;n<=t.length;n++){let o=[n];for(let s=1;s<=e.length;s++)o[s]=t[n-1]===e[s-1]?r[s-1]:1+Math.min(r[s],o[s-1],r[s-1]);r=o}return r[e.length]}function cA(t){return t<=4?1:t<=12?2:3}function fh(){let t=zk(),e=0;try{let r=Ck(t);for(let n of r){let o=n.match(/^context-mode-(\d+)\.db$/);if(!o)continue;let s=parseInt(o[1],10);if(s!==process.pid)try{process.kill(s,0)}catch{let i=mh(t,n);for(let a of["","-wal","-shm"])try{ph(i+a)}catch{}e++}}}catch{}return e}function Nk(t,e){let r=0;try{if(!oA(t))return 0;let n=Date.now()-e*24*60*60*1e3,o=Ck(t).filter(s=>s.endsWith(".db"));for(let s of o)try{let i=mh(t,s);if(Ik(i).mtimeMs<n){for(let c of["","-wal","-shm"])try{ph(i+c)}catch{}r++}}catch{}}catch{}return r}function uA(t,e){let r=[],n=t.indexOf(e);for(;n!==-1;)r.push(n),n=t.indexOf(e,n+1);return r}function lA(t){if(t.length===0)return 1/0;if(t.length===1)return 0;let e=t.map(o=>[...o].sort((s,i)=>s-i)),r=new Array(e.length).fill(0),n=1/0;for(;;){let o=1/0,s=-1/0,i=0;for(let c=0;c<e.length;c++){let u=e[c][r[c]];u<o&&(o=u,i=c),u>s&&(s=u)}let a=s-o;if(a<n&&(n=a),r[i]++,r[i]>=e[i].length)break}return n}var Rk,Ok,Zc,Ak=x(()=>{"use strict";ai();Rk=new Set(["the","and","for","are","but","not","you","all","can","had","her","was","one","our","out","has","his","how","its","may","new","now","old","see","way","who","did","get","got","let","say","she","too","use","will","with","this","that","from","they","been","have","many","some","them","than","each","make","like","just","over","such","take","into","year","your","good","could","would","about","which","their","there","other","after","should","through","also","more","most","only","very","when","what","then","these","those","being","does","done","both","same","still","while","where","here","were","much","update","updates","updated","deps","dev","tests","test","add","added","fix","fixed","run","running","using"]);Ok=4096;Zc=class{#e;#t;#r;#n;#o;#i;#a;#s;#c;#u;#d;#p;#m;#f;#h;#g;#_;#y;#v;#x;#b;#S;#k;#w;#$;constructor(e){let r=Cn();this.#t=e??mh(zk(),`context-mode-${process.pid}.db`),this.#e=new r(this.#t,{timeout:5e3}),Dc(this.#e),this.#R(),this.#O()}cleanup(){try{this.#e.close()}catch{}for(let e of["","-wal","-shm"])try{ph(this.#t+e)}catch{}}#R(){this.#e.exec(`
|
|
154
154
|
CREATE TABLE IF NOT EXISTS sources (
|
|
155
155
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
156
156
|
label TEXT NOT NULL,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as T}from"node:module";import{unlinkSync as g}from"node:fs";import{tmpdir as h}from"node:os";import{join as y}from"node:path";var E=class{#t;constructor(t){this.#t=t}pragma(t){let s=this.#t.prepare(`PRAGMA ${t}`).all();if(!s||s.length===0)return;if(s.length>1)return s;let i=Object.values(s[0]);return i.length===1?i[0]:s[0]}exec(t){let e="",s=null;for(let o=0;o<t.length;o++){let a=t[o];if(s)e+=a,a===s&&(s=null);else if(a==="'"||a==='"')e+=a,s=a;else if(a===";"){let d=e.trim();d&&this.#t.prepare(d).run(),e=""}else e+=a}let i=e.trim();return i&&this.#t.prepare(i).run(),this}prepare(t){let e=this.#t.prepare(t);return{run:(...s)=>e.run(...s),get:(...s)=>{let i=e.get(...s);return i===null?void 0:i},all:(...s)=>e.all(...s),iterate:(...s)=>e.iterate(...s)}}transaction(t){return this.#t.transaction(t)}close(){this.#t.close()}},c=null;function R(){if(!c){let r=T(import.meta.url);try{let t=r("better-sqlite3");if(!t||typeof t!="function")throw new Error("better-sqlite3 loaded but not usable (
|
|
1
|
+
import{createRequire as T}from"node:module";import{unlinkSync as g}from"node:fs";import{tmpdir as h}from"node:os";import{join as y}from"node:path";var E=class{#t;constructor(t){this.#t=t}pragma(t){let s=this.#t.prepare(`PRAGMA ${t}`).all();if(!s||s.length===0)return;if(s.length>1)return s;let i=Object.values(s[0]);return i.length===1?i[0]:s[0]}exec(t){let e="",s=null;for(let o=0;o<t.length;o++){let a=t[o];if(s)e+=a,a===s&&(s=null);else if(a==="'"||a==='"')e+=a,s=a;else if(a===";"){let d=e.trim();d&&this.#t.prepare(d).run(),e=""}else e+=a}let i=e.trim();return i&&this.#t.prepare(i).run(),this}prepare(t){let e=this.#t.prepare(t);return{run:(...s)=>e.run(...s),get:(...s)=>{let i=e.get(...s);return i===null?void 0:i},all:(...s)=>e.all(...s),iterate:(...s)=>e.iterate(...s)}}transaction(t){return this.#t.transaction(t)}close(){this.#t.close()}},c=null;function R(){if(!c){let r=T(import.meta.url);try{let t=r("better-sqlite3");if(!t||typeof t!="function")throw new Error("better-sqlite3 loaded but not usable");new t(":memory:").close(),c=t}catch{if(!globalThis.Bun)throw new Error("better-sqlite3 failed to load and Bun runtime not detected");let t=["bun","sqlite"].join(":"),e=r(t).Database;c=function(i,o){let a=new e(i,{readonly:o?.readonly,create:!0});return new E(a)}}}return c}function S(r){r.pragma("journal_mode = WAL"),r.pragma("synchronous = NORMAL")}function v(r){for(let t of["","-wal","-shm"])try{g(r+t)}catch{}}function m(r){try{r.pragma("wal_checkpoint(TRUNCATE)")}catch{}try{r.close()}catch{}}function p(r="context-mode"){return y(h(),`${r}-${process.pid}.db`)}var u=class{#t;#e;constructor(t){let e=R();this.#t=t,this.#e=new e(t,{timeout:5e3}),S(this.#e),this.initSchema(),this.prepareStatements()}get db(){return this.#e}get dbPath(){return this.#t}close(){m(this.#e)}cleanup(){m(this.#e),v(this.#t)}};import{createHash as l}from"node:crypto";import{execFileSync as L}from"node:child_process";function U(){let r=process.env.CONTEXT_MODE_SESSION_SUFFIX;if(r!==void 0)return r?`__${r}`:"";try{let t=process.cwd(),e=L("git",["worktree","list","--porcelain"],{encoding:"utf-8",timeout:2e3,stdio:["ignore","pipe","ignore"]}).split(/\r?\n/).find(s=>s.startsWith("worktree "))?.replace("worktree ","")?.trim();if(e&&t!==e)return`__${l("sha256").update(t).digest("hex").slice(0,8)}`}catch{}return""}var N=1e3,f=5,n={insertEvent:"insertEvent",getEvents:"getEvents",getEventsByType:"getEventsByType",getEventsByPriority:"getEventsByPriority",getEventsByTypeAndPriority:"getEventsByTypeAndPriority",getEventCount:"getEventCount",checkDuplicate:"checkDuplicate",evictLowestPriority:"evictLowestPriority",updateMetaLastEvent:"updateMetaLastEvent",ensureSession:"ensureSession",getSessionStats:"getSessionStats",incrementCompactCount:"incrementCompactCount",upsertResume:"upsertResume",getResume:"getResume",markResumeConsumed:"markResumeConsumed",deleteEvents:"deleteEvents",deleteMeta:"deleteMeta",deleteResume:"deleteResume",getOldSessions:"getOldSessions"},_=class extends u{constructor(t){super(t?.dbPath??p("session"))}stmt(t){return this.stmts.get(t)}initSchema(){try{let e=this.db.pragma("table_xinfo(session_events)").find(s=>s.name==="data_hash");e&&e.hidden!==0&&this.db.exec("DROP TABLE session_events")}catch{}this.db.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS session_events (
|
|
3
3
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4
4
|
session_id TEXT NOT NULL,
|
package/openclaw.plugin.json
CHANGED
|
@@ -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.46",
|
|
7
7
|
"sandbox": {
|
|
8
8
|
"mode": "permissive",
|
|
9
9
|
"filesystem_access": "full",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP plugin that saves 98% of your context window. Works with Claude Code, Gemini CLI, VS Code Copilot, OpenCode, and Codex CLI. Sandboxed code execution, FTS5 knowledge base, and intent-driven search.",
|
|
6
6
|
"author": "Mert Koseoğlu",
|
package/server.bundle.mjs
CHANGED
|
@@ -150,7 +150,7 @@ FILE_CONTENT <- paste(FILE_CONTENT, collapse="\\n")
|
|
|
150
150
|
${n}`;case"elixir":return`file_content_path = ${o}
|
|
151
151
|
file_path = file_content_path
|
|
152
152
|
file_content = File.read!(file_content_path)
|
|
153
|
-
${n}`}}};import{createRequire as GO}from"node:module";var vp=class{#e;constructor(e){this.#e=e}pragma(e){let n=this.#e.prepare(`PRAGMA ${e}`).all();if(!n||n.length===0)return;if(n.length>1)return n;let o=Object.values(n[0]);return o.length===1?o[0]:n[0]}exec(e){let r="",n=null;for(let s=0;s<e.length;s++){let i=e[s];if(n)r+=i,i===n&&(n=null);else if(i==="'"||i==='"')r+=i,n=i;else if(i===";"){let a=r.trim();a&&this.#e.prepare(a).run(),r=""}else r+=i}let o=r.trim();return o&&this.#e.prepare(o).run(),this}prepare(e){let r=this.#e.prepare(e);return{run:(...n)=>r.run(...n),get:(...n)=>{let o=r.get(...n);return o===null?void 0:o},all:(...n)=>r.all(...n),iterate:(...n)=>r.iterate(...n)}}transaction(e){return this.#e.transaction(e)}close(){this.#e.close()}},Sa=null;function ms(){if(!Sa){let t=GO(import.meta.url);try{let e=t("better-sqlite3");if(!e||typeof e!="function")throw new Error("better-sqlite3 loaded but not usable (
|
|
153
|
+
${n}`}}};import{createRequire as GO}from"node:module";var vp=class{#e;constructor(e){this.#e=e}pragma(e){let n=this.#e.prepare(`PRAGMA ${e}`).all();if(!n||n.length===0)return;if(n.length>1)return n;let o=Object.values(n[0]);return o.length===1?o[0]:n[0]}exec(e){let r="",n=null;for(let s=0;s<e.length;s++){let i=e[s];if(n)r+=i,i===n&&(n=null);else if(i==="'"||i==='"')r+=i,n=i;else if(i===";"){let a=r.trim();a&&this.#e.prepare(a).run(),r=""}else r+=i}let o=r.trim();return o&&this.#e.prepare(o).run(),this}prepare(e){let r=this.#e.prepare(e);return{run:(...n)=>r.run(...n),get:(...n)=>{let o=r.get(...n);return o===null?void 0:o},all:(...n)=>r.all(...n),iterate:(...n)=>r.iterate(...n)}}transaction(e){return this.#e.transaction(e)}close(){this.#e.close()}},Sa=null;function ms(){if(!Sa){let t=GO(import.meta.url);try{let e=t("better-sqlite3");if(!e||typeof e!="function")throw new Error("better-sqlite3 loaded but not usable");new e(":memory:").close(),Sa=e}catch{if(!globalThis.Bun)throw new Error("better-sqlite3 failed to load and Bun runtime not detected");let e=["bun","sqlite"].join(":"),r=t(e).Database;Sa=function(o,s){let i=new r(o,{readonly:s?.readonly,create:!0});return new vp(i)}}}return Sa}function fx(t){t.pragma("journal_mode = WAL"),t.pragma("synchronous = NORMAL")}function mx(t){try{t.pragma("wal_checkpoint(TRUNCATE)")}catch{}try{t.close()}catch{}}import{readFileSync as WO,readdirSync as _x,unlinkSync as Sp,existsSync as YO,statSync as yx}from"node:fs";import{tmpdir as xx}from"node:os";import{join as kp}from"node:path";var hx=new Set(["the","and","for","are","but","not","you","all","can","had","her","was","one","our","out","has","his","how","its","may","new","now","old","see","way","who","did","get","got","let","say","she","too","use","will","with","this","that","from","they","been","have","many","some","them","than","each","make","like","just","over","such","take","into","year","your","good","could","would","about","which","their","there","other","after","should","through","also","more","most","only","very","when","what","then","these","those","being","does","done","both","same","still","while","where","here","were","much","update","updates","updated","deps","dev","tests","test","add","added","fix","fixed","run","running","using"]);function XO(t,e="AND"){let r=t.replace(/['"(){}[\]*:^~]/g," ").split(/\s+/).filter(n=>n.length>0&&!["AND","OR","NOT","NEAR"].includes(n.toUpperCase()));return r.length===0?'""':r.map(n=>`"${n}"`).join(e==="OR"?" OR ":" ")}function QO(t,e="AND"){let r=t.replace(/["'(){}[\]*:^~]/g,"").trim();if(r.length<3)return"";let n=r.split(/\s+/).filter(o=>o.length>=3);return n.length===0?"":n.map(o=>`"${o}"`).join(e==="OR"?" OR ":" ")}function eC(t,e){if(t.length===0)return e.length;if(e.length===0)return t.length;let r=Array.from({length:e.length+1},(n,o)=>o);for(let n=1;n<=t.length;n++){let o=[n];for(let s=1;s<=e.length;s++)o[s]=t[n-1]===e[s-1]?r[s-1]:1+Math.min(r[s],o[s-1],r[s-1]);r=o}return r[e.length]}function tC(t){return t<=4?1:t<=12?2:3}var gx=4096;function bp(){let t=xx(),e=0;try{let r=_x(t);for(let n of r){let o=n.match(/^context-mode-(\d+)\.db$/);if(!o)continue;let s=parseInt(o[1],10);if(s!==process.pid)try{process.kill(s,0)}catch{let i=kp(t,n);for(let a of["","-wal","-shm"])try{Sp(i+a)}catch{}e++}}}catch{}return e}function vx(t,e){let r=0;try{if(!YO(t))return 0;let n=Date.now()-e*24*60*60*1e3,o=_x(t).filter(s=>s.endsWith(".db"));for(let s of o)try{let i=kp(t,s);if(yx(i).mtimeMs<n){for(let c of["","-wal","-shm"])try{Sp(i+c)}catch{}r++}}catch{}}catch{}return r}function rC(t,e){let r=[],n=t.indexOf(e);for(;n!==-1;)r.push(n),n=t.indexOf(e,n+1);return r}function nC(t){if(t.length===0)return 1/0;if(t.length===1)return 0;let e=t.map(o=>[...o].sort((s,i)=>s-i)),r=new Array(e.length).fill(0),n=1/0;for(;;){let o=1/0,s=-1/0,i=0;for(let c=0;c<e.length;c++){let u=e[c][r[c]];u<o&&(o=u,i=c),u>s&&(s=u)}let a=s-o;if(a<n&&(n=a),r[i]++,r[i]>=e[i].length)break}return n}var ka=class{#e;#t;#r;#n;#o;#i;#a;#s;#c;#u;#d;#p;#f;#m;#h;#g;#_;#y;#x;#v;#S;#k;#b;#w;#E;constructor(e){let r=ms();this.#t=e??kp(xx(),`context-mode-${process.pid}.db`),this.#e=new r(this.#t,{timeout:5e3}),fx(this.#e),this.#R(),this.#O()}cleanup(){try{this.#e.close()}catch{}for(let e of["","-wal","-shm"])try{Sp(this.#t+e)}catch{}}#R(){this.#e.exec(`
|
|
154
154
|
CREATE TABLE IF NOT EXISTS sources (
|
|
155
155
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
156
156
|
label TEXT NOT NULL,
|