context-mode 1.0.56 → 1.0.57

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.56"
9
+ "version": "1.0.57"
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.56",
16
+ "version": "1.0.57",
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.56",
3
+ "version": "1.0.57",
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.56",
6
+ "version": "1.0.57",
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.56",
3
+ "version": "1.0.57",
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/server.js CHANGED
@@ -127,7 +127,43 @@ const sessionStats = {
127
127
  cacheBytesSaved: 0, // bytes avoided by TTL cache hits
128
128
  sessionStart: Date.now(),
129
129
  };
130
+ /**
131
+ * Reset session stats to zero. Called when /clear flag is detected.
132
+ * The SessionStart hook writes a .clear-stats flag file on /clear,
133
+ * and the server checks for it before each tool call.
134
+ */
135
+ function resetSessionStats() {
136
+ sessionStats.calls = {};
137
+ sessionStats.bytesReturned = {};
138
+ sessionStats.bytesIndexed = 0;
139
+ sessionStats.bytesSandboxed = 0;
140
+ sessionStats.cacheHits = 0;
141
+ sessionStats.cacheBytesSaved = 0;
142
+ sessionStats.sessionStart = Date.now();
143
+ // Also reset FTS5 content store — drop and recreate on next getStore() call
144
+ if (_store) {
145
+ try {
146
+ _store.cleanup();
147
+ }
148
+ catch { /* best effort */ }
149
+ _store = null;
150
+ }
151
+ }
152
+ /** Check for .clear-stats flag and reset stats if found. */
153
+ function checkClearStatsFlag() {
154
+ const sessDir = join(homedir(), ".claude", "context-mode", "sessions");
155
+ try {
156
+ const flags = readdirSync(sessDir).filter((f) => f.endsWith(".clear-stats"));
157
+ for (const f of flags) {
158
+ unlinkSync(join(sessDir, f));
159
+ }
160
+ if (flags.length > 0)
161
+ resetSessionStats();
162
+ }
163
+ catch { /* best effort */ }
164
+ }
130
165
  function trackResponse(toolName, response) {
166
+ checkClearStatsFlag();
131
167
  const bytes = response.content.reduce((sum, c) => sum + Buffer.byteLength(c.text), 0);
132
168
  sessionStats.calls[toolName] = (sessionStats.calls[toolName] || 0) + 1;
133
169
  sessionStats.bytesReturned[toolName] =
@@ -1370,8 +1406,18 @@ server.registerTool("ctx_stats", {
1370
1406
  description: "Returns context consumption statistics for the current session. " +
1371
1407
  "Shows total bytes returned to context, breakdown by tool, call counts, " +
1372
1408
  "estimated token usage, and context savings ratio.",
1373
- inputSchema: z.object({}),
1374
- }, async () => {
1409
+ inputSchema: z.object({
1410
+ reset: z.boolean().optional().describe("Reset all stats and FTS5 store to zero. Use after /clear."),
1411
+ }),
1412
+ }, async ({ reset }) => {
1413
+ // Check for clear flag BEFORE reading stats
1414
+ checkClearStatsFlag();
1415
+ if (reset) {
1416
+ resetSessionStats();
1417
+ return trackResponse("ctx_stats", {
1418
+ content: [{ type: "text", text: "Session stats and search index reset." }],
1419
+ });
1420
+ }
1375
1421
  const totalBytesReturned = Object.values(sessionStats.bytesReturned).reduce((sum, b) => sum + b, 0);
1376
1422
  const totalCalls = Object.values(sessionStats.calls).reduce((sum, c) => sum + c, 0);
1377
1423
  const uptimeMs = Date.now() - sessionStats.sessionStart;