inkmap-mcp 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundles/antigravity/plugin.json +1 -1
- package/dist/bundles/antigravity/sidecars/inkmap/bridge.js +7 -4
- package/dist/bundles/antigravity/sidecars/inkmap/main.mjs +185 -86
- package/dist/bundles/antigravity/sidecars/inkmap/sidecar.json +1 -6
- 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/host.js +182 -61
- package/dist/bundles/harness/package.json +1 -1
- package/dist/bundles/vscode/dist/extension.js +220 -64
- package/dist/bundles/vscode/package.json +6 -1
- package/dist/cli.cjs +322 -135
- package/dist/codex.html +727 -674
- package/dist/web/app.js +24259 -23521
- package/dist/web/index.html +44 -4
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/harness/src/host.mjs
|
|
2
2
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3
3
|
import { lstat as lstat3, realpath as realpath3 } from "node:fs/promises";
|
|
4
|
-
import { isAbsolute as isAbsolute2, relative as relative3, sep as
|
|
4
|
+
import { isAbsolute as isAbsolute2, relative as relative3, sep as sep3 } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
|
|
7
7
|
// packages/core/dist/product.js
|
|
@@ -56,10 +56,10 @@ import { execFileSync } from "node:child_process";
|
|
|
56
56
|
import { link, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
57
57
|
import { randomUUID } from "node:crypto";
|
|
58
58
|
import { homedir, tmpdir } from "node:os";
|
|
59
|
-
import { dirname, join
|
|
59
|
+
import { dirname, join } from "node:path";
|
|
60
60
|
|
|
61
61
|
// packages/cli/dist/version.js
|
|
62
|
-
var INKMAP_VERSION = "0.3.
|
|
62
|
+
var INKMAP_VERSION = "0.3.18";
|
|
63
63
|
|
|
64
64
|
// packages/cli/dist/license.js
|
|
65
65
|
var ZH_LOCALE_RE = /^zh(?:[-_.]|$)/i;
|
|
@@ -70,6 +70,8 @@ var WAIT_SLOW_MS = 3e4;
|
|
|
70
70
|
var WAIT_FAST_FOR_MS = 30 * 6e4;
|
|
71
71
|
var WAIT_MAX_MS = 3 * 24 * 60 * 6e4;
|
|
72
72
|
var MAX_WAITING = 5;
|
|
73
|
+
var OFFLINE_PRO_GRACE_MS = 7 * 24 * 60 * 6e4;
|
|
74
|
+
var PRO_RECHECK_STAMP_MS = 12 * 60 * 6e4;
|
|
73
75
|
function isWaitingToken(value) {
|
|
74
76
|
const w = value;
|
|
75
77
|
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";
|
|
@@ -142,7 +144,7 @@ function billingOrigin(raw) {
|
|
|
142
144
|
}
|
|
143
145
|
return url.origin;
|
|
144
146
|
}
|
|
145
|
-
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS } = {}) {
|
|
147
|
+
function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHost = "", waitPollMs = WAIT_FAST_MS, reviewPrompt = true } = {}) {
|
|
146
148
|
const listeners = /* @__PURE__ */ new Set();
|
|
147
149
|
let current = { pro: false };
|
|
148
150
|
let trial;
|
|
@@ -153,7 +155,27 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
153
155
|
let sentAppOpen = false;
|
|
154
156
|
let detectedHost = defaultHost;
|
|
155
157
|
const pendingEvents = /* @__PURE__ */ new Map();
|
|
158
|
+
let reviewDue = false;
|
|
159
|
+
let reviewCounting = Promise.resolve();
|
|
160
|
+
const countForReview = (event, count) => {
|
|
161
|
+
reviewCounting = reviewCounting.then(async () => {
|
|
162
|
+
if (disposed || reviewDue)
|
|
163
|
+
return;
|
|
164
|
+
const usage = await readReviewUsage();
|
|
165
|
+
if (usage.done)
|
|
166
|
+
return;
|
|
167
|
+
if (event === "doc_open")
|
|
168
|
+
usage.opens += count;
|
|
169
|
+
else
|
|
170
|
+
usage.edits += count;
|
|
171
|
+
await writeReviewUsage(usage);
|
|
172
|
+
if (usage.opens >= REVIEW_MIN_OPENS && usage.edits >= REVIEW_MIN_EDITS)
|
|
173
|
+
reviewDue = true;
|
|
174
|
+
}).catch(() => {
|
|
175
|
+
});
|
|
176
|
+
};
|
|
156
177
|
let lastCheck = 0;
|
|
178
|
+
let retryAfter = 0;
|
|
157
179
|
let fastPollUntil = 0;
|
|
158
180
|
const expectPurchase = () => void (fastPollUntil = Date.now() + 15 * 6e4);
|
|
159
181
|
let flowCreation;
|
|
@@ -355,6 +377,24 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
355
377
|
timer = setTimeout(() => void refresh(), delay);
|
|
356
378
|
timer.unref();
|
|
357
379
|
}
|
|
380
|
+
async function rememberProCheck(token, active, account) {
|
|
381
|
+
await writeSession(async () => {
|
|
382
|
+
let record;
|
|
383
|
+
try {
|
|
384
|
+
record = JSON.parse(await storage.read() || "{}");
|
|
385
|
+
} catch {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (record.token !== token)
|
|
389
|
+
return;
|
|
390
|
+
const at = typeof record.proVerifiedAt === "number" ? record.proVerifiedAt : void 0;
|
|
391
|
+
if (active ? at !== void 0 && Date.now() - at < PRO_RECHECK_STAMP_MS && at <= Date.now() : at === void 0)
|
|
392
|
+
return;
|
|
393
|
+
const { proVerifiedAt: _at, proAccount: _account, ...rest } = record;
|
|
394
|
+
await storage.write(JSON.stringify(active ? { ...rest, proVerifiedAt: Date.now(), ...account && { proAccount: account } } : rest));
|
|
395
|
+
}).catch(() => {
|
|
396
|
+
});
|
|
397
|
+
}
|
|
358
398
|
function refresh() {
|
|
359
399
|
if (connection)
|
|
360
400
|
return connection;
|
|
@@ -362,6 +402,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
362
402
|
connection = (async () => {
|
|
363
403
|
let token;
|
|
364
404
|
let delay = 6e4;
|
|
405
|
+
let offlinePro;
|
|
365
406
|
try {
|
|
366
407
|
const origin = billingOrigin(getOrigin());
|
|
367
408
|
if (origin !== activeOrigin) {
|
|
@@ -378,6 +419,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
378
419
|
if (record.origin !== origin || typeof record.token !== "string")
|
|
379
420
|
return update(false);
|
|
380
421
|
token = record.token;
|
|
422
|
+
const verifiedAt = record.proVerifiedAt;
|
|
423
|
+
if (typeof verifiedAt === "number" && verifiedAt <= Date.now() && Date.now() - verifiedAt < OFFLINE_PRO_GRACE_MS) {
|
|
424
|
+
offlinePro = { ...typeof record.proAccount === "string" && { account: record.proAccount.slice(0, 64) } };
|
|
425
|
+
}
|
|
381
426
|
const response = await entitlement(origin, record.token);
|
|
382
427
|
if (version !== generation || disposed)
|
|
383
428
|
return;
|
|
@@ -397,9 +442,14 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
397
442
|
if (version !== generation || disposed)
|
|
398
443
|
return;
|
|
399
444
|
applyEntitlement(state);
|
|
400
|
-
|
|
445
|
+
void rememberProCheck(record.token, current.pro, current.account);
|
|
446
|
+
delay = state.active !== true && (state.pending === true || Date.now() < fastPollUntil) ? 2500 : 6e4;
|
|
401
447
|
} catch {
|
|
402
|
-
if (version === generation
|
|
448
|
+
if (version === generation)
|
|
449
|
+
retryAfter = Date.now() + (Date.now() < fastPollUntil ? 2e3 : 3e4);
|
|
450
|
+
if (version === generation && offlinePro)
|
|
451
|
+
update(true, true, offlinePro.account);
|
|
452
|
+
else if (version === generation && Date.now() - lastCheck > 15 * 6e4)
|
|
403
453
|
update(false);
|
|
404
454
|
} finally {
|
|
405
455
|
if (version === generation && token)
|
|
@@ -438,7 +488,7 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
438
488
|
clearTimeout(waitTimer);
|
|
439
489
|
if (disposed || !waiting.length)
|
|
440
490
|
return;
|
|
441
|
-
waitTimer = setTimeout(() => void checkWaiting(), delay);
|
|
491
|
+
waitTimer = setTimeout(() => void checkWaiting().catch(() => scheduleWait(WAIT_SLOW_MS)), delay);
|
|
442
492
|
waitTimer.unref();
|
|
443
493
|
}
|
|
444
494
|
async function checkWaiting() {
|
|
@@ -479,8 +529,10 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
479
529
|
await writeSession(async () => {
|
|
480
530
|
if (disposed || round !== waitRound || w.origin !== billingOrigin(getOrigin()))
|
|
481
531
|
return;
|
|
482
|
-
|
|
532
|
+
if (w.email)
|
|
533
|
+
lastSignIn = w.email.trim().slice(0, 254);
|
|
483
534
|
await storage.write(sessionRecord({ origin: w.origin, token: w.token }));
|
|
535
|
+
clearWaiting();
|
|
484
536
|
++generation;
|
|
485
537
|
activeOrigin = w.origin;
|
|
486
538
|
applyEntitlement(body);
|
|
@@ -517,6 +569,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
517
569
|
}
|
|
518
570
|
if (typeof record.token !== "string" || typeof record.origin !== "string")
|
|
519
571
|
return;
|
|
572
|
+
if (typeof record.checkoutUrl === "string")
|
|
573
|
+
return;
|
|
520
574
|
const response = await entitlement(record.origin, record.token).catch(() => null);
|
|
521
575
|
if (!response?.ok)
|
|
522
576
|
return;
|
|
@@ -549,13 +603,20 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
549
603
|
return;
|
|
550
604
|
}
|
|
551
605
|
if (process.env.INKMAP_ALLOW_TEST_TELEMETRY !== "1") {
|
|
552
|
-
if (origin === "https://billing.example.com" || process.env.INKMAP_DISABLE_TELEMETRY === "1" || process.env.NODE_TEST_CONTEXT)
|
|
553
|
-
return;
|
|
554
|
-
const customHome = process.env.INKMAP_HOME || "";
|
|
555
|
-
const sysTmp = tmpdir();
|
|
556
|
-
if (customHome && (customHome === sysTmp || customHome.startsWith(sysTmp + 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-"))) {
|
|
606
|
+
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") {
|
|
557
607
|
return;
|
|
558
608
|
}
|
|
609
|
+
const norm = (p) => {
|
|
610
|
+
const clean = p.replace(/\\/g, "/");
|
|
611
|
+
return process.platform === "win32" ? clean.toLowerCase() : clean;
|
|
612
|
+
};
|
|
613
|
+
const sysTmp = norm(tmpdir()).replace(/\/+$/, "");
|
|
614
|
+
const homesToCheck = [process.env.INKMAP_HOME || "", homedir()].filter(Boolean).map(norm);
|
|
615
|
+
for (const h of homesToCheck) {
|
|
616
|
+
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-")) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
559
620
|
}
|
|
560
621
|
const id = await (installIdPromise ??= localInstallId().catch(() => void 0));
|
|
561
622
|
if (disposed || !id || !pendingEvents.size)
|
|
@@ -587,12 +648,22 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
587
648
|
});
|
|
588
649
|
}
|
|
589
650
|
return {
|
|
590
|
-
async state() {
|
|
651
|
+
async state(options) {
|
|
591
652
|
await (trial ??= startTrial());
|
|
592
|
-
const interval = !current.pro && Date.now() < fastPollUntil ?
|
|
593
|
-
if (Date.now() - lastCheck >= interval)
|
|
653
|
+
const interval = !current.pro && Date.now() < fastPollUntil ? 2e3 : 6e4;
|
|
654
|
+
if (Date.now() - lastCheck >= interval && Date.now() >= retryAfter)
|
|
594
655
|
await refresh();
|
|
595
656
|
await parkUnpaidSession();
|
|
657
|
+
await reviewCounting;
|
|
658
|
+
if (options?.forUi && reviewDue && hasAccess(current)) {
|
|
659
|
+
reviewDue = false;
|
|
660
|
+
const usage = await readReviewUsage().catch(() => void 0);
|
|
661
|
+
if (usage && !usage.done) {
|
|
662
|
+
await writeReviewUsage({ ...usage, done: true }).catch(() => {
|
|
663
|
+
});
|
|
664
|
+
return { ...current, reviewPrompt: true };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
596
667
|
return current;
|
|
597
668
|
},
|
|
598
669
|
async connect(mode, localeHint) {
|
|
@@ -659,7 +730,9 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
659
730
|
if (cachedOrder && cachedOrder.origin === origin && cachedOrder.locale === loc && Date.now() - cachedOrder.at < 8e3) {
|
|
660
731
|
const hit = cachedOrder.result;
|
|
661
732
|
cachedOrder = void 0;
|
|
662
|
-
|
|
733
|
+
if (current.pro)
|
|
734
|
+
return { status: "active", state: current };
|
|
735
|
+
schedule(hit.status === "qr" || hit.status === "redirect" ? 2500 : 6e4);
|
|
663
736
|
return hit;
|
|
664
737
|
}
|
|
665
738
|
const version = generation;
|
|
@@ -670,6 +743,17 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
670
743
|
record = JSON.parse(stored);
|
|
671
744
|
} catch {
|
|
672
745
|
}
|
|
746
|
+
if (record?.origin === origin && typeof record.token === "string") {
|
|
747
|
+
const rights = await entitlement(origin, record.token).catch(() => null);
|
|
748
|
+
if (rights?.ok) {
|
|
749
|
+
const ent = await rights.json().catch(() => null);
|
|
750
|
+
if (ent && ent.active === true) {
|
|
751
|
+
applyEntitlement(ent);
|
|
752
|
+
schedule(6e4);
|
|
753
|
+
return { status: "active", state: current };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
673
757
|
const requestOrder = async (checkoutUrl, token, cookie, persist) => {
|
|
674
758
|
const res = await checkoutPost(checkoutUrl, "order", origin, {}, token, cookie, localeHint);
|
|
675
759
|
if (res.status === 401 || res.status === 403 || res.status === 404 || res.status === 410)
|
|
@@ -867,13 +951,16 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
867
951
|
if (version !== generation || disposed || origin !== billingOrigin(getOrigin()))
|
|
868
952
|
return phoneFailure();
|
|
869
953
|
clearWaiting();
|
|
954
|
+
const clean = phone.trim().slice(0, 254);
|
|
955
|
+
if (clean)
|
|
956
|
+
lastSignIn = clean;
|
|
870
957
|
await storage.write(sessionRecord({ origin, token, ...checkoutUrl && { checkoutUrl }, ...cookie && { cookie } }));
|
|
871
958
|
++generation;
|
|
872
959
|
activeOrigin = origin;
|
|
873
960
|
applyEntitlement(state);
|
|
874
961
|
if (cachedOrder?.result.status === "active")
|
|
875
962
|
cachedOrder.result.state = current;
|
|
876
|
-
schedule(cachedOrder?.result.status === "qr" ?
|
|
963
|
+
schedule(cachedOrder?.result.status === "qr" || cachedOrder?.result.status === "redirect" ? 2500 : 6e4);
|
|
877
964
|
return { ok: true, value: current };
|
|
878
965
|
});
|
|
879
966
|
} catch {
|
|
@@ -924,6 +1011,8 @@ function licenseService(storage, getOrigin, { loginOnly = false, host: defaultHo
|
|
|
924
1011
|
if (event !== "app_open") {
|
|
925
1012
|
pendingEvents.set(event, Math.min(1e3, (pendingEvents.get(event) ?? 0) + count));
|
|
926
1013
|
}
|
|
1014
|
+
if (reviewPrompt && !process.env.CI && (event === "doc_open" || event === "doc_edit"))
|
|
1015
|
+
countForReview(event, count);
|
|
927
1016
|
if (telemetryTimer)
|
|
928
1017
|
return;
|
|
929
1018
|
telemetryTimer = setTimeout(() => {
|
|
@@ -996,6 +1085,25 @@ async function atomicCreateIfMissing(path, initialContent) {
|
|
|
996
1085
|
return await readFile(path, "utf8");
|
|
997
1086
|
}
|
|
998
1087
|
}
|
|
1088
|
+
var REVIEW_MIN_OPENS = 5;
|
|
1089
|
+
var REVIEW_MIN_EDITS = 3;
|
|
1090
|
+
var reviewUsagePath = () => join(process.env.INKMAP_HOME || join(homedir(), ".inkmap"), "review-prompt");
|
|
1091
|
+
async function readReviewUsage() {
|
|
1092
|
+
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
|
|
1093
|
+
try {
|
|
1094
|
+
const raw = JSON.parse(await readFile(reviewUsagePath(), "utf8"));
|
|
1095
|
+
return { opens: count(raw.opens), edits: count(raw.edits), done: raw.done === true };
|
|
1096
|
+
} catch {
|
|
1097
|
+
return { opens: 0, edits: 0, done: false };
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
async function writeReviewUsage(usage) {
|
|
1101
|
+
const path = reviewUsagePath();
|
|
1102
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
1103
|
+
const temporary = path + "." + randomUUID();
|
|
1104
|
+
await writeFile(temporary, JSON.stringify(usage), { mode: 384 });
|
|
1105
|
+
await rename(temporary, path);
|
|
1106
|
+
}
|
|
999
1107
|
async function localInstallId() {
|
|
1000
1108
|
const path = join(process.env.INKMAP_HOME || join(homedir(), ".inkmap"), "install-id");
|
|
1001
1109
|
const generated = "inst_" + randomUUID().replace(/-/g, "").slice(0, 24);
|
|
@@ -1027,18 +1135,50 @@ async function localTrialDeadline() {
|
|
|
1027
1135
|
}
|
|
1028
1136
|
|
|
1029
1137
|
// packages/cli/dist/server.js
|
|
1030
|
-
import { spawn } from "node:child_process";
|
|
1031
1138
|
import { createHash, randomBytes } from "node:crypto";
|
|
1032
1139
|
import { watch } from "node:fs";
|
|
1033
1140
|
import { lstat as lstat2, mkdir as mkdir2, readFile as readFile3, realpath as realpath2, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
1034
1141
|
import { createServer } from "node:http";
|
|
1035
1142
|
import { homedir as homedir3 } from "node:os";
|
|
1036
|
-
import { basename as basename2, delimiter as delimiter2, dirname as dirname3, extname, join as join3, normalize, relative as relative2, resolve as resolve2, sep as
|
|
1143
|
+
import { basename as basename2, delimiter as delimiter2, dirname as dirname3, extname, join as join3, normalize, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
1144
|
+
|
|
1145
|
+
// packages/cli/dist/open-browser.js
|
|
1146
|
+
import { spawn } from "node:child_process";
|
|
1147
|
+
function run(cmd, args, launched = false) {
|
|
1148
|
+
return new Promise((done) => {
|
|
1149
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
1150
|
+
child.on("error", () => done(false));
|
|
1151
|
+
if (launched)
|
|
1152
|
+
child.on("spawn", () => done(true));
|
|
1153
|
+
else
|
|
1154
|
+
child.on("exit", (code) => done(code === 0));
|
|
1155
|
+
child.unref();
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
async function openBrowserWindow(url) {
|
|
1159
|
+
if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url))
|
|
1160
|
+
return;
|
|
1161
|
+
if (process.platform === "darwin") {
|
|
1162
|
+
if (await run("open", ["-a", "Google Chrome", url]))
|
|
1163
|
+
return;
|
|
1164
|
+
await run("open", [url]);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
if (process.platform === "win32") {
|
|
1168
|
+
if (await run("cmd", ["/c", "start", "", "chrome", url]))
|
|
1169
|
+
return;
|
|
1170
|
+
await run("cmd", ["/c", "start", "", url]);
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (await run("google-chrome", [url], true))
|
|
1174
|
+
return;
|
|
1175
|
+
await run("xdg-open", [url], true);
|
|
1176
|
+
}
|
|
1037
1177
|
|
|
1038
1178
|
// packages/cli/dist/workspace-fs.js
|
|
1039
1179
|
import { lstat, readdir, readFile as readFile2, realpath } from "node:fs/promises";
|
|
1040
1180
|
import { homedir as homedir2 } from "node:os";
|
|
1041
|
-
import { basename, delimiter, dirname as dirname2, isAbsolute, join as join2, posix, relative, resolve, sep
|
|
1181
|
+
import { basename, delimiter, dirname as dirname2, isAbsolute, join as join2, posix, relative, resolve, sep, win32 } from "node:path";
|
|
1042
1182
|
var MAX_MARKDOWN_BYTES = 5 * 1024 * 1024;
|
|
1043
1183
|
var SKIP_SCAN_DIRS = /* @__PURE__ */ new Set([
|
|
1044
1184
|
".git",
|
|
@@ -1067,13 +1207,13 @@ function insideOrEqual(root, target) {
|
|
|
1067
1207
|
if (root === target)
|
|
1068
1208
|
return true;
|
|
1069
1209
|
const rel = relative(root, target);
|
|
1070
|
-
return Boolean(rel && !isAbsolute(rel) && rel !== ".." && !rel.startsWith(".." +
|
|
1210
|
+
return Boolean(rel && !isAbsolute(rel) && rel !== ".." && !rel.startsWith(".." + sep));
|
|
1071
1211
|
}
|
|
1072
1212
|
function hasHiddenSegment(root, target) {
|
|
1073
1213
|
const rel = relative(root, target);
|
|
1074
1214
|
if (!rel || rel === ".")
|
|
1075
1215
|
return false;
|
|
1076
|
-
return rel.split(
|
|
1216
|
+
return rel.split(sep).some((part) => part.startsWith("."));
|
|
1077
1217
|
}
|
|
1078
1218
|
async function findProjectRoot(filePath) {
|
|
1079
1219
|
const home = await realpath(homedir2()).catch(() => homedir2());
|
|
@@ -1205,13 +1345,18 @@ async function fileSource(file, log = () => {
|
|
|
1205
1345
|
log(`\u5DF2\u5199\u56DE ${path}`);
|
|
1206
1346
|
},
|
|
1207
1347
|
watch(onChange) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1348
|
+
try {
|
|
1349
|
+
const watcher = watch(dir, (_, changed) => {
|
|
1350
|
+
if (!changed || changed === basename2(path))
|
|
1351
|
+
onChange();
|
|
1352
|
+
});
|
|
1353
|
+
watcher.on("error", () => {
|
|
1354
|
+
});
|
|
1355
|
+
return () => watcher.close();
|
|
1356
|
+
} catch {
|
|
1357
|
+
return () => {
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1215
1360
|
},
|
|
1216
1361
|
readView: () => readDiskViewState(path),
|
|
1217
1362
|
writeView: (state) => writeDiskViewState(path, state)
|
|
@@ -1225,37 +1370,12 @@ function within(root, rel, allowAbsoluteInRoot = false) {
|
|
|
1225
1370
|
return null;
|
|
1226
1371
|
}
|
|
1227
1372
|
const resolvedRoot = resolve2(root);
|
|
1228
|
-
const base = resolvedRoot.endsWith(
|
|
1373
|
+
const base = resolvedRoot.endsWith(sep2) ? resolvedRoot : resolvedRoot + sep2;
|
|
1229
1374
|
const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? normalize(decoded) : normalize(join3(resolvedRoot, decoded));
|
|
1230
1375
|
return full.startsWith(base) ? full : null;
|
|
1231
1376
|
}
|
|
1232
|
-
async function openBrowserWindow(url) {
|
|
1233
|
-
if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url))
|
|
1234
|
-
return;
|
|
1235
|
-
const run = (cmd, args) => new Promise((done) => {
|
|
1236
|
-
const child = spawn(cmd, args, { stdio: "ignore", detached: true });
|
|
1237
|
-
child.on("error", () => done(false));
|
|
1238
|
-
child.on("exit", (code) => done(code === 0));
|
|
1239
|
-
child.unref();
|
|
1240
|
-
});
|
|
1241
|
-
if (process.platform === "darwin") {
|
|
1242
|
-
if (await run("open", ["-a", "Google Chrome", url]))
|
|
1243
|
-
return;
|
|
1244
|
-
await run("open", [url]);
|
|
1245
|
-
return;
|
|
1246
|
-
}
|
|
1247
|
-
if (process.platform === "win32") {
|
|
1248
|
-
if (await run("cmd", ["/c", "start", "", "chrome", url]))
|
|
1249
|
-
return;
|
|
1250
|
-
await run("cmd", ["/c", "start", "", url]);
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
if (await run("google-chrome", [url]))
|
|
1254
|
-
return;
|
|
1255
|
-
await run("xdg-open", [url]);
|
|
1256
|
-
}
|
|
1257
1377
|
async function serve({ source: initialSource, webRoot: webRoot2, port = 4377, host = "127.0.0.1", log = () => {
|
|
1258
|
-
}, license, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false,
|
|
1378
|
+
}, license, sidebar = false, sidebarPurchase = false, sidebarAccountNavigation = false, workspaceRoots = [], confineToWorkspaceRoots = false, openSource = (path) => fileSource(path, log), allowPurchase = true }) {
|
|
1259
1379
|
if (sidebar && host !== "127.0.0.1")
|
|
1260
1380
|
throw new Error("The sidebar bridge requires loopback.");
|
|
1261
1381
|
const prefix2 = sidebar ? `/s/${randomBytes(24).toString("hex")}/` : "/";
|
|
@@ -1474,7 +1594,6 @@ data: ${JSON.stringify(data)}
|
|
|
1474
1594
|
if (url.pathname === "/api/capabilities" && req.method === "GET") {
|
|
1475
1595
|
return json2(res, 200, {
|
|
1476
1596
|
purchase: canPurchase,
|
|
1477
|
-
...ideWorkspace && { ideWorkspace: true },
|
|
1478
1597
|
...sidebarAccountNavigation && { accountNavigation: "host" }
|
|
1479
1598
|
});
|
|
1480
1599
|
}
|
|
@@ -1495,6 +1614,8 @@ data: ${JSON.stringify(data)}
|
|
|
1495
1614
|
const { md, baseVersion } = JSON.parse(await readBody2(req));
|
|
1496
1615
|
if (typeof md !== "string")
|
|
1497
1616
|
return json2(res, 400, { error: zh() ? "md \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002" : "md must be a string." });
|
|
1617
|
+
if (Buffer.byteLength(md) > MAX_MARKDOWN_BYTES)
|
|
1618
|
+
return json2(res, 413, { error: zh() ? "\u6587\u6863\u8FC7\u5927\u3002" : "Document too large." });
|
|
1498
1619
|
if (!hasAccess(await license?.state() ?? { pro: false }))
|
|
1499
1620
|
return json2(res, 403, { error: "Inkmap trial expired" });
|
|
1500
1621
|
return await serialized(async () => {
|
|
@@ -1512,7 +1633,7 @@ data: ${JSON.stringify(data)}
|
|
|
1512
1633
|
});
|
|
1513
1634
|
}
|
|
1514
1635
|
if (url.pathname === "/api/license" && req.method === "GET")
|
|
1515
|
-
return json2(res, 200, await license?.state() ?? { pro: false });
|
|
1636
|
+
return json2(res, 200, await license?.state({ forUi: true }) ?? { pro: false });
|
|
1516
1637
|
if (url.pathname === "/api/open" && req.method === "POST") {
|
|
1517
1638
|
if (!sameOriginWrite())
|
|
1518
1639
|
return json2(res, 403, { error: "forbidden" });
|
|
@@ -1526,7 +1647,7 @@ data: ${JSON.stringify(data)}
|
|
|
1526
1647
|
if (!sameOriginWrite())
|
|
1527
1648
|
return json2(res, 403, { error: "forbidden" });
|
|
1528
1649
|
const { event } = JSON.parse(await readBody2(req));
|
|
1529
|
-
if (typeof event === "string" && event)
|
|
1650
|
+
if (typeof event === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(event))
|
|
1530
1651
|
license?.track?.(event);
|
|
1531
1652
|
return json2(res, 200, { ok: true });
|
|
1532
1653
|
}
|
|
@@ -1725,7 +1846,7 @@ async function workspaceFile(ctx, address) {
|
|
|
1725
1846
|
};
|
|
1726
1847
|
const [root, path] = await Promise.all([local(header.cwd), local(file.path)]);
|
|
1727
1848
|
const child = relative3(root, path);
|
|
1728
|
-
if (!child || isAbsolute2(child) || child === ".." || child.startsWith(".." +
|
|
1849
|
+
if (!child || isAbsolute2(child) || child === ".." || child.startsWith(".." + sep3) || !/\.md$/i.test(path)) {
|
|
1729
1850
|
throw new FileUnavailable();
|
|
1730
1851
|
}
|
|
1731
1852
|
return { root, path };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-inkmap",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
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",
|