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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as
|
|
1
|
+
import{createRequire as l}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=l(import.meta.url);try{c=r("better-sqlite3")}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 T}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`__${T("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,
|
|
@@ -32,26 +32,26 @@ import{createRequire as p}from"node:module";import{unlinkSync as _}from"node:fs"
|
|
|
32
32
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
33
33
|
consumed INTEGER NOT NULL DEFAULT 0
|
|
34
34
|
);
|
|
35
|
-
`)}prepareStatements(){this.stmts=new Map;let t=(s
|
|
36
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`),t(
|
|
37
|
-
FROM session_events WHERE session_id = ? ORDER BY id ASC LIMIT ?`),t(
|
|
38
|
-
FROM session_events WHERE session_id = ? AND type = ? ORDER BY id ASC LIMIT ?`),t(
|
|
39
|
-
FROM session_events WHERE session_id = ? AND priority >= ? ORDER BY id ASC LIMIT ?`),t(
|
|
40
|
-
FROM session_events WHERE session_id = ? AND type = ? AND priority >= ? ORDER BY id ASC LIMIT ?`),t(
|
|
35
|
+
`)}prepareStatements(){this.stmts=new Map;let t=(e,s)=>{this.stmts.set(e,this.db.prepare(s))};t(n.insertEvent,`INSERT INTO session_events (session_id, type, category, priority, data, source_hook, data_hash)
|
|
36
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`),t(n.getEvents,`SELECT id, session_id, type, category, priority, data, source_hook, created_at, data_hash
|
|
37
|
+
FROM session_events WHERE session_id = ? ORDER BY id ASC LIMIT ?`),t(n.getEventsByType,`SELECT id, session_id, type, category, priority, data, source_hook, created_at, data_hash
|
|
38
|
+
FROM session_events WHERE session_id = ? AND type = ? ORDER BY id ASC LIMIT ?`),t(n.getEventsByPriority,`SELECT id, session_id, type, category, priority, data, source_hook, created_at, data_hash
|
|
39
|
+
FROM session_events WHERE session_id = ? AND priority >= ? ORDER BY id ASC LIMIT ?`),t(n.getEventsByTypeAndPriority,`SELECT id, session_id, type, category, priority, data, source_hook, created_at, data_hash
|
|
40
|
+
FROM session_events WHERE session_id = ? AND type = ? AND priority >= ? ORDER BY id ASC LIMIT ?`),t(n.getEventCount,"SELECT COUNT(*) AS cnt FROM session_events WHERE session_id = ?"),t(n.checkDuplicate,`SELECT 1 FROM (
|
|
41
41
|
SELECT type, data_hash FROM session_events
|
|
42
42
|
WHERE session_id = ? ORDER BY id DESC LIMIT ?
|
|
43
43
|
) AS recent
|
|
44
44
|
WHERE recent.type = ? AND recent.data_hash = ?
|
|
45
|
-
LIMIT 1`),t(
|
|
45
|
+
LIMIT 1`),t(n.evictLowestPriority,`DELETE FROM session_events WHERE id = (
|
|
46
46
|
SELECT id FROM session_events WHERE session_id = ?
|
|
47
47
|
ORDER BY priority ASC, id ASC LIMIT 1
|
|
48
|
-
)`),t(
|
|
48
|
+
)`),t(n.updateMetaLastEvent,`UPDATE session_meta
|
|
49
49
|
SET last_event_at = datetime('now'), event_count = event_count + 1
|
|
50
|
-
WHERE session_id = ?`),t(
|
|
51
|
-
FROM session_meta WHERE session_id = ?`),t(
|
|
50
|
+
WHERE session_id = ?`),t(n.ensureSession,"INSERT OR IGNORE INTO session_meta (session_id, project_dir) VALUES (?, ?)"),t(n.getSessionStats,`SELECT session_id, project_dir, started_at, last_event_at, event_count, compact_count
|
|
51
|
+
FROM session_meta WHERE session_id = ?`),t(n.incrementCompactCount,"UPDATE session_meta SET compact_count = compact_count + 1 WHERE session_id = ?"),t(n.upsertResume,`INSERT INTO session_resume (session_id, snapshot, event_count)
|
|
52
52
|
VALUES (?, ?, ?)
|
|
53
53
|
ON CONFLICT(session_id) DO UPDATE SET
|
|
54
54
|
snapshot = excluded.snapshot,
|
|
55
55
|
event_count = excluded.event_count,
|
|
56
56
|
created_at = datetime('now'),
|
|
57
|
-
consumed = 0`),t(
|
|
57
|
+
consumed = 0`),t(n.getResume,"SELECT snapshot, event_count, consumed FROM session_resume WHERE session_id = ?"),t(n.markResumeConsumed,"UPDATE session_resume SET consumed = 1 WHERE session_id = ?"),t(n.deleteEvents,"DELETE FROM session_events WHERE session_id = ?"),t(n.deleteMeta,"DELETE FROM session_meta WHERE session_id = ?"),t(n.deleteResume,"DELETE FROM session_resume WHERE session_id = ?"),t(n.getOldSessions,"SELECT session_id FROM session_meta WHERE started_at < datetime('now', ? || ' days')")}insertEvent(t,e,s="PostToolUse"){let i=T("sha256").update(e.data).digest("hex").slice(0,16).toUpperCase();this.db.transaction(()=>{if(this.stmt(n.checkDuplicate).get(t,f,e.type,i))return;this.stmt(n.getEventCount).get(t).cnt>=N&&this.stmt(n.evictLowestPriority).run(t),this.stmt(n.insertEvent).run(t,e.type,e.category,e.priority,e.data,s,i),this.stmt(n.updateMetaLastEvent).run(t)})()}getEvents(t,e){let s=e?.limit??1e3,i=e?.type,o=e?.minPriority;return i&&o!==void 0?this.stmt(n.getEventsByTypeAndPriority).all(t,i,o,s):i?this.stmt(n.getEventsByType).all(t,i,s):o!==void 0?this.stmt(n.getEventsByPriority).all(t,o,s):this.stmt(n.getEvents).all(t,s)}getEventCount(t){return this.stmt(n.getEventCount).get(t).cnt}ensureSession(t,e){this.stmt(n.ensureSession).run(t,e)}getSessionStats(t){return this.stmt(n.getSessionStats).get(t)??null}incrementCompactCount(t){this.stmt(n.incrementCompactCount).run(t)}upsertResume(t,e,s){this.stmt(n.upsertResume).run(t,e,s??0)}getResume(t){return this.stmt(n.getResume).get(t)??null}markResumeConsumed(t){this.stmt(n.markResumeConsumed).run(t)}deleteSession(t){this.db.transaction(()=>{this.stmt(n.deleteEvents).run(t),this.stmt(n.deleteResume).run(t),this.stmt(n.deleteMeta).run(t)})()}cleanupOldSessions(t=7){let e=`-${t}`,s=this.stmt(n.getOldSessions).all(e);for(let{session_id:i}of s)this.deleteSession(i);return s.length}};export{_ as SessionDB,U as getWorktreeSuffix};
|
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.28",
|
|
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.28",
|
|
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",
|