context-mode 2.1.7 → 2.1.8

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.1.7"
15
+ "version": "2.1.8"
16
16
  }
package/run.mjs CHANGED
@@ -509,6 +509,14 @@ var V1_SCRIPT_NAMES = Object.freeze([
509
509
  "userpromptsubmit.mjs"
510
510
  ]);
511
511
  var V1_CODEX_HOOKS_DIR = Object.freeze(["hooks", "codex"]);
512
+ var V1_CODEX_SCRIPT_NAMES = Object.freeze([
513
+ "pretooluse.mjs",
514
+ "posttooluse.mjs",
515
+ "sessionstart.mjs",
516
+ "precompact.mjs",
517
+ "userpromptsubmit.mjs",
518
+ "stop.mjs"
519
+ ]);
512
520
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
513
521
  var V1_PI_PACKAGE = "npm:context-mode";
514
522
  var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
@@ -541,7 +549,7 @@ var V1_REASON = Object.freeze({
541
549
  cacheHealFile: "old context-mode cache-heal script file",
542
550
  statusLine: "old context-mode statusLine (context-mode statusline): report only, never removed",
543
551
  mcpEntry: "old context-mode MCP entry mcpServers.context-mode",
544
- codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/*.mjs",
552
+ codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/<event>.mjs",
545
553
  codexToml: "old context-mode config.toml [mcp_servers.context-mode*] section",
546
554
  hookFile: "old context-mode hook file context-mode.json (runs context-mode hook)",
547
555
  vscodeMcp: "old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",
@@ -1371,6 +1379,7 @@ function readResult6(p) {
1371
1379
  const text = p.content === void 0 ? "" : typeof p.content === "string" ? p.content : JSON.stringify(p.content);
1372
1380
  const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
1373
1381
  if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
1382
+ if (p.keep === true) info.keep = true;
1374
1383
  return info;
1375
1384
  }
1376
1385
  function decode9(raw) {
@@ -1447,6 +1456,11 @@ function decode10(raw) {
1447
1456
  const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
1448
1457
  if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
1449
1458
  const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
1459
+ if (typeof p.agentID === "string" && p.agentID !== "") {
1460
+ ev.agentId = p.agentID;
1461
+ ev.agentType = p.agentID;
1462
+ }
1463
+ if (Array.isArray(p.agentTools)) ev.agentTools = p.agentTools.filter((t) => typeof t === "string");
1450
1464
  if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
1451
1465
  if (event === "PreToolUse" || event === "PostToolUse") {
1452
1466
  const name = String(p.tool ?? "");
@@ -1467,7 +1481,7 @@ function encode10(ev, d, _extra) {
1467
1481
  if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
1468
1482
  return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
1469
1483
  case "replace":
1470
- return { stdout: "", exitCode: 0 };
1484
+ return { stdout: ev.event === "PostToolUse" ? d.output : "", exitCode: 0 };
1471
1485
  }
1472
1486
  }
1473
1487
 
@@ -1672,7 +1686,7 @@ var ADAPTERS = Object.freeze([
1672
1686
  }
1673
1687
  ]);
1674
1688
  var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
1675
- var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi"]);
1689
+ var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
1676
1690
  function hasReplace(row) {
1677
1691
  return REPLACE_ROWS.has(row.id);
1678
1692
  }
@@ -3778,7 +3792,7 @@ function moreLine(intent, label) {
3778
3792
  }
3779
3793
 
3780
3794
  // src/core/policy/decide.ts
3781
- import { resolve as resolve3 } from "node:path";
3795
+ import { resolve as resolve5 } from "node:path";
3782
3796
 
3783
3797
  // src/core/policy/lexer.ts
3784
3798
  var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
@@ -5442,10 +5456,10 @@ function READ_DENY_RANGE_MESSAGE(path3, size) {
5442
5456
  }
5443
5457
 
5444
5458
  // src/core/policy/own-file.ts
5445
- import { extname, join as join5 } from "node:path";
5459
+ import { extname, join as join5, resolve as resolve4 } from "node:path";
5446
5460
 
5447
5461
  // src/core/project/contain.ts
5448
- import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
5462
+ import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
5449
5463
  var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
5450
5464
  function real(p) {
5451
5465
  try {
@@ -5477,6 +5491,29 @@ function isInsideAny(roots, p) {
5477
5491
  return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
5478
5492
  });
5479
5493
  }
5494
+ function hasParentStep(cwd, p) {
5495
+ const parts = isAbsolute2(p) ? components(p) : [...components(cwd), ...components(p)];
5496
+ return parts.includes("..");
5497
+ }
5498
+ var rootParts = /* @__PURE__ */ new Map();
5499
+ function lexicalRoot(root) {
5500
+ let rc = rootParts.get(root);
5501
+ if (rc === void 0) {
5502
+ rc = components(resolve3(root));
5503
+ rootParts.set(root, rc);
5504
+ }
5505
+ return rc;
5506
+ }
5507
+ function isLexicallyInsideAny(roots, p) {
5508
+ if (roots.length === 0) return false;
5509
+ const raw = components(p);
5510
+ if (raw.includes("..")) return false;
5511
+ const qc = sep2 === "/" && isAbsolute2(p) ? raw.filter((c) => c !== ".") : components(resolve3(p));
5512
+ return roots.some((root) => {
5513
+ const rc = lexicalRoot(root);
5514
+ return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
5515
+ });
5516
+ }
5480
5517
  function commonRoot(paths) {
5481
5518
  const reals = paths.map(real).filter((r) => r !== void 0);
5482
5519
  if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
@@ -5502,9 +5539,11 @@ function ownDirsOf(agent, env) {
5502
5539
  const own2 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
5503
5540
  return [...own2, shared];
5504
5541
  }
5505
- function isOwnFile(agent, abs, env = process.env) {
5506
- if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
5507
- return isInsideAny(ownDirsOf(agent, env), abs);
5542
+ function isOwnFile(agent, cwd, p, env = process.env) {
5543
+ if (extname(p).toLowerCase() !== AGENT_FILE_EXT) return false;
5544
+ const dirs = ownDirsOf(agent, env);
5545
+ const abs = resolve4(cwd, p);
5546
+ return !hasParentStep(cwd, p) && isLexicallyInsideAny(dirs, abs) || isInsideAny(dirs, abs);
5508
5547
  }
5509
5548
 
5510
5549
  // src/core/policy/read-media.ts
@@ -5595,7 +5634,7 @@ function readPaths(input) {
5595
5634
  }
5596
5635
  function userDenyHit(canonical, input, cwd, rules) {
5597
5636
  if (rules.length === 0) return null;
5598
- const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
5637
+ const readRule = (p) => matchesAnyDenyPattern(resolve5(cwd, p), rules, { tool: READ, projectDir: cwd });
5599
5638
  if (canonical === BASH) {
5600
5639
  const cmd = str(input.command);
5601
5640
  return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
@@ -5732,8 +5771,9 @@ function fileSize(abs) {
5732
5771
  return -1;
5733
5772
  }
5734
5773
  }
5735
- function bigDeny(ev, row, abs, size, root) {
5736
- if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
5774
+ function bigDeny(ev, row, cwd, p, size, root) {
5775
+ const abs = resolve5(cwd, p);
5776
+ if (size <= OUTPUT_CAP || isOwnFile(ev.agent, cwd, p)) return null;
5737
5777
  return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
5738
5778
  }
5739
5779
  function executeCanOpen(root, abs) {
@@ -5748,10 +5788,10 @@ function executeCanOpen(root, abs) {
5748
5788
  function read(ev, row, input, root) {
5749
5789
  if (!present(input.offset) && !present(input.limit)) {
5750
5790
  for (const p of readPaths(input)) {
5751
- const abs = resolve3(ev.cwd, p);
5791
+ const abs = resolve5(ev.cwd, p);
5752
5792
  const size = fileSize(abs);
5753
5793
  if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
5754
- const d = bigDeny(ev, row, abs, size, root);
5794
+ const d = bigDeny(ev, row, ev.cwd, p, size, root);
5755
5795
  if (d !== null) return d;
5756
5796
  }
5757
5797
  }
@@ -5764,7 +5804,7 @@ function shellDump(ev, cmds, row, root) {
5764
5804
  let verdict = null;
5765
5805
  for (const c of cmds) {
5766
5806
  const name = c.argv0.toLowerCase();
5767
- if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
5807
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve5(dir, c.args[0]);
5768
5808
  if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
5769
5809
  if (!has(SHELL_DUMP_COMMANDS, name)) continue;
5770
5810
  const d = dumpTarget(name, c.args);
@@ -5773,8 +5813,8 @@ function shellDump(ev, cmds, row, root) {
5773
5813
  verdict = ALLOW;
5774
5814
  continue;
5775
5815
  }
5776
- const abs = resolve3(dir, d.file);
5777
- const big = bigDeny(ev, row, abs, fileSize(abs), root);
5816
+ const abs = resolve5(dir, d.file);
5817
+ const big = bigDeny(ev, row, dir, d.file, fileSize(abs), root);
5778
5818
  if (big !== null) return big;
5779
5819
  }
5780
5820
  return verdict;
@@ -5782,7 +5822,7 @@ function shellDump(ev, cmds, row, root) {
5782
5822
  function psShellDump(ev, cmd, row, root) {
5783
5823
  if (row.nativeTools.read !== void 0 && row.nativeTools.read.length > 0 && dumpRunsThenReplaces(row)) return null;
5784
5824
  for (const abs of psDumpFiles(cmd, ev.cwd)) {
5785
- const d = bigDeny(ev, row, abs, fileSize(abs), root);
5825
+ const d = bigDeny(ev, row, ev.cwd, abs, fileSize(abs), root);
5786
5826
  if (d !== null) return d;
5787
5827
  }
5788
5828
  return null;
@@ -5844,7 +5884,7 @@ function dumpTarget(name, args) {
5844
5884
  }
5845
5885
 
5846
5886
  // src/core/project/resolve.ts
5847
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
5887
+ import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5848
5888
 
5849
5889
  // src/core/project/sha256.ts
5850
5890
  var K = new Uint32Array([
@@ -6009,7 +6049,7 @@ function gitDirs(dir) {
6009
6049
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
6010
6050
  if (gitDir !== null) {
6011
6051
  const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
6012
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
6052
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve6(gitDir, common)), worktree: cur, start };
6013
6053
  }
6014
6054
  const up = dirname3(cur);
6015
6055
  if (up === cur) return { commonDir: null, start };
@@ -6024,7 +6064,7 @@ function gitDirAt(dotGit) {
6024
6064
  } else {
6025
6065
  const line = firstLine(dotGit);
6026
6066
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
6027
- gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
6067
+ gitDir = resolve6(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
6028
6068
  }
6029
6069
  } catch {
6030
6070
  return null;
@@ -6240,10 +6280,10 @@ function startArgv(argv) {
6240
6280
  return sh === null ? null : [sh, ...argv];
6241
6281
  }
6242
6282
  function runProcess(argv, o) {
6243
- return new Promise((resolve5) => {
6283
+ return new Promise((resolve7) => {
6244
6284
  const isWin2 = process.platform === "win32";
6245
6285
  const start = startArgv(argv);
6246
- if (start === null) return resolve5(NOT_STARTED);
6286
+ if (start === null) return resolve7(NOT_STARTED);
6247
6287
  let child;
6248
6288
  try {
6249
6289
  child = spawn2(start[0], start.slice(1), {
@@ -6257,7 +6297,7 @@ function runProcess(argv, o) {
6257
6297
  windowsHide: true
6258
6298
  });
6259
6299
  } catch {
6260
- return resolve5(NOT_STARTED);
6300
+ return resolve7(NOT_STARTED);
6261
6301
  }
6262
6302
  const stdoutChunks = [];
6263
6303
  const stderrChunks = [];
@@ -6291,7 +6331,7 @@ function runProcess(argv, o) {
6291
6331
  clearTimeout(drainTimer);
6292
6332
  clearTimeout(stopTimer);
6293
6333
  o.signal.removeEventListener("abort", onAbort);
6294
- resolve5({
6334
+ resolve7({
6295
6335
  stdout: Buffer.concat(stdoutChunks),
6296
6336
  stderr: Buffer.concat(stderrChunks),
6297
6337
  exitCode,
package/search.mjs CHANGED
@@ -509,6 +509,14 @@ var V1_SCRIPT_NAMES = Object.freeze([
509
509
  "userpromptsubmit.mjs"
510
510
  ]);
511
511
  var V1_CODEX_HOOKS_DIR = Object.freeze(["hooks", "codex"]);
512
+ var V1_CODEX_SCRIPT_NAMES = Object.freeze([
513
+ "pretooluse.mjs",
514
+ "posttooluse.mjs",
515
+ "sessionstart.mjs",
516
+ "precompact.mjs",
517
+ "userpromptsubmit.mjs",
518
+ "stop.mjs"
519
+ ]);
512
520
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
513
521
  var V1_PI_PACKAGE = "npm:context-mode";
514
522
  var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
@@ -541,7 +549,7 @@ var V1_REASON = Object.freeze({
541
549
  cacheHealFile: "old context-mode cache-heal script file",
542
550
  statusLine: "old context-mode statusLine (context-mode statusline): report only, never removed",
543
551
  mcpEntry: "old context-mode MCP entry mcpServers.context-mode",
544
- codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/*.mjs",
552
+ codexHook: "old context-mode Codex hook entry: context-mode hook codex or hooks/codex/<event>.mjs",
545
553
  codexToml: "old context-mode config.toml [mcp_servers.context-mode*] section",
546
554
  hookFile: "old context-mode hook file context-mode.json (runs context-mode hook)",
547
555
  vscodeMcp: "old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",
@@ -1371,6 +1379,7 @@ function readResult6(p) {
1371
1379
  const text = p.content === void 0 ? "" : typeof p.content === "string" ? p.content : JSON.stringify(p.content);
1372
1380
  const info = { isError: p.isError === true, bytes: Buffer.byteLength(text), text };
1373
1381
  if (typeof p.exitCode === "number") info.exitCode = p.exitCode;
1382
+ if (p.keep === true) info.keep = true;
1374
1383
  return info;
1375
1384
  }
1376
1385
  function decode9(raw) {
@@ -1447,6 +1456,11 @@ function decode10(raw) {
1447
1456
  const event = Object.prototype.hasOwnProperty.call(OPENCODE_EVENTS, native) ? OPENCODE_EVENTS[native] : void 0;
1448
1457
  if (event === void 0) throw new Error("opencode: unknown hook event " + String(p.type));
1449
1458
  const ev = { event, agent: "opencode", sessionId: String(p.sessionID ?? ""), cwd: String(p.directory ?? "") };
1459
+ if (typeof p.agentID === "string" && p.agentID !== "") {
1460
+ ev.agentId = p.agentID;
1461
+ ev.agentType = p.agentID;
1462
+ }
1463
+ if (Array.isArray(p.agentTools)) ev.agentTools = p.agentTools.filter((t) => typeof t === "string");
1450
1464
  if (event === "UserPromptSubmit" && typeof p.message === "string") ev.prompt = p.message;
1451
1465
  if (event === "PreToolUse" || event === "PostToolUse") {
1452
1466
  const name = String(p.tool ?? "");
@@ -1467,7 +1481,7 @@ function encode10(ev, d, _extra) {
1467
1481
  if (ev.event !== "PreToolUse") return { stdout: "", exitCode: 0 };
1468
1482
  return { stdout: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason, exitCode: 2 };
1469
1483
  case "replace":
1470
- return { stdout: "", exitCode: 0 };
1484
+ return { stdout: ev.event === "PostToolUse" ? d.output : "", exitCode: 0 };
1471
1485
  }
1472
1486
  }
1473
1487
 
@@ -1672,7 +1686,7 @@ var ADAPTERS = Object.freeze([
1672
1686
  }
1673
1687
  ]);
1674
1688
  var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
1675
- var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi"]);
1689
+ var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
1676
1690
  function hasReplace(row) {
1677
1691
  return REPLACE_ROWS.has(row.id);
1678
1692
  }
@@ -3778,7 +3792,7 @@ function moreLine(intent, label) {
3778
3792
  }
3779
3793
 
3780
3794
  // src/core/policy/decide.ts
3781
- import { resolve as resolve3 } from "node:path";
3795
+ import { resolve as resolve5 } from "node:path";
3782
3796
 
3783
3797
  // src/core/policy/lexer.ts
3784
3798
  var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
@@ -5442,10 +5456,10 @@ function READ_DENY_RANGE_MESSAGE(path3, size) {
5442
5456
  }
5443
5457
 
5444
5458
  // src/core/policy/own-file.ts
5445
- import { extname, join as join5 } from "node:path";
5459
+ import { extname, join as join5, resolve as resolve4 } from "node:path";
5446
5460
 
5447
5461
  // src/core/project/contain.ts
5448
- import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
5462
+ import { dirname as dirname2, isAbsolute as isAbsolute2, join as join4, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
5449
5463
  var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
5450
5464
  function real(p) {
5451
5465
  try {
@@ -5477,6 +5491,29 @@ function isInsideAny(roots, p) {
5477
5491
  return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
5478
5492
  });
5479
5493
  }
5494
+ function hasParentStep(cwd, p) {
5495
+ const parts = isAbsolute2(p) ? components(p) : [...components(cwd), ...components(p)];
5496
+ return parts.includes("..");
5497
+ }
5498
+ var rootParts = /* @__PURE__ */ new Map();
5499
+ function lexicalRoot(root) {
5500
+ let rc = rootParts.get(root);
5501
+ if (rc === void 0) {
5502
+ rc = components(resolve3(root));
5503
+ rootParts.set(root, rc);
5504
+ }
5505
+ return rc;
5506
+ }
5507
+ function isLexicallyInsideAny(roots, p) {
5508
+ if (roots.length === 0) return false;
5509
+ const raw = components(p);
5510
+ if (raw.includes("..")) return false;
5511
+ const qc = sep2 === "/" && isAbsolute2(p) ? raw.filter((c) => c !== ".") : components(resolve3(p));
5512
+ return roots.some((root) => {
5513
+ const rc = lexicalRoot(root);
5514
+ return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
5515
+ });
5516
+ }
5480
5517
  function commonRoot(paths) {
5481
5518
  const reals = paths.map(real).filter((r) => r !== void 0);
5482
5519
  if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
@@ -5502,9 +5539,11 @@ function ownDirsOf(agent, env) {
5502
5539
  const own2 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
5503
5540
  return [...own2, shared];
5504
5541
  }
5505
- function isOwnFile(agent, abs, env = process.env) {
5506
- if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
5507
- return isInsideAny(ownDirsOf(agent, env), abs);
5542
+ function isOwnFile(agent, cwd, p, env = process.env) {
5543
+ if (extname(p).toLowerCase() !== AGENT_FILE_EXT) return false;
5544
+ const dirs = ownDirsOf(agent, env);
5545
+ const abs = resolve4(cwd, p);
5546
+ return !hasParentStep(cwd, p) && isLexicallyInsideAny(dirs, abs) || isInsideAny(dirs, abs);
5508
5547
  }
5509
5548
 
5510
5549
  // src/core/policy/read-media.ts
@@ -5595,7 +5634,7 @@ function readPaths(input) {
5595
5634
  }
5596
5635
  function userDenyHit(canonical, input, cwd, rules) {
5597
5636
  if (rules.length === 0) return null;
5598
- const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
5637
+ const readRule = (p) => matchesAnyDenyPattern(resolve5(cwd, p), rules, { tool: READ, projectDir: cwd });
5599
5638
  if (canonical === BASH) {
5600
5639
  const cmd = str(input.command);
5601
5640
  return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
@@ -5732,8 +5771,9 @@ function fileSize(abs) {
5732
5771
  return -1;
5733
5772
  }
5734
5773
  }
5735
- function bigDeny(ev, row, abs, size, root) {
5736
- if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
5774
+ function bigDeny(ev, row, cwd, p, size, root) {
5775
+ const abs = resolve5(cwd, p);
5776
+ if (size <= OUTPUT_CAP || isOwnFile(ev.agent, cwd, p)) return null;
5737
5777
  return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
5738
5778
  }
5739
5779
  function executeCanOpen(root, abs) {
@@ -5748,10 +5788,10 @@ function executeCanOpen(root, abs) {
5748
5788
  function read(ev, row, input, root) {
5749
5789
  if (!present(input.offset) && !present(input.limit)) {
5750
5790
  for (const p of readPaths(input)) {
5751
- const abs = resolve3(ev.cwd, p);
5791
+ const abs = resolve5(ev.cwd, p);
5752
5792
  const size = fileSize(abs);
5753
5793
  if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
5754
- const d = bigDeny(ev, row, abs, size, root);
5794
+ const d = bigDeny(ev, row, ev.cwd, p, size, root);
5755
5795
  if (d !== null) return d;
5756
5796
  }
5757
5797
  }
@@ -5764,7 +5804,7 @@ function shellDump(ev, cmds, row, root) {
5764
5804
  let verdict = null;
5765
5805
  for (const c of cmds) {
5766
5806
  const name = c.argv0.toLowerCase();
5767
- if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
5807
+ if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve5(dir, c.args[0]);
5768
5808
  if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
5769
5809
  if (!has(SHELL_DUMP_COMMANDS, name)) continue;
5770
5810
  const d = dumpTarget(name, c.args);
@@ -5773,8 +5813,8 @@ function shellDump(ev, cmds, row, root) {
5773
5813
  verdict = ALLOW;
5774
5814
  continue;
5775
5815
  }
5776
- const abs = resolve3(dir, d.file);
5777
- const big = bigDeny(ev, row, abs, fileSize(abs), root);
5816
+ const abs = resolve5(dir, d.file);
5817
+ const big = bigDeny(ev, row, dir, d.file, fileSize(abs), root);
5778
5818
  if (big !== null) return big;
5779
5819
  }
5780
5820
  return verdict;
@@ -5782,7 +5822,7 @@ function shellDump(ev, cmds, row, root) {
5782
5822
  function psShellDump(ev, cmd, row, root) {
5783
5823
  if (row.nativeTools.read !== void 0 && row.nativeTools.read.length > 0 && dumpRunsThenReplaces(row)) return null;
5784
5824
  for (const abs of psDumpFiles(cmd, ev.cwd)) {
5785
- const d = bigDeny(ev, row, abs, fileSize(abs), root);
5825
+ const d = bigDeny(ev, row, ev.cwd, abs, fileSize(abs), root);
5786
5826
  if (d !== null) return d;
5787
5827
  }
5788
5828
  return null;
@@ -5844,7 +5884,7 @@ function dumpTarget(name, args) {
5844
5884
  }
5845
5885
 
5846
5886
  // src/core/project/resolve.ts
5847
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
5887
+ import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5848
5888
 
5849
5889
  // src/core/project/sha256.ts
5850
5890
  var K = new Uint32Array([
@@ -6009,7 +6049,7 @@ function gitDirs(dir) {
6009
6049
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
6010
6050
  if (gitDir !== null) {
6011
6051
  const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
6012
- return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
6052
+ return { commonDir: realpathSync3.native(common === null ? gitDir : resolve6(gitDir, common)), worktree: cur, start };
6013
6053
  }
6014
6054
  const up = dirname3(cur);
6015
6055
  if (up === cur) return { commonDir: null, start };
@@ -6024,7 +6064,7 @@ function gitDirAt(dotGit) {
6024
6064
  } else {
6025
6065
  const line = firstLine(dotGit);
6026
6066
  if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
6027
- gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
6067
+ gitDir = resolve6(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
6028
6068
  }
6029
6069
  } catch {
6030
6070
  return null;
@@ -6240,10 +6280,10 @@ function startArgv(argv) {
6240
6280
  return sh === null ? null : [sh, ...argv];
6241
6281
  }
6242
6282
  function runProcess(argv, o) {
6243
- return new Promise((resolve5) => {
6283
+ return new Promise((resolve7) => {
6244
6284
  const isWin2 = process.platform === "win32";
6245
6285
  const start = startArgv(argv);
6246
- if (start === null) return resolve5(NOT_STARTED);
6286
+ if (start === null) return resolve7(NOT_STARTED);
6247
6287
  let child;
6248
6288
  try {
6249
6289
  child = spawn2(start[0], start.slice(1), {
@@ -6257,7 +6297,7 @@ function runProcess(argv, o) {
6257
6297
  windowsHide: true
6258
6298
  });
6259
6299
  } catch {
6260
- return resolve5(NOT_STARTED);
6300
+ return resolve7(NOT_STARTED);
6261
6301
  }
6262
6302
  const stdoutChunks = [];
6263
6303
  const stderrChunks = [];
@@ -6291,7 +6331,7 @@ function runProcess(argv, o) {
6291
6331
  clearTimeout(drainTimer);
6292
6332
  clearTimeout(stopTimer);
6293
6333
  o.signal.removeEventListener("abort", onAbort);
6294
- resolve5({
6334
+ resolve7({
6295
6335
  stdout: Buffer.concat(stdoutChunks),
6296
6336
  stderr: Buffer.concat(stderrChunks),
6297
6337
  exitCode,