@mxalbert/context-mode 2.0.2 → 2.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-mode",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "context-mode for Antigravity CLI (agy): sandboxed code execution, FTS5 knowledge base, and session capture. Saves your context window by keeping raw bytes out of the conversation.",
5
5
  "author": {
6
6
  "name": "Mert Koseoğlu",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "context-mode",
3
3
  "description": "context-mode for GitHub Copilot CLI: sandboxed code execution in 11 languages, an FTS5 knowledge base with BM25 ranking, and session capture. Saves your context window by keeping raw bytes out of the conversation.",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "keywords": [
6
6
  "mcp",
7
7
  "context-window",
@@ -685,6 +685,52 @@ function getPlatformSettingsPath(platform) {
685
685
  return undefined;
686
686
  }
687
687
 
688
+ /**
689
+ * Platforms whose PreToolUse response can surface a real "ask" confirmation
690
+ * prompt to the user (hooks/core/formatters.mjs emits permissionDecision:"ask"
691
+ * or the platform equivalent).
692
+ *
693
+ * Everywhere else: an `ask` match on an ordinary Bash command is NOT returned
694
+ * from routePreToolUse (see the Stage-1 comment inside — the host's own
695
+ * permission system decides), while the ctx_* sandbox branches deny with an
696
+ * actionable reason via sandboxAskDecision — the gemini-cli/codex/kimi/kiro
697
+ * formatters silently DROP ask, which would fail the sandbox open. Keep in
698
+ * sync with the per-platform `ask` formatters; claude-code also covers
699
+ * qwen-code, which shares the claude-code hook script and wire protocol
700
+ * (src/cli.ts HOOK_MAP).
701
+ */
702
+ const ASK_CAPABLE_PLATFORMS = new Set([
703
+ "claude-code", // + qwen-code (shared hook script / wire protocol)
704
+ "vscode-copilot",
705
+ "jetbrains-copilot",
706
+ "copilot-cli",
707
+ "cursor",
708
+ "antigravity-cli",
709
+ ]);
710
+
711
+ /**
712
+ * Resolve an `ask` policy match inside the ctx_* sandbox tools for platforms
713
+ * with no confirmation surface. Unlike ordinary Bash calls — where the host's
714
+ * own permission system backs the decision up — nothing re-gates sandbox
715
+ * execution, and several formatters (gemini-cli, codex, kimi return null;
716
+ * kiro exits 0) would silently drop an `ask` decision and run the code
717
+ * unconfirmed. Deny with an actionable reason instead: fail-closed,
718
+ * consistent with the plugin adapters (OpenCode/KiloCode/OpenClaw) that
719
+ * block on ask.
720
+ */
721
+ function sandboxAskDecision(platform, describe, matchedPattern) {
722
+ if (ASK_CAPABLE_PLATFORMS.has(platform || "claude-code")) {
723
+ return { action: "ask" };
724
+ }
725
+ return {
726
+ action: "deny",
727
+ reason:
728
+ `Blocked by security policy: ${describe} matches ask pattern ${matchedPattern} — ` +
729
+ "this platform has no interactive confirmation path for sandbox execution. " +
730
+ "Move the pattern to allow (or deny) in your settings to make the decision explicit.",
731
+ };
732
+ }
733
+
688
734
  /**
689
735
  * Route a PreToolUse event. Returns normalized decision object or null for passthrough.
690
736
  *
@@ -749,9 +795,25 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
749
795
  return { action: "deny", reason: `Blocked by security policy: matches deny pattern ${result.matchedPattern}` };
750
796
  }
751
797
  if (result.decision === "ask" && result.matchedPattern) {
752
- return { action: "ask" };
798
+ // An ask pattern expresses "confirm with me" — a prompt, not a
799
+ // block. Only surface the ask decision on platforms whose
800
+ // PreToolUse response can render a real confirmation prompt
801
+ // (ASK_CAPABLE_PLATFORMS). Elsewhere the decision degraded into
802
+ // a hard block — the OpenCode/KiloCode plugins throw and OpenClaw
803
+ // blocks on ask — silently converting a confirmation intent into
804
+ // a denial: `Bash(git commit:*)` ask-listed for Claude Code's
805
+ // prompt hard-blocked `git commit` on OpenCode with no way to
806
+ // proceed. Fall through to Stage 2 and let the host's own
807
+ // permission system decide. The ctx_* sandbox branches below
808
+ // keep ask enforcement fail-safe instead — prompt where the
809
+ // platform can render one, deny with an actionable reason
810
+ // elsewhere — because no host permission system backs those
811
+ // calls.
812
+ if (ASK_CAPABLE_PLATFORMS.has(platform || "claude-code")) {
813
+ return { action: "ask" };
814
+ }
753
815
  }
754
- // "allow" or no match → fall through to Stage 2
816
+ // "allow" or no match (or ask on a prompt-incapable platform) → fall through to Stage 2
755
817
  }
756
818
  }
757
819
 
@@ -965,7 +1027,7 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
965
1027
  return { action: "deny", reason: `Blocked by security policy: shell code matches deny pattern ${result.matchedPattern}` };
966
1028
  }
967
1029
  if (result.decision === "ask" && result.matchedPattern) {
968
- return { action: "ask" };
1030
+ return sandboxAskDecision(platform, "shell code", result.matchedPattern);
969
1031
  }
970
1032
  }
971
1033
  }
@@ -981,7 +1043,7 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
981
1043
  // Check file path against Read deny patterns
982
1044
  const filePath = toolInput.path ?? "";
983
1045
  const denyGlobs = security.readToolDenyPatterns("Read", projectDir, platformSettingsPath);
984
- const evalResult = security.evaluateFilePath(filePath, denyGlobs);
1046
+ const evalResult = security.evaluateFilePath(filePath, denyGlobs, undefined, projectDir);
985
1047
  if (evalResult.denied) {
986
1048
  return { action: "deny", reason: `Blocked by security policy: file path matches Read deny pattern ${evalResult.matchedPattern}` };
987
1049
  }
@@ -997,7 +1059,7 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
997
1059
  return { action: "deny", reason: `Blocked by security policy: shell code matches deny pattern ${result.matchedPattern}` };
998
1060
  }
999
1061
  if (result.decision === "ask" && result.matchedPattern) {
1000
- return { action: "ask" };
1062
+ return sandboxAskDecision(platform, "shell code", result.matchedPattern);
1001
1063
  }
1002
1064
  }
1003
1065
  }
@@ -1018,7 +1080,7 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
1018
1080
  return { action: "deny", reason: `Blocked by security policy: batch command "${entry.label ?? cmd}" matches deny pattern ${result.matchedPattern}` };
1019
1081
  }
1020
1082
  if (result.decision === "ask" && result.matchedPattern) {
1021
- return { action: "ask" };
1083
+ return sandboxAskDecision(platform, `batch command "${entry.label ?? cmd}"`, result.matchedPattern);
1022
1084
  }
1023
1085
  }
1024
1086
  }
@@ -1048,3 +1110,104 @@ export function routePreToolUse(toolName, toolInput, projectDir, platform, sessi
1048
1110
  // Unknown tool — pass through
1049
1111
  return null;
1050
1112
  }
1113
+
1114
+ /**
1115
+ * Route an OpenCode v2 permission "evaluate" event (ctx.permission.hook).
1116
+ *
1117
+ * v2's permission system asserts every core-tool action before execution and
1118
+ * lets plugins mutate the decision: `event.effect` ("allow" | "deny" | "ask")
1119
+ * and `event.message`. This maps context-mode's security policies onto that
1120
+ * surface, restoring ask/confirmation semantics that the execute.before bridge
1121
+ * cannot express (an ask there can only throw = hard block):
1122
+ *
1123
+ * - deny match → { effect: "deny" } — blocked with a reason. Normally
1124
+ * pre-empted by the execute.before throw (which fires first and is
1125
+ * unaffected by --auto); kept as defense-in-depth for any assert path
1126
+ * execute.before misses.
1127
+ * - ask match → { effect: "ask" } — an interactive confirmation in
1128
+ * TUI runs, restoring the user's ask intent even when host allow rules
1129
+ * would have auto-approved (verified live: a project-tier allow cannot
1130
+ * mask a global-tier ask). Under `--auto` the host auto-approves the
1131
+ * resulting ask too — an explicit opt-in (verified live).
1132
+ * - allow match → { effect: "allow" } — skips the host's default-ask
1133
+ * prompt for commands the user's own global rules pre-approve.
1134
+ * - no match → null — NO OPINION: the host decision (its own rules,
1135
+ * default ask, or --auto) stays untouched.
1136
+ *
1137
+ * Asymmetry is deliberate: deny/ask are honored from ALL policy tiers
1138
+ * (project + global — enforcement direction), while allow is honored from
1139
+ * GLOBAL tiers only. A project-shipped .claude/settings.json can harden a
1140
+ * repo's agent (deny/ask) but must not be able to weaken the host's
1141
+ * confirmation by pre-approving commands in a freshly cloned repo.
1142
+ *
1143
+ * Only the v2 "shell" action carries Bash-policy semantics — resources are the
1144
+ * parsed command statements of one shell invocation. Other actions (read,
1145
+ * write, edit, …) have no context-mode policy mapping (routePreToolUse has no
1146
+ * security branch for them either — parity) and return null.
1147
+ *
1148
+ * Fail-open on a missing security module, mirroring routePreToolUse Stage 1.
1149
+ *
1150
+ * @param {string} action - v2 permission action name ("shell" for the shell tool)
1151
+ * @param {string[]} resources - parsed command statement strings
1152
+ * @param {string} [projectDir] - project directory for policy lookup
1153
+ * @param {string} [platform] - platform ID for the adapter settings path
1154
+ * @returns {{ effect: "allow" | "deny" | "ask", message?: string } | null}
1155
+ */
1156
+ export function routePermissionEvaluate(action, resources, projectDir, platform) {
1157
+ if (action !== "shell") return null;
1158
+ if (!Array.isArray(resources) || resources.length === 0) return null;
1159
+ if (!security) return null;
1160
+
1161
+ const platformSettingsPath = getPlatformSettingsPath(platform);
1162
+ // Full policies (project + global) drive deny/ask — enforcement direction.
1163
+ const policies = security.readBashPolicies(projectDir, platformSettingsPath);
1164
+ if (policies.length === 0) return null;
1165
+
1166
+ const commands = resources.filter((r) => typeof r === "string" && r.length > 0);
1167
+ if (commands.length === 0) return null;
1168
+
1169
+ const results = commands.map((command) => security.evaluateCommand(command, policies));
1170
+
1171
+ // Deny wins across all statements (chain semantics: one denied segment
1172
+ // blocks the whole invocation — same as evaluateCommand).
1173
+ const denied = results.find((r) => r.decision === "deny");
1174
+ if (denied) {
1175
+ return {
1176
+ effect: "deny",
1177
+ message: `Blocked by security policy: matches deny pattern ${denied.matchedPattern}`,
1178
+ };
1179
+ }
1180
+
1181
+ // Ask: evaluated per tier INDEPENDENTLY. evaluateCommand on the combined
1182
+ // policy list returns the FIRST definitive result, so a project-tier allow
1183
+ // would mask a later global-tier ask — and since OpenCode v2's default
1184
+ // shell permission is allow, the user's global ask would silently vanish.
1185
+ // Per-policy calls keep evaluateCommand's chain/subshell parsing while
1186
+ // honoring an explicit ask from EVERY tier.
1187
+ for (const command of commands) {
1188
+ for (const policy of policies) {
1189
+ const result = security.evaluateCommand(command, [policy]);
1190
+ if (result.decision === "ask" && result.matchedPattern) {
1191
+ return {
1192
+ effect: "ask",
1193
+ message: `Confirmation required: matches ask pattern ${result.matchedPattern}`,
1194
+ };
1195
+ }
1196
+ }
1197
+ }
1198
+
1199
+ // Allow: global tiers only (the user's own files) — a project cannot
1200
+ // pre-approve. All statements must be explicitly allowed, mirroring
1201
+ // evaluateCommand's "allowed iff every segment explicitly allowed".
1202
+ const globalPolicies = security.readBashPolicies(undefined, platformSettingsPath);
1203
+ if (globalPolicies.length > 0) {
1204
+ const allAllowed = commands.every((command) => {
1205
+ const result = security.evaluateCommand(command, globalPolicies);
1206
+ return result.decision === "allow" && result.matchedPattern;
1207
+ });
1208
+ if (allAllowed) return { effect: "allow" };
1209
+ }
1210
+
1211
+ // No explicit match — no opinion; the host decides.
1212
+ return null;
1213
+ }
@@ -1,2 +1,2 @@
1
- var P=(t,n)=>()=>(t&&(n=t(t=0)),n);var A,O=P(()=>{"use strict";A={"claude-code":"claude-code","gemini-cli-mcp-client":"gemini-cli","antigravity-client":"antigravity","antigravity-cli":"antigravity-cli",agy:"antigravity-cli","cursor-vscode":"cursor","Visual-Studio-Code":"vscode-copilot","copilot-cli":"copilot-cli","GitHub Copilot CLI":"copilot-cli","github-copilot-cli":"copilot-cli","JetBrains Client":"jetbrains-copilot","IntelliJ IDEA":"jetbrains-copilot",PyCharm:"jetbrains-copilot",Codex:"codex","codex-mcp-client":"codex","Kilo Code":"kilo","Kiro CLI":"kiro","Pi CLI":"pi","Pi Coding Agent":"pi","omp-coding-agent":"omp",Zed:"zed",zed:"zed","qwen-code":"qwen-code","qwen-cli-mcp-client":"qwen-code","kimi-code":"kimi",kimi:"kimi","Kimi Code":"kimi"}});import{existsSync as f,readFileSync as G}from"node:fs";import{resolve as d}from"node:path";import{homedir as v}from"node:os";function $(){if(g!==null)return g!=="miss"&&g.hasCM;try{let t=d(v(),".claude","plugins","installed_plugins.json"),n=G(t,"utf-8"),e=JSON.parse(n),r=[...Object.keys(e.plugins??{}),...Object.keys(e.enabledPlugins??{})].some(i=>i.includes("context-mode"));return g={hasCM:r},r}catch{return g="miss",!1}}function S(t){switch(t){case"claude-code":return[".claude"];case"gemini-cli":return[".gemini"];case"antigravity":return[".gemini"];case"antigravity-cli":return[".gemini"];case"openclaw":return[".openclaw"];case"codex":return[".codex"];case"cursor":return[".cursor"];case"vscode-copilot":return[".vscode"];case"copilot-cli":return[".copilot"];case"kiro":return[".kiro"];case"pi":return[".pi"];case"omp":return[".omp"];case"qwen-code":return[".qwen"];case"kimi":return[".kimi-code"];case"kilo":return[".config","kilo"];case"opencode":return[".config","opencode"];case"zed":return[".config","zed"];case"jetbrains-copilot":return[".config","JetBrains"];default:return null}}function b(t){if(t?.name){let i=A[t.name];if(i)return{platform:i,confidence:"high",reason:`MCP clientInfo.name="${t.name}"`};if(t.name.startsWith("qwen-cli-mcp-client"))return{platform:"qwen-code",confidence:"high",reason:`MCP clientInfo.name="${t.name}" (qwen-cli pattern)`}}let n=process.env.CONTEXT_MODE_PLATFORM;if(n&&["claude-code","gemini-cli","kilo","opencode","codex","vscode-copilot","jetbrains-copilot","copilot-cli","cursor","antigravity","antigravity-cli","kiro","pi","omp","zed","qwen-code","kimi"].includes(n))return{platform:n,confidence:"high",reason:`CONTEXT_MODE_PLATFORM=${n} override`};for(let[i,s]of J)if(s.some(a=>a.detect!==!1&&process.env[a.name]))return i==="vscode-copilot"&&$()?{platform:"claude-code",confidence:"high",reason:"VSCODE_PID set but ~/.claude/plugins/installed_plugins.json lists context-mode (issue #539 fallback)"}:{platform:i,confidence:"high",reason:`${s.filter(a=>a.detect!==!1).map(a=>a.name).join(" or ")} env var set`};let e=v(),o=(()=>{let i=process.env.COPILOT_HOME;return i&&i.trim()!==""?i.startsWith("~")?d(e,i.replace(/^~[/\\]?/,"")):d(i):d(e,".copilot")})(),r=f(d(o,"mcp-config.json"))||f(d(o,"hooks","context-mode.json"));return process.env.COPILOT_HOME?.trim()&&r?{platform:"copilot-cli",confidence:"medium",reason:"context-mode config in explicit COPILOT_HOME exists (mcp-config.json or hooks/context-mode.json)"}:f(d(e,".local","bin","agy"))||f(d(e,".gemini","antigravity-cli"))||f(d(e,".gemini","config","mcp_config.json"))?{platform:"antigravity-cli",confidence:"medium",reason:"Antigravity CLI marker exists (~/.local/bin/agy, ~/.gemini/antigravity-cli, or ~/.gemini/config/mcp_config.json)"}:r?{platform:"copilot-cli",confidence:"medium",reason:"context-mode config in Copilot CLI home exists (mcp-config.json or hooks/context-mode.json; honors COPILOT_HOME)"}:f(d(e,".claude"))?{platform:"claude-code",confidence:"medium",reason:"~/.claude/ directory exists"}:f(d(e,".gemini"))?{platform:"gemini-cli",confidence:"medium",reason:"~/.gemini/ directory exists"}:f(d(e,".codex"))?{platform:"codex",confidence:"medium",reason:"~/.codex/ directory exists"}:f(d(e,".kiro"))?{platform:"kiro",confidence:"medium",reason:"~/.kiro/ directory exists"}:f(d(e,".omp"))?{platform:"omp",confidence:"medium",reason:"~/.omp/ directory exists"}:f(d(e,".pi"))?{platform:"pi",confidence:"medium",reason:"~/.pi/ directory exists"}:f(d(e,".qwen"))?{platform:"qwen-code",confidence:"medium",reason:"~/.qwen/ directory exists"}:f(d(e,".kimi-code"))?{platform:"kimi",confidence:"medium",reason:"~/.kimi-code/ directory exists"}:f(d(e,".openclaw"))?{platform:"openclaw",confidence:"medium",reason:"~/.openclaw/ directory exists"}:f(d(e,".cursor"))?{platform:"cursor",confidence:"medium",reason:"~/.cursor/ directory exists"}:f(d(e,".config","kilo"))?{platform:"kilo",confidence:"medium",reason:"~/.config/kilo/ directory exists"}:f(d(e,".config","JetBrains"))?{platform:"jetbrains-copilot",confidence:"medium",reason:"~/.config/JetBrains/ directory exists"}:f(d(e,".config","opencode"))?{platform:"opencode",confidence:"medium",reason:"~/.config/opencode/ directory exists"}:f(d(e,".config","zed"))?{platform:"zed",confidence:"medium",reason:"~/.config/zed/ directory exists"}:{platform:"claude-code",confidence:"low",reason:"No platform detected, defaulting to Claude Code"}}var g,F,J,D=P(()=>{"use strict";O();g=null;F=[["claude-code",[{name:"CLAUDE_CODE_ENTRYPOINT",role:"identification"},{name:"CLAUDE_PLUGIN_ROOT",role:"identification"},{name:"CLAUDE_PROJECT_DIR",role:"workspace"},{name:"CLAUDE_SESSION_ID",role:"identification"}]],["antigravity",[{name:"ANTIGRAVITY_CLI_ALIAS",role:"identification"}]],["cursor",[{name:"CURSOR_CWD",role:"workspace"},{name:"CURSOR_TRACE_ID",role:"identification"},{name:"CURSOR_CLI",role:"identification"}]],["kilo",[{name:"KILO",role:"identification"},{name:"KILO_PID",role:"identification"}]],["opencode",[{name:"OPENCODE_PROJECT_DIR",role:"workspace"},{name:"OPENCODE_CLIENT",role:"identification"},{name:"OPENCODE_TERMINAL",role:"identification"},{name:"OPENCODE",role:"identification"},{name:"OPENCODE_PID",role:"identification"}]],["zed",[{name:"ZED_SESSION_ID",role:"identification"},{name:"ZED_TERM",role:"identification"}]],["codex",[{name:"CODEX_THREAD_ID",role:"identification"},{name:"CODEX_CI",role:"identification"}]],["gemini-cli",[{name:"GEMINI_PROJECT_DIR",role:"workspace"},{name:"GEMINI_CLI",role:"identification"}]],["vscode-copilot",[{name:"VSCODE_CWD",role:"workspace"},{name:"VSCODE_PID",role:"identification"}]],["jetbrains-copilot",[{name:"IDEA_INITIAL_DIRECTORY",role:"workspace"}]],["qwen-code",[{name:"QWEN_PROJECT_DIR",role:"workspace"}]],["omp",[{name:"PI_CODING_AGENT_DIR",role:"workspace"}]],["pi",[{name:"PI_WORKSPACE_DIR",role:"workspace",detect:!1},{name:"PI_PROJECT_DIR",role:"workspace",detect:!1},{name:"PI_CONFIG_DIR",role:"identification"},{name:"PI_SESSION_FILE",role:"identification"},{name:"PI_COMPILED",role:"identification"},{name:"PI_CODING_AGENT",role:"identification"}]]],J=new Map(F)});import{resolve as h}from"node:path";import{homedir as x}from"node:os";function q(t=process.env){let n=t.CLAUDE_CONFIG_DIR;return n&&n.trim()!==""?n.startsWith("~")?h(x(),n.replace(/^~[/\\]?/,"")):h(n):h(x(),".claude")}function V(t=process.env){return h(q(t),"settings.json")}function E(t=process.env){let n=[],e=b();if(e.platform!=="claude-code"){let r=S(e.platform);r&&r.length>0&&n.push(h(x(),...r,"settings.json"))}let o=V(t);return n.includes(o)||n.push(o),n}var R=P(()=>{"use strict";D()});R();import{readFileSync as N,realpathSync as I}from"node:fs";import{relative as z,resolve as m,sep as H}from"node:path";function L(t){let n=t.match(/^Bash\((.+)\)$/);return n?n[1]:null}function W(t){let n=t.match(/^(\w+)\((.+)\)$/);return n?{tool:n[1],glob:n[2]}:null}function B(t){return t.replace(/[.*+?^${}()|[\]\\\/\-]/g,"\\$&")}function T(t){return t.replace(/[.+?^${}()|[\]\\\/\-]/g,"\\$&").replace(/\*/g,".*")}function U(t,n=!1){let e,o=t.indexOf(":");if(o!==-1){let r=t.slice(0,o),i=t.slice(o+1),s=B(r),a=T(i);e=`^${s}(\\s${a})?$`}else e=`^${T(t)}$`;return new RegExp(e,n?"i":"")}function K(t,n=!1){let e="",o=0;for(;o<t.length;)t[o]==="*"&&t[o+1]==="*"?o+2<t.length&&t[o+2]==="/"?(e+="(.*/)?",o+=3):(e+=".*",o+=2):t[o]==="*"?(e+="[^/]*",o++):t[o]==="?"?(e+="[^/]",o++):(e+=t[o].replace(/[.+^${}()|[\]\\\/\-]/g,"\\$&"),o++);return new RegExp(`^${e}$`,n?"i":"")}function w(t,n,e=!1){for(let o of n){let r=L(o);if(r&&U(r,e).test(t))return o}return null}function M(t,n){let e=0;for(let o=n-1;o>=0&&t[o]==="\\";o--)e++;return e%2===1}function X(t){let n=[],e="",o=!1,r=!1,i=!1,s=0;for(let a=0;a<t.length;a++){let c=t[a],l=M(t,a);c==="'"&&!r&&!i&&!l?(o=!o,e+=c):c==='"'&&!o&&!i&&!l?(r=!r,e+=c):c==="`"&&!o&&!r&&!l?(i=!i,e+=c):!o&&!r&&!i?c==="$"&&t[a+1]==="("&&!l?(s++,e+=c+t[a+1],a++):s>0&&c==="("&&!l?(s++,e+=c):c===")"&&s>0&&!l?(s--,e+=c):s===0&&(c===";"||c===`
2
- `||c==="\r")&&!l?(n.push(e.trim()),e=""):s===0&&c==="|"&&t[a+1]==="|"||s===0&&c==="&"&&t[a+1]==="&"?(n.push(e.trim()),e="",a++):s===0&&c==="&"&&!l||s===0&&c==="|"?(n.push(e.trim()),e=""):e+=c:e+=c}return e.trim()&&n.push(e.trim()),n.filter(a=>a.length>0)}function j(t){let n=[],e=!1,o=!1,r=-1,i=[],s=[],a=0;for(let c=0;c<t.length;c++){let l=t[c],u=M(t,c);if(l==="'"&&!o&&r===-1&&!u)e=!e;else if(l==='"'&&!e&&r===-1&&!u)o=!o;else if(l==="`"&&!e&&!o&&!u)if(r===-1)r=c+1;else{let p=t.slice(r,c);n.push(p),n.push(...j(p)),r=-1}else if(!e&&r===-1){if(l==="$"&&t[c+1]==="("&&!u)t[c+2]==="("?(a+=2,c+=2):(i.push(c+2),s.push(a),a++,c++);else if(l==="("&&!u)a++;else if(l===")"&&!u&&(a>0&&a--,s.length>0&&a===s[s.length-1])){s.pop();let p=i.pop(),y=t.slice(p,c);n.push(y)}}}return n}function k(t){let n=[],e=X(t);for(let o of e){n.push(o);for(let r of j(o))n.push(...k(r))}return n}function _(t){let n;try{n=N(t,"utf-8")}catch{return null}let e;try{e=JSON.parse(n)}catch{return null}let o=e?.permissions;if(!o||typeof o!="object")return null;let r=i=>Array.isArray(i)?i.filter(s=>typeof s=="string"&&L(s)!==null):[];return{allow:r(o.allow),deny:r(o.deny),ask:r(o.ask)}}function ye(t,n){let e=[];if(t){let r=m(t,".claude","settings.local.json"),i=_(r);i&&e.push(i);let s=m(t,".claude","settings.json"),a=_(s);a&&e.push(a)}let o=n!==void 0?[n]:E();for(let r of o){let i=_(r);i&&e.push(i)}return e}function we(t,n,e){return Z(t,"deny",n,e)}function Z(t,n,e,o){let r=[],i=a=>{let c;try{c=N(a,"utf-8")}catch{return null}let l;try{l=JSON.parse(c)}catch{return null}let u=l?.permissions?.[n];if(!Array.isArray(u))return[];let p=[];for(let y of u){if(typeof y!="string")continue;let C=W(y);C&&C.tool===t&&p.push(C.glob)}return p};if(e){let a=i(m(e,".claude","settings.local.json"));a!==null&&r.push(a);let c=i(m(e,".claude","settings.json"));c!==null&&r.push(c)}let s=o!==void 0?[o]:E();for(let a of s){let c=i(a);c!==null&&r.push(c)}return r}function Ce(t,n,e=process.platform==="win32"||process.platform==="darwin"){let o=k(t);for(let r of o)for(let i of n){let s=w(r,i.deny,e);if(s)return{decision:"deny",matchedPattern:s}}for(let r of n){let i=!0,s=!1,a,c;for(let l of o){let u=w(l,r.ask,e);if(u){s=!0,a=u;break}let p=w(l,r.allow,e);p?c=p:i=!1}if(s)return{decision:"ask",matchedPattern:a};if(i&&o.length>0)return{decision:"allow",matchedPattern:c}}return{decision:"ask"}}function Pe(t,n,e=process.platform==="win32"||process.platform==="darwin"){let o=k(t);for(let r of o)for(let i of n){let s=w(r,i.deny,e);if(s)return{decision:"deny",matchedPattern:s}}return{decision:"allow"}}function Y(t,n,e=process.platform==="win32"||process.platform==="darwin",o){let r=s=>s.replace(/\\/g,"/"),i=new Set;if(i.add(r(t)),o){let s=m(o,t);i.add(r(s));try{i.add(r(I(s)))}catch{}}for(let s of n)for(let a of s){let c=K(r(a),e);for(let l of i)if(c.test(l))return{denied:!0,matchedPattern:a}}return{denied:!1}}function Q(t,n,e=process.platform==="win32"||process.platform==="darwin"){if(!n)return!0;let o=m(n),r=m(n,t),i=(s,a)=>{let c=s,l=a;if(e&&(c=c.toLowerCase(),l=l.toLowerCase()),c===l)return!0;let u=z(c,l);return u===""?!0:!(u===".."||u.startsWith(".."+H)||ee(u))};if(!i(o,r))return!1;try{let s=I(o),a=I(r);if(!i(s,a))return!1}catch{}return!0}function ee(t){if(t.startsWith("/"))return!0;if(t.length>=3&&t[1]===":"&&(t[2]==="\\"||t[2]==="/")){let n=t.charCodeAt(0);return n>=65&&n<=90||n>=97&&n<=122}return!1}function xe(t,n,e=[],o=process.platform==="win32"||process.platform==="darwin"){return Q(t,n,o)?{allowed:!0,reason:"inside"}:e.some(r=>r.length>0)&&Y(t,e,o,n).denied?{allowed:!0,reason:"allow-rule"}:{allowed:!1,reason:"outside"}}var te={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 ne(t){let n=[],e=/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*\[([^\]]+)\]/g,o;for(;(o=e.exec(t))!==null;){let i=[...o[1].matchAll(/(['"])(.*?)\1/g)].map(s=>s[2]);i.length>0&&n.push(i.join(" "))}return n}function Ee(t,n){let e=te[n];if(!e&&n!=="python")return[];let o=[];if(e)for(let r of e){r.lastIndex=0;let i;for(;(i=r.exec(t))!==null;){let s=i[i.length-1];s&&o.push(s)}}return n==="python"&&o.push(...ne(t)),o}export{Ce as evaluateCommand,Pe as evaluateCommandDenyOnly,Y as evaluateFilePath,xe as evaluateProjectContainment,Ee as extractShellCommands,j as extractSubshellCommands,K as fileGlobToRegex,U as globToRegex,Q as isPathInsideProject,w as matchesAnyPattern,L as parseBashPattern,W as parseToolPattern,ye as readBashPolicies,we as readToolDenyPatterns,Z as readToolPermissionPatterns,X as splitChainedCommands};
1
+ var E=(t,n)=>()=>(t&&(n=t(t=0)),n);var b,S=E(()=>{"use strict";b={"claude-code":"claude-code","gemini-cli-mcp-client":"gemini-cli","antigravity-client":"antigravity","antigravity-cli":"antigravity-cli",agy:"antigravity-cli","cursor-vscode":"cursor","Visual-Studio-Code":"vscode-copilot","copilot-cli":"copilot-cli","GitHub Copilot CLI":"copilot-cli","github-copilot-cli":"copilot-cli","JetBrains Client":"jetbrains-copilot","IntelliJ IDEA":"jetbrains-copilot",PyCharm:"jetbrains-copilot",Codex:"codex","codex-mcp-client":"codex","Kilo Code":"kilo","Kiro CLI":"kiro","Pi CLI":"pi","Pi Coding Agent":"pi","omp-coding-agent":"omp",Zed:"zed",zed:"zed","qwen-code":"qwen-code","qwen-cli-mcp-client":"qwen-code","kimi-code":"kimi",kimi:"kimi","Kimi Code":"kimi"}});import{existsSync as u,readFileSync as V}from"node:fs";import{resolve as f}from"node:path";import{homedir as R}from"node:os";function z(){if(w!==null)return w!=="miss"&&w.hasCM;try{let t=f(R(),".claude","plugins","installed_plugins.json"),n=V(t,"utf-8"),e=JSON.parse(n),r=[...Object.keys(e.plugins??{}),...Object.keys(e.enabledPlugins??{})].some(i=>i.includes("context-mode"));return w={hasCM:r},r}catch{return w="miss",!1}}function D(t){switch(t){case"claude-code":return[".claude"];case"gemini-cli":return[".gemini"];case"antigravity":return[".gemini"];case"antigravity-cli":return[".gemini"];case"openclaw":return[".openclaw"];case"codex":return[".codex"];case"cursor":return[".cursor"];case"vscode-copilot":return[".vscode"];case"copilot-cli":return[".copilot"];case"kiro":return[".kiro"];case"pi":return[".pi"];case"omp":return[".omp"];case"qwen-code":return[".qwen"];case"kimi":return[".kimi-code"];case"kilo":return[".config","kilo"];case"opencode":return[".config","opencode"];case"zed":return[".config","zed"];case"jetbrains-copilot":return[".config","JetBrains"];default:return null}}function T(t){if(t?.name){let i=b[t.name];if(i)return{platform:i,confidence:"high",reason:`MCP clientInfo.name="${t.name}"`};if(t.name.startsWith("qwen-cli-mcp-client"))return{platform:"qwen-code",confidence:"high",reason:`MCP clientInfo.name="${t.name}" (qwen-cli pattern)`}}let n=process.env.CONTEXT_MODE_PLATFORM;if(n&&["claude-code","gemini-cli","kilo","opencode","codex","vscode-copilot","jetbrains-copilot","copilot-cli","cursor","antigravity","antigravity-cli","kiro","pi","omp","zed","qwen-code","kimi"].includes(n))return{platform:n,confidence:"high",reason:`CONTEXT_MODE_PLATFORM=${n} override`};for(let[i,a]of B)if(a.some(c=>c.detect!==!1&&process.env[c.name]))return i==="vscode-copilot"&&z()?{platform:"claude-code",confidence:"high",reason:"VSCODE_PID set but ~/.claude/plugins/installed_plugins.json lists context-mode (issue #539 fallback)"}:{platform:i,confidence:"high",reason:`${a.filter(c=>c.detect!==!1).map(c=>c.name).join(" or ")} env var set`};let e=R(),o=(()=>{let i=process.env.COPILOT_HOME;return i&&i.trim()!==""?i.startsWith("~")?f(e,i.replace(/^~[/\\]?/,"")):f(i):f(e,".copilot")})(),r=u(f(o,"mcp-config.json"))||u(f(o,"hooks","context-mode.json"));return process.env.COPILOT_HOME?.trim()&&r?{platform:"copilot-cli",confidence:"medium",reason:"context-mode config in explicit COPILOT_HOME exists (mcp-config.json or hooks/context-mode.json)"}:u(f(e,".local","bin","agy"))||u(f(e,".gemini","antigravity-cli"))||u(f(e,".gemini","config","mcp_config.json"))?{platform:"antigravity-cli",confidence:"medium",reason:"Antigravity CLI marker exists (~/.local/bin/agy, ~/.gemini/antigravity-cli, or ~/.gemini/config/mcp_config.json)"}:r?{platform:"copilot-cli",confidence:"medium",reason:"context-mode config in Copilot CLI home exists (mcp-config.json or hooks/context-mode.json; honors COPILOT_HOME)"}:u(f(e,".claude"))?{platform:"claude-code",confidence:"medium",reason:"~/.claude/ directory exists"}:u(f(e,".gemini"))?{platform:"gemini-cli",confidence:"medium",reason:"~/.gemini/ directory exists"}:u(f(e,".codex"))?{platform:"codex",confidence:"medium",reason:"~/.codex/ directory exists"}:u(f(e,".kiro"))?{platform:"kiro",confidence:"medium",reason:"~/.kiro/ directory exists"}:u(f(e,".omp"))?{platform:"omp",confidence:"medium",reason:"~/.omp/ directory exists"}:u(f(e,".pi"))?{platform:"pi",confidence:"medium",reason:"~/.pi/ directory exists"}:u(f(e,".qwen"))?{platform:"qwen-code",confidence:"medium",reason:"~/.qwen/ directory exists"}:u(f(e,".kimi-code"))?{platform:"kimi",confidence:"medium",reason:"~/.kimi-code/ directory exists"}:u(f(e,".openclaw"))?{platform:"openclaw",confidence:"medium",reason:"~/.openclaw/ directory exists"}:u(f(e,".cursor"))?{platform:"cursor",confidence:"medium",reason:"~/.cursor/ directory exists"}:u(f(e,".config","kilo"))?{platform:"kilo",confidence:"medium",reason:"~/.config/kilo/ directory exists"}:u(f(e,".config","JetBrains"))?{platform:"jetbrains-copilot",confidence:"medium",reason:"~/.config/JetBrains/ directory exists"}:u(f(e,".config","opencode"))?{platform:"opencode",confidence:"medium",reason:"~/.config/opencode/ directory exists"}:u(f(e,".config","zed"))?{platform:"zed",confidence:"medium",reason:"~/.config/zed/ directory exists"}:{platform:"claude-code",confidence:"low",reason:"No platform detected, defaulting to Claude Code"}}var w,H,B,N=E(()=>{"use strict";S();w=null;H=[["claude-code",[{name:"CLAUDE_CODE_ENTRYPOINT",role:"identification"},{name:"CLAUDE_PLUGIN_ROOT",role:"identification"},{name:"CLAUDE_PROJECT_DIR",role:"workspace"},{name:"CLAUDE_SESSION_ID",role:"identification"}]],["antigravity",[{name:"ANTIGRAVITY_CLI_ALIAS",role:"identification"}]],["cursor",[{name:"CURSOR_CWD",role:"workspace"},{name:"CURSOR_TRACE_ID",role:"identification"},{name:"CURSOR_CLI",role:"identification"}]],["kilo",[{name:"KILO",role:"identification"},{name:"KILO_PID",role:"identification"}]],["opencode",[{name:"OPENCODE_PROJECT_DIR",role:"workspace"},{name:"OPENCODE_CLIENT",role:"identification"},{name:"OPENCODE_TERMINAL",role:"identification"},{name:"OPENCODE",role:"identification"},{name:"OPENCODE_PID",role:"identification"}]],["zed",[{name:"ZED_SESSION_ID",role:"identification"},{name:"ZED_TERM",role:"identification"}]],["codex",[{name:"CODEX_THREAD_ID",role:"identification"},{name:"CODEX_CI",role:"identification"}]],["gemini-cli",[{name:"GEMINI_PROJECT_DIR",role:"workspace"},{name:"GEMINI_CLI",role:"identification"}]],["vscode-copilot",[{name:"VSCODE_CWD",role:"workspace"},{name:"VSCODE_PID",role:"identification"}]],["jetbrains-copilot",[{name:"IDEA_INITIAL_DIRECTORY",role:"workspace"}]],["qwen-code",[{name:"QWEN_PROJECT_DIR",role:"workspace"}]],["omp",[{name:"PI_CODING_AGENT_DIR",role:"workspace"}]],["pi",[{name:"PI_WORKSPACE_DIR",role:"workspace",detect:!1},{name:"PI_PROJECT_DIR",role:"workspace",detect:!1},{name:"PI_CONFIG_DIR",role:"identification"},{name:"PI_SESSION_FILE",role:"identification"},{name:"PI_COMPILED",role:"identification"},{name:"PI_CODING_AGENT",role:"identification"}]]],B=new Map(H)});import{resolve as C}from"node:path";import{homedir as _}from"node:os";function U(t=process.env){let n=t.CLAUDE_CONFIG_DIR;return n&&n.trim()!==""?n.startsWith("~")?C(_(),n.replace(/^~[/\\]?/,"")):C(n):C(_(),".claude")}function K(t=process.env){return C(U(t),"settings.json")}function I(t=process.env){let n=[],e=T();if(e.platform!=="claude-code"){let r=D(e.platform);r&&r.length>0&&n.push(C(_(),...r,"settings.json"))}let o=K(t);return n.includes(o)||n.push(o),n}var L=E(()=>{"use strict";N()});L();import{readFileSync as F,realpathSync as x}from"node:fs";import{homedir as M}from"node:os";import{dirname as X,isAbsolute as Z,relative as Y,resolve as h,sep as A}from"node:path";function $(t){let n=t.match(/^Bash\((.+)\)$/);return n?n[1]:null}function Q(t){let n=t.match(/^(\w+)\((.+)\)$/);return n?{tool:n[1],glob:n[2]}:null}function ee(t){return t.replace(/[.*+?^${}()|[\]\\\/\-]/g,"\\$&")}function j(t){return t.replace(/[.+?^${}()|[\]\\\/\-]/g,"\\$&").replace(/\*/g,".*")}function te(t,n=!1){let e,o=t.indexOf(":");if(o!==-1){let r=t.slice(0,o),i=t.slice(o+1),a=ee(r),c=j(i);e=`^${a}(\\s${c})?$`}else e=`^${j(t)}$`;return new RegExp(e,n?"i":"")}function ne(t,n=!1){let e="",o=0;for(;o<t.length;)t[o]==="*"&&t[o+1]==="*"?o+2<t.length&&t[o+2]==="/"?(e+="(.*/)?",o+=3):(e+=".*",o+=2):t[o]==="*"?(e+="[^/]*",o++):t[o]==="?"?(e+="[^/]",o++):(e+=t[o].replace(/[.+^${}()|[\]\\\/\-]/g,"\\$&"),o++);return new RegExp(`^${e}$`,n?"i":"")}function P(t,n,e=!1){for(let o of n){let r=$(o);if(r&&te(r,e).test(t))return o}return null}function J(t,n){let e=0;for(let o=n-1;o>=0&&t[o]==="\\";o--)e++;return e%2===1}function oe(t){let n=[],e="",o=!1,r=!1,i=!1,a=0;for(let c=0;c<t.length;c++){let s=t[c],l=J(t,c);s==="'"&&!r&&!i&&!l?(o=!o,e+=s):s==='"'&&!o&&!i&&!l?(r=!r,e+=s):s==="`"&&!o&&!r&&!l?(i=!i,e+=s):!o&&!r&&!i?s==="$"&&t[c+1]==="("&&!l?(a++,e+=s+t[c+1],c++):a>0&&s==="("&&!l?(a++,e+=s):s===")"&&a>0&&!l?(a--,e+=s):a===0&&(s===";"||s===`
2
+ `||s==="\r")&&!l?(n.push(e.trim()),e=""):a===0&&s==="|"&&t[c+1]==="|"||a===0&&s==="&"&&t[c+1]==="&"?(n.push(e.trim()),e="",c++):a===0&&s==="&"&&!l||a===0&&s==="|"?(n.push(e.trim()),e=""):e+=s:e+=s}return e.trim()&&n.push(e.trim()),n.filter(c=>c.length>0)}function W(t){let n=[],e=!1,o=!1,r=-1,i=[],a=[],c=0;for(let s=0;s<t.length;s++){let l=t[s],d=J(t,s);if(l==="'"&&!o&&r===-1&&!d)e=!e;else if(l==='"'&&!e&&r===-1&&!d)o=!o;else if(l==="`"&&!e&&!o&&!d)if(r===-1)r=s+1;else{let p=t.slice(r,s);n.push(p),n.push(...W(p)),r=-1}else if(!e&&r===-1){if(l==="$"&&t[s+1]==="("&&!d)t[s+2]==="("?(c+=2,s+=2):(i.push(s+2),a.push(c),c++,s++);else if(l==="("&&!d)c++;else if(l===")"&&!d&&(c>0&&c--,a.length>0&&c===a[a.length-1])){a.pop();let p=i.pop(),g=t.slice(p,s);n.push(g)}}}return n}function v(t){let n=[],e=oe(t);for(let o of e){n.push(o);for(let r of W(o))n.push(...v(r))}return n}function k(t){let n;try{n=F(t,"utf-8")}catch{return null}let e;try{e=JSON.parse(n)}catch{return null}let o=e?.permissions;if(!o||typeof o!="object")return null;let r=i=>Array.isArray(i)?i.filter(a=>typeof a=="string"&&$(a)!==null):[];return{allow:r(o.allow),deny:r(o.deny),ask:r(o.ask)}}function Ae(t,n){let e=[];if(t){let r=h(t,".claude","settings.local.json"),i=k(r);i&&e.push(i);let a=h(t,".claude","settings.json"),c=k(a);c&&e.push(c)}let o=n!==void 0?[n]:I();for(let r of o){let i=k(r);i&&e.push(i)}return e}function Oe(t,n,e){return re(t,"deny",n,e)}function re(t,n,e,o){let r=[],i=(c,s)=>{let l;try{l=F(c,"utf-8")}catch{return null}let d;try{d=JSON.parse(l)}catch{return null}let p=d?.permissions?.[n];if(!Array.isArray(p))return[];let g=[];for(let y of p){if(typeof y!="string")continue;let m=Q(y);m&&m.tool===t&&(g.push(m.glob),s&&m.glob.startsWith("/")&&!m.glob.startsWith("//")&&g.push(h(s,"."+m.glob)))}return g};if(e){let c=i(h(e,".claude","settings.local.json"),e);c!==null&&r.push(c);let s=i(h(e,".claude","settings.json"),e);s!==null&&r.push(s)}let a=o!==void 0?[o]:I();for(let c of a){let s=i(c,X(c));s!==null&&r.push(s)}return r}function ve(t,n,e=process.platform==="win32"||process.platform==="darwin"){let o=v(t);for(let r of o)for(let i of n){let a=P(r,i.deny,e);if(a)return{decision:"deny",matchedPattern:a}}for(let r of n){let i=!0,a=!1,c,s;for(let l of o){let d=P(l,r.ask,e);if(d){a=!0,c=d;break}let p=P(l,r.allow,e);p?s=p:i=!1}if(a)return{decision:"ask",matchedPattern:c};if(i&&o.length>0)return{decision:"allow",matchedPattern:s}}return{decision:"ask"}}function be(t,n,e=process.platform==="win32"||process.platform==="darwin"){let o=v(t);for(let r of o)for(let i of n){let a=P(r,i.deny,e);if(a)return{decision:"deny",matchedPattern:a}}return{decision:"allow"}}function O(t){return t==="~"?M():t.startsWith("~/")||t.startsWith("~\\")?M()+t.slice(1):t}function G(t){return t.startsWith("//")?t.slice(1):t}function ie(t){let n=t.split(/[\\/]/),e=n.findIndex(r=>r.includes("*")||r.includes("?"));if(e===-1&&(e=n.length),e===0)return null;let o=n.slice(0,e).join(A);if(o.length===0)return null;try{return[x(o),...n.slice(e)].join(A)}catch{return null}}function se(t,n,e=process.platform==="win32"||process.platform==="darwin",o){let r=s=>s.replace(/\\/g,"/"),i=new Set;i.add(r(t));let a=O(t);a!==t&&i.add(r(a));let c=h(o??process.cwd(),a);i.add(r(c));try{i.add(r(x(c)))}catch{}for(let s of n)for(let l of s){let d=new Set;d.add(l),d.add(G(l));let p=O(l);p!==l&&(d.add(p),d.add(G(p))),!Z(l)&&!l.startsWith("~")&&d.add(h(o??process.cwd(),l));let g=new Set;for(let y of d){g.add(y);let m=ie(y);m!==null&&g.add(m)}for(let y of g){let m=ne(r(y),e);for(let q of i)if(m.test(q))return{denied:!0,matchedPattern:l}}}return{denied:!1}}function ce(t,n,e=process.platform==="win32"||process.platform==="darwin"){if(!n)return!0;let o=h(n),r=h(n,O(t)),i=(a,c)=>{let s=a,l=c;if(e&&(s=s.toLowerCase(),l=l.toLowerCase()),s===l)return!0;let d=Y(s,l);return d===""?!0:!(d===".."||d.startsWith(".."+A)||ae(d))};if(!i(o,r))return!1;try{let a=x(o),c=x(r);if(!i(a,c))return!1}catch{}return!0}function ae(t){if(t.startsWith("/"))return!0;if(t.length>=3&&t[1]===":"&&(t[2]==="\\"||t[2]==="/")){let n=t.charCodeAt(0);return n>=65&&n<=90||n>=97&&n<=122}return!1}function Se(t,n,e=[],o=process.platform==="win32"||process.platform==="darwin"){return ce(t,n,o)?{allowed:!0,reason:"inside"}:e.some(r=>r.length>0)&&se(t,e,o,n).denied?{allowed:!0,reason:"allow-rule"}:{allowed:!1,reason:"outside"}}var le={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 de(t){let n=[],e=/subprocess\.(?:run|call|Popen|check_output|check_call)\(\s*\[([^\]]+)\]/g,o;for(;(o=e.exec(t))!==null;){let i=[...o[1].matchAll(/(['"])(.*?)\1/g)].map(a=>a[2]);i.length>0&&n.push(i.join(" "))}return n}function Re(t,n){let e=le[n];if(!e&&n!=="python")return[];let o=[];if(e)for(let r of e){r.lastIndex=0;let i;for(;(i=r.exec(t))!==null;){let a=i[i.length-1];a&&o.push(a)}}return n==="python"&&o.push(...de(t)),o}export{ve as evaluateCommand,be as evaluateCommandDenyOnly,se as evaluateFilePath,Se as evaluateProjectContainment,Re as extractShellCommands,W as extractSubshellCommands,ne as fileGlobToRegex,te as globToRegex,ce as isPathInsideProject,P as matchesAnyPattern,$ as parseBashPattern,Q as parseToolPattern,Ae as readBashPolicies,Oe as readToolDenyPatterns,re as readToolPermissionPatterns,oe as splitChainedCommands};
@@ -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": "2.0.2",
6
+ "version": "2.0.4",
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": "@mxalbert/context-mode",
3
- "version": "2.0.2",
3
+ "version": "2.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",