context-mode 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/run.mjs CHANGED
@@ -168,6 +168,10 @@ var DB_TIMEOUT_MS = 5e3;
168
168
  var DB_WAL_SUFFIX = "-wal";
169
169
  var DB_SHM_SUFFIX = "-shm";
170
170
  var DB_TMP_SUFFIX = ".tmp";
171
+ var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
172
+ var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
173
+ var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
174
+ var DB_PUBLISH_POLL_MS = 5;
171
175
  var SQLITE_PRIMARY_CODE_MASK = 255;
172
176
  var SQLITE_CORRUPT_CODE = 11;
173
177
  var SQLITE_NOTADB_CODE = 26;
@@ -1937,7 +1941,7 @@ function openReadOnlyHandle(sqlite, path3, opts = {}) {
1937
1941
  }
1938
1942
 
1939
1943
  // src/core/store/db.ts
1940
- var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
1944
+ var { existsSync, linkSync, mkdirSync, renameSync, rmSync, statSync } = process.getBuiltinModule("node:fs");
1941
1945
  function versionParts(v) {
1942
1946
  const bare = v.startsWith("v") ? v.slice(1) : v;
1943
1947
  return bare.split(".").map((p) => Number.parseInt(p, 10));
@@ -1969,6 +1973,34 @@ function readUserVersion(raw) {
1969
1973
  const row = raw.prepare("PRAGMA user_version").get();
1970
1974
  return row.user_version;
1971
1975
  }
1976
+ function errCode(err) {
1977
+ return err.code ?? "";
1978
+ }
1979
+ function publishWithoutLink(tmp, path3) {
1980
+ const claim = path3 + DB_PUBLISH_CLAIM_SUFFIX;
1981
+ const start = Date.now();
1982
+ for (; ; ) {
1983
+ if (existsSync(path3)) return;
1984
+ try {
1985
+ mkdirSync(claim);
1986
+ } catch (err) {
1987
+ if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
1988
+ if (Date.now() - start < DB_TIMEOUT_MS) {
1989
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
1990
+ continue;
1991
+ }
1992
+ const held = statSync(claim, { throwIfNoEntry: false });
1993
+ if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
1994
+ throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
1995
+ }
1996
+ try {
1997
+ if (!existsSync(path3)) renameSync(tmp, path3);
1998
+ } finally {
1999
+ rmSync(claim, { recursive: true, force: true });
2000
+ }
2001
+ return;
2002
+ }
2003
+ }
1972
2004
  function createAtomically(sqlite, path3) {
1973
2005
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
1974
2006
  const tmp = path3 + "." + randomUUID2() + DB_TMP_SUFFIX;
@@ -1982,7 +2014,9 @@ function createAtomically(sqlite, path3) {
1982
2014
  try {
1983
2015
  linkSync(tmp, path3);
1984
2016
  } catch (err) {
1985
- if (err.code !== "EEXIST") throw err;
2017
+ const code = errCode(err);
2018
+ if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path3);
2019
+ else if (code !== "EEXIST") throw err;
1986
2020
  }
1987
2021
  } finally {
1988
2022
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
@@ -5215,8 +5249,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
5215
5249
  var CLAUDE_CODE_BUILT_INS = Object.freeze({
5216
5250
  "general-purpose": { tools: null, disallowed: [] },
5217
5251
  fork: { tools: null, disallowed: [] },
5252
+ claude: { tools: null, disallowed: [] },
5218
5253
  Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5219
- Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
5254
+ Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5255
+ "claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
5256
+ "statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
5257
+ "web-fetch": { tools: ["WebFetch"], disallowed: [] }
5220
5258
  });
5221
5259
  function isSubagentCall(ev) {
5222
5260
  return ev.agentId !== void 0 && ev.agentId !== "";
@@ -5225,13 +5263,15 @@ function isSubagentCall(ev) {
5225
5263
  // src/core/policy/unwrap.ts
5226
5264
  var NONE = "";
5227
5265
  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 }
5266
+ sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5267
+ env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5268
+ time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5269
+ nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5270
+ timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
5271
+ command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
5272
+ xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5273
+ // #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
5274
+ rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
5235
5275
  });
5236
5276
  var SHELLS = ["bash", "sh", "zsh"];
5237
5277
  var SCRIPT_FLAG = "c";
@@ -5254,6 +5294,10 @@ function isDuration(s) {
5254
5294
  }
5255
5295
  function peel(w, args) {
5256
5296
  let k = 0;
5297
+ if (w.subcommands.length > 0) {
5298
+ if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
5299
+ k = 1;
5300
+ }
5257
5301
  while (k < args.length) {
5258
5302
  const a = args[k];
5259
5303
  if (a === LONG_OPT2) {
@@ -5624,7 +5668,7 @@ function isMediaRead(agent, abs) {
5624
5668
  }
5625
5669
 
5626
5670
  // src/core/policy/decide.ts
5627
- var { statSync } = process.getBuiltinModule("node:fs");
5671
+ var { statSync: statSync2 } = process.getBuiltinModule("node:fs");
5628
5672
  var BASH = "Bash";
5629
5673
  var READ = "Read";
5630
5674
  var WEBFETCH = "WebFetch";
@@ -5815,7 +5859,7 @@ function inlineHttp(raw) {
5815
5859
  var CD_COMMAND = "cd";
5816
5860
  function fileSize(abs) {
5817
5861
  try {
5818
- const st = statSync(abs);
5862
+ const st = statSync2(abs);
5819
5863
  return st.isFile() ? st.size : -1;
5820
5864
  } catch {
5821
5865
  return -1;
@@ -6049,7 +6093,7 @@ function sha256Hex(text) {
6049
6093
  }
6050
6094
 
6051
6095
  // src/core/project/resolve.ts
6052
- var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
6096
+ var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync3 } = process.getBuiltinModule("node:fs");
6053
6097
  function sourceOf(agent) {
6054
6098
  switch (agent) {
6055
6099
  case "claude-code":
@@ -6110,7 +6154,7 @@ function gitDirs(dir) {
6110
6154
  function gitDirAt(dotGit) {
6111
6155
  let gitDir;
6112
6156
  try {
6113
- if (statSync2(dotGit).isDirectory()) {
6157
+ if (statSync3(dotGit).isDirectory()) {
6114
6158
  gitDir = dotGit;
6115
6159
  } else {
6116
6160
  const line = firstLine(dotGit);
@@ -6216,7 +6260,7 @@ function buildChildEnv(parent, extra) {
6216
6260
  }
6217
6261
 
6218
6262
  // src/core/sandbox/runtimes.ts
6219
- import { accessSync, constants as fsConstants, statSync as statSync3 } from "node:fs";
6263
+ import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
6220
6264
  import path from "node:path";
6221
6265
 
6222
6266
  // src/core/sandbox/path-entries.ts
@@ -6261,7 +6305,7 @@ function fileNames(name, pathExt) {
6261
6305
  function probe(full) {
6262
6306
  let st;
6263
6307
  try {
6264
- st = statSync3(full, { throwIfNoEntry: false });
6308
+ st = statSync4(full, { throwIfNoEntry: false });
6265
6309
  } catch {
6266
6310
  return "unreadable";
6267
6311
  }
package/search.mjs CHANGED
@@ -168,6 +168,10 @@ var DB_TIMEOUT_MS = 5e3;
168
168
  var DB_WAL_SUFFIX = "-wal";
169
169
  var DB_SHM_SUFFIX = "-shm";
170
170
  var DB_TMP_SUFFIX = ".tmp";
171
+ var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
172
+ var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
173
+ var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
174
+ var DB_PUBLISH_POLL_MS = 5;
171
175
  var SQLITE_PRIMARY_CODE_MASK = 255;
172
176
  var SQLITE_CORRUPT_CODE = 11;
173
177
  var SQLITE_NOTADB_CODE = 26;
@@ -1937,7 +1941,7 @@ function openReadOnlyHandle(sqlite, path3, opts = {}) {
1937
1941
  }
1938
1942
 
1939
1943
  // src/core/store/db.ts
1940
- var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
1944
+ var { existsSync, linkSync, mkdirSync, renameSync, rmSync, statSync } = process.getBuiltinModule("node:fs");
1941
1945
  function versionParts(v) {
1942
1946
  const bare = v.startsWith("v") ? v.slice(1) : v;
1943
1947
  return bare.split(".").map((p) => Number.parseInt(p, 10));
@@ -1969,6 +1973,34 @@ function readUserVersion(raw) {
1969
1973
  const row = raw.prepare("PRAGMA user_version").get();
1970
1974
  return row.user_version;
1971
1975
  }
1976
+ function errCode(err) {
1977
+ return err.code ?? "";
1978
+ }
1979
+ function publishWithoutLink(tmp, path3) {
1980
+ const claim = path3 + DB_PUBLISH_CLAIM_SUFFIX;
1981
+ const start = Date.now();
1982
+ for (; ; ) {
1983
+ if (existsSync(path3)) return;
1984
+ try {
1985
+ mkdirSync(claim);
1986
+ } catch (err) {
1987
+ if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
1988
+ if (Date.now() - start < DB_TIMEOUT_MS) {
1989
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
1990
+ continue;
1991
+ }
1992
+ const held = statSync(claim, { throwIfNoEntry: false });
1993
+ if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
1994
+ throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
1995
+ }
1996
+ try {
1997
+ if (!existsSync(path3)) renameSync(tmp, path3);
1998
+ } finally {
1999
+ rmSync(claim, { recursive: true, force: true });
2000
+ }
2001
+ return;
2002
+ }
2003
+ }
1972
2004
  function createAtomically(sqlite, path3) {
1973
2005
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
1974
2006
  const tmp = path3 + "." + randomUUID2() + DB_TMP_SUFFIX;
@@ -1982,7 +2014,9 @@ function createAtomically(sqlite, path3) {
1982
2014
  try {
1983
2015
  linkSync(tmp, path3);
1984
2016
  } catch (err) {
1985
- if (err.code !== "EEXIST") throw err;
2017
+ const code = errCode(err);
2018
+ if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path3);
2019
+ else if (code !== "EEXIST") throw err;
1986
2020
  }
1987
2021
  } finally {
1988
2022
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
@@ -5215,8 +5249,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
5215
5249
  var CLAUDE_CODE_BUILT_INS = Object.freeze({
5216
5250
  "general-purpose": { tools: null, disallowed: [] },
5217
5251
  fork: { tools: null, disallowed: [] },
5252
+ claude: { tools: null, disallowed: [] },
5218
5253
  Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5219
- Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
5254
+ Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
5255
+ "claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
5256
+ "statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
5257
+ "web-fetch": { tools: ["WebFetch"], disallowed: [] }
5220
5258
  });
5221
5259
  function isSubagentCall(ev) {
5222
5260
  return ev.agentId !== void 0 && ev.agentId !== "";
@@ -5225,13 +5263,15 @@ function isSubagentCall(ev) {
5225
5263
  // src/core/policy/unwrap.ts
5226
5264
  var NONE = "";
5227
5265
  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 }
5266
+ sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5267
+ env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
5268
+ time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5269
+ nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5270
+ timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
5271
+ command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
5272
+ xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
5273
+ // #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
5274
+ rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
5235
5275
  });
5236
5276
  var SHELLS = ["bash", "sh", "zsh"];
5237
5277
  var SCRIPT_FLAG = "c";
@@ -5254,6 +5294,10 @@ function isDuration(s) {
5254
5294
  }
5255
5295
  function peel(w, args) {
5256
5296
  let k = 0;
5297
+ if (w.subcommands.length > 0) {
5298
+ if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
5299
+ k = 1;
5300
+ }
5257
5301
  while (k < args.length) {
5258
5302
  const a = args[k];
5259
5303
  if (a === LONG_OPT2) {
@@ -5624,7 +5668,7 @@ function isMediaRead(agent, abs) {
5624
5668
  }
5625
5669
 
5626
5670
  // src/core/policy/decide.ts
5627
- var { statSync } = process.getBuiltinModule("node:fs");
5671
+ var { statSync: statSync2 } = process.getBuiltinModule("node:fs");
5628
5672
  var BASH = "Bash";
5629
5673
  var READ = "Read";
5630
5674
  var WEBFETCH = "WebFetch";
@@ -5815,7 +5859,7 @@ function inlineHttp(raw) {
5815
5859
  var CD_COMMAND = "cd";
5816
5860
  function fileSize(abs) {
5817
5861
  try {
5818
- const st = statSync(abs);
5862
+ const st = statSync2(abs);
5819
5863
  return st.isFile() ? st.size : -1;
5820
5864
  } catch {
5821
5865
  return -1;
@@ -6049,7 +6093,7 @@ function sha256Hex(text) {
6049
6093
  }
6050
6094
 
6051
6095
  // src/core/project/resolve.ts
6052
- var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
6096
+ var { existsSync: existsSync3, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync3 } = process.getBuiltinModule("node:fs");
6053
6097
  function sourceOf(agent) {
6054
6098
  switch (agent) {
6055
6099
  case "claude-code":
@@ -6110,7 +6154,7 @@ function gitDirs(dir) {
6110
6154
  function gitDirAt(dotGit) {
6111
6155
  let gitDir;
6112
6156
  try {
6113
- if (statSync2(dotGit).isDirectory()) {
6157
+ if (statSync3(dotGit).isDirectory()) {
6114
6158
  gitDir = dotGit;
6115
6159
  } else {
6116
6160
  const line = firstLine(dotGit);
@@ -6216,7 +6260,7 @@ function buildChildEnv(parent, extra) {
6216
6260
  }
6217
6261
 
6218
6262
  // src/core/sandbox/runtimes.ts
6219
- import { accessSync, constants as fsConstants, statSync as statSync3 } from "node:fs";
6263
+ import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
6220
6264
  import path from "node:path";
6221
6265
 
6222
6266
  // src/core/sandbox/path-entries.ts
@@ -6261,7 +6305,7 @@ function fileNames(name, pathExt) {
6261
6305
  function probe(full) {
6262
6306
  let st;
6263
6307
  try {
6264
- st = statSync3(full, { throwIfNoEntry: false });
6308
+ st = statSync4(full, { throwIfNoEntry: false });
6265
6309
  } catch {
6266
6310
  return "unreadable";
6267
6311
  }