context-mode 2.1.5 → 2.1.6

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.
@@ -23,7 +23,14 @@ var POINTER_MIN = 640;
23
23
  var STATE_CLOSE_TAG = "</context_mode_state>";
24
24
  var INDEX_WRITE_CHUNK = 1048576;
25
25
  var SYNC_INDEX_MAX_BYTES = 65536;
26
- var REPLACE_TRIGGER_BYTES = 4096;
26
+ var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
27
+ var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
28
+ function readReplaceTrigger(raw) {
29
+ if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
30
+ const n = Number(raw);
31
+ return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
32
+ }
33
+ var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
27
34
  var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
28
35
  var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
29
36
  var REPLACE_RETURN_BYTES = 96;
@@ -249,6 +256,7 @@ function readHintEvery(raw) {
249
256
  }
250
257
  var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
251
258
  var MAX_NEST_DEPTH = 32;
259
+ var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
252
260
  var DENY_PREFIX = "context-mode: ";
253
261
  var DENY_WHAT = Object.freeze({
254
262
  curl: "This curl/wget call",
@@ -342,10 +350,10 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
342
350
  opencode: READ_IMAGES_AND_PDF,
343
351
  pi: READ_IMAGES,
344
352
  vscode: READ_IMAGES,
353
+ zcode: READ_IMAGES,
345
354
  "copilot-cli": [],
346
355
  codex: [],
347
- kiro: [],
348
- zcode: []
356
+ kiro: []
349
357
  });
350
358
  var OWN_TOOL_PREFIX = "ctx_";
351
359
  var SHELL_TOOL = "Bash";
@@ -363,6 +371,7 @@ var RECALL_MAX_ROWS = 340;
363
371
  var COMPACTED_META_PREFIX = "compacted:";
364
372
  var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
365
373
  var UNITS_ANCESTOR_FACTOR = 8;
374
+ var RECALL_QUERY_MAX_TERMS = 64;
366
375
  var RECALL_UNIT_CANDIDATES = 64;
367
376
  var RECALL_SEEN_META_PREFIX = "recall_seen:";
368
377
  var RECALL_OPEN_TAG = "<context_mode_recall>";
@@ -456,7 +465,7 @@ var DECISION_ANSWERS_KEY = "answers";
456
465
  var DECISION_OPTION_KEY = "option";
457
466
  var DECISION_LABEL_JOIN = " | ";
458
467
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
459
- var BUNDLE_SHA = true ? "f75e51d580374d518a8ceefc1422a009ffe67311" : void 0;
468
+ var BUNDLE_SHA = true ? "ee0a1f6058f6abdb5af70b05f825a997bb15615d" : void 0;
460
469
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
461
470
  var DOCTOR_LABEL = Object.freeze({
462
471
  D1: "version",
@@ -542,9 +551,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
542
551
  var D1_PRERELEASE_SEP = "-";
543
552
  var D1_DEFAULT_TAG = "latest";
544
553
  var GIT_LS_REMOTE = "ls-remote";
545
- var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
554
+ var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
546
555
  function D2_NODE_DETAIL(version2) {
547
- return `Node ${version2} is below ${NODE_MIN}`;
556
+ return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version2}`;
548
557
  }
549
558
  var D2_SQLITE_DETAIL = "node:sqlite failed to load";
550
559
  var D2_SQLITE_FIX = "run ctx_doctor";
@@ -709,6 +718,7 @@ var REGEX_ESCAPE = "\\";
709
718
  var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
710
719
  var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
711
720
  var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
721
+ var D5_READ_OWN_DETAIL = "PreToolUse Read of a skill file over the one-read limit under the agent's own config dir came back denied: skill and rule files must reach the model whole (#1326)";
712
722
  var D5_READ_MEDIA_DETAIL = "PreToolUse Read of a PNG over the one-read limit came back denied: an image Read must reach the model as an image block (#1321)";
713
723
  var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
714
724
  function D5_SLOW_DETAIL(ms) {
@@ -720,6 +730,16 @@ var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
720
730
  function D10_DETAIL(mode) {
721
731
  return `enforcement mode: ${mode}`;
722
732
  }
733
+ function D10_PERMISSION_DETAIL(mode) {
734
+ return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
735
+ }
736
+ var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
737
+ var D10_PERMISSION_FIX = "opencode upgrade";
738
+ var OC_SHELL_ACTION = "shell";
739
+ var OC_LEGACY_SHELL_ACTION = "bash";
740
+ var OC_READ_ACTION = "read";
741
+ var OC_WEBFETCH_ACTION = "webfetch";
742
+ var OC_ANY_RESOURCE = "*";
723
743
  var D11_WIN_DETAIL = "Git Bash not found";
724
744
  var D11_WIN_FIX = "install Git for Windows";
725
745
  var D11_POSIX_DETAIL = "no sh on PATH";
@@ -782,6 +802,8 @@ var SETTINGS_FILE = "settings.json";
782
802
  var CLAUDE_USER_CONFIG_FILE = ".claude.json";
783
803
  var HOOKS_JSON_FILE = "hooks.json";
784
804
  var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
805
+ var SETUP_BACKUP_DIR_NAME = "backups";
806
+ var SETUP_MANIFEST_FILE = "manifest.json";
785
807
  var CODEX_HOME_ENV = "CODEX_HOME";
786
808
  var COPILOT_HOME_ENV = "COPILOT_HOME";
787
809
  var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
@@ -875,6 +897,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
875
897
  var JSON_INDENT_UNIT = " ";
876
898
  var MCP_COMMAND_FIELD = "command";
877
899
  var MCP_ARGS_FIELD = "args";
900
+ var MCP_ENV_FIELD = "env";
878
901
  var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
879
902
  var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
880
903
  var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
@@ -992,7 +1015,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
992
1015
 
993
1016
  // src/core/contracts/errors.ts
994
1017
  var ERROR_TEXT = Object.freeze({
995
- NODE_TOO_OLD: "Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",
1018
+ NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
1019
+ // #1328 D-NODE-OLD-1
996
1020
  NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
997
1021
  DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
998
1022
  // D-ORPHAN-WAL-1
@@ -1062,7 +1086,7 @@ var CtxError = class extends Error {
1062
1086
  };
1063
1087
 
1064
1088
  // src/core/hooks/dispatch.ts
1065
- import { dirname as dirname4, join as join7, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
1089
+ import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
1066
1090
 
1067
1091
  // src/core/contracts/agents.ts
1068
1092
  var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
@@ -3411,7 +3435,7 @@ function withLayout(text, layout) {
3411
3435
 
3412
3436
  // src/core/project/config-dir.ts
3413
3437
  import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
3414
- var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
3438
+ var { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
3415
3439
  function homeDirOf(env, platform = process.platform) {
3416
3440
  const set3 = (v) => v !== void 0 && v !== "";
3417
3441
  if (platform === "win32") {
@@ -3438,7 +3462,34 @@ function codexPluginHomeOf(bundleDir2) {
3438
3462
  function codexRunDirOf(env, home, bundleDir2) {
3439
3463
  const dir = env[CODEX_HOME_ENV];
3440
3464
  if (dir !== void 0 && dir !== "") return dir;
3441
- return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
3465
+ return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
3466
+ }
3467
+ function codexSetupHomeOf(env, home) {
3468
+ if (home === "" && !env[DATA_DIR_ENV]) return null;
3469
+ const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
3470
+ let runs;
3471
+ try {
3472
+ runs = readdirSync(base).sort().reverse();
3473
+ } catch {
3474
+ return null;
3475
+ }
3476
+ for (const run of runs) {
3477
+ const file2 = join(base, run, SETUP_MANIFEST_FILE);
3478
+ if (!existsSync(file2)) continue;
3479
+ let entries;
3480
+ try {
3481
+ entries = JSON.parse(readFileSync(file2, "utf8")).entries;
3482
+ } catch {
3483
+ continue;
3484
+ }
3485
+ if (!Array.isArray(entries)) continue;
3486
+ for (const e of entries) {
3487
+ if (e?.agent !== "codex" || typeof e.file !== "string") continue;
3488
+ const p = e.file.includes(win32.sep) ? win32 : posix;
3489
+ if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
3490
+ }
3491
+ }
3492
+ return null;
3442
3493
  }
3443
3494
  function copilotDirOf(env, home) {
3444
3495
  const dir = env[COPILOT_HOME_ENV];
@@ -3518,7 +3569,7 @@ function resolveConfigDir(env) {
3518
3569
  }
3519
3570
 
3520
3571
  // src/core/policy/subagent.ts
3521
- var { readFileSync } = process.getBuiltinModule("node:fs");
3572
+ var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
3522
3573
  function isSubagentCall(ev) {
3523
3574
  return ev.agentId !== void 0 && ev.agentId !== "";
3524
3575
  }
@@ -3579,7 +3630,7 @@ function readPluginAgent(claudeDir, type) {
3579
3630
  if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
3580
3631
  let parsed;
3581
3632
  try {
3582
- parsed = JSON.parse(hostText(readFileSync(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
3633
+ parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
3583
3634
  } catch {
3584
3635
  return null;
3585
3636
  }
@@ -3602,7 +3653,7 @@ function readPluginAgent(claudeDir, type) {
3602
3653
  function readAgentFile(path8) {
3603
3654
  let text;
3604
3655
  try {
3605
- text = readFileSync(path8, "utf8");
3656
+ text = readFileSync2(path8, "utf8");
3606
3657
  } catch {
3607
3658
  return null;
3608
3659
  }
@@ -3810,7 +3861,7 @@ function unwrap(commands) {
3810
3861
 
3811
3862
  // src/core/policy/user-deny.ts
3812
3863
  import { isAbsolute, join as join3, relative, sep } from "node:path";
3813
- var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
3864
+ var { readFileSync: readFileSync3 } = process.getBuiltinModule("node:fs");
3814
3865
  var CLAUDE_DIR = ".claude";
3815
3866
  var LOCAL_SETTINGS = "settings.local.json";
3816
3867
  var SETTINGS = "settings.json";
@@ -3837,7 +3888,7 @@ function isObject(v) {
3837
3888
  function readOne(file2) {
3838
3889
  let text;
3839
3890
  try {
3840
- text = hostText(readFileSync2(file2, "utf8"));
3891
+ text = hostText(readFileSync3(file2, "utf8"));
3841
3892
  } catch (err) {
3842
3893
  return err.code === "ENOENT" ? { kind: "absent" } : { kind: "bad" };
3843
3894
  }
@@ -4000,6 +4051,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
4000
4051
  ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
4001
4052
  });
4002
4053
  var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limit. Run ctx_execute(language, code, file="{path}") and print only the answer.';
4054
+ var READ_DENY_RANGE_TEMPLATE = `context-mode: {size}-byte file, over the one-read limit. Read "{path}" in parts with offset and limit, or sed -n '1,200p'.`;
4003
4055
 
4004
4056
  // src/core/policy/read-deny.ts
4005
4057
  var SIZE = "{size}";
@@ -4007,9 +4059,105 @@ var PATH = "{path}";
4007
4059
  function READ_DENY_MESSAGE(path8, size, prefix = "") {
4008
4060
  return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
4009
4061
  }
4062
+ function READ_DENY_RANGE_MESSAGE(path8, size) {
4063
+ return READ_DENY_RANGE_TEMPLATE.split(SIZE).join(String(size)).split(PATH).join(path8);
4064
+ }
4065
+
4066
+ // src/core/policy/own-file.ts
4067
+ import { extname, join as join5 } from "node:path";
4068
+
4069
+ // src/core/project/contain.ts
4070
+ import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
4071
+ var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
4072
+ function real(p) {
4073
+ try {
4074
+ return realpathSync2.native(p);
4075
+ } catch {
4076
+ return void 0;
4077
+ }
4078
+ }
4079
+ function components(p) {
4080
+ return p.split(sep2).filter((c) => c !== "");
4081
+ }
4082
+ function isInside(root, p) {
4083
+ const r = real(root);
4084
+ const q = real(p);
4085
+ if (r === void 0 || q === void 0) return false;
4086
+ const rc = components(r);
4087
+ const qc = components(q);
4088
+ if (qc.length < rc.length) return false;
4089
+ for (let i = 0; i < rc.length; i += 1) {
4090
+ if (rc[i] !== qc[i]) return false;
4091
+ }
4092
+ return true;
4093
+ }
4094
+ var rootReal = /* @__PURE__ */ new Map();
4095
+ function realRoot(root) {
4096
+ const hit = rootReal.get(root);
4097
+ if (hit !== void 0) return hit;
4098
+ const r = real(root);
4099
+ if (r !== void 0) rootReal.set(root, r);
4100
+ return r;
4101
+ }
4102
+ function isInsideAny(roots, p) {
4103
+ if (roots.length === 0) return false;
4104
+ const q = real(p);
4105
+ if (q === void 0) return false;
4106
+ const qc = components(q);
4107
+ return roots.some((root) => {
4108
+ const r = realRoot(root);
4109
+ if (r === void 0) return false;
4110
+ const rc = components(r);
4111
+ return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
4112
+ });
4113
+ }
4114
+ function commonRoot(paths) {
4115
+ const reals = paths.map(real).filter((r) => r !== void 0);
4116
+ if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
4117
+ const first = reals[0];
4118
+ let n = components(first).length;
4119
+ for (const r of reals) {
4120
+ const rc = components(r);
4121
+ const fc = components(first);
4122
+ let i = 0;
4123
+ while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
4124
+ n = i;
4125
+ }
4126
+ let q = first;
4127
+ while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
4128
+ return q;
4129
+ }
4130
+ function reachedThroughLink(root, p) {
4131
+ const rel = relative2(root, p);
4132
+ const steps = components(rel);
4133
+ if (rel === "" || steps[0] === ".." || rel === p) return false;
4134
+ let at2 = root;
4135
+ for (const step of steps) {
4136
+ at2 = join4(at2, step);
4137
+ try {
4138
+ if (lstatSync(at2).isSymbolicLink()) return true;
4139
+ } catch {
4140
+ return false;
4141
+ }
4142
+ }
4143
+ return false;
4144
+ }
4145
+
4146
+ // src/core/policy/own-file.ts
4147
+ function ownDirsOf(agent, env) {
4148
+ const home = homeDirOf(env);
4149
+ if (home === null) return [];
4150
+ const shared = join5(home, ...SHARED_SKILLS_DIR);
4151
+ const own2 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
4152
+ return [...own2, shared];
4153
+ }
4154
+ function isOwnFile(agent, abs, env = process.env) {
4155
+ if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
4156
+ return isInsideAny(ownDirsOf(agent, env), abs);
4157
+ }
4010
4158
 
4011
4159
  // src/core/policy/read-media.ts
4012
- import { extname } from "node:path";
4160
+ import { extname as extname2 } from "node:path";
4013
4161
  var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
4014
4162
  function head(abs) {
4015
4163
  let fd = null;
@@ -4027,7 +4175,7 @@ function head(abs) {
4027
4175
  function isMediaRead(agent, abs) {
4028
4176
  const types = READ_MEDIA_BY_AGENT[agent] ?? [];
4029
4177
  if (types.length === 0) return false;
4030
- const ext = extname(abs).toLowerCase();
4178
+ const ext = extname2(abs).toLowerCase();
4031
4179
  const named2 = types.filter((t) => READ_MEDIA_TYPES[t].exts.includes(ext));
4032
4180
  if (named2.length === 0) return false;
4033
4181
  const bytes5 = head(abs);
@@ -4058,7 +4206,7 @@ var deny = (reason) => ({ kind: "deny", reason });
4058
4206
  var str = (v) => typeof v === "string" ? v : void 0;
4059
4207
  var present = (v) => v !== void 0 && v !== null;
4060
4208
  var has = (list4, v) => list4.includes(v);
4061
- function decide(ev, row5, userDeny) {
4209
+ function decide(ev, row5, userDeny, root = ev.cwd) {
4062
4210
  const tool = ev.tool;
4063
4211
  if (tool === void 0) return ALLOW;
4064
4212
  const canonical = tool.canonicalName;
@@ -4072,8 +4220,8 @@ function decide(ev, row5, userDeny) {
4072
4220
  const hit = userDenyHit(canonical, input, ev.cwd, rules);
4073
4221
  if (hit !== null) return deny(USER_DENY_REASON_PREFIX + hit);
4074
4222
  if (canonical === WEBFETCH) return webFetch(input, row5);
4075
- if (canonical === BASH) return bash(ev, row5, input, rules);
4076
- if (canonical === READ) return read(ev, row5, input);
4223
+ if (canonical === BASH) return bash(ev, row5, input, rules, root);
4224
+ if (canonical === READ) return read(ev, row5, input, root);
4077
4225
  return ALLOW;
4078
4226
  }
4079
4227
  function denyMessage(kind, match, row5, intent) {
@@ -4126,8 +4274,8 @@ function userDenyHit(canonical, input, cwd, rules) {
4126
4274
  function isShellLanguage(language) {
4127
4275
  if (typeof language !== "string") return false;
4128
4276
  let name = language.toLowerCase();
4129
- const slash = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
4130
- if (slash >= 0) name = name.slice(slash + 1);
4277
+ const slash2 = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
4278
+ if (slash2 >= 0) name = name.slice(slash2 + 1);
4131
4279
  if (name.endsWith(EXE_SUFFIX2)) name = name.slice(0, name.length - EXE_SUFFIX2.length);
4132
4280
  return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
4133
4281
  }
@@ -4175,10 +4323,10 @@ function webFetch(input, row5) {
4175
4323
  const url2 = str(input.url) ?? "";
4176
4324
  return neverDenied(url2) ? ALLOW : deny(denyMessage("webfetch", url2, row5));
4177
4325
  }
4178
- function bash(ev, row5, input, rules) {
4326
+ function bash(ev, row5, input, rules, root) {
4179
4327
  const cmd = str(input.command) ?? "";
4180
4328
  const parsed = parseShell(cmd);
4181
- if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
4329
+ if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(ev, cmd, row5, root) ?? ALLOW;
4182
4330
  const cmds = unwrap(parsed.commands);
4183
4331
  for (const c of cmds) {
4184
4332
  const h = segmentHit(c, rules);
@@ -4190,7 +4338,7 @@ function bash(ev, row5, input, rules) {
4190
4338
  if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
4191
4339
  }
4192
4340
  }
4193
- return shellDump(cmds, ev.cwd, row5) ?? psShellDump(cmd, ev.cwd, row5) ?? ALLOW;
4341
+ return shellDump(ev, cmds, row5, root) ?? psShellDump(ev, cmd, row5, root) ?? ALLOW;
4194
4342
  }
4195
4343
  function denyKind(c) {
4196
4344
  const name = c.argv0.toLowerCase();
@@ -4233,19 +4381,35 @@ function fileSize(abs) {
4233
4381
  return -1;
4234
4382
  }
4235
4383
  }
4236
- function read(ev, row5, input) {
4384
+ function bigDeny(ev, row5, abs, size, root) {
4385
+ if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
4386
+ return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
4387
+ }
4388
+ function executeCanOpen(root, abs) {
4389
+ if (typeof root === "string") return isInsideAny([root], abs);
4390
+ if (isInsideAny([root.worktree], abs)) return true;
4391
+ try {
4392
+ return isInsideAny([root.containmentRoot], abs);
4393
+ } catch {
4394
+ return false;
4395
+ }
4396
+ }
4397
+ function read(ev, row5, input, root) {
4237
4398
  if (!present(input.offset) && !present(input.limit)) {
4238
4399
  for (const p of readPaths(input)) {
4239
4400
  const abs = resolve3(ev.cwd, p);
4240
4401
  const size = fileSize(abs);
4241
- if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
4402
+ if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
4403
+ const d = bigDeny(ev, row5, abs, size, root);
4404
+ if (d !== null) return d;
4405
+ }
4242
4406
  }
4243
4407
  }
4244
4408
  return ALLOW;
4245
4409
  }
4246
- function shellDump(cmds, cwd, row5) {
4410
+ function shellDump(ev, cmds, row5, root) {
4247
4411
  if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
4248
- let dir = cwd;
4412
+ let dir = ev.cwd;
4249
4413
  let verdict = null;
4250
4414
  for (const c of cmds) {
4251
4415
  const name = c.argv0.toLowerCase();
@@ -4259,16 +4423,16 @@ function shellDump(cmds, cwd, row5) {
4259
4423
  continue;
4260
4424
  }
4261
4425
  const abs = resolve3(dir, d.file);
4262
- const size = fileSize(abs);
4263
- if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
4426
+ const big = bigDeny(ev, row5, abs, fileSize(abs), root);
4427
+ if (big !== null) return big;
4264
4428
  }
4265
4429
  return verdict;
4266
4430
  }
4267
- function psShellDump(cmd, cwd, row5) {
4431
+ function psShellDump(ev, cmd, row5, root) {
4268
4432
  if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
4269
- for (const abs of psDumpFiles(cmd, cwd)) {
4270
- const size = fileSize(abs);
4271
- if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
4433
+ for (const abs of psDumpFiles(cmd, ev.cwd)) {
4434
+ const d = bigDeny(ev, row5, abs, fileSize(abs), root);
4435
+ if (d !== null) return d;
4272
4436
  }
4273
4437
  return null;
4274
4438
  }
@@ -4329,64 +4493,7 @@ function dumpTarget(name, args) {
4329
4493
  }
4330
4494
 
4331
4495
  // src/core/project/resolve.ts
4332
- import { basename as basename2, dirname as dirname3, join as join5, resolve as resolve4 } from "node:path";
4333
-
4334
- // src/core/project/contain.ts
4335
- import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
4336
- var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
4337
- function real(p) {
4338
- try {
4339
- return realpathSync2.native(p);
4340
- } catch {
4341
- return void 0;
4342
- }
4343
- }
4344
- function components(p) {
4345
- return p.split(sep2).filter((c) => c !== "");
4346
- }
4347
- function isInside(root, p) {
4348
- const r = real(root);
4349
- const q = real(p);
4350
- if (r === void 0 || q === void 0) return false;
4351
- const rc = components(r);
4352
- const qc = components(q);
4353
- if (qc.length < rc.length) return false;
4354
- for (let i = 0; i < rc.length; i += 1) {
4355
- if (rc[i] !== qc[i]) return false;
4356
- }
4357
- return true;
4358
- }
4359
- function commonRoot(paths) {
4360
- const reals = paths.map(real).filter((r) => r !== void 0);
4361
- if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
4362
- const first = reals[0];
4363
- let n = components(first).length;
4364
- for (const r of reals) {
4365
- const rc = components(r);
4366
- const fc = components(first);
4367
- let i = 0;
4368
- while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
4369
- n = i;
4370
- }
4371
- let q = first;
4372
- while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
4373
- return q;
4374
- }
4375
- function reachedThroughLink(root, p) {
4376
- const rel = relative2(root, p);
4377
- const steps = components(rel);
4378
- if (rel === "" || steps[0] === ".." || rel === p) return false;
4379
- let at2 = root;
4380
- for (const step of steps) {
4381
- at2 = join4(at2, step);
4382
- try {
4383
- if (lstatSync(at2).isSymbolicLink()) return true;
4384
- } catch {
4385
- return false;
4386
- }
4387
- }
4388
- return false;
4389
- }
4496
+ import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
4390
4497
 
4391
4498
  // src/core/project/sha256.ts
4392
4499
  var K = new Uint32Array([
@@ -4501,7 +4608,7 @@ function sha256Hex(text) {
4501
4608
  }
4502
4609
 
4503
4610
  // src/core/project/resolve.ts
4504
- var { existsSync, readFileSync: readFileSync3, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
4611
+ var { existsSync: existsSync2, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
4505
4612
  function sourceOf(agent) {
4506
4613
  switch (agent) {
4507
4614
  case "claude-code":
@@ -4548,9 +4655,9 @@ function gitDirs(dir) {
4548
4655
  }
4549
4656
  const start = cur;
4550
4657
  for (; ; ) {
4551
- const gitDir = gitDirAt(join5(cur, GIT_DIR_NAME));
4658
+ const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
4552
4659
  if (gitDir !== null) {
4553
- const common = firstLine(join5(gitDir, GIT_COMMONDIR_FILE));
4660
+ const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
4554
4661
  return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
4555
4662
  }
4556
4663
  const up = dirname3(cur);
@@ -4571,12 +4678,12 @@ function gitDirAt(dotGit) {
4571
4678
  } catch {
4572
4679
  return null;
4573
4680
  }
4574
- return existsSync(join5(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
4681
+ return existsSync2(join6(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
4575
4682
  }
4576
4683
  function firstLine(file2) {
4577
4684
  let text;
4578
4685
  try {
4579
- text = readFileSync3(file2, "utf8");
4686
+ text = readFileSync4(file2, "utf8");
4580
4687
  } catch {
4581
4688
  return null;
4582
4689
  }
@@ -4612,11 +4719,11 @@ function resolveProject(agent, src) {
4612
4719
  return key;
4613
4720
  },
4614
4721
  get projectDir() {
4615
- pdir ??= join5(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
4722
+ pdir ??= join6(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
4616
4723
  return pdir;
4617
4724
  },
4618
4725
  get dbPath() {
4619
- return join5(this.projectDir, DB_FILE_NAME);
4726
+ return join6(this.projectDir, DB_FILE_NAME);
4620
4727
  },
4621
4728
  worktree,
4622
4729
  get containmentRoot() {
@@ -4767,7 +4874,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
4767
4874
  }
4768
4875
 
4769
4876
  // src/core/store/db.ts
4770
- var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
4877
+ var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
4771
4878
  function versionParts(v) {
4772
4879
  const bare2 = v.startsWith("v") ? v.slice(1) : v;
4773
4880
  return bare2.split(".").map((p) => Number.parseInt(p, 10));
@@ -4821,7 +4928,7 @@ function createAtomically(sqlite, path8) {
4821
4928
  function openWritable(sqlite, path8) {
4822
4929
  let raw = null;
4823
4930
  try {
4824
- if (!existsSync2(path8)) createAtomically(sqlite, path8);
4931
+ if (!existsSync3(path8)) createAtomically(sqlite, path8);
4825
4932
  raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
4826
4933
  applyMigrations(raw, readUserVersion(raw));
4827
4934
  return raw;
@@ -4846,14 +4953,14 @@ async function openDb(project, opts) {
4846
4953
  const sqlite = await loadSqlite();
4847
4954
  mkdirSync2(project.projectDir, { recursive: true });
4848
4955
  const path8 = project.dbPath;
4849
- const sibling = existsSync2(path8 + DB_WAL_SUFFIX) || existsSync2(path8 + DB_SHM_SUFFIX);
4850
- if (sibling && !existsSync2(path8)) {
4956
+ const sibling = existsSync3(path8 + DB_WAL_SUFFIX) || existsSync3(path8 + DB_SHM_SUFFIX);
4957
+ if (sibling && !existsSync3(path8)) {
4851
4958
  throw new CtxError("DB_GONE");
4852
4959
  }
4853
4960
  try {
4854
4961
  let raw;
4855
4962
  if (opts?.readOnly === true) {
4856
- if (!existsSync2(path8)) openWritable(sqlite, path8).close();
4963
+ if (!existsSync3(path8)) openWritable(sqlite, path8).close();
4857
4964
  raw = openReadOnly(sqlite, path8);
4858
4965
  } else {
4859
4966
  raw = openWritable(sqlite, path8);
@@ -5003,11 +5110,6 @@ function readLastPrompt(db, sessionId) {
5003
5110
  const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
5004
5111
  return row5 === void 0 ? "" : row5.body;
5005
5112
  }
5006
- function readFirstPrompt(db, sessionId) {
5007
- if (sessionId === "") return "";
5008
- const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
5009
- return row5 === void 0 ? "" : row5.body;
5010
- }
5011
5113
  function readRecallRows(db, sessionId, worktree, limit) {
5012
5114
  if (sessionId === "") return [];
5013
5115
  return db.raw.prepare("SELECT * FROM events WHERE kind <> 'cost' AND (session_id = ? OR worktree = ?) ORDER BY seq DESC LIMIT ?").all(sessionId, worktree, limit);
@@ -7575,8 +7677,25 @@ function insertUnits(db, sourceId, sessionId, units) {
7575
7677
  start = end;
7576
7678
  }
7577
7679
  }
7578
- function recallQueryText(prompt, goal) {
7579
- return goal === prompt ? prompt : prompt + " " + goal;
7680
+ function recallQueryText(prompt) {
7681
+ const kept = /* @__PURE__ */ new Set();
7682
+ const all = /* @__PURE__ */ new Set();
7683
+ const add = (w) => {
7684
+ if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
7685
+ if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
7686
+ };
7687
+ let cur = "";
7688
+ for (const ch of prompt) {
7689
+ if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
7690
+ if (ch.trim() === "" || ch === "\0") {
7691
+ if (cur !== "") add(cur);
7692
+ cur = "";
7693
+ } else {
7694
+ cur += ch;
7695
+ }
7696
+ }
7697
+ if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
7698
+ return [...kept.size > 0 ? kept : all].join(" ");
7580
7699
  }
7581
7700
  function queryUnits(db, sessionId, q, limit) {
7582
7701
  const match = searchTerms(q).join(" OR ");
@@ -8165,7 +8284,7 @@ function cutPoint(src, start, end, scratch) {
8165
8284
  const r = encoder.encodeInto(src.slice(start, limit), scratch);
8166
8285
  return { end: start + r.read, written: r.written };
8167
8286
  }
8168
- function merge(src, blocks, join24, cap, lineCut) {
8287
+ function merge(src, blocks, join25, cap, lineCut) {
8169
8288
  const out = [];
8170
8289
  const scratch = new Uint8Array(cap);
8171
8290
  let wide;
@@ -8175,7 +8294,7 @@ function merge(src, blocks, join24, cap, lineCut) {
8175
8294
  out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
8176
8295
  };
8177
8296
  for (const b of blocks) {
8178
- if (cur !== void 0 && !join24) {
8297
+ if (cur !== void 0 && !join25) {
8179
8298
  emit(cur.start, cur.end, curBytes);
8180
8299
  cur = void 0;
8181
8300
  }
@@ -8617,7 +8736,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
8617
8736
  }
8618
8737
 
8619
8738
  // src/core/hooks/fallback.ts
8620
- import { join as join6, resolve as resolve5 } from "node:path";
8739
+ import { join as join7, resolve as resolve5 } from "node:path";
8621
8740
  var fs = process.getBuiltinModule("node:fs");
8622
8741
  function isRec(v) {
8623
8742
  return typeof v === "object" && v !== null && !Array.isArray(v);
@@ -8645,9 +8764,9 @@ function homeOf(env) {
8645
8764
  }
8646
8765
  function hookLogPath(env) {
8647
8766
  const dir = env[DATA_DIR_ENV];
8648
- if (dir !== void 0 && dir !== "") return join6(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
8767
+ if (dir !== void 0 && dir !== "") return join7(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
8649
8768
  const home = homeOf(env);
8650
- return home === "" ? "" : join6(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
8769
+ return home === "" ? "" : join7(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
8651
8770
  }
8652
8771
  function errorLabel(err) {
8653
8772
  const code = isRec(err) ? err.code : void 0;
@@ -8658,7 +8777,7 @@ function logHookError(env, agent, stage, err) {
8658
8777
  try {
8659
8778
  const file2 = hookLogPath(env);
8660
8779
  if (file2 === "") return;
8661
- fs.mkdirSync(join6(file2, ".."), { recursive: true });
8780
+ fs.mkdirSync(join7(file2, ".."), { recursive: true });
8662
8781
  const line = JSON.stringify({
8663
8782
  ts: (/* @__PURE__ */ new Date()).toISOString(),
8664
8783
  agent,
@@ -8740,7 +8859,7 @@ function bigFile(abs) {
8740
8859
  function bigRead(agent, input, cwd) {
8741
8860
  if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
8742
8861
  const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
8743
- return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)));
8862
+ return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)) && !isOwnFile(agent, resolve5(cwd, p)));
8744
8863
  }
8745
8864
  function failureOutput(agent, raw, err, cwdFallback = "") {
8746
8865
  const row5 = getAdapter(agent);
@@ -8766,7 +8885,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
8766
8885
  var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
8767
8886
 
8768
8887
  // src/core/hooks/dispatch.ts
8769
- var { lstatSync: lstatSync2, readFileSync: readFileSync4 } = process.getBuiltinModule("node:fs");
8888
+ var { lstatSync: lstatSync2, readFileSync: readFileSync5 } = process.getBuiltinModule("node:fs");
8770
8889
  var ALLOW2 = { kind: "allow" };
8771
8890
  var EMPTY5 = { stdout: "", exitCode: 0 };
8772
8891
  var DIGIT_0 = 48;
@@ -8929,8 +9048,7 @@ async function recall(ev, row5, project, prompt) {
8929
9048
  const seen = seenSeqs(metaGet(db, seenKey));
8930
9049
  const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
8931
9050
  const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
8932
- const goal = readFirstPrompt(db, ev.sessionId);
8933
- const units = queryUnits(db, ev.sessionId, recallQueryText(prompt, goal), RECALL_UNIT_CANDIDATES);
9051
+ const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
8934
9052
  const picked = pickRecall(readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS), prompt, new Set(seen), units, new Set(seenUnits));
8935
9053
  if (picked.text === "") return ALLOW2;
8936
9054
  if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
@@ -9002,7 +9120,7 @@ function askDetached(ev, project, tool, text) {
9002
9120
  }
9003
9121
  async function preToolUse(ev, row5, project, env) {
9004
9122
  const userDeny = readUserDeny(project.worktree, ev.agent);
9005
- const decision0 = decide(ev, row5, userDeny);
9123
+ const decision0 = decide(ev, row5, userDeny, project);
9006
9124
  let decision = decision0;
9007
9125
  if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
9008
9126
  const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
@@ -9028,7 +9146,7 @@ function caseB(ev, row5, d0, userDeny) {
9028
9146
  if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
9029
9147
  const command = tool.input.command;
9030
9148
  if (typeof command !== "string") return d0;
9031
- const wrapper = '"' + join7(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
9149
+ const wrapper = '"' + join8(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
9032
9150
  const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
9033
9151
  return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
9034
9152
  }
@@ -9105,9 +9223,15 @@ async function postToolUse(ev, row5, project, env, settle) {
9105
9223
  settle.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
9106
9224
  return decision;
9107
9225
  }
9226
+ function ownRead(ev, tool, env) {
9227
+ if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
9228
+ const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
9229
+ return p !== void 0 && isOwnFile(ev.agent, resolve6(ev.cwd, p), env);
9230
+ }
9108
9231
  async function postReplace(ev, row5, project, env, tool, result, text) {
9109
9232
  if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
9110
9233
  if (boundedRead(tool)) return ALLOW2;
9234
+ if (ownRead(ev, tool, env)) return ALLOW2;
9111
9235
  if (result.keep === true) return ALLOW2;
9112
9236
  if (!hasReplace(row5)) return ALLOW2;
9113
9237
  let label2;
@@ -9150,7 +9274,7 @@ function replaceBudget(handleLine, more) {
9150
9274
  }
9151
9275
  function hostToolResult(file2, sessionId, env) {
9152
9276
  if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
9153
- const projects = join7(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
9277
+ const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
9154
9278
  const steps = relative3(projects, resolve6(file2)).split(sep3);
9155
9279
  if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
9156
9280
  if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
@@ -9165,7 +9289,7 @@ function wholeOutput(result, sessionId, env) {
9165
9289
  logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
9166
9290
  return head2;
9167
9291
  }
9168
- return readFileSync4(result.persistedPath, "utf8");
9292
+ return readFileSync5(result.persistedPath, "utf8");
9169
9293
  } catch {
9170
9294
  return head2;
9171
9295
  }
@@ -20527,10 +20651,10 @@ function startArgv(argv) {
20527
20651
  return sh === null ? null : [sh, ...argv];
20528
20652
  }
20529
20653
  function runProcess(argv, o) {
20530
- return new Promise((resolve10) => {
20654
+ return new Promise((resolve11) => {
20531
20655
  const isWin2 = process.platform === "win32";
20532
20656
  const start = startArgv(argv);
20533
- if (start === null) return resolve10(NOT_STARTED);
20657
+ if (start === null) return resolve11(NOT_STARTED);
20534
20658
  let child;
20535
20659
  try {
20536
20660
  child = spawn(start[0], start.slice(1), {
@@ -20544,7 +20668,7 @@ function runProcess(argv, o) {
20544
20668
  windowsHide: true
20545
20669
  });
20546
20670
  } catch {
20547
- return resolve10(NOT_STARTED);
20671
+ return resolve11(NOT_STARTED);
20548
20672
  }
20549
20673
  const stdoutChunks = [];
20550
20674
  const stderrChunks = [];
@@ -20569,7 +20693,7 @@ function runProcess(argv, o) {
20569
20693
  settled = true;
20570
20694
  clearTimeout(timer);
20571
20695
  o.signal.removeEventListener("abort", onAbort);
20572
- resolve10({
20696
+ resolve11({
20573
20697
  stdout: Buffer.concat(stdoutChunks),
20574
20698
  stderr: Buffer.concat(stderrChunks),
20575
20699
  exitCode,
@@ -20590,8 +20714,8 @@ function runProcess(argv, o) {
20590
20714
  }
20591
20715
 
20592
20716
  // src/core/index/auto-memory.ts
20593
- import { readdirSync, readFileSync as readFileSync5, statSync as statSync4 } from "node:fs";
20594
- import { join as join8 } from "node:path";
20717
+ import { readdirSync as readdirSync2, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
20718
+ import { join as join9 } from "node:path";
20595
20719
  var MEMORY_FILES = Object.freeze([
20596
20720
  Object.freeze(["CLAUDE.md"]),
20597
20721
  Object.freeze(["CLAUDE.local.md"]),
@@ -20605,7 +20729,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
20605
20729
  var MD = ".md";
20606
20730
  function steeringFiles(worktree) {
20607
20731
  try {
20608
- return readdirSync(join8(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
20732
+ return readdirSync2(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
20609
20733
  } catch {
20610
20734
  return [];
20611
20735
  }
@@ -20613,7 +20737,7 @@ function steeringFiles(worktree) {
20613
20737
  function readAutoMemory(project) {
20614
20738
  const rows = [];
20615
20739
  for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
20616
- const path8 = join8(project.worktree, ...segs);
20740
+ const path8 = join9(project.worktree, ...segs);
20617
20741
  if (!isInside(project.worktree, path8)) continue;
20618
20742
  try {
20619
20743
  const st = statSync4(path8);
@@ -20625,7 +20749,7 @@ function readAutoMemory(project) {
20625
20749
  sourceId: null,
20626
20750
  path: path8,
20627
20751
  label: segs.join("/"),
20628
- text: readFileSync5(path8, "utf8")
20752
+ text: readFileSync6(path8, "utf8")
20629
20753
  });
20630
20754
  } catch {
20631
20755
  }
@@ -21195,19 +21319,19 @@ var ctxBatch = Object.freeze({
21195
21319
  });
21196
21320
 
21197
21321
  // src/core/tools/doctor.ts
21198
- import { readdirSync as readdirSync6, readFileSync as readFileSync14, existsSync as existsSync15 } from "node:fs";
21199
- import { basename as basename5, join as join18 } from "node:path";
21322
+ import { readdirSync as readdirSync7, readFileSync as readFileSync15, existsSync as existsSync16 } from "node:fs";
21323
+ import { basename as basename5, join as join19 } from "node:path";
21200
21324
 
21201
21325
  // src/core/ops/bundle-dir.ts
21202
- import { existsSync as existsSync3 } from "node:fs";
21203
- import { dirname as dirname5, join as join9 } from "node:path";
21326
+ import { existsSync as existsSync4 } from "node:fs";
21327
+ import { dirname as dirname5, join as join10 } from "node:path";
21204
21328
  import { fileURLToPath } from "node:url";
21205
21329
  function bundleDirOf(argv1, moduleFile) {
21206
21330
  const own2 = dirname5(argv1);
21207
- if (existsSync3(join9(own2, SERVER_ENTRY_FILE))) return own2;
21331
+ if (existsSync4(join10(own2, SERVER_ENTRY_FILE))) return own2;
21208
21332
  let dir = dirname5(moduleFile);
21209
21333
  for (; ; ) {
21210
- if (existsSync3(join9(dir, SERVER_ENTRY_FILE))) return dir;
21334
+ if (existsSync4(join10(dir, SERVER_ENTRY_FILE))) return dir;
21211
21335
  const up = dirname5(dir);
21212
21336
  if (up === dir) return own2;
21213
21337
  dir = up;
@@ -21221,17 +21345,17 @@ function ownBundleDir() {
21221
21345
  }
21222
21346
 
21223
21347
  // src/core/ops/doctor-config.ts
21224
- import { existsSync as existsSync8, readdirSync as readdirSync4 } from "node:fs";
21225
- import { join as join13 } from "node:path";
21348
+ import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
21349
+ import { join as join14 } from "node:path";
21226
21350
 
21227
21351
  // src/core/ops/detect-v1.ts
21228
- import { existsSync as existsSync5, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync7 } from "node:fs";
21352
+ import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
21229
21353
  import { tmpdir } from "node:os";
21230
- import { join as join11 } from "node:path";
21354
+ import { join as join12 } from "node:path";
21231
21355
 
21232
21356
  // src/core/ops/host-config.ts
21233
- import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
21234
- import { dirname as dirname6, join as join10 } from "node:path";
21357
+ import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
21358
+ import { dirname as dirname6, join as join11 } from "node:path";
21235
21359
 
21236
21360
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
21237
21361
  var KEYS2 = {
@@ -23348,10 +23472,10 @@ function formatOf(path8) {
23348
23472
  function readHostConfig(agent, path8) {
23349
23473
  let file2 = path8;
23350
23474
  if (agent === "opencode") {
23351
- const jsonc = join10(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
23352
- if (existsSync4(jsonc)) file2 = jsonc;
23475
+ const jsonc = join11(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
23476
+ if (existsSync5(jsonc)) file2 = jsonc;
23353
23477
  }
23354
- const raw = existsSync4(file2) ? readFileSync6(file2, "utf8") : "";
23478
+ const raw = existsSync5(file2) ? readFileSync7(file2, "utf8") : "";
23355
23479
  return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
23356
23480
  }
23357
23481
  function stripJsonComments(text) {
@@ -23696,7 +23820,7 @@ function setText(agent, path8, text, format, key, value) {
23696
23820
  }
23697
23821
  }
23698
23822
  function serverScript() {
23699
- return join10(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
23823
+ return join11(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
23700
23824
  }
23701
23825
  function isNodeCommand(command) {
23702
23826
  if (typeof command !== "string") return false;
@@ -23823,14 +23947,14 @@ function stripJsonc(text) {
23823
23947
  }
23824
23948
  function readJson(file2) {
23825
23949
  try {
23826
- return JSON.parse(stripJsonc(hostText(readFileSync7(file2, "utf8"))));
23950
+ return JSON.parse(stripJsonc(hostText(readFileSync8(file2, "utf8"))));
23827
23951
  } catch {
23828
23952
  return void 0;
23829
23953
  }
23830
23954
  }
23831
23955
  function readText(file2) {
23832
23956
  try {
23833
- return hostText(readFileSync7(file2, "utf8"));
23957
+ return hostText(readFileSync8(file2, "utf8"));
23834
23958
  } catch {
23835
23959
  return "";
23836
23960
  }
@@ -23887,7 +24011,7 @@ function flatCommands(events, prefix) {
23887
24011
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
23888
24012
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
23889
24013
  function dataDir(dir, reason, out) {
23890
- if (existsSync5(dir)) out.push(finding(dir, "", reason));
24014
+ if (existsSync6(dir)) out.push(finding(dir, "", reason));
23891
24015
  }
23892
24016
  function mcpEntry(file2, doc, out) {
23893
24017
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -23895,7 +24019,7 @@ function mcpEntry(file2, doc, out) {
23895
24019
  }
23896
24020
  }
23897
24021
  function claudeShapeSettings(agentHome, out) {
23898
- const file2 = join11(agentHome, SETTINGS_FILE);
24022
+ const file2 = join12(agentHome, SETTINGS_FILE);
23899
24023
  const doc = readJson(file2);
23900
24024
  for (const c of nestedCommands(doc)) {
23901
24025
  if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
@@ -23915,63 +24039,64 @@ function v1HookFile(file2, out) {
23915
24039
  function scanClaudeCode(home, agentHome, out) {
23916
24040
  claudeShapeSettings(agentHome, out);
23917
24041
  for (const ext of V1_CACHE_HEAL_EXTS) {
23918
- const file2 = join11(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
23919
- if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
24042
+ const file2 = join12(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
24043
+ if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
23920
24044
  }
23921
- const userFile = join11(home, CLAUDE_USER_CONFIG_FILE);
24045
+ const userFile = join12(home, CLAUDE_USER_CONFIG_FILE);
23922
24046
  mcpEntry(userFile, readJson(userFile), out);
23923
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24047
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23924
24048
  }
23925
24049
  function scanCodex(agentHome, out) {
23926
- const hooksFile = join11(agentHome, HOOKS_JSON_FILE);
24050
+ const hooksFile = join12(agentHome, HOOKS_JSON_FILE);
23927
24051
  for (const c of nestedCommands(readJson(hooksFile))) {
23928
24052
  if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
23929
24053
  out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
23930
24054
  }
23931
24055
  }
23932
- const tomlFile = join11(agentHome, CONFIG_TOML_FILE);
24056
+ const tomlFile = join12(agentHome, CONFIG_TOML_FILE);
23933
24057
  const config2 = readTomlValue(tomlFile);
23934
24058
  for (const span2 of readTomlTables(tomlFile)) {
23935
24059
  if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
23936
24060
  if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
24061
+ if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
23937
24062
  out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
23938
24063
  }
23939
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24064
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23940
24065
  }
23941
24066
  function scanGemini(agentHome, out) {
23942
- const file2 = join11(agentHome, SETTINGS_FILE);
24067
+ const file2 = join12(agentHome, SETTINGS_FILE);
23943
24068
  for (const c of nestedCommands(readJson(file2))) {
23944
24069
  if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
23945
24070
  }
23946
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
24071
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
23947
24072
  }
23948
24073
  function scanVscode(agentHome, project, out) {
23949
24074
  if (project !== void 0) {
23950
- v1HookFile(join11(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
23951
- const mcpFile2 = join11(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
24075
+ v1HookFile(join12(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
24076
+ const mcpFile2 = join12(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
23952
24077
  const doc = readJson(mcpFile2);
23953
24078
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
23954
24079
  const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
23955
24080
  if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
23956
24081
  out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
23957
24082
  }
23958
- const sessions = join11(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
24083
+ const sessions = join12(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
23959
24084
  dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
23960
24085
  }
23961
- dataDir(join11(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
24086
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
23962
24087
  }
23963
24088
  function jsonFiles(dir) {
23964
24089
  try {
23965
- return readdirSync2(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
24090
+ return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
23966
24091
  } catch {
23967
24092
  return [];
23968
24093
  }
23969
24094
  }
23970
24095
  function scanKiro(agentHome, project, out) {
23971
- const agentsDir = join11(agentHome, KIRO_AGENTS_DIR);
23972
- const defaultFile = join11(agentHome, ...KIRO_AGENT_FILE);
24096
+ const agentsDir = join12(agentHome, KIRO_AGENTS_DIR);
24097
+ const defaultFile = join12(agentHome, ...KIRO_AGENT_FILE);
23973
24098
  for (const name of jsonFiles(agentsDir)) {
23974
- const file2 = join11(agentsDir, name);
24099
+ const file2 = join12(agentsDir, name);
23975
24100
  const doc = readJson(file2);
23976
24101
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
23977
24102
  out.push(finding(file2, "", V1_REASON.kiroAgentFile));
@@ -23982,31 +24107,31 @@ function scanKiro(agentHome, project, out) {
23982
24107
  if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
23983
24108
  }
23984
24109
  }
23985
- const steeringDocs = [join11(agentHome, ...KIRO_STEERING_FILE)];
23986
- if (project !== void 0) steeringDocs.push(join11(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
24110
+ const steeringDocs = [join12(agentHome, ...KIRO_STEERING_FILE)];
24111
+ if (project !== void 0) steeringDocs.push(join12(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
23987
24112
  for (const file2 of steeringDocs) {
23988
- if (existsSync5(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
24113
+ if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
23989
24114
  }
23990
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24115
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
23991
24116
  }
23992
24117
  function piNpmIsCurrent(piAgentDir) {
23993
- const doc = readJson(join11(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
24118
+ const doc = readJson(join12(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
23994
24119
  const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
23995
24120
  return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
23996
24121
  }
23997
24122
  function scanPi(piAgentDir, agentHome, out) {
23998
- const file2 = join11(piAgentDir, SETTINGS_FILE);
24123
+ const file2 = join12(piAgentDir, SETTINGS_FILE);
23999
24124
  const doc = readJson(file2);
24000
24125
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
24001
24126
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
24002
24127
  if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
24003
24128
  if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
24004
24129
  });
24005
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24130
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24006
24131
  }
24007
24132
  function scanOpencode(agentHome, out) {
24008
24133
  for (const name of OPENCODE_CONFIG_FILES) {
24009
- const file2 = join11(agentHome, name);
24134
+ const file2 = join12(agentHome, name);
24010
24135
  const doc = readJson(file2);
24011
24136
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
24012
24137
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
@@ -24017,13 +24142,13 @@ function scanOpencode(agentHome, out) {
24017
24142
  }
24018
24143
  }
24019
24144
  function scanZcode(agentHome, out) {
24020
- const configFile = join11(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
24145
+ const configFile = join12(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
24021
24146
  const config2 = readJson(configFile);
24022
24147
  const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
24023
24148
  for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
24024
24149
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
24025
24150
  }
24026
- const hooksFile = join11(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
24151
+ const hooksFile = join12(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
24027
24152
  for (const c of nestedCommands(readJson(hooksFile))) {
24028
24153
  if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
24029
24154
  }
@@ -24047,14 +24172,14 @@ function firstTmpMatch(dir) {
24047
24172
  }
24048
24173
  }
24049
24174
  function scanAll(home, tmp, out) {
24050
- const root = join11(home, DATA_ROOT.slice(1));
24051
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join11(root, name), V1_REASON.dataRoot, out);
24175
+ const root = join12(home, DATA_ROOT.slice(1));
24176
+ for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join12(root, name), V1_REASON.dataRoot, out);
24052
24177
  if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
24053
24178
  }
24054
24179
  function detectV1(agent, home, scope = {}) {
24055
24180
  const out = [];
24056
24181
  const project = scope.project;
24057
- const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join11(home, ...AGENT_HOME_DIR[agent]);
24182
+ const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join12(home, ...AGENT_HOME_DIR[agent]);
24058
24183
  switch (agent) {
24059
24184
  case "claude-code":
24060
24185
  scanClaudeCode(home, agentHome, out);
@@ -24067,11 +24192,11 @@ function detectV1(agent, home, scope = {}) {
24067
24192
  break;
24068
24193
  case "qwen":
24069
24194
  claudeShapeSettings(agentHome, out);
24070
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24195
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24071
24196
  break;
24072
24197
  case "copilot-cli":
24073
- v1HookFile(join11(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
24074
- dataDir(join11(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24198
+ v1HookFile(join12(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
24199
+ dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
24075
24200
  break;
24076
24201
  case "vscode":
24077
24202
  scanVscode(agentHome, project, out);
@@ -24080,7 +24205,7 @@ function detectV1(agent, home, scope = {}) {
24080
24205
  scanKiro(agentHome, project, out);
24081
24206
  break;
24082
24207
  case "pi":
24083
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join11(agentHome, PI_AGENT_DIR), agentHome, out);
24208
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join12(agentHome, PI_AGENT_DIR), agentHome, out);
24084
24209
  break;
24085
24210
  // D-WIN-PIDIR-1: empty is unset
24086
24211
  case "opencode":
@@ -24095,8 +24220,8 @@ function detectV1(agent, home, scope = {}) {
24095
24220
  }
24096
24221
 
24097
24222
  // src/core/ops/plugin-root.ts
24098
- import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
24099
- import { dirname as dirname7, isAbsolute as isAbsolute2, join as join12, sep as sep4 } from "node:path";
24223
+ import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
24224
+ import { dirname as dirname7, isAbsolute as isAbsolute2, join as join13, sep as sep4 } from "node:path";
24100
24225
  import { fileURLToPath as fileURLToPath2 } from "node:url";
24101
24226
  function missing(agent, path8) {
24102
24227
  return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
@@ -24137,15 +24262,15 @@ var realOrNull = (path8) => {
24137
24262
  };
24138
24263
  var readOrNull = (file2) => {
24139
24264
  try {
24140
- return readFileSync8(file2, "utf8");
24265
+ return readFileSync9(file2, "utf8");
24141
24266
  } catch {
24142
24267
  return null;
24143
24268
  }
24144
24269
  };
24145
24270
  var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
24146
24271
  function enabledPlugins(claudeDir, project) {
24147
- const files = [join12(claudeDir, SETTINGS_FILE)];
24148
- if (project !== void 0) files.push(join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join12(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
24272
+ const files = [join13(claudeDir, SETTINGS_FILE)];
24273
+ if (project !== void 0) files.push(join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
24149
24274
  const out = {};
24150
24275
  for (const file2 of files) {
24151
24276
  const text = readOrNull(file2);
@@ -24161,10 +24286,10 @@ function marketplaceChoice(env, worktree) {
24161
24286
  const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
24162
24287
  const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
24163
24288
  if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
24164
- const record4 = readOrNull(join12(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
24289
+ const record4 = readOrNull(join13(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
24165
24290
  const recorded = record4 === null ? [] : recordedInstalls(record4);
24166
24291
  if (recorded.length === 0) return { record: false };
24167
- const live = recorded.filter((r) => existsSync6(r.installPath));
24292
+ const live = recorded.filter((r) => existsSync7(r.installPath));
24168
24293
  const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
24169
24294
  if (mine !== void 0) return { root: mine.installPath };
24170
24295
  const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
@@ -24184,18 +24309,18 @@ function marketplaceChoice(env, worktree) {
24184
24309
  }
24185
24310
  function marketplaceRoot(adapter, env, worktree) {
24186
24311
  const claudeDir = claudeDirOf(env, requireHomeDir(env));
24187
- const plugins = join12(claudeDir, HOST_PLUGINS_DIR_NAME);
24188
- const cache = join12(plugins, PLUGIN_CACHE_DIR_NAME);
24312
+ const plugins = join13(claudeDir, HOST_PLUGINS_DIR_NAME);
24313
+ const cache = join13(plugins, PLUGIN_CACHE_DIR_NAME);
24189
24314
  const script = process.argv[1];
24190
24315
  const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
24191
24316
  const choice = marketplaceChoice(env, worktree);
24192
24317
  if ("root" in choice) return choice.root;
24193
24318
  if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
24194
24319
  const cacheReal = realOrNull(cache);
24195
- if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync6(join12(ownReal, SERVER_ENTRY_FILE))) return ownReal;
24196
- const pattern = join12(cache, "*", PLUGIN_NAME);
24197
- if (!existsSync6(cache)) throw missing(adapter.id, pattern);
24198
- const found = readdirSync3(cache).sort().map((marketplace) => join12(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync6(dir));
24320
+ if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
24321
+ const pattern = join13(cache, "*", PLUGIN_NAME);
24322
+ if (!existsSync7(cache)) throw missing(adapter.id, pattern);
24323
+ const found = readdirSync4(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
24199
24324
  if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
24200
24325
  return found[0];
24201
24326
  }
@@ -24203,7 +24328,7 @@ function configEntryRoot(adapter, env) {
24203
24328
  const spec = OWN_MCP_ENTRY[adapter.id];
24204
24329
  if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
24205
24330
  const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
24206
- if (!existsSync6(file2)) throw missing(adapter.id, file2);
24331
+ if (!existsSync7(file2)) throw missing(adapter.id, file2);
24207
24332
  const current = readHostConfig(adapter.id, file2);
24208
24333
  const value = parseHostConfig(adapter.id, file2, current.text, current.format);
24209
24334
  const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
@@ -24220,9 +24345,9 @@ function candidate(adapter, env, worktree) {
24220
24345
  case "hooks+mcp":
24221
24346
  return configEntryRoot(adapter, env);
24222
24347
  case "extension":
24223
- return join12(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join12(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
24348
+ return join13(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join13(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
24224
24349
  case "plugin":
24225
- return join12(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
24350
+ return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
24226
24351
  case "in-process":
24227
24352
  return dirname7(fileURLToPath2(import.meta.url));
24228
24353
  }
@@ -24237,7 +24362,7 @@ function resolvePluginRoot(adapter, env, worktree) {
24237
24362
  }
24238
24363
 
24239
24364
  // src/setup/pi-gate.ts
24240
- import { existsSync as existsSync7, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
24365
+ import { existsSync as existsSync8, readFileSync as readFileSync10, realpathSync as realpathSync5 } from "node:fs";
24241
24366
  import path4 from "node:path";
24242
24367
  var EXTENSIONS_KEY = "extensions";
24243
24368
  var PROJECT_DIR = ".pi";
@@ -24245,9 +24370,9 @@ var TRUST_FILE = "trust.json";
24245
24370
  var ALWAYS = "always";
24246
24371
  var SOURCE_PREFIXES = ["npm:", "git:"];
24247
24372
  function load(file2) {
24248
- if (!existsSync7(file2)) return void 0;
24373
+ if (!existsSync8(file2)) return void 0;
24249
24374
  try {
24250
- return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync9(file2, "utf8")), "json") };
24375
+ return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync10(file2, "utf8")), "json") };
24251
24376
  } catch {
24252
24377
  return void 0;
24253
24378
  }
@@ -24382,11 +24507,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
24382
24507
  var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
24383
24508
  function mcpFile(row5, home, env) {
24384
24509
  const spec = OWN_MCP_ENTRY[row5.id];
24385
- if (row5.id === "codex") return join13(codexDirOf(env, home), CONFIG_TOML_FILE);
24510
+ if (row5.id === "codex") return join14(codexDirOf(env, home), CONFIG_TOML_FILE);
24386
24511
  if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
24387
- if (row5.id === "opencode") return join13(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
24512
+ if (row5.id === "opencode") return join14(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
24388
24513
  if (row5.id === "pi") {
24389
- return join13(piAgentDirOf(env, home), SETTINGS_FILE);
24514
+ return join14(piAgentDirOf(env, home), SETTINGS_FILE);
24390
24515
  }
24391
24516
  return null;
24392
24517
  }
@@ -24399,27 +24524,27 @@ function codexNativeDir(env, home) {
24399
24524
  const codexDir = codexDirOf(env, home);
24400
24525
  let enabled;
24401
24526
  try {
24402
- enabled = hostConfigValueAt(readParsed("codex", join13(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
24527
+ enabled = hostConfigValueAt(readParsed("codex", join14(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
24403
24528
  } catch {
24404
24529
  return null;
24405
24530
  }
24406
24531
  if (enabled !== true) return null;
24407
- const cache = join13(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24408
- if (!existsSync8(cache)) return null;
24532
+ const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
24533
+ if (!existsSync9(cache)) return null;
24409
24534
  const found = [];
24410
- for (const market of readdirSync4(cache)) {
24411
- const plugin = join13(cache, market, SERVER_KEY);
24412
- if (!existsSync8(plugin)) continue;
24413
- for (const version2 of readdirSync4(plugin).sort()) {
24414
- const dir = join13(plugin, version2, CODEX_PLUGIN_SUBDIR);
24415
- if (existsSync8(join13(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24535
+ for (const market of readdirSync5(cache)) {
24536
+ const plugin = join14(cache, market, SERVER_KEY);
24537
+ if (!existsSync9(plugin)) continue;
24538
+ for (const version2 of readdirSync5(plugin).sort()) {
24539
+ const dir = join14(plugin, version2, CODEX_PLUGIN_SUBDIR);
24540
+ if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
24416
24541
  }
24417
24542
  }
24418
24543
  return found.length === 0 ? null : found[found.length - 1];
24419
24544
  }
24420
24545
  function nativeMcpWrong(dir, row5) {
24421
24546
  try {
24422
- const entry = hostConfigValueAt(readParsed(row5.id, join13(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
24547
+ const entry = hostConfigValueAt(readParsed(row5.id, join14(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
24423
24548
  if (!isObject4(entry)) return true;
24424
24549
  const args = list2(entry[MCP_ARGS_FIELD]);
24425
24550
  const script = args[0];
@@ -24443,7 +24568,7 @@ function opencodeMcpOwn(entry) {
24443
24568
  function opencodeListed(file2) {
24444
24569
  const { value } = readParsed("opencode", file2);
24445
24570
  const bundle = opencodePluginFile();
24446
- const own2 = [bundle, join13(bundle, ...OPENCODE_PLUGIN_PATH)];
24571
+ const own2 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
24447
24572
  if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
24448
24573
  const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
24449
24574
  return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
@@ -24467,7 +24592,7 @@ function mcpWrong(row5, home, env, worktree) {
24467
24592
  function hookFile(row5, spec, home, env, worktree) {
24468
24593
  const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
24469
24594
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
24470
- const file2 = native !== null ? join13(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join13(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join13(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join13(kiroDirOf(env, home), ...spec.file.slice(1)) : join13(root, ...spec.file);
24595
+ 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);
24471
24596
  return file2;
24472
24597
  }
24473
24598
  function hookParts(row5, home, env, worktree) {
@@ -24478,7 +24603,7 @@ function hookParts(row5, home, env, worktree) {
24478
24603
  const file2 = hookFile(row5, spec, home, env, worktree);
24479
24604
  block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
24480
24605
  if (row5.id === "codex") {
24481
- const config2 = readParsed(row5.id, join13(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
24606
+ const config2 = readParsed(row5.id, join14(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
24482
24607
  if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
24483
24608
  }
24484
24609
  } catch {
@@ -24522,7 +24647,7 @@ function checkHostConfig(row5, env, worktree) {
24522
24647
  function checkPiInstall(env, home, worktree) {
24523
24648
  const found = piInstalledIn(env, home, ownBundleDir(), worktree);
24524
24649
  if (found !== void 0) return { ...pass("D3"), detail: found };
24525
- return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join13(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
24650
+ return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join14(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
24526
24651
  }
24527
24652
  function checkV1Leftovers(agent, home, scope = {}) {
24528
24653
  const findings = detectV1(agent, home, scope);
@@ -24541,10 +24666,10 @@ function parsedOrNull(agent, file2, jsonc) {
24541
24666
  }
24542
24667
  function checkDoubleFire(agent, worktree) {
24543
24668
  if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
24544
- const claude = parsedOrNull(agent, join13(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
24669
+ const claude = parsedOrNull(agent, join14(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
24545
24670
  const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
24546
24671
  const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
24547
- const vscode = parsedOrNull(agent, join13(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
24672
+ const vscode = parsedOrNull(agent, join14(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
24548
24673
  const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
24549
24674
  return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
24550
24675
  }
@@ -24555,7 +24680,7 @@ function configPaths(row5, env, worktree) {
24555
24680
  const mcp = mcpFile(row5, home, env);
24556
24681
  if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
24557
24682
  const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
24558
- if (native !== null) out.push({ label: "Codex plugin MCP", path: join13(native, CODEX_PLUGIN_MCP_FILE) });
24683
+ if (native !== null) out.push({ label: "Codex plugin MCP", path: join14(native, CODEX_PLUGIN_MCP_FILE) });
24559
24684
  const spec = HOOK_HOST_FILE[row5.id];
24560
24685
  if (spec !== null) {
24561
24686
  try {
@@ -24575,7 +24700,7 @@ function configPaths(row5, env, worktree) {
24575
24700
  }
24576
24701
 
24577
24702
  // src/core/ops/doctor-db.ts
24578
- import { existsSync as existsSync9, statSync as statSync5 } from "node:fs";
24703
+ import { existsSync as existsSync10, statSync as statSync5 } from "node:fs";
24579
24704
  var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
24580
24705
  var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
24581
24706
  var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
@@ -24617,15 +24742,15 @@ function orphanFiles(dbPath) {
24617
24742
  const files = [];
24618
24743
  for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
24619
24744
  const path8 = dbPath + suffix;
24620
- if (existsSync9(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
24745
+ if (existsSync10(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
24621
24746
  }
24622
- return files.length > 0 && !existsSync9(dbPath) ? files : [];
24747
+ return files.length > 0 && !existsSync10(dbPath) ? files : [];
24623
24748
  }
24624
24749
  async function checkDb(project) {
24625
24750
  const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
24626
24751
  const orphan = orphanFiles(project.dbPath);
24627
24752
  if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
24628
- if (!existsSync9(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24753
+ if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
24629
24754
  const sqlite = await loadSqlite2();
24630
24755
  if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
24631
24756
  let raw = null;
@@ -24651,7 +24776,7 @@ async function checkDb(project) {
24651
24776
  }
24652
24777
  }
24653
24778
  async function checkIndex(project) {
24654
- if (!existsSync9(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24779
+ if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
24655
24780
  const sqlite = await loadSqlite2();
24656
24781
  if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
24657
24782
  let raw = null;
@@ -24668,8 +24793,8 @@ async function checkIndex(project) {
24668
24793
  }
24669
24794
 
24670
24795
  // src/core/ops/doctor-env.ts
24671
- import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
24672
- import { isAbsolute as isAbsolute3, join as join14, relative as relative4 } from "node:path";
24796
+ import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync6 } from "node:fs";
24797
+ import { isAbsolute as isAbsolute3, join as join15, relative as relative4 } from "node:path";
24673
24798
  function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
24674
24799
  return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
24675
24800
  }
@@ -24681,7 +24806,7 @@ function fail4(id2, detail, fixCommand) {
24681
24806
  }
24682
24807
  function bundleVersion(bundleDir2) {
24683
24808
  try {
24684
- const v = JSON.parse(readFileSync10(join14(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24809
+ const v = JSON.parse(readFileSync11(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
24685
24810
  return typeof v === "string" && v !== "" ? v : void 0;
24686
24811
  } catch {
24687
24812
  return void 0;
@@ -24831,7 +24956,7 @@ function checkMcp(ctx) {
24831
24956
  return named2 || versioned ? pass3("D6") : unknown3("D6", D6_UNKNOWN_DETAIL);
24832
24957
  }
24833
24958
  function piCwdInside(worktree, piCwd) {
24834
- if (piCwd === void 0 || !existsSync10(piCwd)) return false;
24959
+ if (piCwd === void 0 || !existsSync11(piCwd)) return false;
24835
24960
  const rel = relative4(worktree, realpathSync6.native(piCwd));
24836
24961
  return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
24837
24962
  }
@@ -24841,7 +24966,9 @@ function checkProject(i) {
24841
24966
  if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
24842
24967
  return pass3("D7");
24843
24968
  }
24844
- function checkMode(adapter) {
24969
+ function checkMode(adapter, hostPermission) {
24970
+ if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
24971
+ if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
24845
24972
  return pass3("D10", D10_DETAIL(adapter.denyChannel));
24846
24973
  }
24847
24974
  function checkShell(env) {
@@ -24852,7 +24979,7 @@ function checkShell(env) {
24852
24979
  }
24853
24980
 
24854
24981
  // src/core/ops/doctor-hook.ts
24855
- import { existsSync as existsSync12, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24982
+ import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync12, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
24856
24983
  import { tmpdir as tmpdir2 } from "node:os";
24857
24984
  import path7 from "node:path";
24858
24985
 
@@ -26678,7 +26805,7 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
26678
26805
 
26679
26806
  // src/setup/codex-trust.ts
26680
26807
  import { createHash } from "node:crypto";
26681
- import { existsSync as existsSync11, realpathSync as realpathSync7 } from "node:fs";
26808
+ import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
26682
26809
  import path6 from "node:path";
26683
26810
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
26684
26811
 
@@ -26795,14 +26922,14 @@ function pluginHooksFromReply(m, pluginId) {
26795
26922
  function askPluginHooks(env, pluginId, cwd) {
26796
26923
  const bin = whichBin("codex", env);
26797
26924
  if (!bin) return Promise.resolve({ kind: "absent" });
26798
- return new Promise((resolve10) => {
26925
+ return new Promise((resolve11) => {
26799
26926
  let asked;
26800
26927
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
26801
26928
  let f;
26802
26929
  try {
26803
26930
  f = spawnForm(bin, ["app-server"], env);
26804
26931
  } catch {
26805
- resolve10({ kind: "silent" });
26932
+ resolve11({ kind: "silent" });
26806
26933
  return;
26807
26934
  }
26808
26935
  const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
@@ -26812,7 +26939,7 @@ function askPluginHooks(env, pluginId, cwd) {
26812
26939
  let result;
26813
26940
  const settle = () => {
26814
26941
  clearTimeout(grace);
26815
- resolve10(done_(result));
26942
+ resolve11(done_(result));
26816
26943
  };
26817
26944
  let grace;
26818
26945
  const finish2 = (v) => {
@@ -26901,10 +27028,10 @@ function isObject6(v) {
26901
27028
  }
26902
27029
  function loadFixture(bundleDir2, agent) {
26903
27030
  const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
26904
- if (!existsSync12(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
27031
+ if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
26905
27032
  let all;
26906
27033
  try {
26907
- all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
27034
+ all = JSON.parse(hostText(readFileSync12(file2, "utf8")));
26908
27035
  } catch (err) {
26909
27036
  return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
26910
27037
  }
@@ -27017,6 +27144,35 @@ async function mediaProbe(i, timeoutMs) {
27017
27144
  rmSync2(home, { recursive: true, force: true });
27018
27145
  }
27019
27146
  }
27147
+ async function ownProbe(i, timeoutMs) {
27148
+ const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
27149
+ try {
27150
+ const cfg = path7.join(home, ".claude");
27151
+ const refs = path7.join(cfg, "skills", "d5-probe", "references");
27152
+ mkdirSync4(refs, { recursive: true });
27153
+ const filePath = path7.join(refs, "d5-own-probe.md");
27154
+ writeFileSync2(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
27155
+ const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
27156
+ const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
27157
+ cwd: i.bundleDir,
27158
+ env: node.env,
27159
+ signal: i.signal,
27160
+ timeoutMs,
27161
+ stdin: JSON.stringify({
27162
+ session_id: "d5-own-probe",
27163
+ transcript_path: "",
27164
+ cwd: home,
27165
+ hook_event_name: "PreToolUse",
27166
+ tool_name: "Read",
27167
+ tool_use_id: "toolu_d5_own_probe",
27168
+ tool_input: { file_path: filePath }
27169
+ })
27170
+ });
27171
+ return r.stdout.toString("utf8");
27172
+ } finally {
27173
+ rmSync2(home, { recursive: true, force: true });
27174
+ }
27175
+ }
27020
27176
  function isDeny(stdout) {
27021
27177
  if (stdout.trim() === "") return false;
27022
27178
  let out;
@@ -27031,8 +27187,12 @@ async function readProbeDetail(i, timeoutMs) {
27031
27187
  if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
27032
27188
  if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
27033
27189
  if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
27190
+ if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
27034
27191
  return null;
27035
27192
  }
27193
+ async function mediaProbeDetail(i, timeoutMs) {
27194
+ return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
27195
+ }
27036
27196
  function codexHookJournaled(db) {
27037
27197
  if (db === null) return false;
27038
27198
  return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
@@ -27085,7 +27245,7 @@ async function codexStopDetail(i, timeoutMs) {
27085
27245
  timeoutMs,
27086
27246
  stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
27087
27247
  });
27088
- const logged = existsSync12(path7.join(home, HOOK_ERROR_LOG_FILE));
27248
+ const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
27089
27249
  return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
27090
27250
  } finally {
27091
27251
  rmSync2(home, { recursive: true, force: true });
@@ -27096,7 +27256,7 @@ async function checkHookRoundTrip(i) {
27096
27256
  const trust = await codexPluginTrust(i);
27097
27257
  if (trust !== null) return trust;
27098
27258
  }
27099
- if (i.agent === "codex" && existsSync12(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
27259
+ if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
27100
27260
  return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
27101
27261
  }
27102
27262
  const fixture = loadFixture(i.bundleDir, i.agent);
@@ -27132,20 +27292,20 @@ async function checkHookRoundTrip(i) {
27132
27292
  if (n >= minPairs && ms <= HOOK_P95_MS) break;
27133
27293
  }
27134
27294
  if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
27135
- const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
27295
+ const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "zcode" ? await mediaProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
27136
27296
  if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
27137
27297
  return row("PASS", DOCTOR_PASS_DETAIL);
27138
27298
  }
27139
27299
 
27140
27300
  // src/core/ops/db-heal.ts
27141
- import { existsSync as existsSync13, mkdirSync as mkdirSync5, rmSync as rmSync4 } from "node:fs";
27142
- import { basename as basename4, dirname as dirname8, join as join16 } from "node:path";
27301
+ import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
27302
+ import { basename as basename4, dirname as dirname8, join as join17 } from "node:path";
27143
27303
 
27144
27304
  // src/core/store/owners.ts
27145
- import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync12, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
27146
- import { basename as basename3, join as join15 } from "node:path";
27305
+ import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync13, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
27306
+ import { basename as basename3, join as join16 } from "node:path";
27147
27307
  function ownersDir(configDir, projectKey) {
27148
- return join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
27308
+ return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
27149
27309
  }
27150
27310
  function errCode2(err) {
27151
27311
  return err.code;
@@ -27165,7 +27325,7 @@ function listLiveOwners(configDir, projectKey) {
27165
27325
  const dir = ownersDir(configDir, projectKey);
27166
27326
  let names;
27167
27327
  try {
27168
- names = readdirSync5(dir);
27328
+ names = readdirSync6(dir);
27169
27329
  } catch (err) {
27170
27330
  if (errCode2(err) === "ENOENT") return [];
27171
27331
  throw err;
@@ -27173,10 +27333,10 @@ function listLiveOwners(configDir, projectKey) {
27173
27333
  const live = [];
27174
27334
  for (const name of names) {
27175
27335
  if (!name.endsWith(OWNER_PID_EXT)) continue;
27176
- const file2 = join15(dir, name);
27336
+ const file2 = join16(dir, name);
27177
27337
  let text;
27178
27338
  try {
27179
- text = readFileSync12(file2, "utf8");
27339
+ text = readFileSync13(file2, "utf8");
27180
27340
  } catch (err) {
27181
27341
  if (errCode2(err) === "ENOENT") continue;
27182
27342
  throw err;
@@ -27222,7 +27382,7 @@ function renameAside(dbPath) {
27222
27382
  const ts = String(Date.now());
27223
27383
  for (const suffix of DB_SIBLING_SUFFIXES) {
27224
27384
  const file2 = dbPath + suffix;
27225
- if (existsSync13(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
27385
+ if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
27226
27386
  }
27227
27387
  return ts;
27228
27388
  }
@@ -27245,11 +27405,11 @@ function utcStamp(now) {
27245
27405
  return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
27246
27406
  }
27247
27407
  function makeOrphanDir(projectDir) {
27248
- const base = join16(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
27408
+ const base = join17(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
27249
27409
  for (let n = 1; ; n += 1) {
27250
27410
  const dir = n === 1 ? base : base + "-" + String(n);
27251
27411
  try {
27252
- mkdirSync5(dir);
27412
+ mkdirSync6(dir);
27253
27413
  return dir;
27254
27414
  } catch (err) {
27255
27415
  if (err.code !== "EEXIST") throw err;
@@ -27262,7 +27422,7 @@ async function healOrphan(project, files, row5) {
27262
27422
  try {
27263
27423
  dir = makeOrphanDir(dirname8(project.dbPath));
27264
27424
  for (const f of files) {
27265
- const to = join16(dir, basename4(f.path));
27425
+ const to = join17(dir, basename4(f.path));
27266
27426
  renameWithRetry(f.path, to);
27267
27427
  moved.push({ path: to, bytes: f.bytes });
27268
27428
  }
@@ -27329,8 +27489,8 @@ function buildReportHead(input) {
27329
27489
 
27330
27490
  // src/core/ops/doctor-issue.ts
27331
27491
  import { spawnSync as spawnSync3 } from "node:child_process";
27332
- import { closeSync as closeSync2, existsSync as existsSync14, fstatSync, mkdirSync as mkdirSync6, openSync as openSync2, readFileSync as readFileSync13, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
27333
- import { delimiter, join as join17 } from "node:path";
27492
+ import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync14, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
27493
+ import { delimiter, join as join18 } from "node:path";
27334
27494
  var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
27335
27495
  function tildeOf(env) {
27336
27496
  const home = homeDirOf(env);
@@ -27342,8 +27502,8 @@ function tildeOf(env) {
27342
27502
  } catch {
27343
27503
  }
27344
27504
  homes.sort((a, b) => b.length - a.length);
27345
- const slash = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
27346
- return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash(piece)).join("~"), t);
27505
+ const slash2 = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
27506
+ return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash2(piece)).join("~"), t);
27347
27507
  }
27348
27508
  function maskLine(line) {
27349
27509
  const lower = line.toLowerCase();
@@ -27371,8 +27531,8 @@ function onPath(env, tool) {
27371
27531
  const out = [];
27372
27532
  for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
27373
27533
  if (dir === "") continue;
27374
- for (const n of names) if (existsSync14(join17(dir, n))) {
27375
- out.push(join17(dir, n));
27534
+ for (const n of names) if (existsSync15(join18(dir, n))) {
27535
+ out.push(join18(dir, n));
27376
27536
  break;
27377
27537
  }
27378
27538
  }
@@ -27380,7 +27540,7 @@ function onPath(env, tool) {
27380
27540
  }
27381
27541
  function hookLogTail(env) {
27382
27542
  const file2 = hookLogPath(env);
27383
- if (file2 === "" || !existsSync14(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
27543
+ if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
27384
27544
  try {
27385
27545
  const fd = openSync2(file2, "r");
27386
27546
  try {
@@ -27400,7 +27560,7 @@ function hookLogTail(env) {
27400
27560
  }
27401
27561
  async function journalRows(ctx) {
27402
27562
  const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
27403
- if (!existsSync14(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
27563
+ if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
27404
27564
  try {
27405
27565
  const db = await openDb(ctx.project, { readOnly: true });
27406
27566
  try {
@@ -27418,21 +27578,21 @@ function agentConfig(adapter, env, worktree) {
27418
27578
  const home = homeDirOf(env);
27419
27579
  const files = configPaths(adapter, env, worktree);
27420
27580
  if (home !== null) {
27421
- if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join17(claudeDirOf(env, home), SETTINGS_FILE) });
27422
- if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join17(codexDirOf(env, home), CONFIG_TOML_FILE) });
27581
+ if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join18(claudeDirOf(env, home), SETTINGS_FILE) });
27582
+ if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join18(codexDirOf(env, home), CONFIG_TOML_FILE) });
27423
27583
  }
27424
27584
  const out = [];
27425
27585
  const seen = /* @__PURE__ */ new Set();
27426
27586
  for (const f of files) {
27427
27587
  if (seen.has(f.path)) continue;
27428
27588
  seen.add(f.path);
27429
- if (!existsSync14(f.path)) {
27589
+ if (!existsSync15(f.path)) {
27430
27590
  out.push(`${f.label}: ${f.path} (absent)`);
27431
27591
  continue;
27432
27592
  }
27433
27593
  let text = "";
27434
27594
  try {
27435
- text = readFileSync13(f.path, "utf8");
27595
+ text = readFileSync14(f.path, "utf8");
27436
27596
  } catch (err) {
27437
27597
  out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
27438
27598
  continue;
@@ -27502,9 +27662,9 @@ async function buildIssueBody(i) {
27502
27662
  async function writeIssueReport(i) {
27503
27663
  const tilde = tildeOf(i.env);
27504
27664
  const body = await buildIssueBody(i);
27505
- const dir = join17(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
27506
- mkdirSync6(dir, { recursive: true });
27507
- const file2 = join17(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
27665
+ const dir = join18(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
27666
+ mkdirSync7(dir, { recursive: true });
27667
+ const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
27508
27668
  writeFileSync4(file2, body);
27509
27669
  const shown2 = tilde(file2);
27510
27670
  const title = issueTitle(i.adapter.id, i.rows);
@@ -27531,7 +27691,7 @@ async function guard(id2, run) {
27531
27691
  }
27532
27692
  }
27533
27693
  async function codexDb(ctx, adapter) {
27534
- if (adapter.id !== "codex" || !existsSync15(ctx.project.dbPath)) return null;
27694
+ if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
27535
27695
  try {
27536
27696
  return await openDb(ctx.project, { readOnly: true });
27537
27697
  } catch {
@@ -27561,11 +27721,11 @@ async function hookRow(ctx, adapter, host) {
27561
27721
  }
27562
27722
  }
27563
27723
  function ownServerId(configDir, projectKey) {
27564
- const dir = join18(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
27565
- if (!existsSync15(dir)) return "";
27566
- for (const name of readdirSync6(dir)) {
27724
+ const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
27725
+ if (!existsSync16(dir)) return "";
27726
+ for (const name of readdirSync7(dir)) {
27567
27727
  if (!name.endsWith(OWNER_PID_EXT)) continue;
27568
- if (readFileSync14(join18(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
27728
+ if (readFileSync15(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
27569
27729
  }
27570
27730
  return "";
27571
27731
  }
@@ -27591,7 +27751,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
27591
27751
  return r.row;
27592
27752
  },
27593
27753
  D9: () => checkIndex(project),
27594
- D10: () => checkMode(adapter),
27754
+ D10: () => checkMode(adapter, ctx.hostPermission),
27755
+ // D-1331-OC-PERM-1
27595
27756
  D11: () => checkShell(env)
27596
27757
  };
27597
27758
  const rows = [];
@@ -27660,9 +27821,9 @@ var ctxDoctor = Object.freeze({
27660
27821
  });
27661
27822
 
27662
27823
  // src/core/tools/execute.ts
27663
- import { existsSync as existsSync16, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
27824
+ import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
27664
27825
  import { tmpdir as tmpdir3 } from "node:os";
27665
- import { dirname as dirname10, join as join19, parse as parse3, resolve as resolve8 } from "node:path";
27826
+ import { dirname as dirname10, join as join20, parse as parse3, resolve as resolve8 } from "node:path";
27666
27827
 
27667
27828
  // src/core/sandbox/win-build.ts
27668
27829
  var SEPARATORS2 = ";&|(\n";
@@ -27745,7 +27906,7 @@ function schemaLine(issue2) {
27745
27906
  }
27746
27907
  function fileError(given, abs, root) {
27747
27908
  let dir = abs;
27748
- while (!existsSync16(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
27909
+ while (!existsSync17(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
27749
27910
  if (isInside(root, dir)) return null;
27750
27911
  return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
27751
27912
  }
@@ -27826,8 +27987,8 @@ async function handler3(raw, ctx) {
27826
27987
  if (takesDashC(input.language, runtime)) {
27827
27988
  argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
27828
27989
  } else {
27829
- tmpDir = mkdtempSync2(join19(tmpdir3(), TMP_PREFIX));
27830
- const file2 = join19(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
27990
+ tmpDir = mkdtempSync2(join20(tmpdir3(), TMP_PREFIX));
27991
+ const file2 = join20(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
27831
27992
  writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
27832
27993
  argv = scriptArgv(input.language, runtime, file2);
27833
27994
  }
@@ -27863,12 +28024,12 @@ var ctxExecute = {
27863
28024
  };
27864
28025
 
27865
28026
  // src/core/tools/index.ts
27866
- import { existsSync as existsSync17, readFileSync as readFileSync16, statSync as statSync8 } from "node:fs";
27867
- import { dirname as dirname11, extname as extname2, join as join21, relative as relative5, resolve as resolve9 } from "node:path";
28027
+ import { existsSync as existsSync18, readFileSync as readFileSync17, statSync as statSync8 } from "node:fs";
28028
+ import { dirname as dirname11, extname as extname3, join as join22, relative as relative5, resolve as resolve9 } from "node:path";
27868
28029
 
27869
28030
  // src/core/index/walk.ts
27870
- import { readdirSync as readdirSync7, readFileSync as readFileSync15, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
27871
- import { join as join20 } from "node:path";
28031
+ import { readdirSync as readdirSync8, readFileSync as readFileSync16, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
28032
+ import { join as join21 } from "node:path";
27872
28033
  var GITIGNORE = ".gitignore";
27873
28034
  var GIT_DIR = ".git";
27874
28035
  function walkDir(root, containmentRoot) {
@@ -27877,19 +28038,19 @@ function walkDir(root, containmentRoot) {
27877
28038
  const found = [];
27878
28039
  visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
27879
28040
  found.sort(compareFound);
27880
- return found.map((f) => ({ absPath: f.absPath, relPath: join20(...f.dir, f.name) }));
28041
+ return found.map((f) => ({ absPath: f.absPath, relPath: join21(...f.dir, f.name) }));
27881
28042
  }
27882
28043
  function visit(abs, rel, parent, contain, seen, found) {
27883
28044
  let entries;
27884
28045
  try {
27885
- entries = readdirSync7(abs, { withFileTypes: true });
28046
+ entries = readdirSync8(abs, { withFileTypes: true });
27886
28047
  } catch {
27887
28048
  return;
27888
28049
  }
27889
- const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join20(abs, GITIGNORE), rel)) : parent;
28050
+ const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join21(abs, GITIGNORE), rel)) : parent;
27890
28051
  for (const e of entries) {
27891
28052
  if (e.name === GIT_DIR) continue;
27892
- const path8 = join20(abs, e.name);
28053
+ const path8 = join21(abs, e.name);
27893
28054
  let isDir = e.isDirectory();
27894
28055
  let isFile = e.isFile();
27895
28056
  let target = path8;
@@ -27929,7 +28090,7 @@ function compareFound(a, b) {
27929
28090
  function readRules(file2, base) {
27930
28091
  let body;
27931
28092
  try {
27932
- body = readFileSync15(file2, "utf8");
28093
+ body = readFileSync16(file2, "utf8");
27933
28094
  } catch {
27934
28095
  return [];
27935
28096
  }
@@ -28151,18 +28312,18 @@ function request(u, conn, proxy, signal) {
28151
28312
  const host = bare(u.hostname);
28152
28313
  const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
28153
28314
  const path8 = u.pathname + u.search;
28154
- return new Promise((resolve10, reject) => {
28315
+ return new Promise((resolve11, reject) => {
28155
28316
  const onErr = (err) => reject(fail6(causeCode(err)));
28156
28317
  if (proxy === void 0) {
28157
28318
  const mod = u.protocol === "https:" ? https : http;
28158
28319
  const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
28159
- req.on("response", resolve10).on("error", onErr).end();
28320
+ req.on("response", resolve11).on("error", onErr).end();
28160
28321
  return;
28161
28322
  }
28162
28323
  const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
28163
28324
  if (u.protocol === "http:") {
28164
28325
  const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
28165
- req.on("response", resolve10).on("error", onErr).end();
28326
+ req.on("response", resolve11).on("error", onErr).end();
28166
28327
  return;
28167
28328
  }
28168
28329
  const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
@@ -28182,16 +28343,16 @@ function request(u, conn, proxy, signal) {
28182
28343
  headers: { host: u.host },
28183
28344
  createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
28184
28345
  });
28185
- req.on("response", resolve10).on("error", onErr).end();
28346
+ req.on("response", resolve11).on("error", onErr).end();
28186
28347
  });
28187
28348
  tunnel.end();
28188
28349
  });
28189
28350
  }
28190
28351
  function readBody(res) {
28191
- return new Promise((resolve10, reject) => {
28352
+ return new Promise((resolve11, reject) => {
28192
28353
  const parts = [];
28193
28354
  res.on("data", (b) => parts.push(b));
28194
- res.on("end", () => resolve10(Buffer.concat(parts)));
28355
+ res.on("end", () => resolve11(Buffer.concat(parts)));
28195
28356
  res.on("error", (err) => reject(fail6(causeCode(err))));
28196
28357
  res.on("aborted", () => reject(fail6("ECONNRESET")));
28197
28358
  });
@@ -32048,7 +32209,7 @@ function userLabel(label2) {
32048
32209
  return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
32049
32210
  }
32050
32211
  function kindOfPath(p) {
32051
- return EXT_KIND[extname2(p).toLowerCase()] ?? "text";
32212
+ return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
32052
32213
  }
32053
32214
  function kindOfType(contentType) {
32054
32215
  const semi = contentType.indexOf(";");
@@ -32057,14 +32218,14 @@ function kindOfType(contentType) {
32057
32218
  }
32058
32219
  function readUtf8(absPath) {
32059
32220
  try {
32060
- return utf8.decode(readFileSync16(absPath));
32221
+ return utf8.decode(readFileSync17(absPath));
32061
32222
  } catch {
32062
32223
  return void 0;
32063
32224
  }
32064
32225
  }
32065
32226
  function missingOrOutside(given, abs, root) {
32066
32227
  let dir = abs;
32067
- while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
32228
+ while (!existsSync18(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
32068
32229
  if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
32069
32230
  return new CtxError("OUTSIDE_ROOT", { p: given, root });
32070
32231
  }
@@ -32075,7 +32236,7 @@ function pathItems(input, project) {
32075
32236
  if (statSync8(abs).isDirectory()) {
32076
32237
  return walkDir(abs, project.containmentRoot).map((f) => ({
32077
32238
  sourceKind: "path",
32078
- label: pathLabel(join21(base, f.relPath)),
32239
+ label: pathLabel(join22(base, f.relPath)),
32079
32240
  kind: kindOfPath(f.relPath),
32080
32241
  read: () => readUtf8(f.absPath)
32081
32242
  }));
@@ -32254,9 +32415,8 @@ async function handler6(input, ctx) {
32254
32415
  const newest = rows.at(-1);
32255
32416
  if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
32256
32417
  const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
32257
- const goal = readFirstPrompt(db, sessionId);
32258
32418
  const last2 = readLastPrompt(db, sessionId);
32259
- const units = queryUnits(db, sessionId, recallQueryText(last2, goal), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
32419
+ const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
32260
32420
  const block = renderState(rows, newest.turn, { sources, units });
32261
32421
  if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
32262
32422
  return reply3(block, false);
@@ -32615,8 +32775,8 @@ var ctxStats = Object.freeze({
32615
32775
  });
32616
32776
 
32617
32777
  // src/core/ops/host-write.ts
32618
- import { copyFileSync, existsSync as existsSync18, mkdirSync as mkdirSync7, writeFileSync as writeFileSync6 } from "node:fs";
32619
- import { dirname as dirname12, join as join22 } from "node:path";
32778
+ import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
32779
+ import { dirname as dirname12, join as join23 } from "node:path";
32620
32780
  function defaultWrite(file2, text) {
32621
32781
  writeFileSync6(file2, text, "utf8");
32622
32782
  }
@@ -32625,17 +32785,17 @@ function hostConfigPath(agent, home, env) {
32625
32785
  if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
32626
32786
  switch (agent) {
32627
32787
  case "opencode":
32628
- return join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
32788
+ return join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
32629
32789
  // D-WIN-OPENCODE-DIR-1
32630
32790
  case "pi":
32631
- return join22(piAgentDirOf(env, home), SETTINGS_FILE);
32791
+ return join23(piAgentDirOf(env, home), SETTINGS_FILE);
32632
32792
  case "gemini":
32633
- return join22(geminiDirOf(env, home), SETTINGS_FILE);
32793
+ return join23(geminiDirOf(env, home), SETTINGS_FILE);
32634
32794
  // D-R38-GEMINI-HOME-1
32635
32795
  case "copilot-cli":
32636
32796
  return null;
32637
32797
  default:
32638
- return join22(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
32798
+ return join23(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
32639
32799
  }
32640
32800
  }
32641
32801
  function cell3(value) {
@@ -32647,8 +32807,8 @@ function toRow(file2, edit) {
32647
32807
  function writeWithRollback(file2, text, write2, atomic) {
32648
32808
  const trash = file2 + UPGRADE_TRASH_SUFFIX;
32649
32809
  const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
32650
- const had = existsSync18(file2);
32651
- mkdirSync7(dirname12(file2), { recursive: true });
32810
+ const had = existsSync19(file2);
32811
+ mkdirSync8(dirname12(file2), { recursive: true });
32652
32812
  if (had) copyFileSync(file2, trash);
32653
32813
  try {
32654
32814
  write2(tmp, text);
@@ -32677,7 +32837,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
32677
32837
  if (requested === null) return [];
32678
32838
  const current = readHostConfig(row5.id, requested);
32679
32839
  const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
32680
- const exists = existsSync18(current.path);
32840
+ const exists = existsSync19(current.path);
32681
32841
  if (exists && result.text === current.text) return [];
32682
32842
  const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
32683
32843
  writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
@@ -32685,15 +32845,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
32685
32845
  }
32686
32846
 
32687
32847
  // src/core/ops/uninstall.ts
32688
- import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
32689
- import { join as join23 } from "node:path";
32848
+ import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
32849
+ import { join as join24 } from "node:path";
32690
32850
  function row2(area, before, after) {
32691
32851
  return { area, before, after };
32692
32852
  }
32693
32853
  function stopServers(configDir, projectKey) {
32694
32854
  const stopped = listLiveOwners(configDir, projectKey);
32695
- const dir = join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
32696
- for (const serverId of stopped) writeFileSync7(join23(dir, serverId + OWNER_STOP_EXT), "", "utf8");
32855
+ const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
32856
+ for (const serverId of stopped) writeFileSync7(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
32697
32857
  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 };
32698
32858
  }
32699
32859
  function rootOrNull(adapter, env) {
@@ -32711,15 +32871,15 @@ function removeCache(adapter, env, configDir) {
32711
32871
  const root = rootOrNull(adapter, env);
32712
32872
  if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
32713
32873
  if (adapter.installMode === "marketplace") {
32714
- const cache = join23(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
32874
+ const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
32715
32875
  if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
32716
32876
  }
32717
32877
  rmSync6(root, { recursive: true, force: true });
32718
32878
  return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
32719
32879
  }
32720
32880
  case "plugin": {
32721
- const agentDir = join23(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
32722
- if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
32881
+ const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
32882
+ if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
32723
32883
  rmSync6(agentDir, { recursive: true, force: true });
32724
32884
  return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
32725
32885
  }
@@ -32764,7 +32924,7 @@ function ownEntries2(agent, env) {
32764
32924
  }
32765
32925
  if (agent === "opencode") {
32766
32926
  return [{
32767
- file: join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
32927
+ file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
32768
32928
  // D-WIN-OPENCODE-DIR-1
32769
32929
  key: OPENCODE_PLUGIN_KEY,
32770
32930
  shown: OPENCODE_PLUGIN_KEY,
@@ -32775,7 +32935,7 @@ function ownEntries2(agent, env) {
32775
32935
  if (agent === "pi") {
32776
32936
  const agentDir = piAgentDirOf(env, home);
32777
32937
  return [{
32778
- file: join23(agentDir, SETTINGS_FILE),
32938
+ file: join24(agentDir, SETTINGS_FILE),
32779
32939
  key: PI_PACKAGES_KEY,
32780
32940
  shown: PI_PACKAGES_KEY,
32781
32941
  has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
@@ -32797,12 +32957,12 @@ function removeOwnEntries(agent, env) {
32797
32957
  return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
32798
32958
  }
32799
32959
  function removeProjectData(configDir, projectKey) {
32800
- const projects = join23(configDir, PROJECTS_DIR_NAME);
32801
- const dir = join23(projects, projectKey);
32802
- if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
32960
+ const projects = join24(configDir, PROJECTS_DIR_NAME);
32961
+ const dir = join24(projects, projectKey);
32962
+ if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
32803
32963
  if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
32804
- for (const name of readdirSync8(dir)) {
32805
- if (name !== OWNERS_DIR_NAME) rmSync6(join23(dir, name), { recursive: true, force: true });
32964
+ for (const name of readdirSync9(dir)) {
32965
+ if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
32806
32966
  }
32807
32967
  return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
32808
32968
  }
@@ -32810,12 +32970,12 @@ function runUninstall(input) {
32810
32970
  const configDir = resolveConfigDir(input.env);
32811
32971
  const stop = stopServers(configDir, input.project.projectKey);
32812
32972
  const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
32813
- rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join23(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
32973
+ rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
32814
32974
  return { rows, stopped: stop.stopped };
32815
32975
  }
32816
32976
 
32817
32977
  // src/core/ops/v1-remove.ts
32818
- import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync17, rmSync as rmSync7 } from "node:fs";
32978
+ import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync18, rmSync as rmSync7 } from "node:fs";
32819
32979
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
32820
32980
  var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
32821
32981
  var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
@@ -32827,7 +32987,7 @@ function moveAside(target, undo) {
32827
32987
  }
32828
32988
  function keepAside(target, undo) {
32829
32989
  let aside = target + UPGRADE_ASIDE_SUFFIX;
32830
- for (let n = 2; existsSync20(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
32990
+ for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
32831
32991
  renameWithRetry(target, aside);
32832
32992
  undo.push({ trash: aside, target, keep: true });
32833
32993
  return aside;
@@ -32866,8 +33026,8 @@ function locate(doc, path8) {
32866
33026
  return null;
32867
33027
  }
32868
33028
  function stripJsonEntries(agent, file2, findings, kept, undo) {
32869
- const layout = hostLayout(readFileSync17(file2, "utf8"));
32870
- const text = hostText(readFileSync17(file2, "utf8"));
33029
+ const layout = hostLayout(readFileSync18(file2, "utf8"));
33030
+ const text = hostText(readFileSync18(file2, "utf8"));
32871
33031
  const doc = parseHostConfig(agent, file2, text, "jsonc");
32872
33032
  const hit = /* @__PURE__ */ new Set();
32873
33033
  const byContainer = /* @__PURE__ */ new Map();
@@ -32904,20 +33064,20 @@ function removeV1(agent, findings, project) {
32904
33064
  if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
32905
33065
  else if (f.path === "") {
32906
33066
  if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
32907
- else if (existsSync20(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
32908
- else if (existsSync20(f.file)) {
33067
+ else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
33068
+ else if (existsSync21(f.file)) {
32909
33069
  moveAside(f.file, undo);
32910
33070
  done.set(f, UPGRADE_REMOVED);
32911
33071
  } else done.set(f, UPGRADE_NOT_FOUND);
32912
33072
  } else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
32913
33073
  }
32914
33074
  for (const [file2, list4] of entries) {
32915
- if (!existsSync20(file2)) {
33075
+ if (!existsSync21(file2)) {
32916
33076
  for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
32917
33077
  continue;
32918
33078
  }
32919
33079
  if (file2.endsWith(TOML_EXT)) {
32920
- const rawToml = readFileSync17(file2, "utf8");
33080
+ const rawToml = readFileSync18(file2, "utf8");
32921
33081
  const tomlLayout = hostLayout(rawToml);
32922
33082
  let text = hostText(rawToml);
32923
33083
  for (const f of list4) {
@@ -32945,7 +33105,7 @@ function removeV1(agent, findings, project) {
32945
33105
  },
32946
33106
  rollback() {
32947
33107
  for (const u of undo.splice(0).reverse()) {
32948
- if (!existsSync20(u.trash)) continue;
33108
+ if (!existsSync21(u.trash)) continue;
32949
33109
  rmSync7(u.target, { recursive: true, force: true });
32950
33110
  renameWithRetry(u.trash, u.target);
32951
33111
  }
@@ -33075,7 +33235,55 @@ function checkCall(tool, input) {
33075
33235
  }
33076
33236
 
33077
33237
  // src/entries/opencode.ts
33238
+ import { resolve as resolve10 } from "node:path";
33078
33239
  var AGENT = "opencode";
33240
+ var slash = (p) => p.replaceAll("\\", "/");
33241
+ function shellRequest(commands) {
33242
+ const resources = [];
33243
+ for (const cmd of commands) {
33244
+ const parsed = parseShell(cmd);
33245
+ const raws = parsed.ok ? parsed.commands.map((c) => c.raw.trim()).filter((r) => r !== "") : [];
33246
+ resources.push(...raws.length > 0 ? raws : [cmd.trim()]);
33247
+ }
33248
+ return { action: OC_SHELL_ACTION, resources, save: resources };
33249
+ }
33250
+ function permissionRequests(tool, input, base) {
33251
+ const i = input ?? {};
33252
+ const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
33253
+ const out = [];
33254
+ const read3 = (p) => {
33255
+ const abs = slash(resolve10(base, p));
33256
+ return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
33257
+ };
33258
+ if (tool === "ctx_execute") {
33259
+ const language = str3(i.language) ?? OC_ANY_RESOURCE;
33260
+ out.push({ action: tool, resources: [language], save: [language] });
33261
+ if (isShellLanguage(language) && typeof i.code === "string") out.push(shellRequest([i.code]));
33262
+ const file2 = str3(i.file);
33263
+ if (file2 !== void 0) out.push(read3(file2));
33264
+ return out;
33265
+ }
33266
+ if (tool === "ctx_batch") {
33267
+ const commands = Array.isArray(i.commands) ? i.commands.filter((c) => typeof c === "string") : [];
33268
+ out.push({ action: tool, resources: commands, save: commands });
33269
+ if (commands.length > 0) out.push(shellRequest(commands));
33270
+ return out;
33271
+ }
33272
+ if (tool === "ctx_index") {
33273
+ const path8 = str3(i.path);
33274
+ const url2 = str3(i.url);
33275
+ const what = path8 ?? url2 ?? OC_ANY_RESOURCE;
33276
+ out.push({ action: tool, resources: [what], save: [what] });
33277
+ if (path8 !== void 0) out.push(read3(path8));
33278
+ if (url2 !== void 0) out.push({ action: OC_WEBFETCH_ACTION, resources: [url2], save: [OC_ANY_RESOURCE] });
33279
+ return out;
33280
+ }
33281
+ return [{ action: tool, resources: [OC_ANY_RESOURCE], save: [OC_ANY_RESOURCE] }];
33282
+ }
33283
+ async function legacyAsk(req, toolCtx) {
33284
+ const permission = req.action === OC_SHELL_ACTION ? OC_LEGACY_SHELL_ACTION : req.action;
33285
+ await toolCtx.ask?.({ permission, patterns: req.resources, always: req.save, metadata: {} });
33286
+ }
33079
33287
  var id = PLUGIN_ID;
33080
33288
  async function setupLegacy(app) {
33081
33289
  const cwd = app.directory;
@@ -33115,6 +33323,17 @@ async function setupLegacy(app) {
33115
33323
  signal: toolCtx.abort ?? new AbortController().signal,
33116
33324
  protocolVersion: ""
33117
33325
  };
33326
+ const permission = app.permission ?? (typeof toolCtx.ask === "function" ? "wired" : void 0);
33327
+ if (permission !== void 0) ctx.hostPermission = permission;
33328
+ if (permission === "wired") {
33329
+ let base = cwd ?? "";
33330
+ try {
33331
+ base = ctx.project.worktree;
33332
+ } catch {
33333
+ }
33334
+ const check2 = app.assert ?? legacyAsk;
33335
+ for (const req of permissionRequests(tool.name, checked.data, base)) await check2(req, toolCtx);
33336
+ }
33118
33337
  let reply4;
33119
33338
  try {
33120
33339
  reply4 = await tool.handler(checked.data, ctx);
@@ -33189,8 +33408,21 @@ function oc2Text(content) {
33189
33408
  }
33190
33409
  async function setup(ctx) {
33191
33410
  const tools = /* @__PURE__ */ new Map();
33411
+ const assert2 = ctx.permission?.assert;
33192
33412
  const hooks = await setupLegacy({
33193
33413
  directory: ctx.location.directory,
33414
+ // D-1331-OC-PERM-1: ctx.permission.assert is the 2.x plugin check (anomalyco/opencode#50652); "missing" feeds D10.
33415
+ permission: typeof assert2 === "function" ? "wired" : "missing",
33416
+ assert: async (req, t) => {
33417
+ await assert2?.({
33418
+ sessionID: t.sessionID ?? "",
33419
+ ...t.agent === void 0 ? {} : { agent: t.agent },
33420
+ action: req.action,
33421
+ resources: req.resources,
33422
+ save: req.save,
33423
+ ...t.messageID === void 0 || t.callID === void 0 ? {} : { source: { type: "tool", messageID: t.messageID, id: t.callID } }
33424
+ });
33425
+ },
33194
33426
  tool(name, def) {
33195
33427
  tools.set(name, {
33196
33428
  name,
@@ -33199,7 +33431,8 @@ async function setup(ctx) {
33199
33431
  options: { codemode: false },
33200
33432
  // a ctx_* tool is listed to the model by name, not behind the host's code tool
33201
33433
  async execute(input, context) {
33202
- return { content: await def.execute(input, { sessionID: context.sessionID, abort: context.signal }) };
33434
+ const t = { sessionID: context.sessionID, abort: context.signal, agent: context.agent, messageID: context.messageID, callID: context.id };
33435
+ return { content: await def.execute(input, t) };
33203
33436
  }
33204
33437
  });
33205
33438
  }
@@ -33250,6 +33483,7 @@ var opencode_default2 = { id: PLUGIN_ID, server, setup };
33250
33483
  export {
33251
33484
  opencode_default2 as default,
33252
33485
  id,
33486
+ permissionRequests,
33253
33487
  server,
33254
33488
  setup,
33255
33489
  setupLegacy