context-mode 2.2.1 → 2.2.3

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.1"
15
+ "version": "2.2.3"
16
16
  }
package/run.mjs CHANGED
@@ -14,16 +14,9 @@ function prefixToolNames(text, prefix) {
14
14
  }
15
15
  var OUTPUT_CAP = 16384;
16
16
  var INDEX_WRITE_CHUNK = 1048576;
17
- var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
18
- var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
19
- function readReplaceTrigger(raw) {
20
- if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
21
- const n = Number(raw);
22
- return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
23
- }
24
- var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
25
17
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
26
18
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
19
+ var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
27
20
  function shellWord(s) {
28
21
  return "'" + s.split("'").join("'\\''") + "'";
29
22
  }
@@ -178,7 +171,7 @@ var SQLITE_NOTADB_CODE = 26;
178
171
  var HOOK_TIMEOUT_MS = 5e3;
179
172
  var IN_PROCESS_TIMEOUT_MS = 0;
180
173
  var PROJECT_KEY_HEX_LEN = 16;
181
- var SCHEMA_VERSION = 6;
174
+ var SCHEMA_VERSION = 7;
182
175
  var PROJECTS_DIR_NAME = "projects";
183
176
  var DB_FILE_NAME = "context.db";
184
177
  var GIT_DIR_NAME = ".git";
@@ -202,6 +195,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
202
195
  var RUN_WRAPPER_AGENT = "claude-code";
203
196
  var RUN_SESSION_PREFIX = "mcp:";
204
197
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
198
+ var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
205
199
  var NODE_MIN = "24.15.0";
206
200
  var DATA_ROOT = "~/.context-mode";
207
201
  var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
@@ -675,6 +669,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
675
669
  var POWERSHELL_TOOL = "PowerShell";
676
670
  var SHELL_CANONICAL = "Bash";
677
671
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
672
+ var FAILURE_EVENT = "PostToolUseFailure";
678
673
  var MCP_PREFIX = "mcp__";
679
674
  var MCP_SEP = "__";
680
675
  var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
@@ -848,7 +843,14 @@ function requireFields(raw) {
848
843
  }
849
844
  function decode(raw) {
850
845
  requireFields(raw);
851
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
846
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
847
+ const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
848
+ const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
849
+ if (failure) {
850
+ const error = raw.error;
851
+ const text = typeof error === "string" ? error : error === void 0 ? "" : JSON.stringify(error);
852
+ ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
853
+ }
852
854
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
853
855
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
854
856
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1027,9 +1029,9 @@ var NATIVE_TO_CANONICAL2 = {
1027
1029
  grep_search: "Grep",
1028
1030
  web_fetch: "WebFetch"
1029
1031
  };
1030
- var FAILURE_EVENT = "PostToolUseFailure";
1032
+ var FAILURE_EVENT2 = "PostToolUseFailure";
1031
1033
  function decode4(raw) {
1032
- const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1034
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
1033
1035
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1034
1036
  const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1035
1037
  if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
@@ -1349,12 +1351,12 @@ var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1349
1351
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1350
1352
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1351
1353
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1352
- var FAILURE_EVENT2 = "PostToolUseFailure";
1354
+ var FAILURE_EVENT3 = "PostToolUseFailure";
1353
1355
  function decode8(raw) {
1354
1356
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1355
1357
  const p = { ...raw };
1356
1358
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1357
- const failure = p.hook_event_name === FAILURE_EVENT2;
1359
+ const failure = p.hook_event_name === FAILURE_EVENT3;
1358
1360
  if (failure) p.hook_event_name = "PostToolUse";
1359
1361
  const toolName = typeof p.tool_name === "string" ? p.tool_name : "";
1360
1362
  const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
@@ -1445,7 +1447,8 @@ var OPENCODE_EVENTS = {
1445
1447
  var SHELL_TOOL_NAME = "bash";
1446
1448
  var READ_TOOL_NAME = "read";
1447
1449
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1448
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1450
+ var SKILL_TOOL_NAME = "skill";
1451
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1449
1452
  function toCanonicalTool(name) {
1450
1453
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1451
1454
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1745,7 +1748,8 @@ var ERROR_TEXT = Object.freeze({
1745
1748
  NO_RUNTIME: "No <lang> runtime on PATH. Fix: install it or pick another language.",
1746
1749
  FETCH_FAILED: "Fetch failed: <code>. Fix: check the URL or proxy.",
1747
1750
  SSRF: "Blocked private address <host>. Fix: use a public URL.",
1748
- OUTSIDE_ROOT: "Path <p> is outside the project. Fix: use a path inside <root>.",
1751
+ OUTSIDE_ROOT: "Path <p> is outside the project and the folders added to this session. Fix: use a path inside <root>, or add its folder to the session (Claude Code /add-dir, Codex --add-dir).",
1752
+ // #1398 D-1398-HOST-ROOTS-1
1749
1753
  INVALID_ARGS: "Invalid argument <field>. Fix: <action>.",
1750
1754
  ONE_OF_INPUT: "Pass exactly one of <names>. Fix: drop the extra field.",
1751
1755
  SPAWN_FAILED: "Failed to start the process: <detail>. Fix: check the command and PATH.",
@@ -1904,13 +1908,22 @@ CREATE VIRTUAL TABLE line_units USING fts5(
1904
1908
  var DDL_V6 = `
1905
1909
  UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
1906
1910
  `;
1911
+ var DDL_V7 = `
1912
+ ALTER TABLE sources ADD COLUMN unit_lo INTEGER;
1913
+ ALTER TABLE sources ADD COLUMN unit_hi INTEGER;
1914
+ CREATE INDEX IF NOT EXISTS idx_sources_session ON sources(session_id, id);
1915
+ UPDATE sources SET unit_lo = g.lo, unit_hi = g.hi
1916
+ FROM (SELECT source_id, MIN(rowid) AS lo, MAX(rowid) AS hi FROM line_units GROUP BY source_id) AS g
1917
+ WHERE g.source_id = sources.id;
1918
+ `;
1907
1919
  var MIGRATIONS = [
1908
1920
  { version: 1, sql: DDL },
1909
1921
  { version: 2, sql: DDL_V2 },
1910
1922
  { version: 3, sql: DDL_V3 },
1911
1923
  { version: 4, sql: DDL_V4 },
1912
1924
  { version: 5, sql: DDL_V5 },
1913
- { version: 6, sql: DDL_V6 }
1925
+ { version: 6, sql: DDL_V6 },
1926
+ { version: 7, sql: DDL_V7 }
1914
1927
  ];
1915
1928
  function applyMigrations(db, fromVersion) {
1916
1929
  if (fromVersion === SCHEMA_VERSION2) return;
@@ -5529,7 +5542,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
5529
5542
  ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nWrite code that prints only the answer, not the raw data. Runs code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',
5530
5543
  ctx_batch: 'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',
5531
5544
  ctx_index: 'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',
5532
- ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Memory files such as AGENTS.md are searched too. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',
5545
+ ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Memory files such as AGENTS.md are searched too. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. Set `source` with queries `[""]` to read that source whole, in order, a full page per call; `More:` gives the next `offset`. When nothing matches, the reply states the scope and how many sources are indexed.',
5533
5546
  ctx_resume: "Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",
5534
5547
  ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",
5535
5548
  ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",
@@ -5978,7 +5991,7 @@ function dumpTarget(name, args) {
5978
5991
  }
5979
5992
 
5980
5993
  // src/core/project/resolve.ts
5981
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5994
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
5982
5995
 
5983
5996
  // src/core/project/sha256.ts
5984
5997
  var K = new Uint32Array([
@@ -6133,12 +6146,7 @@ function dirOf(kind, src) {
6133
6146
  }
6134
6147
  }
6135
6148
  function gitDirs(dir) {
6136
- let cur;
6137
- try {
6138
- cur = realpathSync3.native(dir);
6139
- } catch {
6140
- throw new CtxError("NO_GIT_DIR", { path: dir });
6141
- }
6149
+ let cur = nearestRealDir(dir);
6142
6150
  const start = cur;
6143
6151
  for (; ; ) {
6144
6152
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
@@ -6151,6 +6159,18 @@ function gitDirs(dir) {
6151
6159
  cur = up;
6152
6160
  }
6153
6161
  }
6162
+ function nearestRealDir(dir) {
6163
+ const walk2 = isAbsolute3(dir);
6164
+ for (let d = walk2 ? resolve6(dir) : dir; ; ) {
6165
+ try {
6166
+ return realpathSync3.native(d);
6167
+ } catch {
6168
+ const up = dirname3(d);
6169
+ if (!walk2 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
6170
+ d = up;
6171
+ }
6172
+ }
6173
+ }
6154
6174
  function gitDirAt(dotGit) {
6155
6175
  let gitDir;
6156
6176
  try {
@@ -6213,7 +6233,7 @@ function resolveProject(agent, src) {
6213
6233
  },
6214
6234
  worktree,
6215
6235
  get containmentRoot() {
6216
- root ??= plain ?? containmentRootOf(dir, commonDir);
6236
+ root ??= plain ?? containmentRootOf(worktree, commonDir);
6217
6237
  return root;
6218
6238
  },
6219
6239
  agent,
package/search.mjs CHANGED
@@ -14,16 +14,9 @@ function prefixToolNames(text, prefix) {
14
14
  }
15
15
  var OUTPUT_CAP = 16384;
16
16
  var INDEX_WRITE_CHUNK = 1048576;
17
- var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
18
- var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
19
- function readReplaceTrigger(raw) {
20
- if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
21
- const n = Number(raw);
22
- return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
23
- }
24
- var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
25
17
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
26
18
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
19
+ var SKILL_LOAD_TOOLS = Object.freeze(["Skill"]);
27
20
  function shellWord(s) {
28
21
  return "'" + s.split("'").join("'\\''") + "'";
29
22
  }
@@ -178,7 +171,7 @@ var SQLITE_NOTADB_CODE = 26;
178
171
  var HOOK_TIMEOUT_MS = 5e3;
179
172
  var IN_PROCESS_TIMEOUT_MS = 0;
180
173
  var PROJECT_KEY_HEX_LEN = 16;
181
- var SCHEMA_VERSION = 6;
174
+ var SCHEMA_VERSION = 7;
182
175
  var PROJECTS_DIR_NAME = "projects";
183
176
  var DB_FILE_NAME = "context.db";
184
177
  var GIT_DIR_NAME = ".git";
@@ -202,6 +195,7 @@ var SEARCH_WRAPPER_FILE = "search.mjs";
202
195
  var RUN_WRAPPER_AGENT = "claude-code";
203
196
  var RUN_SESSION_PREFIX = "mcp:";
204
197
  var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
198
+ var HOST_SESSION_META = Object.freeze({ zcode: "session_id" });
205
199
  var NODE_MIN = "24.15.0";
206
200
  var DATA_ROOT = "~/.context-mode";
207
201
  var DATA_DIR_ENV = "CONTEXT_MODE_DATA_DIR";
@@ -675,6 +669,7 @@ var SHELL_TOOL_NAMES = Object.freeze(["Bash", "PowerShell"]);
675
669
  var POWERSHELL_TOOL = "PowerShell";
676
670
  var SHELL_CANONICAL = "Bash";
677
671
  var CLAUDE_SHAPE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse"];
672
+ var FAILURE_EVENT = "PostToolUseFailure";
678
673
  var MCP_PREFIX = "mcp__";
679
674
  var MCP_SEP = "__";
680
675
  var CLAUDE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
@@ -848,7 +843,14 @@ function requireFields(raw) {
848
843
  }
849
844
  function decode(raw) {
850
845
  requireFields(raw);
851
- const ev = decodeClaudeShape(raw, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
846
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
847
+ const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
848
+ const ev = decodeClaudeShape(payload, "claude-code", TOOL_NAME_PREFIX, CLAUDE_SOURCES);
849
+ if (failure) {
850
+ const error = raw.error;
851
+ const text = typeof error === "string" ? error : error === void 0 ? "" : JSON.stringify(error);
852
+ ev.result = { isError: true, bytes: Buffer.byteLength(text), text, keep: true };
853
+ }
852
854
  if (ev.tool !== void 0 && ev.tool.name === POWERSHELL_TOOL) ev.tool.canonicalName = SHELL_CANONICAL;
853
855
  if (ev.cwd === "") ev.cwd = process.env.CLAUDE_PROJECT_DIR || process.cwd();
854
856
  if (ev.event === "PostToolUse" && ev.tool !== void 0 && ev.tool.callId === void 0) {
@@ -1027,9 +1029,9 @@ var NATIVE_TO_CANONICAL2 = {
1027
1029
  grep_search: "Grep",
1028
1030
  web_fetch: "WebFetch"
1029
1031
  };
1030
- var FAILURE_EVENT = "PostToolUseFailure";
1032
+ var FAILURE_EVENT2 = "PostToolUseFailure";
1031
1033
  function decode4(raw) {
1032
- const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT;
1034
+ const failure = typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === FAILURE_EVENT2;
1033
1035
  const payload = failure ? { ...raw, hook_event_name: "PostToolUse" } : raw;
1034
1036
  const ev = decodeClaudeShape(payload, "qwen", TOOL_NAME_PREFIX4, QWEN_SOURCES);
1035
1037
  if (ev.tool !== void 0 && Object.hasOwn(NATIVE_TO_CANONICAL2, ev.tool.name)) ev.tool.canonicalName = NATIVE_TO_CANONICAL2[ev.tool.name];
@@ -1349,12 +1351,12 @@ var TOOL_NAME_PREFIX8 = "mcp__context-mode__";
1349
1351
  var PLUGIN_TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
1350
1352
  var ZCODE_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
1351
1353
  var TWINS = { hook_event_name: "hookEventName", session_id: "sessionId" };
1352
- var FAILURE_EVENT2 = "PostToolUseFailure";
1354
+ var FAILURE_EVENT3 = "PostToolUseFailure";
1353
1355
  function decode8(raw) {
1354
1356
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("zcode: hook payload is not a JSON object");
1355
1357
  const p = { ...raw };
1356
1358
  for (const [snake, camel] of Object.entries(TWINS)) if (p[snake] === void 0) p[snake] = p[camel];
1357
- const failure = p.hook_event_name === FAILURE_EVENT2;
1359
+ const failure = p.hook_event_name === FAILURE_EVENT3;
1358
1360
  if (failure) p.hook_event_name = "PostToolUse";
1359
1361
  const toolName = typeof p.tool_name === "string" ? p.tool_name : "";
1360
1362
  const prefix = toolName.startsWith(PLUGIN_TOOL_NAME_PREFIX) ? PLUGIN_TOOL_NAME_PREFIX : TOOL_NAME_PREFIX8;
@@ -1445,7 +1447,8 @@ var OPENCODE_EVENTS = {
1445
1447
  var SHELL_TOOL_NAME = "bash";
1446
1448
  var READ_TOOL_NAME = "read";
1447
1449
  var SHELL_TOOL_NAMES5 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
1448
- var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1450
+ var SKILL_TOOL_NAME = "skill";
1451
+ var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", [READ_TOOL_NAME]: "Read", [SKILL_TOOL_NAME]: "Skill", ...Object.fromEntries(SHELL_TOOL_NAMES5.map((n) => [n, "Bash"])) };
1449
1452
  function toCanonicalTool(name) {
1450
1453
  if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
1451
1454
  return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
@@ -1745,7 +1748,8 @@ var ERROR_TEXT = Object.freeze({
1745
1748
  NO_RUNTIME: "No <lang> runtime on PATH. Fix: install it or pick another language.",
1746
1749
  FETCH_FAILED: "Fetch failed: <code>. Fix: check the URL or proxy.",
1747
1750
  SSRF: "Blocked private address <host>. Fix: use a public URL.",
1748
- OUTSIDE_ROOT: "Path <p> is outside the project. Fix: use a path inside <root>.",
1751
+ OUTSIDE_ROOT: "Path <p> is outside the project and the folders added to this session. Fix: use a path inside <root>, or add its folder to the session (Claude Code /add-dir, Codex --add-dir).",
1752
+ // #1398 D-1398-HOST-ROOTS-1
1749
1753
  INVALID_ARGS: "Invalid argument <field>. Fix: <action>.",
1750
1754
  ONE_OF_INPUT: "Pass exactly one of <names>. Fix: drop the extra field.",
1751
1755
  SPAWN_FAILED: "Failed to start the process: <detail>. Fix: check the command and PATH.",
@@ -1904,13 +1908,22 @@ CREATE VIRTUAL TABLE line_units USING fts5(
1904
1908
  var DDL_V6 = `
1905
1909
  UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
1906
1910
  `;
1911
+ var DDL_V7 = `
1912
+ ALTER TABLE sources ADD COLUMN unit_lo INTEGER;
1913
+ ALTER TABLE sources ADD COLUMN unit_hi INTEGER;
1914
+ CREATE INDEX IF NOT EXISTS idx_sources_session ON sources(session_id, id);
1915
+ UPDATE sources SET unit_lo = g.lo, unit_hi = g.hi
1916
+ FROM (SELECT source_id, MIN(rowid) AS lo, MAX(rowid) AS hi FROM line_units GROUP BY source_id) AS g
1917
+ WHERE g.source_id = sources.id;
1918
+ `;
1907
1919
  var MIGRATIONS = [
1908
1920
  { version: 1, sql: DDL },
1909
1921
  { version: 2, sql: DDL_V2 },
1910
1922
  { version: 3, sql: DDL_V3 },
1911
1923
  { version: 4, sql: DDL_V4 },
1912
1924
  { version: 5, sql: DDL_V5 },
1913
- { version: 6, sql: DDL_V6 }
1925
+ { version: 6, sql: DDL_V6 },
1926
+ { version: 7, sql: DDL_V7 }
1914
1927
  ];
1915
1928
  function applyMigrations(db, fromVersion) {
1916
1929
  if (fromVersion === SCHEMA_VERSION2) return;
@@ -5529,7 +5542,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
5529
5542
  ctx_execute: 'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nWrite code that prints only the answer, not the raw data. Runs code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',
5530
5543
  ctx_batch: 'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',
5531
5544
  ctx_index: 'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',
5532
- ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Memory files such as AGENTS.md are searched too. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',
5545
+ ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Memory files such as AGENTS.md are searched too. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. Set `source` with queries `[""]` to read that source whole, in order, a full page per call; `More:` gives the next `offset`. When nothing matches, the reply states the scope and how many sources are indexed.',
5533
5546
  ctx_resume: "Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",
5534
5547
  ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",
5535
5548
  ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",
@@ -5978,7 +5991,7 @@ function dumpTarget(name, args) {
5978
5991
  }
5979
5992
 
5980
5993
  // src/core/project/resolve.ts
5981
- import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve6 } from "node:path";
5994
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute3, join as join6, resolve as resolve6 } from "node:path";
5982
5995
 
5983
5996
  // src/core/project/sha256.ts
5984
5997
  var K = new Uint32Array([
@@ -6133,12 +6146,7 @@ function dirOf(kind, src) {
6133
6146
  }
6134
6147
  }
6135
6148
  function gitDirs(dir) {
6136
- let cur;
6137
- try {
6138
- cur = realpathSync3.native(dir);
6139
- } catch {
6140
- throw new CtxError("NO_GIT_DIR", { path: dir });
6141
- }
6149
+ let cur = nearestRealDir(dir);
6142
6150
  const start = cur;
6143
6151
  for (; ; ) {
6144
6152
  const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
@@ -6151,6 +6159,18 @@ function gitDirs(dir) {
6151
6159
  cur = up;
6152
6160
  }
6153
6161
  }
6162
+ function nearestRealDir(dir) {
6163
+ const walk2 = isAbsolute3(dir);
6164
+ for (let d = walk2 ? resolve6(dir) : dir; ; ) {
6165
+ try {
6166
+ return realpathSync3.native(d);
6167
+ } catch {
6168
+ const up = dirname3(d);
6169
+ if (!walk2 || up === d) throw new CtxError("NO_GIT_DIR", { path: dir });
6170
+ d = up;
6171
+ }
6172
+ }
6173
+ }
6154
6174
  function gitDirAt(dotGit) {
6155
6175
  let gitDir;
6156
6176
  try {
@@ -6213,7 +6233,7 @@ function resolveProject(agent, src) {
6213
6233
  },
6214
6234
  worktree,
6215
6235
  get containmentRoot() {
6216
- root ??= plain ?? containmentRootOf(dir, commonDir);
6236
+ root ??= plain ?? containmentRootOf(worktree, commonDir);
6217
6237
  return root;
6218
6238
  },
6219
6239
  agent,