inkmap-mcp 0.2.5 → 0.2.8

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.
@@ -2,9 +2,9 @@
2
2
  import { execFile } from "node:child_process";
3
3
  import { createHash as createHash2 } from "node:crypto";
4
4
  import { readFileSync, readdirSync } from "node:fs";
5
- import { lstat as lstat2, readdir, readFile as readFile3, realpath as realpath3 } from "node:fs/promises";
5
+ import { lstat as lstat3, readdir as readdir2, readFile as readFile3, realpath as realpath3 } from "node:fs/promises";
6
6
  import { homedir as homedir4 } from "node:os";
7
- import { basename as basename2, dirname as dirname4, extname as extname2, isAbsolute as isAbsolute2, join as join4, normalize as normalize2, relative as relative2, resolve as resolve3, sep as sep3 } from "node:path";
7
+ import { basename as basename2, dirname as dirname4, extname as extname2, isAbsolute as isAbsolute3, join as join4, normalize as normalize2, relative as relative3, resolve as resolve3, sep as sep3 } from "node:path";
8
8
  import { fileURLToPath, pathToFileURL } from "node:url";
9
9
 
10
10
  // packages/core/dist/product.js
@@ -105,8 +105,28 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
105
105
  }
106
106
  function maskPhone(phone) {
107
107
  const clean = phone.trim();
108
+ const at = clean.indexOf("@");
109
+ if (at > 0 && at < clean.length - 1) {
110
+ const local = [...clean.slice(0, at)];
111
+ const domain = clean.slice(at + 1);
112
+ return `${local.length <= 1 ? "***" : local[0] + "***"}@${domain}`.slice(0, 64);
113
+ }
108
114
  return /^1\d{10}$/.test(clean) ? `${clean.slice(0, 3)}****${clean.slice(7)}` : clean.slice(0, 32);
109
115
  }
116
+ function clientLocale() {
117
+ const raw = (process.env.INKMAP_LOCALE || process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || "").trim();
118
+ if (/^zh\b/i.test(raw))
119
+ return "zh";
120
+ if (/^en\b/i.test(process.env.INKMAP_LOCALE || ""))
121
+ return "en";
122
+ try {
123
+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || "";
124
+ if (/^Asia\/(Shanghai|Chongqing|Harbin|Urumqi)$/i.test(tz))
125
+ return "zh";
126
+ } catch {
127
+ }
128
+ return "en";
129
+ }
110
130
  function writeSession(operation) {
111
131
  const next = pendingWrite.then(operation);
112
132
  pendingWrite = next.then(() => {
@@ -151,11 +171,16 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
151
171
  });
152
172
  }
153
173
  function phoneRequest(origin, action, phone, code) {
174
+ const isEmail = phone.includes("@");
175
+ const locale = clientLocale();
154
176
  return fetch(origin + "/billing/v1/phone-sign-in/" + action, {
155
177
  method: "POST",
156
- headers: { "content-type": "application/json" },
178
+ headers: {
179
+ "content-type": "application/json",
180
+ "accept-language": locale === "zh" ? "zh-CN,zh;q=0.9" : "en-US,en;q=0.9"
181
+ },
157
182
  redirect: "error",
158
- body: JSON.stringify({ product: PRODUCT.id, phone, code }),
183
+ body: JSON.stringify({ product: PRODUCT.id, phone, ...isEmail && { email: phone, locale }, code }),
159
184
  signal: AbortSignal.timeout(12e3)
160
185
  });
161
186
  }
@@ -404,8 +429,10 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
404
429
  return { status: "needsPhone" };
405
430
  },
406
431
  async sendPhoneCode(phone) {
407
- if (typeof phone !== "string" || !phone.trim() || phone.length > 40)
432
+ if (typeof phone !== "string" || !phone.trim() || phone.length > 254)
408
433
  return phoneFailure(400);
434
+ const isEmail = phone.includes("@");
435
+ const locale = clientLocale();
409
436
  try {
410
437
  const origin = billingOrigin(getOrigin());
411
438
  if (!loginOnly) {
@@ -413,10 +440,12 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
413
440
  if (!pendingCheckout || pendingCheckout.origin !== origin) {
414
441
  pendingCheckout = await createCheckoutFlow(origin);
415
442
  }
416
- let smsRes = await checkoutPost(pendingCheckout.url, "sms", origin, { phone }, pendingCheckout.token, pendingCheckout.cookie);
443
+ const sendAction = isEmail ? "email/send" : "sms";
444
+ const sendBody = isEmail ? { email: phone, locale } : { phone };
445
+ let smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie);
417
446
  if (smsRes.status === 410 || smsRes.status === 404) {
418
447
  pendingCheckout = await createCheckoutFlow(origin);
419
- smsRes = await checkoutPost(pendingCheckout.url, "sms", origin, { phone }, pendingCheckout.token, pendingCheckout.cookie);
448
+ smsRes = await checkoutPost(pendingCheckout.url, sendAction, origin, sendBody, pendingCheckout.token, pendingCheckout.cookie);
420
449
  }
421
450
  pendingCheckout.cookie = mergeCookies(pendingCheckout.cookie, smsRes);
422
451
  return smsRes.status === 204 ? { ok: true, value: void 0 } : phoneFailure(smsRes.status);
@@ -431,8 +460,9 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
431
460
  }
432
461
  },
433
462
  async signInByPhone(phone, code) {
434
- if (typeof phone !== "string" || !phone.trim() || phone.length > 40 || typeof code !== "string" || !/^\d{6}$/.test(code))
463
+ if (typeof phone !== "string" || !phone.trim() || phone.length > 254 || typeof code !== "string" || !/^\d{6}$/.test(code))
435
464
  return phoneFailure(400);
465
+ const isEmail = phone.includes("@");
436
466
  const version = generation;
437
467
  try {
438
468
  const origin = billingOrigin(getOrigin());
@@ -440,7 +470,9 @@ function licenseService(storage, getOrigin, { loginOnly = false } = {}) {
440
470
  let checkoutUrl;
441
471
  let cookie;
442
472
  if (pendingCheckout && pendingCheckout.origin === origin && !loginOnly) {
443
- const loginRes = await checkoutPost(pendingCheckout.url, "login", origin, { phone, code }, pendingCheckout.token, pendingCheckout.cookie);
473
+ const verifyAction = isEmail ? "email/verify" : "login";
474
+ const verifyBody = isEmail ? { email: phone, code } : { phone, code };
475
+ const loginRes = await checkoutPost(pendingCheckout.url, verifyAction, origin, verifyBody, pendingCheckout.token, pendingCheckout.cookie);
444
476
  if (!loginRes.ok) {
445
477
  if (loginRes.status === 410 || loginRes.status === 404)
446
478
  pendingCheckout = void 0;
@@ -605,9 +637,9 @@ var AD_TTL = 6 * 60 * 60 * 1e3;
605
637
  // packages/cli/dist/server.js
606
638
  import { createHash, randomBytes } from "node:crypto";
607
639
  import { watch } from "node:fs";
608
- import { mkdir as mkdir2, readFile as readFile2, realpath, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
640
+ import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, realpath, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
609
641
  import { homedir as homedir2 } from "node:os";
610
- import { basename, dirname as dirname2, extname, join as join2, normalize, resolve, sep } from "node:path";
642
+ import { basename, delimiter, dirname as dirname2, extname, isAbsolute, join as join2, normalize, relative, resolve, sep } from "node:path";
611
643
  var MAX_BODY = 20 * 1024 * 1024;
612
644
  var hash = (s) => createHash("sha1").update(s).digest("hex");
613
645
  function docName(path) {
@@ -665,24 +697,24 @@ async function fileSource(file, log = () => {
665
697
 
666
698
  // packages/antigravity/src/select.mjs
667
699
  import { randomUUID as randomUUID2 } from "node:crypto";
668
- import { lstat, mkdir as mkdir3, realpath as realpath2, rename as rename3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
700
+ import { lstat as lstat2, mkdir as mkdir3, realpath as realpath2, rename as rename3, rm as rm3, writeFile as writeFile3 } from "node:fs/promises";
669
701
  import { homedir as homedir3 } from "node:os";
670
- import { dirname as dirname3, isAbsolute, join as join3, relative, resolve as resolve2, sep as sep2 } from "node:path";
702
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
671
703
  var MAX_BYTES = 5 * 1024 * 1024;
672
704
  function targetStateFile() {
673
705
  const base = process.env.INKMAP_HOME ?? join3(homedir3(), ".inkmap");
674
706
  return join3(base, "antigravity-target.json");
675
707
  }
676
708
  function inside(root, file) {
677
- const rel = relative(root, file);
678
- return Boolean(rel && !isAbsolute(rel) && rel !== ".." && !rel.startsWith(".." + sep2));
709
+ const rel = relative2(root, file);
710
+ return Boolean(rel && !isAbsolute2(rel) && rel !== ".." && !rel.startsWith(".." + sep2));
679
711
  }
680
712
  async function selectTargetFile(rawFile, rawWorkspace) {
681
713
  if (typeof rawFile !== "string" || !/\.md$/i.test(rawFile.trim())) {
682
714
  throw new Error("\u8BF7\u6307\u5B9A\u4E00\u4E2A .md \u6216 .markmap.md \u6587\u4EF6\u8DEF\u5F84\u3002");
683
715
  }
684
716
  const candidate = resolve2(rawFile.trim());
685
- const info = await lstat(candidate);
717
+ const info = await lstat2(candidate);
686
718
  if (!info.isFile() || info.size > MAX_BYTES) {
687
719
  throw new Error("\u8BF7\u9009\u62E9 5 MiB \u4EE5\u5185\u7684\u666E\u901A Markdown \u6587\u4EF6\u3002");
688
720
  }
@@ -784,14 +816,14 @@ var TYPES = {
784
816
  var hash2 = (text) => createHash2("sha1").update(text).digest("hex");
785
817
  function insideOrEqual(root, target) {
786
818
  if (root === target) return true;
787
- const rel = relative2(root, target);
788
- return Boolean(rel && !isAbsolute2(rel) && rel !== ".." && !rel.startsWith(".." + sep3));
819
+ const rel = relative3(root, target);
820
+ return Boolean(rel && !isAbsolute3(rel) && rel !== ".." && !rel.startsWith(".." + sep3));
789
821
  }
790
822
  function uriToPath(uri) {
791
823
  if (typeof uri !== "string" || !uri) return null;
792
824
  try {
793
825
  if (uri.startsWith("file://")) return fileURLToPath(uri);
794
- if (isAbsolute2(uri)) return uri;
826
+ if (isAbsolute3(uri)) return uri;
795
827
  } catch {
796
828
  }
797
829
  return null;
@@ -801,7 +833,7 @@ async function readTargetSelection() {
801
833
  const raw = JSON.parse(await readFile3(targetStateFile(), "utf8"));
802
834
  if (typeof raw?.file !== "string" || !/\.md$/i.test(raw.file)) return null;
803
835
  const file = await realpath3(raw.file);
804
- const info = await lstat2(file);
836
+ const info = await lstat3(file);
805
837
  if (!info.isFile() || info.size > MAX_BYTES2) return null;
806
838
  const workspace = typeof raw.workspace === "string" ? await realpath3(raw.workspace).catch(() => dirname4(file)) : dirname4(file);
807
839
  if (!insideOrEqual(workspace, file)) return null;
@@ -815,7 +847,7 @@ async function discoverAntigravityProjects() {
815
847
  const roots = [];
816
848
  let entries = [];
817
849
  try {
818
- entries = await readdir(projectsDir);
850
+ entries = await readdir2(projectsDir);
819
851
  } catch {
820
852
  return roots;
821
853
  }
@@ -842,7 +874,7 @@ async function scanMarkdownFiles(rootDir) {
842
874
  if (depth > MAX_SCAN_DEPTH || found.length >= MAX_FILES) return;
843
875
  let entries = [];
844
876
  try {
845
- entries = await readdir(dir, { withFileTypes: true });
877
+ entries = await readdir2(dir, { withFileTypes: true });
846
878
  } catch {
847
879
  return;
848
880
  }
@@ -854,7 +886,7 @@ async function scanMarkdownFiles(rootDir) {
854
886
  if (!SKIP_DIRS.has(entry.name)) await walk(full, depth + 1);
855
887
  } else if (entry.isFile() && /\.md$/i.test(entry.name)) {
856
888
  try {
857
- const info = await lstat2(full);
889
+ const info = await lstat3(full);
858
890
  if (info.isFile() && info.size <= MAX_BYTES2) {
859
891
  const real = await realpath3(full);
860
892
  if (insideOrEqual(rootDir, real)) found.push(real);
@@ -885,7 +917,7 @@ function createAntigravitySidecar({
885
917
  webRoot = defaultWebRoot,
886
918
  billingOrigin: billingOrigin2 = () => process.env.INKMAP_BILLING_ORIGIN || YUNFAN_BILLING_ORIGIN
887
919
  } = {}) {
888
- const license = licenseService(fileSessionStorage(), billingOrigin2);
920
+ const license = licenseService(fileSessionStorage(), billingOrigin2, { loginOnly: true });
889
921
  let activeFile = null;
890
922
  async function allowedRoots(workspaceUris = []) {
891
923
  const roots = /* @__PURE__ */ new Map();
@@ -919,7 +951,7 @@ function createAntigravitySidecar({
919
951
  }
920
952
  const raw = uriToPath(candidatePath.trim()) || resolve3(candidatePath.trim());
921
953
  if (!/\.md$/i.test(raw)) throw new Error("\u8BF7\u9009\u62E9 .md \u6216 .markmap.md \u6587\u4EF6\u3002");
922
- const info = await lstat2(raw);
954
+ const info = await lstat3(raw);
923
955
  if (!info.isFile() || info.size > MAX_BYTES2) throw new Error("\u8BF7\u9009\u62E9 5 MiB \u4EE5\u5185\u7684\u666E\u901A Markdown \u6587\u4EF6\u3002");
924
956
  const real = await realpath3(raw);
925
957
  if (real !== raw || !/\.md$/i.test(real)) throw new Error("\u4E0D\u652F\u6301\u7B26\u53F7\u94FE\u63A5\u6216\u975E Markdown \u6587\u4EF6\u3002");
@@ -948,7 +980,7 @@ function createAntigravitySidecar({
948
980
  const seen = /* @__PURE__ */ new Set();
949
981
  if (target && !seen.has(target.file)) {
950
982
  const owner = roots.find((r) => insideOrEqual(r.path, target.file));
951
- const rel = owner ? relative2(owner.path, target.file) : basename2(target.file);
983
+ const rel = owner ? relative3(owner.path, target.file) : basename2(target.file);
952
984
  items.push({
953
985
  path: target.file,
954
986
  uri: pathToFileURL(target.file).href,
@@ -962,7 +994,7 @@ function createAntigravitySidecar({
962
994
  for (const file of files) {
963
995
  if (seen.has(file)) continue;
964
996
  seen.add(file);
965
- const rel = relative2(root.path, file);
997
+ const rel = relative3(root.path, file);
966
998
  items.push({
967
999
  path: file,
968
1000
  uri: pathToFileURL(file).href,
@@ -1141,17 +1173,11 @@ function createAntigravitySidecar({
1141
1173
  return { ok: true };
1142
1174
  }, "POST");
1143
1175
  app.api("/api/license", async () => await license.state(), "GET");
1144
- app.api("/api/checkout", async (data) => {
1145
- const mode = data?.mode === "buy" ? "buy" : "restore";
1146
- const url = await license.connect(mode);
1176
+ app.api("/api/checkout", async () => {
1177
+ const url = await license.connect("restore");
1147
1178
  openExternalUrl(url);
1148
1179
  return { url };
1149
1180
  }, "POST");
1150
- app.api("/api/order-pro", async () => {
1151
- const result = await license.orderPro();
1152
- if (result.status === "redirect") openExternalUrl(result.url);
1153
- return { result };
1154
- }, "POST");
1155
1181
  app.api("/api/phone-send", async (data) => {
1156
1182
  return { result: await license.sendPhoneCode(String(data?.phone ?? "")) };
1157
1183
  }, "POST");
@@ -1173,7 +1199,7 @@ function createAntigravitySidecar({
1173
1199
  if (!insideOrEqual(dir, candidate) || candidate === dir) return notFound();
1174
1200
  const realAsset = await realpath3(candidate);
1175
1201
  if (!insideOrEqual(dir, realAsset) || !/\.(?:png|jpe?g|gif|webp|svg)$/i.test(realAsset)) return notFound();
1176
- const info = await lstat2(realAsset);
1202
+ const info = await lstat3(realAsset);
1177
1203
  if (!info.isFile() || info.size > MAX_BYTES2) return notFound();
1178
1204
  const type = TYPES[extname2(realAsset).toLowerCase()] || "application/octet-stream";
1179
1205
  return new SidecarResponse(await readFile3(realAsset), {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inkmap-codex",
3
- "version": "0.2.5",
3
+ "version": "0.2.8",
4
4
  "description": "Open Markdown as an editable mind map with Inkmap.",
5
5
  "requires_local_executor": true,
6
6
  "interface": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "inkmap-codex",
4
- "version": "0.2.5",
4
+ "version": "0.2.8",
5
5
  "description": "Open Markdown as an editable mind map with Inkmap.",
6
6
  "extensions": {
7
7
  "com.openai": {