context-mode 2.0.0-next.11 → 2.0.0-next.12

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.
@@ -12,5 +12,5 @@
12
12
  }
13
13
  },
14
14
  "name": "context-mode",
15
- "version": "2.0.0-next.11"
15
+ "version": "2.0.0-next.12"
16
16
  }
package/run.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import{createRequire as __cmRequire}from"node:module";if(typeof process.getBuiltinModule!=="function")process.getBuiltinModule=(id)=>__cmRequire(import.meta.url)(id);
2
+
1
3
  // src/entries/run.ts
2
4
  import { basename as basename2 } from "node:path";
3
5
 
@@ -206,6 +208,24 @@ var DENY_WEBFETCH_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
206
208
  var USER_DENY_REASON_PREFIX = "Blocked by security policy: matches deny pattern ";
207
209
  var POLICY_UNREADABLE_LINE = "context-mode: your deny rules could not be read. Fix: run ctx_doctor.";
208
210
  var PARSE_ERROR_DENY_LINE = "context-mode: could not parse this command; it may be blocked by your own rules. Run it through ctx_execute instead.";
211
+ var HOOK_FAIL_TOOL_KEYS = Object.freeze(["tool_name", "toolName", "tool"]);
212
+ var HOOK_FAIL_EVENT_KEYS = Object.freeze(["hook_event_name", "hookEventName", "type"]);
213
+ var HOOK_FAIL_INPUT_KEYS = Object.freeze(["tool_input", "toolArgs", "input", "args"]);
214
+ var HOOK_FAIL_CWD_KEYS = Object.freeze(["cwd", "directory"]);
215
+ var HOOK_FAIL_PRE_EVENTS = Object.freeze(["pretooluse", "beforetool", "tool_call", "execute.before", "tool.execute.before"]);
216
+ var HOOK_FAULT_STAGES = Object.freeze(["decode", "project", "policy", "store", "encode"]);
217
+ var HOOK_FAIL_TOOLS = Object.freeze({
218
+ shell: Object.freeze(["Bash", "bash", "shell"]),
219
+ read: Object.freeze(["Read", "read_file"]),
220
+ grep: Object.freeze(["Grep", "grep_search"]),
221
+ fetch: Object.freeze(["WebFetch", "web_fetch", "fetch"])
222
+ });
223
+ var HOOK_FAIL_REDIRECT = Object.freeze({
224
+ read: "Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",
225
+ shell: "Run the command with ctx_execute(language, code) or ctx_batch instead; only the part that matches your intent comes back.",
226
+ grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
227
+ fetch: "Index the URL with ctx_index and query it with ctx_search."
228
+ });
209
229
  var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
210
230
  var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
211
231
  var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
@@ -4241,6 +4261,7 @@ function pipeline(p) {
4241
4261
  all.push(...last.cmds);
4242
4262
  const t = at(p);
4243
4263
  if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
4264
+ for (const c of last.cmds) c.pipesOut = true;
4244
4265
  p.i++;
4245
4266
  continue;
4246
4267
  }
@@ -4330,7 +4351,7 @@ var WRAPPERS = Object.freeze({
4330
4351
  command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
4331
4352
  xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
4332
4353
  });
4333
- var SHELLS = ["bash", "sh"];
4354
+ var SHELLS = ["bash", "sh", "zsh"];
4334
4355
  var SCRIPT_FLAG = "c";
4335
4356
  var SHELL_LABEL_SUFFIX = " -c";
4336
4357
  var SHELL_VALUE_OPTS = ["-o", "+o", "-O", "+O"];
@@ -4731,6 +4752,7 @@ function inlineHttp(raw) {
4731
4752
  }
4732
4753
  return false;
4733
4754
  }
4755
+ var CD_COMMAND = "cd";
4734
4756
  function fileSize(abs) {
4735
4757
  try {
4736
4758
  const st = statSync(abs);
@@ -4752,17 +4774,24 @@ function read(ev, row, input) {
4752
4774
  }
4753
4775
  function shellDump(cmds, cwd, row) {
4754
4776
  if (row.nativeTools.read !== void 0 && row.nativeTools.read.length > 0 && dumpRunsThenReplaces(row)) return null;
4755
- if (cmds.length !== 1) return null;
4756
- const c = cmds[0];
4757
- if (c.redirectsToFile || c.endsInBoundedSink) return null;
4758
- const name = c.argv0.toLowerCase();
4759
- if (!has(SHELL_DUMP_COMMANDS, name)) return null;
4760
- const d = dumpTarget(name, c.args);
4761
- if (d === null) return null;
4762
- if (d.bounded) return ALLOW;
4763
- const abs = resolve(cwd, d.file);
4764
- const size = fileSize(abs);
4765
- return size > OUTPUT_CAP ? deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix)) : null;
4777
+ let dir = cwd;
4778
+ let verdict = null;
4779
+ for (const c of cmds) {
4780
+ const name = c.argv0.toLowerCase();
4781
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve(dir, c.args[0]);
4782
+ if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
4783
+ if (!has(SHELL_DUMP_COMMANDS, name)) continue;
4784
+ const d = dumpTarget(name, c.args);
4785
+ if (d === null) continue;
4786
+ if (d.bounded) {
4787
+ verdict = ALLOW;
4788
+ continue;
4789
+ }
4790
+ const abs = resolve(dir, d.file);
4791
+ const size = fileSize(abs);
4792
+ if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
4793
+ }
4794
+ return verdict;
4766
4795
  }
4767
4796
  var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
4768
4797
  function countFlag(a) {
package/search.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import{createRequire as __cmRequire}from"node:module";if(typeof process.getBuiltinModule!=="function")process.getBuiltinModule=(id)=>__cmRequire(import.meta.url)(id);
2
+
1
3
  // src/entries/run.ts
2
4
  import { basename as basename2 } from "node:path";
3
5
 
@@ -206,6 +208,24 @@ var DENY_WEBFETCH_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
206
208
  var USER_DENY_REASON_PREFIX = "Blocked by security policy: matches deny pattern ";
207
209
  var POLICY_UNREADABLE_LINE = "context-mode: your deny rules could not be read. Fix: run ctx_doctor.";
208
210
  var PARSE_ERROR_DENY_LINE = "context-mode: could not parse this command; it may be blocked by your own rules. Run it through ctx_execute instead.";
211
+ var HOOK_FAIL_TOOL_KEYS = Object.freeze(["tool_name", "toolName", "tool"]);
212
+ var HOOK_FAIL_EVENT_KEYS = Object.freeze(["hook_event_name", "hookEventName", "type"]);
213
+ var HOOK_FAIL_INPUT_KEYS = Object.freeze(["tool_input", "toolArgs", "input", "args"]);
214
+ var HOOK_FAIL_CWD_KEYS = Object.freeze(["cwd", "directory"]);
215
+ var HOOK_FAIL_PRE_EVENTS = Object.freeze(["pretooluse", "beforetool", "tool_call", "execute.before", "tool.execute.before"]);
216
+ var HOOK_FAULT_STAGES = Object.freeze(["decode", "project", "policy", "store", "encode"]);
217
+ var HOOK_FAIL_TOOLS = Object.freeze({
218
+ shell: Object.freeze(["Bash", "bash", "shell"]),
219
+ read: Object.freeze(["Read", "read_file"]),
220
+ grep: Object.freeze(["Grep", "grep_search"]),
221
+ fetch: Object.freeze(["WebFetch", "web_fetch", "fetch"])
222
+ });
223
+ var HOOK_FAIL_REDIRECT = Object.freeze({
224
+ read: "Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",
225
+ shell: "Run the command with ctx_execute(language, code) or ctx_batch instead; only the part that matches your intent comes back.",
226
+ grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
227
+ fetch: "Index the URL with ctx_index and query it with ctx_search."
228
+ });
209
229
  var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
210
230
  var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
211
231
  var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
@@ -4241,6 +4261,7 @@ function pipeline(p) {
4241
4261
  all.push(...last.cmds);
4242
4262
  const t = at(p);
4243
4263
  if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
4264
+ for (const c of last.cmds) c.pipesOut = true;
4244
4265
  p.i++;
4245
4266
  continue;
4246
4267
  }
@@ -4330,7 +4351,7 @@ var WRAPPERS = Object.freeze({
4330
4351
  command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
4331
4352
  xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
4332
4353
  });
4333
- var SHELLS = ["bash", "sh"];
4354
+ var SHELLS = ["bash", "sh", "zsh"];
4334
4355
  var SCRIPT_FLAG = "c";
4335
4356
  var SHELL_LABEL_SUFFIX = " -c";
4336
4357
  var SHELL_VALUE_OPTS = ["-o", "+o", "-O", "+O"];
@@ -4731,6 +4752,7 @@ function inlineHttp(raw) {
4731
4752
  }
4732
4753
  return false;
4733
4754
  }
4755
+ var CD_COMMAND = "cd";
4734
4756
  function fileSize(abs) {
4735
4757
  try {
4736
4758
  const st = statSync(abs);
@@ -4752,17 +4774,24 @@ function read(ev, row, input) {
4752
4774
  }
4753
4775
  function shellDump(cmds, cwd, row) {
4754
4776
  if (row.nativeTools.read !== void 0 && row.nativeTools.read.length > 0 && dumpRunsThenReplaces(row)) return null;
4755
- if (cmds.length !== 1) return null;
4756
- const c = cmds[0];
4757
- if (c.redirectsToFile || c.endsInBoundedSink) return null;
4758
- const name = c.argv0.toLowerCase();
4759
- if (!has(SHELL_DUMP_COMMANDS, name)) return null;
4760
- const d = dumpTarget(name, c.args);
4761
- if (d === null) return null;
4762
- if (d.bounded) return ALLOW;
4763
- const abs = resolve(cwd, d.file);
4764
- const size = fileSize(abs);
4765
- return size > OUTPUT_CAP ? deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix)) : null;
4777
+ let dir = cwd;
4778
+ let verdict = null;
4779
+ for (const c of cmds) {
4780
+ const name = c.argv0.toLowerCase();
4781
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve(dir, c.args[0]);
4782
+ if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
4783
+ if (!has(SHELL_DUMP_COMMANDS, name)) continue;
4784
+ const d = dumpTarget(name, c.args);
4785
+ if (d === null) continue;
4786
+ if (d.bounded) {
4787
+ verdict = ALLOW;
4788
+ continue;
4789
+ }
4790
+ const abs = resolve(dir, d.file);
4791
+ const size = fileSize(abs);
4792
+ if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
4793
+ }
4794
+ return verdict;
4766
4795
  }
4767
4796
  var allDigits2 = (s) => s !== "" && [...s].every((ch) => ch >= "0" && ch <= "9");
4768
4797
  function countFlag(a) {