context-mode 1.0.142 → 1.0.143

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.
@@ -6,14 +6,14 @@
6
6
  },
7
7
  "metadata": {
8
8
  "description": "Claude Code plugins by Mert Koseoğlu",
9
- "version": "1.0.142"
9
+ "version": "1.0.143"
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.142",
16
+ "version": "1.0.143",
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.142",
3
+ "version": "1.0.143",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "1.0.142",
3
+ "version": "1.0.143",
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.142",
6
+ "version": "1.0.143",
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.142",
3
+ "version": "1.0.143",
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.js CHANGED
@@ -266,7 +266,18 @@ export function loadDatabase() {
266
266
  const raw = new DatabaseSync(path, {
267
267
  readOnly: opts?.readonly ?? false,
268
268
  });
269
- return new NodeSQLiteAdapter(raw);
269
+ const adapter = new NodeSQLiteAdapter(raw);
270
+ // Propagate busy_timeout — node:sqlite's DatabaseSync constructor
271
+ // silently ignores `{ timeout }` (unlike better-sqlite3's native
272
+ // C++ constructor), so we set it via PRAGMA, mirroring the Bun
273
+ // branch above. Without this, the default is 0 and the first
274
+ // write contention surfaces as immediate `SQLITE_BUSY`/`database
275
+ // is locked` — defeating the 30s grace `withRetry()` is built
276
+ // around. See issue #642 and ADR-0001 (multi-writer contract).
277
+ if (opts?.timeout) {
278
+ adapter.pragma(`busy_timeout = ${opts.timeout}`);
279
+ }
280
+ return adapter;
270
281
  };
271
282
  }
272
283
  else {
@@ -0,0 +1,130 @@
1
+ /**
2
+ * OpenClaw TypeScript plugin entry point for context-mode.
3
+ *
4
+ * Exports an object with { id, name, configSchema, register(api) } for
5
+ * declarative metadata and config validation before code execution.
6
+ *
7
+ * register(api) registers:
8
+ * - before_tool_call hook — Routing enforcement (deny/modify/passthrough)
9
+ * - after_tool_call hook — Session event capture
10
+ * - command:new hook — Session initialization and cleanup
11
+ * - session_start hook — Re-key DB session to OpenClaw's session ID
12
+ * - before_compaction hook — Flush events to resume snapshot
13
+ * - after_compaction hook — Increment compact count
14
+ * - before_prompt_build (p=10) — Resume snapshot injection into system context
15
+ * - before_prompt_build (p=5) — Routing instruction injection into system context
16
+ * - context-mode engine — Context engine with compaction management
17
+ * - /ctx-stats command — Auto-reply command for session statistics
18
+ * - /ctx-doctor command — Auto-reply command for diagnostics
19
+ * - /ctx-upgrade command — Auto-reply command for upgrade
20
+ *
21
+ * Loaded by OpenClaw via: openclaw.extensions entry in package.json
22
+ *
23
+ * OpenClaw plugin paradigm:
24
+ * - Plugins export { id, name, configSchema, register(api) } for metadata
25
+ * - api.registerHook() for event-driven hooks
26
+ * - api.on() for typed lifecycle hooks
27
+ * - api.registerContextEngine() for compaction ownership
28
+ * - api.registerCommand() for auto-reply slash commands
29
+ * - Plugins run in-process with the Gateway (trusted code)
30
+ */
31
+ import type { OpenClawToolDef } from "./openclaw/mcp-tools.js";
32
+ /** Context for auto-reply command handlers. */
33
+ interface CommandContext {
34
+ senderId?: string;
35
+ channel?: string;
36
+ isAuthorizedSender?: boolean;
37
+ args?: string;
38
+ commandBody?: string;
39
+ config?: Record<string, unknown>;
40
+ }
41
+ /** OpenClaw plugin API provided to the register function. */
42
+ interface OpenClawPluginApi {
43
+ registerHook(event: string, handler: (...args: unknown[]) => unknown, meta: {
44
+ name: string;
45
+ description: string;
46
+ }): void;
47
+ /**
48
+ * Register a typed lifecycle hook.
49
+ * Supported names: "session_start", "before_compaction", "after_compaction",
50
+ * "before_prompt_build"
51
+ */
52
+ on(event: string, handler: (...args: unknown[]) => unknown, opts?: {
53
+ priority?: number;
54
+ }): void;
55
+ registerContextEngine(id: string, factory: () => ContextEngineInstance): void;
56
+ registerCommand?(cmd: {
57
+ name: string;
58
+ description: string;
59
+ acceptsArgs?: boolean;
60
+ requireAuth?: boolean;
61
+ handler: (ctx: CommandContext) => {
62
+ text: string;
63
+ } | Promise<{
64
+ text: string;
65
+ }>;
66
+ }): void;
67
+ registerCli?(factory: (ctx: {
68
+ program: unknown;
69
+ }) => void, meta: {
70
+ commands: string[];
71
+ }): void;
72
+ /**
73
+ * Register an agent tool (OpenClaw native registerTool) — see
74
+ * refs/platforms/openclaw/docs/plugins/building-plugins.md:116. Optional in
75
+ * the type so we degrade silently on legacy hosts that pre-date this API.
76
+ */
77
+ registerTool?(tool: OpenClawToolDef, opts?: {
78
+ optional?: boolean;
79
+ }): void;
80
+ logger?: {
81
+ info: (...args: unknown[]) => void;
82
+ error: (...args: unknown[]) => void;
83
+ debug?: (...args: unknown[]) => void;
84
+ warn?: (...args: unknown[]) => void;
85
+ };
86
+ }
87
+ /** Context engine instance returned by the factory. */
88
+ interface ContextEngineInstance {
89
+ info: {
90
+ id: string;
91
+ name: string;
92
+ ownsCompaction: boolean;
93
+ };
94
+ ingest(data: unknown): Promise<{
95
+ ingested: boolean;
96
+ }>;
97
+ assemble(ctx: {
98
+ messages: unknown[];
99
+ }): Promise<{
100
+ messages: unknown[];
101
+ estimatedTokens: number;
102
+ }>;
103
+ compact(): Promise<{
104
+ ok: boolean;
105
+ compacted: boolean;
106
+ }>;
107
+ }
108
+ /**
109
+ * OpenClaw plugin definition. The object form provides declarative metadata
110
+ * (id, name, configSchema) that OpenClaw can read without executing code.
111
+ * register() is called once per agent session with a fresh api object.
112
+ * Each call creates isolated closures (db, sessionId, hooks) — no shared state.
113
+ */
114
+ declare const _default: {
115
+ id: string;
116
+ name: string;
117
+ configSchema: {
118
+ type: "object";
119
+ properties: {
120
+ enabled: {
121
+ type: "boolean";
122
+ default: boolean;
123
+ description: string;
124
+ };
125
+ };
126
+ additionalProperties: boolean;
127
+ };
128
+ register(api: OpenClawPluginApi): void;
129
+ };
130
+ export default _default;