dsh-mcviseron-plugin 0.6.5 → 0.6.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.
- package/CHANGELOG.md +31 -0
- package/README.en.md +17 -4
- package/README.md +19 -6
- package/docs/auth-cookie.md +61 -0
- package/docs/auto-review-context.md +65 -0
- package/docs/automation-task.md +1 -1
- package/docs/dsh-cookie-launcher.md +55 -0
- package/docs/release.md +3 -3
- package/docs/session-end.md +4 -1
- package/lib/auto-review-fix.js +253 -23
- package/lib/client.js +199 -9
- package/lib/index.js +559 -125
- package/package.json +23 -18
- package/scripts/dsh-cookie-launcher/clean-dsh-auth-cookies.py +97 -0
- package/scripts/dsh-cookie-launcher/launch-dsh.vbs +16 -0
- package/scripts/install-dsh-cookie-launcher.ps1 +48 -0
- package/src/api.ts +6 -0
- package/src/auth-cookie/index.ts +175 -0
- package/src/auto-review-fix/index.ts +9 -0
- package/src/client/ConfigForm.tsx +3 -0
- package/src/client/SessionEndControl.tsx +3 -0
- package/src/client/SessionEndGlobalNotice.ts +183 -0
- package/src/client/SettingsSection.tsx +4 -0
- package/src/client/index.ts +15 -0
- package/src/client/locales.ts +14 -0
- package/src/components/auto-review-fix/index.ts +8 -0
- package/src/components/auto-review-fix/review-context.ts +285 -0
- package/src/index.ts +2 -0
- package/src/session-end/index.ts +85 -17
package/lib/index.js
CHANGED
|
@@ -11289,7 +11289,11 @@ var MCVISERON_API = {
|
|
|
11289
11289
|
};
|
|
11290
11290
|
var SESSION_END_API = {
|
|
11291
11291
|
state: "/api/dsh-mcviseron/session-end/state",
|
|
11292
|
-
set: "/api/dsh-mcviseron/session-end/set"
|
|
11292
|
+
set: "/api/dsh-mcviseron/session-end/set",
|
|
11293
|
+
global: "/api/dsh-mcviseron/session-end/global"
|
|
11294
|
+
};
|
|
11295
|
+
var AUTH_COOKIE_API = {
|
|
11296
|
+
prune: "/api/dsh-mcviseron/auth-cookies/prune"
|
|
11293
11297
|
};
|
|
11294
11298
|
|
|
11295
11299
|
// src/namespace.ts
|
|
@@ -11308,10 +11312,10 @@ function parseTimeOfDay(value) {
|
|
|
11308
11312
|
return Number(match[1]) * 60 + Number(match[2]);
|
|
11309
11313
|
}
|
|
11310
11314
|
function normalizeScheduleConfig(input) {
|
|
11311
|
-
const
|
|
11312
|
-
const lightStart = typeof
|
|
11313
|
-
const lightEnd = typeof
|
|
11314
|
-
const enabled = typeof
|
|
11315
|
+
const record2 = input !== null && typeof input === "object" ? input : {};
|
|
11316
|
+
const lightStart = typeof record2.lightStart === "string" && parseTimeOfDay(record2.lightStart) !== void 0 ? record2.lightStart : DEFAULT_SCHEDULE_CONFIG.lightStart;
|
|
11317
|
+
const lightEnd = typeof record2.lightEnd === "string" && parseTimeOfDay(record2.lightEnd) !== void 0 ? record2.lightEnd : DEFAULT_SCHEDULE_CONFIG.lightEnd;
|
|
11318
|
+
const enabled = typeof record2.enabled === "boolean" ? record2.enabled : DEFAULT_SCHEDULE_CONFIG.enabled;
|
|
11315
11319
|
return { enabled, lightStart, lightEnd };
|
|
11316
11320
|
}
|
|
11317
11321
|
|
|
@@ -11425,15 +11429,15 @@ function unwrapValue(value) {
|
|
|
11425
11429
|
}
|
|
11426
11430
|
function toPluginView(descriptor) {
|
|
11427
11431
|
const plain = toPlain(unwrapValue(descriptor.value));
|
|
11428
|
-
const
|
|
11432
|
+
const record2 = isRecord(plain) ? plain : {};
|
|
11429
11433
|
return {
|
|
11430
11434
|
ns: String(descriptor.ns),
|
|
11431
11435
|
value: {
|
|
11432
11436
|
...normalizeScheduleConfig(plain),
|
|
11433
|
-
autoReviewFix: isRecord(
|
|
11434
|
-
taskGuard: isRecord(
|
|
11435
|
-
restart: isRecord(
|
|
11436
|
-
sessionEnd: isRecord(
|
|
11437
|
+
autoReviewFix: isRecord(record2.autoReviewFix) ? record2.autoReviewFix : {},
|
|
11438
|
+
taskGuard: isRecord(record2.taskGuard) ? record2.taskGuard : {},
|
|
11439
|
+
restart: isRecord(record2.restart) ? record2.restart : {},
|
|
11440
|
+
sessionEnd: isRecord(record2.sessionEnd) ? record2.sessionEnd : {}
|
|
11437
11441
|
},
|
|
11438
11442
|
revision: descriptor.revision
|
|
11439
11443
|
};
|
|
@@ -11468,11 +11472,11 @@ function makeSettingsRoutes(settings) {
|
|
|
11468
11472
|
if (body === void 0 || typeof body !== "object" || body === null) {
|
|
11469
11473
|
return json(res, 400, { ok: false, code: "settings-rejected", message: "unreadable JSON body" });
|
|
11470
11474
|
}
|
|
11471
|
-
const
|
|
11472
|
-
if (
|
|
11475
|
+
const record2 = body;
|
|
11476
|
+
if (record2.ns !== MCVISERON_SETTINGS_NAMESPACE || !Array.isArray(record2.ops)) {
|
|
11473
11477
|
return json(res, 400, { ok: false, code: "settings-rejected", message: "malformed settings request" });
|
|
11474
11478
|
}
|
|
11475
|
-
const ops =
|
|
11479
|
+
const ops = record2.ops;
|
|
11476
11480
|
const valid = ops.every((op) => {
|
|
11477
11481
|
if (op.op !== "set" && op.op !== "unset") return false;
|
|
11478
11482
|
const rule = ruleFor(op.path);
|
|
@@ -11483,7 +11487,7 @@ function makeSettingsRoutes(settings) {
|
|
|
11483
11487
|
if (!valid) {
|
|
11484
11488
|
return json(res, 400, { ok: false, code: "settings-rejected", message: "malformed settings operation" });
|
|
11485
11489
|
}
|
|
11486
|
-
const expectedRevision = typeof
|
|
11490
|
+
const expectedRevision = typeof record2.expectedRevision === "number" ? record2.expectedRevision : void 0;
|
|
11487
11491
|
try {
|
|
11488
11492
|
await settings.mutate(MCVISERON_SETTINGS_NAMESPACE, ops, expectedRevision);
|
|
11489
11493
|
} catch (error) {
|
|
@@ -11565,18 +11569,382 @@ function apply(ctx, _config) {
|
|
|
11565
11569
|
});
|
|
11566
11570
|
}
|
|
11567
11571
|
|
|
11572
|
+
// src/auth-cookie/index.ts
|
|
11573
|
+
var auth_cookie_exports = {};
|
|
11574
|
+
__export(auth_cookie_exports, {
|
|
11575
|
+
AUTH_COOKIE_PREFIX: () => AUTH_COOKIE_PREFIX,
|
|
11576
|
+
apply: () => apply2,
|
|
11577
|
+
authCookieName: () => authCookieName,
|
|
11578
|
+
authCookieNames: () => authCookieNames,
|
|
11579
|
+
expiredAuthCookie: () => expiredAuthCookie,
|
|
11580
|
+
inject: () => inject2,
|
|
11581
|
+
makeAuthCookieRoutes: () => makeAuthCookieRoutes,
|
|
11582
|
+
pruneCookieHeaders: () => pruneCookieHeaders,
|
|
11583
|
+
pruneScript: () => pruneScript,
|
|
11584
|
+
requestAuthority: () => requestAuthority,
|
|
11585
|
+
staleAuthCookieNames: () => staleAuthCookieNames
|
|
11586
|
+
});
|
|
11587
|
+
import { createHash } from "node:crypto";
|
|
11588
|
+
import { appendFileSync } from "node:fs";
|
|
11589
|
+
import { tmpdir } from "node:os";
|
|
11590
|
+
import { join } from "node:path";
|
|
11591
|
+
var AUTH_COOKIE_PREFIX = "dsh-auth-";
|
|
11592
|
+
var EXPIRED_AT = "Thu, 01 Jan 1970 00:00:00 GMT";
|
|
11593
|
+
function logPrune(authority, pruned) {
|
|
11594
|
+
try {
|
|
11595
|
+
appendFileSync(
|
|
11596
|
+
join(tmpdir(), "dsh-mcviseron-auth-cookie.log"),
|
|
11597
|
+
(/* @__PURE__ */ new Date()).toISOString() + " pruned=" + pruned + " authority=" + authority + "\n",
|
|
11598
|
+
"utf8"
|
|
11599
|
+
);
|
|
11600
|
+
} catch {
|
|
11601
|
+
}
|
|
11602
|
+
}
|
|
11603
|
+
function authCookieName(authority) {
|
|
11604
|
+
return AUTH_COOKIE_PREFIX + createHash("sha256").update(authority).digest("base64url");
|
|
11605
|
+
}
|
|
11606
|
+
function requestAuthority(host, secure) {
|
|
11607
|
+
if (typeof host !== "string" || host === "") return void 0;
|
|
11608
|
+
try {
|
|
11609
|
+
const url = new URL((secure ? "https:" : "http:") + "//" + host);
|
|
11610
|
+
return secure ? url.origin : url.host;
|
|
11611
|
+
} catch {
|
|
11612
|
+
return void 0;
|
|
11613
|
+
}
|
|
11614
|
+
}
|
|
11615
|
+
function validAuthCookieName(name) {
|
|
11616
|
+
if (!name.startsWith(AUTH_COOKIE_PREFIX)) return false;
|
|
11617
|
+
return /^[A-Za-z0-9_-]+$/.test(name.slice(AUTH_COOKIE_PREFIX.length));
|
|
11618
|
+
}
|
|
11619
|
+
function authCookieNames(header) {
|
|
11620
|
+
if (typeof header !== "string" || header === "") return [];
|
|
11621
|
+
const names = /* @__PURE__ */ new Set();
|
|
11622
|
+
for (const segment of header.split(";")) {
|
|
11623
|
+
const at = segment.indexOf("=");
|
|
11624
|
+
const name = (at === -1 ? segment : segment.slice(0, at)).trim();
|
|
11625
|
+
if (validAuthCookieName(name)) names.add(name);
|
|
11626
|
+
}
|
|
11627
|
+
return [...names];
|
|
11628
|
+
}
|
|
11629
|
+
function staleAuthCookieNames(header, currentName) {
|
|
11630
|
+
return authCookieNames(header).filter((name) => name !== currentName);
|
|
11631
|
+
}
|
|
11632
|
+
function expiredAuthCookie(name, secure) {
|
|
11633
|
+
return name + "=; Max-Age=0; Path=/; Expires=" + EXPIRED_AT + "; HttpOnly; SameSite=Strict" + (secure ? "; Secure" : "");
|
|
11634
|
+
}
|
|
11635
|
+
function pruneCookieHeaders(req, secure) {
|
|
11636
|
+
const authority = requestAuthority(req.headers.host, secure);
|
|
11637
|
+
if (authority === void 0) return [];
|
|
11638
|
+
const current = authCookieName(authority);
|
|
11639
|
+
return staleAuthCookieNames(req.headers.cookie, current).map((name) => expiredAuthCookie(name, secure));
|
|
11640
|
+
}
|
|
11641
|
+
function pruneScript() {
|
|
11642
|
+
return "(function(){try{fetch(" + JSON.stringify(AUTH_COOKIE_API.prune) + ',{method:"POST",credentials:"same-origin",cache:"no-store"}).catch(function(){})}catch(e){}})()';
|
|
11643
|
+
}
|
|
11644
|
+
function json2(res, status, body, extra = {}) {
|
|
11645
|
+
res.writeHead(status, {
|
|
11646
|
+
"content-type": "application/json; charset=utf-8",
|
|
11647
|
+
"cache-control": "no-store",
|
|
11648
|
+
...extra
|
|
11649
|
+
});
|
|
11650
|
+
res.end(JSON.stringify(body));
|
|
11651
|
+
}
|
|
11652
|
+
function makeAuthCookieRoutes(options) {
|
|
11653
|
+
const route = {
|
|
11654
|
+
kind: "exact",
|
|
11655
|
+
path: AUTH_COOKIE_API.prune,
|
|
11656
|
+
handler: (req, res) => {
|
|
11657
|
+
if (req.method !== "POST") {
|
|
11658
|
+
json2(res, 405, { ok: false, error: "method-not-allowed" });
|
|
11659
|
+
return;
|
|
11660
|
+
}
|
|
11661
|
+
if (!isLoopbackRequest(req)) {
|
|
11662
|
+
json2(res, 403, { ok: false, error: "forbidden" });
|
|
11663
|
+
return;
|
|
11664
|
+
}
|
|
11665
|
+
const secure = options.secure();
|
|
11666
|
+
const authority = requestAuthority(req.headers.host, secure);
|
|
11667
|
+
if (authority === void 0) {
|
|
11668
|
+
json2(res, 400, { ok: false, error: "host-required" });
|
|
11669
|
+
return;
|
|
11670
|
+
}
|
|
11671
|
+
const stale = staleAuthCookieNames(req.headers.cookie, authCookieName(authority));
|
|
11672
|
+
logPrune(authority, stale.length);
|
|
11673
|
+
const extra = stale.length === 0 ? {} : { "set-cookie": stale.map((name) => expiredAuthCookie(name, secure)) };
|
|
11674
|
+
json2(res, 200, { ok: true, pruned: stale.length }, extra);
|
|
11675
|
+
}
|
|
11676
|
+
};
|
|
11677
|
+
return [route];
|
|
11678
|
+
}
|
|
11679
|
+
function eventBusOf(ctx) {
|
|
11680
|
+
const root = ctx.root;
|
|
11681
|
+
return root ?? ctx;
|
|
11682
|
+
}
|
|
11683
|
+
function installIndexInjection(ctx) {
|
|
11684
|
+
const bus = eventBusOf(ctx);
|
|
11685
|
+
if (typeof bus.on !== "function") return;
|
|
11686
|
+
try {
|
|
11687
|
+
ctx.effect(() => {
|
|
11688
|
+
const dispose = bus.on?.("webserver/index-inject", (table) => {
|
|
11689
|
+
if (!Array.isArray(table)) return;
|
|
11690
|
+
table.push({ kind: "script", placement: "head", text: pruneScript() });
|
|
11691
|
+
});
|
|
11692
|
+
return () => {
|
|
11693
|
+
if (typeof dispose === "function") dispose();
|
|
11694
|
+
};
|
|
11695
|
+
}, "mcviseron-auth-cookie: index injection");
|
|
11696
|
+
} catch {
|
|
11697
|
+
}
|
|
11698
|
+
}
|
|
11699
|
+
var inject2 = ["webServer"];
|
|
11700
|
+
function apply2(ctx) {
|
|
11701
|
+
const secure = () => {
|
|
11702
|
+
try {
|
|
11703
|
+
return ctx.webServer.protocol === "https:";
|
|
11704
|
+
} catch {
|
|
11705
|
+
return false;
|
|
11706
|
+
}
|
|
11707
|
+
};
|
|
11708
|
+
const routes = makeAuthCookieRoutes({ secure });
|
|
11709
|
+
ctx.effect(() => {
|
|
11710
|
+
const disposers = routes.map((route) => ctx.webServer.register(route));
|
|
11711
|
+
return () => {
|
|
11712
|
+
for (const dispose of disposers) dispose();
|
|
11713
|
+
};
|
|
11714
|
+
}, "mcviseron-auth-cookie: prune route");
|
|
11715
|
+
installIndexInjection(ctx);
|
|
11716
|
+
}
|
|
11717
|
+
|
|
11568
11718
|
// src/auto-review-fix/index.ts
|
|
11569
11719
|
var auto_review_fix_exports = {};
|
|
11570
11720
|
__export(auto_review_fix_exports, {
|
|
11571
11721
|
Config: () => Config2,
|
|
11572
11722
|
DEFAULT_AUTO_REVIEW_CONFIG: () => DEFAULT_AUTO_REVIEW_CONFIG,
|
|
11573
|
-
apply: () =>
|
|
11723
|
+
apply: () => apply3
|
|
11574
11724
|
});
|
|
11575
11725
|
import z2 from "@deepseek-ai/schemastery";
|
|
11576
11726
|
|
|
11577
11727
|
// src/components/auto-review-fix/index.ts
|
|
11578
11728
|
import { randomUUID } from "node:crypto";
|
|
11579
11729
|
|
|
11730
|
+
// src/components/auto-review-fix/review-context.ts
|
|
11731
|
+
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
11732
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
11733
|
+
import { join as join2 } from "node:path";
|
|
11734
|
+
var REVIEW_MARKER = "REVIEW_POLICY";
|
|
11735
|
+
var REVIEW_MARKER_2 = "final authorization reviewer";
|
|
11736
|
+
var HISTORY_HEADER = "FILTERED_HISTORY\n\n";
|
|
11737
|
+
var PROJECT_HEADER = "PROJECT_INSTRUCTIONS\n\n";
|
|
11738
|
+
var ACTION_HEADER = "\n\nPENDING_ACTION\n\n";
|
|
11739
|
+
var USER_TEXT_CHARS = 4e3;
|
|
11740
|
+
var TOOL_ARGUMENT_CHARS = 2e3;
|
|
11741
|
+
var PROJECT_MAX_CHARS = 4e4;
|
|
11742
|
+
function record(value) {
|
|
11743
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
11744
|
+
}
|
|
11745
|
+
function textOf(message) {
|
|
11746
|
+
if (!record(message) || !Array.isArray(message.content)) return void 0;
|
|
11747
|
+
const texts = [];
|
|
11748
|
+
for (const block of message.content) {
|
|
11749
|
+
if (!record(block) || block.type !== "text" || typeof block.text !== "string") return void 0;
|
|
11750
|
+
texts.push(block.text);
|
|
11751
|
+
}
|
|
11752
|
+
return texts.join("");
|
|
11753
|
+
}
|
|
11754
|
+
function isAutoReviewRequest(options) {
|
|
11755
|
+
if (!record(options)) return false;
|
|
11756
|
+
const system = options.system;
|
|
11757
|
+
if (typeof system !== "string" || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false;
|
|
11758
|
+
if (!Array.isArray(options.messages) || options.messages.length === 0) return false;
|
|
11759
|
+
const text2 = textOf(options.messages[0]);
|
|
11760
|
+
return text2 !== void 0 && text2.includes(HISTORY_HEADER) && text2.includes(ACTION_HEADER);
|
|
11761
|
+
}
|
|
11762
|
+
function truncateText(text2, limit) {
|
|
11763
|
+
if (text2.length <= limit) return text2;
|
|
11764
|
+
return text2.slice(0, limit) + "\n\u2026[" + String(text2.length - limit) + " characters omitted]";
|
|
11765
|
+
}
|
|
11766
|
+
function compactBlock(block) {
|
|
11767
|
+
if (!record(block)) return { type: "text", text: "[non-text history block omitted from reviewer context]" };
|
|
11768
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
11769
|
+
return { ...block, text: truncateText(block.text, USER_TEXT_CHARS) };
|
|
11770
|
+
}
|
|
11771
|
+
return {
|
|
11772
|
+
type: "text",
|
|
11773
|
+
text: "[" + String(block.type ?? "attachment") + " omitted from reviewer context]"
|
|
11774
|
+
};
|
|
11775
|
+
}
|
|
11776
|
+
function compactEntry(entry) {
|
|
11777
|
+
if (!record(entry)) return { kind: "summary", role: "fact", content: [{ type: "text", text: "[invalid history entry omitted]" }] };
|
|
11778
|
+
if (entry.kind === "user-message" && Array.isArray(entry.content)) {
|
|
11779
|
+
return { ...entry, content: entry.content.map(compactBlock) };
|
|
11780
|
+
}
|
|
11781
|
+
if (entry.kind === "tool-call") {
|
|
11782
|
+
const value = entry.arguments;
|
|
11783
|
+
if (typeof value === "string") {
|
|
11784
|
+
return { ...entry, arguments: truncateText(value, TOOL_ARGUMENT_CHARS) };
|
|
11785
|
+
}
|
|
11786
|
+
if (value !== void 0) {
|
|
11787
|
+
let rendered;
|
|
11788
|
+
try {
|
|
11789
|
+
rendered = JSON.stringify(value) ?? "";
|
|
11790
|
+
} catch {
|
|
11791
|
+
rendered = "";
|
|
11792
|
+
}
|
|
11793
|
+
return { ...entry, arguments: truncateText(rendered, TOOL_ARGUMENT_CHARS) };
|
|
11794
|
+
}
|
|
11795
|
+
}
|
|
11796
|
+
return entry;
|
|
11797
|
+
}
|
|
11798
|
+
function protectedEntry(entry) {
|
|
11799
|
+
if (!record(entry)) return false;
|
|
11800
|
+
return entry.role === "human-instruction" || entry.role === "direct-parent-instruction";
|
|
11801
|
+
}
|
|
11802
|
+
function summaryEntry(omitted, originalChars) {
|
|
11803
|
+
return {
|
|
11804
|
+
kind: "summary",
|
|
11805
|
+
role: "fact",
|
|
11806
|
+
content: [{
|
|
11807
|
+
type: "text",
|
|
11808
|
+
text: "[auto-review-fix] " + String(omitted) + " earlier history entries omitted from the reviewer context (original history " + String(originalChars) + " chars). Current action and human instructions are retained."
|
|
11809
|
+
}]
|
|
11810
|
+
};
|
|
11811
|
+
}
|
|
11812
|
+
function jsonLength(value) {
|
|
11813
|
+
try {
|
|
11814
|
+
return JSON.stringify(value)?.length ?? 0;
|
|
11815
|
+
} catch {
|
|
11816
|
+
return Number.MAX_SAFE_INTEGER;
|
|
11817
|
+
}
|
|
11818
|
+
}
|
|
11819
|
+
function boundEntries(entries, maxChars, keepRecent) {
|
|
11820
|
+
const normalized = entries.map(compactEntry);
|
|
11821
|
+
const originalChars = jsonLength(normalized);
|
|
11822
|
+
const recentStart = Math.max(0, normalized.length - Math.max(1, keepRecent));
|
|
11823
|
+
const selected = normalized.filter((entry, index) => protectedEntry(entry) || index >= recentStart);
|
|
11824
|
+
let omitted = normalized.length - selected.length;
|
|
11825
|
+
while (selected.length > 1 && jsonLength(selected) > maxChars) {
|
|
11826
|
+
const at = selected.findIndex((entry) => !protectedEntry(entry));
|
|
11827
|
+
if (at < 0) selected.shift();
|
|
11828
|
+
else selected.splice(at, 1);
|
|
11829
|
+
omitted += 1;
|
|
11830
|
+
}
|
|
11831
|
+
if (omitted > 0) selected.unshift(summaryEntry(omitted, originalChars));
|
|
11832
|
+
return selected;
|
|
11833
|
+
}
|
|
11834
|
+
function parseArray(text2) {
|
|
11835
|
+
try {
|
|
11836
|
+
const value = JSON.parse(text2);
|
|
11837
|
+
return Array.isArray(value) ? value : void 0;
|
|
11838
|
+
} catch {
|
|
11839
|
+
return void 0;
|
|
11840
|
+
}
|
|
11841
|
+
}
|
|
11842
|
+
function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
|
|
11843
|
+
try {
|
|
11844
|
+
appendFileSync2(
|
|
11845
|
+
join2(tmpdir2(), "dsh-mcviseron-auto-review.log"),
|
|
11846
|
+
(/* @__PURE__ */ new Date()).toISOString() + " review context trimmed: " + String(originalChars) + " -> " + String(nextChars) + " chars, history " + String(originalEntries) + " -> " + String(nextEntries) + "\n",
|
|
11847
|
+
"utf8"
|
|
11848
|
+
);
|
|
11849
|
+
} catch {
|
|
11850
|
+
}
|
|
11851
|
+
}
|
|
11852
|
+
function trimReviewRequest(options, settings) {
|
|
11853
|
+
if (!settings.enabled || !isAutoReviewRequest(options)) return options;
|
|
11854
|
+
const messages = options.messages;
|
|
11855
|
+
const message = messages[0];
|
|
11856
|
+
const text2 = textOf(message);
|
|
11857
|
+
if (text2 === void 0) return options;
|
|
11858
|
+
const projectAt = text2.indexOf(PROJECT_HEADER);
|
|
11859
|
+
const historyAt = text2.indexOf(HISTORY_HEADER, projectAt + 1);
|
|
11860
|
+
const actionAt = text2.indexOf(ACTION_HEADER, historyAt + 1);
|
|
11861
|
+
if (projectAt < 0 || historyAt < 0 || actionAt < 0) return options;
|
|
11862
|
+
const projectJson = text2.slice(projectAt + PROJECT_HEADER.length, historyAt - 2);
|
|
11863
|
+
const historyJson = text2.slice(historyAt + HISTORY_HEADER.length, actionAt);
|
|
11864
|
+
const project = parseArray(projectJson);
|
|
11865
|
+
const history = parseArray(historyJson);
|
|
11866
|
+
if (project === void 0 || history === void 0) return options;
|
|
11867
|
+
const nextProject = boundEntries(project, PROJECT_MAX_CHARS, 4);
|
|
11868
|
+
const nextHistory = boundEntries(history, settings.maxHistoryChars, settings.keepRecentEntries);
|
|
11869
|
+
const nextText = text2.slice(0, projectAt) + PROJECT_HEADER + JSON.stringify(nextProject) + HISTORY_HEADER + JSON.stringify(nextHistory) + text2.slice(actionAt);
|
|
11870
|
+
if (nextText === text2) return options;
|
|
11871
|
+
logTrim(text2.length, nextText.length, history.length, nextHistory.length);
|
|
11872
|
+
const content = [{ type: "text", text: nextText }];
|
|
11873
|
+
return {
|
|
11874
|
+
...options,
|
|
11875
|
+
messages: [
|
|
11876
|
+
{ ...message, content },
|
|
11877
|
+
...messages.slice(1)
|
|
11878
|
+
]
|
|
11879
|
+
};
|
|
11880
|
+
}
|
|
11881
|
+
var guardedLlms = /* @__PURE__ */ new WeakMap();
|
|
11882
|
+
function whenService(ctx, name, run) {
|
|
11883
|
+
try {
|
|
11884
|
+
const inject5 = ctx.inject;
|
|
11885
|
+
if (typeof inject5 === "function") {
|
|
11886
|
+
inject5.call(ctx, [name], run);
|
|
11887
|
+
return;
|
|
11888
|
+
}
|
|
11889
|
+
const get = ctx.get;
|
|
11890
|
+
if (typeof get === "function" && get.call(ctx, name) !== void 0) run(ctx);
|
|
11891
|
+
} catch {
|
|
11892
|
+
}
|
|
11893
|
+
}
|
|
11894
|
+
function serviceOf(scope, name) {
|
|
11895
|
+
try {
|
|
11896
|
+
const direct = scope[name];
|
|
11897
|
+
if (direct !== void 0) return direct;
|
|
11898
|
+
} catch {
|
|
11899
|
+
}
|
|
11900
|
+
try {
|
|
11901
|
+
const get = scope.get;
|
|
11902
|
+
return typeof get === "function" ? get.call(scope, name) : void 0;
|
|
11903
|
+
} catch {
|
|
11904
|
+
return void 0;
|
|
11905
|
+
}
|
|
11906
|
+
}
|
|
11907
|
+
function effectOf(scope, setup, label) {
|
|
11908
|
+
try {
|
|
11909
|
+
const effect = scope.effect;
|
|
11910
|
+
if (typeof effect === "function") effect.call(scope, setup, label);
|
|
11911
|
+
} catch {
|
|
11912
|
+
}
|
|
11913
|
+
}
|
|
11914
|
+
function installReviewContextGuard(ctx, settings) {
|
|
11915
|
+
if (!settings.enabled) return;
|
|
11916
|
+
whenService(ctx, "llm", (scope) => {
|
|
11917
|
+
const llm = serviceOf(scope, "llm");
|
|
11918
|
+
if (llm === null || typeof llm !== "object" || typeof llm.stream !== "function") return;
|
|
11919
|
+
const existing = guardedLlms.get(llm);
|
|
11920
|
+
if (existing !== void 0) {
|
|
11921
|
+
existing.settings = settings;
|
|
11922
|
+
return;
|
|
11923
|
+
}
|
|
11924
|
+
const original = llm.stream;
|
|
11925
|
+
const state = { settings };
|
|
11926
|
+
const wrapper = function(options) {
|
|
11927
|
+
let next = options;
|
|
11928
|
+
try {
|
|
11929
|
+
next = trimReviewRequest(options, state.settings);
|
|
11930
|
+
} catch {
|
|
11931
|
+
next = options;
|
|
11932
|
+
}
|
|
11933
|
+
return original.call(this, next);
|
|
11934
|
+
};
|
|
11935
|
+
try {
|
|
11936
|
+
llm.stream = wrapper;
|
|
11937
|
+
guardedLlms.set(llm, state);
|
|
11938
|
+
} catch {
|
|
11939
|
+
return;
|
|
11940
|
+
}
|
|
11941
|
+
effectOf(scope, () => () => {
|
|
11942
|
+
if (llm.stream === wrapper) llm.stream = original;
|
|
11943
|
+
guardedLlms.delete(llm);
|
|
11944
|
+
}, "mcviseron: restore llm.stream");
|
|
11945
|
+
});
|
|
11946
|
+
}
|
|
11947
|
+
|
|
11580
11948
|
// src/components/auto-review-fix/translate.ts
|
|
11581
11949
|
var TRANSLATION_LABEL = "\u3010\u5BA1\u67E5\u7406\u7531 \xB7 \u4E2D\u6587\u7FFB\u8BD1\u3011";
|
|
11582
11950
|
var SYSTEM_PROMPT = [
|
|
@@ -11743,14 +12111,19 @@ function normalizeConfig(config) {
|
|
|
11743
12111
|
timeoutMs: numberSetting(source, "translateTimeoutMs", 6e3, 500, 6e4),
|
|
11744
12112
|
maxChars: numberSetting(source, "translateMaxChars", 4e3, 100, 2e4),
|
|
11745
12113
|
provider: stringSetting(source, "translateProvider", ""),
|
|
11746
|
-
model: stringSetting(source, "translateModel", "")
|
|
12114
|
+
model: stringSetting(source, "translateModel", ""),
|
|
12115
|
+
reviewContext: {
|
|
12116
|
+
enabled: boolSetting(source, "reviewContextGuard", true),
|
|
12117
|
+
maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars", 12e4, 2e4, 6e5),
|
|
12118
|
+
keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries", 16, 4, 64)
|
|
12119
|
+
}
|
|
11747
12120
|
};
|
|
11748
12121
|
}
|
|
11749
|
-
function
|
|
12122
|
+
function whenService2(ctx, name, run) {
|
|
11750
12123
|
try {
|
|
11751
|
-
const
|
|
11752
|
-
if (typeof
|
|
11753
|
-
|
|
12124
|
+
const inject5 = ctx.inject;
|
|
12125
|
+
if (typeof inject5 === "function") {
|
|
12126
|
+
inject5.call(ctx, [name], run);
|
|
11754
12127
|
return;
|
|
11755
12128
|
}
|
|
11756
12129
|
const get = ctx.get;
|
|
@@ -11759,7 +12132,7 @@ function whenService(ctx, name, run) {
|
|
|
11759
12132
|
} catch {
|
|
11760
12133
|
}
|
|
11761
12134
|
}
|
|
11762
|
-
function
|
|
12135
|
+
function serviceOf2(scope, name) {
|
|
11763
12136
|
try {
|
|
11764
12137
|
const direct = scope[name];
|
|
11765
12138
|
if (direct !== void 0) return direct;
|
|
@@ -11772,7 +12145,7 @@ function serviceOf(scope, name) {
|
|
|
11772
12145
|
return void 0;
|
|
11773
12146
|
}
|
|
11774
12147
|
}
|
|
11775
|
-
function
|
|
12148
|
+
function effectOf2(scope, setup, label) {
|
|
11776
12149
|
try {
|
|
11777
12150
|
const effect = scope.effect;
|
|
11778
12151
|
if (typeof effect === "function") effect.call(scope, setup, label);
|
|
@@ -11790,8 +12163,8 @@ function rootIsActive(root) {
|
|
|
11790
12163
|
}
|
|
11791
12164
|
}
|
|
11792
12165
|
function installPresetGuard(ctx) {
|
|
11793
|
-
|
|
11794
|
-
const presets =
|
|
12166
|
+
whenService2(ctx, "permissionPresets", (scope) => {
|
|
12167
|
+
const presets = serviceOf2(scope, "permissionPresets");
|
|
11795
12168
|
if (presets === null || typeof presets !== "object") return;
|
|
11796
12169
|
if (typeof presets.set !== "function") return;
|
|
11797
12170
|
if (guardedPresets.has(presets)) return;
|
|
@@ -11812,18 +12185,18 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
11812
12185
|
if (!settings.enabled || request === null || typeof request !== "object") return request;
|
|
11813
12186
|
const display = request.displayReason;
|
|
11814
12187
|
if (display === null || typeof display !== "object" || Array.isArray(display)) return request;
|
|
11815
|
-
const
|
|
11816
|
-
const key = chineseKey(
|
|
12188
|
+
const record2 = display;
|
|
12189
|
+
const key = chineseKey(record2);
|
|
11817
12190
|
if (key === void 0) return request;
|
|
11818
|
-
const english = englishText(
|
|
12191
|
+
const english = englishText(record2);
|
|
11819
12192
|
if (english === void 0 || !isAutoReviewText(english)) return request;
|
|
11820
|
-
const localized =
|
|
12193
|
+
const localized = record2[key];
|
|
11821
12194
|
if (typeof localized !== "string" || hasTranslation(localized)) return request;
|
|
11822
12195
|
const excerpt = reviewerExcerpt(english);
|
|
11823
12196
|
if (excerpt.length === 0 || excerpt.length > settings.maxChars) return request;
|
|
11824
12197
|
if (isPredominantlyChinese(excerpt)) return request;
|
|
11825
12198
|
if (translationRoute(settings, request) === void 0) return request;
|
|
11826
|
-
const llm =
|
|
12199
|
+
const llm = serviceOf2(scope, "llm");
|
|
11827
12200
|
const translated = await translate(llm, settings, request, excerpt);
|
|
11828
12201
|
if (translated === void 0) return request;
|
|
11829
12202
|
const cleaned = cleanTranslation(translated);
|
|
@@ -11834,7 +12207,7 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
11834
12207
|
return {
|
|
11835
12208
|
...request,
|
|
11836
12209
|
...reasonWithTranslation !== originalReason ? { reason: reasonWithTranslation } : {},
|
|
11837
|
-
displayReason: { ...
|
|
12210
|
+
displayReason: { ...record2, [key]: withTranslation(localized, cleaned) }
|
|
11838
12211
|
};
|
|
11839
12212
|
}
|
|
11840
12213
|
function sessionIdOf(agent) {
|
|
@@ -11851,8 +12224,8 @@ function rejectionKey(agent, callId) {
|
|
|
11851
12224
|
return sessionId === "" ? "" : sessionId + ":" + callId;
|
|
11852
12225
|
}
|
|
11853
12226
|
function approvalReasonText(request) {
|
|
11854
|
-
const
|
|
11855
|
-
const display =
|
|
12227
|
+
const record2 = request;
|
|
12228
|
+
const display = record2.displayReason;
|
|
11856
12229
|
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
11857
12230
|
const key = chineseKey(display);
|
|
11858
12231
|
if (key !== void 0) {
|
|
@@ -11862,12 +12235,12 @@ function approvalReasonText(request) {
|
|
|
11862
12235
|
const english = englishText(display);
|
|
11863
12236
|
if (english !== void 0 && english !== "") return english;
|
|
11864
12237
|
}
|
|
11865
|
-
return typeof
|
|
12238
|
+
return typeof record2.reason === "string" ? record2.reason : "";
|
|
11866
12239
|
}
|
|
11867
12240
|
function isAutoReviewApproval(request) {
|
|
11868
|
-
const
|
|
11869
|
-
if (typeof
|
|
11870
|
-
const display =
|
|
12241
|
+
const record2 = request;
|
|
12242
|
+
if (typeof record2.reason === "string" && isAutoReviewText(record2.reason)) return true;
|
|
12243
|
+
const display = record2.displayReason;
|
|
11871
12244
|
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
11872
12245
|
const english = englishText(display);
|
|
11873
12246
|
if (english !== void 0 && isAutoReviewText(english)) return true;
|
|
@@ -11938,8 +12311,8 @@ function installRejectionRelay(ctx, relay) {
|
|
|
11938
12311
|
});
|
|
11939
12312
|
}
|
|
11940
12313
|
function installApprovalTranslation(ctx, settings, relay) {
|
|
11941
|
-
|
|
11942
|
-
const approval =
|
|
12314
|
+
whenService2(ctx, "approval", (scope) => {
|
|
12315
|
+
const approval = serviceOf2(scope, "approval");
|
|
11943
12316
|
if (approval === null || typeof approval !== "object") return;
|
|
11944
12317
|
const original = approval.request;
|
|
11945
12318
|
if (typeof original !== "function") return;
|
|
@@ -11967,7 +12340,7 @@ function installApprovalTranslation(ctx, settings, relay) {
|
|
|
11967
12340
|
} catch {
|
|
11968
12341
|
return;
|
|
11969
12342
|
}
|
|
11970
|
-
|
|
12343
|
+
effectOf2(scope, () => () => {
|
|
11971
12344
|
if (approval.request === wrapper) approval.request = call;
|
|
11972
12345
|
}, "mcviseron: restore approval.request");
|
|
11973
12346
|
});
|
|
@@ -11975,6 +12348,7 @@ function installApprovalTranslation(ctx, settings, relay) {
|
|
|
11975
12348
|
function installAutoReview(ctx, config) {
|
|
11976
12349
|
const settings = normalizeConfig(config);
|
|
11977
12350
|
if (settings.keepPresetGuard) installPresetGuard(ctx);
|
|
12351
|
+
if (settings.reviewContext.enabled) installReviewContextGuard(ctx, settings.reviewContext);
|
|
11978
12352
|
if (settings.enabled) {
|
|
11979
12353
|
const relay = createRejectionRelay();
|
|
11980
12354
|
installRejectionRelay(ctx, relay);
|
|
@@ -11989,7 +12363,10 @@ var DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
|
11989
12363
|
translateTimeoutMs: 6e3,
|
|
11990
12364
|
translateMaxChars: 4e3,
|
|
11991
12365
|
translateProvider: "",
|
|
11992
|
-
translateModel: ""
|
|
12366
|
+
translateModel: "",
|
|
12367
|
+
reviewContextGuard: true,
|
|
12368
|
+
reviewMaxHistoryChars: 12e4,
|
|
12369
|
+
reviewKeepRecentEntries: 16
|
|
11993
12370
|
};
|
|
11994
12371
|
var Config2 = z2.object({
|
|
11995
12372
|
keepPresetGuard: z2.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.keepPresetGuard).volatile(),
|
|
@@ -11997,9 +12374,12 @@ var Config2 = z2.object({
|
|
|
11997
12374
|
translateTimeoutMs: z2.number().min(500).max(6e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateTimeoutMs).volatile(),
|
|
11998
12375
|
translateMaxChars: z2.number().min(100).max(2e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateMaxChars).volatile(),
|
|
11999
12376
|
translateProvider: z2.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateProvider).volatile(),
|
|
12000
|
-
translateModel: z2.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile()
|
|
12377
|
+
translateModel: z2.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile(),
|
|
12378
|
+
reviewContextGuard: z2.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.reviewContextGuard).volatile(),
|
|
12379
|
+
reviewMaxHistoryChars: z2.number().min(2e4).max(6e5).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
|
|
12380
|
+
reviewKeepRecentEntries: z2.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile()
|
|
12001
12381
|
}).default(DEFAULT_AUTO_REVIEW_CONFIG);
|
|
12002
|
-
function
|
|
12382
|
+
function apply3(ctx, config) {
|
|
12003
12383
|
installAutoReview(ctx, toPlain(config));
|
|
12004
12384
|
}
|
|
12005
12385
|
|
|
@@ -12009,19 +12389,19 @@ __export(restart_exports, {
|
|
|
12009
12389
|
Config: () => Config3,
|
|
12010
12390
|
DEFAULT_RESTART_CONFIG: () => DEFAULT_RESTART_CONFIG,
|
|
12011
12391
|
RESTART_API: () => RESTART_API,
|
|
12012
|
-
apply: () =>
|
|
12392
|
+
apply: () => apply4,
|
|
12013
12393
|
closeDesktop: () => closeDesktop,
|
|
12014
12394
|
deriveDesktopAppPath: () => deriveDesktopAppPath,
|
|
12015
|
-
inject: () =>
|
|
12395
|
+
inject: () => inject3,
|
|
12016
12396
|
launchRestart: () => launchRestart,
|
|
12017
12397
|
makeRestartRoutes: () => makeRestartRoutes,
|
|
12018
12398
|
makeTaskScript: () => makeTaskScript,
|
|
12019
12399
|
resolveRestartTarget: () => resolveRestartTarget
|
|
12020
12400
|
});
|
|
12021
12401
|
import { execFileSync } from "node:child_process";
|
|
12022
|
-
import { appendFileSync, existsSync } from "node:fs";
|
|
12023
|
-
import { tmpdir } from "node:os";
|
|
12024
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
12402
|
+
import { appendFileSync as appendFileSync3, existsSync } from "node:fs";
|
|
12403
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
12404
|
+
import { basename, dirname, join as join3, resolve } from "node:path";
|
|
12025
12405
|
import z3 from "@deepseek-ai/schemastery";
|
|
12026
12406
|
var DEFAULT_RESTART_CONFIG = { enabled: true, appPath: "" };
|
|
12027
12407
|
var Config3 = z3.object({
|
|
@@ -12050,13 +12430,13 @@ function deriveDesktopAppPath(execPath, argv, exists) {
|
|
|
12050
12430
|
if (argv0 !== "" && argv0 !== execPath && !isNode(argv0) && exists(argv0)) return argv0;
|
|
12051
12431
|
const runtimeDir = argv[2] ?? "";
|
|
12052
12432
|
if (runtimeDir === "") return execPath;
|
|
12053
|
-
const candidate =
|
|
12433
|
+
const candidate = join3(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
|
|
12054
12434
|
return exists(candidate) ? candidate : execPath;
|
|
12055
12435
|
}
|
|
12056
12436
|
var RESTART_TASK_NAME = "DSH-MCviseron-Restart";
|
|
12057
12437
|
var RESTART_DELAY_SECONDS = 6;
|
|
12058
12438
|
function restartLogPath() {
|
|
12059
|
-
return
|
|
12439
|
+
return join3(tmpdir3(), "dsh-mcviseron-restart.log");
|
|
12060
12440
|
}
|
|
12061
12441
|
function makeTaskScript(target, taskName, delaySeconds) {
|
|
12062
12442
|
const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
|
|
@@ -12097,26 +12477,26 @@ function launchHelper(target) {
|
|
|
12097
12477
|
"-Command",
|
|
12098
12478
|
makeTaskScript(target, RESTART_TASK_NAME, RESTART_DELAY_SECONDS)
|
|
12099
12479
|
], { windowsHide: true, timeout: 2e4, encoding: "utf8" });
|
|
12100
|
-
|
|
12480
|
+
appendFileSync3(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: scheduled ${target.exePath} in ${RESTART_DELAY_SECONDS}s
|
|
12101
12481
|
`, "utf8");
|
|
12102
12482
|
} catch (error) {
|
|
12103
12483
|
const message = error instanceof Error ? error.message : String(error);
|
|
12104
|
-
|
|
12484
|
+
appendFileSync3(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: task registration failed: ${message}
|
|
12105
12485
|
`, "utf8");
|
|
12106
12486
|
throw new Error("cannot schedule the restart task: " + message, { cause: error });
|
|
12107
12487
|
}
|
|
12108
12488
|
setTimeout(() => {
|
|
12109
12489
|
try {
|
|
12110
12490
|
process.kill(target.mainPid);
|
|
12111
|
-
|
|
12491
|
+
appendFileSync3(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${target.mainPid}
|
|
12112
12492
|
`, "utf8");
|
|
12113
12493
|
} catch (error) {
|
|
12114
|
-
|
|
12494
|
+
appendFileSync3(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill failed: ${error instanceof Error ? error.message : String(error)}
|
|
12115
12495
|
`, "utf8");
|
|
12116
12496
|
}
|
|
12117
12497
|
}, 700);
|
|
12118
12498
|
}
|
|
12119
|
-
function
|
|
12499
|
+
function json3(res, status, body) {
|
|
12120
12500
|
res.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
12121
12501
|
res.end(JSON.stringify(body));
|
|
12122
12502
|
}
|
|
@@ -12143,12 +12523,12 @@ function makeRestartRoutes(deps) {
|
|
|
12143
12523
|
path: RESTART_API.status,
|
|
12144
12524
|
handler: async (req, res) => {
|
|
12145
12525
|
try {
|
|
12146
|
-
if (req.method !== "GET" && req.method !== "POST") return
|
|
12147
|
-
if (!isLoopbackRequest(req)) return
|
|
12526
|
+
if (req.method !== "GET" && req.method !== "POST") return json3(res, 405, { ok: false, error: "method-not-allowed" });
|
|
12527
|
+
if (!isLoopbackRequest(req)) return json3(res, 403, { ok: false, error: "forbidden" });
|
|
12148
12528
|
const target = deps.target();
|
|
12149
|
-
|
|
12529
|
+
json3(res, 200, target === void 0 ? { ok: true, available: false, reason: "desktop-app-unavailable" } : { ok: true, available: true, appPath: target.exePath, mainPid: target.mainPid });
|
|
12150
12530
|
} catch (error) {
|
|
12151
|
-
|
|
12531
|
+
json3(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
12152
12532
|
}
|
|
12153
12533
|
}
|
|
12154
12534
|
};
|
|
@@ -12157,28 +12537,28 @@ function makeRestartRoutes(deps) {
|
|
|
12157
12537
|
path: RESTART_API.execute,
|
|
12158
12538
|
handler: async (req, res) => {
|
|
12159
12539
|
try {
|
|
12160
|
-
if (req.method !== "POST") return
|
|
12161
|
-
if (!isLoopbackRequest(req)) return
|
|
12540
|
+
if (req.method !== "POST") return json3(res, 405, { ok: false, error: "method-not-allowed" });
|
|
12541
|
+
if (!isLoopbackRequest(req)) return json3(res, 403, { ok: false, error: "forbidden" });
|
|
12162
12542
|
const body = await readJsonBody2(req);
|
|
12163
12543
|
if (body === void 0 || typeof body !== "object" || body === null || body.confirm !== true) {
|
|
12164
|
-
return
|
|
12544
|
+
return json3(res, 400, { ok: false, error: "confirmation-required" });
|
|
12165
12545
|
}
|
|
12166
12546
|
const latest = now();
|
|
12167
|
-
if (latest - lastLaunch < 5e3) return
|
|
12547
|
+
if (latest - lastLaunch < 5e3) return json3(res, 429, { ok: false, error: "restart-already-scheduled" });
|
|
12168
12548
|
const target = deps.target();
|
|
12169
|
-
if (target === void 0) return
|
|
12549
|
+
if (target === void 0) return json3(res, 409, { ok: false, error: "desktop-app-unavailable" });
|
|
12170
12550
|
deps.launch(target);
|
|
12171
12551
|
lastLaunch = latest;
|
|
12172
|
-
|
|
12552
|
+
json3(res, 200, { ok: true, restarting: true, appPath: target.exePath });
|
|
12173
12553
|
} catch (error) {
|
|
12174
|
-
|
|
12554
|
+
json3(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
12175
12555
|
}
|
|
12176
12556
|
}
|
|
12177
12557
|
};
|
|
12178
12558
|
return [status, execute];
|
|
12179
12559
|
}
|
|
12180
|
-
var
|
|
12181
|
-
function
|
|
12560
|
+
var inject3 = ["webServer"];
|
|
12561
|
+
function apply4(ctx, config) {
|
|
12182
12562
|
const plain = toPlain(config) ?? {};
|
|
12183
12563
|
if (plain.enabled === false) return;
|
|
12184
12564
|
const appPath = typeof plain.appPath === "string" ? plain.appPath : "";
|
|
@@ -12199,9 +12579,9 @@ var session_end_exports = {};
|
|
|
12199
12579
|
__export(session_end_exports, {
|
|
12200
12580
|
Config: () => Config4,
|
|
12201
12581
|
DEFAULT_SESSION_END_CONFIG: () => DEFAULT_SESSION_END_CONFIG,
|
|
12202
|
-
apply: () =>
|
|
12582
|
+
apply: () => apply5,
|
|
12203
12583
|
createSessionEndController: () => createSessionEndController,
|
|
12204
|
-
inject: () =>
|
|
12584
|
+
inject: () => inject4,
|
|
12205
12585
|
inspectRunningTasks: () => inspectRunningTasks,
|
|
12206
12586
|
isSessionEndMode: () => isSessionEndMode,
|
|
12207
12587
|
makeSessionEndRoutes: () => makeSessionEndRoutes,
|
|
@@ -12209,9 +12589,9 @@ __export(session_end_exports, {
|
|
|
12209
12589
|
shutdownComputer: () => shutdownComputer
|
|
12210
12590
|
});
|
|
12211
12591
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
12212
|
-
import { appendFileSync as
|
|
12213
|
-
import { tmpdir as
|
|
12214
|
-
import { join as
|
|
12592
|
+
import { appendFileSync as appendFileSync4, existsSync as existsSync2 } from "node:fs";
|
|
12593
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
12594
|
+
import { join as join4 } from "node:path";
|
|
12215
12595
|
import z4 from "@deepseek-ai/schemastery";
|
|
12216
12596
|
|
|
12217
12597
|
// src/session-end/email.ts
|
|
@@ -12343,11 +12723,11 @@ function isSessionEndMode(value) {
|
|
|
12343
12723
|
return value === "off" || value === "restart" || value === "close" || value === "shutdown";
|
|
12344
12724
|
}
|
|
12345
12725
|
function sessionLogPath() {
|
|
12346
|
-
return
|
|
12726
|
+
return join4(tmpdir4(), "dsh-mcviseron-session-end.log");
|
|
12347
12727
|
}
|
|
12348
12728
|
function defaultLog(message) {
|
|
12349
12729
|
try {
|
|
12350
|
-
|
|
12730
|
+
appendFileSync4(sessionLogPath(), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
12351
12731
|
} catch {
|
|
12352
12732
|
}
|
|
12353
12733
|
}
|
|
@@ -12410,6 +12790,7 @@ function createSessionEndController(deps = {}) {
|
|
|
12410
12790
|
const log = deps.log ?? defaultLog;
|
|
12411
12791
|
const entries = /* @__PURE__ */ new Map();
|
|
12412
12792
|
const timers = /* @__PURE__ */ new Map();
|
|
12793
|
+
let dispatching = false;
|
|
12413
12794
|
const resolveTarget = deps.resolveTarget ?? (() => resolveRestartTarget(
|
|
12414
12795
|
process.execPath,
|
|
12415
12796
|
process.ppid,
|
|
@@ -12460,7 +12841,16 @@ function createSessionEndController(deps = {}) {
|
|
|
12460
12841
|
};
|
|
12461
12842
|
const fire = (sessionId, entry) => {
|
|
12462
12843
|
cancel(sessionId);
|
|
12463
|
-
|
|
12844
|
+
if (dispatching) {
|
|
12845
|
+
entries.delete(sessionId);
|
|
12846
|
+
return;
|
|
12847
|
+
}
|
|
12848
|
+
dispatching = true;
|
|
12849
|
+
for (const [id, timer] of timers) {
|
|
12850
|
+
clearTimeout(timer);
|
|
12851
|
+
timers.delete(id);
|
|
12852
|
+
}
|
|
12853
|
+
entries.clear();
|
|
12464
12854
|
const mode = entry.mode;
|
|
12465
12855
|
try {
|
|
12466
12856
|
if (mode === "restart") {
|
|
@@ -12505,7 +12895,15 @@ function createSessionEndController(deps = {}) {
|
|
|
12505
12895
|
get(sessionId) {
|
|
12506
12896
|
return view(sessionId);
|
|
12507
12897
|
},
|
|
12508
|
-
|
|
12898
|
+
list() {
|
|
12899
|
+
return [...entries.entries()].map(([sessionId, entry]) => ({
|
|
12900
|
+
sessionId,
|
|
12901
|
+
label: entry.label ?? "",
|
|
12902
|
+
armedAt: entry.armedAt,
|
|
12903
|
+
...view(sessionId)
|
|
12904
|
+
}));
|
|
12905
|
+
},
|
|
12906
|
+
set(sessionId, mode, requestedBy, label) {
|
|
12509
12907
|
if (sessionId === "") throw new TypeError("sessionId must be non-empty");
|
|
12510
12908
|
if (!enabled) throw new Error("session-end actions are disabled");
|
|
12511
12909
|
if (!isSessionEndMode(mode)) throw new TypeError("unknown session-end mode: " + String(mode));
|
|
@@ -12520,6 +12918,8 @@ function createSessionEndController(deps = {}) {
|
|
|
12520
12918
|
entries.set(sessionId, {
|
|
12521
12919
|
mode,
|
|
12522
12920
|
requestedBy,
|
|
12921
|
+
...label === void 0 || label === "" ? {} : { label },
|
|
12922
|
+
armedAt: Date.now(),
|
|
12523
12923
|
waiting: false,
|
|
12524
12924
|
runningAgents: 0,
|
|
12525
12925
|
runningJobs: 0
|
|
@@ -12544,10 +12944,11 @@ function createSessionEndController(deps = {}) {
|
|
|
12544
12944
|
for (const timer of timers.values()) clearTimeout(timer);
|
|
12545
12945
|
timers.clear();
|
|
12546
12946
|
entries.clear();
|
|
12947
|
+
dispatching = false;
|
|
12547
12948
|
}
|
|
12548
12949
|
};
|
|
12549
12950
|
}
|
|
12550
|
-
function
|
|
12951
|
+
function json4(res, status, body) {
|
|
12551
12952
|
res.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
12552
12953
|
res.end(JSON.stringify(body));
|
|
12553
12954
|
}
|
|
@@ -12578,17 +12979,17 @@ function makeSessionEndRoutes(controller) {
|
|
|
12578
12979
|
path: SESSION_END_API.state,
|
|
12579
12980
|
handler: async (req, res) => {
|
|
12580
12981
|
try {
|
|
12581
|
-
if (req.method !== "POST") return
|
|
12582
|
-
if (!isLoopbackRequest(req)) return
|
|
12982
|
+
if (req.method !== "POST") return json4(res, 405, { ok: false, error: "method-not-allowed" });
|
|
12983
|
+
if (!isLoopbackRequest(req)) return json4(res, 403, { ok: false, error: "forbidden" });
|
|
12583
12984
|
const sessionId = bodySessionId(await readJsonBody3(req));
|
|
12584
|
-
if (sessionId === void 0) return
|
|
12985
|
+
if (sessionId === void 0) return json4(res, 400, { ok: false, error: "sessionId-required" });
|
|
12585
12986
|
if (!seen.has(sessionId)) {
|
|
12586
12987
|
seen.add(sessionId);
|
|
12587
12988
|
defaultLog("state request: session=" + sessionId);
|
|
12588
12989
|
}
|
|
12589
|
-
|
|
12990
|
+
json4(res, 200, { ok: true, ...controller.get(sessionId) });
|
|
12590
12991
|
} catch (error) {
|
|
12591
|
-
|
|
12992
|
+
json4(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
12592
12993
|
}
|
|
12593
12994
|
}
|
|
12594
12995
|
};
|
|
@@ -12597,22 +12998,40 @@ function makeSessionEndRoutes(controller) {
|
|
|
12597
12998
|
path: SESSION_END_API.set,
|
|
12598
12999
|
handler: async (req, res) => {
|
|
12599
13000
|
try {
|
|
12600
|
-
if (req.method !== "POST") return
|
|
12601
|
-
if (!isLoopbackRequest(req)) return
|
|
13001
|
+
if (req.method !== "POST") return json4(res, 405, { ok: false, error: "method-not-allowed" });
|
|
13002
|
+
if (!isLoopbackRequest(req)) return json4(res, 403, { ok: false, error: "forbidden" });
|
|
12602
13003
|
const body = await readJsonBody3(req);
|
|
12603
13004
|
const sessionId = bodySessionId(body);
|
|
12604
|
-
if (sessionId === void 0) return
|
|
13005
|
+
if (sessionId === void 0) return json4(res, 400, { ok: false, error: "sessionId-required" });
|
|
12605
13006
|
const mode = body.mode;
|
|
12606
|
-
if (!isSessionEndMode(mode)) return
|
|
12607
|
-
|
|
13007
|
+
if (!isSessionEndMode(mode)) return json4(res, 400, { ok: false, error: "mode-invalid" });
|
|
13008
|
+
json4(res, 200, { ok: true, ...controller.set(sessionId, mode, "user") });
|
|
12608
13009
|
} catch (error) {
|
|
12609
|
-
|
|
13010
|
+
json4(res, 400, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
13011
|
+
}
|
|
13012
|
+
}
|
|
13013
|
+
};
|
|
13014
|
+
const global = {
|
|
13015
|
+
kind: "exact",
|
|
13016
|
+
path: SESSION_END_API.global,
|
|
13017
|
+
handler: (req, res) => {
|
|
13018
|
+
if (req.method !== "POST" && req.method !== "GET") {
|
|
13019
|
+
json4(res, 405, { ok: false, error: "method-not-allowed" });
|
|
13020
|
+
return;
|
|
13021
|
+
}
|
|
13022
|
+
if (!isLoopbackRequest(req)) {
|
|
13023
|
+
json4(res, 403, { ok: false, error: "forbidden" });
|
|
13024
|
+
return;
|
|
12610
13025
|
}
|
|
13026
|
+
json4(res, 200, {
|
|
13027
|
+
ok: true,
|
|
13028
|
+
actions: controller.list().filter((action) => action.requestedBy === "ai" && action.mode !== "off")
|
|
13029
|
+
});
|
|
12611
13030
|
}
|
|
12612
13031
|
};
|
|
12613
|
-
return [state, set];
|
|
13032
|
+
return [state, set, global];
|
|
12614
13033
|
}
|
|
12615
|
-
function
|
|
13034
|
+
function serviceOf3(ctx, name) {
|
|
12616
13035
|
try {
|
|
12617
13036
|
const direct = ctx[name];
|
|
12618
13037
|
if (direct !== void 0) return direct;
|
|
@@ -12626,11 +13045,11 @@ function serviceOf2(ctx, name) {
|
|
|
12626
13045
|
}
|
|
12627
13046
|
}
|
|
12628
13047
|
function installGuidance(ctx) {
|
|
12629
|
-
const
|
|
12630
|
-
if (typeof
|
|
13048
|
+
const inject5 = ctx.inject;
|
|
13049
|
+
if (typeof inject5 !== "function") return;
|
|
12631
13050
|
try {
|
|
12632
|
-
|
|
12633
|
-
const systemPrompt =
|
|
13051
|
+
inject5.call(ctx, ["systemPrompt"], (scope) => {
|
|
13052
|
+
const systemPrompt = serviceOf3(scope, "systemPrompt");
|
|
12634
13053
|
if (systemPrompt === void 0 || typeof systemPrompt.section !== "function") return;
|
|
12635
13054
|
try {
|
|
12636
13055
|
systemPrompt.section({
|
|
@@ -12648,11 +13067,11 @@ function installGuidance(ctx) {
|
|
|
12648
13067
|
}
|
|
12649
13068
|
var emailed = /* @__PURE__ */ new Map();
|
|
12650
13069
|
function installAgentTool(ctx, controller, options, log) {
|
|
12651
|
-
const
|
|
12652
|
-
if (typeof
|
|
13070
|
+
const inject5 = ctx.inject;
|
|
13071
|
+
if (typeof inject5 !== "function") return;
|
|
12653
13072
|
try {
|
|
12654
|
-
|
|
12655
|
-
const tools =
|
|
13073
|
+
inject5.call(ctx, ["tools"], (scope) => {
|
|
13074
|
+
const tools = serviceOf3(scope, "tools");
|
|
12656
13075
|
if (tools === void 0 || typeof tools.register !== "function") return;
|
|
12657
13076
|
const definition = {
|
|
12658
13077
|
name: "set_session_end_action",
|
|
@@ -12664,15 +13083,19 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
12664
13083
|
"Use close only when the user explicitly asks to close DSH. Shutdown is user-only. If unsure whether a restart is required, ask the user instead of arming."
|
|
12665
13084
|
].join(" "),
|
|
12666
13085
|
parameters: {
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
13086
|
+
type: "object",
|
|
13087
|
+
additionalProperties: false,
|
|
13088
|
+
required: ["action"],
|
|
13089
|
+
properties: {
|
|
13090
|
+
action: {
|
|
13091
|
+
type: "string",
|
|
13092
|
+
enum: ["restart", "close", "off"],
|
|
13093
|
+
description: "restart DSH after this turn, close DSH, or clear the pending action"
|
|
13094
|
+
},
|
|
13095
|
+
reason: {
|
|
13096
|
+
type: "string",
|
|
13097
|
+
description: "Optional short reason shown in the tool result; the user sees the same action in the composer"
|
|
13098
|
+
}
|
|
12676
13099
|
}
|
|
12677
13100
|
},
|
|
12678
13101
|
output: {
|
|
@@ -12708,18 +13131,28 @@ function installAgentTool(ctx, controller, options, log) {
|
|
|
12708
13131
|
if (action === "close" && !before.available.close) {
|
|
12709
13132
|
throw new Error("close is unavailable in this host");
|
|
12710
13133
|
}
|
|
12711
|
-
|
|
13134
|
+
const session = exec.agent?.session;
|
|
13135
|
+
const title = session?.header?.title ?? session?.header?.name ?? session?.title;
|
|
13136
|
+
let label = typeof title === "string" && title !== "" ? title : "";
|
|
13137
|
+
if (label === "") {
|
|
13138
|
+
try {
|
|
13139
|
+
const titles = serviceOf3(ctx, "sessionTitle");
|
|
13140
|
+
const snapshot = titles?.get?.(session);
|
|
13141
|
+
const folded = snapshot !== null && typeof snapshot === "object" ? snapshot.title : void 0;
|
|
13142
|
+
if (typeof folded === "string" && folded !== "") label = folded;
|
|
13143
|
+
} catch {
|
|
13144
|
+
}
|
|
13145
|
+
}
|
|
13146
|
+
controller.set(sessionId, action, "ai", label);
|
|
12712
13147
|
if (action !== "off" && options.notifyEmailOnAi) {
|
|
12713
13148
|
const key = sessionId + ":" + action;
|
|
12714
13149
|
const now = Date.now();
|
|
12715
13150
|
const previous = emailed.get(key) ?? 0;
|
|
12716
13151
|
if (now - previous > 6e4) {
|
|
12717
13152
|
emailed.set(key, now);
|
|
12718
|
-
const
|
|
12719
|
-
const title = session?.header?.title ?? session?.header?.name ?? session?.title;
|
|
12720
|
-
const sessionName = typeof title === "string" && title !== "" ? title : sessionId;
|
|
13153
|
+
const sessionName = label === "" ? sessionId : label;
|
|
12721
13154
|
void sendSessionEndEmail({
|
|
12722
|
-
settings:
|
|
13155
|
+
settings: serviceOf3(ctx, "settings"),
|
|
12723
13156
|
template: options,
|
|
12724
13157
|
sessionId,
|
|
12725
13158
|
sessionName,
|
|
@@ -12777,15 +13210,15 @@ function normalizeSessionEndOptions(input) {
|
|
|
12777
13210
|
appPath: string("appPath", "")
|
|
12778
13211
|
};
|
|
12779
13212
|
}
|
|
12780
|
-
var
|
|
12781
|
-
function
|
|
13213
|
+
var inject4 = ["webServer"];
|
|
13214
|
+
function apply5(ctx, config) {
|
|
12782
13215
|
const options = normalizeSessionEndOptions(config);
|
|
12783
13216
|
const log = defaultLog;
|
|
12784
13217
|
const controller = createSessionEndController({
|
|
12785
13218
|
enabled: options.enabled,
|
|
12786
13219
|
graceMs: options.graceMs,
|
|
12787
13220
|
appPath: options.appPath,
|
|
12788
|
-
hasRunningTasks: () => inspectRunningTasks(
|
|
13221
|
+
hasRunningTasks: () => inspectRunningTasks(serviceOf3(ctx, "agents"), serviceOf3(ctx, "jobs"))
|
|
12789
13222
|
});
|
|
12790
13223
|
const routes = makeSessionEndRoutes(controller);
|
|
12791
13224
|
ctx.effect(() => {
|
|
@@ -12824,7 +13257,7 @@ var task_guard_exports = {};
|
|
|
12824
13257
|
__export(task_guard_exports, {
|
|
12825
13258
|
Config: () => Config5,
|
|
12826
13259
|
DEFAULT_TASK_GUARD_CONFIG: () => DEFAULT_TASK_GUARD_CONFIG,
|
|
12827
|
-
apply: () =>
|
|
13260
|
+
apply: () => apply6
|
|
12828
13261
|
});
|
|
12829
13262
|
import z5 from "@deepseek-ai/schemastery";
|
|
12830
13263
|
|
|
@@ -12987,7 +13420,7 @@ function completionPayload(todos, matched) {
|
|
|
12987
13420
|
}));
|
|
12988
13421
|
return JSON.stringify({ todos: updated });
|
|
12989
13422
|
}
|
|
12990
|
-
function
|
|
13423
|
+
function serviceOf4(scope, name) {
|
|
12991
13424
|
try {
|
|
12992
13425
|
const direct = scope[name];
|
|
12993
13426
|
if (direct !== void 0) return direct;
|
|
@@ -13016,7 +13449,7 @@ function sessionRoute2(agent) {
|
|
|
13016
13449
|
}
|
|
13017
13450
|
function noticeContext(agent, config, ctx) {
|
|
13018
13451
|
const route = sessionRoute2(agent);
|
|
13019
|
-
const llm =
|
|
13452
|
+
const llm = serviceOf4(ctx, "llm");
|
|
13020
13453
|
return {
|
|
13021
13454
|
llm,
|
|
13022
13455
|
route,
|
|
@@ -13335,12 +13768,12 @@ function isTracked(toolName, config) {
|
|
|
13335
13768
|
}
|
|
13336
13769
|
function readTodos(value) {
|
|
13337
13770
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
|
|
13338
|
-
const
|
|
13339
|
-
if (Object.keys(
|
|
13340
|
-
if (!Array.isArray(
|
|
13771
|
+
const record2 = value;
|
|
13772
|
+
if (Object.keys(record2).some((key) => key !== "todos")) return null;
|
|
13773
|
+
if (!Array.isArray(record2.todos)) return null;
|
|
13341
13774
|
const todos = [];
|
|
13342
13775
|
const seen = /* @__PURE__ */ new Set();
|
|
13343
|
-
for (const item of
|
|
13776
|
+
for (const item of record2.todos) {
|
|
13344
13777
|
if (item === null || typeof item !== "object" || Array.isArray(item)) return null;
|
|
13345
13778
|
const entry = item;
|
|
13346
13779
|
if (Object.keys(entry).some((key) => key !== "content" && key !== "status")) return null;
|
|
@@ -13536,7 +13969,7 @@ var Config5 = z5.object({
|
|
|
13536
13969
|
include: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.include).volatile(),
|
|
13537
13970
|
exclude: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.exclude).volatile()
|
|
13538
13971
|
}).default(DEFAULT_TASK_GUARD_CONFIG);
|
|
13539
|
-
function
|
|
13972
|
+
function apply6(ctx, config) {
|
|
13540
13973
|
installTaskGuard(ctx, toPlain(config));
|
|
13541
13974
|
}
|
|
13542
13975
|
|
|
@@ -13566,8 +13999,9 @@ function mount(ctx, component, config) {
|
|
|
13566
13999
|
logger?.warn?.(new Error("mcviseron: cannot mount a component", { cause: error }));
|
|
13567
14000
|
}
|
|
13568
14001
|
}
|
|
13569
|
-
function
|
|
14002
|
+
function apply7(ctx, rawConfig) {
|
|
13570
14003
|
const config = toPlain(rawConfig) ?? {};
|
|
14004
|
+
mount(ctx, auth_cookie_exports, {});
|
|
13571
14005
|
mount(ctx, appearance_exports, {
|
|
13572
14006
|
enabled: config.enabled ?? DEFAULT_SCHEDULE_CONFIG.enabled,
|
|
13573
14007
|
lightStart: config.lightStart ?? DEFAULT_SCHEDULE_CONFIG.lightStart,
|
|
@@ -13585,5 +14019,5 @@ function apply6(ctx, rawConfig) {
|
|
|
13585
14019
|
}
|
|
13586
14020
|
export {
|
|
13587
14021
|
Config6 as Config,
|
|
13588
|
-
|
|
14022
|
+
apply7 as apply
|
|
13589
14023
|
};
|