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.
@@ -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.18";
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";
@@ -187,7 +188,7 @@ function billingOrigin(raw) {
187
188
  }
188
189
  return url.origin;
189
190
  }
190
- function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS } = {}) {
191
+ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS, reviewPrompt = true } = {}) {
191
192
  const listeners = /* @__PURE__ */ new Set();
192
193
  let current = { pro: false };
193
194
  let trial;
@@ -198,7 +199,22 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
198
199
  let sentAppOpen = false;
199
200
  let detectedHost = defaultHost;
200
201
  const pendingEvents = /* @__PURE__ */ new Map();
202
+ let reviewDue = false;
203
+ let reviewCounting = Promise.resolve();
204
+ const countForReview = (event, count) => {
205
+ reviewCounting = reviewCounting.then(async () => {
206
+ if (disposed || reviewDue) return;
207
+ const usage = await readReviewUsage();
208
+ if (usage.done) return;
209
+ if (event === "doc_open") usage.opens += count;
210
+ else usage.edits += count;
211
+ await writeReviewUsage(usage);
212
+ if (usage.opens >= REVIEW_MIN_OPENS && usage.edits >= REVIEW_MIN_EDITS) reviewDue = true;
213
+ }).catch(() => {
214
+ });
215
+ };
201
216
  let lastCheck = 0;
217
+ let retryAfter = 0;
202
218
  let fastPollUntil = 0;
203
219
  const expectPurchase = () => void (fastPollUntil = Date.now() + 15 * 6e4);
204
220
  let flowCreation;
@@ -389,12 +405,29 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
389
405
  timer = setTimeout(() => void refresh(), delay);
390
406
  timer.unref();
391
407
  }
408
+ async function rememberProCheck(token, active, account) {
409
+ await writeSession(async () => {
410
+ let record;
411
+ try {
412
+ record = JSON.parse(await storage.read() || "{}");
413
+ } catch {
414
+ return;
415
+ }
416
+ if (record.token !== token) return;
417
+ const at = typeof record.proVerifiedAt === "number" ? record.proVerifiedAt : void 0;
418
+ if (active ? at !== void 0 && Date.now() - at < PRO_RECHECK_STAMP_MS && at <= Date.now() : at === void 0) return;
419
+ const { proVerifiedAt: _at, proAccount: _account, ...rest } = record;
420
+ await storage.write(JSON.stringify(active ? { ...rest, proVerifiedAt: Date.now(), ...account && { proAccount: account } } : rest));
421
+ }).catch(() => {
422
+ });
423
+ }
392
424
  function refresh() {
393
425
  if (connection) return connection;
394
426
  const version = generation;
395
427
  connection = (async () => {
396
428
  let token;
397
429
  let delay = 6e4;
430
+ let offlinePro;
398
431
  try {
399
432
  const origin = billingOrigin(getOrigin());
400
433
  if (origin !== activeOrigin) {
@@ -408,6 +441,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
408
441
  const record = JSON.parse(stored);
409
442
  if (record.origin !== origin || typeof record.token !== "string") return update(false);
410
443
  token = record.token;
444
+ const verifiedAt = record.proVerifiedAt;
445
+ if (typeof verifiedAt === "number" && verifiedAt <= Date.now() && Date.now() - verifiedAt < OFFLINE_PRO_GRACE_MS) {
446
+ offlinePro = { ...typeof record.proAccount === "string" && { account: record.proAccount.slice(0, 64) } };
447
+ }
411
448
  const response = await entitlement(origin, record.token);
412
449
  if (version !== generation || disposed) return;
413
450
  if (response.status === 401) {
@@ -423,9 +460,12 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
423
460
  const state = await response.json();
424
461
  if (version !== generation || disposed) return;
425
462
  applyEntitlement(state);
426
- delay = state.active !== true && state.pending === true ? 2500 : 6e4;
463
+ void rememberProCheck(record.token, current.pro, current.account);
464
+ delay = state.active !== true && (state.pending === true || Date.now() < fastPollUntil) ? 2500 : 6e4;
427
465
  } catch {
428
- if (version === generation && Date.now() - lastCheck > 15 * 6e4) update(false);
466
+ if (version === generation) retryAfter = Date.now() + (Date.now() < fastPollUntil ? 2e3 : 3e4);
467
+ if (version === generation && offlinePro) update(true, true, offlinePro.account);
468
+ else if (version === generation && Date.now() - lastCheck > 15 * 6e4) update(false);
429
469
  } finally {
430
470
  if (version === generation && token) schedule(delay);
431
471
  }
@@ -459,7 +499,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
459
499
  function scheduleWait(delay) {
460
500
  clearTimeout(waitTimer);
461
501
  if (disposed || !waiting.length) return;
462
- waitTimer = setTimeout(() => void checkWaiting(), delay);
502
+ waitTimer = setTimeout(() => void checkWaiting().catch(() => scheduleWait(WAIT_SLOW_MS)), delay);
463
503
  waitTimer.unref();
464
504
  }
465
505
  async function checkWaiting() {
@@ -493,8 +533,9 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
493
533
  if (disposed || round !== waitRound) return;
494
534
  await writeSession(async () => {
495
535
  if (disposed || round !== waitRound || w.origin !== billingOrigin(getOrigin())) return;
496
- clearWaiting();
536
+ if (w.email) lastSignIn = w.email.trim().slice(0, 254);
497
537
  await storage.write(sessionRecord({ origin: w.origin, token: w.token }));
538
+ clearWaiting();
498
539
  ++generation;
499
540
  activeOrigin = w.origin;
500
541
  applyEntitlement(body);
@@ -526,6 +567,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
526
567
  } catch {
527
568
  }
528
569
  if (typeof record.token !== "string" || typeof record.origin !== "string") return;
570
+ if (typeof record.checkoutUrl === "string") return;
529
571
  const response = await entitlement(record.origin, record.token).catch(() => null);
530
572
  if (!response?.ok) return;
531
573
  const latest = await response.json().catch(() => null);
@@ -555,12 +597,20 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
555
597
  return;
556
598
  }
557
599
  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-"))) {
600
+ 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
601
  return;
563
602
  }
603
+ const norm = (p) => {
604
+ const clean = p.replace(/\\/g, "/");
605
+ return process.platform === "win32" ? clean.toLowerCase() : clean;
606
+ };
607
+ const sysTmp = norm((0, import_node_os.tmpdir)()).replace(/\/+$/, "");
608
+ const homesToCheck = [process.env.INKMAP_HOME || "", (0, import_node_os.homedir)()].filter(Boolean).map(norm);
609
+ for (const h of homesToCheck) {
610
+ 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-")) {
611
+ return;
612
+ }
613
+ }
564
614
  }
565
615
  const id = await (installIdPromise ??= localInstallId().catch(() => void 0));
566
616
  if (disposed || !id || !pendingEvents.size) return;
@@ -590,11 +640,21 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
590
640
  });
591
641
  }
592
642
  return {
593
- async state() {
643
+ async state(options) {
594
644
  await (trial ??= startTrial());
595
- const interval = !current.pro && Date.now() < fastPollUntil ? 4e3 : 6e4;
596
- if (Date.now() - lastCheck >= interval) await refresh();
645
+ const interval = !current.pro && Date.now() < fastPollUntil ? 2e3 : 6e4;
646
+ if (Date.now() - lastCheck >= interval && Date.now() >= retryAfter) await refresh();
597
647
  await parkUnpaidSession();
648
+ await reviewCounting;
649
+ if (options?.forUi && reviewDue && hasAccess(current)) {
650
+ reviewDue = false;
651
+ const usage = await readReviewUsage().catch(() => void 0);
652
+ if (usage && !usage.done) {
653
+ await writeReviewUsage({ ...usage, done: true }).catch(() => {
654
+ });
655
+ return { ...current, reviewPrompt: true };
656
+ }
657
+ }
598
658
  return current;
599
659
  },
600
660
  async connect(mode, localeHint) {
@@ -656,7 +716,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
656
716
  if (cachedOrder && cachedOrder.origin === origin && cachedOrder.locale === loc && Date.now() - cachedOrder.at < 8e3) {
657
717
  const hit = cachedOrder.result;
658
718
  cachedOrder = void 0;
659
- schedule(hit.status === "qr" || hit.status === "redirect" ? 4e3 : 6e4);
719
+ if (current.pro) return { status: "active", state: current };
720
+ schedule(hit.status === "qr" || hit.status === "redirect" ? 2500 : 6e4);
660
721
  return hit;
661
722
  }
662
723
  const version = generation;
@@ -666,6 +727,17 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
666
727
  if (stored) record = JSON.parse(stored);
667
728
  } catch {
668
729
  }
730
+ if (record?.origin === origin && typeof record.token === "string") {
731
+ const rights = await entitlement(origin, record.token).catch(() => null);
732
+ if (rights?.ok) {
733
+ const ent = await rights.json().catch(() => null);
734
+ if (ent && ent.active === true) {
735
+ applyEntitlement(ent);
736
+ schedule(6e4);
737
+ return { status: "active", state: current };
738
+ }
739
+ }
740
+ }
669
741
  const requestOrder = async (checkoutUrl, token, cookie, persist) => {
670
742
  const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, localeHint);
671
743
  if (res.status === 401 || res.status === 403 || res.status === 404 || res.status === 410) return null;
@@ -844,12 +916,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
844
916
  return await writeSession(async () => {
845
917
  if (version !== generation || disposed || origin !== billingOrigin(getOrigin())) return phoneFailure();
846
918
  clearWaiting();
919
+ const clean = phone.trim().slice(0, 254);
920
+ if (clean) lastSignIn = clean;
847
921
  await storage.write(sessionRecord({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
848
922
  ++generation;
849
923
  activeOrigin = origin;
850
924
  applyEntitlement(state);
851
925
  if (cachedOrder?.result.status === "active") cachedOrder.result.state = current;
852
- schedule(cachedOrder?.result.status === "qr" ? 4e3 : 6e4);
926
+ schedule(cachedOrder?.result.status === "qr" || cachedOrder?.result.status === "redirect" ? 2500 : 6e4);
853
927
  return { ok: true, value: current };
854
928
  });
855
929
  } catch {
@@ -896,6 +970,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
896
970
  if (event !== "app_open") {
897
971
  pendingEvents.set(event, Math.min(1e3, (pendingEvents.get(event) ?? 0) + count));
898
972
  }
973
+ if (reviewPrompt && !process.env.CI && (event === "doc_open" || event === "doc_edit")) countForReview(event, count);
899
974
  if (telemetryTimer) return;
900
975
  telemetryTimer = setTimeout(() => {
901
976
  telemetryTimer = void 0;
@@ -959,6 +1034,25 @@ async function atomicCreateIfMissing(path2, initialContent) {
959
1034
  return await (0, import_promises.readFile)(path2, "utf8");
960
1035
  }
961
1036
  }
1037
+ var REVIEW_MIN_OPENS = 5;
1038
+ var REVIEW_MIN_EDITS = 3;
1039
+ var reviewUsagePath = () => (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "review-prompt");
1040
+ async function readReviewUsage() {
1041
+ const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
1042
+ try {
1043
+ const raw = JSON.parse(await (0, import_promises.readFile)(reviewUsagePath(), "utf8"));
1044
+ return { opens: count(raw.opens), edits: count(raw.edits), done: raw.done === true };
1045
+ } catch {
1046
+ return { opens: 0, edits: 0, done: false };
1047
+ }
1048
+ }
1049
+ async function writeReviewUsage(usage) {
1050
+ const path2 = reviewUsagePath();
1051
+ await (0, import_promises.mkdir)((0, import_node_path.dirname)(path2), { recursive: true, mode: 448 });
1052
+ const temporary = path2 + "." + (0, import_node_crypto.randomUUID)();
1053
+ await (0, import_promises.writeFile)(temporary, JSON.stringify(usage), { mode: 384 });
1054
+ await (0, import_promises.rename)(temporary, path2);
1055
+ }
962
1056
  async function localInstallId() {
963
1057
  const path2 = (0, import_node_path.join)(process.env.INKMAP_HOME || (0, import_node_path.join)((0, import_node_os.homedir)(), ".inkmap"), "install-id");
964
1058
  const generated = "inst_" + (0, import_node_crypto.randomUUID)().replace(/-/g, "").slice(0, 24);
@@ -972,6 +1066,33 @@ async function localTrialDeadline() {
972
1066
  return Number.isSafeInteger(started) && started > 0 && started <= Date.now() ? started + TRIAL_MS : void 0;
973
1067
  }
974
1068
 
1069
+ // packages/cli/src/open-browser.ts
1070
+ var import_node_child_process2 = require("node:child_process");
1071
+ function run(cmd, args, launched = false) {
1072
+ return new Promise((done) => {
1073
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1074
+ child.on("error", () => done(false));
1075
+ if (launched) child.on("spawn", () => done(true));
1076
+ else child.on("exit", (code) => done(code === 0));
1077
+ child.unref();
1078
+ });
1079
+ }
1080
+ async function openBrowserWindow(url) {
1081
+ if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url)) return;
1082
+ if (process.platform === "darwin") {
1083
+ if (await run("open", ["-a", "Google Chrome", url])) return;
1084
+ await run("open", [url]);
1085
+ return;
1086
+ }
1087
+ if (process.platform === "win32") {
1088
+ if (await run("cmd", ["/c", "start", "", "chrome", url])) return;
1089
+ await run("cmd", ["/c", "start", "", url]);
1090
+ return;
1091
+ }
1092
+ if (await run("google-chrome", [url], true)) return;
1093
+ await run("xdg-open", [url], true);
1094
+ }
1095
+
975
1096
  // packages/cli/src/workspace-fs.ts
976
1097
  var import_promises2 = require("node:fs/promises");
977
1098
  var import_node_os2 = require("node:os");
@@ -1130,12 +1251,17 @@ async function fileSource(file, log = () => {
1130
1251
  log(`\u5DF2\u5199\u56DE ${path2}`);
1131
1252
  },
1132
1253
  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();
1254
+ try {
1255
+ const watcher = (0, import_node_fs.watch)(dir, (_, changed) => {
1256
+ if (!changed || changed === (0, import_node_path3.basename)(path2)) onChange();
1257
+ });
1258
+ watcher.on("error", () => {
1259
+ });
1260
+ return () => watcher.close();
1261
+ } catch {
1262
+ return () => {
1263
+ };
1264
+ }
1139
1265
  },
1140
1266
  readView: () => readDiskViewState(path2),
1141
1267
  writeView: (state) => writeDiskViewState(path2, state)
@@ -1153,27 +1279,6 @@ function within(root, rel, allowAbsoluteInRoot = false) {
1153
1279
  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
1280
  return full.startsWith(base) ? full : null;
1155
1281
  }
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
1282
  async function serve({
1178
1283
  source: initialSource,
1179
1284
  webRoot,
@@ -1185,7 +1290,6 @@ async function serve({
1185
1290
  sidebar = false,
1186
1291
  sidebarPurchase = false,
1187
1292
  sidebarAccountNavigation = false,
1188
- ideWorkspace = false,
1189
1293
  workspaceRoots = [],
1190
1294
  confineToWorkspaceRoots = false,
1191
1295
  openSource = (path2) => fileSource(path2, log),
@@ -1401,7 +1505,6 @@ data: ${JSON.stringify(data)}
1401
1505
  if (url.pathname === "/api/capabilities" && req.method === "GET") {
1402
1506
  return json(res, 200, {
1403
1507
  purchase: canPurchase,
1404
- ...ideWorkspace && { ideWorkspace: true },
1405
1508
  ...sidebarAccountNavigation && { accountNavigation: "host" }
1406
1509
  });
1407
1510
  }
@@ -1419,6 +1522,7 @@ data: ${JSON.stringify(data)}
1419
1522
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1420
1523
  const { md, baseVersion } = JSON.parse(await readBody(req));
1421
1524
  if (typeof md !== "string") return json(res, 400, { error: zh2() ? "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002" : "md must be a string." });
1525
+ if (Buffer.byteLength(md) > MAX_MARKDOWN_BYTES) return json(res, 413, { error: zh2() ? "\u6587\u6863\u8FC7\u5927\u3002" : "Document too large." });
1422
1526
  if (!hasAccess(await license?.state() ?? { pro: false })) return json(res, 403, { error: "Inkmap trial expired" });
1423
1527
  return await serialized(async () => {
1424
1528
  await refresh();
@@ -1433,7 +1537,7 @@ data: ${JSON.stringify(data)}
1433
1537
  return json(res, 200, { version });
1434
1538
  });
1435
1539
  }
1436
- if (url.pathname === "/api/license" && req.method === "GET") return json(res, 200, await license?.state() ?? { pro: false });
1540
+ if (url.pathname === "/api/license" && req.method === "GET") return json(res, 200, await license?.state({ forUi: true }) ?? { pro: false });
1437
1541
  if (url.pathname === "/api/open" && req.method === "POST") {
1438
1542
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1439
1543
  const { file } = JSON.parse(await readBody(req));
@@ -1445,7 +1549,7 @@ data: ${JSON.stringify(data)}
1445
1549
  if (url.pathname === "/api/telemetry" && req.method === "POST") {
1446
1550
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1447
1551
  const { event } = JSON.parse(await readBody(req));
1448
- if (typeof event === "string" && event) license?.track?.(event);
1552
+ if (typeof event === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(event)) license?.track?.(event);
1449
1553
  return json(res, 200, { ok: true });
1450
1554
  }
1451
1555
  if (url.pathname === "/api/open-browser" && req.method === "POST") {
@@ -1713,7 +1817,11 @@ var zh = {
1713
1817
  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
1818
  harnessAlready: "DeepSeek Harness \u4E2D\u5DF2\u5B89\u88C5 Inkmap\u3002",
1715
1819
  harnessNotFound: "\u672A\u627E\u5230 DeepSeek Harness \u684C\u9762\u7248\u3002",
1716
- harnessFailed: "\u5B89\u88C5\u5230 DeepSeek Harness \u5931\u8D25\uFF1A{error}"
1820
+ harnessFailed: "\u5B89\u88C5\u5230 DeepSeek Harness \u5931\u8D25\uFF1A{error}",
1821
+ 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",
1822
+ reviewRate: "\u53BB\u5546\u5E97\u7ED9\u597D\u8BC4",
1823
+ reviewStar: "GitHub \u70B9 Star",
1824
+ reviewLater: "\u4EE5\u540E\u518D\u8BF4"
1717
1825
  };
1718
1826
  var en = {
1719
1827
  openMarkdownFirst: "Open a Markdown file first",
@@ -1759,7 +1867,11 @@ var en = {
1759
1867
  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
1868
  harnessAlready: "Inkmap is already installed in DeepSeek Harness.",
1761
1869
  harnessNotFound: "DeepSeek Harness desktop was not found.",
1762
- harnessFailed: "Could not install Inkmap in DeepSeek Harness: {error}"
1870
+ harnessFailed: "Could not install Inkmap in DeepSeek Harness: {error}",
1871
+ reviewTip: "Enjoying Inkmap for your Markdown docs? A quick 5-star review or GitHub Star helps more developers discover it \u2764\uFE0F",
1872
+ reviewRate: "Rate Extension",
1873
+ reviewStar: "Star on GitHub",
1874
+ reviewLater: "Maybe later"
1763
1875
  };
1764
1876
  var isChinese = () => detectOsLocale() === "zh";
1765
1877
  function t(key, vars = {}) {
@@ -1842,7 +1954,8 @@ async function openUrl(url) {
1842
1954
  const ok = await new Promise((done) => {
1843
1955
  const child = (0, import_node_child_process3.spawn)(cmd, args, { stdio: "ignore", detached: true });
1844
1956
  child.on("error", () => done(false));
1845
- child.on("exit", (code) => done(code === 0));
1957
+ if (cmd === "google-chrome") child.on("spawn", () => done(true));
1958
+ else child.on("exit", (code) => done(code === 0));
1846
1959
  child.unref();
1847
1960
  });
1848
1961
  if (!ok) await fallback();
@@ -1860,7 +1973,7 @@ function extensionLicense(context) {
1860
1973
  if (token) await context.secrets.store(KEY, token);
1861
1974
  else await context.secrets.delete(KEY);
1862
1975
  }
1863
- }, () => vscode3.workspace.getConfiguration("inkmap").get("billingOrigin") || process.env.INKMAP_BILLING_ORIGIN || "" || YUNFAN_BILLING_ORIGIN, { host });
1976
+ }, () => vscode3.workspace.getConfiguration("inkmap").get("billingOrigin") || process.env.INKMAP_BILLING_ORIGIN || "" || YUNFAN_BILLING_ORIGIN, { host, reviewPrompt: false });
1864
1977
  }
1865
1978
  async function openCheckout(license, mode, localeHint) {
1866
1979
  const url = await license.connect(mode, localeHint);
@@ -1892,6 +2005,7 @@ function webviewHtml(html, { webBase, assetBase, cspSource, nonce, locale }) {
1892
2005
  // packages/vscode/src/mindmapEditor.ts
1893
2006
  var VIEW_STATE_PREFIX2 = "inkmap.viewState:";
1894
2007
  var CHANGE_DELAY = 120;
2008
+ var DIAGRAM_CHANGE_DELAY = 700;
1895
2009
  var REVEAL_DELAY = 150;
1896
2010
  var MindmapEditorProvider = class {
1897
2011
  constructor(context, license) {
@@ -1928,8 +2042,6 @@ var MindmapEditorProvider = class {
1928
2042
  }
1929
2043
  async resolveCustomTextEditor(document, panel) {
1930
2044
  const webview = panel.webview;
1931
- this.panels.add(panel);
1932
- this.panelDocuments.set(panel, document.uri.toString());
1933
2045
  const webRoot = vscode4.Uri.joinPath(this.context.extensionUri, "dist", "web");
1934
2046
  const assets = docDir(document.uri);
1935
2047
  webview.options = {
@@ -1937,6 +2049,8 @@ var MindmapEditorProvider = class {
1937
2049
  localResourceRoots: [webRoot, ...assets ? [assets] : [], ...(vscode4.workspace.workspaceFolders ?? []).map((f) => f.uri)]
1938
2050
  };
1939
2051
  webview.html = await editorHtml(webview, webRoot, assets);
2052
+ this.panels.add(panel);
2053
+ this.panelDocuments.set(panel, document.uri.toString());
1940
2054
  const viewKey = VIEW_STATE_PREFIX2 + document.uri.toString();
1941
2055
  const state = () => {
1942
2056
  const viewState = document.uri.scheme === "untitled" ? void 0 : sanitizeViewState(this.context.workspaceState.get(viewKey));
@@ -1970,7 +2084,10 @@ var MindmapEditorProvider = class {
1970
2084
  vscode4.workspace.onDidChangeTextDocument((e) => {
1971
2085
  if (applying || e.document !== document || !e.contentChanges.length) return;
1972
2086
  clearTimeout(changeTimer);
1973
- changeTimer = setTimeout(() => post({ type: "change", doc: state() }), CHANGE_DELAY);
2087
+ const before = document.getText(new vscode4.Range(new vscode4.Position(0, 0), e.contentChanges[0].range.start));
2088
+ const fences = before.match(/^\s*(?:`{3,}|~{3,}).*$/gm) ?? [];
2089
+ const inDiagram = fences.length % 2 === 1 && /mermaid/i.test(fences[fences.length - 1]);
2090
+ changeTimer = setTimeout(() => post({ type: "change", doc: state() }), inDiagram ? DIAGRAM_CHANGE_DELAY : CHANGE_DELAY);
1974
2091
  }),
1975
2092
  vscode4.window.onDidChangeTextEditorSelection((e) => {
1976
2093
  if (e.textEditor.document !== document) return;
@@ -1982,7 +2099,7 @@ var MindmapEditorProvider = class {
1982
2099
  }),
1983
2100
  webview.onDidReceiveMessage(async (msg) => {
1984
2101
  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";
2102
+ 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
2103
  if (!accountAction && msg.type !== "ready" && msg.type !== "viewState" && msg.type !== "select" && !hasAccess(await this.license.state())) {
1987
2104
  if ("id" in msg) return post({ type: "error", id: msg.id, message: t("trialExpired") });
1988
2105
  return;
@@ -1991,6 +2108,8 @@ var MindmapEditorProvider = class {
1991
2108
  case "ready": {
1992
2109
  this.readyPanels.add(panel);
1993
2110
  void this.context.globalState?.update("inkmap.hasOpenedMap", true);
2111
+ const opens = (this.context.globalState?.get("inkmap.docOpenCount") ?? 0) + 1;
2112
+ void this.context.globalState?.update("inkmap.docOpenCount", opens);
1994
2113
  this.license.track?.("doc_open");
1995
2114
  const [license, chat] = await Promise.all([this.license.state(), chatAvailable()]);
1996
2115
  await post({ type: "doc", doc: state(), license, chat });
@@ -2003,6 +2122,11 @@ var MindmapEditorProvider = class {
2003
2122
  }
2004
2123
  case "openInBrowser":
2005
2124
  return vscode4.commands.executeCommand("inkmap.openInBrowser", document.uri);
2125
+ case "checkLicense": {
2126
+ const latest = await this.license.state();
2127
+ await post({ type: "license", state: latest });
2128
+ return;
2129
+ }
2006
2130
  case "telemetry": {
2007
2131
  this.license.track?.(msg.event);
2008
2132
  return;
@@ -2023,6 +2147,9 @@ var MindmapEditorProvider = class {
2023
2147
  applying = false;
2024
2148
  }
2025
2149
  this.license.track?.("doc_edit");
2150
+ const edits = (this.context.globalState?.get("inkmap.docEditCount") ?? 0) + 1;
2151
+ void this.context.globalState?.update("inkmap.docEditCount", edits);
2152
+ this.maybeOfferReview(edits);
2026
2153
  return post({ type: "saved", id: msg.id, version: String(document.version) });
2027
2154
  }
2028
2155
  case "undo":
@@ -2075,15 +2202,26 @@ var MindmapEditorProvider = class {
2075
2202
  void vscode4.env.openExternal(vscode4.Uri.parse(msg.url));
2076
2203
  }
2077
2204
  return;
2205
+ // The webview waits for an answer to each of these without a timeout, so a failure must be reported.
2078
2206
  case "signOut":
2079
- await this.license.deactivate();
2080
- return post({ type: "signedOut", id: msg.id });
2081
2207
  case "sendPhoneCode":
2082
- return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
2083
2208
  case "signInByPhone":
2084
- return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code, msg.locale) });
2085
2209
  case "saveFile":
2086
- return post({ type: "fileSaved", id: msg.id, saved: await saveDataUrl(msg.name, msg.dataUrl, assets) });
2210
+ try {
2211
+ if (msg.type === "signOut") {
2212
+ await this.license.deactivate();
2213
+ return post({ type: "signedOut", id: msg.id });
2214
+ }
2215
+ if (msg.type === "sendPhoneCode") {
2216
+ return post({ type: "phoneCodeSent", id: msg.id, result: await this.license.sendPhoneCode(msg.phone, msg.locale) });
2217
+ }
2218
+ if (msg.type === "signInByPhone") {
2219
+ return post({ type: "phoneSignIn", id: msg.id, result: await this.license.signInByPhone(msg.phone, msg.code, msg.locale) });
2220
+ }
2221
+ return post({ type: "fileSaved", id: msg.id, saved: await saveDataUrl(msg.name, msg.dataUrl, assets) });
2222
+ } catch (error) {
2223
+ return post({ type: "error", id: msg.id, message: error instanceof Error ? error.message : String(error) });
2224
+ }
2087
2225
  }
2088
2226
  })
2089
2227
  );
@@ -2094,6 +2232,22 @@ var MindmapEditorProvider = class {
2094
2232
  disposables.forEach((d) => d.dispose());
2095
2233
  });
2096
2234
  }
2235
+ maybeOfferReview(edits) {
2236
+ const state = this.context.globalState;
2237
+ if (!state || state.get("inkmap.reviewPrompted")) return;
2238
+ const opens = state.get("inkmap.docOpenCount") ?? 0;
2239
+ if (opens < 5 || edits < 3) return;
2240
+ void state.update("inkmap.reviewPrompted", true);
2241
+ const app = (vscode4.env.appName || "").toLowerCase();
2242
+ const openVsxFork = /(cursor|windsurf|trae|qoder|antigravity|codium|positron)/.test(app);
2243
+ 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";
2244
+ const rateLabel = t("reviewRate");
2245
+ const starLabel = t("reviewStar");
2246
+ void vscode4.window.showInformationMessage(t("reviewTip"), rateLabel, starLabel, t("reviewLater")).then((pick) => {
2247
+ if (pick === rateLabel) void vscode4.env.openExternal(vscode4.Uri.parse(storeUrl));
2248
+ else if (pick === starLabel) void vscode4.env.openExternal(vscode4.Uri.parse("https://github.com/zhiyuanvision-lang/InkMap"));
2249
+ });
2250
+ }
2097
2251
  };
2098
2252
  async function saveDataUrl(name, dataUrl, dir) {
2099
2253
  const match = dataUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s);
@@ -2403,10 +2557,10 @@ function activate(context) {
2403
2557
  const license = extensionLicense(context);
2404
2558
  license.track?.("plugin_activate");
2405
2559
  const browsers = new BrowserServers(context, vscode5.Uri.joinPath(context.extensionUri, "dist", "web").fsPath, log, license);
2406
- const withUri = (run) => (arg) => {
2560
+ const withUri = (run2) => (arg) => {
2407
2561
  const uri = targetUri(arg);
2408
2562
  if (!uri) return vscode5.window.showWarningMessage(t("openMarkdownFirst"));
2409
- return run(uri);
2563
+ return run2(uri);
2410
2564
  };
2411
2565
  const openToSide = withUri(
2412
2566
  (uri) => vscode5.commands.executeCommand("vscode.openWith", uri, MindmapEditorProvider.viewType, {
@@ -2468,7 +2622,8 @@ function activate(context) {
2468
2622
  context.subscriptions.push(statusBar, vscode5.window.onDidChangeActiveTextEditor(updateStatusBar));
2469
2623
  }
2470
2624
  const editors = new MindmapEditorProvider(context, license);
2471
- chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available));
2625
+ void chatAvailable().then((available) => vscode5.commands.executeCommand("setContext", "inkmap.chatAvailable", available), () => {
2626
+ });
2472
2627
  maybeOfferWelcome();
2473
2628
  if (vscode5.languages?.registerCodeLensProvider) {
2474
2629
  const lensEmitter = vscode5.EventEmitter ? new vscode5.EventEmitter() : void 0;
@@ -2521,7 +2676,8 @@ function activate(context) {
2521
2676
  if (!target || !(0, import_node_path4.isAbsolute)(target) || !/\.md$/i.test(target)) return;
2522
2677
  const info = await (0, import_promises5.lstat)(target).catch(() => null);
2523
2678
  if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
2524
- void openFileInEditorPane(target);
2679
+ await openFileInEditorPane(target).catch(() => {
2680
+ });
2525
2681
  }
2526
2682
  }
2527
2683
  }),
@@ -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.18",
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%",