inkmap-mcp 0.3.16 → 0.3.17

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.
@@ -95,7 +95,6 @@ var import_node_child_process3 = require("node:child_process");
95
95
  var vscode2 = __toESM(require("vscode"));
96
96
 
97
97
  // packages/cli/src/server.ts
98
- var import_node_child_process2 = require("node:child_process");
99
98
  var import_node_crypto2 = require("node:crypto");
100
99
  var import_node_fs = require("node:fs");
101
100
  var import_promises3 = require("node:fs/promises");
@@ -111,7 +110,7 @@ var import_node_os = require("node:os");
111
110
  var import_node_path = require("node:path");
112
111
 
113
112
  // packages/cli/src/version.ts
114
- var INKMAP_VERSION = "0.3.16";
113
+ var INKMAP_VERSION = "0.3.17";
115
114
 
116
115
  // packages/cli/src/license.ts
117
116
  var ZH_LOCALE_RE = /^zh(?:[-_.]|$)/i;
@@ -122,6 +121,8 @@ var WAIT_SLOW_MS = 3e4;
122
121
  var WAIT_FAST_FOR_MS = 30 * 6e4;
123
122
  var WAIT_MAX_MS = 3 * 24 * 60 * 6e4;
124
123
  var MAX_WAITING = 5;
124
+ var OFFLINE_PRO_GRACE_MS = 7 * 24 * 60 * 6e4;
125
+ var PRO_RECHECK_STAMP_MS = 12 * 60 * 6e4;
125
126
  function isWaitingToken(value) {
126
127
  const w = value;
127
128
  return Boolean(w) && typeof w.origin === "string" && typeof w.token === "string" && /^[A-Za-z0-9_-]{43}$/.test(w.token) && typeof w.email === "string" && typeof w.since === "number" && typeof w.fastUntil === "number";
@@ -199,6 +200,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
199
200
  let detectedHost = defaultHost;
200
201
  const pendingEvents = /* @__PURE__ */ new Map();
201
202
  let lastCheck = 0;
203
+ let retryAfter = 0;
202
204
  let fastPollUntil = 0;
203
205
  const expectPurchase = () => void (fastPollUntil = Date.now() + 15 * 6e4);
204
206
  let flowCreation;
@@ -389,12 +391,29 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
389
391
  timer = setTimeout(() => void refresh(), delay);
390
392
  timer.unref();
391
393
  }
394
+ async function rememberProCheck(token, active, account) {
395
+ await writeSession(async () => {
396
+ let record;
397
+ try {
398
+ record = JSON.parse(await storage.read() || "{}");
399
+ } catch {
400
+ return;
401
+ }
402
+ if (record.token !== token) return;
403
+ const at = typeof record.proVerifiedAt === "number" ? record.proVerifiedAt : void 0;
404
+ if (active ? at !== void 0 && Date.now() - at < PRO_RECHECK_STAMP_MS && at <= Date.now() : at === void 0) return;
405
+ const { proVerifiedAt: _at, proAccount: _account, ...rest } = record;
406
+ await storage.write(JSON.stringify(active ? { ...rest, proVerifiedAt: Date.now(), ...account && { proAccount: account } } : rest));
407
+ }).catch(() => {
408
+ });
409
+ }
392
410
  function refresh() {
393
411
  if (connection) return connection;
394
412
  const version = generation;
395
413
  connection = (async () => {
396
414
  let token;
397
415
  let delay = 6e4;
416
+ let offlinePro;
398
417
  try {
399
418
  const origin = billingOrigin(getOrigin());
400
419
  if (origin !== activeOrigin) {
@@ -408,6 +427,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
408
427
  const record = JSON.parse(stored);
409
428
  if (record.origin !== origin || typeof record.token !== "string") return update(false);
410
429
  token = record.token;
430
+ const verifiedAt = record.proVerifiedAt;
431
+ if (typeof verifiedAt === "number" && verifiedAt <= Date.now() && Date.now() - verifiedAt < OFFLINE_PRO_GRACE_MS) {
432
+ offlinePro = { ...typeof record.proAccount === "string" && { account: record.proAccount.slice(0, 64) } };
433
+ }
411
434
  const response = await entitlement(origin, record.token);
412
435
  if (version !== generation || disposed) return;
413
436
  if (response.status === 401) {
@@ -423,9 +446,12 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
423
446
  const state = await response.json();
424
447
  if (version !== generation || disposed) return;
425
448
  applyEntitlement(state);
426
- delay = state.active !== true && state.pending === true ? 2500 : 6e4;
449
+ void rememberProCheck(record.token, current.pro, current.account);
450
+ delay = state.active !== true && (state.pending === true || Date.now() < fastPollUntil) ? 2500 : 6e4;
427
451
  } catch {
428
- if (version === generation && Date.now() - lastCheck > 15 * 6e4) update(false);
452
+ if (version === generation) retryAfter = Date.now() + (Date.now() < fastPollUntil ? 2e3 : 3e4);
453
+ if (version === generation && offlinePro) update(true, true, offlinePro.account);
454
+ else if (version === generation && Date.now() - lastCheck > 15 * 6e4) update(false);
429
455
  } finally {
430
456
  if (version === generation && token) schedule(delay);
431
457
  }
@@ -459,7 +485,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
459
485
  function scheduleWait(delay) {
460
486
  clearTimeout(waitTimer);
461
487
  if (disposed || !waiting.length) return;
462
- waitTimer = setTimeout(() => void checkWaiting(), delay);
488
+ waitTimer = setTimeout(() => void checkWaiting().catch(() => scheduleWait(WAIT_SLOW_MS)), delay);
463
489
  waitTimer.unref();
464
490
  }
465
491
  async function checkWaiting() {
@@ -493,8 +519,9 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
493
519
  if (disposed || round !== waitRound) return;
494
520
  await writeSession(async () => {
495
521
  if (disposed || round !== waitRound || w.origin !== billingOrigin(getOrigin())) return;
496
- clearWaiting();
522
+ if (w.email) lastSignIn = w.email.trim().slice(0, 254);
497
523
  await storage.write(sessionRecord({ origin: w.origin, token: w.token }));
524
+ clearWaiting();
498
525
  ++generation;
499
526
  activeOrigin = w.origin;
500
527
  applyEntitlement(body);
@@ -526,6 +553,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
526
553
  } catch {
527
554
  }
528
555
  if (typeof record.token !== "string" || typeof record.origin !== "string") return;
556
+ if (typeof record.checkoutUrl === "string") return;
529
557
  const response = await entitlement(record.origin, record.token).catch(() => null);
530
558
  if (!response?.ok) return;
531
559
  const latest = await response.json().catch(() => null);
@@ -555,12 +583,20 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
555
583
  return;
556
584
  }
557
585
  if (process.env.INKMAP_ALLOW_TEST_TELEMETRY !== "1") {
558
- if (origin === "https://billing.example.com" || process.env.INKMAP_DISABLE_TELEMETRY === "1" || process.env.NODE_TEST_CONTEXT) return;
559
- const customHome = process.env.INKMAP_HOME || "";
560
- const sysTmp = (0, import_node_os.tmpdir)();
561
- 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-"))) {
586
+ 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") {
562
587
  return;
563
588
  }
589
+ const norm = (p) => {
590
+ const clean = p.replace(/\\/g, "/");
591
+ return process.platform === "win32" ? clean.toLowerCase() : clean;
592
+ };
593
+ const sysTmp = norm((0, import_node_os.tmpdir)()).replace(/\/+$/, "");
594
+ const homesToCheck = [process.env.INKMAP_HOME || "", (0, import_node_os.homedir)()].filter(Boolean).map(norm);
595
+ for (const h of homesToCheck) {
596
+ if (h === sysTmp || h.startsWith(sysTmp + "/") || h.startsWith("/tmp/") || h.startsWith("/private/tmp/") || h.includes("/var/folders/") || h.includes("/appdata/local/temp/") || h.includes("/temp/inkmap") || h.includes("inkmap-npm-isolated-") || h.includes("inkmap-antigravity-mcp-") || h.includes("inkmap-local-editor-") || h.includes("inkmap-harness-") || h.includes("inkmap-test-")) {
597
+ return;
598
+ }
599
+ }
564
600
  }
565
601
  const id = await (installIdPromise ??= localInstallId().catch(() => void 0));
566
602
  if (disposed || !id || !pendingEvents.size) return;
@@ -592,8 +628,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
592
628
  return {
593
629
  async state() {
594
630
  await (trial ??= startTrial());
595
- const interval = !current.pro && Date.now() < fastPollUntil ? 4e3 : 6e4;
596
- if (Date.now() - lastCheck >= interval) await refresh();
631
+ const interval = !current.pro && Date.now() < fastPollUntil ? 2e3 : 6e4;
632
+ if (Date.now() - lastCheck >= interval && Date.now() >= retryAfter) await refresh();
597
633
  await parkUnpaidSession();
598
634
  return current;
599
635
  },
@@ -656,7 +692,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
656
692
  if (cachedOrder && cachedOrder.origin === origin && cachedOrder.locale === loc && Date.now() - cachedOrder.at < 8e3) {
657
693
  const hit = cachedOrder.result;
658
694
  cachedOrder = void 0;
659
- schedule(hit.status === "qr" || hit.status === "redirect" ? 4e3 : 6e4);
695
+ if (current.pro) return { status: "active", state: current };
696
+ schedule(hit.status === "qr" || hit.status === "redirect" ? 2500 : 6e4);
660
697
  return hit;
661
698
  }
662
699
  const version = generation;
@@ -666,6 +703,17 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
666
703
  if (stored) record = JSON.parse(stored);
667
704
  } catch {
668
705
  }
706
+ if (record?.origin === origin && typeof record.token === "string") {
707
+ const rights = await entitlement(origin, record.token).catch(() => null);
708
+ if (rights?.ok) {
709
+ const ent = await rights.json().catch(() => null);
710
+ if (ent && ent.active === true) {
711
+ applyEntitlement(ent);
712
+ schedule(6e4);
713
+ return { status: "active", state: current };
714
+ }
715
+ }
716
+ }
669
717
  const requestOrder = async (checkoutUrl, token, cookie, persist) => {
670
718
  const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, localeHint);
671
719
  if (res.status === 401 || res.status === 403 || res.status === 404 || res.status === 410) return null;
@@ -844,12 +892,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
844
892
  return await writeSession(async () => {
845
893
  if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) return phoneFailure();
846
894
  clearWaiting();
895
+ const clean = phone.trim().slice(0, 254);
896
+ if (clean) lastSignIn = clean;
847
897
  await storage.write(sessionRecord({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
848
898
  ++generation;
849
899
  activeOrigin = origin;
850
900
  applyEntitlement(state);
851
901
  if (cachedOrder?.result.status === "active") cachedOrder.result.state = current;
852
- schedule(cachedOrder?.result.status === "qr" ? 4e3 : 6e4);
902
+ schedule(cachedOrder?.result.status === "qr" || cachedOrder?.result.status === "redirect" ? 2500 : 6e4);
853
903
  return { ok: true, value: current };
854
904
  });
855
905
  } catch {
@@ -972,6 +1022,33 @@ async function localTrialDeadline() {
972
1022
  return Number.isSafeInteger(started) && started > 0 && started <= Date.now() ? started + TRIAL_MS : void 0;
973
1023
  }
974
1024
 
1025
+ // packages/cli/src/open-browser.ts
1026
+ var import_node_child_process2 = require("node:child_process");
1027
+ function run(cmd, args, launched = false) {
1028
+ return new Promise((done) => {
1029
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1030
+ child.on("error", () => done(false));
1031
+ if (launched) child.on("spawn", () => done(true));
1032
+ else child.on("exit", (code) => done(code === 0));
1033
+ child.unref();
1034
+ });
1035
+ }
1036
+ async function openBrowserWindow(url) {
1037
+ if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url)) return;
1038
+ if (process.platform === "darwin") {
1039
+ if (await run("open", ["-a", "Google Chrome", url])) return;
1040
+ await run("open", [url]);
1041
+ return;
1042
+ }
1043
+ if (process.platform === "win32") {
1044
+ if (await run("cmd", ["/c", "start", "", "chrome", url])) return;
1045
+ await run("cmd", ["/c", "start", "", url]);
1046
+ return;
1047
+ }
1048
+ if (await run("google-chrome", [url], true)) return;
1049
+ await run("xdg-open", [url], true);
1050
+ }
1051
+
975
1052
  // packages/cli/src/workspace-fs.ts
976
1053
  var import_promises2 = require("node:fs/promises");
977
1054
  var import_node_os2 = require("node:os");
@@ -1130,12 +1207,17 @@ async function fileSource(file, log = () => {
1130
1207
  log(`\u5DF2\u5199\u56DE ${path2}`);
1131
1208
  },
1132
1209
  watch(onChange) {
1133
- const watcher = (0, import_node_fs.watch)(dir, (_, changed) => {
1134
- if (!changed || changed === (0, import_node_path3.basename)(path2)) onChange();
1135
- });
1136
- watcher.on("error", () => {
1137
- });
1138
- return () => watcher.close();
1210
+ try {
1211
+ const watcher = (0, import_node_fs.watch)(dir, (_, changed) => {
1212
+ if (!changed || changed === (0, import_node_path3.basename)(path2)) onChange();
1213
+ });
1214
+ watcher.on("error", () => {
1215
+ });
1216
+ return () => watcher.close();
1217
+ } catch {
1218
+ return () => {
1219
+ };
1220
+ }
1139
1221
  },
1140
1222
  readView: () => readDiskViewState(path2),
1141
1223
  writeView: (state) => writeDiskViewState(path2, state)
@@ -1153,27 +1235,6 @@ function within(root, rel, allowAbsoluteInRoot = false) {
1153
1235
  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));
1154
1236
  return full.startsWith(base) ? full : null;
1155
1237
  }
1156
- async function openBrowserWindow(url) {
1157
- if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url)) return;
1158
- const run = (cmd, args) => new Promise((done) => {
1159
- const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1160
- child.on("error", () => done(false));
1161
- child.on("exit", (code) => done(code === 0));
1162
- child.unref();
1163
- });
1164
- if (process.platform === "darwin") {
1165
- if (await run("open", ["-a", "Google Chrome", url])) return;
1166
- await run("open", [url]);
1167
- return;
1168
- }
1169
- if (process.platform === "win32") {
1170
- if (await run("cmd", ["/c", "start", "", "chrome", url])) return;
1171
- await run("cmd", ["/c", "start", "", url]);
1172
- return;
1173
- }
1174
- if (await run("google-chrome", [url])) return;
1175
- await run("xdg-open", [url]);
1176
- }
1177
1238
  async function serve({
1178
1239
  source: initialSource,
1179
1240
  webRoot,
@@ -1185,7 +1246,6 @@ async function serve({
1185
1246
  sidebar = false,
1186
1247
  sidebarPurchase = false,
1187
1248
  sidebarAccountNavigation = false,
1188
- ideWorkspace = false,
1189
1249
  workspaceRoots = [],
1190
1250
  confineToWorkspaceRoots = false,
1191
1251
  openSource = (path2) => fileSource(path2, log),
@@ -1401,7 +1461,6 @@ data: ${JSON.stringify(data)}
1401
1461
  if (url.pathname === "/api/capabilities" && req.method === "GET") {
1402
1462
  return json(res, 200, {
1403
1463
  purchase: canPurchase,
1404
- ...ideWorkspace && { ideWorkspace: true },
1405
1464
  ...sidebarAccountNavigation && { accountNavigation: "host" }
1406
1465
  });
1407
1466
  }
@@ -1419,6 +1478,7 @@ data: ${JSON.stringify(data)}
1419
1478
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1420
1479
  const { md, baseVersion } = JSON.parse(await readBody(req));
1421
1480
  if (typeof md !== "string") return json(res, 400, { error: zh2() ? "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002" : "md must be a string." });
1481
+ if (Buffer.byteLength(md) > MAX_MARKDOWN_BYTES) return json(res, 413, { error: zh2() ? "\u6587\u6863\u8FC7\u5927\u3002" : "Document too large." });
1422
1482
  if (!hasAccess(await license?.state() ?? { pro: false })) return json(res, 403, { error: "Inkmap trial expired" });
1423
1483
  return await serialized(async () => {
1424
1484
  await refresh();
@@ -1445,7 +1505,7 @@ data: ${JSON.stringify(data)}
1445
1505
  if (url.pathname === "/api/telemetry" && req.method === "POST") {
1446
1506
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1447
1507
  const { event } = JSON.parse(await readBody(req));
1448
- if (typeof event === "string" && event) license?.track?.(event);
1508
+ if (typeof event === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(event)) license?.track?.(event);
1449
1509
  return json(res, 200, { ok: true });
1450
1510
  }
1451
1511
  if (url.pathname === "/api/open-browser" && req.method === "POST") {
@@ -1713,7 +1773,11 @@ var zh = {
1713
1773
  harnessConfigured: "\u5DF2\u5728 DeepSeek Harness \u4E2D\u52A0\u5165 Inkmap \u63D2\u4EF6\u7D22\u5F15\uFF1B\u672A\u627E\u5230 dsh \u547D\u4EE4\uFF0C\u8BF7\u5728 DeepSeek Harness \u7684\u300C\u63D2\u4EF6\u300D\u9875\u5B89\u88C5 Inkmap\u3002",
1714
1774
  harnessAlready: "DeepSeek Harness \u4E2D\u5DF2\u5B89\u88C5 Inkmap\u3002",
1715
1775
  harnessNotFound: "\u672A\u627E\u5230 DeepSeek Harness \u684C\u9762\u7248\u3002",
1716
- harnessFailed: "\u5B89\u88C5\u5230 DeepSeek Harness \u5931\u8D25\uFF1A{error}"
1776
+ harnessFailed: "\u5B89\u88C5\u5230 DeepSeek Harness \u5931\u8D25\uFF1A{error}",
1777
+ reviewTip: "\u559C\u6B22\u7528 Inkmap \u68B3\u7406 Markdown \u5417\uFF1F\u82B1 10 \u79D2\u7ED9\u4E2A\u4E94\u661F\u8BC4\u4EF7\u6216 GitHub Star\uFF0C\u80FD\u5E2E\u66F4\u591A\u5F00\u53D1\u8005\u770B\u5230\u5B83 \u2764\uFE0F",
1778
+ reviewRate: "\u53BB\u5546\u5E97\u7ED9\u597D\u8BC4",
1779
+ reviewStar: "GitHub \u70B9 Star",
1780
+ reviewLater: "\u4EE5\u540E\u518D\u8BF4"
1717
1781
  };
1718
1782
  var en = {
1719
1783
  openMarkdownFirst: "Open a Markdown file first",
@@ -1759,7 +1823,11 @@ var en = {
1759
1823
  harnessConfigured: "The Inkmap plugin index was added to DeepSeek Harness, but the dsh command was not found. Install Inkmap from the Plugins page in DeepSeek Harness.",
1760
1824
  harnessAlready: "Inkmap is already installed in DeepSeek Harness.",
1761
1825
  harnessNotFound: "DeepSeek Harness desktop was not found.",
1762
- harnessFailed: "Could not install Inkmap in DeepSeek Harness: {error}"
1826
+ harnessFailed: "Could not install Inkmap in DeepSeek Harness: {error}",
1827
+ reviewTip: "Enjoying Inkmap for your Markdown docs? A quick 5-star review or GitHub Star helps more developers discover it \u2764\uFE0F",
1828
+ reviewRate: "Rate Extension",
1829
+ reviewStar: "Star on GitHub",
1830
+ reviewLater: "Maybe later"
1763
1831
  };
1764
1832
  var isChinese = () => detectOsLocale() === "zh";
1765
1833
  function t(key, vars = {}) {
@@ -1842,7 +1910,8 @@ async function openUrl(url) {
1842
1910
  const ok = await new Promise((done) => {
1843
1911
  const child = (0, import_node_child_process3.spawn)(cmd, args, { stdio: "ignore", detached: true });
1844
1912
  child.on("error", () => done(false));
1845
- child.on("exit", (code) => done(code === 0));
1913
+ if (cmd === "google-chrome") child.on("spawn", () => done(true));
1914
+ else child.on("exit", (code) => done(code === 0));
1846
1915
  child.unref();
1847
1916
  });
1848
1917
  if (!ok) await fallback();
@@ -1892,6 +1961,7 @@ function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
1892
1961
  // packages/vscode/src/mindmapEditor.ts
1893
1962
  var VIEW_STATE_PREFIX2 = "inkmap.viewState:";
1894
1963
  var CHANGE_DELAY = 120;
1964
+ var DIAGRAM_CHANGE_DELAY = 700;
1895
1965
  var REVEAL_DELAY = 150;
1896
1966
  var MindmapEditorProvider = class {
1897
1967
  constructor(context, license) {
@@ -1928,8 +1998,6 @@ var MindmapEditorProvider = class {
1928
1998
  }
1929
1999
  async resolveCustomTextEditor(document, panel) {
1930
2000
  const webview = panel.webview;
1931
- this.panels.add(panel);
1932
- this.panelDocuments.set(panel, document.uri.toString());
1933
2001
  const webRoot = vscode4.Uri.joinPath(this.context.extensionUri, "dist", "web");
1934
2002
  const assets = docDir(document.uri);
1935
2003
  webview.options = {
@@ -1937,6 +2005,8 @@ var MindmapEditorProvider = class {
1937
2005
  localResourceRoots: [webRoot, ...assets ? [assets] : [], ...(vscode4.workspace.workspaceFolders ?? []).map((f) => f.uri)]
1938
2006
  };
1939
2007
  webview.html = await editorHtml(webview, webRoot, assets);
2008
+ this.panels.add(panel);
2009
+ this.panelDocuments.set(panel, document.uri.toString());
1940
2010
  const viewKey = VIEW_STATE_PREFIX2 + document.uri.toString();
1941
2011
  const state = () => {
1942
2012
  const viewState = document.uri.scheme === "untitled" ? void 0 : sanitizeViewState(this.context.workspaceState.get(viewKey));
@@ -1970,7 +2040,10 @@ var MindmapEditorProvider = class {
1970
2040
  vscode4.workspace.onDidChangeTextDocument((e) => {
1971
2041
  if (applying || e.document !== document || !e.contentChanges.length) return;
1972
2042
  clearTimeout(changeTimer);
1973
- changeTimer = setTimeout(() => post({ type: "change", doc: state() }), CHANGE_DELAY);
2043
+ const before = document.getText(new vscode4.Range(new vscode4.Position(0, 0), e.contentChanges[0].range.start));
2044
+ const fences = before.match(/^\s*(?:`{3,}|~{3,}).*$/gm) ?? [];
2045
+ const inDiagram = fences.length % 2 === 1 && /mermaid/i.test(fences[fences.length - 1]);
2046
+ changeTimer = setTimeout(() => post({ type: "change", doc: state() }), inDiagram ? DIAGRAM_CHANGE_DELAY : CHANGE_DELAY);
1974
2047
  }),
1975
2048
  vscode4.window.onDidChangeTextEditorSelection((e) => {
1976
2049
  if (e.textEditor.document !== document) return;
@@ -1982,7 +2055,7 @@ var MindmapEditorProvider = class {
1982
2055
  }),
1983
2056
  webview.onDidReceiveMessage(async (msg) => {
1984
2057
  if (msg.type === "mapMarkdownChange") return;
1985
- const accountAction = msg.type === "checkout" || msg.type === "orderPro" || msg.type === "openExternal" || msg.type === "signOut" || msg.type === "sendPhoneCode" || msg.type === "signInByPhone" || msg.type === "openInBrowser" || msg.type === "telemetry";
2058
+ const accountAction = msg.type === "checkout" || msg.type === "orderPro" || msg.type === "openExternal" || msg.type === "signOut" || msg.type === "sendPhoneCode" || msg.type === "signInByPhone" || msg.type === "openInBrowser" || msg.type === "checkLicense" || msg.type === "telemetry";
1986
2059
  if (!accountAction && msg.type !== "ready" && msg.type !== "viewState" && msg.type !== "select" && !hasAccess(await this.license.state())) {
1987
2060
  if ("id" in msg) return post({ type: "error", id: msg.id, message: t("trialExpired") });
1988
2061
  return;
@@ -1991,6 +2064,8 @@ var MindmapEditorProvider = class {
1991
2064
  case "ready": {
1992
2065
  this.readyPanels.add(panel);
1993
2066
  void this.context.globalState?.update("inkmap.hasOpenedMap", true);
2067
+ const opens = (this.context.globalState?.get("inkmap.docOpenCount") ?? 0) + 1;
2068
+ void this.context.globalState?.update("inkmap.docOpenCount", opens);
1994
2069
  this.license.track?.("doc_open");
1995
2070
  const [license, chat] = await Promise.all([this.license.state(), chatAvailable()]);
1996
2071
  await post({ type: "doc", doc: state(), license, chat });
@@ -2003,6 +2078,11 @@ var MindmapEditorProvider = class {
2003
2078
  }
2004
2079
  case "openInBrowser":
2005
2080
  return vscode4.commands.executeCommand("inkmap.openInBrowser", document.uri);
2081
+ case "checkLicense": {
2082
+ const latest = await this.license.state();
2083
+ await post({ type: "license", state: latest });
2084
+ return;
2085
+ }
2006
2086
  case "telemetry": {
2007
2087
  this.license.track?.(msg.event);
2008
2088
  return;
@@ -2023,6 +2103,9 @@ var MindmapEditorProvider = class {
2023
2103
  applying = false;
2024
2104
  }
2025
2105
  this.license.track?.("doc_edit");
2106
+ const edits = (this.context.globalState?.get("inkmap.docEditCount") ?? 0) + 1;
2107
+ void this.context.globalState?.update("inkmap.docEditCount", edits);
2108
+ this.maybeOfferReview(edits);
2026
2109
  return post({ type: "saved", id: msg.id, version: String(document.version) });
2027
2110
  }
2028
2111
  case "undo":
@@ -2075,15 +2158,26 @@ var MindmapEditorProvider = class {
2075
2158
  void vscode4.env.openExternal(vscode4.Uri.parse(msg.url));
2076
2159
  }
2077
2160
  return;
2161
+ // The webview waits for an answer to each of these without a timeout, so a failure must be reported.
2078
2162
  case "signOut":
2079
- await this.license.deactivate();
2080
- return post({ type: "signedOut", id: msg.id });
2081
2163
  case "sendPhoneCode":
2082
- return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
2083
2164
  case "signInByPhone":
2084
- return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code, msg.locale) });
2085
2165
  case "saveFile":
2086
- return post({ type: "fileSaved", id: msg.id, saved: await saveDataUrl(msg.name, msg.dataUrl, assets) });
2166
+ try {
2167
+ if (msg.type === "signOut") {
2168
+ await this.license.deactivate();
2169
+ return post({ type: "signedOut", id: msg.id });
2170
+ }
2171
+ if (msg.type === "sendPhoneCode") {
2172
+ return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
2173
+ }
2174
+ if (msg.type === "signInByPhone") {
2175
+ return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code, msg.locale) });
2176
+ }
2177
+ return post({ type: "fileSaved", id: msg.id, saved: await saveDataUrl(msg.name, msg.dataUrl, assets) });
2178
+ } catch (error) {
2179
+ return post({ type: "error", id: msg.id, message: error instanceof Error ? error.message : String(error) });
2180
+ }
2087
2181
  }
2088
2182
  })
2089
2183
  );
@@ -2094,6 +2188,22 @@ var MindmapEditorProvider = class {
2094
2188
  disposables.forEach((d) => d.dispose());
2095
2189
  });
2096
2190
  }
2191
+ maybeOfferReview(edits) {
2192
+ const state = this.context.globalState;
2193
+ if (!state || state.get("inkmap.reviewPrompted")) return;
2194
+ const opens = state.get("inkmap.docOpenCount") ?? 0;
2195
+ if (opens < 5 || edits < 3) return;
2196
+ void state.update("inkmap.reviewPrompted", true);
2197
+ const app = (vscode4.env.appName || "").toLowerCase();
2198
+ const openVsxFork = /(cursor|windsurf|trae|qoder|antigravity|codium|positron)/.test(app);
2199
+ const storeUrl = openVsxFork ? "https://open-vsx.org/extension/inkmap/inkmap-vscode/reviews" : "https://marketplace.visualstudio.com/items?itemName=inkmap.inkmap-vscode&ssr=false#review-details";
2200
+ const rateLabel = t("reviewRate");
2201
+ const starLabel = t("reviewStar");
2202
+ void vscode4.window.showInformationMessage(t("reviewTip"), rateLabel, starLabel, t("reviewLater")).then((pick) => {
2203
+ if (pick === rateLabel) void vscode4.env.openExternal(vscode4.Uri.parse(storeUrl));
2204
+ else if (pick === starLabel) void vscode4.env.openExternal(vscode4.Uri.parse("https://github.com/zhiyuanvision-lang/InkMap"));
2205
+ });
2206
+ }
2097
2207
  };
2098
2208
  async function saveDataUrl(name, dataUrl, dir) {
2099
2209
  const match = dataUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s);
@@ -2403,10 +2513,10 @@ function activate(context) {
2403
2513
  const license = extensionLicense(context);
2404
2514
  license.track?.("plugin_activate");
2405
2515
  const browsers = new BrowserServers(context, vscode5.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license);
2406
- const withUri = (run) => (arg) => {
2516
+ const withUri = (run2) => (arg) => {
2407
2517
  const uri = targetUri(arg);
2408
2518
  if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
2409
- return run(uri);
2519
+ return run2(uri);
2410
2520
  };
2411
2521
  const openToSide = withUri(
2412
2522
  (uri) => vscode5.commands.executeCommand("vscode.openWith", uri, MindmapEditorProvider.viewType, {
@@ -2468,7 +2578,8 @@ function activate(context) {
2468
2578
  context.subscriptions.push(statusBar, vscode5.window.onDidChangeActiveTextEditor(updateStatusBar));
2469
2579
  }
2470
2580
  const editors = new MindmapEditorProvider(context, license);
2471
- chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available));
2581
+ void chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available), () => {
2582
+ });
2472
2583
  maybeOfferWelcome();
2473
2584
  if (vscode5.languages?.registerCodeLensProvider) {
2474
2585
  const lensEmitter = vscode5.EventEmitter ? new vscode5.EventEmitter() : void 0;
@@ -2521,7 +2632,8 @@ function activate(context) {
2521
2632
  if (!target || !(0, import_node_path4.isAbsolute)(target) || !/\.md$/i.test(target)) return;
2522
2633
  const info = await (0, import_promises5.lstat)(target).catch(() => null);
2523
2634
  if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
2524
- void openFileInEditorPane(target);
2635
+ await openFileInEditorPane(target).catch(() => {
2636
+ });
2525
2637
  }
2526
2638
  }
2527
2639
  }),
@@ -2,7 +2,7 @@
2
2
  "name": "inkmap-vscode",
3
3
  "displayName": "%displayName%",
4
4
  "description": "%description%",
5
- "version": "0.3.16",
5
+ "version": "0.3.17",
6
6
  "publisher": "inkmap",
7
7
  "homepage": "https://zhiyuanv.com/software.html",
8
8
  "repository": {
@@ -128,6 +128,11 @@
128
128
  "title": "%command.installDeepSeekHarness%",
129
129
  "category": "Inkmap"
130
130
  },
131
+ {
132
+ "command": "inkmap.codeLensOpen",
133
+ "title": "%command.open%",
134
+ "category": "Inkmap"
135
+ },
131
136
  {
132
137
  "command": "inkmap.openDemo",
133
138
  "title": "%command.openDemo%",