inkmap-mcp 0.3.16 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -411,13 +411,13 @@ ${line}---
411
411
  else {
412
412
  const section = norm.match(SETTINGS_SECTION);
413
413
  if (!section)
414
- updated = norm.replace(/---\n$/, `inkmap:
414
+ updated = norm.replace(/---\n$/, () => `inkmap:
415
415
  ${line}---
416
416
  `);
417
417
  else {
418
418
  const keyLine = new RegExp(`^[ \\t]+${key}:.*\\n`, "m");
419
- const body = keyLine.test(section[1]) ? section[1].replace(keyLine, line) : section[1] + line;
420
- updated = norm.replace(SETTINGS_SECTION, `inkmap:
419
+ const body = keyLine.test(section[1]) ? section[1].replace(keyLine, () => line) : section[1] + line;
420
+ updated = norm.replace(SETTINGS_SECTION, () => `inkmap:
421
421
  ${body}`);
422
422
  }
423
423
  }
@@ -466,7 +466,7 @@ var INKMAP_VERSION;
466
466
  var init_version = __esm({
467
467
  "packages/cli/dist/version.js"() {
468
468
  "use strict";
469
- INKMAP_VERSION = "0.3.16";
469
+ INKMAP_VERSION = "0.3.18";
470
470
  }
471
471
  });
472
472
 
@@ -549,7 +549,7 @@ function billingOrigin(raw) {
549
549
  }
550
550
  return url2.origin;
551
551
  }
552
- function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS } = {}) {
552
+ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS, reviewPrompt = true } = {}) {
553
553
  const listeners = /* @__PURE__ */ new Set();
554
554
  let current = { pro: false };
555
555
  let trial;
@@ -560,7 +560,27 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
560
560
  let sentAppOpen = false;
561
561
  let detectedHost = defaultHost;
562
562
  const pendingEvents = /* @__PURE__ */ new Map();
563
+ let reviewDue = false;
564
+ let reviewCounting = Promise.resolve();
565
+ const countForReview = (event, count) => {
566
+ reviewCounting = reviewCounting.then(async () => {
567
+ if (disposed || reviewDue)
568
+ return;
569
+ const usage = await readReviewUsage();
570
+ if (usage.done)
571
+ return;
572
+ if (event === "doc_open")
573
+ usage.opens += count;
574
+ else
575
+ usage.edits += count;
576
+ await writeReviewUsage(usage);
577
+ if (usage.opens >= REVIEW_MIN_OPENS && usage.edits >= REVIEW_MIN_EDITS)
578
+ reviewDue = true;
579
+ }).catch(() => {
580
+ });
581
+ };
563
582
  let lastCheck = 0;
583
+ let retryAfter = 0;
564
584
  let fastPollUntil = 0;
565
585
  const expectPurchase = () => void (fastPollUntil = Date.now() + 15 * 6e4);
566
586
  let flowCreation;
@@ -762,6 +782,24 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
762
782
  timer = setTimeout(() => void refresh(), delay);
763
783
  timer.unref();
764
784
  }
785
+ async function rememberProCheck(token, active, account) {
786
+ await writeSession(async () => {
787
+ let record2;
788
+ try {
789
+ record2 = JSON.parse(await storage.read() || "{}");
790
+ } catch {
791
+ return;
792
+ }
793
+ if (record2.token !== token)
794
+ return;
795
+ const at = typeof record2.proVerifiedAt === "number" ? record2.proVerifiedAt : void 0;
796
+ if (active ? at !== void 0 && Date.now() - at < PRO_RECHECK_STAMP_MS && at <= Date.now() : at === void 0)
797
+ return;
798
+ const { proVerifiedAt: _at, proAccount: _account, ...rest } = record2;
799
+ await storage.write(JSON.stringify(active ? { ...rest, proVerifiedAt: Date.now(), ...account && { proAccount: account } } : rest));
800
+ }).catch(() => {
801
+ });
802
+ }
765
803
  function refresh() {
766
804
  if (connection)
767
805
  return connection;
@@ -769,6 +807,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
769
807
  connection = (async () => {
770
808
  let token;
771
809
  let delay = 6e4;
810
+ let offlinePro;
772
811
  try {
773
812
  const origin = billingOrigin(getOrigin());
774
813
  if (origin !== activeOrigin) {
@@ -785,6 +824,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
785
824
  if (record2.origin !== origin || typeof record2.token !== "string")
786
825
  return update(false);
787
826
  token = record2.token;
827
+ const verifiedAt = record2.proVerifiedAt;
828
+ if (typeof verifiedAt === "number" && verifiedAt <= Date.now() && Date.now() - verifiedAt < OFFLINE_PRO_GRACE_MS) {
829
+ offlinePro = { ...typeof record2.proAccount === "string" && { account: record2.proAccount.slice(0, 64) } };
830
+ }
788
831
  const response = await entitlement(origin, record2.token);
789
832
  if (version2 !== generation || disposed)
790
833
  return;
@@ -804,9 +847,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
804
847
  if (version2 !== generation || disposed)
805
848
  return;
806
849
  applyEntitlement(state);
807
- delay = state.active !== true && state.pending === true ? 2500 : 6e4;
850
+ void rememberProCheck(record2.token, current.pro, current.account);
851
+ delay = state.active !== true && (state.pending === true || Date.now() < fastPollUntil) ? 2500 : 6e4;
808
852
  } catch {
809
- if (version2 === generation && Date.now() - lastCheck > 15 * 6e4)
853
+ if (version2 === generation)
854
+ retryAfter = Date.now() + (Date.now() < fastPollUntil ? 2e3 : 3e4);
855
+ if (version2 === generation && offlinePro)
856
+ update(true, true, offlinePro.account);
857
+ else if (version2 === generation && Date.now() - lastCheck > 15 * 6e4)
810
858
  update(false);
811
859
  } finally {
812
860
  if (version2 === generation && token)
@@ -845,7 +893,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
845
893
  clearTimeout(waitTimer);
846
894
  if (disposed || !waiting.length)
847
895
  return;
848
- waitTimer = setTimeout(() => void checkWaiting(), delay);
896
+ waitTimer = setTimeout(() => void checkWaiting().catch(() => scheduleWait(WAIT_SLOW_MS)), delay);
849
897
  waitTimer.unref();
850
898
  }
851
899
  async function checkWaiting() {
@@ -886,8 +934,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
886
934
  await writeSession(async () => {
887
935
  if (disposed || round !== waitRound || w2.origin !== billingOrigin(getOrigin()))
888
936
  return;
889
- clearWaiting();
937
+ if (w2.email)
938
+ lastSignIn = w2.email.trim().slice(0, 254);
890
939
  await storage.write(sessionRecord({ origin: w2.origin, token: w2.token }));
940
+ clearWaiting();
891
941
  ++generation;
892
942
  activeOrigin = w2.origin;
893
943
  applyEntitlement(body);
@@ -924,6 +974,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
924
974
  }
925
975
  if (typeof record2.token !== "string" || typeof record2.origin !== "string")
926
976
  return;
977
+ if (typeof record2.checkoutUrl === "string")
978
+ return;
927
979
  const response = await entitlement(record2.origin, record2.token).catch(() => null);
928
980
  if (!response?.ok)
929
981
  return;
@@ -956,13 +1008,20 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
956
1008
  return;
957
1009
  }
958
1010
  if (process.env.INKMAP_ALLOW_TEST_TELEMETRY !== "1") {
959
- if (origin === "https://billing.example.com" || process.env.INKMAP_DISABLE_TELEMETRY === "1" || process.env.NODE_TEST_CONTEXT)
960
- return;
961
- const customHome = process.env.INKMAP_HOME || "";
962
- const sysTmp = (0, import_node_os.tmpdir)();
963
- if (customHome && (customHome === sysTmp || customHome.startsWith(sysTmp + import_node_path.sep) || customHome.startsWith("/tmp/") || customHome.startsWith("/private/tmp/") || customHome.includes("/var/folders/") || customHome.includes("inkmap-npm-isolated-") || customHome.includes("inkmap-antigravity-mcp-") || customHome.includes("inkmap-local-editor-") || customHome.includes("inkmap-harness-"))) {
1011
+ if (origin === "https://billing.example.com" || process.env.INKMAP_DISABLE_TELEMETRY === "1" || process.env.NODE_TEST_CONTEXT || process.env.VITEST || process.env.JEST_WORKER_ID || process.env.CI === "true" || process.env.CI === "1") {
964
1012
  return;
965
1013
  }
1014
+ const norm = (p2) => {
1015
+ const clean = p2.replace(/\\/g, "/");
1016
+ return process.platform === "win32" ? clean.toLowerCase() : clean;
1017
+ };
1018
+ const sysTmp = norm((0, import_node_os.tmpdir)()).replace(/\/+$/, "");
1019
+ const homesToCheck = [process.env.INKMAP_HOME || "", (0, import_node_os.homedir)()].filter(Boolean).map(norm);
1020
+ for (const h2 of homesToCheck) {
1021
+ if (h2 === sysTmp || h2.startsWith(sysTmp + "/") || h2.startsWith("/tmp/") || h2.startsWith("/private/tmp/") || h2.includes("/var/folders/") || h2.includes("/appdata/local/temp/") || h2.includes("/temp/inkmap") || h2.includes("inkmap-npm-isolated-") || h2.includes("inkmap-antigravity-mcp-") || h2.includes("inkmap-local-editor-") || h2.includes("inkmap-harness-") || h2.includes("inkmap-test-")) {
1022
+ return;
1023
+ }
1024
+ }
966
1025
  }
967
1026
  const id = await (installIdPromise ??= localInstallId().catch(() => void 0));
968
1027
  if (disposed || !id || !pendingEvents.size)
@@ -994,12 +1053,22 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
994
1053
  });
995
1054
  }
996
1055
  return {
997
- async state() {
1056
+ async state(options) {
998
1057
  await (trial ??= startTrial());
999
- const interval = !current.pro && Date.now() < fastPollUntil ? 4e3 : 6e4;
1000
- if (Date.now() - lastCheck >= interval)
1058
+ const interval = !current.pro && Date.now() < fastPollUntil ? 2e3 : 6e4;
1059
+ if (Date.now() - lastCheck >= interval && Date.now() >= retryAfter)
1001
1060
  await refresh();
1002
1061
  await parkUnpaidSession();
1062
+ await reviewCounting;
1063
+ if (options?.forUi && reviewDue && hasAccess(current)) {
1064
+ reviewDue = false;
1065
+ const usage = await readReviewUsage().catch(() => void 0);
1066
+ if (usage && !usage.done) {
1067
+ await writeReviewUsage({ ...usage, done: true }).catch(() => {
1068
+ });
1069
+ return { ...current, reviewPrompt: true };
1070
+ }
1071
+ }
1003
1072
  return current;
1004
1073
  },
1005
1074
  async connect(mode, localeHint) {
@@ -1066,7 +1135,9 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
1066
1135
  if (cachedOrder && cachedOrder.origin === origin && cachedOrder.locale === loc && Date.now() - cachedOrder.at < 8e3) {
1067
1136
  const hit = cachedOrder.result;
1068
1137
  cachedOrder = void 0;
1069
- schedule(hit.status === "qr" || hit.status === "redirect" ? 4e3 : 6e4);
1138
+ if (current.pro)
1139
+ return { status: "active", state: current };
1140
+ schedule(hit.status === "qr" || hit.status === "redirect" ? 2500 : 6e4);
1070
1141
  return hit;
1071
1142
  }
1072
1143
  const version2 = generation;
@@ -1077,6 +1148,17 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
1077
1148
  record2 = JSON.parse(stored);
1078
1149
  } catch {
1079
1150
  }
1151
+ if (record2?.origin === origin && typeof record2.token === "string") {
1152
+ const rights = await entitlement(origin, record2.token).catch(() => null);
1153
+ if (rights?.ok) {
1154
+ const ent = await rights.json().catch(() => null);
1155
+ if (ent && ent.active === true) {
1156
+ applyEntitlement(ent);
1157
+ schedule(6e4);
1158
+ return { status: "active", state: current };
1159
+ }
1160
+ }
1161
+ }
1080
1162
  const requestOrder = async (checkoutUrl, token, cookie, persist) => {
1081
1163
  const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, localeHint);
1082
1164
  if (res.status === 401 || res.status === 403 || res.status === 404 || res.status === 410)
@@ -1274,13 +1356,16 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
1274
1356
  if (version2 !== generation || disposed || origin !== billingOrigin(getOrigin()))
1275
1357
  return phoneFailure();
1276
1358
  clearWaiting();
1359
+ const clean = phone.trim().slice(0, 254);
1360
+ if (clean)
1361
+ lastSignIn = clean;
1277
1362
  await storage.write(sessionRecord({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
1278
1363
  ++generation;
1279
1364
  activeOrigin = origin;
1280
1365
  applyEntitlement(state);
1281
1366
  if (cachedOrder?.result.status === "active")
1282
1367
  cachedOrder.result.state = current;
1283
- schedule(cachedOrder?.result.status === "qr" ? 4e3 : 6e4);
1368
+ schedule(cachedOrder?.result.status === "qr" || cachedOrder?.result.status === "redirect" ? 2500 : 6e4);
1284
1369
  return { ok: true, value: current };
1285
1370
  });
1286
1371
  } catch {
@@ -1331,6 +1416,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
1331
1416
  if (event !== "app_open") {
1332
1417
  pendingEvents.set(event, Math.min(1e3, (pendingEvents.get(event) ?? 0) + count));
1333
1418
  }
1419
+ if (reviewPrompt && !process.env.CI && (event === "doc_open" || event === "doc_edit"))
1420
+ countForReview(event, count);
1334
1421
  if (telemetryTimer)
1335
1422
  return;
1336
1423
  telemetryTimer = setTimeout(() => {
@@ -1402,6 +1489,22 @@ async function atomicCreateIfMissing(path, initialContent) {
1402
1489
  return await (0, import_promises.readFile)(path, "utf8");
1403
1490
  }
1404
1491
  }
1492
+ async function readReviewUsage() {
1493
+ const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
1494
+ try {
1495
+ const raw = JSON.parse(await (0, import_promises.readFile)(reviewUsagePath(), "utf8"));
1496
+ return { opens: count(raw.opens), edits: count(raw.edits), done: raw.done === true };
1497
+ } catch {
1498
+ return { opens: 0, edits: 0, done: false };
1499
+ }
1500
+ }
1501
+ async function writeReviewUsage(usage) {
1502
+ const path = reviewUsagePath();
1503
+ await (0, import_promises.mkdir)((0, import_node_path.dirname)(path), { recursive: true, mode: 448 });
1504
+ const temporary = path + "." + (0, import_node_crypto.randomUUID)();
1505
+ await (0, import_promises.writeFile)(temporary, JSON.stringify(usage), { mode: 384 });
1506
+ await (0, import_promises.rename)(temporary, path);
1507
+ }
1405
1508
  async function localInstallId() {
1406
1509
  const path = (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "install-id");
1407
1510
  const generated = "inst_" + (0, import_node_crypto.randomUUID)().replace(/-/g, "").slice(0, 24);
@@ -1431,7 +1534,7 @@ async function localTrialDeadline() {
1431
1534
  const started = Number(value);
1432
1535
  return Number.isSafeInteger(started) && started > 0 && started <= Date.now() ? started + TRIAL_MS : void 0;
1433
1536
  }
1434
- var import_node_child_process, import_promises, import_node_crypto, import_node_os, import_node_path, ZH_LOCALE_RE, EN_LOCALE_RE, cachedOsLocale, WAIT_FAST_MS, WAIT_SLOW_MS, WAIT_FAST_FOR_MS, WAIT_MAX_MS, MAX_WAITING, DOMESTIC_TIME_ZONE, posixLocale, PASSIVE_TELEMETRY_EVENTS;
1537
+ var import_node_child_process, import_promises, import_node_crypto, import_node_os, import_node_path, ZH_LOCALE_RE, EN_LOCALE_RE, cachedOsLocale, WAIT_FAST_MS, WAIT_SLOW_MS, WAIT_FAST_FOR_MS, WAIT_MAX_MS, MAX_WAITING, OFFLINE_PRO_GRACE_MS, PRO_RECHECK_STAMP_MS, DOMESTIC_TIME_ZONE, posixLocale, PASSIVE_TELEMETRY_EVENTS, REVIEW_MIN_OPENS, REVIEW_MIN_EDITS, reviewUsagePath;
1435
1538
  var init_license = __esm({
1436
1539
  "packages/cli/dist/license.js"() {
1437
1540
  "use strict";
@@ -1449,9 +1552,59 @@ var init_license = __esm({
1449
1552
  WAIT_FAST_FOR_MS = 30 * 6e4;
1450
1553
  WAIT_MAX_MS = 3 * 24 * 60 * 6e4;
1451
1554
  MAX_WAITING = 5;
1555
+ OFFLINE_PRO_GRACE_MS = 7 * 24 * 60 * 6e4;
1556
+ PRO_RECHECK_STAMP_MS = 12 * 60 * 6e4;
1452
1557
  DOMESTIC_TIME_ZONE = /^(Asia\/(Shanghai|Chongqing|Chungking|Harbin|Urumqi|Beijing)|PRC)$/i;
1453
1558
  posixLocale = (env) => (env.LC_ALL || env.LC_MESSAGES || env.LANG || "").trim();
1454
1559
  PASSIVE_TELEMETRY_EVENTS = /* @__PURE__ */ new Set(["plugin_activate", "plugin_install", "onboarding_view"]);
1560
+ REVIEW_MIN_OPENS = 5;
1561
+ REVIEW_MIN_EDITS = 3;
1562
+ reviewUsagePath = () => (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "review-prompt");
1563
+ }
1564
+ });
1565
+
1566
+ // packages/cli/dist/open-browser.js
1567
+ function run(cmd, args, launched = false) {
1568
+ return new Promise((done) => {
1569
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1570
+ child.on("error", () => done(false));
1571
+ if (launched)
1572
+ child.on("spawn", () => done(true));
1573
+ else
1574
+ child.on("exit", (code) => done(code === 0));
1575
+ child.unref();
1576
+ });
1577
+ }
1578
+ function openSystemBrowser(url2) {
1579
+ if (process.env.INKMAP_NO_OPEN === "1")
1580
+ return;
1581
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
1582
+ void run(cmd, args, true);
1583
+ }
1584
+ async function openBrowserWindow(url2) {
1585
+ if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url2))
1586
+ return;
1587
+ if (process.platform === "darwin") {
1588
+ if (await run("open", ["-a", "Google Chrome", url2]))
1589
+ return;
1590
+ await run("open", [url2]);
1591
+ return;
1592
+ }
1593
+ if (process.platform === "win32") {
1594
+ if (await run("cmd", ["/c", "start", "", "chrome", url2]))
1595
+ return;
1596
+ await run("cmd", ["/c", "start", "", url2]);
1597
+ return;
1598
+ }
1599
+ if (await run("google-chrome", [url2], true))
1600
+ return;
1601
+ await run("xdg-open", [url2], true);
1602
+ }
1603
+ var import_node_child_process2;
1604
+ var init_open_browser = __esm({
1605
+ "packages/cli/dist/open-browser.js"() {
1606
+ "use strict";
1607
+ import_node_child_process2 = require("node:child_process");
1455
1608
  }
1456
1609
  });
1457
1610
 
@@ -1471,11 +1624,10 @@ function hasHiddenSegment(root, target) {
1471
1624
  async function hasSymlinkUnderRoot(realRoot, rawTarget) {
1472
1625
  let cur = rawTarget;
1473
1626
  while (cur && cur !== (0, import_node_path2.dirname)(cur)) {
1474
- const st = await (0, import_promises2.lstat)(cur);
1475
- if (st.isSymbolicLink())
1476
- return true;
1477
1627
  if (await (0, import_promises2.realpath)(cur) === realRoot)
1478
1628
  return false;
1629
+ if ((await (0, import_promises2.lstat)(cur)).isSymbolicLink())
1630
+ return true;
1479
1631
  cur = (0, import_node_path2.dirname)(cur);
1480
1632
  }
1481
1633
  return false;
@@ -1782,13 +1934,18 @@ async function fileSource(file2, log = () => {
1782
1934
  log(`\u5DF2\u5199\u56DE ${path}`);
1783
1935
  },
1784
1936
  watch(onChange) {
1785
- const watcher = (0, import_node_fs.watch)(dir, (_2, changed) => {
1786
- if (!changed || changed === (0, import_node_path3.basename)(path))
1787
- onChange();
1788
- });
1789
- watcher.on("error", () => {
1790
- });
1791
- return () => watcher.close();
1937
+ try {
1938
+ const watcher = (0, import_node_fs.watch)(dir, (_2, changed) => {
1939
+ if (!changed || changed === (0, import_node_path3.basename)(path))
1940
+ onChange();
1941
+ });
1942
+ watcher.on("error", () => {
1943
+ });
1944
+ return () => watcher.close();
1945
+ } catch {
1946
+ return () => {
1947
+ };
1948
+ }
1792
1949
  },
1793
1950
  readView: () => readDiskViewState(path),
1794
1951
  writeView: (state) => writeDiskViewState(path, state)
@@ -1806,33 +1963,8 @@ function within(root, rel, allowAbsoluteInRoot = false) {
1806
1963
  const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? (0, import_node_path3.normalize)(decoded) : (0, import_node_path3.normalize)((0, import_node_path3.join)(resolvedRoot, decoded));
1807
1964
  return full.startsWith(base) ? full : null;
1808
1965
  }
1809
- async function openBrowserWindow(url2) {
1810
- if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url2))
1811
- return;
1812
- const run = (cmd, args) => new Promise((done) => {
1813
- const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1814
- child.on("error", () => done(false));
1815
- child.on("exit", (code) => done(code === 0));
1816
- child.unref();
1817
- });
1818
- if (process.platform === "darwin") {
1819
- if (await run("open", ["-a", "Google Chrome", url2]))
1820
- return;
1821
- await run("open", [url2]);
1822
- return;
1823
- }
1824
- if (process.platform === "win32") {
1825
- if (await run("cmd", ["/c", "start", "", "chrome", url2]))
1826
- return;
1827
- await run("cmd", ["/c", "start", "", url2]);
1828
- return;
1829
- }
1830
- if (await run("google-chrome", [url2]))
1831
- return;
1832
- await run("xdg-open", [url2]);
1833
- }
1834
1966
  async function serve({ source: initialSource, webRoot, port = 4377, host = "127.0.0.1", log = () => {
1835
- }, license, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false, ideWorkspace = false, workspaceRoots = [], confineToWorkspaceRoots = false, openSource = (path) => fileSource(path, log), allowPurchase = true }) {
1967
+ }, license, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false, workspaceRoots = [], confineToWorkspaceRoots = false, openSource = (path) => fileSource(path, log), allowPurchase = true }) {
1836
1968
  if (sidebar && host !== "127.0.0.1")
1837
1969
  throw new Error("The sidebar bridge requires loopback.");
1838
1970
  const prefix = sidebar ? `/s/${(0, import_node_crypto2.randomBytes)(24).toString("hex")}/` : "/";
@@ -2051,7 +2183,6 @@ data: ${JSON.stringify(data)}
2051
2183
  if (url2.pathname === "/api/capabilities" && req.method === "GET") {
2052
2184
  return json2(res, 200, {
2053
2185
  purchase: canPurchase,
2054
- ...ideWorkspace && { ideWorkspace: true },
2055
2186
  ...sidebarAccountNavigation && { accountNavigation: "host" }
2056
2187
  });
2057
2188
  }
@@ -2072,6 +2203,8 @@ data: ${JSON.stringify(data)}
2072
2203
  const { md, baseVersion } = JSON.parse(await readBody(req));
2073
2204
  if (typeof md !== "string")
2074
2205
  return json2(res, 400, { error: zh() ? "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002" : "md must be a string." });
2206
+ if (Buffer.byteLength(md) > MAX_MARKDOWN_BYTES)
2207
+ return json2(res, 413, { error: zh() ? "\u6587\u6863\u8FC7\u5927\u3002" : "Document too large." });
2075
2208
  if (!hasAccess(await license?.state() ?? { pro: false }))
2076
2209
  return json2(res, 403, { error: "Inkmap trial expired" });
2077
2210
  return await serialized(async () => {
@@ -2089,7 +2222,7 @@ data: ${JSON.stringify(data)}
2089
2222
  });
2090
2223
  }
2091
2224
  if (url2.pathname === "/api/license" && req.method === "GET")
2092
- return json2(res, 200, await license?.state() ?? { pro: false });
2225
+ return json2(res, 200, await license?.state({ forUi: true }) ?? { pro: false });
2093
2226
  if (url2.pathname === "/api/open" && req.method === "POST") {
2094
2227
  if (!sameOriginWrite())
2095
2228
  return json2(res, 403, { error: "forbidden" });
@@ -2103,7 +2236,7 @@ data: ${JSON.stringify(data)}
2103
2236
  if (!sameOriginWrite())
2104
2237
  return json2(res, 403, { error: "forbidden" });
2105
2238
  const { event } = JSON.parse(await readBody(req));
2106
- if (typeof event === "string" && event)
2239
+ if (typeof event === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(event))
2107
2240
  license?.track?.(event);
2108
2241
  return json2(res, 200, { ok: true });
2109
2242
  }
@@ -2260,12 +2393,11 @@ data: ${JSON.stringify(data)}
2260
2393
  })
2261
2394
  };
2262
2395
  }
2263
- var import_node_child_process2, import_node_crypto2, import_node_fs, import_promises3, import_node_http, import_node_os3, import_node_path3, MAX_BODY, TYPES, HttpError, LOOPBACK_HOST, hash;
2396
+ var import_node_crypto2, import_node_fs, import_promises3, import_node_http, import_node_os3, import_node_path3, MAX_BODY, TYPES, HttpError, LOOPBACK_HOST, hash;
2264
2397
  var init_server = __esm({
2265
2398
  "packages/cli/dist/server.js"() {
2266
2399
  "use strict";
2267
2400
  init_dist();
2268
- import_node_child_process2 = require("node:child_process");
2269
2401
  import_node_crypto2 = require("node:crypto");
2270
2402
  import_node_fs = require("node:fs");
2271
2403
  import_promises3 = require("node:fs/promises");
@@ -2273,6 +2405,7 @@ var init_server = __esm({
2273
2405
  import_node_os3 = require("node:os");
2274
2406
  import_node_path3 = require("node:path");
2275
2407
  init_license();
2408
+ init_open_browser();
2276
2409
  init_workspace_fs();
2277
2410
  MAX_BODY = 20 * 1024 * 1024;
2278
2411
  TYPES = {
@@ -23652,7 +23785,7 @@ function visit(schema, fnOrHandlers) {
23652
23785
  return h2 ? h2(node2, rewritten) : node2;
23653
23786
  };
23654
23787
  const cache = /* @__PURE__ */ new Map();
23655
- function run(s) {
23788
+ function run2(s) {
23656
23789
  const cached2 = cache.get(s);
23657
23790
  if (cached2 === RESOLVING) {
23658
23791
  return new $ZodLazy({
@@ -23678,21 +23811,21 @@ function visit(schema, fnOrHandlers) {
23678
23811
  let changed = false;
23679
23812
  const newShape = {};
23680
23813
  for (const k2 of keys) {
23681
- const mapped = run(oldShape[k2]);
23814
+ const mapped = run2(oldShape[k2]);
23682
23815
  if (mapped !== oldShape[k2])
23683
23816
  changed = true;
23684
23817
  newShape[k2] = mapped;
23685
23818
  }
23686
23819
  let newCatchall = def.catchall;
23687
23820
  if (def.catchall) {
23688
- newCatchall = run(def.catchall);
23821
+ newCatchall = run2(def.catchall);
23689
23822
  if (newCatchall !== def.catchall)
23690
23823
  changed = true;
23691
23824
  }
23692
23825
  return changed ? clone(s, { ...def, shape: newShape, catchall: newCatchall }) : s;
23693
23826
  }
23694
23827
  case "array": {
23695
- const mapped = run(def.element);
23828
+ const mapped = run2(def.element);
23696
23829
  return mapped === def.element ? s : clone(s, { ...def, element: mapped });
23697
23830
  }
23698
23831
  case "tuple": {
@@ -23700,14 +23833,14 @@ function visit(schema, fnOrHandlers) {
23700
23833
  let changed = false;
23701
23834
  const newItems = [];
23702
23835
  for (const item of oldItems) {
23703
- const mapped = run(item);
23836
+ const mapped = run2(item);
23704
23837
  if (mapped !== item)
23705
23838
  changed = true;
23706
23839
  newItems.push(mapped);
23707
23840
  }
23708
23841
  let newRest = def.rest;
23709
23842
  if (def.rest) {
23710
- newRest = run(def.rest);
23843
+ newRest = run2(def.rest);
23711
23844
  if (newRest !== def.rest)
23712
23845
  changed = true;
23713
23846
  }
@@ -23715,12 +23848,12 @@ function visit(schema, fnOrHandlers) {
23715
23848
  }
23716
23849
  case "record":
23717
23850
  case "map": {
23718
- const newKey = run(def.keyType);
23719
- const newVal = run(def.valueType);
23851
+ const newKey = run2(def.keyType);
23852
+ const newVal = run2(def.valueType);
23720
23853
  return newKey === def.keyType && newVal === def.valueType ? s : clone(s, { ...def, keyType: newKey, valueType: newVal });
23721
23854
  }
23722
23855
  case "set": {
23723
- const newVal = run(def.valueType);
23856
+ const newVal = run2(def.valueType);
23724
23857
  return newVal === def.valueType ? s : clone(s, { ...def, valueType: newVal });
23725
23858
  }
23726
23859
  case "union": {
@@ -23728,7 +23861,7 @@ function visit(schema, fnOrHandlers) {
23728
23861
  let changed = false;
23729
23862
  const newOptions = [];
23730
23863
  for (const opt of oldOptions) {
23731
- const mapped = run(opt);
23864
+ const mapped = run2(opt);
23732
23865
  if (mapped !== opt)
23733
23866
  changed = true;
23734
23867
  newOptions.push(mapped);
@@ -23736,8 +23869,8 @@ function visit(schema, fnOrHandlers) {
23736
23869
  return changed ? clone(s, { ...def, options: newOptions }) : s;
23737
23870
  }
23738
23871
  case "intersection": {
23739
- const newLeft = run(def.left);
23740
- const newRight = run(def.right);
23872
+ const newLeft = run2(def.left);
23873
+ const newRight = run2(def.right);
23741
23874
  return newLeft === def.left && newRight === def.right ? s : clone(s, { ...def, left: newLeft, right: newRight });
23742
23875
  }
23743
23876
  case "optional":
@@ -23749,23 +23882,23 @@ function visit(schema, fnOrHandlers) {
23749
23882
  case "nonoptional":
23750
23883
  case "promise":
23751
23884
  case "success": {
23752
- const newInner = run(def.innerType);
23885
+ const newInner = run2(def.innerType);
23753
23886
  return newInner === def.innerType ? s : clone(s, { ...def, innerType: newInner });
23754
23887
  }
23755
23888
  case "pipe": {
23756
- const newIn = run(def.in);
23757
- const newOut = run(def.out);
23889
+ const newIn = run2(def.in);
23890
+ const newOut = run2(def.out);
23758
23891
  return newIn === def.in && newOut === def.out ? s : clone(s, { ...def, in: newIn, out: newOut });
23759
23892
  }
23760
23893
  case "function": {
23761
- const newInput = run(def.input);
23762
- const newOutput = run(def.output);
23894
+ const newInput = run2(def.input);
23895
+ const newOutput = run2(def.output);
23763
23896
  return newInput === def.input && newOutput === def.output ? s : clone(s, { ...def, input: newInput, output: newOutput });
23764
23897
  }
23765
23898
  case "lazy": {
23766
23899
  const original = def.getter;
23767
23900
  const { _cachedInner, ...rest } = def;
23768
- return clone(s, { ...rest, getter: () => run(original()) });
23901
+ return clone(s, { ...rest, getter: () => run2(original()) });
23769
23902
  }
23770
23903
  // A leaf by choice: `parts` are regex fragments, not data positions.
23771
23904
  case "template_literal":
@@ -23796,7 +23929,7 @@ function visit(schema, fnOrHandlers) {
23796
23929
  }
23797
23930
  }
23798
23931
  }
23799
- return run(schema);
23932
+ return run2(schema);
23800
23933
  }
23801
23934
  var RESOLVING;
23802
23935
  var init_visit = __esm({
@@ -40490,15 +40623,6 @@ __export(codex_exports, {
40490
40623
  function resolveWebRoot() {
40491
40624
  return WEB_ROOT_CANDIDATES.find((dir) => (0, import_node_fs2.existsSync)((0, import_node_path5.join)(dir, "index.html"))) ?? null;
40492
40625
  }
40493
- function openSystemBrowser(url2) {
40494
- if (process.env.INKMAP_NO_OPEN === "1")
40495
- return;
40496
- const [cmd, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
40497
- const child = (0, import_node_child_process3.spawn)(cmd, args, { stdio: "ignore", detached: true });
40498
- child.on("error", () => {
40499
- });
40500
- child.unref();
40501
- }
40502
40626
  async function validatedMarkdownFile(path) {
40503
40627
  if (!path || !/\.md$/i.test(path))
40504
40628
  throw new Error(say("\u8BF7\u9009\u62E9 .md \u6216 .markmap.md \u6587\u4EF6\u3002", "Choose a .md or .markmap.md file."));
@@ -40619,8 +40743,7 @@ async function createInkmapMcpServer(options = {}) {
40619
40743
  webRoot,
40620
40744
  port: 0,
40621
40745
  license: browserBilling,
40622
- sidebar: false,
40623
- ideWorkspace: false
40746
+ sidebar: false
40624
40747
  });
40625
40748
  })();
40626
40749
  fallbackEditors.set("__workspace__", pending);
@@ -40824,7 +40947,7 @@ async function createInkmapMcpServer(options = {}) {
40824
40947
  title: "Check Inkmap access",
40825
40948
  annotations: { readOnlyHint: true },
40826
40949
  _meta: appOnly
40827
- }, async () => ({ content: [], structuredContent: { ...await billing.state() } }));
40950
+ }, async () => ({ content: [], structuredContent: { ...await billing.state({ forUi: true }) } }));
40828
40951
  server.registerTool("inkmap_restore_access", {
40829
40952
  title: "Sign in to Yunfan",
40830
40953
  inputSchema: { locale: external_exports.string().optional() },
@@ -40859,16 +40982,20 @@ async function serveCodex() {
40859
40982
  server.server.onclose = () => {
40860
40983
  void dispose();
40861
40984
  };
40985
+ const shutdown = () => void dispose().finally(() => process.exit(0));
40986
+ process.stdin.once("end", shutdown);
40987
+ process.stdin.once("close", shutdown);
40988
+ process.once("SIGTERM", shutdown);
40989
+ process.once("SIGINT", shutdown);
40862
40990
  await server.connect(transport);
40863
40991
  }
40864
- var import_node_child_process3, import_node_fs2, import_promises5, import_node_os4, import_node_path5, import_node_url3, UI, HTML, WEB_ROOT_CANDIDATES, INLINE_DOC_LIMIT, appOnly;
40992
+ var import_node_fs2, import_promises5, import_node_os4, import_node_path5, import_node_url3, UI, HTML, WEB_ROOT_CANDIDATES, INLINE_DOC_LIMIT, appOnly;
40865
40993
  var init_codex = __esm({
40866
40994
  "packages/cli/dist/codex.js"() {
40867
40995
  "use strict";
40868
40996
  init_mcp();
40869
40997
  init_stdio2();
40870
40998
  init_server4();
40871
- import_node_child_process3 = require("node:child_process");
40872
40999
  import_node_fs2 = require("node:fs");
40873
41000
  import_promises5 = require("node:fs/promises");
40874
41001
  import_node_os4 = require("node:os");
@@ -40878,6 +41005,7 @@ var init_codex = __esm({
40878
41005
  init_dist();
40879
41006
  init_license();
40880
41007
  init_mcp_files();
41008
+ init_open_browser();
40881
41009
  init_version();
40882
41010
  init_workspace_fs();
40883
41011
  init_server();
@@ -40905,14 +41033,14 @@ function probeCliCommand(cmd, args = ["--version"]) {
40905
41033
  try {
40906
41034
  if (process.platform === "win32" && !cmd.toLowerCase().endsWith(".exe")) {
40907
41035
  const commandLine = `"${[cmd, ...args].map(quoteWinArg).join(" ")}"`;
40908
- const res = (0, import_node_child_process4.spawnSync)("cmd.exe", ["/d", "/s", "/c", commandLine], {
41036
+ const res = (0, import_node_child_process3.spawnSync)("cmd.exe", ["/d", "/s", "/c", commandLine], {
40909
41037
  stdio: "ignore",
40910
41038
  windowsVerbatimArguments: true,
40911
41039
  windowsHide: true
40912
41040
  });
40913
41041
  return res.status === 0;
40914
41042
  }
40915
- return (0, import_node_child_process4.spawnSync)(cmd, args, { stdio: "ignore" }).status === 0;
41043
+ return (0, import_node_child_process3.spawnSync)(cmd, args, { stdio: "ignore" }).status === 0;
40916
41044
  } catch {
40917
41045
  return false;
40918
41046
  }
@@ -40920,7 +41048,7 @@ function probeCliCommand(cmd, args = ["--version"]) {
40920
41048
  function execCliSync(cmd, args, options = {}) {
40921
41049
  if (process.platform === "win32" && !cmd.toLowerCase().endsWith(".exe")) {
40922
41050
  const commandLine = `"${[cmd, ...args].map(quoteWinArg).join(" ")}"`;
40923
- const res = (0, import_node_child_process4.spawnSync)("cmd.exe", ["/d", "/s", "/c", commandLine], {
41051
+ const res = (0, import_node_child_process3.spawnSync)("cmd.exe", ["/d", "/s", "/c", commandLine], {
40924
41052
  ...options,
40925
41053
  encoding: options.encoding ?? "utf8",
40926
41054
  stdio: options.stdio ?? "pipe",
@@ -40934,7 +41062,7 @@ function execCliSync(cmd, args, options = {}) {
40934
41062
  }
40935
41063
  return String(res.stdout ?? "");
40936
41064
  }
40937
- return (0, import_node_child_process4.execFileSync)(cmd, args, options) ?? "";
41065
+ return (0, import_node_child_process3.execFileSync)(cmd, args, options) ?? "";
40938
41066
  }
40939
41067
  function crc32(buf) {
40940
41068
  let c = 4294967295;
@@ -41015,6 +41143,12 @@ function normalizeTarget(raw) {
41015
41143
  return "cursor";
41016
41144
  if (key === "vscode" || key === "code" || key === "vs-code")
41017
41145
  return "vscode";
41146
+ if (key === "trae")
41147
+ return "trae";
41148
+ if (key === "windsurf")
41149
+ return "windsurf";
41150
+ if (key === "vscodium" || key === "codium")
41151
+ return "vscodium";
41018
41152
  if (key === "antigravity" || key === "agy")
41019
41153
  return "antigravity";
41020
41154
  if (key === "codex" || key === "chatgpt")
@@ -41045,8 +41179,9 @@ function getClaudeDesktopDir() {
41045
41179
  function getCursorDir() {
41046
41180
  return process.env.INKMAP_CURSOR_CONFIG_DIR || (0, import_node_path6.join)((0, import_node_os5.homedir)(), ".cursor");
41047
41181
  }
41048
- function getVscodeDir() {
41049
- return process.env.INKMAP_VSCODE_CONFIG_DIR || (0, import_node_path6.join)((0, import_node_os5.homedir)(), ".vscode");
41182
+ function getEditorDir(editor) {
41183
+ const { env, dir } = EXTENSION_EDITORS[editor];
41184
+ return process.env[env] || (0, import_node_path6.join)((0, import_node_os5.homedir)(), dir);
41050
41185
  }
41051
41186
  function getClaudeCodeConfigPath() {
41052
41187
  return process.env.INKMAP_CLAUDE_CODE_CONFIG || (0, import_node_path6.join)((0, import_node_os5.homedir)(), ".claude.json");
@@ -41054,11 +41189,39 @@ function getClaudeCodeConfigPath() {
41054
41189
  function getAntigravityConfigDir() {
41055
41190
  return process.env.ANTIGRAVITY_CONFIG_DIR || (0, import_node_path6.join)((0, import_node_os5.homedir)(), ".gemini", "config");
41056
41191
  }
41192
+ function editorPathMarkers(editor) {
41193
+ if (editor === "cursor")
41194
+ return ["cursor.app", "cursor"];
41195
+ const { macApp, winDir } = EXTENSION_EDITORS[editor];
41196
+ return [macApp.toLowerCase(), winDir.toLowerCase()];
41197
+ }
41198
+ function resolveCommandOnPath(cmd) {
41199
+ const exts = process.platform === "win32" ? ["", ".cmd", ".exe", ".bat"] : [""];
41200
+ for (const dir of (process.env.PATH || "").split(import_node_path6.delimiter).filter(Boolean)) {
41201
+ for (const ext of exts) {
41202
+ const candidate = (0, import_node_path6.join)(dir, cmd + ext);
41203
+ try {
41204
+ if ((0, import_node_fs3.statSync)(candidate).isFile())
41205
+ return (0, import_node_fs3.realpathSync)(candidate);
41206
+ } catch {
41207
+ }
41208
+ }
41209
+ }
41210
+ return null;
41211
+ }
41212
+ function pathCommandBelongsTo(cmd, editor) {
41213
+ if (!probeCliCommand(cmd))
41214
+ return false;
41215
+ const real = resolveCommandOnPath(cmd);
41216
+ if (!real)
41217
+ return true;
41218
+ const segments = real.toLowerCase().split(/[\\/]+/);
41219
+ const others = ["cursor", ...EXTENSION_EDITOR_KEYS].filter((e) => e !== editor);
41220
+ return !others.some((other) => editorPathMarkers(other).some((marker) => segments.includes(marker)));
41221
+ }
41057
41222
  function findCursorCommand() {
41058
41223
  if (process.env.INKMAP_ISOLATED_DETECT)
41059
41224
  return null;
41060
- if (probeCliCommand("cursor"))
41061
- return "cursor";
41062
41225
  if (process.platform === "darwin") {
41063
41226
  for (const dir of ["/Applications", (0, import_node_path6.join)((0, import_node_os5.homedir)(), "Applications")]) {
41064
41227
  const cmd = (0, import_node_path6.join)(dir, "Cursor.app/Contents/Resources/app/bin/cursor");
@@ -41071,26 +41234,32 @@ function findCursorCommand() {
41071
41234
  if ((0, import_node_fs3.existsSync)(cmd))
41072
41235
  return cmd;
41073
41236
  }
41074
- return null;
41237
+ return pathCommandBelongsTo("cursor", "cursor") ? "cursor" : null;
41075
41238
  }
41076
- function findVscodeCommand() {
41239
+ function findEditorCommand(editor) {
41077
41240
  if (process.env.INKMAP_ISOLATED_DETECT)
41078
41241
  return null;
41079
- if (probeCliCommand("code"))
41080
- return "code";
41242
+ const { cli, macApp, winDir } = EXTENSION_EDITORS[editor];
41081
41243
  if (process.platform === "darwin") {
41082
41244
  for (const dir of ["/Applications", (0, import_node_path6.join)((0, import_node_os5.homedir)(), "Applications")]) {
41083
- const cmd = (0, import_node_path6.join)(dir, "Visual Studio Code.app/Contents/Resources/app/bin/code");
41245
+ const cmd = (0, import_node_path6.join)(dir, macApp, "Contents", "Resources", "app", "bin", cli);
41084
41246
  if ((0, import_node_fs3.existsSync)(cmd))
41085
41247
  return cmd;
41086
41248
  }
41087
41249
  } else if (process.platform === "win32") {
41088
41250
  const localApp = process.env.LOCALAPPDATA || (0, import_node_path6.join)((0, import_node_os5.homedir)(), "AppData", "Local");
41089
- const cmd = (0, import_node_path6.join)(localApp, "Programs", "Microsoft VS Code", "bin", "code.cmd");
41251
+ const cmd = (0, import_node_path6.join)(localApp, "Programs", winDir, "bin", `${cli}.cmd`);
41090
41252
  if ((0, import_node_fs3.existsSync)(cmd))
41091
41253
  return cmd;
41092
41254
  }
41093
- return null;
41255
+ return pathCommandBelongsTo(cli, editor) ? cli : null;
41256
+ }
41257
+ function isEditorInstalled(editor) {
41258
+ if (process.env.INKMAP_ISOLATED_DETECT) {
41259
+ const dir = process.env[EXTENSION_EDITORS[editor].env];
41260
+ return Boolean(dir && (0, import_node_fs3.existsSync)(dir));
41261
+ }
41262
+ return (0, import_node_fs3.existsSync)(getEditorDir(editor)) || Boolean(findEditorCommand(editor));
41094
41263
  }
41095
41264
  function findCodexCommand() {
41096
41265
  if (process.env.INKMAP_CODEX_BIN) {
@@ -41145,6 +41314,10 @@ function detectInstalledTargets() {
41145
41314
  if ((0, import_node_fs3.existsSync)(getCursorDir()) || Boolean(findCursorCommand())) {
41146
41315
  found.push("cursor");
41147
41316
  }
41317
+ for (const editor of EXTENSION_EDITOR_KEYS) {
41318
+ if (isEditorInstalled(editor))
41319
+ found.push(editor);
41320
+ }
41148
41321
  const agyDir = getAntigravityConfigDir();
41149
41322
  if ((0, import_node_fs3.existsSync)(agyDir) || !process.env.ANTIGRAVITY_CONFIG_DIR && (0, import_node_fs3.existsSync)((0, import_node_path6.join)((0, import_node_os5.homedir)(), ".gemini", "antigravity"))) {
41150
41323
  found.push("antigravity");
@@ -41178,9 +41351,16 @@ function readJsonObject(filePath) {
41178
41351
  }
41179
41352
  function writeJsonAtomic(filePath, data) {
41180
41353
  (0, import_node_fs3.mkdirSync)((0, import_node_path6.dirname)(filePath), { recursive: true });
41181
- const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
41182
- (0, import_node_fs3.writeFileSync)(tmp, JSON.stringify(data, null, 2) + "\n", "utf8");
41183
- (0, import_node_fs3.renameSync)(tmp, filePath);
41354
+ let target = filePath;
41355
+ let mode = 384;
41356
+ try {
41357
+ target = (0, import_node_fs3.realpathSync)(filePath);
41358
+ mode = (0, import_node_fs3.statSync)(target).mode & 511;
41359
+ } catch {
41360
+ }
41361
+ const tmp = `${target}.${process.pid}.${Date.now()}.tmp`;
41362
+ (0, import_node_fs3.writeFileSync)(tmp, JSON.stringify(data, null, 2) + "\n", { encoding: "utf8", mode });
41363
+ (0, import_node_fs3.renameSync)(tmp, target);
41184
41364
  }
41185
41365
  function stageStandaloneMcpApp() {
41186
41366
  const appDir = (0, import_node_path6.join)(getInkmapHome(), "mcp-app");
@@ -41269,7 +41449,9 @@ function installIdeExtension(editorDir, cliCmd) {
41269
41449
  (0, import_node_fs3.writeFileSync)(vsixPath, buildZipBuffer(entries));
41270
41450
  try {
41271
41451
  execCliSync(cliCmd, ["--install-extension", vsixPath, "--force"], { stdio: "pipe" });
41272
- return (0, import_node_path6.join)(editorDir, "extensions", `inkmap.inkmap-vscode-${version2}`);
41452
+ const installed = (0, import_node_path6.join)(editorDir, "extensions", `inkmap.inkmap-vscode-${version2}`);
41453
+ if ((0, import_node_fs3.existsSync)((0, import_node_path6.join)(installed, "package.json")))
41454
+ return installed;
41273
41455
  } catch {
41274
41456
  }
41275
41457
  }
@@ -41604,10 +41786,9 @@ async function runInstall(options = {}) {
41604
41786
  const log = options.log ?? ((msg) => console.log(msg));
41605
41787
  const workspaces = options.workspaces ?? [];
41606
41788
  const explicitTargets = options.targets && options.targets.length > 0 ? options.targets : null;
41607
- const targets = explicitTargets ?? detectInstalledTargets();
41608
41789
  const result = { installed: [], removed: [] };
41609
41790
  if (options.uninstall) {
41610
- const toRemove = explicitTargets ?? ["claude", "claude-code", "cursor", "vscode", "antigravity", "codex", "deepseek"];
41791
+ const toRemove = explicitTargets ?? ["claude", "claude-code", "cursor", ...EXTENSION_EDITOR_KEYS, "antigravity", "codex", "deepseek"];
41611
41792
  for (const target of toRemove) {
41612
41793
  if (target === "claude") {
41613
41794
  const cfg = (0, import_node_path6.join)(getClaudeDesktopDir(), "claude_desktop_config.json");
@@ -41623,9 +41804,9 @@ async function runInstall(options = {}) {
41623
41804
  const removedExt = uninstallIdeExtension(getCursorDir(), findCursorCommand());
41624
41805
  if (removedMcp || removedExt)
41625
41806
  result.removed.push({ target, location: cfg });
41626
- } else if (target === "vscode") {
41627
- if (uninstallIdeExtension(getVscodeDir(), findVscodeCommand())) {
41628
- result.removed.push({ target, location: (0, import_node_path6.join)(getVscodeDir(), "extensions") });
41807
+ } else if (isExtensionEditor(target)) {
41808
+ if (uninstallIdeExtension(getEditorDir(target), findEditorCommand(target))) {
41809
+ result.removed.push({ target, location: (0, import_node_path6.join)(getEditorDir(target), "extensions") });
41629
41810
  }
41630
41811
  } else if (target === "antigravity") {
41631
41812
  const dir = (0, import_node_path6.join)(getAntigravityConfigDir(), "plugins", "inkmap");
@@ -41680,6 +41861,7 @@ async function runInstall(options = {}) {
41680
41861
  return result;
41681
41862
  }
41682
41863
  const { serverScript, appDir } = stageStandaloneMcpApp();
41864
+ const targets = explicitTargets ?? detectInstalledTargets();
41683
41865
  const zhLocale = isChineseTerminalLocale();
41684
41866
  if (targets.length === 0) {
41685
41867
  log(`[inkmap] \u5DF2\u5C06 MCP App \u6838\u5FC3\u6587\u4EF6\u5C31\u7EEA\u5230: ${appDir}`);
@@ -41687,7 +41869,7 @@ async function runInstall(options = {}) {
41687
41869
  log(" npx -y inkmap-mcp@latest install claude # Claude Desktop (macOS / Windows / Ubuntu)");
41688
41870
  log(" npx -y inkmap-mcp@latest install claude-code # Claude Code CLI");
41689
41871
  log(" npx -y inkmap-mcp@latest install cursor # Cursor (MCP + \u53F3\u4FA7\u539F\u751F\u7F16\u8F91\u5668\u6807\u7B7E)");
41690
- log(" npx -y inkmap-mcp@latest install vscode # VS Code (\u539F\u751F\u7F16\u8F91\u5668\u6269\u5C55)");
41872
+ log(" npx -y inkmap-mcp@latest install vscode # VS Code / trae / windsurf / vscodium (\u539F\u751F\u7F16\u8F91\u5668\u6269\u5C55)");
41691
41873
  log(" npx -y inkmap-mcp@latest install antigravity # Google Antigravity");
41692
41874
  log(" npx -y inkmap-mcp@latest install codex # OpenAI Codex Desktop");
41693
41875
  log(" npx -y inkmap-mcp@latest install deepseek # DeepSeek Harness");
@@ -41726,13 +41908,14 @@ async function runInstall(options = {}) {
41726
41908
  location: extLoc ? `${cfg} + ${extLoc}` : cfg,
41727
41909
  note: zhLocale ? "\u5DF2\u540C\u65F6\u5B89\u88C5 MCP \u670D\u52A1\u4E0E\u53F3\u4FA7\u4E3B\u7F16\u8F91\u533A\u5BFC\u56FE\u6269\u5C55\uFF08Reload Window \u540E\u5BF9\u8BDD\u53EF\u76F4\u63A5\u6253\u5F00\u53F3\u4FA7\u5BFC\u56FE\u6807\u7B7E\uFF09" : "Installed both MCP server and native right-pane mind map extension (Reload Window to activate)"
41728
41910
  });
41729
- } else if (target === "vscode") {
41730
- const extLoc = installIdeExtension(getVscodeDir(), findVscodeCommand());
41911
+ } else if (isExtensionEditor(target)) {
41912
+ const { label } = EXTENSION_EDITORS[target];
41913
+ const extLoc = installIdeExtension(getEditorDir(target), findEditorCommand(target));
41731
41914
  if (extLoc) {
41732
41915
  result.installed.push({
41733
41916
  target,
41734
41917
  location: extLoc,
41735
- note: zhLocale ? "\u5DF2\u5728 VS Code \u5B89\u88C5\u539F\u751F Inkmap \u601D\u7EF4\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55" : "Installed native Inkmap mind map editor extension in VS Code"
41918
+ note: zhLocale ? `\u5DF2\u5728 ${label} \u5B89\u88C5\u539F\u751F Inkmap \u601D\u7EF4\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55\uFF08Reload Window \u540E\u751F\u6548\uFF09` : `Installed native Inkmap mind map editor extension in ${label} (Reload Window to activate)`
41736
41919
  });
41737
41920
  }
41738
41921
  } else if (target === "antigravity") {
@@ -41805,7 +41988,7 @@ async function runInstall(options = {}) {
41805
41988
  log(" Qoder, WorkBuddy, Claude Desktop, Claude Code, OpenAI Codex, Google Antigravity & Trae!");
41806
41989
  log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
41807
41990
  }
41808
- if (!options.uninstall && result.installed.length > 0) {
41991
+ if (result.installed.length > 0) {
41809
41992
  try {
41810
41993
  const { fileSessionStorage: fileSessionStorage2, licenseService: licenseService2 } = await Promise.resolve().then(() => (init_license(), license_exports));
41811
41994
  const { YUNFAN_BILLING_ORIGIN: YUNFAN_BILLING_ORIGIN2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
@@ -41835,6 +42018,9 @@ async function runInstallCli(argv, uninstall = false) {
41835
42018
  claude-code Claude Code CLI (~/.claude.json)
41836
42019
  cursor Cursor (MCP + \u53F3\u4FA7\u4E3B\u7F16\u8F91\u533A\u539F\u751F\u5BFC\u56FE\u6269\u5C55)
41837
42020
  vscode VS Code (\u539F\u751F\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55)
42021
+ trae Trae (\u539F\u751F\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55)
42022
+ windsurf Windsurf (\u539F\u751F\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55)
42023
+ vscodium VSCodium (\u539F\u751F\u5BFC\u56FE\u7F16\u8F91\u5668\u6269\u5C55)
41838
42024
  antigravity Google Antigravity (~/.gemini/config/plugins/inkmap)
41839
42025
  codex OpenAI Codex Desktop
41840
42026
  deepseek DeepSeek Harness (~/.dsh/profiles/desktop)
@@ -41857,7 +42043,7 @@ async function runInstallCli(argv, uninstall = false) {
41857
42043
  }
41858
42044
  const normalized = normalizeTarget(arg);
41859
42045
  if (!normalized) {
41860
- throw new Error(`\u672A\u77E5\u5BA2\u6237\u7AEF\u76EE\u6807: ${arg}\uFF08\u652F\u6301: claude, claude-code, cursor, vscode, antigravity, codex, deepseek, all\uFF09`);
42046
+ throw new Error(`\u672A\u77E5\u5BA2\u6237\u7AEF\u76EE\u6807: ${arg}\uFF08\u652F\u6301: claude, claude-code, cursor, vscode, trae, windsurf, vscodium, antigravity, codex, deepseek, all\uFF09`);
41861
42047
  }
41862
42048
  if (normalized === "all") {
41863
42049
  explicitAll = true;
@@ -41871,17 +42057,25 @@ async function runInstallCli(argv, uninstall = false) {
41871
42057
  uninstall
41872
42058
  });
41873
42059
  }
41874
- var import_node_child_process4, import_node_fs3, import_node_os5, import_node_path6, import_node_url4, import_node_zlib, DIST_DIR, PKG_ROOT, SERVER_WRAPPER, CRC_TABLE;
42060
+ var import_node_child_process3, import_node_fs3, import_node_os5, import_node_path6, import_node_url4, import_node_zlib, EXTENSION_EDITORS, EXTENSION_EDITOR_KEYS, isExtensionEditor, DIST_DIR, PKG_ROOT, SERVER_WRAPPER, CRC_TABLE;
41875
42061
  var init_install = __esm({
41876
42062
  "packages/cli/dist/install.js"() {
41877
42063
  "use strict";
41878
- import_node_child_process4 = require("node:child_process");
42064
+ import_node_child_process3 = require("node:child_process");
41879
42065
  import_node_fs3 = require("node:fs");
41880
42066
  import_node_os5 = require("node:os");
41881
42067
  import_node_path6 = require("node:path");
41882
42068
  import_node_url4 = require("node:url");
41883
42069
  import_node_zlib = require("node:zlib");
41884
42070
  init_license();
42071
+ EXTENSION_EDITORS = {
42072
+ vscode: { label: "VS Code", dir: ".vscode", env: "INKMAP_VSCODE_CONFIG_DIR", cli: "code", macApp: "Visual Studio Code.app", winDir: "Microsoft VS Code" },
42073
+ trae: { label: "Trae", dir: ".trae", env: "INKMAP_TRAE_CONFIG_DIR", cli: "trae", macApp: "Trae.app", winDir: "Trae" },
42074
+ windsurf: { label: "Windsurf", dir: ".windsurf", env: "INKMAP_WINDSURF_CONFIG_DIR", cli: "windsurf", macApp: "Windsurf.app", winDir: "Windsurf" },
42075
+ vscodium: { label: "VSCodium", dir: ".vscode-oss", env: "INKMAP_VSCODIUM_CONFIG_DIR", cli: "codium", macApp: "VSCodium.app", winDir: "VSCodium" }
42076
+ };
42077
+ EXTENSION_EDITOR_KEYS = Object.keys(EXTENSION_EDITORS);
42078
+ isExtensionEditor = (target) => target in EXTENSION_EDITORS;
41885
42079
  DIST_DIR = (0, import_node_path6.dirname)((0, import_node_url4.fileURLToPath)(inkmapModuleUrl));
41886
42080
  PKG_ROOT = (0, import_node_path6.resolve)(DIST_DIR, "..");
41887
42081
  SERVER_WRAPPER = `#!/usr/bin/env node
@@ -41911,11 +42105,11 @@ __export(index_exports, {
41911
42105
  main: () => main
41912
42106
  });
41913
42107
  module.exports = __toCommonJS(index_exports);
41914
- var import_node_child_process5 = require("node:child_process");
41915
42108
  var import_node_path7 = require("node:path");
41916
42109
  var import_node_url5 = require("node:url");
41917
42110
  init_dist();
41918
42111
  init_license();
42112
+ init_open_browser();
41919
42113
  init_server();
41920
42114
  init_version();
41921
42115
  var WEB_ROOT = (0, import_node_url5.fileURLToPath)(new URL("./web/", inkmapModuleUrl));
@@ -41930,13 +42124,6 @@ var USAGE = `Inkmap v${INKMAP_VERSION} \u2014 Markdown \u4EA4\u4E92\u601D\u7EF4\
41930
42124
  \u4EE5\u6807\u51C6 MCP App (stdio) \u6A21\u5F0F\u542F\u52A8\u670D\u52A1
41931
42125
  npx -y inkmap-mcp@latest <\u6587\u4EF6.md> [--port \u7AEF\u53E3] [--no-open] [--sidebar [--sidebar-purchase]]
41932
42126
  \u5728\u672C\u5730\u6D4F\u89C8\u5668\u4E2D\u4EE5\u601D\u7EF4\u5BFC\u56FE\u6253\u5F00\u5E76\u5B9E\u65F6\u53CC\u5411\u7F16\u8F91 Markdown \u6587\u4EF6`;
41933
- function openBrowser(url2) {
41934
- const [cmd, args] = process.platform === "darwin" ? ["open", [url2]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url2]] : ["xdg-open", [url2]];
41935
- const child = (0, import_node_child_process5.spawn)(cmd, args, { stdio: "ignore", detached: true });
41936
- child.on("error", () => {
41937
- });
41938
- child.unref();
41939
- }
41940
42127
  function appendEnvWorkspaces(dirs) {
41941
42128
  if (dirs.length === 0)
41942
42129
  return;
@@ -42031,7 +42218,7 @@ ${USAGE}`);
42031
42218
  console.log(`[inkmap] \u6B63\u5728\u7F16\u8F91 ${file2}`);
42032
42219
  console.log(`[inkmap] ${served.url} \uFF08Ctrl+C \u9000\u51FA\uFF09`);
42033
42220
  if (open2 && !sidebar)
42034
- openBrowser(served.url);
42221
+ openSystemBrowser(served.url);
42035
42222
  const stop = () => {
42036
42223
  license.dispose();
42037
42224
  return served.close().then(() => process.exit(0));