context-mode 1.0.3 → 1.0.4
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/build/cli.js +13 -7
- package/build/server.js +1 -1
- package/hooks/gemini-cli/aftertool.mjs +1 -2
- package/hooks/gemini-cli/beforetool.mjs +1 -2
- package/hooks/gemini-cli/precompress.mjs +1 -2
- package/hooks/gemini-cli/sessionstart.mjs +1 -2
- package/hooks/posttooluse.mjs +1 -2
- package/hooks/precompact.mjs +1 -2
- package/hooks/pretooluse.mjs +1 -2
- package/hooks/sessionstart.mjs +1 -2
- package/hooks/suppress-stderr.mjs +25 -0
- package/hooks/userpromptsubmit.mjs +1 -2
- package/hooks/vscode-copilot/posttooluse.mjs +1 -2
- package/hooks/vscode-copilot/precompact.mjs +1 -2
- package/hooks/vscode-copilot/pretooluse.mjs +1 -2
- package/hooks/vscode-copilot/sessionstart.mjs +1 -2
- 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.4"
|
|
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.4",
|
|
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.4",
|
|
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",
|
package/build/cli.js
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
import * as p from "@clack/prompts";
|
|
15
15
|
import color from "picocolors";
|
|
16
16
|
import { execSync } from "node:child_process";
|
|
17
|
-
import { readFileSync, cpSync, accessSync, readdirSync, rmSync, constants } from "node:fs";
|
|
17
|
+
import { readFileSync, cpSync, accessSync, readdirSync, rmSync, closeSync, openSync, constants } from "node:fs";
|
|
18
18
|
import { resolve, dirname, join } from "node:path";
|
|
19
|
-
import { tmpdir } from "node:os";
|
|
19
|
+
import { tmpdir, devNull } from "node:os";
|
|
20
20
|
import { fileURLToPath } from "node:url";
|
|
21
21
|
import { detectRuntimes, getRuntimeSummary, hasBunRuntime, getAvailableLanguages, } from "./runtime.js";
|
|
22
22
|
// ── Adapter imports ──────────────────────────────────────
|
|
@@ -46,11 +46,17 @@ const HOOK_MAP = {
|
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
async function hookDispatch(platform, event) {
|
|
49
|
-
// Suppress stderr — native C++ modules (better-sqlite3)
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
49
|
+
// Suppress stderr at OS fd level — native C++ modules (better-sqlite3) write
|
|
50
|
+
// directly to fd 2 during initialization, bypassing Node.js process.stderr.
|
|
51
|
+
// Platforms like Claude Code interpret ANY stderr output as hook failure.
|
|
52
|
+
// Cross-platform: os.devNull → /dev/null (Unix) or \\.\NUL (Windows). See: #68
|
|
53
|
+
try {
|
|
54
|
+
closeSync(2);
|
|
55
|
+
openSync(devNull, "w"); // Acquires fd 2 (lowest available)
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
process.stderr.write = (() => true);
|
|
59
|
+
}
|
|
54
60
|
const scriptPath = HOOK_MAP[platform]?.[event];
|
|
55
61
|
if (!scriptPath) {
|
|
56
62
|
process.exit(1);
|
package/build/server.js
CHANGED
|
@@ -12,7 +12,7 @@ import { PolyglotExecutor } from "./executor.js";
|
|
|
12
12
|
import { ContentStore, cleanupStaleDBs } from "./store.js";
|
|
13
13
|
import { readBashPolicies, evaluateCommandDenyOnly, extractShellCommands, readToolDenyPatterns, evaluateFilePath, } from "./security.js";
|
|
14
14
|
import { detectRuntimes, getRuntimeSummary, getAvailableLanguages, hasBunRuntime, } from "./runtime.js";
|
|
15
|
-
const VERSION = "1.0.
|
|
15
|
+
const VERSION = "1.0.4";
|
|
16
16
|
// Prevent silent server death from unhandled async errors
|
|
17
17
|
process.on("unhandledRejection", (err) => {
|
|
18
18
|
process.stderr.write(`[context-mode] unhandledRejection: ${err}\n`);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
process.stderr.write = () => true;
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Gemini CLI BeforeTool hook for context-mode
|
|
6
5
|
* Thin wrapper — uses shared routing core, no self-heal, no Claude Code-specific logic.
|
package/hooks/posttooluse.mjs
CHANGED
package/hooks/precompact.mjs
CHANGED
package/hooks/pretooluse.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
process.stderr.write = () => true;
|
|
2
|
+
import "./suppress-stderr.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Unified PreToolUse hook for context-mode (Claude Code)
|
|
6
5
|
* Redirects data-fetching tools to context-mode MCP tools
|
package/hooks/sessionstart.mjs
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suppress stderr at the OS file descriptor level.
|
|
3
|
+
*
|
|
4
|
+
* Native C++ modules (better-sqlite3) write directly to fd 2 during
|
|
5
|
+
* initialization, bypassing Node.js process.stderr. Platforms like
|
|
6
|
+
* Claude Code interpret ANY stderr output as hook failure.
|
|
7
|
+
*
|
|
8
|
+
* This module MUST be the first import in every hook entry point.
|
|
9
|
+
* ESM evaluates imports depth-first in declaration order, so importing
|
|
10
|
+
* this module first ensures fd 2 is redirected to /dev/null before
|
|
11
|
+
* any native modules are loaded.
|
|
12
|
+
*
|
|
13
|
+
* Cross-platform: os.devNull → /dev/null (Unix) or \\.\NUL (Windows).
|
|
14
|
+
* See: https://github.com/mksglu/context-mode/issues/68
|
|
15
|
+
*/
|
|
16
|
+
import { closeSync, openSync } from "node:fs";
|
|
17
|
+
import { devNull } from "node:os";
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
closeSync(2);
|
|
21
|
+
openSync(devNull, "w"); // Acquires fd 2 (lowest available)
|
|
22
|
+
} catch {
|
|
23
|
+
// Fallback: suppress at Node.js stream level
|
|
24
|
+
process.stderr.write = /** @type {any} */ (() => true);
|
|
25
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
process.stderr.write = () => true;
|
|
2
|
+
import "../suppress-stderr.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* VS Code Copilot PreToolUse hook for context-mode
|
|
6
5
|
* Thin wrapper — uses shared routing core, no self-heal, no Claude Code-specific logic.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-mode",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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
|
@@ -202,7 +202,7 @@ ${n}`}}};import{createRequire as YE}from"node:module";var dd=null;function $y(){
|
|
|
202
202
|
`);Buffer.byteLength(x)>r&&p.length>1&&(p.pop(),g(),p=[_])}g(),i=[]},u=0;for(;u<o.length;){let l=o[u];if(/^[-_*]{3,}\s*$/.test(l)){c(),u++;continue}let d=l.match(/^(#{1,4})\s+(.+)$/);if(d){c();let m=d[1].length,p=d[2].trim();for(;s.length>0&&s[s.length-1].level>=m;)s.pop();s.push({level:m,text:p}),a=p,i.push(l),u++;continue}let f=l.match(/^(`{3,})(.*)?$/);if(f){let m=f[1],p=[l];for(u++;u<o.length;){if(p.push(o[u]),o[u].startsWith(m)&&o[u].trim()===m){u++;break}u++}i.push(...p);continue}i.push(l),u++}return c(),n}#T(e,r){let n=e.split(/\n\s*\n/);if(n.length>=3&&n.length<=200&&n.every(c=>Buffer.byteLength(c)<5e3))return n.map((c,u)=>{let l=c.trim();return{title:l.split(`
|
|
203
203
|
`)[0].slice(0,80)||`Section ${u+1}`,content:l}}).filter(c=>c.content.length>0);let o=e.split(`
|
|
204
204
|
`);if(o.length<=r)return[{title:"Output",content:e}];let s=[],a=Math.max(r-2,1);for(let c=0;c<o.length;c+=a){let u=o.slice(c,c+r);if(u.length===0)break;let l=c+1,d=Math.min(c+u.length,o.length),f=u[0]?.trim().slice(0,80);s.push({title:f||`Lines ${l}-${d}`,content:u.join(`
|
|
205
|
-
`)})}return s}#b(e,r,n,o){let s=r.length>0?r.join(" > "):"(root)",i=JSON.stringify(e,null,2);if(Buffer.byteLength(i)<=o&&!(typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).some(c=>typeof c=="object"&&c!==null))){n.push({title:s,content:i,hasCode:!0});return}if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=Object.entries(e);if(a.length>0){for(let[c,u]of a)this.#b(u,[...r,c],n,o);return}n.push({title:s,content:i,hasCode:!0});return}if(Array.isArray(e)){this.#P(e,r,n,o);return}n.push({title:s,content:i,hasCode:!1})}#E(e){if(e.length===0)return null;let r=e[0];if(typeof r!="object"||r===null||Array.isArray(r))return null;let n=["id","name","title","path","slug","key","label"],o=r;for(let s of n)if(s in o&&(typeof o[s]=="string"||typeof o[s]=="number"))return s;return null}#z(e,r,n,o,s){let i=e?`${e} > `:"";if(!s)return r===n?`${i}[${r}]`:`${i}[${r}-${n}]`;let a=c=>String(c[s]);return o.length===1?`${i}${a(o[0])}`:o.length<=3?i+o.map(a).join(", "):`${i}${a(o[0])}\u2026${a(o[o.length-1])}`}#P(e,r,n,o){let s=r.length>0?r.join(" > "):"(root)",i=this.#E(e),a=[],c=0,u=l=>{if(a.length===0)return;let d=this.#z(s,c,l,a,i);n.push({title:d,content:JSON.stringify(a,null,2),hasCode:!0})};for(let l=0;l<e.length;l++){a.push(e[l]);let d=JSON.stringify(a,null,2);Buffer.byteLength(d)>o&&a.length>1&&(a.pop(),u(l-1),a=[e[l]],c=l)}u(c+a.length-1)}#R(e,r){return e.length===0?r||"Untitled":e.map(n=>n.text).join(" > ")}};import{readFileSync as Iy}from"node:fs";import{resolve as bn}from"node:path";import{homedir as Oy}from"node:os";function Ny(t){let e=t.match(/^Bash\((.+)\)$/);return e?e[1]:null}function oz(t){let e=t.match(/^(\w+)\((.+)\)$/);return e?{tool:e[1],glob:e[2]}:null}function sz(t){return t.replace(/[.*+?^${}()|[\]\\\/\-]/g,"\\$&")}function Ry(t){return t.replace(/[.+?^${}()|[\]\\\/\-]/g,"\\$&").replace(/\*/g,".*")}function iz(t,e=!1){let r,n=t.indexOf(":");if(n!==-1){let o=t.slice(0,n),s=t.slice(n+1),i=sz(o),a=Ry(s);r=`^${i}(\\s${a})?$`}else r=`^${Ry(t)}$`;return new RegExp(r,e?"i":"")}function az(t,e=!1){let r="",n=0;for(;n<t.length;)t[n]==="*"&&t[n+1]==="*"?n+2<t.length&&t[n+2]==="/"?(r+="(.*/)?",n+=3):(r+=".*",n+=2):t[n]==="*"?(r+="[^/]*",n++):t[n]==="?"?(r+="[^/]",n++):(r+=t[n].replace(/[.+^${}()|[\]\\\/\-]/g,"\\$&"),n++);return new RegExp(`^${r}$`,e?"i":"")}function cz(t,e,r=!1){for(let n of e){let o=Ny(n);if(o&&iz(o,r).test(t))return n}return null}function uz(t){let e=[],r="",n=!1,o=!1,s=!1;for(let i=0;i<t.length;i++){let a=t[i],c=i>0?t[i-1]:"";a==="'"&&!o&&!s&&c!=="\\"?(n=!n,r+=a):a==='"'&&!n&&!s&&c!=="\\"?(o=!o,r+=a):a==="`"&&!n&&!o&&c!=="\\"?(s=!s,r+=a):!n&&!o&&!s?a===";"?(e.push(r.trim()),r=""):a==="|"&&t[i+1]==="|"||a==="&"&&t[i+1]==="&"?(e.push(r.trim()),r="",i++):a==="|"?(e.push(r.trim()),r=""):r+=a:r+=a}return r.trim()&&e.push(r.trim()),e.filter(i=>i.length>0)}function pd(t){let e;try{e=Iy(t,"utf-8")}catch{return null}let r;try{r=JSON.parse(e)}catch{return null}let n=r?.permissions;if(!n||typeof n!="object")return null;let o=s=>Array.isArray(s)?s.filter(i=>typeof i=="string"&&Ny(i)!==null):[];return{allow:o(n.allow),deny:o(n.deny),ask:o(n.ask)}}function fd(t,e){let r=[];if(t){let s=bn(t,".claude","settings.local.json"),i=pd(s);i&&r.push(i);let a=bn(t,".claude","settings.json"),c=pd(a);c&&r.push(c)}let n=e??bn(Oy(),".claude","settings.json"),o=pd(n);return o&&r.push(o),r}function Cy(t,e,r){let n=[],o=a=>{let c;try{c=Iy(a,"utf-8")}catch{return null}let u;try{u=JSON.parse(c)}catch{return null}let l=u?.permissions?.deny;if(!Array.isArray(l))return[];let d=[];for(let f of l){if(typeof f!="string")continue;let m=oz(f);m&&m.tool===t&&d.push(m.glob)}return d};if(e){let a=o(bn(e,".claude","settings.local.json"));a!==null&&n.push(a);let c=o(bn(e,".claude","settings.json"));c!==null&&n.push(c)}let s=r??bn(Oy(),".claude","settings.json"),i=o(s);return i!==null&&n.push(i),n}function md(t,e,r=process.platform==="win32"){let n=uz(t);for(let o of n)for(let s of e){let i=cz(o,s.deny,r);if(i)return{decision:"deny",matchedPattern:i}}return{decision:"allow"}}function Ay(t,e,r=process.platform==="win32"){let n=t.replace(/\\/g,"/");for(let o of e)for(let s of o)if(az(s,r).test(n))return{denied:!0,matchedPattern:s};return{denied:!1}}var lz={python:[/os\.system\(\s*(['"])(.*?)\1\s*\)/g,/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*(['"])(.*?)\1/g],javascript:[/exec(?:Sync|File|FileSync)?\(\s*(['"`])(.*?)\1/g,/spawn(?:Sync)?\(\s*(['"`])(.*?)\1/g],typescript:[/exec(?:Sync|File|FileSync)?\(\s*(['"`])(.*?)\1/g,/spawn(?:Sync)?\(\s*(['"`])(.*?)\1/g],ruby:[/system\(\s*(['"])(.*?)\1/g,/`(.*?)`/g],go:[/exec\.Command\(\s*(['"`])(.*?)\1/g],php:[/shell_exec\(\s*(['"`])(.*?)\1/g,/(?:^|[^.])exec\(\s*(['"`])(.*?)\1/g,/(?:^|[^.])system\(\s*(['"`])(.*?)\1/g,/passthru\(\s*(['"`])(.*?)\1/g,/proc_open\(\s*(['"`])(.*?)\1/g],rust:[/Command::new\(\s*(['"`])(.*?)\1/g]};function dz(t){let e=[],r=/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*\[([^\]]+)\]/g,n;for(;(n=r.exec(t))!==null;){let s=[...n[1].matchAll(/(['"])(.*?)\1/g)].map(i=>i[2]);s.length>0&&e.push(s.join(" "))}return e}function jy(t,e){let r=lz[e];if(!r&&e!=="python")return[];let n=[];if(r)for(let o of r){o.lastIndex=0;let s;for(;(s=o.exec(t))!==null;){let i=s[s.length-1];i&&n.push(i)}}return e==="python"&&n.push(...dz(t)),n}var Fy="1.0.
|
|
205
|
+
`)})}return s}#b(e,r,n,o){let s=r.length>0?r.join(" > "):"(root)",i=JSON.stringify(e,null,2);if(Buffer.byteLength(i)<=o&&!(typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).some(c=>typeof c=="object"&&c!==null))){n.push({title:s,content:i,hasCode:!0});return}if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let a=Object.entries(e);if(a.length>0){for(let[c,u]of a)this.#b(u,[...r,c],n,o);return}n.push({title:s,content:i,hasCode:!0});return}if(Array.isArray(e)){this.#P(e,r,n,o);return}n.push({title:s,content:i,hasCode:!1})}#E(e){if(e.length===0)return null;let r=e[0];if(typeof r!="object"||r===null||Array.isArray(r))return null;let n=["id","name","title","path","slug","key","label"],o=r;for(let s of n)if(s in o&&(typeof o[s]=="string"||typeof o[s]=="number"))return s;return null}#z(e,r,n,o,s){let i=e?`${e} > `:"";if(!s)return r===n?`${i}[${r}]`:`${i}[${r}-${n}]`;let a=c=>String(c[s]);return o.length===1?`${i}${a(o[0])}`:o.length<=3?i+o.map(a).join(", "):`${i}${a(o[0])}\u2026${a(o[o.length-1])}`}#P(e,r,n,o){let s=r.length>0?r.join(" > "):"(root)",i=this.#E(e),a=[],c=0,u=l=>{if(a.length===0)return;let d=this.#z(s,c,l,a,i);n.push({title:d,content:JSON.stringify(a,null,2),hasCode:!0})};for(let l=0;l<e.length;l++){a.push(e[l]);let d=JSON.stringify(a,null,2);Buffer.byteLength(d)>o&&a.length>1&&(a.pop(),u(l-1),a=[e[l]],c=l)}u(c+a.length-1)}#R(e,r){return e.length===0?r||"Untitled":e.map(n=>n.text).join(" > ")}};import{readFileSync as Iy}from"node:fs";import{resolve as bn}from"node:path";import{homedir as Oy}from"node:os";function Ny(t){let e=t.match(/^Bash\((.+)\)$/);return e?e[1]:null}function oz(t){let e=t.match(/^(\w+)\((.+)\)$/);return e?{tool:e[1],glob:e[2]}:null}function sz(t){return t.replace(/[.*+?^${}()|[\]\\\/\-]/g,"\\$&")}function Ry(t){return t.replace(/[.+?^${}()|[\]\\\/\-]/g,"\\$&").replace(/\*/g,".*")}function iz(t,e=!1){let r,n=t.indexOf(":");if(n!==-1){let o=t.slice(0,n),s=t.slice(n+1),i=sz(o),a=Ry(s);r=`^${i}(\\s${a})?$`}else r=`^${Ry(t)}$`;return new RegExp(r,e?"i":"")}function az(t,e=!1){let r="",n=0;for(;n<t.length;)t[n]==="*"&&t[n+1]==="*"?n+2<t.length&&t[n+2]==="/"?(r+="(.*/)?",n+=3):(r+=".*",n+=2):t[n]==="*"?(r+="[^/]*",n++):t[n]==="?"?(r+="[^/]",n++):(r+=t[n].replace(/[.+^${}()|[\]\\\/\-]/g,"\\$&"),n++);return new RegExp(`^${r}$`,e?"i":"")}function cz(t,e,r=!1){for(let n of e){let o=Ny(n);if(o&&iz(o,r).test(t))return n}return null}function uz(t){let e=[],r="",n=!1,o=!1,s=!1;for(let i=0;i<t.length;i++){let a=t[i],c=i>0?t[i-1]:"";a==="'"&&!o&&!s&&c!=="\\"?(n=!n,r+=a):a==='"'&&!n&&!s&&c!=="\\"?(o=!o,r+=a):a==="`"&&!n&&!o&&c!=="\\"?(s=!s,r+=a):!n&&!o&&!s?a===";"?(e.push(r.trim()),r=""):a==="|"&&t[i+1]==="|"||a==="&"&&t[i+1]==="&"?(e.push(r.trim()),r="",i++):a==="|"?(e.push(r.trim()),r=""):r+=a:r+=a}return r.trim()&&e.push(r.trim()),e.filter(i=>i.length>0)}function pd(t){let e;try{e=Iy(t,"utf-8")}catch{return null}let r;try{r=JSON.parse(e)}catch{return null}let n=r?.permissions;if(!n||typeof n!="object")return null;let o=s=>Array.isArray(s)?s.filter(i=>typeof i=="string"&&Ny(i)!==null):[];return{allow:o(n.allow),deny:o(n.deny),ask:o(n.ask)}}function fd(t,e){let r=[];if(t){let s=bn(t,".claude","settings.local.json"),i=pd(s);i&&r.push(i);let a=bn(t,".claude","settings.json"),c=pd(a);c&&r.push(c)}let n=e??bn(Oy(),".claude","settings.json"),o=pd(n);return o&&r.push(o),r}function Cy(t,e,r){let n=[],o=a=>{let c;try{c=Iy(a,"utf-8")}catch{return null}let u;try{u=JSON.parse(c)}catch{return null}let l=u?.permissions?.deny;if(!Array.isArray(l))return[];let d=[];for(let f of l){if(typeof f!="string")continue;let m=oz(f);m&&m.tool===t&&d.push(m.glob)}return d};if(e){let a=o(bn(e,".claude","settings.local.json"));a!==null&&n.push(a);let c=o(bn(e,".claude","settings.json"));c!==null&&n.push(c)}let s=r??bn(Oy(),".claude","settings.json"),i=o(s);return i!==null&&n.push(i),n}function md(t,e,r=process.platform==="win32"){let n=uz(t);for(let o of n)for(let s of e){let i=cz(o,s.deny,r);if(i)return{decision:"deny",matchedPattern:i}}return{decision:"allow"}}function Ay(t,e,r=process.platform==="win32"){let n=t.replace(/\\/g,"/");for(let o of e)for(let s of o)if(az(s,r).test(n))return{denied:!0,matchedPattern:s};return{denied:!1}}var lz={python:[/os\.system\(\s*(['"])(.*?)\1\s*\)/g,/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*(['"])(.*?)\1/g],javascript:[/exec(?:Sync|File|FileSync)?\(\s*(['"`])(.*?)\1/g,/spawn(?:Sync)?\(\s*(['"`])(.*?)\1/g],typescript:[/exec(?:Sync|File|FileSync)?\(\s*(['"`])(.*?)\1/g,/spawn(?:Sync)?\(\s*(['"`])(.*?)\1/g],ruby:[/system\(\s*(['"])(.*?)\1/g,/`(.*?)`/g],go:[/exec\.Command\(\s*(['"`])(.*?)\1/g],php:[/shell_exec\(\s*(['"`])(.*?)\1/g,/(?:^|[^.])exec\(\s*(['"`])(.*?)\1/g,/(?:^|[^.])system\(\s*(['"`])(.*?)\1/g,/passthru\(\s*(['"`])(.*?)\1/g,/proc_open\(\s*(['"`])(.*?)\1/g],rust:[/Command::new\(\s*(['"`])(.*?)\1/g]};function dz(t){let e=[],r=/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*\[([^\]]+)\]/g,n;for(;(n=r.exec(t))!==null;){let s=[...n[1].matchAll(/(['"])(.*?)\1/g)].map(i=>i[2]);s.length>0&&e.push(s.join(" "))}return e}function jy(t,e){let r=lz[e];if(!r&&e!=="python")return[];let n=[];if(r)for(let o of r){o.lastIndex=0;let s;for(;(s=o.exec(t))!==null;){let i=s[s.length-1];i&&n.push(i)}}return e==="python"&&n.push(...dz(t)),n}var Fy="1.0.4";process.on("unhandledRejection",t=>{process.stderr.write(`[context-mode] unhandledRejection: ${t}
|
|
206
206
|
`)});process.on("uncaughtException",t=>{process.stderr.write(`[context-mode] uncaughtException: ${t?.message??t}
|
|
207
207
|
`)});var vd=xi(),_z=gy(vd),Et=new yi({name:"context-mode",version:Fy}),zo=new $i({runtimes:vd,projectRoot:process.env.CLAUDE_PROJECT_DIR}),$n=null;function vz(t){try{let e=ki(qy(),".claude","context-mode","sessions");if(!Dy(e))return;let r=mz(e).filter(n=>n.endsWith("-events.md"));for(let n of r){let o=ki(e,n);try{t.index({path:o,source:"session-events"}),fz(o)}catch{}}}catch{}}function Po(){return $n||($n=new wi),vz($n),$n}var De={calls:{},bytesReturned:{},bytesIndexed:0,bytesSandboxed:0,sessionStart:Date.now()};function W(t,e){let r=e.content.reduce((n,o)=>n+Buffer.byteLength(o.text),0);return De.calls[t]=(De.calls[t]||0)+1,De.bytesReturned[t]=(De.bytesReturned[t]||0)+r,e}function ir(t){De.bytesIndexed+=t}function xd(t,e){try{let r=fd(process.env.CLAUDE_PROJECT_DIR),n=md(t,r);if(n.decision==="deny")return W(e,{content:[{type:"text",text:`Command blocked by security policy: matches deny pattern ${n.matchedPattern}`}],isError:!0})}catch{}return null}function Uy(t,e,r){try{let n=jy(t,e);if(n.length===0)return null;let o=fd(process.env.CLAUDE_PROJECT_DIR);for(let s of n){let i=md(s,o);if(i.decision==="deny")return W(r,{content:[{type:"text",text:`Command blocked by security policy: embedded shell command "${s}" matches deny pattern ${i.matchedPattern}`}],isError:!0})}}catch{}return null}function xz(t,e){try{let r=Cy("Read",process.env.CLAUDE_PROJECT_DIR),n=Ay(t,r);if(n.denied)return W(e,{content:[{type:"text",text:`File access blocked by security policy: path matches Read deny pattern ${n.matchedPattern}`}],isError:!0})}catch{}return null}var bz=_z.join(", "),$z=ud()?" (Bun detected \u2014 JS/TS runs 3-5x faster)":"",wz="",kz="";function Sz(t){let e=[],r=0,n=0;for(;n<t.length;)if(t[n]===wz){for(e.push(r),n++;n<t.length&&t[n]!==kz;)r++,n++;n<t.length&&n++}else r++,n++;return e}function Vy(t,e,r=1500,n){if(t.length<=r)return t;let o=[];if(n)for(let u of Sz(n))o.push(u);if(o.length===0){let u=e.toLowerCase().split(/\s+/).filter(d=>d.length>2),l=t.toLowerCase();for(let d of u){let f=l.indexOf(d);for(;f!==-1;)o.push(f),f=l.indexOf(d,f+1)}}if(o.length===0)return t.slice(0,r)+`
|
|
208
208
|
\u2026`;o.sort((u,l)=>u-l);let s=300,i=[];for(let u of o){let l=Math.max(0,u-s),d=Math.min(t.length,u+s);i.length>0&&l<=i[i.length-1][1]?i[i.length-1][1]=d:i.push([l,d])}let a=[],c=0;for(let[u,l]of i){if(c>=r)break;let d=t.slice(u,Math.min(l,u+(r-c)));a.push((u>0?"\u2026":"")+d+(l<t.length?"\u2026":"")),c+=d.length}return a.join(`
|