context-mode 2.1.10 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/pi/index.js CHANGED
@@ -11342,6 +11342,10 @@ var DB_TIMEOUT_MS = 5e3;
11342
11342
  var DB_WAL_SUFFIX = "-wal";
11343
11343
  var DB_SHM_SUFFIX = "-shm";
11344
11344
  var DB_TMP_SUFFIX = ".tmp";
11345
+ var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
11346
+ var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
11347
+ var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
11348
+ var DB_PUBLISH_POLL_MS = 5;
11345
11349
  var SQLITE_PRIMARY_CODE_MASK = 255;
11346
11350
  var SQLITE_CORRUPT_CODE = 11;
11347
11351
  var SQLITE_NOTADB_CODE = 26;
@@ -11509,6 +11513,7 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
11509
11513
  qwen: READ_IMAGES_AND_PDF,
11510
11514
  opencode: READ_IMAGES_AND_PDF,
11511
11515
  pi: READ_IMAGES,
11516
+ omp: READ_IMAGES,
11512
11517
  vscode: READ_IMAGES,
11513
11518
  zcode: READ_IMAGES,
11514
11519
  "copilot-cli": [],
@@ -11625,7 +11630,7 @@ var DECISION_ANSWERS_KEY = "answers";
11625
11630
  var DECISION_OPTION_KEY = "option";
11626
11631
  var DECISION_LABEL_JOIN = " | ";
11627
11632
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
11628
- var BUNDLE_SHA = true ? "877eebcc432f90882c2b5ea04ad22fc95e9dc6c2" : void 0;
11633
+ var BUNDLE_SHA = true ? "1fce537096e8e2b7d1924c2b5ff2b83287f157ee" : void 0;
11629
11634
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
11630
11635
  var DOCTOR_LABEL = Object.freeze({
11631
11636
  D1: "version",
@@ -11781,7 +11786,9 @@ var AGENT_HOME_DIR = Object.freeze({
11781
11786
  kiro: [".kiro"],
11782
11787
  zcode: [".zcode"],
11783
11788
  pi: [".pi"],
11784
- opencode: [".config", "opencode"]
11789
+ opencode: [".config", "opencode"],
11790
+ omp: [".omp"]
11791
+ // ADR-0026: OMP data and plugins live under ~/.omp
11785
11792
  });
11786
11793
  var UPGRADE_RESTART_LINE = "restart needed";
11787
11794
  var UPGRADE_HOST_AREA = "host update";
@@ -11870,16 +11877,6 @@ var UNSUPPORTED_HOSTS = Object.freeze([
11870
11877
  binaries: [],
11871
11878
  source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
11872
11879
  }),
11873
- unsupported({
11874
- id: "omp",
11875
- name: "OMP (oh-my-pi)",
11876
- clientNames: ["omp-coding-agent"],
11877
- envVars: [],
11878
- pluginPaths: [],
11879
- configDirs: [".omp"],
11880
- binaries: ["omp"],
11881
- source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
11882
- }),
11883
11880
  unsupported({
11884
11881
  id: "openclaw",
11885
11882
  name: "OpenClaw",
@@ -11946,7 +11943,9 @@ var HOOK_HOST_FILE = Object.freeze({
11946
11943
  kiro: { root: "home", file: [".kiro", "hooks", "context-mode.json"], key: ["hooks"], shape: "kiro", timeoutKey: "timeout", matcher: false },
11947
11944
  zcode: { root: "home", file: [".zcode", "cli", "config.json"], key: ["hooks", "events"], shape: "zcode", timeoutKey: "timeoutMs", matcher: true },
11948
11945
  pi: null,
11949
- opencode: null
11946
+ opencode: null,
11947
+ omp: null
11948
+ // ADR-0026: in-process, no hook file
11950
11949
  });
11951
11950
  var TOOL_HOOK_EVENTS = Object.freeze(["PreToolUse", "PostToolUse"]);
11952
11951
  var HOOK_MATCHER_FIELD = "matcher";
@@ -11997,6 +11996,12 @@ var D11_POSIX_FIX = "install sh or add it to PATH";
11997
11996
  function D11_PASS_DETAIL(shell, win) {
11998
11997
  return `${win ? "Git Bash" : "sh"}: ${shell}`;
11999
11998
  }
11999
+ function D11_RUNTIME_DETAIL(lang, unreadable) {
12000
+ return `${lang} not found, unreadable on PATH: ${unreadable.join(", ")}`;
12001
+ }
12002
+ function D11_RUNTIME_FIX(lang) {
12003
+ return `install ${lang}, or turn off its app alias and PATH entry that cannot be read`;
12004
+ }
12000
12005
  var DB_SIBLING_SUFFIXES = Object.freeze(["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]);
12001
12006
  var HEAL_TMP_SUFFIX = ".heal";
12002
12007
  var HEAL_TS_SEP = ".";
@@ -12008,6 +12013,8 @@ var UPGRADE_HOST_COMMAND = Object.freeze({
12008
12013
  gemini: "gemini extensions update context-mode",
12009
12014
  qwen: "qwen extensions update context-mode",
12010
12015
  pi: "pi update --extensions",
12016
+ omp: "omp plugin upgrade context-mode",
12017
+ // ADR-0026 decision 4: OMP native update
12011
12018
  opencode: "opencode plugin update",
12012
12019
  "copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
12013
12020
  vscode: "npm i -g context-mode && context-mode setup --agents vscode",
@@ -12051,6 +12058,14 @@ var PI_NPM_DIR = "npm";
12051
12058
  var PI_NODE_MODULES_DIR = "node_modules";
12052
12059
  var PI_PACKAGE_JSON_FILE = "package.json";
12053
12060
  var PI_LIST_COMMAND = "pi list";
12061
+ var OMP_LIST_COMMAND = "omp plugin list";
12062
+ var OMP_ENABLE_COMMAND = "omp plugin enable context-mode";
12063
+ var OMP_MIN_VERSION = "14.7.0";
12064
+ var OMP_FLOOR_INFO = (v) => `OMP ${v} is older than the tested floor ${OMP_MIN_VERSION}. Update it with: omp update`;
12065
+ var OMP_CONTENT_INFO = "OMP keeps tool output in content; context-mode writes its notes there.";
12066
+ var OMP_PRINT_MODE_INFO = "Print mode sends no prompt event. Use omp or omp --mode rpc to keep prompts.";
12067
+ var OMP_SCRIPTS_INFO = "Add < /dev/null in scripts.";
12068
+ var OMP_IMPORT_INFO = (claude, mcp) => `OMP also imports context-mode from ${claude}. To run it once, add "context-mode" to disabledServers in ${mcp}.`;
12054
12069
  var PI_CURRENT_MAJOR = 2;
12055
12070
  var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
12056
12071
  var V1_TMP_PREFIX = "context-mode-";
@@ -12261,6 +12276,8 @@ var NATIVE_INSTALL = Object.freeze({
12261
12276
  qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
12262
12277
  opencode: ["opencode plugin add context-mode"],
12263
12278
  pi: ["pi install npm:context-mode"],
12279
+ omp: ["omp plugin install context-mode"],
12280
+ // ADR-0026 decision 4: OMP native install
12264
12281
  "copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
12265
12282
  vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
12266
12283
  kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
@@ -12290,6 +12307,9 @@ function readResult(p) {
12290
12307
  if (p.keep === true) info.keep = true;
12291
12308
  return info;
12292
12309
  }
12310
+ function decodeOmp(raw) {
12311
+ return { ...decode(raw), agent: "omp" };
12312
+ }
12293
12313
  function decode(raw) {
12294
12314
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
12295
12315
  const p = raw;
@@ -12405,7 +12425,7 @@ var CtxError = class extends Error {
12405
12425
  import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
12406
12426
 
12407
12427
  // src/core/contracts/agents.ts
12408
- var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
12428
+ var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
12409
12429
 
12410
12430
  // src/adapters/claude-code.ts
12411
12431
  var TOOL_NAME_PREFIX2 = "mcp__plugin_context-mode_context-mode__";
@@ -13369,14 +13389,36 @@ var ADAPTERS = Object.freeze([
13369
13389
  decode: decode10,
13370
13390
  encode: encode10,
13371
13391
  toCanonicalTool
13392
+ },
13393
+ {
13394
+ // ADR-0026 (D-OMP-ROW-1): OMP runs the Pi extension API in-process, so the row reuses the Pi decode, encode and
13395
+ // permission check; tool names stay bare. Only the entry path and the skills folder are its own.
13396
+ id: "omp",
13397
+ installMode: "in-process",
13398
+ projectSource: "pi:ctx.cwd",
13399
+ toolNamePrefix: TOOL_NAME_PREFIX,
13400
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
13401
+ execReadOnlyHint: false,
13402
+ eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
13403
+ compactDelivery: "pi-flag",
13404
+ compactSummary: "none",
13405
+ hookTimeoutMs: IN_PROCESS_TIMEOUT_MS,
13406
+ denyChannel: "deny-reason",
13407
+ hookChannel: { kind: "in-process", path: "omp/index.js" },
13408
+ skillChannel: { kind: "package", path: "skills" },
13409
+ // D-OMP-SKILLS-1
13410
+ decode: decodeOmp,
13411
+ encode,
13412
+ checkPermission
13413
+ // D-OMP-FIRE-1: agent omp in rows
13372
13414
  }
13373
13415
  ]);
13374
13416
  var BY_ID = new Map(ADAPTERS.map((r) => [r.id, r]));
13375
- var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
13417
+ var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode", "omp"]);
13376
13418
  function hasReplace(row5) {
13377
13419
  return REPLACE_ROWS.has(row5.id);
13378
13420
  }
13379
- var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi"]);
13421
+ var DUMP_REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "copilot-cli", "pi", "omp"]);
13380
13422
  function dumpRunsThenReplaces(row5) {
13381
13423
  return DUMP_REPLACE_ROWS.has(row5.id) && hasReplace(row5);
13382
13424
  }
@@ -14848,8 +14890,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
14848
14890
  var CLAUDE_CODE_BUILT_INS = Object.freeze({
14849
14891
  "general-purpose": { tools: null, disallowed: [] },
14850
14892
  fork: { tools: null, disallowed: [] },
14893
+ claude: { tools: null, disallowed: [] },
14851
14894
  Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
14852
- Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
14895
+ Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
14896
+ "claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
14897
+ "statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
14898
+ "web-fetch": { tools: ["WebFetch"], disallowed: [] }
14853
14899
  });
14854
14900
  var BUILT_IN_AGENT = "claude-code";
14855
14901
  function isSubagentCall(ev) {
@@ -14870,7 +14916,8 @@ function toolSetForAgentType(ev, src) {
14870
14916
  const type = ev.agentType ?? "";
14871
14917
  const def = findDef(type, src) ?? builtIn(ev.agent, type);
14872
14918
  if (def === null) return null;
14873
- const tools = (def.tools ?? allKnownToolNames(row5)).map((n) => norm(row5, n));
14919
+ const known = allKnownToolNames(row5);
14920
+ const tools = def.tools === null ? known : def.tools.map((n) => norm(row5, n)).flatMap((n) => [n, ...known.filter((k) => grants(n, k))]);
14874
14921
  const deny2 = def.disallowed.map((n) => norm(row5, n));
14875
14922
  return unique(tools.filter((n) => !deny2.some((d) => denies(d, n))));
14876
14923
  }
@@ -15026,6 +15073,13 @@ function geminiValid(s) {
15026
15073
  }
15027
15074
  return out;
15028
15075
  }
15076
+ function grants(entry, name) {
15077
+ if (!entry.startsWith(MCP_SERVER_TOOL_PREFIX)) return false;
15078
+ const wild = MCP_NAME_JOIN + "*";
15079
+ const server = entry.slice(MCP_SERVER_TOOL_PREFIX.length, entry.endsWith(wild) ? -wild.length : entry.length);
15080
+ if (server === "" || server.indexOf("*") >= 0 || server.indexOf(MCP_NAME_JOIN) >= 0) return false;
15081
+ return name.startsWith(MCP_SERVER_TOOL_PREFIX + server + MCP_NAME_JOIN);
15082
+ }
15029
15083
  function denies(rule, name) {
15030
15084
  if (rule.endsWith("*")) return name.startsWith(rule.slice(0, -1));
15031
15085
  if (rule === name) return true;
@@ -15042,13 +15096,15 @@ function unique(names) {
15042
15096
  // src/core/policy/unwrap.ts
15043
15097
  var NONE = "";
15044
15098
  var WRAPPERS = Object.freeze({
15045
- sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
15046
- env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
15047
- time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
15048
- nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
15049
- timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
15050
- command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
15051
- xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
15099
+ sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
15100
+ env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
15101
+ time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
15102
+ nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
15103
+ timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
15104
+ command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
15105
+ xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
15106
+ // #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
15107
+ rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
15052
15108
  });
15053
15109
  var SHELLS = ["bash", "sh", "zsh"];
15054
15110
  var SCRIPT_FLAG = "c";
@@ -15071,6 +15127,10 @@ function isDuration(s) {
15071
15127
  }
15072
15128
  function peel(w, args) {
15073
15129
  let k = 0;
15130
+ if (w.subcommands.length > 0) {
15131
+ if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
15132
+ k = 1;
15133
+ }
15074
15134
  while (k < args.length) {
15075
15135
  const a = args[k];
15076
15136
  if (a === LONG_OPT2) {
@@ -15956,6 +16016,7 @@ function sourceOf(agent) {
15956
16016
  case "opencode":
15957
16017
  return "spawn-cwd";
15958
16018
  case "pi":
16019
+ case "omp":
15959
16020
  return "pi:ctx.cwd";
15960
16021
  }
15961
16022
  }
@@ -16205,7 +16266,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
16205
16266
  }
16206
16267
 
16207
16268
  // src/core/store/db.ts
16208
- var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
16269
+ var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync3 } = process.getBuiltinModule("node:fs");
16209
16270
  function versionParts(v) {
16210
16271
  const bare2 = v.startsWith("v") ? v.slice(1) : v;
16211
16272
  return bare2.split(".").map((p) => Number.parseInt(p, 10));
@@ -16237,6 +16298,34 @@ function readUserVersion(raw) {
16237
16298
  const row5 = raw.prepare("PRAGMA user_version").get();
16238
16299
  return row5.user_version;
16239
16300
  }
16301
+ function errCode(err) {
16302
+ return err.code ?? "";
16303
+ }
16304
+ function publishWithoutLink(tmp, path8) {
16305
+ const claim3 = path8 + DB_PUBLISH_CLAIM_SUFFIX;
16306
+ const start = Date.now();
16307
+ for (; ; ) {
16308
+ if (existsSync3(path8)) return;
16309
+ try {
16310
+ mkdirSync2(claim3);
16311
+ } catch (err) {
16312
+ if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
16313
+ if (Date.now() - start < DB_TIMEOUT_MS) {
16314
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
16315
+ continue;
16316
+ }
16317
+ const held = statSync3(claim3, { throwIfNoEntry: false });
16318
+ if (held !== void 0 && held.mtimeMs < start) rmSync(claim3, { recursive: true, force: true });
16319
+ throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim3} was held; open again`);
16320
+ }
16321
+ try {
16322
+ if (!existsSync3(path8)) renameSync(tmp, path8);
16323
+ } finally {
16324
+ rmSync(claim3, { recursive: true, force: true });
16325
+ }
16326
+ return;
16327
+ }
16328
+ }
16240
16329
  function createAtomically(sqlite, path8) {
16241
16330
  const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
16242
16331
  const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
@@ -16250,7 +16339,9 @@ function createAtomically(sqlite, path8) {
16250
16339
  try {
16251
16340
  linkSync(tmp, path8);
16252
16341
  } catch (err) {
16253
- if (err.code !== "EEXIST") throw err;
16342
+ const code = errCode(err);
16343
+ if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path8);
16344
+ else if (code !== "EEXIST") throw err;
16254
16345
  }
16255
16346
  } finally {
16256
16347
  for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
@@ -16441,9 +16532,15 @@ function readLastPrompt(db, sessionId) {
16441
16532
  const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
16442
16533
  return row5 === void 0 ? "" : row5.body;
16443
16534
  }
16444
- function readRecallRows(db, sessionId, worktree, limit) {
16535
+ function readRecallRows(db, sessionId, worktree, limit, maxSeq = Number.MAX_SAFE_INTEGER) {
16445
16536
  if (sessionId === "") return [];
16446
- return db.raw.prepare("SELECT * FROM events WHERE kind <> 'cost' AND (session_id = ? OR worktree = ?) ORDER BY seq DESC LIMIT ?").all(sessionId, worktree, limit);
16537
+ return db.raw.prepare(
16538
+ "SELECT * FROM events WHERE kind <> 'cost' AND ((session_id = ? AND seq <= ?) OR (worktree = ? AND session_id <> ?)) ORDER BY seq DESC LIMIT ?"
16539
+ ).all(sessionId, maxSeq, worktree, sessionId, limit);
16540
+ }
16541
+ function readMaxSeq(db) {
16542
+ const row5 = db.raw.prepare("SELECT COALESCE(MAX(seq), 0) AS n FROM events").get();
16543
+ return Number(row5.n);
16447
16544
  }
16448
16545
  function hasAgentRows(db, worktree, agent) {
16449
16546
  return db.raw.prepare("SELECT 1 FROM events WHERE worktree = ? AND agent = ? LIMIT 1").get(worktree, agent) !== void 0;
@@ -16451,6 +16548,10 @@ function hasAgentRows(db, worktree, agent) {
16451
16548
  function hasSessionRows(db, sessionId) {
16452
16549
  return db.raw.prepare("SELECT 1 FROM events WHERE session_id = ? LIMIT 1").get(sessionId) !== void 0;
16453
16550
  }
16551
+ function lastSessionSeq(db, sessionId) {
16552
+ const row5 = db.raw.prepare("SELECT MAX(seq) AS m FROM events WHERE session_id = ?").get(sessionId);
16553
+ return row5?.m ?? 0;
16554
+ }
16454
16555
 
16455
16556
  // src/core/store/snippet.ts
16456
16557
  var K1 = 1.2;
@@ -19028,12 +19129,16 @@ function recallQueryText(prompt) {
19028
19129
  if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
19029
19130
  return [...kept.size > 0 ? kept : all].join(" ");
19030
19131
  }
19031
- function queryUnits(db, sessionId, q, limit) {
19132
+ function readMaxSourceId(db) {
19133
+ const row5 = db.raw.prepare("SELECT COALESCE(MAX(id), 0) AS n FROM sources").get();
19134
+ return Number(row5.n);
19135
+ }
19136
+ function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEGER) {
19032
19137
  const match = searchTerms(q).join(" OR ");
19033
19138
  if (match === "" || sessionId === "") return [];
19034
19139
  const rows = db.raw.prepare(
19035
- "SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? ORDER BY bm25(line_units) LIMIT ?"
19036
- ).all(match, sessionId, limit);
19140
+ "SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? AND s.id <= ? ORDER BY bm25(line_units) LIMIT ?"
19141
+ ).all(match, sessionId, maxSourceId, limit);
19037
19142
  return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
19038
19143
  }
19039
19144
 
@@ -19615,7 +19720,7 @@ function cutPoint(src, start, end, scratch) {
19615
19720
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
19616
19721
  return { end: start + r.read, written: r.written };
19617
19722
  }
19618
- function merge2(src, blocks, join27, cap, lineCut) {
19723
+ function merge2(src, blocks, join29, cap, lineCut) {
19619
19724
  const out = [];
19620
19725
  const scratch = new Uint8Array(cap);
19621
19726
  let wide;
@@ -19625,7 +19730,7 @@ function merge2(src, blocks, join27, cap, lineCut) {
19625
19730
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
19626
19731
  };
19627
19732
  for (const b of blocks) {
19628
- if (cur !== void 0 && !join27) {
19733
+ if (cur !== void 0 && !join29) {
19629
19734
  emit(cur.start, cur.end, curBytes);
19630
19735
  cur = void 0;
19631
19736
  }
@@ -20267,7 +20372,7 @@ async function handleHook(agent, raw, env) {
20267
20372
  try {
20268
20373
  fault(env, "project");
20269
20374
  const argv = agent === "vscode" ? [WORKSPACE_FOLDER_FLAG, ev.cwd] : process.argv;
20270
- project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: agent === "pi" ? ev.cwd : void 0 });
20375
+ project = resolveProject(agent, { env, argv, cwd: ev.cwd, piCwd: getAdapter(agent).projectSource === "pi:ctx.cwd" ? ev.cwd : void 0 });
20271
20376
  } catch (err) {
20272
20377
  return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
20273
20378
  }
@@ -20317,8 +20422,9 @@ async function sessionStart(ev, row5, project) {
20317
20422
  if (ev.source === "compact" && hasRecall(row5)) markCompacted(await openDb(project), ev.sessionId);
20318
20423
  if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
20319
20424
  const db2 = await openDb(project);
20320
- if (!shouldHint(db2, ev.sessionId, COMPACT_STATE_KEY)) return ALLOW2;
20321
- return { kind: "hint", text: compactText(db2, ev, row5), onceKey: COMPACT_STATE_KEY };
20425
+ const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
20426
+ if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
20427
+ return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
20322
20428
  }
20323
20429
  const db = await openDb(project);
20324
20430
  if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
@@ -20365,7 +20471,22 @@ async function firstTurnResume(ev, row5, project) {
20365
20471
  return { kind: "hint", text: withPrefix(RESUME_HINT, row5), onceKey: RESUME_HINT_KEY };
20366
20472
  }
20367
20473
  function markCompacted(db, sessionId) {
20368
- if (sessionId !== "") metaSet(db, COMPACTED_META_PREFIX + sessionId, PENDING_COMPACT_FLAG);
20474
+ if (sessionId === "") return;
20475
+ metaSet(db, COMPACTED_META_PREFIX + sessionId, JSON.stringify({ seq: readMaxSeq(db), source: readMaxSourceId(db) }));
20476
+ }
20477
+ function compactBoundary(value) {
20478
+ const all = { seq: Number.MAX_SAFE_INTEGER, source: Number.MAX_SAFE_INTEGER };
20479
+ try {
20480
+ const v = JSON.parse(value);
20481
+ if (typeof v !== "object" || v === null) return all;
20482
+ const { seq, source } = v;
20483
+ return {
20484
+ seq: typeof seq === "number" ? seq : all.seq,
20485
+ source: typeof source === "number" ? source : all.source
20486
+ };
20487
+ } catch {
20488
+ return all;
20489
+ }
20369
20490
  }
20370
20491
  function seenSeqs(value) {
20371
20492
  if (value === null) return [];
@@ -20388,13 +20509,16 @@ function seenUnitKeys(value) {
20388
20509
  async function recall(ev, row5, project, prompt) {
20389
20510
  if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
20390
20511
  const db = await openDb(project);
20391
- if (metaGet(db, COMPACTED_META_PREFIX + ev.sessionId) === null) return ALLOW2;
20512
+ const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
20513
+ if (compacted === null) return ALLOW2;
20514
+ const boundary = compactBoundary(compacted);
20392
20515
  const seenKey = RECALL_SEEN_META_PREFIX + ev.sessionId;
20393
20516
  const seen = seenSeqs(metaGet(db, seenKey));
20394
20517
  const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
20395
20518
  const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
20396
- const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
20397
- const picked = pickRecall(readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS), prompt, new Set(seen), units, new Set(seenUnits));
20519
+ const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES, boundary.source);
20520
+ const rows = readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS, boundary.seq);
20521
+ const picked = pickRecall(rows, prompt, new Set(seen), units, new Set(seenUnits));
20398
20522
  if (picked.text === "") return ALLOW2;
20399
20523
  if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
20400
20524
  if (picked.units !== void 0) metaSet(db, unitsKey, JSON.stringify([...seenUnits, ...picked.units]));
@@ -20581,6 +20705,7 @@ function ownRead(ev, tool, env) {
20581
20705
  async function postReplace(ev, row5, project, env, tool, result, text) {
20582
20706
  if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
20583
20707
  if (boundedRead(tool)) return ALLOW2;
20708
+ if (ompRangedRead(ev, tool)) return ALLOW2;
20584
20709
  if (ownRead(ev, tool, env)) return ALLOW2;
20585
20710
  if (result.keep === true) return ALLOW2;
20586
20711
  if (!hasReplace(row5)) return ALLOW2;
@@ -20595,6 +20720,7 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
20595
20720
  shell: has3(row5.nativeTools.shell),
20596
20721
  read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
20597
20722
  };
20723
+ if (set3 !== null && !caller.ctx && !caller.shell && !caller.read) return ALLOW2;
20598
20724
  label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
20599
20725
  } else {
20600
20726
  label2 = mainLabel(tool, ev);
@@ -20628,6 +20754,53 @@ function searchTwin(handle, intent, project) {
20628
20754
  function boundedRead(tool) {
20629
20755
  return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
20630
20756
  }
20757
+ function ompRangedRead(ev, tool) {
20758
+ if (ev.agent !== "omp" || !RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
20759
+ const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
20760
+ if (p === void 0 || !rangedPathSuffix(p)) return false;
20761
+ try {
20762
+ return lstatSync2(resolve8(ev.cwd, p), { throwIfNoEntry: false }) === void 0;
20763
+ } catch {
20764
+ return false;
20765
+ }
20766
+ }
20767
+ function rangedPathSuffix(path8) {
20768
+ let cut = path8.lastIndexOf(":");
20769
+ let sel = path8.slice(cut + 1);
20770
+ if (sel.toLowerCase() === "raw") {
20771
+ cut = path8.lastIndexOf(":", cut - 1);
20772
+ sel = path8.slice(cut + 1, path8.length - 4);
20773
+ }
20774
+ if (cut <= 0 || !rangeList(sel)) return false;
20775
+ let file2 = path8.slice(0, cut);
20776
+ if (file2.toLowerCase().endsWith(":raw")) file2 = file2.slice(0, -4);
20777
+ return file2.length > 1 || !asciiLetter(file2);
20778
+ }
20779
+ function rangeList(sel) {
20780
+ return sel !== "" && sel.split(",").every(rangeItem);
20781
+ }
20782
+ function rangeItem(item) {
20783
+ if (item.startsWith("-")) return digitsOnly(item.slice(1));
20784
+ let i = 0;
20785
+ while (i < item.length && digit(item[i])) i++;
20786
+ if (i === 0) return false;
20787
+ if (i === item.length) return true;
20788
+ const op = item[i];
20789
+ const rest = item.slice(i + 1);
20790
+ return op === "-" && (rest === "" || digitsOnly(rest)) || op === "+" && digitsOnly(rest);
20791
+ }
20792
+ function digitsOnly(s) {
20793
+ if (s === "") return false;
20794
+ for (const c of s) if (!digit(c)) return false;
20795
+ return true;
20796
+ }
20797
+ function digit(c) {
20798
+ return c >= "0" && c <= "9";
20799
+ }
20800
+ function asciiLetter(s) {
20801
+ const c = s.toLowerCase();
20802
+ return c.length === 1 && c >= "a" && c <= "z";
20803
+ }
20631
20804
  function replaceOutput(body, handleLine) {
20632
20805
  return body === "" ? handleLine : body + "\n" + handleLine;
20633
20806
  }
@@ -20762,7 +20935,7 @@ function buildChildEnv(parent, extra) {
20762
20935
  }
20763
20936
 
20764
20937
  // src/core/sandbox/runtimes.ts
20765
- import { accessSync, constants as fsConstants, statSync as statSync3 } from "node:fs";
20938
+ import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
20766
20939
  import path from "node:path";
20767
20940
 
20768
20941
  // src/core/sandbox/path-entries.ts
@@ -20804,22 +20977,34 @@ function fileNames(name, pathExt) {
20804
20977
  if (!isWin() || path.extname(name) !== "") return [name];
20805
20978
  return [...pathExt.map((ext) => name + ext), name];
20806
20979
  }
20807
- function isRunnable(full) {
20808
- const st = statSync3(full, { throwIfNoEntry: false });
20809
- if (st === void 0 || !st.isFile()) return false;
20980
+ function probe(full) {
20981
+ let st;
20982
+ try {
20983
+ st = statSync4(full, { throwIfNoEntry: false });
20984
+ } catch {
20985
+ return "unreadable";
20986
+ }
20987
+ if (st === void 0 || !st.isFile()) return "absent";
20810
20988
  if (isWin()) {
20811
20989
  const ext = path.extname(full).toLowerCase();
20812
- return ext === "" || WIN_STARTABLE_EXT.includes(ext);
20990
+ return ext === "" || WIN_STARTABLE_EXT.includes(ext) ? "runnable" : "absent";
20813
20991
  }
20814
20992
  try {
20815
20993
  accessSync(full, fsConstants.X_OK);
20816
- return true;
20994
+ return "runnable";
20817
20995
  } catch {
20818
- return false;
20996
+ return "absent";
20819
20997
  }
20820
20998
  }
20999
+ function isRunnable(full) {
21000
+ return probe(full) === "runnable";
21001
+ }
20821
21002
  function findRuntime(lang, env = process.env) {
20822
- if (isWin() && WIN_SHELL_LANGS.includes(lang)) return findGitBash(env);
21003
+ return lookupRuntime(lang, env).found;
21004
+ }
21005
+ function lookupRuntime(lang, env = process.env) {
21006
+ const unreadable = [];
21007
+ if (isWin() && WIN_SHELL_LANGS.includes(lang)) return { found: findGitBash(env), unreadable };
20823
21008
  const dirs = pathEntries(envValue(env, "PATH") ?? "", process.platform, path.delimiter);
20824
21009
  const pathExt = isWin() ? (envValue(env, "PATHEXT") ?? PATHEXT_DEFAULT).split(PATHEXT_SEPARATOR).filter((e) => e !== "") : [];
20825
21010
  const names = candidates(lang);
@@ -20828,13 +21013,15 @@ function findRuntime(lang, env = process.env) {
20828
21013
  for (const name of names) {
20829
21014
  for (const file2 of fileNames(name, pathExt)) {
20830
21015
  const full = path.join(dir, file2);
20831
- if (!isRunnable(full)) continue;
20832
- if (!isWin() || path.extname(full) !== "") return full;
21016
+ const state = probe(full);
21017
+ if (state === "unreadable") unreadable.push(full);
21018
+ if (state !== "runnable") continue;
21019
+ if (!isWin() || path.extname(full) !== "") return { found: full, unreadable };
20833
21020
  if (shim === null) shim = full;
20834
21021
  }
20835
21022
  }
20836
21023
  }
20837
- return shim;
21024
+ return { found: shim, unreadable };
20838
21025
  }
20839
21026
  function findGitBash(env) {
20840
21027
  const git2 = findRuntime(GIT_BIN, env);
@@ -20914,7 +21101,7 @@ function runProcess(argv, o) {
20914
21101
  let stopTimer;
20915
21102
  const kill = () => {
20916
21103
  if (child.pid !== void 0) killTree(child.pid);
20917
- if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
21104
+ if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(true), KILL_GRACE_MS);
20918
21105
  };
20919
21106
  const onAbort = () => {
20920
21107
  if (killedBy !== null || settled) return;
@@ -20943,15 +21130,21 @@ function runProcess(argv, o) {
20943
21130
  ...held ? { held: true } : {}
20944
21131
  });
20945
21132
  };
20946
- const finishHeld = () => {
21133
+ const finishHeld = (force = false) => {
20947
21134
  if (settled) return;
20948
- held = exited && killedBy === null;
20949
- child.stdout.destroy();
20950
- child.stderr.destroy();
20951
- if (child.pid !== void 0) killTree(child.pid);
20952
- settle3(child.exitCode);
21135
+ const seen = chunkCount;
21136
+ setImmediate(() => {
21137
+ if (settled || !force && chunkCount !== seen) return;
21138
+ held = exited && killedBy === null && !(child.stdout.readableEnded && child.stderr.readableEnded);
21139
+ child.stdout.destroy();
21140
+ child.stderr.destroy();
21141
+ if (child.pid !== void 0) killTree(child.pid);
21142
+ settle3(child.exitCode);
21143
+ });
20953
21144
  };
21145
+ let chunkCount = 0;
20954
21146
  const bump = () => {
21147
+ chunkCount++;
20955
21148
  if (!exited || settled) return;
20956
21149
  clearTimeout(graceTimer);
20957
21150
  graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
@@ -20969,7 +21162,7 @@ function runProcess(argv, o) {
20969
21162
  if (settled) return;
20970
21163
  exited = true;
20971
21164
  graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
20972
- drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
21165
+ drainTimer = setTimeout(() => finishHeld(true), PIPE_DRAIN_MAX_MS);
20973
21166
  });
20974
21167
  child.on("error", () => settle3(null));
20975
21168
  child.stdin.on("error", () => {
@@ -20982,7 +21175,7 @@ function runProcess(argv, o) {
20982
21175
  }
20983
21176
 
20984
21177
  // src/core/index/auto-memory.ts
20985
- import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
21178
+ import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync5 } from "node:fs";
20986
21179
  import { join as join9 } from "node:path";
20987
21180
  var MEMORY_FILES = Object.freeze([
20988
21181
  Object.freeze(["CLAUDE.md"]),
@@ -21008,7 +21201,7 @@ function readAutoMemory(project) {
21008
21201
  const path8 = join9(project.worktree, ...segs);
21009
21202
  if (!isInside(project.worktree, path8)) continue;
21010
21203
  try {
21011
- const st = statSync4(path8);
21204
+ const st = statSync5(path8);
21012
21205
  if (!st.isFile()) continue;
21013
21206
  rows.push({
21014
21207
  origin: "memory",
@@ -21078,15 +21271,42 @@ function sourceCount(db, scope, ctx, source) {
21078
21271
  });
21079
21272
  return Number(row5.n);
21080
21273
  }
21081
- function zeroHits(db, scope, ctx, source, mem, offset = 0) {
21082
- const n = sourceCount(db, scope, ctx, source) + mem.rows.length;
21274
+ function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
21275
+ const inScope = sourceCount(db, scope, ctx, source);
21276
+ const n = inScope + mem.rows.length;
21083
21277
  if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
21084
- return reply('No hits in scope "' + scope + '" across ' + n + " source(s).", false);
21278
+ const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
21279
+ const pick4 = nm.pick;
21280
+ if (pick4 === null || mem.named || inScope > 0) return reply(head2, false);
21281
+ if (pick4.id !== null) {
21282
+ const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
21283
+ return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
21284
+ }
21285
+ return reply(head2 + "\n" + unknownSource(db, scope, ctx, nm.arg), true);
21286
+ }
21287
+ var STORED_SOURCES = `
21288
+ SELECT MAX(id) AS id, label FROM sources
21289
+ WHERE (:scope <> 'session' OR session_id = :session_id)
21290
+ AND (:scope <> 'worktree' OR worktree = :worktree)
21291
+ GROUP BY label ORDER BY MAX(id) DESC LIMIT :limit`;
21292
+ var STORED_SOURCES_SHOWN = 5;
21293
+ function unknownSource(db, scope, ctx, given) {
21294
+ const line = "Source " + JSON.stringify(given) + ' is not a stored source in scope "' + scope + '".';
21295
+ const rows = db.raw.prepare(STORED_SOURCES).all({
21296
+ scope,
21297
+ session_id: ctx.sessionId,
21298
+ worktree: ctx.project.worktree,
21299
+ limit: STORED_SOURCES_SHOWN + 1
21300
+ });
21301
+ if (rows.length === 0) return line + '\nctx_index stores one: ctx_index({content:"...", source:' + JSON.stringify(given) + "}).";
21302
+ const names = rows.slice(0, STORED_SOURCES_SHOWN).map((r) => isLongLabel(r.label) ? sourceHandle(Number(r.id)) : JSON.stringify(r.label));
21303
+ const more = rows.length > STORED_SOURCES_SHOWN ? ", ..." : "";
21304
+ return line + "\nStored sources, newest first: " + names.join(", ") + more + ". " + callText([], scope, void 0, 'sort:"timeline"') + " lists them all.";
21085
21305
  }
21086
21306
  function named(given, pick4) {
21087
- if (given === void 0 || pick4 === null) return { arg: given, note: null };
21307
+ if (given === void 0 || pick4 === null) return { arg: given, note: null, pick: null };
21088
21308
  const arg = pick4.id !== null && isLongLabel(given) ? sourceHandle(pick4.id) : given;
21089
- return { arg, note: collisionLine(given, pick4) };
21309
+ return { arg, note: collisionLine(given, pick4), pick: pick4 };
21090
21310
  }
21091
21311
  function sourceCard(db, id, input, scope, arg) {
21092
21312
  const row5 = sourceCardRow(db, id);
@@ -21218,7 +21438,7 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
21218
21438
  });
21219
21439
  const take = fetched.map((h) => replyHits(h, size));
21220
21440
  const pages = fetched.map((h, i) => h.slice(0, take[i]));
21221
- if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
21441
+ if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries, offset);
21222
21442
  const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
21223
21443
  let reserve = 0;
21224
21444
  for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
@@ -21288,7 +21508,7 @@ function timelineLine(r) {
21288
21508
  }
21289
21509
  function timeline(db, input, scope, ctx, nm, ms) {
21290
21510
  const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
21291
- if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
21511
+ if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries);
21292
21512
  const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
21293
21513
  const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
21294
21514
  const lines = nm.note === null ? [] : [nm.note];
@@ -21591,8 +21811,8 @@ var ctxBatch = Object.freeze({
21591
21811
  });
21592
21812
 
21593
21813
  // src/core/tools/doctor.ts
21594
- import { readdirSync as readdirSync8, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
21595
- import { basename as basename5, join as join19 } from "node:path";
21814
+ import { readdirSync as readdirSync8, readFileSync as readFileSync17, existsSync as existsSync17 } from "node:fs";
21815
+ import { basename as basename5, join as join20 } from "node:path";
21596
21816
 
21597
21817
  // src/core/ops/bundle-dir.ts
21598
21818
  import { existsSync as existsSync4 } from "node:fs";
@@ -21617,8 +21837,8 @@ function ownBundleDir() {
21617
21837
  }
21618
21838
 
21619
21839
  // src/core/ops/doctor-config.ts
21620
- import { existsSync as existsSync9, readdirSync as readdirSync6, readFileSync as readFileSync11 } from "node:fs";
21621
- import { dirname as dirname8, isAbsolute as isAbsolute4, join as join14, resolve as resolve9 } from "node:path";
21840
+ import { existsSync as existsSync11, readdirSync as readdirSync6, readFileSync as readFileSync13 } from "node:fs";
21841
+ import { dirname as dirname8, isAbsolute as isAbsolute5, join as join16, resolve as resolve9 } from "node:path";
21622
21842
 
21623
21843
  // src/core/ops/detect-v1.ts
21624
21844
  import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync8 } from "node:fs";
@@ -23673,16 +23893,16 @@ function parseTOML(code, options) {
23673
23893
  }
23674
23894
 
23675
23895
  // src/core/ops/atomic-file.ts
23676
- import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
23896
+ import { mkdirSync as mkdirSync3, renameSync as renameSync2, unlinkSync, writeFileSync } from "node:fs";
23677
23897
  import path3 from "node:path";
23678
23898
  function sleepSync(ms) {
23679
23899
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
23680
23900
  }
23681
- function errCode(e) {
23901
+ function errCode2(e) {
23682
23902
  return e.code;
23683
23903
  }
23684
23904
  function renameWithRetry(from, to, opts = {}) {
23685
- const rename = opts.rename ?? renameSync;
23905
+ const rename = opts.rename ?? renameSync2;
23686
23906
  const sleep2 = opts.sleep ?? sleepSync;
23687
23907
  const win = (opts.platform ?? process.platform) === "win32";
23688
23908
  for (let attempt = 0; ; attempt += 1) {
@@ -23690,7 +23910,7 @@ function renameWithRetry(from, to, opts = {}) {
23690
23910
  rename(from, to);
23691
23911
  return;
23692
23912
  } catch (e) {
23693
- const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode(e) ?? "");
23913
+ const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
23694
23914
  if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw e;
23695
23915
  sleep2(ATOMIC_RENAME_DELAY_MS);
23696
23916
  }
@@ -23705,15 +23925,15 @@ function unlinkWithRetry(file2, opts = {}) {
23705
23925
  unlink(file2);
23706
23926
  return;
23707
23927
  } catch (e) {
23708
- if (errCode(e) === "ENOENT") return;
23709
- const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode(e) ?? "");
23928
+ if (errCode2(e) === "ENOENT") return;
23929
+ const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
23710
23930
  if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw replaceFailure(file2, e);
23711
23931
  sleep2(ATOMIC_RENAME_DELAY_MS);
23712
23932
  }
23713
23933
  }
23714
23934
  }
23715
23935
  function replaceFailure(file2, e) {
23716
- const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode(e) ?? "");
23936
+ const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
23717
23937
  const cause = e.message;
23718
23938
  return new Error(busy ? `Could not replace ${file2}: ${cause}. Fix: close the program using ${file2}, then re-run` : `Could not write ${file2}: ${cause}. Fix: check the path and its permissions, then re-run`, { cause: e });
23719
23939
  }
@@ -24607,6 +24827,14 @@ function configEntryRoot(adapter, env) {
24607
24827
  if (typeof script !== "string" || !isAbsolute3(script)) throw missing(adapter.id, file2);
24608
24828
  return dirname7(script);
24609
24829
  }
24830
+ function packageDirOf(dir) {
24831
+ for (let cur = dir; ; ) {
24832
+ if (existsSync7(join13(cur, D1_PACKAGE_FILE))) return cur;
24833
+ const up = dirname7(cur);
24834
+ if (up === cur) return dir;
24835
+ cur = up;
24836
+ }
24837
+ }
24610
24838
  function candidate(adapter, env, worktree) {
24611
24839
  switch (adapter.installMode) {
24612
24840
  case "marketplace":
@@ -24620,7 +24848,7 @@ function candidate(adapter, env, worktree) {
24620
24848
  case "plugin":
24621
24849
  return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
24622
24850
  case "in-process":
24623
- return dirname7(fileURLToPath2(import.meta.url));
24851
+ return packageDirOf(dirname7(fileURLToPath2(import.meta.url)));
24624
24852
  }
24625
24853
  }
24626
24854
  function resolvePluginRoot(adapter, env, worktree) {
@@ -24701,14 +24929,281 @@ function piInstalledIn(env, home, pkgDir, cwd) {
24701
24929
  return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
24702
24930
  }
24703
24931
 
24932
+ // src/core/ops/doctor-env.ts
24933
+ import { existsSync as existsSync9, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
24934
+ import { isAbsolute as isAbsolute4, join as join14, relative as relative4 } from "node:path";
24935
+ function pass(id, detail = DOCTOR_PASS_DETAIL) {
24936
+ return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
24937
+ }
24938
+ function unknown2(id, detail, fixCommand) {
24939
+ return fixCommand === void 0 ? { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail } : { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail, fixCommand };
24940
+ }
24941
+ function fail2(id, detail, fixCommand) {
24942
+ return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
24943
+ }
24944
+ function warn(id, detail, fixCommand) {
24945
+ return { id, label: DOCTOR_LABEL[id], status: "WARN", detail, fixCommand };
24946
+ }
24947
+ function bundleVersion(bundleDir2) {
24948
+ try {
24949
+ const v = JSON.parse(readFileSync11(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24950
+ return typeof v === "string" && v !== "" ? v : void 0;
24951
+ } catch {
24952
+ return void 0;
24953
+ }
24954
+ }
24955
+ function channelOf(version4) {
24956
+ const at2 = version4.indexOf(D1_PRERELEASE_SEP);
24957
+ if (at2 < 0) return D1_DEFAULT_TAG;
24958
+ const pre = version4.slice(at2 + 1);
24959
+ const dot = pre.indexOf(".");
24960
+ const tag2 = dot < 0 ? pre : pre.slice(0, dot);
24961
+ return tag2 === "" ? D1_DEFAULT_TAG : tag2;
24962
+ }
24963
+ function firstLine3(b) {
24964
+ const text = b.toString("utf8").trim();
24965
+ const nl = text.indexOf("\n");
24966
+ return (nl < 0 ? text : text.slice(0, nl)).trim();
24967
+ }
24968
+ function gitCause(r, timeoutMs) {
24969
+ if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
24970
+ if (r.killed === "cancel") return D1_GIT_CANCEL;
24971
+ if (r.exitCode === null) return D1_GIT_NO_START;
24972
+ return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
24973
+ }
24974
+ function fetchCause(err, timeoutMs) {
24975
+ const name = err instanceof Error ? err.name : "";
24976
+ if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
24977
+ const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
24978
+ const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
24979
+ const msg = cause instanceof Error ? cause.message : String(cause);
24980
+ const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
24981
+ return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
24982
+ }
24983
+ async function npmLatest(url4, tag2, signal, timeoutMs) {
24984
+ try {
24985
+ const res = await fetch(url4, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
24986
+ if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
24987
+ const body = await res.json();
24988
+ const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
24989
+ return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
24990
+ } catch (err) {
24991
+ return { ok: false, cause: fetchCause(err, timeoutMs) };
24992
+ }
24993
+ }
24994
+ function digits(s) {
24995
+ if (s === "") return false;
24996
+ for (const ch of s) if (ch < "0" || ch > "9") return false;
24997
+ return true;
24998
+ }
24999
+ function parseVersion(v) {
25000
+ const at2 = v.indexOf(D1_PRERELEASE_SEP);
25001
+ const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
25002
+ if (core.length !== 3 || !core.every(digits)) return null;
25003
+ const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
25004
+ if (at2 < 0) return { core: nums, pre: [] };
25005
+ const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
25006
+ if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
25007
+ if (pre.length === 1) return { core: nums, pre: [pre[0]] };
25008
+ return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
25009
+ }
25010
+ function sign(n) {
25011
+ return n < 0 ? -1 : n > 0 ? 1 : 0;
25012
+ }
25013
+ function compareVersions(a, b) {
25014
+ const x = parseVersion(a);
25015
+ const y = parseVersion(b);
25016
+ if (x === null || y === null) return null;
25017
+ for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
25018
+ if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
25019
+ if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
25020
+ return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
25021
+ }
25022
+ function highestTag(stdout, tag2) {
25023
+ let best;
25024
+ for (const line of stdout.split("\n")) {
25025
+ const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
25026
+ if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
25027
+ const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
25028
+ if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
25029
+ if (best === void 0 || compareVersions(v, best) === 1) best = v;
25030
+ }
25031
+ return best;
25032
+ }
25033
+ function versionRow(head2, installed, tag2, source, latest, tail, update) {
25034
+ const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
25035
+ if (cmp === 0) return pass("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
25036
+ if (cmp > 0) return pass("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
25037
+ return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
25038
+ }
25039
+ async function checkVersion(i) {
25040
+ if (i.bundleSha === void 0) return unknown2("D1", D1_DEV_BUILD_DETAIL);
25041
+ const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
25042
+ if (i.version === void 0) return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
25043
+ const tag2 = channelOf(i.version);
25044
+ const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
25045
+ const git2 = findRuntime(GIT_BIN, i.env);
25046
+ const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
25047
+ if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
25048
+ let cause = D1_GIT_MISSING;
25049
+ if (git2 !== null) {
25050
+ const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
25051
+ cwd: i.cwd,
25052
+ env: { ...i.env, ...GIT_NO_PROMPT_ENV },
25053
+ signal: i.signal,
25054
+ timeoutMs: i.timeoutMs
25055
+ });
25056
+ if (r.exitCode === 0 && r.killed === null) {
25057
+ const latest = highestTag(r.stdout.toString("utf8"), tag2);
25058
+ if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
25059
+ cause = D1_GIT_NO_TAG(tag2);
25060
+ } else {
25061
+ cause = gitCause(r, i.timeoutMs);
25062
+ }
25063
+ }
25064
+ return unknown2("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
25065
+ }
25066
+ function numbers(v) {
25067
+ const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
25068
+ return bare2.split(NODE_VERSION_SEP).map(Number);
25069
+ }
25070
+ function belowMin(version4) {
25071
+ const got = numbers(version4);
25072
+ const min = numbers(NODE_MIN);
25073
+ for (let k = 0; k < min.length; k++) {
25074
+ const g = got[k] ?? 0;
25075
+ if (g !== min[k]) return g < min[k];
25076
+ }
25077
+ return false;
25078
+ }
25079
+ async function sqliteLoads() {
25080
+ try {
25081
+ await import(SQLITE_MODULE);
25082
+ return true;
25083
+ } catch {
25084
+ return false;
25085
+ }
25086
+ }
25087
+ async function checkNode(i) {
25088
+ const bun = i.bunVersion === void 0 ? [] : [D2_BUN_DETAIL(i.bunVersion)];
25089
+ const withBun = (detail) => [detail, ...bun].join(D4_REASON_JOIN);
25090
+ if (belowMin(i.nodeVersion)) return fail2("D2", withBun(D2_NODE_DETAIL(i.nodeVersion)), D2_NODE_FIX);
25091
+ if (!await sqliteLoads()) return fail2("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
25092
+ return pass("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
25093
+ }
25094
+ function checkMcp(ctx, adapter) {
25095
+ const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
25096
+ const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
25097
+ if (named2 || versioned) return pass("D6");
25098
+ return adapter?.installMode === "in-process" ? pass("D6", D6_IN_PROCESS_DETAIL) : unknown2("D6", D6_UNKNOWN_DETAIL);
25099
+ }
25100
+ function piCwdInside(worktree, piCwd) {
25101
+ if (piCwd === void 0 || !existsSync9(piCwd)) return false;
25102
+ const rel = relative4(worktree, realpathSync6.native(piCwd));
25103
+ return rel === "" || !rel.startsWith("..") && !isAbsolute4(rel);
25104
+ }
25105
+ function checkProject(i) {
25106
+ const bad = fail2("D7", D7_DETAIL(i.project.source), D7_FIX);
25107
+ if (i.project.source !== i.adapter.projectSource) return bad;
25108
+ if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
25109
+ return pass("D7");
25110
+ }
25111
+ function checkMode(adapter, hostPermission) {
25112
+ if (hostPermission === "missing") return fail2("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
25113
+ if (hostPermission === "wired") return pass("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
25114
+ return pass("D10", D10_DETAIL(adapter.denyChannel));
25115
+ }
25116
+ function checkShell(env) {
25117
+ const win = process.platform === "win32";
25118
+ const shell = findRuntime("shell", env);
25119
+ if (shell !== null) return pass("D11", D11_PASS_DETAIL(shell, win));
25120
+ return win ? fail2("D11", D11_WIN_DETAIL, D11_WIN_FIX) : fail2("D11", D11_POSIX_DETAIL, D11_POSIX_FIX);
25121
+ }
25122
+ function checkRuntimes(env, shellRow) {
25123
+ if (shellRow.status !== "PASS") return shellRow;
25124
+ for (const lang of EXEC_LANGUAGES) {
25125
+ if (lang === "shell") continue;
25126
+ const r = lookupRuntime(lang, env);
25127
+ if (r.found === null && r.unreadable.length > 0) return warn("D11", D11_RUNTIME_DETAIL(lang, r.unreadable), D11_RUNTIME_FIX(lang));
25128
+ }
25129
+ return shellRow;
25130
+ }
25131
+
25132
+ // src/core/ops/omp-import.ts
25133
+ import { join as join15 } from "node:path";
25134
+ var { existsSync: existsSync10, readFileSync: readFileSync12 } = process.getBuiltinModule("node:fs");
25135
+ var OMP_DISABLED_SERVERS_KEY = "disabledServers";
25136
+ var OMP_MCP_FILE = "mcp.json";
25137
+ var OMP_CONFIG_FILE = "config.yml";
25138
+ var ENABLED_PROVIDERS = "enabledProviders";
25139
+ var DISABLED_PROVIDERS = "disabledProviders";
25140
+ var CLAUDE_PROVIDER = "claude";
25141
+ var ALL_PROVIDERS = ["*", "all"];
25142
+ function ompImportFiles(home) {
25143
+ const agentDir = join15(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
25144
+ return { config: join15(agentDir, OMP_CONFIG_FILE), mcp: join15(agentDir, OMP_MCP_FILE), claude: join15(home, CLAUDE_USER_CONFIG_FILE) };
25145
+ }
25146
+ function readText2(file2) {
25147
+ try {
25148
+ return existsSync10(file2) ? hostText(readFileSync12(file2, "utf8")) : void 0;
25149
+ } catch {
25150
+ return void 0;
25151
+ }
25152
+ }
25153
+ var unquote3 = (s) => {
25154
+ const t = s.trim();
25155
+ const q = t[0];
25156
+ return (q === '"' || q === "'") && t.endsWith(q) && t.length > 1 ? t.slice(1, -1) : t;
25157
+ };
25158
+ var withoutComment = (s) => {
25159
+ const at2 = s.indexOf(" #");
25160
+ return at2 === -1 ? s : s.slice(0, at2);
25161
+ };
25162
+ function yamlTopList(text, key) {
25163
+ const lines = text.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
25164
+ const head2 = `${key}:`;
25165
+ const at2 = lines.findIndex((l) => l.startsWith(head2));
25166
+ if (at2 === -1) return [];
25167
+ const rest = withoutComment(lines[at2].slice(head2.length)).trim();
25168
+ if (rest.startsWith("[")) {
25169
+ const end = rest.indexOf("]");
25170
+ return (end === -1 ? rest.slice(1) : rest.slice(1, end)).split(",").map(unquote3).filter((x) => x !== "");
25171
+ }
25172
+ if (rest !== "") return [];
25173
+ const out = [];
25174
+ for (const line of lines.slice(at2 + 1)) {
25175
+ const t = line.trim();
25176
+ if (t === "" || t.startsWith("#")) continue;
25177
+ if (line === line.trimStart() && !t.startsWith("-")) break;
25178
+ if (!t.startsWith("-")) break;
25179
+ out.push(unquote3(withoutComment(t.slice(1))));
25180
+ }
25181
+ return out;
25182
+ }
25183
+ function ompImportsUs(files, env) {
25184
+ const config4 = readText2(files.config) ?? "";
25185
+ if (yamlTopList(config4, DISABLED_PROVIDERS).includes(CLAUDE_PROVIDER)) return false;
25186
+ const enabled = yamlTopList(config4, ENABLED_PROVIDERS);
25187
+ const dirSet = env[CLAUDE_CONFIG_DIR_ENV] !== void 0 && env[CLAUDE_CONFIG_DIR_ENV] !== "";
25188
+ if (!dirSet && !enabled.some((p) => p === CLAUDE_PROVIDER || ALL_PROVIDERS.includes(p))) return false;
25189
+ const claude = readText2(files.claude);
25190
+ if (claude === void 0) return false;
25191
+ try {
25192
+ const servers = JSON.parse(claude)[MCP_SERVERS_KEY];
25193
+ return typeof servers === "object" && servers !== null && Object.hasOwn(servers, SERVER_KEY);
25194
+ } catch {
25195
+ return false;
25196
+ }
25197
+ }
25198
+
24704
25199
  // src/core/ops/doctor-config.ts
24705
25200
  var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
24706
25201
  var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
24707
25202
  var list2 = (v) => Array.isArray(v) ? v : [];
24708
- function pass(id) {
25203
+ function pass2(id) {
24709
25204
  return { id, label: DOCTOR_LABEL[id], status: "PASS", detail: DOCTOR_PASS_DETAIL };
24710
25205
  }
24711
- function fail2(id, detail, fixCommand) {
25206
+ function fail3(id, detail, fixCommand) {
24712
25207
  return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
24713
25208
  }
24714
25209
  function readParsed(agent, file2) {
@@ -24778,11 +25273,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
24778
25273
  var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
24779
25274
  function mcpFile(row5, home, env) {
24780
25275
  const spec = OWN_MCP_ENTRY[row5.id];
24781
- if (row5.id === "codex") return join14(codexDirOf(env, home), CONFIG_TOML_FILE);
25276
+ if (row5.id === "codex") return join16(codexDirOf(env, home), CONFIG_TOML_FILE);
24782
25277
  if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
24783
- if (row5.id === "opencode") return join14(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
25278
+ if (row5.id === "opencode") return join16(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
24784
25279
  if (row5.id === "pi") {
24785
- return join14(piAgentDirOf(env, home), SETTINGS_FILE);
25280
+ return join16(piAgentDirOf(env, home), SETTINGS_FILE);
24786
25281
  }
24787
25282
  return null;
24788
25283
  }
@@ -24795,27 +25290,27 @@ function codexNativeDir(env, home) {
24795
25290
  const codexDir = codexDirOf(env, home);
24796
25291
  let enabled;
24797
25292
  try {
24798
- enabled = hostConfigValueAt(readParsed("codex", join14(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
25293
+ enabled = hostConfigValueAt(readParsed("codex", join16(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
24799
25294
  } catch {
24800
25295
  return null;
24801
25296
  }
24802
25297
  if (enabled !== true) return null;
24803
- const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24804
- if (!existsSync9(cache)) return null;
25298
+ const cache = join16(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
25299
+ if (!existsSync11(cache)) return null;
24805
25300
  const found = [];
24806
25301
  for (const market of readdirSync6(cache)) {
24807
- const plugin = join14(cache, market, SERVER_KEY);
24808
- if (!existsSync9(plugin)) continue;
25302
+ const plugin = join16(cache, market, SERVER_KEY);
25303
+ if (!existsSync11(plugin)) continue;
24809
25304
  for (const version4 of readdirSync6(plugin).sort()) {
24810
- const dir = join14(plugin, version4, CODEX_PLUGIN_SUBDIR);
24811
- if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
25305
+ const dir = join16(plugin, version4, CODEX_PLUGIN_SUBDIR);
25306
+ if (existsSync11(join16(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24812
25307
  }
24813
25308
  }
24814
25309
  return found.length === 0 ? null : found[found.length - 1];
24815
25310
  }
24816
25311
  function nativeMcpWrong(dir, row5) {
24817
25312
  try {
24818
- const entry = hostConfigValueAt(readParsed(row5.id, join14(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
25313
+ const entry = hostConfigValueAt(readParsed(row5.id, join16(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
24819
25314
  if (!isObject4(entry)) return true;
24820
25315
  const args = list2(entry[MCP_ARGS_FIELD]);
24821
25316
  const script = args[0];
@@ -24886,17 +25381,17 @@ function opencodePluginDirs(configDir, worktree) {
24886
25381
  return [configDir, opencodeProjectDir(worktree)];
24887
25382
  }
24888
25383
  function opencodeProjectDir(worktree) {
24889
- return join14(worktree, OPENCODE_PROJECT_DIR);
25384
+ return join16(worktree, OPENCODE_PROJECT_DIR);
24890
25385
  }
24891
25386
  function packageResolves(fromDir) {
24892
25387
  for (let d = fromDir; ; d = dirname8(d)) {
24893
- if (existsSync9(join14(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
25388
+ if (existsSync11(join16(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
24894
25389
  if (dirname8(d) === d) return false;
24895
25390
  }
24896
25391
  }
24897
25392
  function opencodeDirPlugins(dirs) {
24898
25393
  const bundle = opencodePluginFile();
24899
- const ownFile = join14(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
25394
+ const ownFile = join16(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
24900
25395
  const isModule = (p) => OWN_PLUGIN_MODULES.includes(p);
24901
25396
  const isPath = (p) => {
24902
25397
  if (p === ownFile || p === `${FILE_URL_PREFIX}${ownFile}`) return true;
@@ -24906,7 +25401,7 @@ function opencodeDirPlugins(dirs) {
24906
25401
  };
24907
25402
  const out = [];
24908
25403
  for (const dir of dirs) {
24909
- const pdir = join14(dir, OPENCODE_PLUGINS_DIR);
25404
+ const pdir = join16(dir, OPENCODE_PLUGINS_DIR);
24910
25405
  let names;
24911
25406
  try {
24912
25407
  names = readdirSync6(pdir);
@@ -24914,12 +25409,12 @@ function opencodeDirPlugins(dirs) {
24914
25409
  continue;
24915
25410
  }
24916
25411
  for (const name of names) {
24917
- const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join14(pdir, name)] : [];
24918
- const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join14(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
25412
+ const loose = OPENCODE_PLUGIN_EXTS.some((x) => name.endsWith(x)) ? [join16(pdir, name)] : [];
25413
+ const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x) => join16(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x}`))];
24919
25414
  for (const f of files) {
24920
25415
  let text;
24921
25416
  try {
24922
- const b = readFileSync11(f);
25417
+ const b = readFileSync13(f);
24923
25418
  if (b.length > OPENCODE_DIR_FILE_MAX) continue;
24924
25419
  text = b.toString("utf8");
24925
25420
  } catch {
@@ -24930,7 +25425,7 @@ function opencodeDirPlugins(dirs) {
24930
25425
  const loads = lits.some((p) => {
24931
25426
  if (isModule(p)) return packageResolves(dirname8(f));
24932
25427
  const bare2 = p.startsWith(FILE_URL_PREFIX) ? p.slice(FILE_URL_PREFIX.length) : p;
24933
- return existsSync9(isAbsolute4(bare2) ? bare2 : resolve9(dirname8(f), bare2));
25428
+ return existsSync11(isAbsolute5(bare2) ? bare2 : resolve9(dirname8(f), bare2));
24934
25429
  });
24935
25430
  out.push({ file: f, loads });
24936
25431
  }
@@ -24948,19 +25443,19 @@ function opencodeMcpOwn(entry) {
24948
25443
  return isNodeCommand(node3) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
24949
25444
  }
24950
25445
  function opencodeFileValue(file2) {
24951
- if (!existsSync9(file2)) return {};
24952
- return parseHostConfig("opencode", file2, hostText(readFileSync11(file2, "utf8")), "jsonc");
25446
+ if (!existsSync11(file2)) return {};
25447
+ return parseHostConfig("opencode", file2, hostText(readFileSync13(file2, "utf8")), "jsonc");
24953
25448
  }
24954
25449
  function opencodeValueListed(value) {
24955
25450
  const bundle = opencodePluginFile();
24956
- const own4 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
25451
+ const own4 = [bundle, join16(bundle, ...OPENCODE_PLUGIN_PATH)];
24957
25452
  if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
24958
25453
  const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
24959
25454
  return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
24960
25455
  }
24961
25456
  function opencodeListed(file2, worktree) {
24962
25457
  const dirs = [dirname8(file2), worktree];
24963
- if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join14(dir, name)))))) return true;
25458
+ if (dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join16(dir, name)))))) return true;
24964
25459
  return opencodeDirPlugin(opencodePluginDirs(dirname8(file2), worktree)) !== void 0;
24965
25460
  }
24966
25461
  function mcpWrong(row5, home, env, worktree) {
@@ -24982,7 +25477,7 @@ function mcpWrong(row5, home, env, worktree) {
24982
25477
  function hookFile(row5, spec, home, env, worktree) {
24983
25478
  const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
24984
25479
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
24985
- const file2 = native !== null ? join14(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join14(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join14(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join14(kiroDirOf(env, home), ...spec.file.slice(1)) : join14(root, ...spec.file);
25480
+ const file2 = native !== null ? join16(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join16(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join16(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join16(kiroDirOf(env, home), ...spec.file.slice(1)) : join16(root, ...spec.file);
24986
25481
  return file2;
24987
25482
  }
24988
25483
  function hookParts(row5, home, env, worktree) {
@@ -24993,7 +25488,7 @@ function hookParts(row5, home, env, worktree) {
24993
25488
  const file2 = hookFile(row5, spec, home, env, worktree);
24994
25489
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
24995
25490
  if (row5.id === "codex") {
24996
- const config4 = readParsed(row5.id, join14(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
25491
+ const config4 = readParsed(row5.id, join16(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
24997
25492
  if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
24998
25493
  }
24999
25494
  } catch {
@@ -25022,29 +25517,67 @@ function hookParts(row5, home, env, worktree) {
25022
25517
  }
25023
25518
  function checkHostConfig(row5, env, worktree) {
25024
25519
  const home = homeDirOf(env);
25025
- if (home === null) return fail2("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
25520
+ if (home === null) return fail3("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
25026
25521
  if (row5.installMode === "marketplace") {
25027
25522
  const choice = marketplaceChoice(env, worktree);
25028
- if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
25523
+ if ("installs" in choice) return fail3("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
25029
25524
  }
25030
25525
  if (row5.id === "pi") return checkPiInstall(env, home, worktree);
25526
+ if (row5.id === "omp") return checkOmpInstall(home);
25031
25527
  const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
25032
- if (parts.length === 0) return pass("D3");
25528
+ if (parts.length === 0) return pass2("D3");
25033
25529
  const detail = D3_DETAIL(parts);
25034
25530
  const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
25035
- return fail2("D3", detail, fix);
25531
+ return fail3("D3", detail, fix);
25036
25532
  }
25037
25533
  function checkPiInstall(env, home, worktree) {
25038
25534
  const found = piInstalledIn(env, home, ownBundleDir(), worktree);
25039
- if (found !== void 0) return { ...pass("D3"), detail: found };
25040
- return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join14(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
25535
+ if (found !== void 0) return { ...pass2("D3"), detail: found };
25536
+ return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join16(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
25537
+ }
25538
+ var OMP_PLUGINS_DIR = "plugins";
25539
+ var OMP_LOCK_FILE = "omp-plugins.lock.json";
25540
+ function readJson2(file2) {
25541
+ try {
25542
+ const doc = JSON.parse(readFileSync13(file2, "utf8"));
25543
+ return typeof doc === "object" && doc !== null ? doc : void 0;
25544
+ } catch {
25545
+ return void 0;
25546
+ }
25547
+ }
25548
+ function ownEntry(doc, key) {
25549
+ const map2 = doc?.[key];
25550
+ return typeof map2 === "object" && map2 !== null ? map2[SERVER_KEY] : void 0;
25551
+ }
25552
+ function checkOmpInstall(home) {
25553
+ const dir = join16(home, ...AGENT_HOME_DIR.omp, OMP_PLUGINS_DIR);
25554
+ const lock = join16(dir, OMP_LOCK_FILE);
25555
+ const pkg = join16(dir, PI_PACKAGE_JSON_FILE);
25556
+ const entry = ownEntry(readJson2(lock), "plugins");
25557
+ const missing2 = (file2) => fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + file2, NATIVE_INSTALL.omp[0]);
25558
+ if (typeof entry !== "object" || entry === null) return missing2(lock);
25559
+ if (ownEntry(readJson2(pkg), "dependencies") === void 0) return missing2(pkg);
25560
+ if (entry.enabled !== true) return fail3("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + lock, OMP_ENABLE_COMMAND);
25561
+ return { ...pass2("D3"), detail: lock };
25562
+ }
25563
+ function ompInfoLines(env, version4) {
25564
+ const out = [];
25565
+ if (version4 !== void 0 && compareVersions(version4, OMP_MIN_VERSION) === -1) out.push(OMP_FLOOR_INFO(version4));
25566
+ out.push(OMP_CONTENT_INFO, OMP_PRINT_MODE_INFO, OMP_SCRIPTS_INFO);
25567
+ const home = homeDirOf(env);
25568
+ if (home === null) return out;
25569
+ const files = ompImportFiles(home);
25570
+ if (!ompImportsUs(files, env)) return out;
25571
+ const listed = readJson2(files.mcp)?.[OMP_DISABLED_SERVERS_KEY];
25572
+ if (!(Array.isArray(listed) && listed.includes(SERVER_KEY))) out.push(OMP_IMPORT_INFO(files.claude, files.mcp));
25573
+ return out;
25041
25574
  }
25042
25575
  function checkV1Leftovers(agent, home, scope = {}) {
25043
25576
  const findings = detectV1(agent, home, scope);
25044
- if (findings.length === 0) return pass("D4");
25577
+ if (findings.length === 0) return pass2("D4");
25045
25578
  const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
25046
- if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
25047
- return { ...fail2("D4", detail, DOCTOR_FIX_UPGRADE), status: "WARN" };
25579
+ if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass2("D4"), detail };
25580
+ return { ...fail3("D4", detail, DOCTOR_FIX_UPGRADE), status: "WARN" };
25048
25581
  }
25049
25582
  function parsedOrNull(agent, file2, jsonc) {
25050
25583
  try {
@@ -25055,13 +25588,13 @@ function parsedOrNull(agent, file2, jsonc) {
25055
25588
  }
25056
25589
  }
25057
25590
  function checkDoubleFire(agent, worktree) {
25058
- if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
25059
- const claude = parsedOrNull(agent, join14(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
25591
+ if (agent !== "claude-code" && agent !== "vscode") return pass2("D5b");
25592
+ const claude = parsedOrNull(agent, join16(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
25060
25593
  const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
25061
25594
  const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
25062
- const vscode = parsedOrNull(agent, join14(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
25595
+ const vscode = parsedOrNull(agent, join16(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
25063
25596
  const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
25064
- return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
25597
+ return hooksOn && useClaudeHooks ? fail3("D5b", D5B_DETAIL, D5B_FIX) : pass2("D5b");
25065
25598
  }
25066
25599
  function configPaths(row5, env, worktree) {
25067
25600
  const home = homeDirOf(env);
@@ -25070,7 +25603,7 @@ function configPaths(row5, env, worktree) {
25070
25603
  const mcp = mcpFile(row5, home, env);
25071
25604
  if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
25072
25605
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
25073
- if (native !== null) out.push({ label: "Codex plugin MCP", path: join14(native, CODEX_PLUGIN_MCP_FILE) });
25606
+ if (native !== null) out.push({ label: "Codex plugin MCP", path: join16(native, CODEX_PLUGIN_MCP_FILE) });
25074
25607
  const spec = HOOK_HOST_FILE[row5.id];
25075
25608
  if (spec !== null) {
25076
25609
  try {
@@ -25090,10 +25623,10 @@ function configPaths(row5, env, worktree) {
25090
25623
  }
25091
25624
 
25092
25625
  // src/core/ops/doctor-db.ts
25093
- import { existsSync as existsSync10, statSync as statSync5 } from "node:fs";
25094
- var unknown2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
25095
- var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
25096
- var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
25626
+ import { existsSync as existsSync12, statSync as statSync6 } from "node:fs";
25627
+ var unknown3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
25628
+ var pass3 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
25629
+ var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
25097
25630
  function isCorrupt2(err) {
25098
25631
  if (typeof err !== "object" || err === null) return false;
25099
25632
  const code = err.errcode;
@@ -25132,17 +25665,17 @@ function orphanFiles(dbPath) {
25132
25665
  const files = [];
25133
25666
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
25134
25667
  const path8 = dbPath + suffix;
25135
- if (existsSync10(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
25668
+ if (existsSync12(path8)) files.push({ path: path8, bytes: statSync6(path8).size });
25136
25669
  }
25137
- return files.length > 0 && !existsSync10(dbPath) ? files : [];
25670
+ return files.length > 0 && !existsSync12(dbPath) ? files : [];
25138
25671
  }
25139
25672
  async function checkDb(project) {
25140
25673
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
25141
25674
  const orphan = orphanFiles(project.dbPath);
25142
- if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
25143
- if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
25675
+ if (orphan.length > 0) return { row: fail4(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
25676
+ if (!existsSync12(project.dbPath)) return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
25144
25677
  const sqlite = await loadSqlite2();
25145
- if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
25678
+ if (sqlite === null) return { row: unknown3("D8", D2_SQLITE_DETAIL), ...clean };
25146
25679
  let raw = null;
25147
25680
  try {
25148
25681
  raw = openRead(sqlite, project.dbPath);
@@ -25155,226 +25688,35 @@ async function checkDb(project) {
25155
25688
  }
25156
25689
  const schemaStale = got !== null && got !== SCHEMA_VERSION;
25157
25690
  const integrityFailed = failsOnCorrupt(() => !integrityOk(db));
25158
- if (integrityFailed) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
25159
- if (schemaStale && got !== null) return { row: fail3(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
25160
- return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
25691
+ if (integrityFailed) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale, integrityFailed, orphan: [] };
25692
+ if (schemaStale && got !== null) return { row: fail4(D8_STALE_SCHEMA_DETAIL(got, SCHEMA_VERSION), DOCTOR_FIX_UPGRADE), schemaStale, integrityFailed, orphan: [] };
25693
+ return { row: pass3("D8", DOCTOR_PASS_DETAIL), ...clean };
25161
25694
  } catch (err) {
25162
- if (isCorrupt2(err)) return { row: fail3(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
25163
- return { row: unknown2("D8", message2(err)), ...clean };
25695
+ if (isCorrupt2(err)) return { row: fail4(D8_INTEGRITY_DETAIL, D8_INTEGRITY_FIX), schemaStale: false, integrityFailed: true, orphan: [] };
25696
+ return { row: unknown3("D8", message2(err)), ...clean };
25164
25697
  } finally {
25165
25698
  raw?.close();
25166
25699
  }
25167
25700
  }
25168
25701
  async function checkIndex(project) {
25169
- if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
25702
+ if (!existsSync12(project.dbPath)) return pass3("D9", D9_INDEX_DETAIL(0, 0));
25170
25703
  const sqlite = await loadSqlite2();
25171
- if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
25704
+ if (sqlite === null) return unknown3("D9", D2_SQLITE_DETAIL);
25172
25705
  let raw = null;
25173
25706
  try {
25174
25707
  raw = openRead(sqlite, project.dbPath);
25175
25708
  const sources = Number(cell(raw.prepare("SELECT count(*) FROM sources").get()));
25176
25709
  const chunks = Number(cell(raw.prepare("SELECT count(*) FROM chunks").get()));
25177
- return pass2("D9", D9_INDEX_DETAIL(sources, chunks));
25710
+ return pass3("D9", D9_INDEX_DETAIL(sources, chunks));
25178
25711
  } catch (err) {
25179
- return unknown2("D9", message2(err));
25712
+ return unknown3("D9", message2(err));
25180
25713
  } finally {
25181
25714
  raw?.close();
25182
25715
  }
25183
25716
  }
25184
25717
 
25185
- // src/core/ops/doctor-env.ts
25186
- import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
25187
- import { isAbsolute as isAbsolute5, join as join15, relative as relative4 } from "node:path";
25188
- function pass3(id, detail = DOCTOR_PASS_DETAIL) {
25189
- return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
25190
- }
25191
- function unknown3(id, detail, fixCommand) {
25192
- return fixCommand === void 0 ? { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail } : { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail, fixCommand };
25193
- }
25194
- function fail4(id, detail, fixCommand) {
25195
- return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
25196
- }
25197
- function warn(id, detail, fixCommand) {
25198
- return { id, label: DOCTOR_LABEL[id], status: "WARN", detail, fixCommand };
25199
- }
25200
- function bundleVersion(bundleDir2) {
25201
- try {
25202
- const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
25203
- return typeof v === "string" && v !== "" ? v : void 0;
25204
- } catch {
25205
- return void 0;
25206
- }
25207
- }
25208
- function channelOf(version4) {
25209
- const at2 = version4.indexOf(D1_PRERELEASE_SEP);
25210
- if (at2 < 0) return D1_DEFAULT_TAG;
25211
- const pre = version4.slice(at2 + 1);
25212
- const dot = pre.indexOf(".");
25213
- const tag2 = dot < 0 ? pre : pre.slice(0, dot);
25214
- return tag2 === "" ? D1_DEFAULT_TAG : tag2;
25215
- }
25216
- function firstLine3(b) {
25217
- const text = b.toString("utf8").trim();
25218
- const nl = text.indexOf("\n");
25219
- return (nl < 0 ? text : text.slice(0, nl)).trim();
25220
- }
25221
- function gitCause(r, timeoutMs) {
25222
- if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
25223
- if (r.killed === "cancel") return D1_GIT_CANCEL;
25224
- if (r.exitCode === null) return D1_GIT_NO_START;
25225
- return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
25226
- }
25227
- function fetchCause(err, timeoutMs) {
25228
- const name = err instanceof Error ? err.name : "";
25229
- if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
25230
- const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
25231
- const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
25232
- const msg = cause instanceof Error ? cause.message : String(cause);
25233
- const parts = code !== "" && !msg.includes(code) ? [code, msg] : [msg];
25234
- return D1_NPM_ERROR(parts.filter((part) => part !== "").join(" "));
25235
- }
25236
- async function npmLatest(url4, tag2, signal, timeoutMs) {
25237
- try {
25238
- const res = await fetch(url4, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
25239
- if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
25240
- const body = await res.json();
25241
- const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
25242
- return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
25243
- } catch (err) {
25244
- return { ok: false, cause: fetchCause(err, timeoutMs) };
25245
- }
25246
- }
25247
- function digits(s) {
25248
- if (s === "") return false;
25249
- for (const ch of s) if (ch < "0" || ch > "9") return false;
25250
- return true;
25251
- }
25252
- function parseVersion(v) {
25253
- const at2 = v.indexOf(D1_PRERELEASE_SEP);
25254
- const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
25255
- if (core.length !== 3 || !core.every(digits)) return null;
25256
- const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
25257
- if (at2 < 0) return { core: nums, pre: [] };
25258
- const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
25259
- if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
25260
- if (pre.length === 1) return { core: nums, pre: [pre[0]] };
25261
- return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
25262
- }
25263
- function sign(n) {
25264
- return n < 0 ? -1 : n > 0 ? 1 : 0;
25265
- }
25266
- function compareVersions(a, b) {
25267
- const x = parseVersion(a);
25268
- const y = parseVersion(b);
25269
- if (x === null || y === null) return null;
25270
- for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
25271
- if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
25272
- if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
25273
- return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
25274
- }
25275
- function highestTag(stdout, tag2) {
25276
- let best;
25277
- for (const line of stdout.split("\n")) {
25278
- const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
25279
- if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
25280
- const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
25281
- if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
25282
- if (best === void 0 || compareVersions(v, best) === 1) best = v;
25283
- }
25284
- return best;
25285
- }
25286
- function versionRow(head2, installed, tag2, source, latest, tail, update) {
25287
- const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
25288
- if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
25289
- if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
25290
- return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
25291
- }
25292
- async function checkVersion(i) {
25293
- if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
25294
- const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
25295
- if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
25296
- const tag2 = channelOf(i.version);
25297
- const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
25298
- const git2 = findRuntime(GIT_BIN, i.env);
25299
- const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
25300
- if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
25301
- let cause = D1_GIT_MISSING;
25302
- if (git2 !== null) {
25303
- const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
25304
- cwd: i.cwd,
25305
- env: { ...i.env, ...GIT_NO_PROMPT_ENV },
25306
- signal: i.signal,
25307
- timeoutMs: i.timeoutMs
25308
- });
25309
- if (r.exitCode === 0 && r.killed === null) {
25310
- const latest = highestTag(r.stdout.toString("utf8"), tag2);
25311
- if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
25312
- cause = D1_GIT_NO_TAG(tag2);
25313
- } else {
25314
- cause = gitCause(r, i.timeoutMs);
25315
- }
25316
- }
25317
- return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git2 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
25318
- }
25319
- function numbers(v) {
25320
- const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
25321
- return bare2.split(NODE_VERSION_SEP).map(Number);
25322
- }
25323
- function belowMin(version4) {
25324
- const got = numbers(version4);
25325
- const min = numbers(NODE_MIN);
25326
- for (let k = 0; k < min.length; k++) {
25327
- const g = got[k] ?? 0;
25328
- if (g !== min[k]) return g < min[k];
25329
- }
25330
- return false;
25331
- }
25332
- async function sqliteLoads() {
25333
- try {
25334
- await import(SQLITE_MODULE);
25335
- return true;
25336
- } catch {
25337
- return false;
25338
- }
25339
- }
25340
- async function checkNode(i) {
25341
- const bun = i.bunVersion === void 0 ? [] : [D2_BUN_DETAIL(i.bunVersion)];
25342
- const withBun = (detail) => [detail, ...bun].join(D4_REASON_JOIN);
25343
- if (belowMin(i.nodeVersion)) return fail4("D2", withBun(D2_NODE_DETAIL(i.nodeVersion)), D2_NODE_FIX);
25344
- if (!await sqliteLoads()) return fail4("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
25345
- return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
25346
- }
25347
- function checkMcp(ctx, adapter) {
25348
- const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
25349
- const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
25350
- if (named2 || versioned) return pass3("D6");
25351
- return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown3("D6", D6_UNKNOWN_DETAIL);
25352
- }
25353
- function piCwdInside(worktree, piCwd) {
25354
- if (piCwd === void 0 || !existsSync11(piCwd)) return false;
25355
- const rel = relative4(worktree, realpathSync6.native(piCwd));
25356
- return rel === "" || !rel.startsWith("..") && !isAbsolute5(rel);
25357
- }
25358
- function checkProject(i) {
25359
- const bad = fail4("D7", D7_DETAIL(i.project.source), D7_FIX);
25360
- if (i.project.source !== i.adapter.projectSource) return bad;
25361
- if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
25362
- return pass3("D7");
25363
- }
25364
- function checkMode(adapter, hostPermission) {
25365
- if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
25366
- if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
25367
- return pass3("D10", D10_DETAIL(adapter.denyChannel));
25368
- }
25369
- function checkShell(env) {
25370
- const win = process.platform === "win32";
25371
- const shell = findRuntime("shell", env);
25372
- if (shell !== null) return pass3("D11", D11_PASS_DETAIL(shell, win));
25373
- return win ? fail4("D11", D11_WIN_DETAIL, D11_WIN_FIX) : fail4("D11", D11_POSIX_DETAIL, D11_POSIX_FIX);
25374
- }
25375
-
25376
25718
  // src/core/ops/doctor-hook.ts
25377
- import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync13, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
25719
+ import { existsSync as existsSync14, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync14, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
25378
25720
  import { tmpdir as tmpdir2 } from "node:os";
25379
25721
  import path7 from "node:path";
25380
25722
 
@@ -27118,7 +27460,9 @@ var HOST_SHAPES = {
27118
27460
  kiro: kiro_default,
27119
27461
  zcode: zcode_default,
27120
27462
  pi: pi_default,
27121
- opencode: opencode_default
27463
+ opencode: opencode_default,
27464
+ omp: pi_default
27465
+ // ADR-0026: OMP reads the Pi extension reply
27122
27466
  };
27123
27467
  var NOTE_KEYS = /* @__PURE__ */ new Set(["$schema", "title", "description", "definitions", "default"]);
27124
27468
  var RULE_KEYS = /* @__PURE__ */ new Set(["type", "enum", "const", "required", "properties", "additionalProperties", "items", "allOf", "$ref"]);
@@ -27200,13 +27544,13 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
27200
27544
 
27201
27545
  // src/setup/codex-trust.ts
27202
27546
  import { createHash } from "node:crypto";
27203
- import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
27547
+ import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
27204
27548
  import path6 from "node:path";
27205
27549
  import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
27206
27550
 
27207
27551
  // src/setup/spawn-bin.ts
27208
27552
  import { spawnSync } from "node:child_process";
27209
- import { accessSync as accessSync2, constants as fsc, statSync as statSync6 } from "node:fs";
27553
+ import { accessSync as accessSync2, constants as fsc, statSync as statSync7 } from "node:fs";
27210
27554
  import path5 from "node:path";
27211
27555
  var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
27212
27556
  var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
@@ -27224,7 +27568,7 @@ function whichBin(bin, env, platform = process.platform) {
27224
27568
  const f = path5.join(dir, n);
27225
27569
  try {
27226
27570
  accessSync2(f, fsc.X_OK);
27227
- if (statSync6(f).isFile()) return f;
27571
+ if (statSync7(f).isFile()) return f;
27228
27572
  } catch {
27229
27573
  }
27230
27574
  }
@@ -27423,10 +27767,10 @@ function isObject6(v) {
27423
27767
  }
27424
27768
  function loadFixture(bundleDir2, agent) {
27425
27769
  const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
27426
- if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
27770
+ if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
27427
27771
  let all;
27428
27772
  try {
27429
- all = JSON.parse(hostText(readFileSync13(file2, "utf8")));
27773
+ all = JSON.parse(hostText(readFileSync14(file2, "utf8")));
27430
27774
  } catch (err) {
27431
27775
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
27432
27776
  }
@@ -27448,7 +27792,8 @@ var CWD_KEY = {
27448
27792
  kiro: "cwd",
27449
27793
  zcode: "cwd",
27450
27794
  pi: "cwd",
27451
- opencode: "directory"
27795
+ opencode: "directory",
27796
+ omp: "cwd"
27452
27797
  };
27453
27798
  function payloadFor(agent, payload, worktree) {
27454
27799
  return worktree !== void 0 && isObject6(payload) ? { ...payload, [CWD_KEY[agent]]: worktree } : payload;
@@ -27640,7 +27985,7 @@ async function codexStopDetail(i, timeoutMs) {
27640
27985
  timeoutMs,
27641
27986
  stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
27642
27987
  });
27643
- const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
27988
+ const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
27644
27989
  return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
27645
27990
  } finally {
27646
27991
  rmSync2(home, { recursive: true, force: true });
@@ -27651,7 +27996,7 @@ async function checkHookRoundTrip(i) {
27651
27996
  const trust = await codexPluginTrust(i);
27652
27997
  if (trust !== null) return trust;
27653
27998
  }
27654
- if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
27999
+ if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
27655
28000
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
27656
28001
  }
27657
28002
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -27700,19 +28045,19 @@ async function checkHookRoundTrip(i) {
27700
28045
  }
27701
28046
 
27702
28047
  // src/core/ops/db-heal.ts
27703
- import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
27704
- import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
28048
+ import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
28049
+ import { basename as basename4, dirname as dirname9, join as join18 } from "node:path";
27705
28050
 
27706
28051
  // src/core/store/owners.ts
27707
- import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
27708
- import { basename as basename3, join as join16 } from "node:path";
28052
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync15, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
28053
+ import { basename as basename3, join as join17 } from "node:path";
27709
28054
  function ownersDir(configDir, projectKey) {
27710
- return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
28055
+ return join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
27711
28056
  }
27712
28057
  function ownerFile(configDir, projectKey, serverId) {
27713
- return join16(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
28058
+ return join17(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
27714
28059
  }
27715
- function errCode2(err) {
28060
+ function errCode3(err) {
27716
28061
  return err.code;
27717
28062
  }
27718
28063
  function writeOwnerPid(configDir, projectKey, serverId) {
@@ -27728,8 +28073,8 @@ function isLive(pid) {
27728
28073
  process.kill(pid, 0);
27729
28074
  return true;
27730
28075
  } catch (err) {
27731
- if (errCode2(err) === "ESRCH") return false;
27732
- if (errCode2(err) === "EPERM") return true;
28076
+ if (errCode3(err) === "ESRCH") return false;
28077
+ if (errCode3(err) === "EPERM") return true;
27733
28078
  throw err;
27734
28079
  }
27735
28080
  }
@@ -27739,18 +28084,18 @@ function listLiveOwners(configDir, projectKey) {
27739
28084
  try {
27740
28085
  names = readdirSync7(dir);
27741
28086
  } catch (err) {
27742
- if (errCode2(err) === "ENOENT") return [];
28087
+ if (errCode3(err) === "ENOENT") return [];
27743
28088
  throw err;
27744
28089
  }
27745
28090
  const live = [];
27746
28091
  for (const name of names) {
27747
28092
  if (!name.endsWith(OWNER_PID_EXT)) continue;
27748
- const file2 = join16(dir, name);
28093
+ const file2 = join17(dir, name);
27749
28094
  let text;
27750
28095
  try {
27751
- text = readFileSync14(file2, "utf8");
28096
+ text = readFileSync15(file2, "utf8");
27752
28097
  } catch (err) {
27753
- if (errCode2(err) === "ENOENT") continue;
28098
+ if (errCode3(err) === "ENOENT") continue;
27754
28099
  throw err;
27755
28100
  }
27756
28101
  const serverId = basename3(name, OWNER_PID_EXT);
@@ -27794,7 +28139,7 @@ function renameAside(dbPath) {
27794
28139
  const ts = String(Date.now());
27795
28140
  for (const suffix of DB_SIBLING_SUFFIXES) {
27796
28141
  const file2 = dbPath + suffix;
27797
- if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
28142
+ if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
27798
28143
  }
27799
28144
  return ts;
27800
28145
  }
@@ -27817,7 +28162,7 @@ function utcStamp(now) {
27817
28162
  return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
27818
28163
  }
27819
28164
  function makeOrphanDir(projectDir) {
27820
- const base = join17(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
28165
+ const base = join18(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
27821
28166
  for (let n = 1; ; n += 1) {
27822
28167
  const dir = n === 1 ? base : base + "-" + String(n);
27823
28168
  try {
@@ -27834,7 +28179,7 @@ async function healOrphan(project, files, row5) {
27834
28179
  try {
27835
28180
  dir = makeOrphanDir(dirname9(project.dbPath));
27836
28181
  for (const f of files) {
27837
- const to = join17(dir, basename4(f.path));
28182
+ const to = join18(dir, basename4(f.path));
27838
28183
  renameWithRetry(f.path, to);
27839
28184
  moved.push({ path: to, bytes: f.bytes });
27840
28185
  }
@@ -27852,8 +28197,8 @@ function keyIsTyped(key) {
27852
28197
  if (key.length === 0) return false;
27853
28198
  for (const ch of key) {
27854
28199
  const upper = ch >= "A" && ch <= "Z";
27855
- const digit = ch >= "0" && ch <= "9";
27856
- if (!upper && !digit && ch !== "_") return false;
28200
+ const digit2 = ch >= "0" && ch <= "9";
28201
+ if (!upper && !digit2 && ch !== "_") return false;
27857
28202
  }
27858
28203
  return true;
27859
28204
  }
@@ -27932,8 +28277,8 @@ function unsupportedHostOf(sig) {
27932
28277
 
27933
28278
  // src/core/ops/doctor-issue.ts
27934
28279
  import { spawnSync as spawnSync3 } from "node:child_process";
27935
- import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync15, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
27936
- import { delimiter, dirname as dirname10, join as join18 } from "node:path";
28280
+ import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync16, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
28281
+ import { delimiter, dirname as dirname10, join as join19 } from "node:path";
27937
28282
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
27938
28283
  function tildeOf(env) {
27939
28284
  const home = homeDirOf(env);
@@ -27989,8 +28334,8 @@ function onPath(env, tool) {
27989
28334
  const out = [];
27990
28335
  for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
27991
28336
  if (dir === "") continue;
27992
- for (const n of names) if (existsSync15(join18(dir, n))) {
27993
- out.push(join18(dir, n));
28337
+ for (const n of names) if (existsSync16(join19(dir, n))) {
28338
+ out.push(join19(dir, n));
27994
28339
  break;
27995
28340
  }
27996
28341
  }
@@ -27998,7 +28343,7 @@ function onPath(env, tool) {
27998
28343
  }
27999
28344
  function hookLogTail(env) {
28000
28345
  const file2 = hookLogPath(env);
28001
- if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
28346
+ if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
28002
28347
  try {
28003
28348
  const fd = openSync2(file2, "r");
28004
28349
  try {
@@ -28018,7 +28363,7 @@ function hookLogTail(env) {
28018
28363
  }
28019
28364
  async function journalRows(ctx) {
28020
28365
  const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
28021
- if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
28366
+ if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
28022
28367
  try {
28023
28368
  const db = await openDb(ctx.project, { readOnly: true });
28024
28369
  try {
@@ -28036,21 +28381,21 @@ function agentConfig(adapter, env, worktree) {
28036
28381
  const home = homeDirOf(env);
28037
28382
  const files = configPaths(adapter, env, worktree);
28038
28383
  if (home !== null) {
28039
- if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join18(claudeDirOf(env, home), SETTINGS_FILE) });
28040
- if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join18(codexDirOf(env, home), CONFIG_TOML_FILE) });
28384
+ if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join19(claudeDirOf(env, home), SETTINGS_FILE) });
28385
+ if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join19(codexDirOf(env, home), CONFIG_TOML_FILE) });
28041
28386
  }
28042
28387
  const out = [];
28043
28388
  const seen = /* @__PURE__ */ new Set();
28044
28389
  for (const f of files) {
28045
28390
  if (seen.has(f.path)) continue;
28046
28391
  seen.add(f.path);
28047
- if (!existsSync15(f.path)) {
28392
+ if (!existsSync16(f.path)) {
28048
28393
  out.push(`${f.label}: ${f.path} (absent)`);
28049
28394
  continue;
28050
28395
  }
28051
28396
  let text = "";
28052
28397
  try {
28053
- text = readFileSync15(f.path, "utf8");
28398
+ text = readFileSync16(f.path, "utf8");
28054
28399
  } catch (err) {
28055
28400
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
28056
28401
  continue;
@@ -28121,9 +28466,9 @@ async function buildIssueBody(i) {
28121
28466
  async function writeIssueReport(i) {
28122
28467
  const tilde = tildeOf(i.env);
28123
28468
  const body = await buildIssueBody(i);
28124
- const dir = join18(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
28469
+ const dir = join19(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
28125
28470
  mkdirSync7(dir, { recursive: true });
28126
- const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
28471
+ const file2 = join19(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
28127
28472
  writeFileSync4(file2, body);
28128
28473
  const shown2 = tilde(file2);
28129
28474
  const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
@@ -28150,7 +28495,7 @@ async function guard(id, run) {
28150
28495
  }
28151
28496
  }
28152
28497
  async function codexDb(ctx, adapter) {
28153
- if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
28498
+ if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
28154
28499
  try {
28155
28500
  return await openDb(ctx.project, { readOnly: true });
28156
28501
  } catch {
@@ -28186,11 +28531,11 @@ async function hookRow(ctx, adapter, host) {
28186
28531
  }
28187
28532
  }
28188
28533
  function ownServerId(configDir, projectKey) {
28189
- const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
28190
- if (!existsSync16(dir)) return "";
28534
+ const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
28535
+ if (!existsSync17(dir)) return "";
28191
28536
  for (const name of readdirSync8(dir)) {
28192
28537
  if (!name.endsWith(OWNER_PID_EXT)) continue;
28193
- if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
28538
+ if (readFileSync17(join20(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
28194
28539
  }
28195
28540
  return "";
28196
28541
  }
@@ -28220,7 +28565,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
28220
28565
  D9: () => checkIndex(project),
28221
28566
  D10: () => checkMode(adapter, ctx.hostPermission),
28222
28567
  // D-1331-OC-PERM-1
28223
- D11: () => checkShell(env)
28568
+ D11: () => checkRuntimes(env, checkShell(env))
28224
28569
  };
28225
28570
  const rows = [];
28226
28571
  for (const id of DOCTOR_CHECK_ORDER) rows.push(await guard(id, checks[id]));
@@ -28250,7 +28595,7 @@ async function doctorReply(ctx, host) {
28250
28595
  const runtime = runtimeInfo(host.env, ctx.signal);
28251
28596
  const rows = await runDoctorChecks(ctx, adapter, host);
28252
28597
  const failed = rows.some((r) => r.status === "FAIL");
28253
- const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
28598
+ const command = adapter.id === "pi" ? failed ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : adapter.id === "omp" ? ompCommand(rows, failed) : `context-mode ${failed ? "setup" : "doctor"} --agents ${adapter.id}`;
28254
28599
  const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
28255
28600
  const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir), await runtime);
28256
28601
  const table3 = buildReport(input);
@@ -28264,7 +28609,8 @@ async function doctorReply(ctx, host) {
28264
28609
  }
28265
28610
  const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
28266
28611
  const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
28267
- const whole2 = [envLine2, table3, ...docs, ...notes].join("\n");
28612
+ const info = adapter.id === "omp" ? ompInfoLines(host.env, ctx.clientInfo?.version) : [];
28613
+ const whole2 = [envLine2, table3, ...docs, ...info, ...notes].join("\n");
28268
28614
  const bytes5 = Buffer.byteLength(whole2, "utf8");
28269
28615
  if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
28270
28616
  const db = await openDb(ctx.project);
@@ -28273,9 +28619,14 @@ async function doctorReply(ctx, host) {
28273
28619
  } finally {
28274
28620
  closeDb(db);
28275
28621
  }
28276
- const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
28622
+ const text = [envLine2, buildReportHead(input), ...docs, ...info, ...notes].join("\n");
28277
28623
  return { text, isError: false, sandboxBytes: bytes5 };
28278
28624
  }
28625
+ function ompCommand(rows, failed) {
28626
+ if (!failed) return OMP_LIST_COMMAND;
28627
+ const d3 = rows.find((r) => r.id === "D3" && r.status === "FAIL");
28628
+ return d3?.fixCommand ?? NATIVE_INSTALL.omp[0];
28629
+ }
28279
28630
  async function handler2(_input, ctx) {
28280
28631
  return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
28281
28632
  }
@@ -28289,9 +28640,9 @@ var ctxDoctor = Object.freeze({
28289
28640
  });
28290
28641
 
28291
28642
  // src/core/tools/execute.ts
28292
- import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
28643
+ import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
28293
28644
  import { tmpdir as tmpdir3 } from "node:os";
28294
- import { dirname as dirname12, join as join20, parse as parse3, resolve as resolve11 } from "node:path";
28645
+ import { dirname as dirname12, join as join21, parse as parse3, resolve as resolve11 } from "node:path";
28295
28646
 
28296
28647
  // src/core/sandbox/win-build.ts
28297
28648
  var SEPARATORS2 = ";&|(\n";
@@ -28374,7 +28725,7 @@ function schemaLine(issue4) {
28374
28725
  }
28375
28726
  function fileError(given, abs, root) {
28376
28727
  let dir = abs;
28377
- while (!existsSync17(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
28728
+ while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
28378
28729
  if (isInside(root, dir)) return null;
28379
28730
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
28380
28731
  }
@@ -28443,7 +28794,12 @@ async function handler3(raw, ctx) {
28443
28794
  if (bad !== null) return fail5(bad);
28444
28795
  extra.CTX_FILE = abs;
28445
28796
  }
28446
- const runtime = findRuntime(input.language);
28797
+ let runtime;
28798
+ try {
28799
+ runtime = findRuntime(input.language);
28800
+ } catch {
28801
+ runtime = null;
28802
+ }
28447
28803
  if (runtime === null) return fail5(noRuntimeError(input.language).toLine());
28448
28804
  const env = buildChildEnv(process.env, extra);
28449
28805
  const timeoutMs = input.timeoutMs ?? EXEC_TIMEOUT_MS;
@@ -28455,8 +28811,8 @@ async function handler3(raw, ctx) {
28455
28811
  if (takesDashC(input.language, runtime)) {
28456
28812
  argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
28457
28813
  } else {
28458
- tmpDir = mkdtempSync2(join20(tmpdir3(), TMP_PREFIX));
28459
- const file2 = join20(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
28814
+ tmpDir = mkdtempSync2(join21(tmpdir3(), TMP_PREFIX));
28815
+ const file2 = join21(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
28460
28816
  writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
28461
28817
  argv = scriptArgv(input.language, runtime, file2);
28462
28818
  }
@@ -28492,12 +28848,12 @@ var ctxExecute = {
28492
28848
  };
28493
28849
 
28494
28850
  // src/core/tools/index.ts
28495
- import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as statSync8 } from "node:fs";
28496
- import { dirname as dirname13, extname as extname3, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
28851
+ import { existsSync as existsSync19, readFileSync as readFileSync20, statSync as statSync9 } from "node:fs";
28852
+ import { dirname as dirname13, extname as extname3, join as join24, relative as relative5, resolve as resolve12 } from "node:path";
28497
28853
 
28498
28854
  // src/core/index/walk.ts
28499
- import { readdirSync as readdirSync9, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
28500
- import { join as join21 } from "node:path";
28855
+ import { readdirSync as readdirSync9, readFileSync as readFileSync18, realpathSync as realpathSync10, statSync as statSync8 } from "node:fs";
28856
+ import { join as join22 } from "node:path";
28501
28857
  var GITIGNORE = ".gitignore";
28502
28858
  var GIT_DIR = ".git";
28503
28859
  function walkDir(root, containmentRoot) {
@@ -28506,7 +28862,7 @@ function walkDir(root, containmentRoot) {
28506
28862
  const found = [];
28507
28863
  visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
28508
28864
  found.sort(compareFound);
28509
- return found.map((f) => ({ absPath: f.absPath, relPath: join21(...f.dir, f.name) }));
28865
+ return found.map((f) => ({ absPath: f.absPath, relPath: join22(...f.dir, f.name) }));
28510
28866
  }
28511
28867
  function visit(abs, rel, parent, contain, seen, found) {
28512
28868
  let entries;
@@ -28515,10 +28871,10 @@ function visit(abs, rel, parent, contain, seen, found) {
28515
28871
  } catch {
28516
28872
  return;
28517
28873
  }
28518
- const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join21(abs, GITIGNORE), rel)) : parent;
28874
+ const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join22(abs, GITIGNORE), rel)) : parent;
28519
28875
  for (const e of entries) {
28520
28876
  if (e.name === GIT_DIR) continue;
28521
- const path8 = join21(abs, e.name);
28877
+ const path8 = join22(abs, e.name);
28522
28878
  let isDir = e.isDirectory();
28523
28879
  let isFile = e.isFile();
28524
28880
  let target = path8;
@@ -28530,7 +28886,7 @@ function visit(abs, rel, parent, contain, seen, found) {
28530
28886
  continue;
28531
28887
  }
28532
28888
  if (!isInside(contain, resolved)) continue;
28533
- const st = statSync7(resolved);
28889
+ const st = statSync8(resolved);
28534
28890
  isDir = st.isDirectory();
28535
28891
  isFile = st.isFile();
28536
28892
  target = resolved;
@@ -28558,7 +28914,7 @@ function compareFound(a, b) {
28558
28914
  function readRules(file2, base) {
28559
28915
  let body;
28560
28916
  try {
28561
- body = readFileSync17(file2, "utf8");
28917
+ body = readFileSync18(file2, "utf8");
28562
28918
  } catch {
28563
28919
  return [];
28564
28920
  }
@@ -28641,10 +28997,12 @@ function globSeg(pat, name) {
28641
28997
  }
28642
28998
 
28643
28999
  // src/core/sandbox/fetch.ts
29000
+ import { readFileSync as readFileSync19 } from "node:fs";
28644
29001
  import { lookup } from "node:dns/promises";
28645
29002
  import http from "node:http";
28646
29003
  import https from "node:https";
28647
29004
  import { BlockList, isIP } from "node:net";
29005
+ import { join as join23 } from "node:path";
28648
29006
  import { connect as tlsConnect } from "node:tls";
28649
29007
  var PRIVATE_RANGES = [
28650
29008
  ["127.0.0.0", 8, "ipv4"],
@@ -28676,6 +29034,21 @@ for (const [net, prefix, type] of PRIVATE_RANGES) BLOCKED.addSubnet(net, prefix,
28676
29034
  var STATUS_OK_FIRST = 200;
28677
29035
  var STATUS_OK_END = 300;
28678
29036
  var STATUS_REDIRECT = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
29037
+ var UA_HOME = "https://github.com/mksglu/context-mode";
29038
+ var UA_DEV_VERSION = "dev";
29039
+ var namedHeaders;
29040
+ function baseHeaders() {
29041
+ if (namedHeaders === void 0) {
29042
+ let version4 = UA_DEV_VERSION;
29043
+ try {
29044
+ const v = JSON.parse(readFileSync19(join23(ownBundleDir(), D1_PACKAGE_FILE), "utf8")).version;
29045
+ if (typeof v === "string" && v !== "") version4 = v;
29046
+ } catch {
29047
+ }
29048
+ namedHeaders = Object.freeze({ "user-agent": "context-mode/" + version4 + " (+" + UA_HOME + ")", accept: "*/*" });
29049
+ }
29050
+ return namedHeaders;
29051
+ }
28679
29052
  function fail6(code) {
28680
29053
  return new CtxError("FETCH_FAILED", { code });
28681
29054
  }
@@ -28784,11 +29157,11 @@ function request(u, conn, proxy, signal) {
28784
29157
  const onErr = (err) => reject(fail6(causeCode(err)));
28785
29158
  if (proxy === void 0) {
28786
29159
  const mod = u.protocol === "https:" ? https : http;
28787
- const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
29160
+ const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { ...baseHeaders(), host: u.host } });
28788
29161
  req.on("response", resolve13).on("error", onErr).end();
28789
29162
  return;
28790
29163
  }
28791
- const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
29164
+ const proxyHeaders = proxy.auth === void 0 ? { ...baseHeaders() } : { ...baseHeaders(), "proxy-authorization": proxy.auth };
28792
29165
  if (u.protocol === "http:") {
28793
29166
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
28794
29167
  req.on("response", resolve13).on("error", onErr).end();
@@ -28808,7 +29181,7 @@ function request(u, conn, proxy, signal) {
28808
29181
  port,
28809
29182
  path: path8,
28810
29183
  signal,
28811
- headers: { host: u.host },
29184
+ headers: { ...baseHeaders(), host: u.host },
28812
29185
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
28813
29186
  });
28814
29187
  req.on("response", resolve13).on("error", onErr).end();
@@ -28850,7 +29223,7 @@ async function safeFetch(url4, signal) {
28850
29223
  }
28851
29224
  if (status < STATUS_OK_FIRST || status >= STATUS_OK_END) {
28852
29225
  res.resume();
28853
- throw fail6(status);
29226
+ throw fail6(status + " from " + bare(current.hostname));
28854
29227
  }
28855
29228
  const body = await readBody(res);
28856
29229
  const shown2 = new URL(current.href);
@@ -29216,8 +29589,8 @@ var EntityDecoder = class {
29216
29589
  while (offset < inputLength) {
29217
29590
  const char = input.charCodeAt(offset);
29218
29591
  if (isNumber2(char) || isHexadecimalCharacter(char)) {
29219
- const digit = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
29220
- result = result * 16 + digit;
29592
+ const digit2 = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
29593
+ result = result * 16 + digit2;
29221
29594
  consumed += 1;
29222
29595
  offset += 1;
29223
29596
  } else {
@@ -29245,13 +29618,13 @@ var EntityDecoder = class {
29245
29618
  let { result } = this;
29246
29619
  let { consumed } = this;
29247
29620
  while (offset < inputLength) {
29248
- const digit = input.charCodeAt(offset) - CharCodes.ZERO;
29249
- if (digit >>> 0 > 9) {
29621
+ const digit2 = input.charCodeAt(offset) - CharCodes.ZERO;
29622
+ if (digit2 >>> 0 > 9) {
29250
29623
  this.result = result;
29251
29624
  this.consumed = consumed;
29252
- return this.emitNumericEntity(digit + CharCodes.ZERO, 2);
29625
+ return this.emitNumericEntity(digit2 + CharCodes.ZERO, 2);
29253
29626
  }
29254
- result = result * 10 + digit;
29627
+ result = result * 10 + digit2;
29255
29628
  consumed += 1;
29256
29629
  offset += 1;
29257
29630
  }
@@ -32686,14 +33059,14 @@ function kindOfType(contentType) {
32686
33059
  }
32687
33060
  function readUtf8(absPath) {
32688
33061
  try {
32689
- return utf8.decode(readFileSync18(absPath));
33062
+ return utf8.decode(readFileSync20(absPath));
32690
33063
  } catch {
32691
33064
  return void 0;
32692
33065
  }
32693
33066
  }
32694
33067
  function missingOrOutside(given, abs, root) {
32695
33068
  let dir = abs;
32696
- while (!existsSync18(dir) && dirname13(dir) !== dir) dir = dirname13(dir);
33069
+ while (!existsSync19(dir) && dirname13(dir) !== dir) dir = dirname13(dir);
32697
33070
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
32698
33071
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
32699
33072
  }
@@ -32701,10 +33074,10 @@ function pathItems(input, project) {
32701
33074
  const abs = resolve12(project.worktree, input.path);
32702
33075
  if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
32703
33076
  const base = relative5(project.worktree, abs);
32704
- if (statSync8(abs).isDirectory()) {
33077
+ if (statSync9(abs).isDirectory()) {
32705
33078
  return walkDir(abs, project.containmentRoot).map((f) => ({
32706
33079
  sourceKind: "path",
32707
- label: pathLabel(join22(base, f.relPath)),
33080
+ label: pathLabel(join24(base, f.relPath)),
32708
33081
  kind: kindOfPath(f.relPath),
32709
33082
  read: () => readUtf8(f.absPath)
32710
33083
  }));
@@ -33244,8 +33617,8 @@ var ctxStats = Object.freeze({
33244
33617
  });
33245
33618
 
33246
33619
  // src/core/ops/host-write.ts
33247
- import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
33248
- import { dirname as dirname14, join as join23 } from "node:path";
33620
+ import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
33621
+ import { dirname as dirname14, join as join25 } from "node:path";
33249
33622
  function defaultWrite(file2, text) {
33250
33623
  writeFileSync6(file2, text, "utf8");
33251
33624
  }
@@ -33254,17 +33627,20 @@ function hostConfigPath(agent, home, env) {
33254
33627
  if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
33255
33628
  switch (agent) {
33256
33629
  case "opencode":
33257
- return join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
33630
+ return join25(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
33258
33631
  // D-WIN-OPENCODE-DIR-1
33259
33632
  case "pi":
33260
- return join23(piAgentDirOf(env, home), SETTINGS_FILE);
33633
+ return join25(piAgentDirOf(env, home), SETTINGS_FILE);
33261
33634
  case "gemini":
33262
- return join23(geminiDirOf(env, home), SETTINGS_FILE);
33635
+ return join25(geminiDirOf(env, home), SETTINGS_FILE);
33263
33636
  // D-R38-GEMINI-HOME-1
33264
33637
  case "copilot-cli":
33265
33638
  return null;
33639
+ case "omp":
33640
+ return null;
33641
+ // ADR-0026 decision 8 (D-OMP-UPGRADE-1): OMP loads the plugin from its own store; no MCP entry, nothing under ~/.pi
33266
33642
  default:
33267
- return join23(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
33643
+ return join25(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
33268
33644
  }
33269
33645
  }
33270
33646
  function cell3(value) {
@@ -33276,7 +33652,7 @@ function toRow(file2, edit) {
33276
33652
  function writeWithRollback(file2, text, write2, atomic) {
33277
33653
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
33278
33654
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
33279
- const had = existsSync19(file2);
33655
+ const had = existsSync20(file2);
33280
33656
  mkdirSync8(dirname14(file2), { recursive: true });
33281
33657
  if (had) copyFileSync(file2, trash);
33282
33658
  try {
@@ -33306,7 +33682,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
33306
33682
  if (requested === null) return [];
33307
33683
  const current = readHostConfig(row5.id, requested);
33308
33684
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
33309
- const exists = existsSync19(current.path);
33685
+ const exists = existsSync20(current.path);
33310
33686
  if (exists && result.text === current.text) return [];
33311
33687
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
33312
33688
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -33314,15 +33690,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
33314
33690
  }
33315
33691
 
33316
33692
  // src/core/ops/uninstall.ts
33317
- import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
33318
- import { join as join24 } from "node:path";
33693
+ import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
33694
+ import { join as join26 } from "node:path";
33319
33695
  function row2(area, before, after) {
33320
33696
  return { area, before, after };
33321
33697
  }
33322
33698
  function stopServers(configDir, projectKey) {
33323
33699
  const stopped = listLiveOwners(configDir, projectKey);
33324
- const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
33325
- for (const serverId of stopped) writeFileSync7(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
33700
+ const dir = join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
33701
+ for (const serverId of stopped) writeFileSync7(join26(dir, serverId + OWNER_STOP_EXT), "", "utf8");
33326
33702
  return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
33327
33703
  }
33328
33704
  function rootOrNull(adapter, env) {
@@ -33340,15 +33716,15 @@ function removeCache(adapter, env, configDir) {
33340
33716
  const root = rootOrNull(adapter, env);
33341
33717
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
33342
33718
  if (adapter.installMode === "marketplace") {
33343
- const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
33719
+ const cache = join26(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
33344
33720
  if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
33345
33721
  }
33346
33722
  rmSync6(root, { recursive: true, force: true });
33347
33723
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
33348
33724
  }
33349
33725
  case "plugin": {
33350
- const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
33351
- if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
33726
+ const agentDir = join26(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
33727
+ if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
33352
33728
  rmSync6(agentDir, { recursive: true, force: true });
33353
33729
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
33354
33730
  }
@@ -33393,7 +33769,7 @@ function ownEntries2(agent, env) {
33393
33769
  }
33394
33770
  if (agent === "opencode") {
33395
33771
  return [{
33396
- file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
33772
+ file: join26(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
33397
33773
  // D-WIN-OPENCODE-DIR-1
33398
33774
  key: OPENCODE_PLUGIN_KEY,
33399
33775
  shown: OPENCODE_PLUGIN_KEY,
@@ -33404,13 +33780,22 @@ function ownEntries2(agent, env) {
33404
33780
  if (agent === "pi") {
33405
33781
  const agentDir = piAgentDirOf(env, home);
33406
33782
  return [{
33407
- file: join24(agentDir, SETTINGS_FILE),
33783
+ file: join26(agentDir, SETTINGS_FILE),
33408
33784
  key: PI_PACKAGES_KEY,
33409
33785
  shown: PI_PACKAGES_KEY,
33410
33786
  has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
33411
33787
  drop: (v) => v.filter((x) => piSource2(x) !== PI_GIT_PACKAGE)
33412
33788
  }];
33413
33789
  }
33790
+ if (agent === "omp") {
33791
+ return [{
33792
+ file: ompImportFiles(home).mcp,
33793
+ key: OMP_DISABLED_SERVERS_KEY,
33794
+ shown: OMP_DISABLED_SERVERS_KEY,
33795
+ has: (v) => Array.isArray(v) && v.includes(SERVER_KEY),
33796
+ drop: (v) => v.filter((x) => x !== SERVER_KEY)
33797
+ }];
33798
+ }
33414
33799
  return [];
33415
33800
  }
33416
33801
  function removeOwnEntries(agent, env) {
@@ -33426,12 +33811,12 @@ function removeOwnEntries(agent, env) {
33426
33811
  return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
33427
33812
  }
33428
33813
  function removeProjectData(configDir, projectKey) {
33429
- const projects = join24(configDir, PROJECTS_DIR_NAME);
33430
- const dir = join24(projects, projectKey);
33431
- if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
33814
+ const projects = join26(configDir, PROJECTS_DIR_NAME);
33815
+ const dir = join26(projects, projectKey);
33816
+ if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
33432
33817
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
33433
33818
  for (const name of readdirSync10(dir)) {
33434
- if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
33819
+ if (name !== OWNERS_DIR_NAME) rmSync6(join26(dir, name), { recursive: true, force: true });
33435
33820
  }
33436
33821
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
33437
33822
  }
@@ -33439,12 +33824,12 @@ function runUninstall(input) {
33439
33824
  const configDir = resolveConfigDir(input.env);
33440
33825
  const stop = stopServers(configDir, input.project.projectKey);
33441
33826
  const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
33442
- rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
33827
+ rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join26(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
33443
33828
  return { rows, stopped: stop.stopped };
33444
33829
  }
33445
33830
 
33446
33831
  // src/core/ops/v1-remove.ts
33447
- import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync19, rmSync as rmSync7 } from "node:fs";
33832
+ import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync21, rmSync as rmSync7 } from "node:fs";
33448
33833
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
33449
33834
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
33450
33835
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -33456,7 +33841,7 @@ function moveAside(target, undo) {
33456
33841
  }
33457
33842
  function keepAside(target, undo) {
33458
33843
  let aside = target + UPGRADE_ASIDE_SUFFIX;
33459
- for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
33844
+ for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
33460
33845
  renameWithRetry(target, aside);
33461
33846
  undo.push({ trash: aside, target, keep: true });
33462
33847
  return aside;
@@ -33495,8 +33880,8 @@ function locate(doc, path8) {
33495
33880
  return null;
33496
33881
  }
33497
33882
  function stripJsonEntries(agent, file2, findings, kept, undo) {
33498
- const layout = hostLayout(readFileSync19(file2, "utf8"));
33499
- const text = hostText(readFileSync19(file2, "utf8"));
33883
+ const layout = hostLayout(readFileSync21(file2, "utf8"));
33884
+ const text = hostText(readFileSync21(file2, "utf8"));
33500
33885
  const doc = parseHostConfig(agent, file2, text, "jsonc");
33501
33886
  const hit = /* @__PURE__ */ new Set();
33502
33887
  const byContainer = /* @__PURE__ */ new Map();
@@ -33533,20 +33918,20 @@ function removeV1(agent, findings, project) {
33533
33918
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
33534
33919
  else if (f.path === "") {
33535
33920
  if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
33536
- else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
33537
- else if (existsSync21(f.file)) {
33921
+ else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
33922
+ else if (existsSync22(f.file)) {
33538
33923
  moveAside(f.file, undo);
33539
33924
  done.set(f, UPGRADE_REMOVED);
33540
33925
  } else done.set(f, UPGRADE_NOT_FOUND);
33541
33926
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
33542
33927
  }
33543
33928
  for (const [file2, list4] of entries) {
33544
- if (!existsSync21(file2)) {
33929
+ if (!existsSync22(file2)) {
33545
33930
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
33546
33931
  continue;
33547
33932
  }
33548
33933
  if (file2.endsWith(TOML_EXT)) {
33549
- const rawToml = readFileSync19(file2, "utf8");
33934
+ const rawToml = readFileSync21(file2, "utf8");
33550
33935
  const tomlLayout = hostLayout(rawToml);
33551
33936
  let text = hostText(rawToml);
33552
33937
  for (const f of list4) {
@@ -33574,7 +33959,7 @@ function removeV1(agent, findings, project) {
33574
33959
  },
33575
33960
  rollback() {
33576
33961
  for (const u of undo.splice(0).reverse()) {
33577
- if (!existsSync21(u.trash)) continue;
33962
+ if (!existsSync22(u.trash)) continue;
33578
33963
  rmSync7(u.target, { recursive: true, force: true });
33579
33964
  renameWithRetry(u.trash, u.target);
33580
33965
  }
@@ -33705,8 +34090,8 @@ function checkCall(tool, input) {
33705
34090
 
33706
34091
  // src/entries/server.ts
33707
34092
  import { randomUUID } from "node:crypto";
33708
- import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
33709
- import { dirname as dirname15, join as join26 } from "node:path";
34093
+ import { existsSync as existsSync24, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
34094
+ import { dirname as dirname15, join as join28 } from "node:path";
33710
34095
  import { fileURLToPath as fileURLToPath3 } from "node:url";
33711
34096
 
33712
34097
  // node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
@@ -51677,8 +52062,8 @@ function liftWireOnlyMaterial(message3, kind) {
51677
52062
  };
51678
52063
  }
51679
52064
  function codecResultValidator(codec, method) {
51680
- const probe = codec.validateResult(method, void 0);
51681
- if (!probe.ok && probe.reason === "not-in-era") return void 0;
52065
+ const probe2 = codec.validateResult(method, void 0);
52066
+ if (!probe2.ok && probe2.reason === "not-in-era") return void 0;
51682
52067
  return { "~standard": {
51683
52068
  version: 1,
51684
52069
  vendor: "mcp-wire-codec",
@@ -61771,8 +62156,8 @@ function installExitGuard(opts) {
61771
62156
  }
61772
62157
 
61773
62158
  // src/core/store/cleanup.ts
61774
- import { existsSync as existsSync22, readdirSync as readdirSync11, rmSync as rmSync8 } from "node:fs";
61775
- import { join as join25 } from "node:path";
62159
+ import { existsSync as existsSync23, readdirSync as readdirSync11, rmSync as rmSync8 } from "node:fs";
62160
+ import { join as join27 } from "node:path";
61776
62161
  function deleteSource(raw, id) {
61777
62162
  raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
61778
62163
  deleteChunkRows(raw, { sourceId: id });
@@ -61807,7 +62192,7 @@ function userVersion(raw) {
61807
62192
  return raw.prepare("PRAGMA user_version").get().user_version;
61808
62193
  }
61809
62194
  function openForSweep(dbPath, projectKey) {
61810
- if (!existsSync22(dbPath) && (existsSync22(dbPath + DB_WAL_SUFFIX) || existsSync22(dbPath + DB_SHM_SUFFIX))) {
62195
+ if (!existsSync23(dbPath) && (existsSync23(dbPath + DB_WAL_SUFFIX) || existsSync23(dbPath + DB_SHM_SUFFIX))) {
61811
62196
  throw new CtxError("DB_GONE");
61812
62197
  }
61813
62198
  const sqlite = process.getBuiltinModule("node:sqlite");
@@ -61828,8 +62213,8 @@ function lastAccess(raw) {
61828
62213
  return row5.t;
61829
62214
  }
61830
62215
  function sweepOne(configDir, projectKey, cutoff) {
61831
- const dir = join25(configDir, PROJECTS_DIR_NAME, projectKey);
61832
- const db = openForSweep(join25(dir, DB_FILE_NAME), projectKey);
62216
+ const dir = join27(configDir, PROJECTS_DIR_NAME, projectKey);
62217
+ const db = openForSweep(join27(dir, DB_FILE_NAME), projectKey);
61833
62218
  let dead;
61834
62219
  try {
61835
62220
  dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
@@ -61842,7 +62227,7 @@ function sweepOne(configDir, projectKey, cutoff) {
61842
62227
  function sweepDeadProjects(configDir) {
61843
62228
  let entries;
61844
62229
  try {
61845
- entries = readdirSync11(join25(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
62230
+ entries = readdirSync11(join27(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
61846
62231
  } catch (err) {
61847
62232
  if (err.code === "ENOENT") return [];
61848
62233
  throw err;
@@ -62007,15 +62392,15 @@ async function startServer(argv, env) {
62007
62392
  opening.catch(() => pending.delete(project.dbPath));
62008
62393
  }
62009
62394
  const db = await opening;
62010
- if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
62395
+ if (!existsSync24(db.path)) throw new CtxError("DB_GONE");
62011
62396
  return db;
62012
62397
  }
62013
62398
  function stopMarker(configDir, projectKey) {
62014
- return join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
62399
+ return join28(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
62015
62400
  }
62016
62401
  function stopRequested() {
62017
62402
  const configDir = resolveConfigDir(process.env);
62018
- return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
62403
+ return held.some((db) => existsSync24(stopMarker(configDir, db.projectKey)));
62019
62404
  }
62020
62405
  async function journal(project, ctx, name, reply4) {
62021
62406
  const db = await ownDb(project);
@@ -62135,6 +62520,23 @@ if (isEntry(import.meta.main, process.argv[1], fileURLToPath3(import.meta.url)))
62135
62520
  function str3(v) {
62136
62521
  return typeof v === "string" ? v : "";
62137
62522
  }
62523
+ function appendPayload(base, payload) {
62524
+ if (Array.isArray(base)) return [...base, payload];
62525
+ const text = str3(base);
62526
+ return text === "" ? payload : text + "\n\n" + payload;
62527
+ }
62528
+ var SECTION = "context_mode";
62529
+ function deliver(event, payload) {
62530
+ const options = event.systemPromptOptions;
62531
+ const sections = field(options, "sections");
62532
+ if (typeof sections === "object" && sections !== null && !Array.isArray(sections) && field(options, "forceSystemPrompt") === void 0) {
62533
+ const named2 = sections;
62534
+ if (payload === "") delete named2[SECTION];
62535
+ else named2[SECTION] = payload;
62536
+ return {};
62537
+ }
62538
+ return payload === "" ? {} : { systemPrompt: appendPayload(event.systemPrompt, payload) };
62539
+ }
62138
62540
  function textOf2(content) {
62139
62541
  if (typeof content === "string") return content;
62140
62542
  if (!Array.isArray(content)) return "";
@@ -62143,15 +62545,18 @@ function textOf2(content) {
62143
62545
  function field(v, key) {
62144
62546
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v[key] : void 0;
62145
62547
  }
62146
- function excludedTools(pi) {
62147
- let settings;
62548
+ function listOf2(settings) {
62549
+ const list4 = field(field(settings, "contextMode"), "excludeTools");
62550
+ return Array.isArray(list4) ? list4.filter((n) => typeof n === "string") : void 0;
62551
+ }
62552
+ function excludedTools(pi, host = "pi") {
62148
62553
  try {
62149
- settings = pi.getSettings?.();
62554
+ if (host === "pi") return listOf2(pi.getSettings?.()) ?? [];
62555
+ const settings = pi.pi?.settings;
62556
+ return listOf2(settings?.getProjectSettings?.()) ?? listOf2(settings?.getGlobalSettings?.()) ?? [];
62150
62557
  } catch {
62151
62558
  return [];
62152
62559
  }
62153
- const list4 = field(field(settings, "contextMode"), "excludeTools");
62154
- return Array.isArray(list4) ? list4.filter((n) => typeof n === "string") : [];
62155
62560
  }
62156
62561
  function errorReply2(err) {
62157
62562
  return { text: err instanceof CtxError ? err.toLine() : INTERNAL_ERROR_LINE, isError: true, sandboxBytes: 0 };
@@ -62161,6 +62566,10 @@ function toPi(reply4) {
62161
62566
  return { content: [{ type: "text", text: reply4.text }], details: {} };
62162
62567
  }
62163
62568
  function piExtension(pi) {
62569
+ hostExtension(pi, "pi");
62570
+ }
62571
+ function hostExtension(pi, host = "pi") {
62572
+ const agent = host;
62164
62573
  const env = process.env;
62165
62574
  let sessionId = "";
62166
62575
  let cwd = "";
@@ -62170,15 +62579,16 @@ function piExtension(pi) {
62170
62579
  let payload = "";
62171
62580
  const journal = ownJournal();
62172
62581
  let toolsRegistered = false;
62582
+ let openPrompt;
62173
62583
  function identify(ctx) {
62174
62584
  if (sessionId === "") sessionId = str3(ctx?.sessionManager?.getSessionId());
62175
62585
  if (cwd === "") cwd = str3(ctx?.cwd);
62176
62586
  }
62177
62587
  function hook(raw, atTurn) {
62178
- return handleHook("pi", { ...raw, sessionId, cwd, turn: atTurn }, env);
62588
+ return handleHook(agent, { ...raw, sessionId, cwd, turn: atTurn }, env);
62179
62589
  }
62180
62590
  function projectOf() {
62181
- project ??= resolveProject("pi", { env, argv: process.argv, cwd, piCwd: cwd });
62591
+ project ??= resolveProject(agent, { env, argv: process.argv, cwd, piCwd: cwd });
62182
62592
  return project;
62183
62593
  }
62184
62594
  async function runTool(tool, params, signal) {
@@ -62211,6 +62621,7 @@ function piExtension(pi) {
62211
62621
  label: tool.name,
62212
62622
  description: tool.description,
62213
62623
  parameters: external_exports.toJSONSchema(tool.schema),
62624
+ loadMode: "essential",
62214
62625
  execute: async (_toolCallId, params, signal) => toPi(await runTool(tool, params, signal))
62215
62626
  };
62216
62627
  }
@@ -62224,15 +62635,18 @@ function piExtension(pi) {
62224
62635
  }
62225
62636
  pi.on("before_agent_start", async (event, ctx) => {
62226
62637
  identify(ctx);
62227
- turn += 1;
62638
+ const prompt = typeof event.prompt === "string" ? event.prompt : void 0;
62639
+ const rerun = prompt !== void 0 && prompt === openPrompt;
62640
+ openPrompt = prompt;
62641
+ if (!rerun) turn += 1;
62228
62642
  registerTools();
62229
- const base = str3(event.systemPrompt);
62230
- const withPayload = () => ({ systemPrompt: base === "" ? payload : base + "\n\n" + payload });
62643
+ const withPayload = () => deliver(event, payload);
62644
+ if (rerun && payload !== "") return withPayload();
62231
62645
  let out;
62232
62646
  try {
62233
62647
  out = await hook({ type: compactPending ? "session_compact" : "session_start" }, turn);
62234
62648
  } catch {
62235
- return payload === "" ? {} : withPayload();
62649
+ return withPayload();
62236
62650
  }
62237
62651
  const compactTurn = compactPending;
62238
62652
  compactPending = false;
@@ -62245,6 +62659,7 @@ function piExtension(pi) {
62245
62659
  });
62246
62660
  pi.on("input", async (event, ctx) => {
62247
62661
  identify(ctx);
62662
+ openPrompt = void 0;
62248
62663
  await hook({ type: "input", message: str3(event.text) }, turn + 1);
62249
62664
  return void 0;
62250
62665
  });
@@ -62262,7 +62677,7 @@ function piExtension(pi) {
62262
62677
  input: event.input,
62263
62678
  content: textOf2(event.content),
62264
62679
  isError: event.isError === true,
62265
- keep: excludedTools(pi).includes(str3(event.toolName))
62680
+ keep: excludedTools(pi, host).includes(str3(event.toolName))
62266
62681
  }, turn);
62267
62682
  if (out.stdout === "") return void 0;
62268
62683
  const patch = { content: [{ type: "text", text: out.stdout }] };
@@ -62271,11 +62686,19 @@ function piExtension(pi) {
62271
62686
  });
62272
62687
  pi.on("session_compact", () => {
62273
62688
  compactPending = true;
62689
+ openPrompt = void 0;
62690
+ return void 0;
62691
+ });
62692
+ pi.on("agent_end", () => {
62693
+ openPrompt = void 0;
62274
62694
  return void 0;
62275
62695
  });
62696
+ if (host === "omp") registerTools();
62276
62697
  }
62277
62698
  export {
62278
- piExtension as default
62699
+ piExtension as default,
62700
+ excludedTools,
62701
+ hostExtension
62279
62702
  };
62280
62703
  /*! Bundled license information:
62281
62704