dsh-mcviseron-plugin 0.7.3 → 0.8.1
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 +85 -0
- package/README.en.md +17 -13
- package/README.md +22 -18
- package/docs/archive-integration.md +29 -0
- package/docs/auto-review-context.md +25 -24
- package/docs/automation-task.md +1 -1
- package/docs/automation-tasks.md +49 -0
- package/docs/linux-restart.md +96 -0
- package/lib/auto-review-fix.js +135 -6
- package/lib/client.js +172 -27
- package/lib/index.js +421 -84
- package/lib/restart.js +94 -16
- package/package.json +24 -23
- package/src/api.ts +5 -0
- package/src/archive-integration/index.ts +83 -0
- package/src/auto-review-fix/index.ts +2 -2
- package/src/automation-tasks/index.ts +55 -14
- package/src/client/RestartCard.tsx +38 -5
- package/src/client/SettingsSection.tsx +92 -3
- package/src/client/locales.ts +50 -12
- package/src/components/auto-review-fix/index.ts +2 -2
- package/src/components/auto-review-fix/review-context.ts +144 -2
- package/src/index.ts +2 -0
- package/src/restart/index.ts +139 -30
- package/src/session-end/index.ts +2 -2
package/lib/index.js
CHANGED
|
@@ -10466,13 +10466,13 @@ var require_smtp_transport = __commonJS({
|
|
|
10466
10466
|
var require_sendmail_transport = __commonJS({
|
|
10467
10467
|
"node_modules/.pnpm/nodemailer@6.10.1/node_modules/nodemailer/lib/sendmail-transport/index.js"(exports, module) {
|
|
10468
10468
|
"use strict";
|
|
10469
|
-
var
|
|
10469
|
+
var spawn2 = __require("child_process").spawn;
|
|
10470
10470
|
var packageData = require_package();
|
|
10471
10471
|
var shared = require_shared();
|
|
10472
10472
|
var SendmailTransport = class {
|
|
10473
10473
|
constructor(options) {
|
|
10474
10474
|
options = options || {};
|
|
10475
|
-
this._spawn =
|
|
10475
|
+
this._spawn = spawn2;
|
|
10476
10476
|
this.options = options || {};
|
|
10477
10477
|
this.name = "Sendmail";
|
|
10478
10478
|
this.version = packageData.version;
|
|
@@ -11295,6 +11295,9 @@ var SESSION_END_API = {
|
|
|
11295
11295
|
var AUTH_COOKIE_API = {
|
|
11296
11296
|
prune: "/api/dsh-mcviseron/auth-cookies/prune"
|
|
11297
11297
|
};
|
|
11298
|
+
var ARCHIVE_API = {
|
|
11299
|
+
status: "/api/dsh-mcviseron/archive-integration/status"
|
|
11300
|
+
};
|
|
11298
11301
|
|
|
11299
11302
|
// src/namespace.ts
|
|
11300
11303
|
var MCVISERON_SETTINGS_NAMESPACE = "mcviseron";
|
|
@@ -11569,15 +11572,103 @@ function apply(ctx, _config) {
|
|
|
11569
11572
|
});
|
|
11570
11573
|
}
|
|
11571
11574
|
|
|
11575
|
+
// src/archive-integration/index.ts
|
|
11576
|
+
var archive_integration_exports = {};
|
|
11577
|
+
__export(archive_integration_exports, {
|
|
11578
|
+
apply: () => apply2,
|
|
11579
|
+
inject: () => inject2,
|
|
11580
|
+
makeArchiveStatus: () => makeArchiveStatus
|
|
11581
|
+
});
|
|
11582
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
11583
|
+
import { homedir } from "node:os";
|
|
11584
|
+
import { join } from "node:path";
|
|
11585
|
+
function dshHome() {
|
|
11586
|
+
const raw = process.env.DSH_HOME;
|
|
11587
|
+
if (raw !== void 0 && raw.trim() !== "") return raw.trim().startsWith("~") ? join(homedir(), raw.trim().slice(1).replace(/^[\\/]/, "")) : raw.trim();
|
|
11588
|
+
return join(homedir(), ".dsh");
|
|
11589
|
+
}
|
|
11590
|
+
function archiveAvailable(ctx) {
|
|
11591
|
+
try {
|
|
11592
|
+
const loader = ctx.loader;
|
|
11593
|
+
for (const entry of loader?.entries?.() ?? []) {
|
|
11594
|
+
const name = String(entry.options?.name ?? "");
|
|
11595
|
+
if (name.includes("session-archive") && entry.disabled !== true && entry.fiber !== void 0 && entry.fiber !== null) return true;
|
|
11596
|
+
}
|
|
11597
|
+
} catch {
|
|
11598
|
+
}
|
|
11599
|
+
return false;
|
|
11600
|
+
}
|
|
11601
|
+
function archivedIds(ctx) {
|
|
11602
|
+
try {
|
|
11603
|
+
const registry = ctx.get?.("workspaceRegistry");
|
|
11604
|
+
const value = registry?.archivedSessionIds;
|
|
11605
|
+
return Array.isArray(value) ? value.filter((id) => typeof id === "string" && id.length > 0) : [];
|
|
11606
|
+
} catch {
|
|
11607
|
+
return [];
|
|
11608
|
+
}
|
|
11609
|
+
}
|
|
11610
|
+
function makeArchiveStatus(ctx) {
|
|
11611
|
+
const available = archiveAvailable(ctx);
|
|
11612
|
+
const ledgerPath = join(dshHome(), "dsh-session-archive", "archive-ledger.json");
|
|
11613
|
+
let ledger;
|
|
11614
|
+
try {
|
|
11615
|
+
ledger = JSON.parse(readFileSync(ledgerPath, "utf8"));
|
|
11616
|
+
} catch {
|
|
11617
|
+
ledger = void 0;
|
|
11618
|
+
}
|
|
11619
|
+
const entries = ledger?.entries !== null && typeof ledger?.entries === "object" ? ledger.entries : {};
|
|
11620
|
+
const ids = archivedIds(ctx);
|
|
11621
|
+
let observed = 0;
|
|
11622
|
+
let manual = 0;
|
|
11623
|
+
for (const entry of Object.values(entries)) {
|
|
11624
|
+
if (entry.source === "observed") observed++;
|
|
11625
|
+
else if (entry.source === "manual") manual++;
|
|
11626
|
+
}
|
|
11627
|
+
let unknown = 0;
|
|
11628
|
+
for (const id of ids) if (entries[id] === void 0) unknown++;
|
|
11629
|
+
return {
|
|
11630
|
+
ok: true,
|
|
11631
|
+
available,
|
|
11632
|
+
ledgerPath,
|
|
11633
|
+
ledgerExists: existsSync(ledgerPath),
|
|
11634
|
+
entries: Object.keys(entries).length,
|
|
11635
|
+
observed,
|
|
11636
|
+
manual,
|
|
11637
|
+
archivedCount: ids.length,
|
|
11638
|
+
unknownCount: unknown
|
|
11639
|
+
};
|
|
11640
|
+
}
|
|
11641
|
+
var inject2 = ["webServer"];
|
|
11642
|
+
function apply2(ctx) {
|
|
11643
|
+
ctx.effect(() => ctx.webServer.register({
|
|
11644
|
+
kind: "exact",
|
|
11645
|
+
path: ARCHIVE_API.status,
|
|
11646
|
+
handler: async (req, res) => {
|
|
11647
|
+
const send = (status, value) => {
|
|
11648
|
+
res.statusCode = status;
|
|
11649
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
11650
|
+
res.end(JSON.stringify(value));
|
|
11651
|
+
};
|
|
11652
|
+
if (req.method !== "GET" && req.method !== "POST") return send(405, { ok: false, error: "method-not-allowed" });
|
|
11653
|
+
if (!isLoopbackRequest(req)) return send(403, { ok: false, error: "forbidden" });
|
|
11654
|
+
try {
|
|
11655
|
+
send(200, makeArchiveStatus(ctx));
|
|
11656
|
+
} catch (error) {
|
|
11657
|
+
send(500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
11658
|
+
}
|
|
11659
|
+
}
|
|
11660
|
+
}), "mcviseron: archive integration status");
|
|
11661
|
+
}
|
|
11662
|
+
|
|
11572
11663
|
// src/auth-cookie/index.ts
|
|
11573
11664
|
var auth_cookie_exports = {};
|
|
11574
11665
|
__export(auth_cookie_exports, {
|
|
11575
11666
|
AUTH_COOKIE_PREFIX: () => AUTH_COOKIE_PREFIX,
|
|
11576
|
-
apply: () =>
|
|
11667
|
+
apply: () => apply3,
|
|
11577
11668
|
authCookieName: () => authCookieName,
|
|
11578
11669
|
authCookieNames: () => authCookieNames,
|
|
11579
11670
|
expiredAuthCookie: () => expiredAuthCookie,
|
|
11580
|
-
inject: () =>
|
|
11671
|
+
inject: () => inject3,
|
|
11581
11672
|
makeAuthCookieRoutes: () => makeAuthCookieRoutes,
|
|
11582
11673
|
pruneCookieHeaders: () => pruneCookieHeaders,
|
|
11583
11674
|
pruneScript: () => pruneScript,
|
|
@@ -11587,13 +11678,13 @@ __export(auth_cookie_exports, {
|
|
|
11587
11678
|
import { createHash } from "node:crypto";
|
|
11588
11679
|
import { appendFileSync } from "node:fs";
|
|
11589
11680
|
import { tmpdir } from "node:os";
|
|
11590
|
-
import { join } from "node:path";
|
|
11681
|
+
import { join as join2 } from "node:path";
|
|
11591
11682
|
var AUTH_COOKIE_PREFIX = "dsh-auth-";
|
|
11592
11683
|
var EXPIRED_AT = "Thu, 01 Jan 1970 00:00:00 GMT";
|
|
11593
11684
|
function logPrune(authority, pruned) {
|
|
11594
11685
|
try {
|
|
11595
11686
|
appendFileSync(
|
|
11596
|
-
|
|
11687
|
+
join2(tmpdir(), "dsh-mcviseron-auth-cookie.log"),
|
|
11597
11688
|
(/* @__PURE__ */ new Date()).toISOString() + " pruned=" + pruned + " authority=" + authority + "\n",
|
|
11598
11689
|
"utf8"
|
|
11599
11690
|
);
|
|
@@ -11696,8 +11787,8 @@ function installIndexInjection(ctx) {
|
|
|
11696
11787
|
} catch {
|
|
11697
11788
|
}
|
|
11698
11789
|
}
|
|
11699
|
-
var
|
|
11700
|
-
function
|
|
11790
|
+
var inject3 = ["webServer"];
|
|
11791
|
+
function apply3(ctx) {
|
|
11701
11792
|
const secure = () => {
|
|
11702
11793
|
try {
|
|
11703
11794
|
return ctx.webServer.protocol === "https:";
|
|
@@ -11718,12 +11809,12 @@ function apply2(ctx) {
|
|
|
11718
11809
|
// src/automation-tasks/index.ts
|
|
11719
11810
|
var automation_tasks_exports = {};
|
|
11720
11811
|
__export(automation_tasks_exports, {
|
|
11721
|
-
apply: () =>
|
|
11812
|
+
apply: () => apply4,
|
|
11722
11813
|
makeAutomationTaskTools: () => makeAutomationTaskTools
|
|
11723
11814
|
});
|
|
11724
11815
|
import { appendFileSync as appendFileSync2 } from "node:fs";
|
|
11725
11816
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
11726
|
-
import { join as
|
|
11817
|
+
import { join as join3 } from "node:path";
|
|
11727
11818
|
var OUTPUT_SCHEMA = { type: "object", additionalProperties: true };
|
|
11728
11819
|
var SELECTOR_KEYS = ["after_seconds", "at", "every_seconds", "daily", "weekly", "cron"];
|
|
11729
11820
|
function output() {
|
|
@@ -11734,10 +11825,23 @@ function output() {
|
|
|
11734
11825
|
}
|
|
11735
11826
|
function log(message) {
|
|
11736
11827
|
try {
|
|
11737
|
-
appendFileSync2(
|
|
11828
|
+
appendFileSync2(join3(tmpdir2(), "dsh-mcviseron-automation-tasks.log"), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
11738
11829
|
} catch {
|
|
11739
11830
|
}
|
|
11740
11831
|
}
|
|
11832
|
+
function isModernSchedule(schedule) {
|
|
11833
|
+
return typeof schedule.edit === "function";
|
|
11834
|
+
}
|
|
11835
|
+
function modernTiming(args) {
|
|
11836
|
+
if (args.after_seconds !== void 0) return { kind: "after", after_seconds: args.after_seconds };
|
|
11837
|
+
if (args.at !== void 0) return { kind: "at", at: args.at };
|
|
11838
|
+
if (args.every_seconds !== void 0) return { kind: "every", every_seconds: args.every_seconds };
|
|
11839
|
+
if (args.daily !== void 0) return { kind: "daily", daily: args.daily };
|
|
11840
|
+
if (args.weekly !== void 0) return { kind: "weekly", weekly: args.weekly };
|
|
11841
|
+
if (args.cron !== void 0) return { kind: "cron", cron: args.cron };
|
|
11842
|
+
if (args.rrule !== void 0) return { kind: "rrule", rrule: args.rrule };
|
|
11843
|
+
return void 0;
|
|
11844
|
+
}
|
|
11741
11845
|
function listRecords(result) {
|
|
11742
11846
|
return Array.isArray(result) ? result : result.items;
|
|
11743
11847
|
}
|
|
@@ -11860,7 +11964,7 @@ function makeAutomationTaskTools(schedule) {
|
|
|
11860
11964
|
const sessionId = sessionIdOf(exec);
|
|
11861
11965
|
if (sessionId === "") return { ok: false, code: "no_session", error: "no current session" };
|
|
11862
11966
|
try {
|
|
11863
|
-
return { ok: true, tasks: listRecords(await schedule.list({ sessionId })) };
|
|
11967
|
+
return { ok: true, tasks: listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })) };
|
|
11864
11968
|
} catch (error) {
|
|
11865
11969
|
return serviceFailure(error);
|
|
11866
11970
|
}
|
|
@@ -11877,11 +11981,23 @@ function makeAutomationTaskTools(schedule) {
|
|
|
11877
11981
|
const invalidInput = validateCreate(args);
|
|
11878
11982
|
if (invalidInput !== void 0) return invalid(invalidInput);
|
|
11879
11983
|
try {
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11984
|
+
let record2;
|
|
11985
|
+
if (isModernSchedule(schedule)) {
|
|
11986
|
+
const timing = modernTiming(args);
|
|
11987
|
+
if (timing === void 0) return invalid("timing is required");
|
|
11988
|
+
record2 = await schedule.create({
|
|
11989
|
+
title: String(args.title).trim(),
|
|
11990
|
+
prompt: String(args.prompt).trim(),
|
|
11991
|
+
timing,
|
|
11992
|
+
target: { kind: "session", sessionId }
|
|
11993
|
+
}, sessionId, exec.signal);
|
|
11994
|
+
} else {
|
|
11995
|
+
record2 = await schedule.create(sessionId, {
|
|
11996
|
+
...args,
|
|
11997
|
+
title: String(args.title).trim(),
|
|
11998
|
+
prompt: String(args.prompt).trim()
|
|
11999
|
+
}, exec.signal);
|
|
12000
|
+
}
|
|
11885
12001
|
return { ok: true, task: record2 };
|
|
11886
12002
|
} catch (error) {
|
|
11887
12003
|
return serviceFailure(error);
|
|
@@ -11900,9 +12016,18 @@ function makeAutomationTaskTools(schedule) {
|
|
|
11900
12016
|
if (invalidInput !== void 0) return invalid(invalidInput);
|
|
11901
12017
|
try {
|
|
11902
12018
|
const id = String(args.id);
|
|
11903
|
-
const expected = listRecords(await schedule.list({ sessionId })).find((record2) => record2.id === id);
|
|
11904
|
-
if (expected === void 0) return { ok: false, code: "schedule_not_found", error: "automation task not found
|
|
12019
|
+
const expected = listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })).find((record2) => record2.id === id);
|
|
12020
|
+
if (expected === void 0) return { ok: false, code: "schedule_not_found", error: "automation task not found: " + id };
|
|
11905
12021
|
const change = timingChange(args);
|
|
12022
|
+
if (isModernSchedule(schedule)) {
|
|
12023
|
+
const patch = {};
|
|
12024
|
+
if (args.title !== void 0) patch.title = String(args.title).trim();
|
|
12025
|
+
if (args.prompt !== void 0) patch.prompt = String(args.prompt).trim();
|
|
12026
|
+
const timing = modernTiming(args);
|
|
12027
|
+
if (timing !== void 0) patch.timing = timing;
|
|
12028
|
+
const result2 = await schedule.edit({ id, action: "update", patch }, sessionId, exec.signal);
|
|
12029
|
+
return { ok: true, task: result2 };
|
|
12030
|
+
}
|
|
11906
12031
|
const result = await schedule.update({
|
|
11907
12032
|
sessionId,
|
|
11908
12033
|
id,
|
|
@@ -11930,6 +12055,10 @@ function makeAutomationTaskTools(schedule) {
|
|
|
11930
12055
|
return invalid("id must be a non-empty string without surrounding whitespace");
|
|
11931
12056
|
}
|
|
11932
12057
|
try {
|
|
12058
|
+
if (isModernSchedule(schedule)) {
|
|
12059
|
+
const result2 = await schedule.edit({ id: String(args.id), action: "delete" }, sessionId, exec.signal);
|
|
12060
|
+
return { ok: true, ...result2 };
|
|
12061
|
+
}
|
|
11933
12062
|
const result = await schedule.delete({ sessionId, id: String(args.id) }, exec.signal);
|
|
11934
12063
|
return { ok: true, ...result };
|
|
11935
12064
|
} catch (error) {
|
|
@@ -11948,11 +12077,11 @@ function serviceOf(scope, name) {
|
|
|
11948
12077
|
return void 0;
|
|
11949
12078
|
}
|
|
11950
12079
|
}
|
|
11951
|
-
function
|
|
11952
|
-
const
|
|
11953
|
-
if (typeof
|
|
12080
|
+
function apply4(ctx) {
|
|
12081
|
+
const inject6 = ctx.inject;
|
|
12082
|
+
if (typeof inject6 !== "function") return;
|
|
11954
12083
|
try {
|
|
11955
|
-
|
|
12084
|
+
inject6.call(ctx, ["tools", "schedule"], (scope) => {
|
|
11956
12085
|
const tools = serviceOf(scope, "tools");
|
|
11957
12086
|
const schedule = serviceOf(scope, "schedule");
|
|
11958
12087
|
if (tools === void 0 || typeof tools.register !== "function" || schedule === void 0) {
|
|
@@ -11983,7 +12112,7 @@ function apply3(ctx) {
|
|
|
11983
12112
|
log("tool injection failed: " + (error instanceof Error ? error.message : String(error)));
|
|
11984
12113
|
}
|
|
11985
12114
|
try {
|
|
11986
|
-
|
|
12115
|
+
inject6.call(ctx, ["systemPrompt"], (scope) => {
|
|
11987
12116
|
const systemPrompt = serviceOf(scope, "systemPrompt");
|
|
11988
12117
|
if (typeof systemPrompt?.section === "function") {
|
|
11989
12118
|
systemPrompt.section({
|
|
@@ -12007,7 +12136,7 @@ var auto_review_fix_exports = {};
|
|
|
12007
12136
|
__export(auto_review_fix_exports, {
|
|
12008
12137
|
Config: () => Config2,
|
|
12009
12138
|
DEFAULT_AUTO_REVIEW_CONFIG: () => DEFAULT_AUTO_REVIEW_CONFIG,
|
|
12010
|
-
apply: () =>
|
|
12139
|
+
apply: () => apply5
|
|
12011
12140
|
});
|
|
12012
12141
|
import z2 from "@deepseek-ai/schemastery";
|
|
12013
12142
|
|
|
@@ -12017,7 +12146,7 @@ import { randomUUID } from "node:crypto";
|
|
|
12017
12146
|
// src/components/auto-review-fix/review-context.ts
|
|
12018
12147
|
import { appendFileSync as appendFileSync3 } from "node:fs";
|
|
12019
12148
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
12020
|
-
import { join as
|
|
12149
|
+
import { join as join4 } from "node:path";
|
|
12021
12150
|
var REVIEW_MARKER = "REVIEW_POLICY";
|
|
12022
12151
|
var REVIEW_MARKER_2 = "final authorization reviewer";
|
|
12023
12152
|
var HISTORY_HEADER = "FILTERED_HISTORY\n\n";
|
|
@@ -12038,7 +12167,7 @@ function textOf(message) {
|
|
|
12038
12167
|
}
|
|
12039
12168
|
return texts.join("");
|
|
12040
12169
|
}
|
|
12041
|
-
function
|
|
12170
|
+
function isLegacyAutoReviewRequest(options) {
|
|
12042
12171
|
if (!record(options)) return false;
|
|
12043
12172
|
const system = options.system;
|
|
12044
12173
|
if (typeof system !== "string" || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false;
|
|
@@ -12129,7 +12258,7 @@ function parseArray(text3) {
|
|
|
12129
12258
|
function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
|
|
12130
12259
|
try {
|
|
12131
12260
|
appendFileSync3(
|
|
12132
|
-
|
|
12261
|
+
join4(tmpdir3(), "dsh-mcviseron-auto-review.log"),
|
|
12133
12262
|
(/* @__PURE__ */ new Date()).toISOString() + " review context trimmed: " + String(originalChars) + " -> " + String(nextChars) + " chars, history " + String(originalEntries) + " -> " + String(nextEntries) + "\n",
|
|
12134
12263
|
"utf8"
|
|
12135
12264
|
);
|
|
@@ -12137,7 +12266,9 @@ function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
|
|
|
12137
12266
|
}
|
|
12138
12267
|
}
|
|
12139
12268
|
function trimReviewRequest(options, settings) {
|
|
12140
|
-
if (!settings.enabled
|
|
12269
|
+
if (!settings.enabled) return options;
|
|
12270
|
+
if (isModernAutoReviewRequest(options)) return trimModernReviewRequest(options, settings);
|
|
12271
|
+
if (!isLegacyAutoReviewRequest(options)) return options;
|
|
12141
12272
|
const messages = options.messages;
|
|
12142
12273
|
const message = messages[0];
|
|
12143
12274
|
const text3 = textOf(message);
|
|
@@ -12165,12 +12296,139 @@ function trimReviewRequest(options, settings) {
|
|
|
12165
12296
|
]
|
|
12166
12297
|
};
|
|
12167
12298
|
}
|
|
12299
|
+
var MODERN_PURPOSE = "auto-review";
|
|
12300
|
+
var ENVIRONMENT_HEADER = "ENVIRONMENT\n";
|
|
12301
|
+
var MODERN_USER_ROLES = /* @__PURE__ */ new Set(["user-instruction", "direct-parent-instruction", "constraint", "checkpoint", "human-instruction"]);
|
|
12302
|
+
var MODERN_USER_TEXT_CHARS = 8e3;
|
|
12303
|
+
var MODERN_TOOL_ARGUMENT_CHARS = 4e3;
|
|
12304
|
+
var MODERN_SCHEMA_DESCRIPTION_CHARS = 4e3;
|
|
12305
|
+
var MODERN_SCHEMA_PARAMETER_CHARS = 12e3;
|
|
12306
|
+
function isModernAutoReviewRequest(options) {
|
|
12307
|
+
if (!record(options) || options.purpose !== MODERN_PURPOSE) return false;
|
|
12308
|
+
if (typeof options.system !== "string" || !options.system.includes(REVIEW_MARKER) || !options.system.includes(REVIEW_MARKER_2)) return false;
|
|
12309
|
+
if (!Array.isArray(options.messages) || options.messages.length < 2) return false;
|
|
12310
|
+
const first = textOf(options.messages[0]);
|
|
12311
|
+
return first !== void 0 && first.startsWith(ENVIRONMENT_HEADER);
|
|
12312
|
+
}
|
|
12313
|
+
function modernRole(entry) {
|
|
12314
|
+
return record(entry) && typeof entry.role === "string" ? entry.role : void 0;
|
|
12315
|
+
}
|
|
12316
|
+
function modernProtected(entry, index, lastIndex, schemaIndexes) {
|
|
12317
|
+
if (index === lastIndex) return true;
|
|
12318
|
+
const role = modernRole(entry);
|
|
12319
|
+
if (role !== void 0 && MODERN_USER_ROLES.has(role)) return true;
|
|
12320
|
+
return schemaIndexes.has(index);
|
|
12321
|
+
}
|
|
12322
|
+
function compactModernContent(content, textLimit) {
|
|
12323
|
+
if (!Array.isArray(content)) return [];
|
|
12324
|
+
return content.map((block) => {
|
|
12325
|
+
if (!record(block)) return { type: "text", text: "[non-text history block omitted from reviewer context]" };
|
|
12326
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
12327
|
+
return { ...block, text: truncateText(block.text, textLimit) };
|
|
12328
|
+
}
|
|
12329
|
+
return { type: "text", text: "[" + String(block.type ?? "attachment") + " omitted from reviewer context]" };
|
|
12330
|
+
});
|
|
12331
|
+
}
|
|
12332
|
+
function compactModernEntry(entry, pending) {
|
|
12333
|
+
if (!record(entry)) return { kind: "summary", role: "fact", content: [{ type: "text", text: "[invalid history entry omitted]" }] };
|
|
12334
|
+
if (pending) return entry;
|
|
12335
|
+
if (entry.kind === "user-message") {
|
|
12336
|
+
return { ...entry, content: compactModernContent(entry.content, MODERN_USER_TEXT_CHARS) };
|
|
12337
|
+
}
|
|
12338
|
+
if (entry.kind === "tool-call") {
|
|
12339
|
+
if (typeof entry.arguments === "string") {
|
|
12340
|
+
return { ...entry, arguments: truncateText(entry.arguments, MODERN_TOOL_ARGUMENT_CHARS) };
|
|
12341
|
+
}
|
|
12342
|
+
if (entry.arguments !== void 0) {
|
|
12343
|
+
let rendered = "";
|
|
12344
|
+
try {
|
|
12345
|
+
rendered = JSON.stringify(entry.arguments) ?? "";
|
|
12346
|
+
} catch {
|
|
12347
|
+
rendered = "";
|
|
12348
|
+
}
|
|
12349
|
+
return { ...entry, arguments: truncateText(rendered, MODERN_TOOL_ARGUMENT_CHARS) };
|
|
12350
|
+
}
|
|
12351
|
+
}
|
|
12352
|
+
if (entry.kind === "tool-schema") {
|
|
12353
|
+
const description = typeof entry.description === "string" ? truncateText(entry.description, MODERN_SCHEMA_DESCRIPTION_CHARS) : entry.description;
|
|
12354
|
+
let parameters = entry.parameters;
|
|
12355
|
+
if (parameters !== void 0) {
|
|
12356
|
+
try {
|
|
12357
|
+
const rendered = JSON.stringify(parameters) ?? "";
|
|
12358
|
+
if (rendered.length > MODERN_SCHEMA_PARAMETER_CHARS) parameters = truncateText(rendered, MODERN_SCHEMA_PARAMETER_CHARS);
|
|
12359
|
+
} catch {
|
|
12360
|
+
parameters = "[unserializable schema parameters omitted]";
|
|
12361
|
+
}
|
|
12362
|
+
}
|
|
12363
|
+
return { ...entry, description, parameters };
|
|
12364
|
+
}
|
|
12365
|
+
return entry;
|
|
12366
|
+
}
|
|
12367
|
+
function modernSchemaIndexes(entries) {
|
|
12368
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
12369
|
+
entries.forEach((entry, index) => {
|
|
12370
|
+
if (!record(entry) || entry.kind !== "tool-schema") return;
|
|
12371
|
+
indexes.set(String(entry.mode) + "\0" + String(entry.name), index);
|
|
12372
|
+
});
|
|
12373
|
+
return new Set(indexes.values());
|
|
12374
|
+
}
|
|
12375
|
+
function trimModernReviewRequest(options, settings) {
|
|
12376
|
+
const messages = options.messages;
|
|
12377
|
+
const first = textOf(messages[0]);
|
|
12378
|
+
if (first === void 0 || !first.startsWith(ENVIRONMENT_HEADER)) return options;
|
|
12379
|
+
const entries = [];
|
|
12380
|
+
for (const message of messages.slice(1)) {
|
|
12381
|
+
const text3 = textOf(message);
|
|
12382
|
+
if (text3 === void 0) return options;
|
|
12383
|
+
try {
|
|
12384
|
+
entries.push(JSON.parse(text3));
|
|
12385
|
+
} catch {
|
|
12386
|
+
return options;
|
|
12387
|
+
}
|
|
12388
|
+
}
|
|
12389
|
+
if (entries.length === 0) return options;
|
|
12390
|
+
const lastIndex = entries.length - 1;
|
|
12391
|
+
const schemaIndexes = modernSchemaIndexes(entries);
|
|
12392
|
+
const recentStart = Math.max(0, entries.length - Math.max(1, settings.keepRecentEntries));
|
|
12393
|
+
const selected = [];
|
|
12394
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
12395
|
+
if (index >= recentStart || modernProtected(entries[index], index, lastIndex, schemaIndexes)) selected.push(index);
|
|
12396
|
+
}
|
|
12397
|
+
let omitted = entries.length - selected.length;
|
|
12398
|
+
const compacted = selected.map((index) => compactModernEntry(entries[index], index === lastIndex));
|
|
12399
|
+
while (selected.length > 2 && jsonLength(compacted) > settings.maxHistoryChars) {
|
|
12400
|
+
let at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1 && !modernProtected(entries[index], index, lastIndex, schemaIndexes));
|
|
12401
|
+
if (at < 0) at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1);
|
|
12402
|
+
if (at < 0) break;
|
|
12403
|
+
selected.splice(at, 1);
|
|
12404
|
+
compacted.splice(at, 1);
|
|
12405
|
+
omitted += 1;
|
|
12406
|
+
}
|
|
12407
|
+
const summary = {
|
|
12408
|
+
kind: "summary",
|
|
12409
|
+
role: "fact",
|
|
12410
|
+
content: [{
|
|
12411
|
+
type: "text",
|
|
12412
|
+
text: "[auto-review-fix] " + String(omitted) + " earlier history entries omitted from the reviewer context (original history " + String(jsonLength(entries)) + " chars). Current action, instructions and recent context are retained."
|
|
12413
|
+
}]
|
|
12414
|
+
};
|
|
12415
|
+
const nextMessages = [messages[0]];
|
|
12416
|
+
if (omitted > 0) nextMessages.push({ role: "user", content: [{ type: "text", text: JSON.stringify(summary) }] });
|
|
12417
|
+
selected.forEach((originalIndex, position) => {
|
|
12418
|
+
const original = messages[originalIndex + 1];
|
|
12419
|
+
if (originalIndex === lastIndex) nextMessages.push(original);
|
|
12420
|
+
else nextMessages.push({ ...original, content: [{ type: "text", text: JSON.stringify(compacted[position]) }] });
|
|
12421
|
+
});
|
|
12422
|
+
if (jsonLength(nextMessages) >= jsonLength(messages)) return options;
|
|
12423
|
+
logTrim(jsonLength(messages), jsonLength(nextMessages), entries.length, selected.length);
|
|
12424
|
+
return { ...options, messages: nextMessages };
|
|
12425
|
+
}
|
|
12168
12426
|
var guardedLlms = /* @__PURE__ */ new WeakMap();
|
|
12169
12427
|
function whenService(ctx, name, run) {
|
|
12170
12428
|
try {
|
|
12171
|
-
const
|
|
12172
|
-
if (typeof
|
|
12173
|
-
|
|
12429
|
+
const inject6 = ctx.inject;
|
|
12430
|
+
if (typeof inject6 === "function") {
|
|
12431
|
+
inject6.call(ctx, [name], run);
|
|
12174
12432
|
return;
|
|
12175
12433
|
}
|
|
12176
12434
|
const get = ctx.get;
|
|
@@ -12401,16 +12659,16 @@ function normalizeConfig(config) {
|
|
|
12401
12659
|
model: stringSetting(source, "translateModel", ""),
|
|
12402
12660
|
reviewContext: {
|
|
12403
12661
|
enabled: boolSetting(source, "reviewContextGuard", true),
|
|
12404
|
-
maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars",
|
|
12405
|
-
keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries",
|
|
12662
|
+
maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars", 2e5, 2e4, 6e5),
|
|
12663
|
+
keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries", 32, 4, 64)
|
|
12406
12664
|
}
|
|
12407
12665
|
};
|
|
12408
12666
|
}
|
|
12409
12667
|
function whenService2(ctx, name, run) {
|
|
12410
12668
|
try {
|
|
12411
|
-
const
|
|
12412
|
-
if (typeof
|
|
12413
|
-
|
|
12669
|
+
const inject6 = ctx.inject;
|
|
12670
|
+
if (typeof inject6 === "function") {
|
|
12671
|
+
inject6.call(ctx, [name], run);
|
|
12414
12672
|
return;
|
|
12415
12673
|
}
|
|
12416
12674
|
const get = ctx.get;
|
|
@@ -12652,8 +12910,8 @@ var DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
|
12652
12910
|
translateProvider: "",
|
|
12653
12911
|
translateModel: "",
|
|
12654
12912
|
reviewContextGuard: true,
|
|
12655
|
-
reviewMaxHistoryChars:
|
|
12656
|
-
reviewKeepRecentEntries:
|
|
12913
|
+
reviewMaxHistoryChars: 2e5,
|
|
12914
|
+
reviewKeepRecentEntries: 32
|
|
12657
12915
|
};
|
|
12658
12916
|
var Config2 = z2.object({
|
|
12659
12917
|
keepPresetGuard: z2.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.keepPresetGuard).volatile(),
|
|
@@ -12666,7 +12924,7 @@ var Config2 = z2.object({
|
|
|
12666
12924
|
reviewMaxHistoryChars: z2.number().min(2e4).max(6e5).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
|
|
12667
12925
|
reviewKeepRecentEntries: z2.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile()
|
|
12668
12926
|
}).default(DEFAULT_AUTO_REVIEW_CONFIG);
|
|
12669
|
-
function
|
|
12927
|
+
function apply5(ctx, config) {
|
|
12670
12928
|
installAutoReview(ctx, toPlain(config));
|
|
12671
12929
|
}
|
|
12672
12930
|
|
|
@@ -12676,19 +12934,21 @@ __export(restart_exports, {
|
|
|
12676
12934
|
Config: () => Config3,
|
|
12677
12935
|
DEFAULT_RESTART_CONFIG: () => DEFAULT_RESTART_CONFIG,
|
|
12678
12936
|
RESTART_API: () => RESTART_API,
|
|
12679
|
-
apply: () =>
|
|
12937
|
+
apply: () => apply6,
|
|
12680
12938
|
closeDesktop: () => closeDesktop,
|
|
12681
12939
|
deriveDesktopAppPath: () => deriveDesktopAppPath,
|
|
12682
|
-
inject: () =>
|
|
12940
|
+
inject: () => inject4,
|
|
12683
12941
|
launchRestart: () => launchRestart,
|
|
12684
12942
|
makeRestartRoutes: () => makeRestartRoutes,
|
|
12685
12943
|
makeTaskScript: () => makeTaskScript,
|
|
12686
|
-
|
|
12944
|
+
resolveProcessRestartTarget: () => resolveProcessRestartTarget,
|
|
12945
|
+
resolveRestartTarget: () => resolveRestartTarget,
|
|
12946
|
+
restartMode: () => restartMode
|
|
12687
12947
|
});
|
|
12688
|
-
import { execFileSync } from "node:child_process";
|
|
12689
|
-
import { appendFileSync as appendFileSync4, existsSync } from "node:fs";
|
|
12948
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
12949
|
+
import { appendFileSync as appendFileSync4, existsSync as existsSync2, writeFileSync } from "node:fs";
|
|
12690
12950
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
12691
|
-
import { basename, dirname, join as
|
|
12951
|
+
import { basename, dirname, join as join5, resolve } from "node:path";
|
|
12692
12952
|
import z3 from "@deepseek-ai/schemastery";
|
|
12693
12953
|
var DEFAULT_RESTART_CONFIG = { enabled: true, appPath: "" };
|
|
12694
12954
|
var Config3 = z3.object({
|
|
@@ -12701,7 +12961,9 @@ var RESTART_API = {
|
|
|
12701
12961
|
execute: "/api/dsh-mcviseron/restart/execute"
|
|
12702
12962
|
};
|
|
12703
12963
|
function resolveRestartTarget(execPath, parentPid, exists, override = "", argv = [], platform = process.platform) {
|
|
12704
|
-
if (platform !== "win32")
|
|
12964
|
+
if (platform !== "win32") {
|
|
12965
|
+
return resolveProcessRestartTarget({ platform, execPath, argv: argv.slice(1), cwd: process.cwd() });
|
|
12966
|
+
}
|
|
12705
12967
|
if (!Number.isSafeInteger(parentPid) || parentPid <= 0) return void 0;
|
|
12706
12968
|
const configured = typeof override === "string" ? override.trim() : "";
|
|
12707
12969
|
const candidate = configured !== "" ? configured : deriveDesktopAppPath(execPath, argv, exists);
|
|
@@ -12710,6 +12972,23 @@ function resolveRestartTarget(execPath, parentPid, exists, override = "", argv =
|
|
|
12710
12972
|
if (name === "node" || name === "node.exe") return void 0;
|
|
12711
12973
|
return { mainPid: parentPid, hostPid: process.pid, exePath: candidate };
|
|
12712
12974
|
}
|
|
12975
|
+
function resolveProcessRestartTarget(options = {}) {
|
|
12976
|
+
const platform = options.platform ?? process.platform;
|
|
12977
|
+
if (platform === "win32") return void 0;
|
|
12978
|
+
const argv = options.argv ?? process.argv.slice(1);
|
|
12979
|
+
if (argv.length === 0 || argv[0] === "") return void 0;
|
|
12980
|
+
const env = options.env ?? process.env;
|
|
12981
|
+
const override = (env.DSH_MCVISERON_RESTART_MODE ?? "").trim().toLowerCase();
|
|
12982
|
+
const supervised = override === "supervisor-exit" || override === "exit" || override !== "reexec" && (env.INVOCATION_ID !== void 0 || env.JOURNAL_STREAM !== void 0 || env.SYSTEMD_EXEC_PID !== void 0 || env.KUBERNETES_SERVICE_HOST !== void 0 || existsSync2("/.dockerenv") || options.pid1 === true || (options.pid ?? process.pid) === 1);
|
|
12983
|
+
const nodeArgs = options.execArgv ?? process.execArgv;
|
|
12984
|
+
return {
|
|
12985
|
+
hostPid: options.pid ?? process.pid,
|
|
12986
|
+
exePath: options.execPath ?? process.execPath,
|
|
12987
|
+
mode: supervised ? "supervisor-exit" : "reexec",
|
|
12988
|
+
argv: [...nodeArgs, ...argv],
|
|
12989
|
+
cwd: options.cwd ?? process.cwd()
|
|
12990
|
+
};
|
|
12991
|
+
}
|
|
12713
12992
|
function deriveDesktopAppPath(execPath, argv, exists) {
|
|
12714
12993
|
const isNode = (value) => /^node(\.exe)?$/i.test(basename(value));
|
|
12715
12994
|
if (!isNode(execPath)) return execPath;
|
|
@@ -12717,13 +12996,16 @@ function deriveDesktopAppPath(execPath, argv, exists) {
|
|
|
12717
12996
|
if (argv0 !== "" && argv0 !== execPath && !isNode(argv0) && exists(argv0)) return argv0;
|
|
12718
12997
|
const runtimeDir = argv[2] ?? "";
|
|
12719
12998
|
if (runtimeDir === "") return execPath;
|
|
12720
|
-
const candidate =
|
|
12999
|
+
const candidate = join5(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
|
|
12721
13000
|
return exists(candidate) ? candidate : execPath;
|
|
12722
13001
|
}
|
|
13002
|
+
function restartMode(target) {
|
|
13003
|
+
return target.mode ?? (target.mainPid !== void 0 ? "desktop" : "reexec");
|
|
13004
|
+
}
|
|
12723
13005
|
var RESTART_TASK_NAME = "DSH-MCviseron-Restart";
|
|
12724
13006
|
var RESTART_DELAY_SECONDS = 6;
|
|
12725
13007
|
function restartLogPath() {
|
|
12726
|
-
return
|
|
13008
|
+
return join5(tmpdir4(), "dsh-mcviseron-restart.log");
|
|
12727
13009
|
}
|
|
12728
13010
|
function makeTaskScript(target, taskName, delaySeconds) {
|
|
12729
13011
|
const quote = (value) => "'" + value.replace(/'/g, "''") + "'";
|
|
@@ -12736,14 +13018,62 @@ function makeTaskScript(target, taskName, delaySeconds) {
|
|
|
12736
13018
|
""
|
|
12737
13019
|
].join("\n");
|
|
12738
13020
|
}
|
|
13021
|
+
function writeRestartLog(message) {
|
|
13022
|
+
try {
|
|
13023
|
+
appendFileSync4(restartLogPath(), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
13024
|
+
} catch {
|
|
13025
|
+
}
|
|
13026
|
+
}
|
|
13027
|
+
var PROCESS_HELPER = [
|
|
13028
|
+
"const { spawn } = require('node:child_process')",
|
|
13029
|
+
"const [pidText, cwd, exe, ...args] = process.argv.slice(2)",
|
|
13030
|
+
"const pid = Number(pidText)",
|
|
13031
|
+
"const started = Date.now()",
|
|
13032
|
+
"const start = () => {",
|
|
13033
|
+
" try {",
|
|
13034
|
+
' const child = spawn(exe, args, { cwd, detached: true, stdio: "ignore", env: process.env })',
|
|
13035
|
+
" child.unref()",
|
|
13036
|
+
" } catch { /* the supervisor or user will see the failure */ }",
|
|
13037
|
+
"}",
|
|
13038
|
+
"const timer = setInterval(() => {",
|
|
13039
|
+
" let alive = false",
|
|
13040
|
+
" try { process.kill(pid, 0); alive = true } catch { /* parent is gone */ }",
|
|
13041
|
+
" if (!alive || Date.now() - started > 30_000) { clearInterval(timer); start() }",
|
|
13042
|
+
"}, 100)",
|
|
13043
|
+
"timer.unref?.()"
|
|
13044
|
+
].join("\n");
|
|
13045
|
+
function ensureProcessHelper() {
|
|
13046
|
+
const path = join5(tmpdir4(), "dsh-mcviseron-restart-helper.cjs");
|
|
13047
|
+
writeFileSync(path, PROCESS_HELPER, "utf8");
|
|
13048
|
+
return path;
|
|
13049
|
+
}
|
|
13050
|
+
function launchProcessRestart(target) {
|
|
13051
|
+
if (target.mode === "supervisor-exit") {
|
|
13052
|
+
writeRestartLog("host: supervised restart requested; exit 75");
|
|
13053
|
+
setTimeout(() => process.exit(75), 300);
|
|
13054
|
+
return;
|
|
13055
|
+
}
|
|
13056
|
+
try {
|
|
13057
|
+
const helper = ensureProcessHelper();
|
|
13058
|
+
const args = [helper, String(process.pid), target.cwd ?? process.cwd(), target.exePath, ...target.argv ?? []];
|
|
13059
|
+
const child = spawn(process.execPath, args, { detached: true, stdio: "ignore", env: { ...process.env, DSH_MCVISERON_RESTARTED: "1" } });
|
|
13060
|
+
child.unref();
|
|
13061
|
+
writeRestartLog("host: detached re-exec helper started");
|
|
13062
|
+
} catch (error) {
|
|
13063
|
+
writeRestartLog("host: re-exec helper failed: " + (error instanceof Error ? error.message : String(error)));
|
|
13064
|
+
throw new Error("cannot start the Linux restart helper", { cause: error });
|
|
13065
|
+
}
|
|
13066
|
+
setTimeout(() => process.exit(0), 300);
|
|
13067
|
+
}
|
|
12739
13068
|
function launchRestart(target) {
|
|
12740
|
-
launchHelper(target);
|
|
13069
|
+
if (restartMode(target) === "desktop") launchHelper(target);
|
|
13070
|
+
else launchProcessRestart(target);
|
|
12741
13071
|
}
|
|
12742
13072
|
function closeDesktop(target) {
|
|
12743
|
-
const
|
|
13073
|
+
const mainPid = target?.mainPid;
|
|
12744
13074
|
setTimeout(() => {
|
|
12745
13075
|
try {
|
|
12746
|
-
if (target !== void 0
|
|
13076
|
+
if (mainPid !== void 0 && target !== void 0 && restartMode(target) === "desktop") process.kill(mainPid);
|
|
12747
13077
|
else process.exit(0);
|
|
12748
13078
|
} catch {
|
|
12749
13079
|
try {
|
|
@@ -12772,10 +13102,12 @@ function launchHelper(target) {
|
|
|
12772
13102
|
`, "utf8");
|
|
12773
13103
|
throw new Error("cannot schedule the restart task: " + message, { cause: error });
|
|
12774
13104
|
}
|
|
13105
|
+
const mainPid = target.mainPid;
|
|
13106
|
+
if (mainPid === void 0) throw new Error("desktop restart target has no main PID");
|
|
12775
13107
|
setTimeout(() => {
|
|
12776
13108
|
try {
|
|
12777
|
-
process.kill(
|
|
12778
|
-
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${
|
|
13109
|
+
process.kill(mainPid);
|
|
13110
|
+
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${mainPid}
|
|
12779
13111
|
`, "utf8");
|
|
12780
13112
|
} catch (error) {
|
|
12781
13113
|
appendFileSync4(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill failed: ${error instanceof Error ? error.message : String(error)}
|
|
@@ -12813,7 +13145,7 @@ function makeRestartRoutes(deps) {
|
|
|
12813
13145
|
if (req.method !== "GET" && req.method !== "POST") return json3(res, 405, { ok: false, error: "method-not-allowed" });
|
|
12814
13146
|
if (!isLoopbackRequest(req)) return json3(res, 403, { ok: false, error: "forbidden" });
|
|
12815
13147
|
const target = deps.target();
|
|
12816
|
-
json3(res, 200, target === void 0 ? { ok: true, available: false, reason: "
|
|
13148
|
+
json3(res, 200, target === void 0 ? { ok: true, available: false, reason: "restart-target-unavailable" } : { ok: true, available: true, mode: restartMode(target), appPath: target.exePath, mainPid: target.mainPid ?? null });
|
|
12817
13149
|
} catch (error) {
|
|
12818
13150
|
json3(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
12819
13151
|
}
|
|
@@ -12830,13 +13162,16 @@ function makeRestartRoutes(deps) {
|
|
|
12830
13162
|
if (body === void 0 || typeof body !== "object" || body === null || body.confirm !== true) {
|
|
12831
13163
|
return json3(res, 400, { ok: false, error: "confirmation-required" });
|
|
12832
13164
|
}
|
|
13165
|
+
const action = body.action ?? "restart";
|
|
13166
|
+
if (action !== "restart" && action !== "close") return json3(res, 400, { ok: false, error: "action-invalid" });
|
|
12833
13167
|
const latest = now();
|
|
12834
|
-
if (latest - lastLaunch < 5e3) return json3(res, 429, { ok: false, error: "restart-already-scheduled" });
|
|
13168
|
+
if (action === "restart" && latest - lastLaunch < 5e3) return json3(res, 429, { ok: false, error: "restart-already-scheduled" });
|
|
12835
13169
|
const target = deps.target();
|
|
12836
|
-
if (target === void 0) return json3(res, 409, { ok: false, error: "
|
|
12837
|
-
deps.launch(target);
|
|
12838
|
-
|
|
12839
|
-
|
|
13170
|
+
if (action === "restart" && target === void 0) return json3(res, 409, { ok: false, error: "restart-target-unavailable" });
|
|
13171
|
+
if (action === "restart") deps.launch(target);
|
|
13172
|
+
else (deps.close ?? closeDesktop)(target);
|
|
13173
|
+
if (action === "restart") lastLaunch = latest;
|
|
13174
|
+
json3(res, 200, { ok: true, action, restarting: action === "restart", closing: action === "close", mode: target === void 0 ? null : restartMode(target) });
|
|
12840
13175
|
} catch (error) {
|
|
12841
13176
|
json3(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
12842
13177
|
}
|
|
@@ -12844,14 +13179,15 @@ function makeRestartRoutes(deps) {
|
|
|
12844
13179
|
};
|
|
12845
13180
|
return [status, execute];
|
|
12846
13181
|
}
|
|
12847
|
-
var
|
|
12848
|
-
function
|
|
13182
|
+
var inject4 = ["webServer"];
|
|
13183
|
+
function apply6(ctx, config) {
|
|
12849
13184
|
const plain = toPlain(config) ?? {};
|
|
12850
13185
|
if (plain.enabled === false) return;
|
|
12851
13186
|
const appPath = typeof plain.appPath === "string" ? plain.appPath : "";
|
|
12852
13187
|
const routes = makeRestartRoutes({
|
|
12853
|
-
target: () => resolveRestartTarget(process.execPath, process.ppid,
|
|
12854
|
-
launch:
|
|
13188
|
+
target: () => resolveRestartTarget(process.execPath, process.ppid, existsSync2, appPath, process.argv),
|
|
13189
|
+
launch: launchRestart,
|
|
13190
|
+
close: closeDesktop
|
|
12855
13191
|
});
|
|
12856
13192
|
ctx.effect(() => {
|
|
12857
13193
|
const disposers = routes.map((route) => ctx.webServer.register(route));
|
|
@@ -12866,9 +13202,9 @@ var session_end_exports = {};
|
|
|
12866
13202
|
__export(session_end_exports, {
|
|
12867
13203
|
Config: () => Config4,
|
|
12868
13204
|
DEFAULT_SESSION_END_CONFIG: () => DEFAULT_SESSION_END_CONFIG,
|
|
12869
|
-
apply: () =>
|
|
13205
|
+
apply: () => apply7,
|
|
12870
13206
|
createSessionEndController: () => createSessionEndController,
|
|
12871
|
-
inject: () =>
|
|
13207
|
+
inject: () => inject5,
|
|
12872
13208
|
inspectRunningTasks: () => inspectRunningTasks,
|
|
12873
13209
|
isSessionEndMode: () => isSessionEndMode,
|
|
12874
13210
|
makeSessionEndRoutes: () => makeSessionEndRoutes,
|
|
@@ -12876,9 +13212,9 @@ __export(session_end_exports, {
|
|
|
12876
13212
|
shutdownComputer: () => shutdownComputer
|
|
12877
13213
|
});
|
|
12878
13214
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
12879
|
-
import { appendFileSync as appendFileSync5, existsSync as
|
|
13215
|
+
import { appendFileSync as appendFileSync5, existsSync as existsSync3 } from "node:fs";
|
|
12880
13216
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
12881
|
-
import { join as
|
|
13217
|
+
import { join as join6 } from "node:path";
|
|
12882
13218
|
import z4 from "@deepseek-ai/schemastery";
|
|
12883
13219
|
|
|
12884
13220
|
// src/session-end/email.ts
|
|
@@ -13010,7 +13346,7 @@ function isSessionEndMode(value) {
|
|
|
13010
13346
|
return value === "off" || value === "restart" || value === "close" || value === "shutdown";
|
|
13011
13347
|
}
|
|
13012
13348
|
function sessionLogPath() {
|
|
13013
|
-
return
|
|
13349
|
+
return join6(tmpdir5(), "dsh-mcviseron-session-end.log");
|
|
13014
13350
|
}
|
|
13015
13351
|
function defaultLog(message) {
|
|
13016
13352
|
try {
|
|
@@ -13081,7 +13417,7 @@ function createSessionEndController(deps = {}) {
|
|
|
13081
13417
|
const resolveTarget = deps.resolveTarget ?? (() => resolveRestartTarget(
|
|
13082
13418
|
process.execPath,
|
|
13083
13419
|
process.ppid,
|
|
13084
|
-
|
|
13420
|
+
existsSync3,
|
|
13085
13421
|
typeof deps.appPath === "string" ? deps.appPath : "",
|
|
13086
13422
|
process.argv
|
|
13087
13423
|
));
|
|
@@ -13097,12 +13433,12 @@ function createSessionEndController(deps = {}) {
|
|
|
13097
13433
|
};
|
|
13098
13434
|
const view = (sessionId) => {
|
|
13099
13435
|
const entry = entries.get(sessionId);
|
|
13100
|
-
let available = { restart: false, close:
|
|
13436
|
+
let available = { restart: false, close: true, shutdown: platform === "win32" };
|
|
13101
13437
|
try {
|
|
13102
13438
|
const target = resolveTarget();
|
|
13103
13439
|
available = {
|
|
13104
13440
|
restart: target !== void 0,
|
|
13105
|
-
close:
|
|
13441
|
+
close: true,
|
|
13106
13442
|
shutdown: platform === "win32"
|
|
13107
13443
|
};
|
|
13108
13444
|
} catch {
|
|
@@ -13332,10 +13668,10 @@ function serviceOf4(ctx, name) {
|
|
|
13332
13668
|
}
|
|
13333
13669
|
}
|
|
13334
13670
|
function installGuidance(ctx) {
|
|
13335
|
-
const
|
|
13336
|
-
if (typeof
|
|
13671
|
+
const inject6 = ctx.inject;
|
|
13672
|
+
if (typeof inject6 !== "function") return;
|
|
13337
13673
|
try {
|
|
13338
|
-
|
|
13674
|
+
inject6.call(ctx, ["systemPrompt"], (scope) => {
|
|
13339
13675
|
const systemPrompt = serviceOf4(scope, "systemPrompt");
|
|
13340
13676
|
if (systemPrompt === void 0 || typeof systemPrompt.section !== "function") return;
|
|
13341
13677
|
try {
|
|
@@ -13354,10 +13690,10 @@ function installGuidance(ctx) {
|
|
|
13354
13690
|
}
|
|
13355
13691
|
var emailed = /* @__PURE__ */ new Map();
|
|
13356
13692
|
function installAgentTool(ctx, controller, options, log2) {
|
|
13357
|
-
const
|
|
13358
|
-
if (typeof
|
|
13693
|
+
const inject6 = ctx.inject;
|
|
13694
|
+
if (typeof inject6 !== "function") return;
|
|
13359
13695
|
try {
|
|
13360
|
-
|
|
13696
|
+
inject6.call(ctx, ["tools"], (scope) => {
|
|
13361
13697
|
const tools = serviceOf4(scope, "tools");
|
|
13362
13698
|
if (tools === void 0 || typeof tools.register !== "function") return;
|
|
13363
13699
|
const definition = {
|
|
@@ -13497,8 +13833,8 @@ function normalizeSessionEndOptions(input) {
|
|
|
13497
13833
|
appPath: string("appPath", "")
|
|
13498
13834
|
};
|
|
13499
13835
|
}
|
|
13500
|
-
var
|
|
13501
|
-
function
|
|
13836
|
+
var inject5 = ["webServer"];
|
|
13837
|
+
function apply7(ctx, config) {
|
|
13502
13838
|
const options = normalizeSessionEndOptions(config);
|
|
13503
13839
|
const log2 = defaultLog;
|
|
13504
13840
|
const controller = createSessionEndController({
|
|
@@ -13544,7 +13880,7 @@ var task_guard_exports = {};
|
|
|
13544
13880
|
__export(task_guard_exports, {
|
|
13545
13881
|
Config: () => Config5,
|
|
13546
13882
|
DEFAULT_TASK_GUARD_CONFIG: () => DEFAULT_TASK_GUARD_CONFIG,
|
|
13547
|
-
apply: () =>
|
|
13883
|
+
apply: () => apply8
|
|
13548
13884
|
});
|
|
13549
13885
|
import z5 from "@deepseek-ai/schemastery";
|
|
13550
13886
|
|
|
@@ -14256,7 +14592,7 @@ var Config5 = z5.object({
|
|
|
14256
14592
|
include: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.include).volatile(),
|
|
14257
14593
|
exclude: z5.array(z5.string()).default(DEFAULT_TASK_GUARD_CONFIG.exclude).volatile()
|
|
14258
14594
|
}).default(DEFAULT_TASK_GUARD_CONFIG);
|
|
14259
|
-
function
|
|
14595
|
+
function apply8(ctx, config) {
|
|
14260
14596
|
installTaskGuard(ctx, toPlain(config));
|
|
14261
14597
|
}
|
|
14262
14598
|
|
|
@@ -14286,9 +14622,10 @@ function mount(ctx, component, config) {
|
|
|
14286
14622
|
logger?.warn?.(new Error("mcviseron: cannot mount a component", { cause: error }));
|
|
14287
14623
|
}
|
|
14288
14624
|
}
|
|
14289
|
-
function
|
|
14625
|
+
function apply9(ctx, rawConfig) {
|
|
14290
14626
|
const config = toPlain(rawConfig) ?? {};
|
|
14291
14627
|
mount(ctx, automation_tasks_exports, {});
|
|
14628
|
+
mount(ctx, archive_integration_exports, {});
|
|
14292
14629
|
mount(ctx, auth_cookie_exports, {});
|
|
14293
14630
|
mount(ctx, appearance_exports, {
|
|
14294
14631
|
enabled: config.enabled ?? DEFAULT_SCHEDULE_CONFIG.enabled,
|
|
@@ -14307,5 +14644,5 @@ function apply8(ctx, rawConfig) {
|
|
|
14307
14644
|
}
|
|
14308
14645
|
export {
|
|
14309
14646
|
Config6 as Config,
|
|
14310
|
-
|
|
14647
|
+
apply9 as apply
|
|
14311
14648
|
};
|