context-mode 2.2.0 → 2.2.2

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.2.0"
15
+ "version": "2.2.2"
16
16
  }
package/run.mjs CHANGED
@@ -24,6 +24,7 @@ function readReplaceTrigger(raw) {
24
24
  var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
25
25
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
26
26
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
27
+ var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
27
28
  function shellWord(s) {
28
29
  return "'" + s.split("'").join("'\\''") + "'";
29
30
  }
@@ -168,6 +169,10 @@ var DB_TIMEOUT_MS = 5e3;
168
169
  var DB_WAL_SUFFIX = "-wal";
169
170
  var DB_SHM_SUFFIX = "-shm";
170
171
  var DB_TMP_SUFFIX = ".tmp";
172
+ var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
173
+ var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
174
+ var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
175
+ var DB_PUBLISH_POLL_MS = 5;
171
176
  var SQLITE_PRIMARY_CODE_MASK = 255;
172
177
  var SQLITE_CORRUPT_CODE = 11;
173
178
  var SQLITE_NOTADB_CODE = 26;
@@ -198,6 +203,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
198
203
  var RUN_WRAPPER_AGENT = "claude-code";
199
204
  var RUN_SESSION_PREFIX = "mcp:";
200
205
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
206
+ var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
201
207
  var NODE_MIN = "24.15.0";
202
208
  var DATA_ROOT = "~/.context-mode";
203
209
  var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
@@ -671,6 +677,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
671
677
  var POWERSHELL_TOOL = "PowerShell";
672
678
  var SHELL_CANONICAL = "Bash";
673
679
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
680
+ var FAILURE_EVENT = "PostToolUseFailure";
674
681
  var MCP_PREFIX = "mcp__";
675
682
  var MCP_SEP = "__";
676
683
  var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
@@ -844,7 +851,14 @@ function requireFields(raw) {
844
851
  }
845
852
  function decode(raw) {
846
853
  requireFields(raw);
847
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
854
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
855
+ const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
856
+ const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
857
+ if (failure) {
858
+ const error = raw.error;
859
+ const text = typeof error === "string" ? error : error === void 0 ? "" : JSON.stringify(error);
860
+ ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
861
+ }
848
862
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
849
863
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
850
864
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1023,9 +1037,9 @@ var NATIVE_TO_CANONICAL2 = {
1023
1037
  grep_search: "Grep",
1024
1038
  web_fetch: "WebFetch"
1025
1039
  };
1026
- var FAILURE_EVENT = "PostToolUseFailure";
1040
+ var FAILURE_EVENT2 = "PostToolUseFailure";
1027
1041
  function decode4(raw) {
1028
- const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1042
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
1029
1043
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1030
1044
  const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1031
1045
  if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
@@ -1345,12 +1359,12 @@ var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1345
1359
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1346
1360
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1347
1361
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1348
- var FAILURE_EVENT2 = "PostToolUseFailure";
1362
+ var FAILURE_EVENT3 = "PostToolUseFailure";
1349
1363
  function decode8(raw) {
1350
1364
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1351
1365
  const p = { ...raw };
1352
1366
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1353
- const failure = p.hook_event_name === FAILURE_EVENT2;
1367
+ const failure = p.hook_event_name === FAILURE_EVENT3;
1354
1368
  if (failure) p.hook_event_name = "PostToolUse";
1355
1369
  const toolName = typeof p.tool_name === "string" ? p.tool_name : "";
1356
1370
  const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
@@ -1441,7 +1455,8 @@ var OPENCODE_EVENTS = {
1441
1455
  var SHELL_TOOL_NAME = "bash";
1442
1456
  var READ_TOOL_NAME = "read";
1443
1457
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1444
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1458
+ var SKILL_TOOL_NAME = "skill";
1459
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1445
1460
  function toCanonicalTool(name) {
1446
1461
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1447
1462
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1937,7 +1952,7 @@ function openReadOnlyHandle(sqlite, path3, opts = {}) {
1937
1952
  }
1938
1953
 
1939
1954
  // src/core/store/db.ts
1940
- var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
1955
+ var { existsSync, linkSync, mkdirSync, renameSync, rmSync, statSync } = process.getBuiltinModule("node:fs");
1941
1956
  function versionParts(v) {
1942
1957
  const bare = v.startsWith("v") ? v.slice(1) : v;
1943
1958
  return bare.split(".").map((p) => Number.parseInt(p, 10));
@@ -1969,6 +1984,34 @@ function readUserVersion(raw) {
1969
1984
  const row = raw.prepare("PRAGMA user_version").get();
1970
1985
  return row.user_version;
1971
1986
  }
1987
+ function errCode(err) {
1988
+ return err.code ?? "";
1989
+ }
1990
+ function publishWithoutLink(tmp, path3) {
1991
+ const claim = path3 + DB_PUBLISH_CLAIM_SUFFIX;
1992
+ const start = Date.now();
1993
+ for (; ; ) {
1994
+ if (existsSync(path3)) return;
1995
+ try {
1996
+ mkdirSync(claim);
1997
+ } catch (err) {
1998
+ if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
1999
+ if (Date.now() - start < DB_TIMEOUT_MS) {
2000
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
2001
+ continue;
2002
+ }
2003
+ const held = statSync(claim, { throwIfNoEntry: false });
2004
+ if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
2005
+ throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
2006
+ }
2007
+ try {
2008
+ if (!existsSync(path3)) renameSync(tmp, path3);
2009
+ } finally {
2010
+ rmSync(claim, { recursive: true, force: true });
2011
+ }
2012
+ return;
2013
+ }
2014
+ }
1972
2015
  function createAtomically(sqlite, path3) {
1973
2016
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
1974
2017
  const tmp = path3 + "." + randomUUID2() + DB_TMP_SUFFIX;
@@ -1982,7 +2025,9 @@ function createAtomically(sqlite, path3) {
1982
2025
  try {
1983
2026
  linkSync(tmp, path3);
1984
2027
  } catch (err) {
1985
- if (err.code !== "EEXIST") throw err;
2028
+ const code = errCode(err);
2029
+ if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path3);
2030
+ else if (code !== "EEXIST") throw err;
1986
2031
  }
1987
2032
  } finally {
1988
2033
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
@@ -5215,8 +5260,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
5215
5260
  var CLAUDE_CODE_BUILT_INS = Object.freeze({
5216
5261
  "general-purpose": { tools: null, disallowed: [] },
5217
5262
  fork: { tools: null, disallowed: [] },
5263
+ claude: { tools: null, disallowed: [] },
5218
5264
  Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5219
- Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
5265
+ Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5266
+ "claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
5267
+ "statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
5268
+ "web-fetch": { tools: ["WebFetch"], disallowed: [] }
5220
5269
  });
5221
5270
  function isSubagentCall(ev) {
5222
5271
  return ev.agentId !== void 0 && ev.agentId !== "";
@@ -5225,13 +5274,15 @@ function isSubagentCall(ev) {
5225
5274
  // src/core/policy/unwrap.ts
5226
5275
  var NONE = "";
5227
5276
  var WRAPPERS = Object.freeze({
5228
- sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
5229
- env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
5230
- time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
5231
- nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
5232
- timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
5233
- command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
5234
- xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
5277
+ sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5278
+ env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5279
+ time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5280
+ nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5281
+ timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
5282
+ command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
5283
+ xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5284
+ // #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
5285
+ rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
5235
5286
  });
5236
5287
  var SHELLS = ["bash", "sh", "zsh"];
5237
5288
  var SCRIPT_FLAG = "c";
@@ -5254,6 +5305,10 @@ function isDuration(s) {
5254
5305
  }
5255
5306
  function peel(w, args) {
5256
5307
  let k = 0;
5308
+ if (w.subcommands.length > 0) {
5309
+ if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
5310
+ k = 1;
5311
+ }
5257
5312
  while (k < args.length) {
5258
5313
  const a = args[k];
5259
5314
  if (a === LONG_OPT2) {
@@ -5624,7 +5679,7 @@ function isMediaRead(agent, abs) {
5624
5679
  }
5625
5680
 
5626
5681
  // src/core/policy/decide.ts
5627
- var { statSync } = process.getBuiltinModule("node:fs");
5682
+ var { statSync: statSync2 } = process.getBuiltinModule("node:fs");
5628
5683
  var BASH = "Bash";
5629
5684
  var READ = "Read";
5630
5685
  var WEBFETCH = "WebFetch";
@@ -5815,7 +5870,7 @@ function inlineHttp(raw) {
5815
5870
  var CD_COMMAND = "cd";
5816
5871
  function fileSize(abs) {
5817
5872
  try {
5818
- const st = statSync(abs);
5873
+ const st = statSync2(abs);
5819
5874
  return st.isFile() ? st.size : -1;
5820
5875
  } catch {
5821
5876
  return -1;
@@ -5934,7 +5989,7 @@ function dumpTarget(name, args) {
5934
5989
  }
5935
5990
 
5936
5991
  // src/core/project/resolve.ts
5937
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5992
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
5938
5993
 
5939
5994
  // src/core/project/sha256.ts
5940
5995
  var K = new Uint32Array([
@@ -6049,7 +6104,7 @@ function sha256Hex(text) {
6049
6104
  }
6050
6105
 
6051
6106
  // src/core/project/resolve.ts
6052
- var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
6107
+ var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync3 } = process.getBuiltinModule("node:fs");
6053
6108
  function sourceOf(agent) {
6054
6109
  switch (agent) {
6055
6110
  case "claude-code":
@@ -6089,12 +6144,7 @@ function dirOf(kind, src) {
6089
6144
  }
6090
6145
  }
6091
6146
  function gitDirs(dir) {
6092
- let cur;
6093
- try {
6094
- cur = realpathSync3.native(dir);
6095
- } catch {
6096
- throw new CtxError("NO_GIT_DIR", { path: dir });
6097
- }
6147
+ let cur = nearestRealDir(dir);
6098
6148
  const start = cur;
6099
6149
  for (; ; ) {
6100
6150
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
@@ -6107,10 +6157,22 @@ function gitDirs(dir) {
6107
6157
  cur = up;
6108
6158
  }
6109
6159
  }
6160
+ function nearestRealDir(dir) {
6161
+ const walk2 = isAbsolute3(dir);
6162
+ for (let d = walk2 ? resolve6(dir) : dir; ; ) {
6163
+ try {
6164
+ return realpathSync3.native(d);
6165
+ } catch {
6166
+ const up = dirname3(d);
6167
+ if (!walk2 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
6168
+ d = up;
6169
+ }
6170
+ }
6171
+ }
6110
6172
  function gitDirAt(dotGit) {
6111
6173
  let gitDir;
6112
6174
  try {
6113
- if (statSync2(dotGit).isDirectory()) {
6175
+ if (statSync3(dotGit).isDirectory()) {
6114
6176
  gitDir = dotGit;
6115
6177
  } else {
6116
6178
  const line = firstLine(dotGit);
@@ -6169,7 +6231,7 @@ function resolveProject(agent, src) {
6169
6231
  },
6170
6232
  worktree,
6171
6233
  get containmentRoot() {
6172
- root ??= plain ?? containmentRootOf(dir, commonDir);
6234
+ root ??= plain ?? containmentRootOf(worktree, commonDir);
6173
6235
  return root;
6174
6236
  },
6175
6237
  agent,
@@ -6216,7 +6278,7 @@ function buildChildEnv(parent, extra) {
6216
6278
  }
6217
6279
 
6218
6280
  // src/core/sandbox/runtimes.ts
6219
- import { accessSync, constants as fsConstants, statSync as statSync3 } from "node:fs";
6281
+ import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
6220
6282
  import path from "node:path";
6221
6283
 
6222
6284
  // src/core/sandbox/path-entries.ts
@@ -6261,7 +6323,7 @@ function fileNames(name, pathExt) {
6261
6323
  function probe(full) {
6262
6324
  let st;
6263
6325
  try {
6264
- st = statSync3(full, { throwIfNoEntry: false });
6326
+ st = statSync4(full, { throwIfNoEntry: false });
6265
6327
  } catch {
6266
6328
  return "unreadable";
6267
6329
  }
package/search.mjs CHANGED
@@ -24,6 +24,7 @@ function readReplaceTrigger(raw) {
24
24
  var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
25
25
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
26
26
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
27
+ var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
27
28
  function shellWord(s) {
28
29
  return "'" + s.split("'").join("'\\''") + "'";
29
30
  }
@@ -168,6 +169,10 @@ var DB_TIMEOUT_MS = 5e3;
168
169
  var DB_WAL_SUFFIX = "-wal";
169
170
  var DB_SHM_SUFFIX = "-shm";
170
171
  var DB_TMP_SUFFIX = ".tmp";
172
+ var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
173
+ var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
174
+ var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
175
+ var DB_PUBLISH_POLL_MS = 5;
171
176
  var SQLITE_PRIMARY_CODE_MASK = 255;
172
177
  var SQLITE_CORRUPT_CODE = 11;
173
178
  var SQLITE_NOTADB_CODE = 26;
@@ -198,6 +203,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
198
203
  var RUN_WRAPPER_AGENT = "claude-code";
199
204
  var RUN_SESSION_PREFIX = "mcp:";
200
205
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
206
+ var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
201
207
  var NODE_MIN = "24.15.0";
202
208
  var DATA_ROOT = "~/.context-mode";
203
209
  var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
@@ -671,6 +677,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
671
677
  var POWERSHELL_TOOL = "PowerShell";
672
678
  var SHELL_CANONICAL = "Bash";
673
679
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
680
+ var FAILURE_EVENT = "PostToolUseFailure";
674
681
  var MCP_PREFIX = "mcp__";
675
682
  var MCP_SEP = "__";
676
683
  var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
@@ -844,7 +851,14 @@ function requireFields(raw) {
844
851
  }
845
852
  function decode(raw) {
846
853
  requireFields(raw);
847
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
854
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
855
+ const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
856
+ const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
857
+ if (failure) {
858
+ const error = raw.error;
859
+ const text = typeof error === "string" ? error : error === void 0 ? "" : JSON.stringify(error);
860
+ ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
861
+ }
848
862
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
849
863
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
850
864
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1023,9 +1037,9 @@ var NATIVE_TO_CANONICAL2 = {
1023
1037
  grep_search: "Grep",
1024
1038
  web_fetch: "WebFetch"
1025
1039
  };
1026
- var FAILURE_EVENT = "PostToolUseFailure";
1040
+ var FAILURE_EVENT2 = "PostToolUseFailure";
1027
1041
  function decode4(raw) {
1028
- const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1042
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
1029
1043
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1030
1044
  const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1031
1045
  if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
@@ -1345,12 +1359,12 @@ var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1345
1359
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1346
1360
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1347
1361
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1348
- var FAILURE_EVENT2 = "PostToolUseFailure";
1362
+ var FAILURE_EVENT3 = "PostToolUseFailure";
1349
1363
  function decode8(raw) {
1350
1364
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1351
1365
  const p = { ...raw };
1352
1366
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1353
- const failure = p.hook_event_name === FAILURE_EVENT2;
1367
+ const failure = p.hook_event_name === FAILURE_EVENT3;
1354
1368
  if (failure) p.hook_event_name = "PostToolUse";
1355
1369
  const toolName = typeof p.tool_name === "string" ? p.tool_name : "";
1356
1370
  const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
@@ -1441,7 +1455,8 @@ var OPENCODE_EVENTS = {
1441
1455
  var SHELL_TOOL_NAME = "bash";
1442
1456
  var READ_TOOL_NAME = "read";
1443
1457
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1444
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1458
+ var SKILL_TOOL_NAME = "skill";
1459
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1445
1460
  function toCanonicalTool(name) {
1446
1461
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1447
1462
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1937,7 +1952,7 @@ function openReadOnlyHandle(sqlite, path3, opts = {}) {
1937
1952
  }
1938
1953
 
1939
1954
  // src/core/store/db.ts
1940
- var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
1955
+ var { existsSync, linkSync, mkdirSync, renameSync, rmSync, statSync } = process.getBuiltinModule("node:fs");
1941
1956
  function versionParts(v) {
1942
1957
  const bare = v.startsWith("v") ? v.slice(1) : v;
1943
1958
  return bare.split(".").map((p) => Number.parseInt(p, 10));
@@ -1969,6 +1984,34 @@ function readUserVersion(raw) {
1969
1984
  const row = raw.prepare("PRAGMA user_version").get();
1970
1985
  return row.user_version;
1971
1986
  }
1987
+ function errCode(err) {
1988
+ return err.code ?? "";
1989
+ }
1990
+ function publishWithoutLink(tmp, path3) {
1991
+ const claim = path3 + DB_PUBLISH_CLAIM_SUFFIX;
1992
+ const start = Date.now();
1993
+ for (; ; ) {
1994
+ if (existsSync(path3)) return;
1995
+ try {
1996
+ mkdirSync(claim);
1997
+ } catch (err) {
1998
+ if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
1999
+ if (Date.now() - start < DB_TIMEOUT_MS) {
2000
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
2001
+ continue;
2002
+ }
2003
+ const held = statSync(claim, { throwIfNoEntry: false });
2004
+ if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
2005
+ throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
2006
+ }
2007
+ try {
2008
+ if (!existsSync(path3)) renameSync(tmp, path3);
2009
+ } finally {
2010
+ rmSync(claim, { recursive: true, force: true });
2011
+ }
2012
+ return;
2013
+ }
2014
+ }
1972
2015
  function createAtomically(sqlite, path3) {
1973
2016
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
1974
2017
  const tmp = path3 + "." + randomUUID2() + DB_TMP_SUFFIX;
@@ -1982,7 +2025,9 @@ function createAtomically(sqlite, path3) {
1982
2025
  try {
1983
2026
  linkSync(tmp, path3);
1984
2027
  } catch (err) {
1985
- if (err.code !== "EEXIST") throw err;
2028
+ const code = errCode(err);
2029
+ if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path3);
2030
+ else if (code !== "EEXIST") throw err;
1986
2031
  }
1987
2032
  } finally {
1988
2033
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
@@ -5215,8 +5260,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
5215
5260
  var CLAUDE_CODE_BUILT_INS = Object.freeze({
5216
5261
  "general-purpose": { tools: null, disallowed: [] },
5217
5262
  fork: { tools: null, disallowed: [] },
5263
+ claude: { tools: null, disallowed: [] },
5218
5264
  Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5219
- Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
5265
+ Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5266
+ "claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
5267
+ "statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
5268
+ "web-fetch": { tools: ["WebFetch"], disallowed: [] }
5220
5269
  });
5221
5270
  function isSubagentCall(ev) {
5222
5271
  return ev.agentId !== void 0 && ev.agentId !== "";
@@ -5225,13 +5274,15 @@ function isSubagentCall(ev) {
5225
5274
  // src/core/policy/unwrap.ts
5226
5275
  var NONE = "";
5227
5276
  var WRAPPERS = Object.freeze({
5228
- sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
5229
- env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
5230
- time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
5231
- nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
5232
- timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
5233
- command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
5234
- xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
5277
+ sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5278
+ env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5279
+ time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5280
+ nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5281
+ timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
5282
+ command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
5283
+ xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5284
+ // #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
5285
+ rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
5235
5286
  });
5236
5287
  var SHELLS = ["bash", "sh", "zsh"];
5237
5288
  var SCRIPT_FLAG = "c";
@@ -5254,6 +5305,10 @@ function isDuration(s) {
5254
5305
  }
5255
5306
  function peel(w, args) {
5256
5307
  let k = 0;
5308
+ if (w.subcommands.length > 0) {
5309
+ if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
5310
+ k = 1;
5311
+ }
5257
5312
  while (k < args.length) {
5258
5313
  const a = args[k];
5259
5314
  if (a === LONG_OPT2) {
@@ -5624,7 +5679,7 @@ function isMediaRead(agent, abs) {
5624
5679
  }
5625
5680
 
5626
5681
  // src/core/policy/decide.ts
5627
- var { statSync } = process.getBuiltinModule("node:fs");
5682
+ var { statSync: statSync2 } = process.getBuiltinModule("node:fs");
5628
5683
  var BASH = "Bash";
5629
5684
  var READ = "Read";
5630
5685
  var WEBFETCH = "WebFetch";
@@ -5815,7 +5870,7 @@ function inlineHttp(raw) {
5815
5870
  var CD_COMMAND = "cd";
5816
5871
  function fileSize(abs) {
5817
5872
  try {
5818
- const st = statSync(abs);
5873
+ const st = statSync2(abs);
5819
5874
  return st.isFile() ? st.size : -1;
5820
5875
  } catch {
5821
5876
  return -1;
@@ -5934,7 +5989,7 @@ function dumpTarget(name, args) {
5934
5989
  }
5935
5990
 
5936
5991
  // src/core/project/resolve.ts
5937
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5992
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
5938
5993
 
5939
5994
  // src/core/project/sha256.ts
5940
5995
  var K = new Uint32Array([
@@ -6049,7 +6104,7 @@ function sha256Hex(text) {
6049
6104
  }
6050
6105
 
6051
6106
  // src/core/project/resolve.ts
6052
- var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
6107
+ var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync3 } = process.getBuiltinModule("node:fs");
6053
6108
  function sourceOf(agent) {
6054
6109
  switch (agent) {
6055
6110
  case "claude-code":
@@ -6089,12 +6144,7 @@ function dirOf(kind, src) {
6089
6144
  }
6090
6145
  }
6091
6146
  function gitDirs(dir) {
6092
- let cur;
6093
- try {
6094
- cur = realpathSync3.native(dir);
6095
- } catch {
6096
- throw new CtxError("NO_GIT_DIR", { path: dir });
6097
- }
6147
+ let cur = nearestRealDir(dir);
6098
6148
  const start = cur;
6099
6149
  for (; ; ) {
6100
6150
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
@@ -6107,10 +6157,22 @@ function gitDirs(dir) {
6107
6157
  cur = up;
6108
6158
  }
6109
6159
  }
6160
+ function nearestRealDir(dir) {
6161
+ const walk2 = isAbsolute3(dir);
6162
+ for (let d = walk2 ? resolve6(dir) : dir; ; ) {
6163
+ try {
6164
+ return realpathSync3.native(d);
6165
+ } catch {
6166
+ const up = dirname3(d);
6167
+ if (!walk2 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
6168
+ d = up;
6169
+ }
6170
+ }
6171
+ }
6110
6172
  function gitDirAt(dotGit) {
6111
6173
  let gitDir;
6112
6174
  try {
6113
- if (statSync2(dotGit).isDirectory()) {
6175
+ if (statSync3(dotGit).isDirectory()) {
6114
6176
  gitDir = dotGit;
6115
6177
  } else {
6116
6178
  const line = firstLine(dotGit);
@@ -6169,7 +6231,7 @@ function resolveProject(agent, src) {
6169
6231
  },
6170
6232
  worktree,
6171
6233
  get containmentRoot() {
6172
- root ??= plain ?? containmentRootOf(dir, commonDir);
6234
+ root ??= plain ?? containmentRootOf(worktree, commonDir);
6173
6235
  return root;
6174
6236
  },
6175
6237
  agent,
@@ -6216,7 +6278,7 @@ function buildChildEnv(parent, extra) {
6216
6278
  }
6217
6279
 
6218
6280
  // src/core/sandbox/runtimes.ts
6219
- import { accessSync, constants as fsConstants, statSync as statSync3 } from "node:fs";
6281
+ import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
6220
6282
  import path from "node:path";
6221
6283
 
6222
6284
  // src/core/sandbox/path-entries.ts
@@ -6261,7 +6323,7 @@ function fileNames(name, pathExt) {
6261
6323
  function probe(full) {
6262
6324
  let st;
6263
6325
  try {
6264
- st = statSync3(full, { throwIfNoEntry: false });
6326
+ st = statSync4(full, { throwIfNoEntry: false });
6265
6327
  } catch {
6266
6328
  return "unreadable";
6267
6329
  }