context-mode 2.0.0-next.37 → 2.0.0-next.39

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/pi/index.js CHANGED
@@ -11173,6 +11173,7 @@ function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
11173
11173
  var HANDLE_PROMPT_WORDS = 3;
11174
11174
  var MAX_CHUNK_BYTES = 4096;
11175
11175
  var SEARCH_PAGE_SIZE = 20;
11176
+ var MEMORY_LABEL_PREFIX = "memory ";
11176
11177
  var SEARCH_REPLY_HITS = 5;
11177
11178
  var SNIPPET_MAX_BYTES = 800;
11178
11179
  var SNIPPET_CODE_MAX_BYTES = 2048;
@@ -11570,7 +11571,7 @@ var DECISION_OPTION_KEY = "option";
11570
11571
  var DECISION_LABEL_JOIN = " | ";
11571
11572
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
11572
11573
  var RELEASE_BRANCH = "release";
11573
- var BUNDLE_SHA = true ? "2ed67370714045804b7620af1f3af2c9eabc1713" : void 0;
11574
+ var BUNDLE_SHA = true ? "1fdd9889d173fa80227ade07d30705291f097df5" : void 0;
11574
11575
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
11575
11576
  var DOCTOR_LABEL = Object.freeze({
11576
11577
  D1: "version",
@@ -14896,7 +14897,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
14896
14897
  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.',
14897
14898
  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.',
14898
14899
  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.',
14899
- ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. 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.',
14900
+ 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.',
14900
14901
  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.",
14901
14902
  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.",
14902
14903
  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",
@@ -18225,7 +18226,7 @@ function ftsQueryTimeline(db, scope, ctx, sessionId, limit, after, source, memor
18225
18226
  }
18226
18227
  }
18227
18228
  for (const m of memory) {
18228
- if (m.ts > from && (source === void 0 || m.label === source)) merged.push(m);
18229
+ if (m.ts > from && (source === void 0 || m.label === source || MEMORY_LABEL_PREFIX + m.label === source)) merged.push(m);
18229
18230
  }
18230
18231
  merged.sort(timelineOrder);
18231
18232
  let end = Math.min(limit, merged.length);
@@ -20232,17 +20233,29 @@ function runProcess(argv, o) {
20232
20233
  }
20233
20234
 
20234
20235
  // src/core/index/auto-memory.ts
20235
- import { readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
20236
+ import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
20236
20237
  import { join as join7 } from "node:path";
20237
- var CLAUDE_CODE_MEMORY_FILES = Object.freeze([
20238
+ var MEMORY_FILES = Object.freeze([
20238
20239
  Object.freeze(["CLAUDE.md"]),
20239
20240
  Object.freeze(["CLAUDE.local.md"]),
20240
- Object.freeze([".claude", "CLAUDE.md"])
20241
+ Object.freeze([".claude", "CLAUDE.md"]),
20242
+ Object.freeze(["AGENTS.md"]),
20243
+ Object.freeze(["GEMINI.md"]),
20244
+ Object.freeze(["QWEN.md"]),
20245
+ Object.freeze([".github", "copilot-instructions.md"])
20241
20246
  ]);
20247
+ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
20248
+ var MD = ".md";
20249
+ function steeringFiles(worktree) {
20250
+ try {
20251
+ return readdirSync(join7(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
20252
+ } catch {
20253
+ return [];
20254
+ }
20255
+ }
20242
20256
  function readAutoMemory(project) {
20243
- if (project.agent !== "claude-code") return [];
20244
20257
  const rows = [];
20245
- for (const segs of CLAUDE_CODE_MEMORY_FILES) {
20258
+ for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
20246
20259
  const path7 = join7(project.worktree, ...segs);
20247
20260
  if (!isInside(project.worktree, path7)) continue;
20248
20261
  try {
@@ -20262,6 +20275,24 @@ function readAutoMemory(project) {
20262
20275
  }
20263
20276
  return rows;
20264
20277
  }
20278
+ function memoryFileNamed(rows, value) {
20279
+ const v = value.split("\\").join("/");
20280
+ return rows.find((r) => r.label === v || MEMORY_LABEL_PREFIX + r.label === v) ?? null;
20281
+ }
20282
+ function memoryChunks(rows) {
20283
+ const out = [];
20284
+ rows.forEach((r, i) => {
20285
+ for (const c of chunkText(r.text, "md")) out.push({ fileNo: i + 1, label: r.label, ord: c.ord, text: c.text });
20286
+ });
20287
+ return out;
20288
+ }
20289
+ function memoryHits(chunks, q, limit) {
20290
+ if (chunks.length === 0) return [];
20291
+ const texts = chunks.map((c) => c.text);
20292
+ const any3 = rankTexts(texts, q, "any");
20293
+ const all = rankTexts(texts, q, "all");
20294
+ return chunks.map((c, i) => ({ c, s: any3[i], full: all[i] > 0 })).filter((e) => e.s > 0).sort((a, b) => Number(b.full) - Number(a.full) || b.s - a.s || a.c.fileNo - b.c.fileNo || a.c.ord - b.c.ord).slice(0, limit).map((e) => ({ sourceId: -e.c.fileNo, label: MEMORY_LABEL_PREFIX + e.c.label, ord: e.c.ord, snippet: highlight(e.c.text, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full }));
20295
+ }
20265
20296
 
20266
20297
  // src/core/tools/search.ts
20267
20298
  function unknownField(issue4) {
@@ -20298,8 +20329,8 @@ function sourceCount(db, scope, ctx, source) {
20298
20329
  });
20299
20330
  return Number(row5.n);
20300
20331
  }
20301
- function zeroHits(db, scope, ctx, source, offset = 0) {
20302
- const n = sourceCount(db, scope, ctx, source);
20332
+ function zeroHits(db, scope, ctx, source, mem, offset = 0) {
20333
+ const n = sourceCount(db, scope, ctx, source) + mem.rows.length;
20303
20334
  if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
20304
20335
  return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
20305
20336
  }
@@ -20322,7 +20353,7 @@ function sourceCard(db, id, input, scope, arg) {
20322
20353
  }
20323
20354
  function callText(queries, scope, source, cursor) {
20324
20355
  const src = source === void 0 ? "" : ", source:" + JSON.stringify(source);
20325
- return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + ", " + cursor + "})";
20356
+ return "ctx_search({queries:" + JSON.stringify(queries) + ", scope:" + JSON.stringify(scope) + src + (cursor === "" ? "" : ", " + cursor) + "})";
20326
20357
  }
20327
20358
  function decisionQueries(input) {
20328
20359
  return input.source === DECISION_SOURCE && input.queries.length === 0 ? [""] : input.queries;
@@ -20399,14 +20430,46 @@ function replyHits(hits, size) {
20399
20430
  while (n < size && n < hits.length && hits[n].full === true) n++;
20400
20431
  return n;
20401
20432
  }
20402
- function relevance(db, given, scope, ctx, nm) {
20433
+ var MEMORY_HITS = 2;
20434
+ function mergeMemory(content, memory) {
20435
+ const out = [];
20436
+ let c = 0;
20437
+ let m = 0;
20438
+ let lastMem = true;
20439
+ while (c < content.length || m < memory.length) {
20440
+ const rank = (h) => h === void 0 ? -1 : h.full === true ? 1 : 0;
20441
+ const rc = rank(content[c]);
20442
+ const rm = rank(memory[m]);
20443
+ const mem = rc < 0 || rm > rc || rm === rc && !lastMem;
20444
+ if (mem) {
20445
+ out.push(memory[m++]);
20446
+ lastMem = true;
20447
+ } else {
20448
+ out.push(content[c++]);
20449
+ lastMem = false;
20450
+ }
20451
+ }
20452
+ return out;
20453
+ }
20454
+ var contentIn = (hits, n) => hits.slice(0, n).filter((h) => h.sourceId > 0).length;
20455
+ function relevance(db, given, scope, ctx, nm, ms, indexed) {
20403
20456
  const input = { ...given, queries: decisionQueries(given) };
20404
20457
  const offset = input.offset ?? 0;
20405
20458
  const size = pageSize(input);
20406
- const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
20459
+ const mem = ms.named || offset === 0 ? memoryChunks(ms.rows) : [];
20460
+ const count2 = (hits, n) => ms.named ? Math.min(n, hits.length) : contentIn(hits, n);
20461
+ const fetched = input.queries.map((q) => {
20462
+ if (ms.named) {
20463
+ const want = offset + size + 1;
20464
+ const content2 = indexed ? ftsQuery(db, q, scope, ctx.project, ctx.sessionId, want, 0, input.source) : [];
20465
+ return mergeMemory(content2, memoryHits(mem, q, want)).slice(offset, want);
20466
+ }
20467
+ const content = page(db, q, input, scope, ctx, offset, 1);
20468
+ return mem.length === 0 ? content : mergeMemory(content, memoryHits(mem, q, MEMORY_HITS));
20469
+ });
20407
20470
  const take = fetched.map((h) => replyHits(h, size));
20408
20471
  const pages = fetched.map((h, i) => h.slice(0, take[i]));
20409
- if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, offset);
20472
+ if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
20410
20473
  const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
20411
20474
  let reserve = 0;
20412
20475
  for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
@@ -20439,13 +20502,13 @@ function relevance(db, given, scope, ctx, nm) {
20439
20502
  }
20440
20503
  const line = shownLabel(hit.label, hit.sourceId) + " #" + hit.ord + ": " + hit.snippet;
20441
20504
  if (used + bytes2(line) + 1 + reserve > OUTPUT_CAP) {
20442
- cut = offset + i;
20505
+ cut = offset + count2(hits, i);
20443
20506
  stopped = true;
20444
20507
  break;
20445
20508
  }
20446
20509
  const room = total.get(hit.sourceId);
20447
20510
  if (room !== void 0 && mine.has(hit.sourceId) && (spent.get(hit.sourceId) ?? 0) + bytes2(line) + 1 > room * SMALL_SOURCE_SHARE * (qi + 1) / input.queries.length) {
20448
- cut = offset + i;
20511
+ cut = offset + count2(hits, i);
20449
20512
  break;
20450
20513
  }
20451
20514
  lines.push(line);
@@ -20460,7 +20523,7 @@ function relevance(db, given, scope, ctx, nm) {
20460
20523
  used += bytes2(line) + 1;
20461
20524
  }
20462
20525
  if (cut >= 0) more.push({ q, pos: cut });
20463
- else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
20526
+ else if (count2(fetched[qi], fetched[qi].length) > count2(fetched[qi], take[qi])) more.push({ q, pos: offset + count2(fetched[qi], take[qi]) });
20464
20527
  });
20465
20528
  const moreLines = [];
20466
20529
  const byPos = /* @__PURE__ */ new Map();
@@ -20474,10 +20537,9 @@ function timelineLine(r) {
20474
20537
  const seq = r.seq === null ? "" : " #" + r.seq;
20475
20538
  return "[" + new Date(r.ts).toISOString() + "] " + shownLabel(r.label, r.sourceId) + seq + " " + first;
20476
20539
  }
20477
- function timeline(db, input, scope, ctx, nm) {
20478
- const memory = scope === "session" ? [] : readAutoMemory(ctx.project);
20479
- const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, memory);
20480
- if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source);
20540
+ function timeline(db, input, scope, ctx, nm, ms) {
20541
+ const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
20542
+ if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
20481
20543
  const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
20482
20544
  const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
20483
20545
  const lines = nm.note === null ? [] : [nm.note];
@@ -20506,6 +20568,15 @@ function timeline(db, input, scope, ctx, nm) {
20506
20568
  if (more && lastTs !== null) lines.push(moreLine3(lastTs));
20507
20569
  return reply(lines.join("\n"), false);
20508
20570
  }
20571
+ function answer(db, input, scope, ctx, nm, ms, indexed, sort, pick4) {
20572
+ if (sort === "timeline") return timeline(db, input, scope, ctx, nm, ms);
20573
+ if (pick4 !== null && pick4.id !== null && input.queries.length === 0) {
20574
+ const card = sourceCard(db, pick4.id, input, scope, nm.arg);
20575
+ if (card !== null) return card;
20576
+ }
20577
+ const rows = ms.named ? null : jsonRowsReply(db, input, scope, ctx, nm);
20578
+ return rows ?? relevance(db, input, scope, ctx, nm, ms, indexed);
20579
+ }
20509
20580
  async function handler(input, ctx) {
20510
20581
  const sort = input.sort ?? "relevance";
20511
20582
  if (sort === "timeline" && input.offset !== void 0) {
@@ -20521,12 +20592,18 @@ async function handler(input, ctx) {
20521
20592
  const pick4 = given !== void 0 && given !== DECISION_SOURCE ? pickSource(db, given) : null;
20522
20593
  if (pick4 !== null) input = { ...input, source: pick4.label };
20523
20594
  const nm = named(given, pick4);
20524
- if (sort === "timeline") return timeline(db, input, scope, ctx, nm);
20525
- if (pick4 !== null && pick4.id !== null && input.queries.length === 0) {
20526
- const card = sourceCard(db, pick4.id, input, scope, nm.arg);
20527
- if (card !== null) return card;
20528
- }
20529
- return jsonRowsReply(db, input, scope, ctx, nm) ?? relevance(db, input, scope, ctx, nm);
20595
+ const indexed = pick4 !== null && pick4.id !== null;
20596
+ const files = scope !== "session" || given !== void 0 ? readAutoMemory(ctx.project) : [];
20597
+ const file2 = given === void 0 || given === DECISION_SOURCE ? null : memoryFileNamed(files, given);
20598
+ const ms = { rows: scope === "session" ? [] : file2 !== null ? [file2] : given === void 0 ? files : [], named: file2 !== null };
20599
+ if (file2 !== null && indexed && scope !== "session") {
20600
+ const both = "Source " + JSON.stringify(given) + ": searched the indexed source " + shownLabel(pick4.label, pick4.id) + " and the memory file " + file2.label + ".";
20601
+ nm.note = nm.note === null ? both : nm.note + "\n" + both;
20602
+ }
20603
+ const out = answer(db, input, scope, ctx, nm, ms, indexed, sort, pick4);
20604
+ if (file2 === null || scope !== "session") return out;
20605
+ const call = callText(input.queries, "worktree", nm.arg, sort === "timeline" ? 'sort:"timeline"' : "");
20606
+ return reply(out.text + "\nMemory file " + file2.label + ' is in scope "worktree": ' + call + " searches it.", out.isError);
20530
20607
  } finally {
20531
20608
  closeDb(db);
20532
20609
  }
@@ -20662,7 +20739,7 @@ function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
20662
20739
  function bytes3(s) {
20663
20740
  return Buffer.byteLength(s, "utf8");
20664
20741
  }
20665
- function answer(db, ctx, ownIds, queries, share, own4) {
20742
+ function answer2(db, ctx, ownIds, queries, share, own4) {
20666
20743
  const seen = /* @__PURE__ */ new Set();
20667
20744
  const lines = [];
20668
20745
  for (const [qi, q] of queries.entries()) {
@@ -20725,7 +20802,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
20725
20802
  notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
20726
20803
  const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
20727
20804
  const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
20728
- const answered = answer(db, ctx, idx.ids, queries, share, idx.bodies);
20805
+ const answered = answer2(db, ctx, idx.ids, queries, share, idx.bodies);
20729
20806
  sections = answered.lines;
20730
20807
  const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
20731
20808
  const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
@@ -20761,15 +20838,15 @@ var ctxBatch = Object.freeze({
20761
20838
  });
20762
20839
 
20763
20840
  // src/core/tools/doctor.ts
20764
- import { readdirSync as readdirSync5, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
20841
+ import { readdirSync as readdirSync6, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
20765
20842
  import { basename as basename5, dirname as dirname8, join as join16 } from "node:path";
20766
20843
 
20767
20844
  // src/core/ops/doctor-config.ts
20768
- import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
20845
+ import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
20769
20846
  import { join as join11 } from "node:path";
20770
20847
 
20771
20848
  // src/core/ops/detect-v1.ts
20772
- import { existsSync as existsSync4, opendirSync, readdirSync, readFileSync as readFileSync7 } from "node:fs";
20849
+ import { existsSync as existsSync4, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
20773
20850
  import { tmpdir } from "node:os";
20774
20851
  import { join as join9 } from "node:path";
20775
20852
 
@@ -23489,7 +23566,7 @@ function scanVscode(agentHome, project, out) {
23489
23566
  }
23490
23567
  function jsonFiles(dir) {
23491
23568
  try {
23492
- return readdirSync(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
23569
+ return readdirSync2(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
23493
23570
  } catch {
23494
23571
  return [];
23495
23572
  }
@@ -23615,7 +23692,7 @@ function detectV1(agent, home, scope = {}) {
23615
23692
  }
23616
23693
 
23617
23694
  // src/core/ops/plugin-root.ts
23618
- import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23695
+ import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
23619
23696
  import { dirname as dirname6, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
23620
23697
  import { fileURLToPath } from "node:url";
23621
23698
  function missing(agent, path7) {
@@ -23715,7 +23792,7 @@ function marketplaceRoot(adapter, env, worktree) {
23715
23792
  if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
23716
23793
  const pattern = join10(cache, "*", PLUGIN_NAME);
23717
23794
  if (!existsSync5(cache)) throw missing(adapter.id, pattern);
23718
- const found = readdirSync2(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync5(dir));
23795
+ const found = readdirSync3(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync5(dir));
23719
23796
  if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
23720
23797
  return found[0];
23721
23798
  }
@@ -23858,10 +23935,10 @@ function codexNativeDir(env, home) {
23858
23935
  const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
23859
23936
  if (!existsSync6(cache)) return null;
23860
23937
  const found = [];
23861
- for (const market of readdirSync3(cache)) {
23938
+ for (const market of readdirSync4(cache)) {
23862
23939
  const plugin = join11(cache, market, SERVER_KEY);
23863
23940
  if (!existsSync6(plugin)) continue;
23864
- for (const version4 of readdirSync3(plugin).sort()) {
23941
+ for (const version4 of readdirSync4(plugin).sort()) {
23865
23942
  const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
23866
23943
  if (existsSync6(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
23867
23944
  }
@@ -24636,7 +24713,7 @@ import { existsSync as existsSync11, mkdirSync as mkdirSync5, rmSync as rmSync3
24636
24713
  import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
24637
24714
 
24638
24715
  // src/core/store/owners.ts
24639
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24716
+ import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24640
24717
  import { basename as basename3, join as join13 } from "node:path";
24641
24718
  function ownersDir(configDir, projectKey) {
24642
24719
  return join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
@@ -24669,7 +24746,7 @@ function listLiveOwners(configDir, projectKey) {
24669
24746
  const dir = ownersDir(configDir, projectKey);
24670
24747
  let names;
24671
24748
  try {
24672
- names = readdirSync4(dir);
24749
+ names = readdirSync5(dir);
24673
24750
  } catch (err) {
24674
24751
  if (errCode2(err) === "ENOENT") return [];
24675
24752
  throw err;
@@ -25067,7 +25144,7 @@ async function hookRow(ctx, adapter, host) {
25067
25144
  function ownServerId(configDir, projectKey) {
25068
25145
  const dir = join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
25069
25146
  if (!existsSync13(dir)) return "";
25070
- for (const name of readdirSync5(dir)) {
25147
+ for (const name of readdirSync6(dir)) {
25071
25148
  if (!name.endsWith(OWNER_PID_EXT)) continue;
25072
25149
  if (readFileSync13(join16(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
25073
25150
  }
@@ -25371,7 +25448,7 @@ import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as
25371
25448
  import { dirname as dirname10, extname, join as join19, relative as relative3, resolve as resolve7 } from "node:path";
25372
25449
 
25373
25450
  // src/core/index/walk.ts
25374
- import { readdirSync as readdirSync6, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25451
+ import { readdirSync as readdirSync7, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync7 } from "node:fs";
25375
25452
  import { join as join18 } from "node:path";
25376
25453
  var GITIGNORE = ".gitignore";
25377
25454
  var GIT_DIR = ".git";
@@ -25386,7 +25463,7 @@ function walkDir(root, containmentRoot) {
25386
25463
  function visit(abs, rel, parent, contain, seen, found) {
25387
25464
  let entries;
25388
25465
  try {
25389
- entries = readdirSync6(abs, { withFileTypes: true });
25466
+ entries = readdirSync7(abs, { withFileTypes: true });
25390
25467
  } catch {
25391
25468
  return;
25392
25469
  }
@@ -30145,7 +30222,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
30145
30222
  }
30146
30223
 
30147
30224
  // src/core/ops/plugin-swap.ts
30148
- import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30225
+ import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
30149
30226
  import { basename as basename6, join as join21, win32 as win322 } from "node:path";
30150
30227
  function linkTarget(path7, win) {
30151
30228
  if (!isLink(path7)) return null;
@@ -30156,7 +30233,7 @@ function isLink(path7) {
30156
30233
  return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
30157
30234
  }
30158
30235
  function generations(agentDir) {
30159
- return readdirSync7(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
30236
+ return readdirSync8(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
30160
30237
  }
30161
30238
  function settleLinks(link, tmp, old, opts) {
30162
30239
  if (isLink(tmp)) unlinkSync2(tmp);
@@ -30225,7 +30302,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
30225
30302
  }
30226
30303
 
30227
30304
  // src/core/ops/uninstall.ts
30228
- import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
30305
+ import { existsSync as existsSync19, readdirSync as readdirSync9, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
30229
30306
  import { join as join23 } from "node:path";
30230
30307
  function row2(area, before, after) {
30231
30308
  return { area, before, after };
@@ -30341,7 +30418,7 @@ function removeProjectData(configDir, projectKey) {
30341
30418
  const dir = join23(projects, projectKey);
30342
30419
  if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
30343
30420
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
30344
- for (const name of readdirSync8(dir)) {
30421
+ for (const name of readdirSync9(dir)) {
30345
30422
  if (name !== OWNERS_DIR_NAME) rmSync7(join23(dir, name), { recursive: true, force: true });
30346
30423
  }
30347
30424
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
@@ -30486,7 +30563,7 @@ function removeV1(agent, findings) {
30486
30563
 
30487
30564
  // src/core/ops/verify-sums.ts
30488
30565
  import { createHash as createHash2 } from "node:crypto";
30489
- import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync17 } from "node:fs";
30566
+ import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync17 } from "node:fs";
30490
30567
  import { join as join24 } from "node:path";
30491
30568
  function mismatch() {
30492
30569
  return new CtxError("BUNDLE_HASH_MISMATCH");
@@ -30505,7 +30582,7 @@ function parseSums(text) {
30505
30582
  return sums;
30506
30583
  }
30507
30584
  function walk3(dir, prefix, out) {
30508
- for (const entry of readdirSync9(dir, { withFileTypes: true })) {
30585
+ for (const entry of readdirSync10(dir, { withFileTypes: true })) {
30509
30586
  const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
30510
30587
  if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
30511
30588
  const abs = join24(dir, entry.name);
@@ -34164,26 +34241,26 @@ function isRecursive(inst, stack2, resolve8) {
34164
34241
  let result = NONE3;
34165
34242
  const check2 = (child) => {
34166
34243
  if (result !== PROVEN && child?._zod) {
34167
- const answer2 = isRecursive(child, stack2, resolve8);
34168
- if (answer2 > result)
34169
- result = answer2;
34244
+ const answer3 = isRecursive(child, stack2, resolve8);
34245
+ if (answer3 > result)
34246
+ result = answer3;
34170
34247
  }
34171
34248
  };
34172
34249
  const shape = (sh, spread) => {
34173
- let answer2 = NONE3;
34250
+ let answer3 = NONE3;
34174
34251
  for (const key of Reflect.ownKeys(sh)) {
34175
34252
  const desc = Object.getOwnPropertyDescriptor(sh, key);
34176
34253
  if (spread && !desc.enumerable)
34177
34254
  continue;
34178
34255
  const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve8) : NONE3;
34179
- if (child > answer2)
34180
- answer2 = child;
34256
+ if (child > answer3)
34257
+ answer3 = child;
34181
34258
  }
34182
- return answer2;
34259
+ return answer3;
34183
34260
  };
34184
- const merge5 = (answer2) => {
34185
- if (answer2 > result)
34186
- result = answer2;
34261
+ const merge5 = (answer3) => {
34262
+ if (answer3 > result)
34263
+ result = answer3;
34187
34264
  };
34188
34265
  const def = inst._zod.def;
34189
34266
  const kind = def.type;
@@ -34286,10 +34363,10 @@ function isRecursive(inst, stack2, resolve8) {
34286
34363
  stack2.delete(inst);
34287
34364
  return settle(inst, result);
34288
34365
  }
34289
- function settle(inst, answer2) {
34290
- if (answer2 !== ASSUMED)
34291
- recursive.set(inst, answer2 === PROVEN);
34292
- return answer2;
34366
+ function settle(inst, answer3) {
34367
+ if (answer3 !== ASSUMED)
34368
+ recursive.set(inst, answer3 === PROVEN);
34369
+ return answer3;
34293
34370
  }
34294
34371
  function bucketFor(state, inst) {
34295
34372
  let bucket = state.buckets.get(inst);
@@ -41693,26 +41770,26 @@ function isRecursive2(inst, stack2, resolve8) {
41693
41770
  let result = NONE4;
41694
41771
  const check2 = (child) => {
41695
41772
  if (result !== PROVEN2 && child?._zod) {
41696
- const answer2 = isRecursive2(child, stack2, resolve8);
41697
- if (answer2 > result)
41698
- result = answer2;
41773
+ const answer3 = isRecursive2(child, stack2, resolve8);
41774
+ if (answer3 > result)
41775
+ result = answer3;
41699
41776
  }
41700
41777
  };
41701
41778
  const shape = (sh, spread) => {
41702
- let answer2 = NONE4;
41779
+ let answer3 = NONE4;
41703
41780
  for (const key of Reflect.ownKeys(sh)) {
41704
41781
  const desc = Object.getOwnPropertyDescriptor(sh, key);
41705
41782
  if (spread && !desc.enumerable)
41706
41783
  continue;
41707
41784
  const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve8) : NONE4;
41708
- if (child > answer2)
41709
- answer2 = child;
41785
+ if (child > answer3)
41786
+ answer3 = child;
41710
41787
  }
41711
- return answer2;
41788
+ return answer3;
41712
41789
  };
41713
- const merge5 = (answer2) => {
41714
- if (answer2 > result)
41715
- result = answer2;
41790
+ const merge5 = (answer3) => {
41791
+ if (answer3 > result)
41792
+ result = answer3;
41716
41793
  };
41717
41794
  const def = inst._zod.def;
41718
41795
  const kind = def.type;
@@ -41815,10 +41892,10 @@ function isRecursive2(inst, stack2, resolve8) {
41815
41892
  stack2.delete(inst);
41816
41893
  return settle2(inst, result);
41817
41894
  }
41818
- function settle2(inst, answer2) {
41819
- if (answer2 !== ASSUMED2)
41820
- recursive2.set(inst, answer2 === PROVEN2);
41821
- return answer2;
41895
+ function settle2(inst, answer3) {
41896
+ if (answer3 !== ASSUMED2)
41897
+ recursive2.set(inst, answer3 === PROVEN2);
41898
+ return answer3;
41822
41899
  }
41823
41900
  function bucketFor2(state, inst) {
41824
41901
  let bucket = state.buckets.get(inst);
@@ -58740,7 +58817,7 @@ function installExitGuard(opts) {
58740
58817
  }
58741
58818
 
58742
58819
  // src/core/store/cleanup.ts
58743
- import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
58820
+ import { existsSync as existsSync22, readdirSync as readdirSync11, rmSync as rmSync10 } from "node:fs";
58744
58821
  import { join as join26 } from "node:path";
58745
58822
  function deleteSource(raw, id) {
58746
58823
  raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
@@ -58811,7 +58888,7 @@ function sweepOne(configDir, projectKey, cutoff) {
58811
58888
  function sweepDeadProjects(configDir) {
58812
58889
  let entries;
58813
58890
  try {
58814
- entries = readdirSync10(join26(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
58891
+ entries = readdirSync11(join26(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
58815
58892
  } catch (err) {
58816
58893
  if (err.code === "ENOENT") return [];
58817
58894
  throw err;
@@ -12,5 +12,5 @@
12
12
  }
13
13
  },
14
14
  "name": "context-mode",
15
- "version": "2.0.0-next.37"
15
+ "version": "2.0.0-next.39"
16
16
  }
package/run.mjs CHANGED
@@ -5019,7 +5019,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
5019
5019
  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.',
5020
5020
  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.',
5021
5021
  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.',
5022
- ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. 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.',
5022
+ 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.',
5023
5023
  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.",
5024
5024
  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.",
5025
5025
  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",
package/search.mjs CHANGED
@@ -5019,7 +5019,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
5019
5019
  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.',
5020
5020
  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.',
5021
5021
  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.',
5022
- ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. 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.',
5022
+ 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.',
5023
5023
  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.",
5024
5024
  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.",
5025
5025
  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",