context-mode 2.1.2 → 2.1.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.
package/run.mjs CHANGED
@@ -14,6 +14,8 @@ function prefixToolNames(text, prefix) {
14
14
  }
15
15
  var OUTPUT_CAP = 16384;
16
16
  var INDEX_WRITE_CHUNK = 1048576;
17
+ var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
18
+ var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
17
19
  var MAX_CHUNK_BYTES = 4096;
18
20
  var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
19
21
  var DECAY_X1000 = Object.freeze([
@@ -168,6 +170,7 @@ var GIT_COMMONDIR_FILE = "commondir";
168
170
  var GIT_HEAD_FILE = "HEAD";
169
171
  var WORKSPACE_FOLDER_FLAG = "--workspace-folder";
170
172
  var EXEC_LANGUAGES = Object.freeze(["shell", "powershell", "javascript", "typescript", "python"]);
173
+ var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
171
174
  var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
172
175
  var SOURCE_LABEL_MAX_CHARS = 80;
173
176
  var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
@@ -183,6 +186,7 @@ var RUN_SESSION_PREFIX = "mcp:";
183
186
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
184
187
  var NODE_MIN = "24.15.0";
185
188
  var DATA_ROOT = "~/.context-mode";
189
+ var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
186
190
  var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
187
191
  var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
188
192
  var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
@@ -252,7 +256,8 @@ var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
252
256
  var SED_COMMAND = "sed";
253
257
  var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
254
258
  var JQ_COMMAND = "jq";
255
- var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path"]);
259
+ var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
260
+ var READ_PATH_LIST_KEY = "filePaths";
256
261
  var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
257
262
  var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
258
263
  var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
@@ -321,19 +326,18 @@ var AGENT_HOME_DIR = Object.freeze({
321
326
  var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
322
327
  var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
323
328
  var GIT_HEAD_SHA_ARGS = Object.freeze(["rev-parse", "HEAD"]);
324
- var UPGRADE_GIT_CHECKOUT_AGENTS = Object.freeze(["pi", "opencode"]);
325
329
  var GIT_NO_PROMPT_ENV = Object.freeze({ GIT_TERMINAL_PROMPT: "0" });
326
330
  var GIT_NO_CRLF_ENV = Object.freeze({ GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "core.autocrlf", GIT_CONFIG_VALUE_0: "false" });
327
331
  var GIT_BIN = "git";
328
332
  var WIN_SHELL_LANGS = Object.freeze(["shell", "bash", "sh"]);
329
333
  var GIT_BASH_RELATIVE = Object.freeze([["..", "bin", "bash.exe"], ["..", "..", "bin", "bash.exe"]]);
334
+ var PERSISTED_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
330
335
  var OPS_SPLIT_FILES = Object.freeze([
331
336
  "doctor-env.ts",
332
337
  "doctor-config.ts",
333
338
  "doctor-hook.ts",
334
339
  "doctor-db.ts",
335
340
  "doctor-heal.ts",
336
- "release-fetch.ts",
337
341
  "verify-sums.ts",
338
342
  "plugin-swap.ts",
339
343
  "host-write.ts",
@@ -358,9 +362,15 @@ var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
358
362
  var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
359
363
  var UPGRADE_HOST_COMMAND = Object.freeze({
360
364
  "claude-code": "claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",
361
- codex: "rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",
362
- gemini: "gemini extensions install https://github.com/mksglu/context-mode --auto-update",
363
- qwen: "qwen extensions install https://github.com/mksglu/context-mode --auto-update"
365
+ codex: "codex plugin marketplace upgrade context-mode",
366
+ gemini: "gemini extensions update context-mode",
367
+ qwen: "qwen extensions update context-mode",
368
+ pi: "pi update --extensions",
369
+ opencode: "opencode plugin update",
370
+ "copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
371
+ vscode: "npm i -g context-mode && context-mode setup --agents vscode",
372
+ kiro: "npm i -g context-mode && context-mode setup --agents kiro",
373
+ zcode: "npm i -g context-mode && context-mode setup --agents zcode"
364
374
  });
365
375
  var V1_SCRIPT_NAMES = Object.freeze([
366
376
  "afteragentresponse.mjs",
@@ -380,12 +390,16 @@ var V1_SCRIPT_NAMES = Object.freeze([
380
390
  ]);
381
391
  var V1_CODEX_HOOKS_DIR = Object.freeze(["hooks", "codex"]);
382
392
  var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
393
+ var V1_PI_PACKAGE = "npm:context-mode";
383
394
  var VSCODE_USER_DIR_SEGMENTS = Object.freeze(["Code", "User"]);
384
395
  var VSCODE_MCP_FILE = "mcp.json";
385
396
  var KIRO_AGENT_FILE = Object.freeze(["agents", "default.json"]);
386
397
  var KIRO_STEERING_FILE = Object.freeze(["steering", "KIRO.md"]);
387
398
  var OPENCODE_CONFIG_FILES = Object.freeze(["opencode.jsonc", "opencode.json"]);
388
399
  var OPENCODE_NPM_SPEC_PREFIX = `${SERVER_KEY}@`;
400
+ var NPM_VERSION_SEP = "@";
401
+ var OPENCODE_NPM_LATEST = `${OPENCODE_NPM_SPEC_PREFIX}latest`;
402
+ var PI_NPM_LATEST = `${V1_PI_PACKAGE}${NPM_VERSION_SEP}latest`;
389
403
  var V1_DATA_ROOT_ENTRIES = Object.freeze(["content", "platform.json"]);
390
404
  var PI_ROLE = "custom";
391
405
  var V1_PATH_SEPS = Object.freeze(["/", "\\"]);
@@ -406,13 +420,17 @@ var V1_REASON = Object.freeze({
406
420
  kiroSteering: "old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",
407
421
  piNpm: "old context-mode Pi package npm:context-mode",
408
422
  opencodePlugin: "old context-mode OpenCode plugin spec context-mode",
423
+ piGit: "old context-mode Pi entry git:github.com/mksglu/context-mode@release: ctx_upgrade replaces it with npm:context-mode@latest",
424
+ opencodeGit: "old context-mode OpenCode entry git+https://github.com/mksglu/context-mode.git#release: ctx_upgrade replaces it with context-mode@latest",
409
425
  zcodeHook: "old context-mode ZCode hook entry: command contains context-mode hook",
410
426
  dataDir: "old context-mode data dir <agent home>/context-mode/",
411
427
  dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
412
428
  dataRoot: "old context-mode content under ~/.context-mode/",
413
- tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
429
+ tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep",
430
+ projectLink: "context-mode path in the project reached through a link: report only, upgrade keeps it as is and never follows a link"
414
431
  });
415
- var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
432
+ var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering, V1_REASON.piGit, V1_REASON.opencodeGit, V1_REASON.projectLink]);
433
+ var UPGRADE_KEEP_ASIDE_REASONS = Object.freeze([V1_REASON.dataDir, V1_REASON.dataRoot]);
416
434
  var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
417
435
  var OPENCODE_PLUGIN_PATH = Object.freeze(["opencode", "plugin.js"]);
418
436
  var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
@@ -498,13 +516,13 @@ var NATIVE_INSTALL = Object.freeze({
498
516
  "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
499
517
  vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
500
518
  kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
501
- zcode: ["npm i -g context-mode", "context-mode setup --agents zcode"]
519
+ zcode: ["zcode plugins marketplace add mksglu/context-mode", "zcode plugins install context-mode@context-mode"]
502
520
  });
503
521
  var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
504
522
 
505
523
  // src/core/tools/run-wrapper.ts
506
524
  import { randomUUID } from "node:crypto";
507
- import { dirname as dirname4, join as join5 } from "node:path";
525
+ import { dirname as dirname4, join as join6 } from "node:path";
508
526
 
509
527
  // src/adapters/claude-code.ts
510
528
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -721,6 +739,7 @@ var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
721
739
  var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
722
740
  var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
723
741
  var EMPTY = { stdout: "", exitCode: 0 };
742
+ var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
724
743
  function own(p, key) {
725
744
  return Object.hasOwn(p, key) ? p[key] : void 0;
726
745
  }
@@ -740,13 +759,67 @@ function canonicalName2(name, mcp) {
740
759
  if (typeof server !== "string" || typeof tool !== "string") return name;
741
760
  return "mcp:" + server + ":" + tool;
742
761
  }
762
+ function partsText(llm) {
763
+ if (!Array.isArray(llm) || llm.length === 0) return void 0;
764
+ const out = [];
765
+ for (const part of llm) {
766
+ if (typeof part === "string") {
767
+ out.push(part);
768
+ continue;
769
+ }
770
+ if (typeof part !== "object" || part === null) return void 0;
771
+ const t = own(part, "text");
772
+ if (typeof t !== "string") return void 0;
773
+ out.push(t);
774
+ }
775
+ return out.join("");
776
+ }
743
777
  function readResult2(resp) {
744
778
  const obj = typeof resp === "object" && resp !== null ? resp : void 0;
745
779
  const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
746
- const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : JSON.stringify(resp);
780
+ const text = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
747
781
  const err = obj === void 0 ? void 0 : own(obj, "error");
748
782
  return { isError: err !== void 0 && err !== null, bytes: Buffer.byteLength(text), text };
749
783
  }
784
+ var URL_STARTS = ["https://", "http://"];
785
+ var URL_TRAIL = `.,;:!?)]}>'"`;
786
+ var SPACE = " \n\r\f\v";
787
+ function words(text) {
788
+ const out = [];
789
+ let cur = "";
790
+ for (const ch of text) {
791
+ if (SPACE.includes(ch)) {
792
+ if (cur !== "") out.push(cur);
793
+ cur = "";
794
+ } else cur += ch;
795
+ }
796
+ if (cur !== "") out.push(cur);
797
+ return out;
798
+ }
799
+ function firstUrl(prompt) {
800
+ if (typeof prompt !== "string") return void 0;
801
+ for (const word of words(prompt)) {
802
+ const lower = word.toLowerCase();
803
+ const at2 = URL_STARTS.map((s) => lower.indexOf(s)).filter((i) => i >= 0).sort((a, b) => a - b)[0];
804
+ if (at2 === void 0) continue;
805
+ let url = word.slice(at2);
806
+ while (url.length > 0 && URL_TRAIL.includes(url[url.length - 1])) url = url.slice(0, -1);
807
+ return url;
808
+ }
809
+ return void 0;
810
+ }
811
+ function nativeInput(name, input) {
812
+ if (name === "web_fetch" && own(input, "url") === void 0) {
813
+ const url = firstUrl(own(input, "prompt"));
814
+ return url === void 0 ? input : { ...input, url };
815
+ }
816
+ if (name === "read_many_files" && own(input, "file_path") === void 0) {
817
+ const inc = own(input, "include");
818
+ const list2 = Array.isArray(inc) ? inc.filter((v) => typeof v === "string") : [];
819
+ return list2.length === 0 ? input : { ...input, file_path: list2.join(" ") };
820
+ }
821
+ return input;
822
+ }
750
823
  function decode3(raw) {
751
824
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("gemini: hook payload is not a JSON object");
752
825
  const p = raw;
@@ -764,7 +837,7 @@ function decode3(raw) {
764
837
  ev.tool = {
765
838
  name,
766
839
  canonicalName: canonicalName2(name, own(p, "mcp_context")),
767
- input: typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
840
+ input: nativeInput(name, typeof input === "object" && input !== null && !Array.isArray(input) ? input : {})
768
841
  };
769
842
  }
770
843
  if (event === "PostToolUse") ev.result = readResult2(own(p, "tool_response"));
@@ -782,7 +855,7 @@ function encode3(ev, d, _extra) {
782
855
  return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
783
856
  case "replace":
784
857
  if (ev.event !== "PostToolUse") return EMPTY;
785
- return { stdout: JSON.stringify({ decision: "deny", reason: d.output }), exitCode: 0 };
858
+ return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
786
859
  }
787
860
  }
788
861
 
@@ -843,6 +916,14 @@ function canonicalName3(name) {
843
916
  if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
844
917
  return name;
845
918
  }
919
+ var isNum = (v) => typeof v === "number" && Number.isFinite(v);
920
+ function viewRange(name, input) {
921
+ const r = input.view_range;
922
+ if (name !== "view" || !Array.isArray(r) || !isNum(r[0])) return input;
923
+ const out = { ...input, offset: r[0] };
924
+ if (isNum(r[1]) && r[1] >= r[0]) out.limit = r[1] - r[0] + 1;
925
+ return out;
926
+ }
846
927
  function readArgs(v) {
847
928
  if (isRecord(v)) return v;
848
929
  if (typeof v !== "string") return {};
@@ -887,7 +968,7 @@ function decode5(raw) {
887
968
  if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
888
969
  if (event === "PreToolUse" || event === "PostToolUse") {
889
970
  const toolName = String(raw[k.tool] ?? "");
890
- const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: readArgs(raw[k.args]) };
971
+ const tool = { name: toolName, canonicalName: canonicalName3(toolName), input: viewRange(toolName, readArgs(raw[k.args])) };
891
972
  ev.tool = tool;
892
973
  }
893
974
  if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
@@ -935,18 +1016,18 @@ function canonicalName4(name) {
935
1016
  if (sep3 <= 0 || sep3 === rest.length - 1) return name;
936
1017
  return "mcp:" + rest.slice(0, sep3) + ":" + rest.slice(sep3 + MCP_SEP2.length);
937
1018
  }
938
- var isNum = (v) => typeof v === "number" && Number.isFinite(v);
1019
+ var isNum2 = (v) => typeof v === "number" && Number.isFinite(v);
939
1020
  function policyInput(name, canonical, input) {
940
1021
  if (canonical === "Read" && READ_TOOL_NAMES.includes(name)) {
941
1022
  const out = { ...input };
942
1023
  if (name === "read_file") {
943
1024
  if (typeof input.filePath === "string") out.file_path = input.filePath;
944
- if (isNum(input.startLine)) out.offset = input.startLine;
945
- if (isNum(input.startLine) && isNum(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
946
- } else if (Array.isArray(input.view_range) && isNum(input.view_range[0])) {
1025
+ if (isNum2(input.startLine)) out.offset = input.startLine;
1026
+ if (isNum2(input.startLine) && isNum2(input.endLine) && input.endLine >= input.startLine) out.limit = input.endLine - input.startLine + 1;
1027
+ } else if (Array.isArray(input.view_range) && isNum2(input.view_range[0])) {
947
1028
  out.offset = input.view_range[0];
948
1029
  const end = input.view_range[1];
949
- if (isNum(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
1030
+ if (isNum2(end) && end >= input.view_range[0]) out.limit = end - input.view_range[0] + 1;
950
1031
  }
951
1032
  return out;
952
1033
  }
@@ -1107,6 +1188,7 @@ function encode7(ev, d, _extra) {
1107
1188
 
1108
1189
  // src/adapters/zcode.ts
1109
1190
  var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1191
+ var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1110
1192
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1111
1193
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1112
1194
  var FAILURE_EVENT2 = "PostToolUseFailure";
@@ -1116,7 +1198,9 @@ function decode8(raw) {
1116
1198
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1117
1199
  const failure = p.hook_event_name === FAILURE_EVENT2;
1118
1200
  if (failure) p.hook_event_name = "PostToolUse";
1119
- const ev = decodeClaudeShape(p, "zcode", TOOL_NAME_PREFIX8, ZCODE_SOURCES);
1201
+ const toolName = typeof p.tool_name === "string" ? p.tool_name : "";
1202
+ const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
1203
+ const ev = decodeClaudeShape(p, "zcode", prefix, ZCODE_SOURCES);
1120
1204
  if (failure) {
1121
1205
  const text = typeof p.error === "string" ? p.error : p.error === void 0 ? "" : JSON.stringify(p.error);
1122
1206
  ev.result = { isError: true, bytes: Buffer.byteLength(text), text };
@@ -1197,8 +1281,9 @@ var OPENCODE_EVENTS = {
1197
1281
  "step-finish": "Usage"
1198
1282
  };
1199
1283
  var SHELL_TOOL_NAME = "bash";
1284
+ var READ_TOOL_NAME = "read";
1200
1285
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1201
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1286
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1202
1287
  function toCanonicalTool(name) {
1203
1288
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1204
1289
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1426,9 +1511,9 @@ var ADAPTERS = Object.freeze([
1426
1511
  installMode: "in-process",
1427
1512
  projectSource: "spawn-cwd",
1428
1513
  toolNamePrefix: TOOL_NAME_PREFIX10,
1429
- nativeTools: { shell: [SHELL_TOOL_NAME] },
1514
+ nativeTools: { shell: [SHELL_TOOL_NAME], read: [READ_TOOL_NAME] },
1430
1515
  execReadOnlyHint: false,
1431
- // D-HF-OPENCODE-SHELL-1
1516
+ // D-HF-OPENCODE-SHELL-1, D-R44-OC-READ-1
1432
1517
  // Usage: step-finish cost row (DEVIATIONS D-M5-arch-2).
1433
1518
  eventMap: { SessionStart: "context", UserPromptSubmit: "prompt", PreToolUse: "execute.before", PostToolUse: "execute.after", PreCompact: "compaction", Usage: "step-finish" },
1434
1519
  compactDelivery: "opencode-cache",
@@ -1656,6 +1741,15 @@ function applyMigrations(db, fromVersion) {
1656
1741
  }
1657
1742
  }
1658
1743
 
1744
+ // src/core/store/open-read.ts
1745
+ function openReadOnlyHandle(sqlite, path3, opts = {}) {
1746
+ const bun = "bun" in opts ? opts.bun : process.versions.bun;
1747
+ if (bun === void 0) return new sqlite.DatabaseSync(path3, { timeout: DB_TIMEOUT_MS, readOnly: true });
1748
+ const raw = new sqlite.DatabaseSync(path3, { timeout: DB_TIMEOUT_MS });
1749
+ if (opts.queryOnly !== false) raw.exec("PRAGMA query_only = ON");
1750
+ return raw;
1751
+ }
1752
+
1659
1753
  // src/core/store/db.ts
1660
1754
  var { existsSync, linkSync, mkdirSync, rmSync } = process.getBuiltinModule("node:fs");
1661
1755
  function versionParts(v) {
@@ -1721,7 +1815,7 @@ function openWritable(sqlite, path3) {
1721
1815
  }
1722
1816
  }
1723
1817
  function openReadOnly(sqlite, path3) {
1724
- const raw = new sqlite.DatabaseSync(path3, { timeout: DB_TIMEOUT_MS, readOnly: true });
1818
+ const raw = openReadOnlyHandle(sqlite, path3);
1725
1819
  try {
1726
1820
  const found = readUserVersion(raw);
1727
1821
  if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
@@ -3432,18 +3526,18 @@ function insertChunks(db, id, src, chunks) {
3432
3526
  }
3433
3527
  }
3434
3528
  function toMatch(q) {
3435
- const words = [];
3529
+ const words2 = [];
3436
3530
  let cur = "";
3437
3531
  for (const ch of q) {
3438
3532
  if (ch.trim() === "" || ch === "\0") {
3439
- if (cur !== "") words.push(cur);
3533
+ if (cur !== "") words2.push(cur);
3440
3534
  cur = "";
3441
3535
  } else {
3442
3536
  cur += ch === '"' ? '""' : ch;
3443
3537
  }
3444
3538
  }
3445
- if (cur !== "") words.push(cur);
3446
- return words.map((w) => `"${w}"*`).join(" ");
3539
+ if (cur !== "") words2.push(cur);
3540
+ return words2.map((w) => `"${w}"*`).join(" ");
3447
3541
  }
3448
3542
  function toMatchAny(q) {
3449
3543
  const terms = new Set(toMatch(q).split(" ").filter((t) => t !== ""));
@@ -4071,6 +4165,9 @@ var SUBSHELL_CLOSE = ")";
4071
4165
  var CASE_BREAK = ";;";
4072
4166
  var FUNC_PARENS = ["(", ")"];
4073
4167
  var NOT = "!";
4168
+ function append(out, items) {
4169
+ for (const x of items) out.push(x);
4170
+ }
4074
4171
  var KW = Object.freeze({
4075
4172
  group: "{",
4076
4173
  groupEnd: "}",
@@ -4250,12 +4347,12 @@ function ifBody(p) {
4250
4347
  const t = at(p);
4251
4348
  if (isWord(t, KW.then) || isWord(t, KW.else)) {
4252
4349
  p.i++;
4253
- out.push(...list(p, [KW.elif, KW.else, KW.fi]));
4350
+ append(out, list(p, [KW.elif, KW.else, KW.fi]));
4254
4351
  continue;
4255
4352
  }
4256
4353
  if (isWord(t, KW.elif)) {
4257
4354
  p.i++;
4258
- out.push(...list(p, [KW.then]));
4355
+ append(out, list(p, [KW.then]));
4259
4356
  continue;
4260
4357
  }
4261
4358
  if (isWord(t, KW.fi)) p.i++;
@@ -4266,7 +4363,7 @@ function ifBody(p) {
4266
4363
  function loopBody(p) {
4267
4364
  p.i++;
4268
4365
  const out = list(p, [KW.do]);
4269
- out.push(...doBlock(p));
4366
+ append(out, doBlock(p));
4270
4367
  return out;
4271
4368
  }
4272
4369
  function forBody(p) {
@@ -4280,10 +4377,10 @@ function forBody(p) {
4280
4377
  p.i++;
4281
4378
  const from = p.i;
4282
4379
  while ((at(p)?.kind === "word" || at(p)?.kind === "unhandled") && !isWord(at(p), KW.do)) p.i++;
4283
- out.push(...carrierOf(p, from, p.i));
4380
+ append(out, carrierOf(p, from, p.i));
4284
4381
  }
4285
4382
  }
4286
- out.push(...doBlock(p));
4383
+ append(out, doBlock(p));
4287
4384
  return out;
4288
4385
  }
4289
4386
  function caseBody(p) {
@@ -4292,7 +4389,7 @@ function caseBody(p) {
4292
4389
  const subject = at(p);
4293
4390
  if (subject !== void 0 && subject.kind !== "op" && subject.kind !== "io") {
4294
4391
  p.i++;
4295
- out.push(...carrierOf(p, p.i - 1, p.i));
4392
+ append(out, carrierOf(p, p.i - 1, p.i));
4296
4393
  }
4297
4394
  if (isWord(at(p), KW.in)) p.i++;
4298
4395
  while (p.i < p.toks.length && p.err === null) {
@@ -4315,7 +4412,7 @@ function caseBody(p) {
4315
4412
  p.i++;
4316
4413
  const body = list(p, [KW.esac]);
4317
4414
  tag(body, KW.case);
4318
- out.push(...body);
4415
+ append(out, body);
4319
4416
  }
4320
4417
  return out;
4321
4418
  }
@@ -4330,7 +4427,7 @@ function hasFuncParens(p, from) {
4330
4427
  }
4331
4428
  function simple(p) {
4332
4429
  const first = p.i;
4333
- const words = [];
4430
+ const words2 = [];
4334
4431
  let toFile = false;
4335
4432
  while (p.i < p.toks.length) {
4336
4433
  const t = p.toks[p.i];
@@ -4339,7 +4436,7 @@ function simple(p) {
4339
4436
  toFile = ioRedirect(p) || toFile;
4340
4437
  continue;
4341
4438
  }
4342
- if (words.length === 0 && t.kind === "word" && isAssignment(t.text)) {
4439
+ if (words2.length === 0 && t.kind === "word" && isAssignment(t.text)) {
4343
4440
  p.i++;
4344
4441
  const open = at(p);
4345
4442
  if (t.text.endsWith(OPT_VALUE) && open !== void 0 && isOp(open, SUBSHELL_OPEN) && open.start === t.end) {
@@ -4353,15 +4450,15 @@ function simple(p) {
4353
4450
  }
4354
4451
  continue;
4355
4452
  }
4356
- words.push(t);
4453
+ words2.push(t);
4357
4454
  p.i++;
4358
4455
  }
4359
4456
  if (p.i === first) return EMPTY3();
4360
4457
  const raw = p.src.slice(p.toks[first].start, p.toks[p.i - 1].end);
4361
- if (words.length === 0) return { cmds: carrier(raw), simple: null };
4458
+ if (words2.length === 0) return { cmds: carrier(raw), simple: null };
4362
4459
  const text = (t) => t.kind === "word" ? dequote(t.text) : t.text;
4363
- const argv0 = baseName(text(words[0]));
4364
- const args = words.slice(1).map(text);
4460
+ const argv0 = baseName(text(words2[0]));
4461
+ const args = words2.slice(1).map(text);
4365
4462
  const cmd = { argv0, args, redirectsToFile: toFile || writesFile(argv0, args), endsInBoundedSink: false, raw };
4366
4463
  return { cmds: [cmd], simple: cmd };
4367
4464
  }
@@ -4432,7 +4529,7 @@ function pipeline(p) {
4432
4529
  let last = EMPTY3();
4433
4530
  while (p.err === null) {
4434
4531
  last = element(p);
4435
- all.push(...last.cmds);
4532
+ append(all, last.cmds);
4436
4533
  const t = at(p);
4437
4534
  if (t !== void 0 && t.kind === "op" && PIPES.includes(t.text)) {
4438
4535
  for (const c of last.cmds) c.pipesOut = true;
@@ -4461,7 +4558,7 @@ function list(p, stop) {
4461
4558
  }
4462
4559
  if (t.kind === "word" && stop.includes(t.text)) return out;
4463
4560
  const before = p.i;
4464
- out.push(...pipeline(p));
4561
+ append(out, pipeline(p));
4465
4562
  if (p.i === before && p.err === null) p.i++;
4466
4563
  }
4467
4564
  return out;
@@ -4474,7 +4571,7 @@ function parseShell(cmd) {
4474
4571
  const p = { toks: s.tokens, src: cmd, bodies: new Set(s.heredocBodies), i: 0, depth: 0, err: null };
4475
4572
  const commands = [];
4476
4573
  while (p.i < p.toks.length && p.err === null) {
4477
- commands.push(...list(p, NO_STOP));
4574
+ append(commands, list(p, NO_STOP));
4478
4575
  if (p.i < p.toks.length) p.i++;
4479
4576
  }
4480
4577
  if (p.err !== null) return { ok: false, construct: p.err };
@@ -4729,57 +4826,57 @@ function param(word, names) {
4729
4826
  const hits = names.filter((p) => p.startsWith(name));
4730
4827
  return { full: hits.length === 1 ? hits[0] : void 0, inline };
4731
4828
  }
4732
- function psDump(words) {
4733
- if (words.length === 0) return null;
4734
- const name = cmdName(words[0]);
4829
+ function psDump(words2) {
4830
+ if (words2.length === 0) return null;
4831
+ const name = cmdName(words2[0]);
4735
4832
  if (!READ_COMMANDS.includes(name)) {
4736
- const lower = words[0].toLowerCase();
4833
+ const lower = words2[0].toLowerCase();
4737
4834
  const cls = FILE_CLASSES.find((c) => lower.startsWith(c));
4738
- if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words.length < MIN_STATIC_CALL) return null;
4739
- return { file: words[1], bounded: false };
4835
+ if (cls === void 0 || !FILE_READS.includes(lower.slice(cls.length)) || words2.length < MIN_STATIC_CALL) return null;
4836
+ return { file: words2[1], bounded: false };
4740
4837
  }
4741
4838
  const files = [];
4742
4839
  let bounded = false;
4743
- for (let k = 1; k < words.length; k++) {
4744
- const a = words[k];
4840
+ for (let k = 1; k < words2.length; k++) {
4841
+ const a = words2[k];
4745
4842
  if (!a.startsWith(DASH) || a.length === DASH.length) {
4746
4843
  files.push(a);
4747
4844
  continue;
4748
4845
  }
4749
4846
  const p = param(a, ALL_PARAMS);
4750
4847
  if (p.full === void 0 || !VALUE_PARAMS.includes(p.full)) continue;
4751
- const value = p.inline ?? words[++k];
4848
+ const value = p.inline ?? words2[++k];
4752
4849
  if (value === void 0) return null;
4753
4850
  if (PATH_PARAMS.includes(p.full)) files.push(value);
4754
4851
  if (BOUND_PARAMS.includes(p.full)) bounded = true;
4755
4852
  }
4756
4853
  return files.length === 1 ? { file: files[0], bounded } : null;
4757
4854
  }
4758
- function nestedScript(name, words) {
4855
+ function nestedScript(name, words2) {
4759
4856
  if (POWERSHELLS.includes(name)) {
4760
- for (let k = 1; k < words.length; k++) {
4761
- const w = words[k];
4857
+ for (let k = 1; k < words2.length; k++) {
4858
+ const w = words2[k];
4762
4859
  if (!w.startsWith(DASH) || w.length === DASH.length) continue;
4763
4860
  const p = param(w, [COMMAND_PARAM]);
4764
4861
  if (p.full === void 0) continue;
4765
- return [...p.inline === void 0 ? [] : [p.inline], ...words.slice(k + 1)].join(" ");
4862
+ return [...p.inline === void 0 ? [] : [p.inline], ...words2.slice(k + 1)].join(" ");
4766
4863
  }
4767
4864
  return null;
4768
4865
  }
4769
4866
  if (CMDS.includes(name)) {
4770
- for (let k = 1; k < words.length; k++) {
4771
- if (CMD_RUN_FLAGS.includes(words[k].toLowerCase())) return words.slice(k + 1).join(" ");
4867
+ for (let k = 1; k < words2.length; k++) {
4868
+ if (CMD_RUN_FLAGS.includes(words2[k].toLowerCase())) return words2.slice(k + 1).join(" ");
4772
4869
  }
4773
4870
  }
4774
4871
  return null;
4775
4872
  }
4776
- function cdTarget(words) {
4777
- for (let k = 1; k < words.length; k++) {
4778
- const w = words[k];
4873
+ function cdTarget(words2) {
4874
+ for (let k = 1; k < words2.length; k++) {
4875
+ const w = words2[k];
4779
4876
  if (w.toLowerCase() === "/d") continue;
4780
4877
  if (!w.startsWith(DASH) || w.length === DASH.length) return w;
4781
4878
  const p = param(w, PATH_PARAMS);
4782
- if (p.full !== void 0) return p.inline ?? words[k + 1] ?? null;
4879
+ if (p.full !== void 0) return p.inline ?? words2[k + 1] ?? null;
4783
4880
  }
4784
4881
  return null;
4785
4882
  }
@@ -4839,8 +4936,13 @@ function requireHomeDir(env, platform = process.platform) {
4839
4936
  if (home !== null) return home;
4840
4937
  throw new CtxError("NO_HOME", { name: platform === "win32" ? "USERPROFILE" : "HOME" });
4841
4938
  }
4939
+ function dataRootOf(env, home) {
4940
+ const dir = env[DATA_DIR_ENV];
4941
+ return dir !== void 0 && dir !== "" ? resolve2(dir) : join(home, DATA_ROOT.slice(1));
4942
+ }
4842
4943
  function resolveConfigDir(env) {
4843
- const dir = join(requireHomeDir(env), DATA_ROOT.slice(1));
4944
+ const set = env[DATA_DIR_ENV];
4945
+ const dir = dataRootOf(env, set !== void 0 && set !== "" ? "" : requireHomeDir(env));
4844
4946
  mkdirSync2(dir, { recursive: true });
4845
4947
  return realpathSync.native(dir);
4846
4948
  }
@@ -5007,14 +5109,13 @@ function tokenize(glob, path3) {
5007
5109
  }
5008
5110
  return toks;
5009
5111
  }
5010
- function globMatch(glob, text, path3) {
5011
- const toks = tokenize(glob, path3);
5112
+ function matchStarts(toks, text, path3, ends) {
5012
5113
  const n = text.length;
5013
- let next = new Uint8Array(n + 1);
5014
- next[n] = 1;
5114
+ let next = ends;
5115
+ let cur = new Uint8Array(n + 1);
5015
5116
  for (let i = toks.length - 1; i >= 0; i--) {
5016
5117
  const tok = toks[i];
5017
- const cur = new Uint8Array(n + 1);
5118
+ if (next === ends) next = Uint8Array.from(ends);
5018
5119
  let acc = 0;
5019
5120
  for (let j = n; j >= 0; j--) {
5020
5121
  const has2 = j < n;
@@ -5038,9 +5139,19 @@ function globMatch(glob, text, path3) {
5038
5139
  break;
5039
5140
  }
5040
5141
  }
5041
- next = cur;
5142
+ const done = cur;
5143
+ cur = next;
5144
+ next = done;
5042
5145
  }
5043
- return next[0] === 1;
5146
+ return next;
5147
+ }
5148
+ function globMatch(glob, text, path3) {
5149
+ const toks = tokenize(glob, path3);
5150
+ const first = toks[0];
5151
+ if (first !== void 0 && first.t === "lit" && text[0] !== first.c) return false;
5152
+ const ends = new Uint8Array(text.length + 1);
5153
+ ends[text.length] = 1;
5154
+ return matchStarts(toks, text, path3, ends)[0] === 1;
5044
5155
  }
5045
5156
  function parsePattern(pattern) {
5046
5157
  const open = pattern.indexOf("(");
@@ -5048,14 +5159,25 @@ function parsePattern(pattern) {
5048
5159
  const glob = pattern.slice(open + 1, pattern.length - ")".length);
5049
5160
  return glob === "" ? null : { tool: pattern.slice(0, open), glob };
5050
5161
  }
5162
+ function commandStarts(glob, text) {
5163
+ const n = text.length;
5164
+ const ends = new Uint8Array(n + 1);
5165
+ ends[n] = 1;
5166
+ if (!glob.endsWith(PREFIX_RULE)) return matchStarts(tokenize(glob, false), text, false, ends);
5167
+ for (let k = 0; k < n; k++) if (WHITESPACE.includes(text[k])) ends[k] = 1;
5168
+ return matchStarts(tokenize(glob.slice(0, glob.length - PREFIX_RULE.length), false), text, false, ends);
5169
+ }
5051
5170
  function matchCommand(glob, text) {
5052
- if (!glob.endsWith(PREFIX_RULE)) return globMatch(glob, text, false);
5053
- const head = glob.slice(0, glob.length - PREFIX_RULE.length);
5054
- if (globMatch(head, text, false)) return true;
5055
- for (let k = 0; k < text.length; k++) {
5056
- if (WHITESPACE.includes(text[k]) && globMatch(head, text.slice(0, k), false)) return true;
5171
+ return commandStarts(glob, text)[0] === 1;
5172
+ }
5173
+ function denyPatternFromAny(text, patterns, from) {
5174
+ for (const pattern of patterns) {
5175
+ const p = parsePattern(pattern);
5176
+ if (p === null || p.tool !== BASH_TOOL) continue;
5177
+ const starts = commandStarts(p.glob, text);
5178
+ for (let j = 0; j <= text.length; j++) if (from[j] === 1 && starts[j] === 1) return pattern;
5057
5179
  }
5058
- return false;
5180
+ return null;
5059
5181
  }
5060
5182
  var DRIVE_PREFIX = /^[A-Za-z]:(?=\/)/;
5061
5183
  function toSlash(p) {
@@ -5126,6 +5248,7 @@ var HOST_SEP = ".";
5126
5248
  var SED_RANGE_SEP = ",";
5127
5249
  var SED_PRINT = "p";
5128
5250
  var SED_SCRIPT_FLAGS = ["-e", "--expression"];
5251
+ var EXE_SUFFIX = ".exe";
5129
5252
  var COMMAND_STARTS = ";&|(`\n\r";
5130
5253
  var ALLOW = Object.freeze({ kind: "allow" });
5131
5254
  var deny = (reason) => ({ kind: "deny", reason });
@@ -5163,6 +5286,11 @@ function readPath(input) {
5163
5286
  }
5164
5287
  return void 0;
5165
5288
  }
5289
+ function readPaths(input) {
5290
+ const one = readPath(input);
5291
+ const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((p) => typeof p === "string" && p !== "") : [];
5292
+ return one === void 0 ? many : [one, ...many];
5293
+ }
5166
5294
  function userDenyHit(canonical, input, cwd, rules) {
5167
5295
  if (rules.length === 0) return null;
5168
5296
  const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
@@ -5171,35 +5299,65 @@ function userDenyHit(canonical, input, cwd, rules) {
5171
5299
  return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
5172
5300
  }
5173
5301
  if (canonical === READ) {
5174
- const p = readPath(input);
5175
- return p === void 0 ? null : readRule(p);
5302
+ for (const p of readPaths(input)) {
5303
+ const h = readRule(p);
5304
+ if (h !== null) return h;
5305
+ }
5306
+ return null;
5176
5307
  }
5177
5308
  if (canonical === CTX_EXECUTE) {
5178
5309
  const file = str(input.file);
5179
5310
  const byFile = file === void 0 || file === "" ? null : readRule(file);
5180
5311
  if (byFile !== null) return byFile;
5181
5312
  const code = str(input.code);
5182
- return input.language === SHELL_LANGUAGE && code !== void 0 ? matchesAnyDenyPattern(code, rules) : null;
5313
+ return isShellLanguage(input.language) && code !== void 0 ? shellHit(code, rules) : null;
5183
5314
  }
5184
5315
  if (canonical === CTX_BATCH && Array.isArray(input.commands)) {
5185
5316
  for (const c of input.commands) {
5186
- const h = typeof c === "string" ? matchesAnyDenyPattern(c, rules) : null;
5317
+ const h = typeof c === "string" ? shellHit(c, rules) : null;
5187
5318
  if (h !== null) return h;
5188
5319
  }
5189
5320
  }
5190
5321
  return null;
5191
5322
  }
5323
+ function isShellLanguage(language) {
5324
+ if (typeof language !== "string") return false;
5325
+ let name = language.toLowerCase();
5326
+ const slash = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
5327
+ if (slash >= 0) name = name.slice(slash + 1);
5328
+ if (name.endsWith(EXE_SUFFIX)) name = name.slice(0, name.length - EXE_SUFFIX.length);
5329
+ return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
5330
+ }
5331
+ function shellHit(cmd, rules) {
5332
+ const whole = matchesAnyDenyPattern(cmd, rules);
5333
+ if (whole !== null) return whole;
5334
+ const parsed = parseShell(cmd);
5335
+ if (!parsed.ok) return couldMatchRule(cmd, rules);
5336
+ for (const c of unwrap(parsed.commands)) {
5337
+ const h = segmentHit(c, rules);
5338
+ if (h !== null) return h;
5339
+ }
5340
+ return null;
5341
+ }
5192
5342
  function segmentHit(c, rules) {
5193
5343
  if (rules.length === 0) return null;
5194
5344
  return matchesAnyDenyPattern([c.argv0, ...c.args].join(" "), rules) ?? matchesAnyDenyPattern(c.raw, rules);
5195
5345
  }
5196
- function couldMatch(text, rules) {
5197
- if (rules.length === 0) return false;
5346
+ function couldMatchRule(text, rules) {
5347
+ if (rules.length === 0) return null;
5348
+ const from = new Uint8Array(text.length + 1);
5349
+ let pending = false;
5198
5350
  for (let k = 0; k <= text.length; k++) {
5199
- if (k > 0 && !COMMAND_STARTS.includes(text.charAt(k - 1))) continue;
5200
- if (matchesAnyDenyPattern(text.slice(k).trimStart(), rules) !== null) return true;
5351
+ if (k === 0 || COMMAND_STARTS.includes(text.charAt(k - 1))) pending = true;
5352
+ if (pending && (k === text.length || text.charAt(k).trim() !== "")) {
5353
+ from[k] = 1;
5354
+ pending = false;
5355
+ }
5201
5356
  }
5202
- return false;
5357
+ return denyPatternFromAny(text, rules, from);
5358
+ }
5359
+ function couldMatch(text, rules) {
5360
+ return couldMatchRule(text, rules) !== null;
5203
5361
  }
5204
5362
  function neverDenied(url) {
5205
5363
  let host;
@@ -5274,8 +5432,7 @@ function fileSize(abs) {
5274
5432
  }
5275
5433
  function read(ev, row, input) {
5276
5434
  if (!present(input.offset) && !present(input.limit)) {
5277
- const p = readPath(input);
5278
- if (p !== void 0) {
5435
+ for (const p of readPaths(input)) {
5279
5436
  const abs = resolve3(ev.cwd, p);
5280
5437
  const size = fileSize(abs);
5281
5438
  if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row.toolNamePrefix));
@@ -5369,11 +5526,11 @@ function dumpTarget(name, args) {
5369
5526
  }
5370
5527
 
5371
5528
  // src/core/project/resolve.ts
5372
- import { basename as basename2, dirname as dirname3, join as join4, resolve as resolve4 } from "node:path";
5529
+ import { basename as basename2, dirname as dirname3, join as join5, resolve as resolve4 } from "node:path";
5373
5530
 
5374
5531
  // src/core/project/contain.ts
5375
- import { dirname as dirname2, sep as sep2 } from "node:path";
5376
- var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
5532
+ import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
5533
+ var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
5377
5534
  function real(p) {
5378
5535
  try {
5379
5536
  return realpathSync2.native(p);
@@ -5561,9 +5718,9 @@ function gitDirs(dir) {
5561
5718
  }
5562
5719
  const start = cur;
5563
5720
  for (; ; ) {
5564
- const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
5721
+ const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
5565
5722
  if (gitDir !== null) {
5566
- const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
5723
+ const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
5567
5724
  return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
5568
5725
  }
5569
5726
  const up = dirname3(cur);
@@ -5584,7 +5741,7 @@ function gitDirAt(dotGit) {
5584
5741
  } catch {
5585
5742
  return null;
5586
5743
  }
5587
- return existsSync2(join4(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
5744
+ return existsSync2(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
5588
5745
  }
5589
5746
  function firstLine(file) {
5590
5747
  let text;
@@ -5625,11 +5782,11 @@ function resolveProject(agent, src) {
5625
5782
  return key;
5626
5783
  },
5627
5784
  get projectDir() {
5628
- pdir ??= join4(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
5785
+ pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
5629
5786
  return pdir;
5630
5787
  },
5631
5788
  get dbPath() {
5632
- return join4(this.projectDir, DB_FILE_NAME);
5789
+ return join5(this.projectDir, DB_FILE_NAME);
5633
5790
  },
5634
5791
  worktree,
5635
5792
  get containmentRoot() {
@@ -6121,7 +6278,7 @@ function cutPoint(src, start, end, scratch) {
6121
6278
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
6122
6279
  return { end: start + r.read, written: r.written };
6123
6280
  }
6124
- function merge(src, blocks, join6, cap, lineCut) {
6281
+ function merge(src, blocks, join7, cap, lineCut) {
6125
6282
  const out = [];
6126
6283
  const scratch = new Uint8Array(cap);
6127
6284
  let wide;
@@ -6131,7 +6288,7 @@ function merge(src, blocks, join6, cap, lineCut) {
6131
6288
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes2 });
6132
6289
  };
6133
6290
  for (const b of blocks) {
6134
- if (cur !== void 0 && !join6) {
6291
+ if (cur !== void 0 && !join7) {
6135
6292
  emit(cur.start, cur.end, curBytes);
6136
6293
  cur = void 0;
6137
6294
  }
@@ -6239,7 +6396,7 @@ function sourceLabel(command) {
6239
6396
  return Array.from(RUN_LABEL_PREFIX + first).slice(0, SOURCE_LABEL_MAX_CHARS).join("");
6240
6397
  }
6241
6398
  function moreLine2(bundleDir, sourceId, terms) {
6242
- return RUN_MORE_PREFIX + JSON.stringify(join5(bundleDir, SEARCH_WRAPPER_FILE)) + " " + sourceId + " " + JSON.stringify(terms);
6399
+ return RUN_MORE_PREFIX + JSON.stringify(join6(bundleDir, SEARCH_WRAPPER_FILE)) + " " + sourceId + " " + JSON.stringify(terms);
6243
6400
  }
6244
6401
  function bytes(s) {
6245
6402
  return Buffer.byteLength(s, "utf8");