inkmap-mcp 0.3.17 → 0.3.19
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/LICENSE.md +4 -2
- package/README.md +2 -1
- package/dist/bundles/antigravity/plugin.json +1 -1
- package/dist/bundles/antigravity/sidecars/inkmap/main.mjs +167 -32
- package/dist/bundles/codex/inkmap-codex/.codex-plugin/plugin.json +1 -1
- package/dist/bundles/codex/inkmap-codex/plugin.json +1 -1
- package/dist/bundles/harness/client.js +3 -0
- package/dist/bundles/harness/host.js +191 -55
- package/dist/bundles/harness/package.json +1 -1
- package/dist/bundles/vscode/dist/extension.js +263 -105
- package/dist/bundles/vscode/package.json +1 -1
- package/dist/cli.cjs +373 -216
- package/dist/codex.html +532 -531
- package/dist/web/app.js +50726 -50599
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/harness/src/host.mjs
|
|
2
2
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3
|
-
import { lstat as lstat3, realpath as
|
|
3
|
+
import { lstat as lstat3, realpath as realpath4 } from "node:fs/promises";
|
|
4
4
|
import { isAbsolute as isAbsolute2, relative as relative3, sep as sep3 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
@@ -26,6 +26,52 @@ function hasAccess(state, now = Date.now()) {
|
|
|
26
26
|
return state.pro || (state.trialUntil ?? 0) > now;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// packages/core/dist/images.js
|
|
30
|
+
var MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
31
|
+
var startsWith = (bytes, signature, offset = 0) => [...signature].every((char, i) => bytes[offset + i] === char.charCodeAt(0));
|
|
32
|
+
function sniffImage(bytes) {
|
|
33
|
+
if (startsWith(bytes, "\x89PNG\r\n\n"))
|
|
34
|
+
return "png";
|
|
35
|
+
if (startsWith(bytes, "\xFF\xD8\xFF"))
|
|
36
|
+
return "jpg";
|
|
37
|
+
if (startsWith(bytes, "GIF87a") || startsWith(bytes, "GIF89a"))
|
|
38
|
+
return "gif";
|
|
39
|
+
if (startsWith(bytes, "RIFF") && startsWith(bytes, "WEBP", 8))
|
|
40
|
+
return "webp";
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
function decodeImageDataUrl(dataUrl) {
|
|
44
|
+
const match = typeof dataUrl === "string" ? /^data:[\w.+/-]*;base64,([A-Za-z0-9+/]*={0,2})$/.exec(dataUrl) : null;
|
|
45
|
+
if (!match)
|
|
46
|
+
return { problem: "type" };
|
|
47
|
+
if (match[1].length * 3 / 4 - 2 > MAX_IMAGE_BYTES)
|
|
48
|
+
return { problem: "size" };
|
|
49
|
+
let binary;
|
|
50
|
+
try {
|
|
51
|
+
binary = atob(match[1]);
|
|
52
|
+
} catch {
|
|
53
|
+
return { problem: "type" };
|
|
54
|
+
}
|
|
55
|
+
if (binary.length > MAX_IMAGE_BYTES)
|
|
56
|
+
return { problem: "size" };
|
|
57
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
58
|
+
const extension = sniffImage(bytes);
|
|
59
|
+
return extension ? { bytes, extension } : { problem: "type" };
|
|
60
|
+
}
|
|
61
|
+
function imageFolderName(documentFileName) {
|
|
62
|
+
const stem = documentFileName.replace(/\.(?:md|markdown)$/i, "").trim();
|
|
63
|
+
return `${/^\.*$/.test(stem) ? "images" : stem}.assets`;
|
|
64
|
+
}
|
|
65
|
+
function imageFileName(when, extension, attempt = 1) {
|
|
66
|
+
const two = (n) => String(n).padStart(2, "0");
|
|
67
|
+
const stamp = `${when.getFullYear()}${two(when.getMonth() + 1)}${two(when.getDate())}-${two(when.getHours())}${two(when.getMinutes())}${two(when.getSeconds())}`;
|
|
68
|
+
return `image-${stamp}${attempt > 1 ? `-${attempt}` : ""}.${extension}`;
|
|
69
|
+
}
|
|
70
|
+
function imageLinkPath(folder, file) {
|
|
71
|
+
const encode = (part) => part.replace(/[%\s()<>#?[\]\\"]/g, (char) => encodeURIComponent(char).replace(/\(/g, "%28").replace(/\)/g, "%29"));
|
|
72
|
+
return `${encode(folder)}/${encode(file)}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
29
75
|
// packages/core/dist/index.js
|
|
30
76
|
function sanitizeViewState(raw) {
|
|
31
77
|
if (!raw || typeof raw !== "object")
|
|
@@ -59,7 +105,7 @@ import { homedir, tmpdir } from "node:os";
|
|
|
59
105
|
import { dirname, join } from "node:path";
|
|
60
106
|
|
|
61
107
|
// packages/cli/dist/version.js
|
|
62
|
-
var INKMAP_VERSION = "0.3.
|
|
108
|
+
var INKMAP_VERSION = "0.3.19";
|
|
63
109
|
|
|
64
110
|
// packages/cli/dist/license.js
|
|
65
111
|
var ZH_LOCALE_RE = /^zh(?:[-_.]|$)/i;
|
|
@@ -144,7 +190,7 @@ function billingOrigin(raw) {
|
|
|
144
190
|
}
|
|
145
191
|
return url.origin;
|
|
146
192
|
}
|
|
147
|
-
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS } = {}) {
|
|
193
|
+
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS, reviewPrompt = true } = {}) {
|
|
148
194
|
const listeners = /* @__PURE__ */ new Set();
|
|
149
195
|
let current = { pro: false };
|
|
150
196
|
let trial;
|
|
@@ -155,6 +201,25 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
155
201
|
let sentAppOpen = false;
|
|
156
202
|
let detectedHost = defaultHost;
|
|
157
203
|
const pendingEvents = /* @__PURE__ */ new Map();
|
|
204
|
+
let reviewDue = false;
|
|
205
|
+
let reviewCounting = Promise.resolve();
|
|
206
|
+
const countForReview = (event, count) => {
|
|
207
|
+
reviewCounting = reviewCounting.then(async () => {
|
|
208
|
+
if (disposed || reviewDue)
|
|
209
|
+
return;
|
|
210
|
+
const usage = await readReviewUsage();
|
|
211
|
+
if (usage.done)
|
|
212
|
+
return;
|
|
213
|
+
if (event === "doc_open")
|
|
214
|
+
usage.opens += count;
|
|
215
|
+
else
|
|
216
|
+
usage.edits += count;
|
|
217
|
+
await writeReviewUsage(usage);
|
|
218
|
+
if (usage.opens >= REVIEW_MIN_OPENS && usage.edits >= REVIEW_MIN_EDITS)
|
|
219
|
+
reviewDue = true;
|
|
220
|
+
}).catch(() => {
|
|
221
|
+
});
|
|
222
|
+
};
|
|
158
223
|
let lastCheck = 0;
|
|
159
224
|
let retryAfter = 0;
|
|
160
225
|
let fastPollUntil = 0;
|
|
@@ -629,12 +694,22 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
629
694
|
});
|
|
630
695
|
}
|
|
631
696
|
return {
|
|
632
|
-
async state() {
|
|
697
|
+
async state(options) {
|
|
633
698
|
await (trial ??= startTrial());
|
|
634
699
|
const interval = !current.pro && Date.now() < fastPollUntil ? 2e3 : 6e4;
|
|
635
700
|
if (Date.now() - lastCheck >= interval && Date.now() >= retryAfter)
|
|
636
701
|
await refresh();
|
|
637
702
|
await parkUnpaidSession();
|
|
703
|
+
await reviewCounting;
|
|
704
|
+
if (options?.forUi && reviewDue && hasAccess(current)) {
|
|
705
|
+
reviewDue = false;
|
|
706
|
+
const usage = await readReviewUsage().catch(() => void 0);
|
|
707
|
+
if (usage && !usage.done) {
|
|
708
|
+
await writeReviewUsage({ ...usage, done: true }).catch(() => {
|
|
709
|
+
});
|
|
710
|
+
return { ...current, reviewPrompt: true };
|
|
711
|
+
}
|
|
712
|
+
}
|
|
638
713
|
return current;
|
|
639
714
|
},
|
|
640
715
|
async connect(mode, localeHint) {
|
|
@@ -982,6 +1057,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
982
1057
|
if (event !== "app_open") {
|
|
983
1058
|
pendingEvents.set(event, Math.min(1e3, (pendingEvents.get(event) ?? 0) + count));
|
|
984
1059
|
}
|
|
1060
|
+
if (reviewPrompt && !process.env.CI && (event === "doc_open" || event === "doc_edit"))
|
|
1061
|
+
countForReview(event, count);
|
|
985
1062
|
if (telemetryTimer)
|
|
986
1063
|
return;
|
|
987
1064
|
telemetryTimer = setTimeout(() => {
|
|
@@ -1054,6 +1131,25 @@ async function atomicCreateIfMissing(path, initialContent) {
|
|
|
1054
1131
|
return await readFile(path, "utf8");
|
|
1055
1132
|
}
|
|
1056
1133
|
}
|
|
1134
|
+
var REVIEW_MIN_OPENS = 5;
|
|
1135
|
+
var REVIEW_MIN_EDITS = 3;
|
|
1136
|
+
var reviewUsagePath = () => join(process.env.INKMAP_HOME || join(homedir(), ".inkmap"), "review-prompt");
|
|
1137
|
+
async function readReviewUsage() {
|
|
1138
|
+
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
1139
|
+
try {
|
|
1140
|
+
const raw = JSON.parse(await readFile(reviewUsagePath(), "utf8"));
|
|
1141
|
+
return { opens: count(raw.opens), edits: count(raw.edits), done: raw.done === true };
|
|
1142
|
+
} catch {
|
|
1143
|
+
return { opens: 0, edits: 0, done: false };
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
async function writeReviewUsage(usage) {
|
|
1147
|
+
const path = reviewUsagePath();
|
|
1148
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
1149
|
+
const temporary = path + "." + randomUUID();
|
|
1150
|
+
await writeFile(temporary, JSON.stringify(usage), { mode: 384 });
|
|
1151
|
+
await rename(temporary, path);
|
|
1152
|
+
}
|
|
1057
1153
|
async function localInstallId() {
|
|
1058
1154
|
const path = join(process.env.INKMAP_HOME || join(homedir(), ".inkmap"), "install-id");
|
|
1059
1155
|
const generated = "inst_" + randomUUID().replace(/-/g, "").slice(0, 24);
|
|
@@ -1087,48 +1183,20 @@ async function localTrialDeadline() {
|
|
|
1087
1183
|
// packages/cli/dist/server.js
|
|
1088
1184
|
import { createHash, randomBytes } from "node:crypto";
|
|
1089
1185
|
import { watch } from "node:fs";
|
|
1090
|
-
import { lstat as lstat2, mkdir as
|
|
1186
|
+
import { lstat as lstat2, mkdir as mkdir3, readFile as readFile3, realpath as realpath3, rename as rename2, rm as rm2, stat, writeFile as writeFile3 } from "node:fs/promises";
|
|
1091
1187
|
import { createServer } from "node:http";
|
|
1092
1188
|
import { homedir as homedir3 } from "node:os";
|
|
1093
|
-
import { basename as basename2, delimiter as delimiter2, dirname as dirname3, extname, join as
|
|
1189
|
+
import { basename as basename2, delimiter as delimiter2, dirname as dirname3, extname, join as join4, normalize, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
1094
1190
|
|
|
1095
|
-
// packages/cli/dist/
|
|
1096
|
-
import {
|
|
1097
|
-
|
|
1098
|
-
return new Promise((done) => {
|
|
1099
|
-
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
1100
|
-
child.on("error", () => done(false));
|
|
1101
|
-
if (launched)
|
|
1102
|
-
child.on("spawn", () => done(true));
|
|
1103
|
-
else
|
|
1104
|
-
child.on("exit", (code) => done(code === 0));
|
|
1105
|
-
child.unref();
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
async function openBrowserWindow(url) {
|
|
1109
|
-
if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url))
|
|
1110
|
-
return;
|
|
1111
|
-
if (process.platform === "darwin") {
|
|
1112
|
-
if (await run("open", ["-a", "Google Chrome", url]))
|
|
1113
|
-
return;
|
|
1114
|
-
await run("open", [url]);
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
if (process.platform === "win32") {
|
|
1118
|
-
if (await run("cmd", ["/c", "start", "", "chrome", url]))
|
|
1119
|
-
return;
|
|
1120
|
-
await run("cmd", ["/c", "start", "", url]);
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
if (await run("google-chrome", [url], true))
|
|
1124
|
-
return;
|
|
1125
|
-
await run("xdg-open", [url], true);
|
|
1126
|
-
}
|
|
1191
|
+
// packages/cli/dist/image-assets.js
|
|
1192
|
+
import { mkdir as mkdir2, realpath as realpath2, writeFile as writeFile2 } from "node:fs/promises";
|
|
1193
|
+
import { join as join3 } from "node:path";
|
|
1127
1194
|
|
|
1128
1195
|
// packages/cli/dist/workspace-fs.js
|
|
1129
1196
|
import { lstat, readdir, readFile as readFile2, realpath } from "node:fs/promises";
|
|
1130
1197
|
import { homedir as homedir2 } from "node:os";
|
|
1131
1198
|
import { basename, delimiter, dirname as dirname2, isAbsolute, join as join2, posix, relative, resolve, sep, win32 } from "node:path";
|
|
1199
|
+
var say = (zh, en) => detectOsLocale() === "zh" ? zh : en;
|
|
1132
1200
|
var MAX_MARKDOWN_BYTES = 5 * 1024 * 1024;
|
|
1133
1201
|
var SKIP_SCAN_DIRS = /* @__PURE__ */ new Set([
|
|
1134
1202
|
".git",
|
|
@@ -1224,6 +1292,60 @@ async function scanMarkdownFiles(rootDir, { maxFiles = 200, maxDepth = 4, byRece
|
|
|
1224
1292
|
return found;
|
|
1225
1293
|
}
|
|
1226
1294
|
|
|
1295
|
+
// packages/cli/dist/image-assets.js
|
|
1296
|
+
async function saveImageAsset(documentDir, documentFileName, image, when = /* @__PURE__ */ new Date()) {
|
|
1297
|
+
const folder = imageFolderName(documentFileName);
|
|
1298
|
+
const target = join3(documentDir, folder);
|
|
1299
|
+
await mkdir2(target, { recursive: true });
|
|
1300
|
+
if (!insideOrEqual(await realpath2(documentDir), await realpath2(target))) {
|
|
1301
|
+
throw new Error(say("\u56FE\u7247\u76EE\u5F55\u6307\u5411\u6587\u6863\u76EE\u5F55\u4E4B\u5916\uFF0C\u672A\u4FDD\u5B58\u56FE\u7247\u3002", "The pictures folder leads outside the document's folder, so nothing was saved."));
|
|
1302
|
+
}
|
|
1303
|
+
for (let attempt = 1; attempt <= 100; attempt++) {
|
|
1304
|
+
const name2 = imageFileName(when, image.extension, attempt);
|
|
1305
|
+
try {
|
|
1306
|
+
await writeFile2(join3(target, name2), image.bytes, { flag: "wx" });
|
|
1307
|
+
return imageLinkPath(folder, name2);
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
if (error.code !== "EEXIST")
|
|
1310
|
+
throw error;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
throw new Error(say("\u65E0\u6CD5\u4E3A\u56FE\u7247\u751F\u6210\u65B0\u7684\u6587\u4EF6\u540D\u3002", "Could not find a free file name for the picture."));
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// packages/cli/dist/open-browser.js
|
|
1317
|
+
import { spawn } from "node:child_process";
|
|
1318
|
+
function run(cmd, args, launched = false) {
|
|
1319
|
+
return new Promise((done) => {
|
|
1320
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
1321
|
+
child.on("error", () => done(false));
|
|
1322
|
+
if (launched)
|
|
1323
|
+
child.on("spawn", () => done(true));
|
|
1324
|
+
else
|
|
1325
|
+
child.on("exit", (code) => done(code === 0));
|
|
1326
|
+
child.unref();
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
async function openBrowserWindow(url) {
|
|
1330
|
+
if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url))
|
|
1331
|
+
return;
|
|
1332
|
+
if (process.platform === "darwin") {
|
|
1333
|
+
if (await run("open", ["-a", "Google Chrome", url]))
|
|
1334
|
+
return;
|
|
1335
|
+
await run("open", [url]);
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (process.platform === "win32") {
|
|
1339
|
+
if (await run("cmd", ["/c", "start", "", "chrome", url]))
|
|
1340
|
+
return;
|
|
1341
|
+
await run("cmd", ["/c", "start", "", url]);
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
if (await run("google-chrome", [url], true))
|
|
1345
|
+
return;
|
|
1346
|
+
await run("xdg-open", [url], true);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1227
1349
|
// packages/cli/dist/server.js
|
|
1228
1350
|
var MAX_BODY = 20 * 1024 * 1024;
|
|
1229
1351
|
var TYPES = {
|
|
@@ -1257,8 +1379,8 @@ function docName(path) {
|
|
|
1257
1379
|
return basename2(path).replace(/\.md$/i, "").replace(/\.markmap$/i, "");
|
|
1258
1380
|
}
|
|
1259
1381
|
function viewStateFile(key) {
|
|
1260
|
-
const base = process.env.INKMAP_HOME ||
|
|
1261
|
-
return
|
|
1382
|
+
const base = process.env.INKMAP_HOME || join4(homedir3(), ".inkmap");
|
|
1383
|
+
return join4(base, "view-state", hash(key) + ".json");
|
|
1262
1384
|
}
|
|
1263
1385
|
async function readDiskViewState(key) {
|
|
1264
1386
|
try {
|
|
@@ -1269,10 +1391,10 @@ async function readDiskViewState(key) {
|
|
|
1269
1391
|
}
|
|
1270
1392
|
async function writeDiskViewState(key, state) {
|
|
1271
1393
|
const target = viewStateFile(key);
|
|
1272
|
-
await
|
|
1394
|
+
await mkdir3(dirname3(target), { recursive: true, mode: 448 });
|
|
1273
1395
|
const temp = `${target}.${process.pid}.${Date.now()}`;
|
|
1274
1396
|
try {
|
|
1275
|
-
await
|
|
1397
|
+
await writeFile3(temp, JSON.stringify(state), { mode: 384 });
|
|
1276
1398
|
await rename2(temp, target);
|
|
1277
1399
|
} finally {
|
|
1278
1400
|
await rm2(temp, { force: true }).catch(() => {
|
|
@@ -1281,7 +1403,7 @@ async function writeDiskViewState(key, state) {
|
|
|
1281
1403
|
}
|
|
1282
1404
|
async function fileSource(file, log = () => {
|
|
1283
1405
|
}) {
|
|
1284
|
-
const path = await
|
|
1406
|
+
const path = await realpath3(resolve2(file)).catch(() => resolve2(file));
|
|
1285
1407
|
if (!(await stat(path)).isFile())
|
|
1286
1408
|
throw new Error(`\u4E0D\u662F\u6587\u4EF6\uFF1A${path}`);
|
|
1287
1409
|
const dir = dirname3(path);
|
|
@@ -1291,7 +1413,7 @@ async function fileSource(file, log = () => {
|
|
|
1291
1413
|
dir,
|
|
1292
1414
|
read: () => readFile3(path, "utf8"),
|
|
1293
1415
|
async write(md) {
|
|
1294
|
-
await
|
|
1416
|
+
await writeFile3(path, md, "utf8");
|
|
1295
1417
|
log(`\u5DF2\u5199\u56DE ${path}`);
|
|
1296
1418
|
},
|
|
1297
1419
|
watch(onChange) {
|
|
@@ -1321,7 +1443,7 @@ function within(root, rel, allowAbsoluteInRoot = false) {
|
|
|
1321
1443
|
}
|
|
1322
1444
|
const resolvedRoot = resolve2(root);
|
|
1323
1445
|
const base = resolvedRoot.endsWith(sep2) ? resolvedRoot : resolvedRoot + sep2;
|
|
1324
|
-
const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? normalize(decoded) : normalize(
|
|
1446
|
+
const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? normalize(decoded) : normalize(join4(resolvedRoot, decoded));
|
|
1325
1447
|
return full.startsWith(base) ? full : null;
|
|
1326
1448
|
}
|
|
1327
1449
|
async function serve({ source: initialSource, webRoot: webRoot2, port = 4377, host = "127.0.0.1", log = () => {
|
|
@@ -1379,17 +1501,17 @@ data: ${JSON.stringify(data)}
|
|
|
1379
1501
|
}), 80);
|
|
1380
1502
|
};
|
|
1381
1503
|
let unwatch = activeSource.watch(scheduleRefresh);
|
|
1382
|
-
const canonicalActiveKey = async () => activeSource.key ? await
|
|
1504
|
+
const canonicalActiveKey = async () => activeSource.key ? await realpath3(activeSource.key).catch(() => activeSource.key) : void 0;
|
|
1383
1505
|
async function collectWorkspaceFiles() {
|
|
1384
1506
|
const roots = /* @__PURE__ */ new Map();
|
|
1385
1507
|
if (activeSource.key && !confineToWorkspaceRoots) {
|
|
1386
|
-
const realKey = await
|
|
1387
|
-
const projRoot = await
|
|
1508
|
+
const realKey = await realpath3(activeSource.key).catch(() => activeSource.key);
|
|
1509
|
+
const projRoot = await realpath3(await findProjectRoot(realKey)).catch(() => dirname3(realKey));
|
|
1388
1510
|
roots.set(projRoot, { path: projRoot, name: basename2(projRoot), active: true });
|
|
1389
1511
|
}
|
|
1390
1512
|
const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(delimiter2)].filter(Boolean);
|
|
1391
1513
|
for (const raw of envRoots) {
|
|
1392
|
-
const real = await
|
|
1514
|
+
const real = await realpath3(resolve2(raw)).catch(() => null);
|
|
1393
1515
|
if (real && !roots.has(real)) {
|
|
1394
1516
|
roots.set(real, { path: real, name: basename2(real), active: roots.size === 0 });
|
|
1395
1517
|
}
|
|
@@ -1427,7 +1549,7 @@ data: ${JSON.stringify(data)}
|
|
|
1427
1549
|
throw notMarkdown();
|
|
1428
1550
|
const resolvedCandidate = resolve2(candidatePath);
|
|
1429
1551
|
const rawStat = await lstat2(resolvedCandidate).catch(() => null);
|
|
1430
|
-
const realTarget = await
|
|
1552
|
+
const realTarget = await realpath3(resolvedCandidate).catch(() => null);
|
|
1431
1553
|
const targetStat = realTarget ? await stat(realTarget).catch(() => null) : null;
|
|
1432
1554
|
if (!rawStat || rawStat.isSymbolicLink() && !trustCaller || !realTarget || !targetStat?.isFile() || targetStat.size > MAX_MARKDOWN_BYTES) {
|
|
1433
1555
|
throw new HttpError(403, zh() ? "\u8BF7\u9009\u62E9 5 MiB \u4EE5\u5185\u7684\u666E\u901A Markdown \u6587\u4EF6\u3002" : "Choose a regular Markdown file up to 5 MiB.");
|
|
@@ -1582,8 +1704,22 @@ data: ${JSON.stringify(data)}
|
|
|
1582
1704
|
return json2(res, 200, { version });
|
|
1583
1705
|
});
|
|
1584
1706
|
}
|
|
1707
|
+
if (url.pathname === "/api/image" && req.method === "POST") {
|
|
1708
|
+
if (!sameOriginWrite())
|
|
1709
|
+
return json2(res, 403, { error: "forbidden" });
|
|
1710
|
+
const image = decodeImageDataUrl(JSON.parse(await readBody2(req)).dataUrl);
|
|
1711
|
+
if ("problem" in image) {
|
|
1712
|
+
return json2(res, image.problem === "size" ? 413 : 415, { error: image.problem });
|
|
1713
|
+
}
|
|
1714
|
+
if (!hasAccess(await license?.state() ?? { pro: false }))
|
|
1715
|
+
return json2(res, 403, { error: "Inkmap trial expired" });
|
|
1716
|
+
return await serialized(async () => {
|
|
1717
|
+
const name2 = activeSource.key ? basename2(activeSource.key) : activeSource.name;
|
|
1718
|
+
return json2(res, 200, { path: await saveImageAsset(activeSource.dir, name2, image) });
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1585
1721
|
if (url.pathname === "/api/license" && req.method === "GET")
|
|
1586
|
-
return json2(res, 200, await license?.state() ?? { pro: false });
|
|
1722
|
+
return json2(res, 200, await license?.state({ forUi: true }) ?? { pro: false });
|
|
1587
1723
|
if (url.pathname === "/api/open" && req.method === "POST") {
|
|
1588
1724
|
if (!sameOriginWrite())
|
|
1589
1725
|
return json2(res, 403, { error: "forbidden" });
|
|
@@ -1697,8 +1833,8 @@ data: ${JSON.stringify(data)}
|
|
|
1697
1833
|
if (url.pathname.startsWith("/doc-assets/")) {
|
|
1698
1834
|
let asset = within(activeSource.dir, url.pathname.slice("/doc-assets/".length), true);
|
|
1699
1835
|
if (asset) {
|
|
1700
|
-
const root = await
|
|
1701
|
-
asset = await
|
|
1836
|
+
const root = await realpath3(activeSource.dir).catch(() => null);
|
|
1837
|
+
asset = await realpath3(asset).catch(() => null);
|
|
1702
1838
|
const allowedExt = sidebar ? /\.(?:png|jpe?g|gif|webp|avif|bmp|ico)$/i : /\.(?:png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i;
|
|
1703
1839
|
if (!root || !asset || !insideOrEqual(root, asset) || !allowedExt.test(asset))
|
|
1704
1840
|
asset = null;
|
|
@@ -1792,7 +1928,7 @@ async function workspaceFile(ctx, address) {
|
|
|
1792
1928
|
if (typeof hostPath !== "string") throw new FileUnavailable();
|
|
1793
1929
|
const roundTrip = fs.processPathFromHostPath(hostPath);
|
|
1794
1930
|
if (roundTrip === void 0 || (await fs.resolve(roundTrip)).targetKey !== target.targetKey) throw new FileUnavailable();
|
|
1795
|
-
return
|
|
1931
|
+
return realpath4(hostPath);
|
|
1796
1932
|
};
|
|
1797
1933
|
const [root, path] = await Promise.all([local(header.cwd), local(file.path)]);
|
|
1798
1934
|
const child = relative3(root, path);
|
|
@@ -1803,7 +1939,7 @@ async function workspaceFile(ctx, address) {
|
|
|
1803
1939
|
}
|
|
1804
1940
|
async function assertFile(path) {
|
|
1805
1941
|
const info = await lstat3(path);
|
|
1806
|
-
if (!info.isFile() || info.size > maxBytes || await
|
|
1942
|
+
if (!info.isFile() || info.size > maxBytes || await realpath4(path) !== path) throw new FileUnavailable();
|
|
1807
1943
|
}
|
|
1808
1944
|
async function confinedSource(path) {
|
|
1809
1945
|
const source = await fileSource(path);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inkmap",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"description": "Inkmap 思维导图 — 在 DeepSeek Harness 中将本地 Markdown 实时渲染为可双向编辑的思维导图 (Markmap) 与 Mermaid 流程图 / Interactive two-way Markdown mind map & Mermaid flowchart editor for DeepSeek Harness.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"icon": "./icon.svg",
|