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/restart.js
CHANGED
|
@@ -2,8 +2,8 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
const require = createRequire(import.meta.url);
|
|
3
3
|
|
|
4
4
|
// src/restart/index.ts
|
|
5
|
-
import { execFileSync } from "node:child_process";
|
|
6
|
-
import { appendFileSync, existsSync } from "node:fs";
|
|
5
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
6
|
+
import { appendFileSync, existsSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
8
8
|
import { basename, dirname, join, resolve } from "node:path";
|
|
9
9
|
import z from "@deepseek-ai/schemastery";
|
|
@@ -74,7 +74,9 @@ var RESTART_API = {
|
|
|
74
74
|
execute: "/api/dsh-mcviseron/restart/execute"
|
|
75
75
|
};
|
|
76
76
|
function resolveRestartTarget(execPath, parentPid, exists, override = "", argv = [], platform = process.platform) {
|
|
77
|
-
if (platform !== "win32")
|
|
77
|
+
if (platform !== "win32") {
|
|
78
|
+
return resolveProcessRestartTarget({ platform, execPath, argv: argv.slice(1), cwd: process.cwd() });
|
|
79
|
+
}
|
|
78
80
|
if (!Number.isSafeInteger(parentPid) || parentPid <= 0) return void 0;
|
|
79
81
|
const configured = typeof override === "string" ? override.trim() : "";
|
|
80
82
|
const candidate = configured !== "" ? configured : deriveDesktopAppPath(execPath, argv, exists);
|
|
@@ -83,6 +85,23 @@ function resolveRestartTarget(execPath, parentPid, exists, override = "", argv =
|
|
|
83
85
|
if (name === "node" || name === "node.exe") return void 0;
|
|
84
86
|
return { mainPid: parentPid, hostPid: process.pid, exePath: candidate };
|
|
85
87
|
}
|
|
88
|
+
function resolveProcessRestartTarget(options = {}) {
|
|
89
|
+
const platform = options.platform ?? process.platform;
|
|
90
|
+
if (platform === "win32") return void 0;
|
|
91
|
+
const argv = options.argv ?? process.argv.slice(1);
|
|
92
|
+
if (argv.length === 0 || argv[0] === "") return void 0;
|
|
93
|
+
const env = options.env ?? process.env;
|
|
94
|
+
const override = (env.DSH_MCVISERON_RESTART_MODE ?? "").trim().toLowerCase();
|
|
95
|
+
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 || existsSync("/.dockerenv") || options.pid1 === true || (options.pid ?? process.pid) === 1);
|
|
96
|
+
const nodeArgs = options.execArgv ?? process.execArgv;
|
|
97
|
+
return {
|
|
98
|
+
hostPid: options.pid ?? process.pid,
|
|
99
|
+
exePath: options.execPath ?? process.execPath,
|
|
100
|
+
mode: supervised ? "supervisor-exit" : "reexec",
|
|
101
|
+
argv: [...nodeArgs, ...argv],
|
|
102
|
+
cwd: options.cwd ?? process.cwd()
|
|
103
|
+
};
|
|
104
|
+
}
|
|
86
105
|
function deriveDesktopAppPath(execPath, argv, exists) {
|
|
87
106
|
const isNode = (value) => /^node(\.exe)?$/i.test(basename(value));
|
|
88
107
|
if (!isNode(execPath)) return execPath;
|
|
@@ -93,6 +112,9 @@ function deriveDesktopAppPath(execPath, argv, exists) {
|
|
|
93
112
|
const candidate = join(resolve(runtimeDir, "../../.."), "DeepSeek Harness.exe");
|
|
94
113
|
return exists(candidate) ? candidate : execPath;
|
|
95
114
|
}
|
|
115
|
+
function restartMode(target) {
|
|
116
|
+
return target.mode ?? (target.mainPid !== void 0 ? "desktop" : "reexec");
|
|
117
|
+
}
|
|
96
118
|
var RESTART_TASK_NAME = "DSH-MCviseron-Restart";
|
|
97
119
|
var RESTART_DELAY_SECONDS = 6;
|
|
98
120
|
function restartLogPath() {
|
|
@@ -109,14 +131,62 @@ function makeTaskScript(target, taskName, delaySeconds) {
|
|
|
109
131
|
""
|
|
110
132
|
].join("\n");
|
|
111
133
|
}
|
|
134
|
+
function writeRestartLog(message) {
|
|
135
|
+
try {
|
|
136
|
+
appendFileSync(restartLogPath(), (/* @__PURE__ */ new Date()).toISOString() + " " + message + "\n", "utf8");
|
|
137
|
+
} catch {
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
var PROCESS_HELPER = [
|
|
141
|
+
"const { spawn } = require('node:child_process')",
|
|
142
|
+
"const [pidText, cwd, exe, ...args] = process.argv.slice(2)",
|
|
143
|
+
"const pid = Number(pidText)",
|
|
144
|
+
"const started = Date.now()",
|
|
145
|
+
"const start = () => {",
|
|
146
|
+
" try {",
|
|
147
|
+
' const child = spawn(exe, args, { cwd, detached: true, stdio: "ignore", env: process.env })',
|
|
148
|
+
" child.unref()",
|
|
149
|
+
" } catch { /* the supervisor or user will see the failure */ }",
|
|
150
|
+
"}",
|
|
151
|
+
"const timer = setInterval(() => {",
|
|
152
|
+
" let alive = false",
|
|
153
|
+
" try { process.kill(pid, 0); alive = true } catch { /* parent is gone */ }",
|
|
154
|
+
" if (!alive || Date.now() - started > 30_000) { clearInterval(timer); start() }",
|
|
155
|
+
"}, 100)",
|
|
156
|
+
"timer.unref?.()"
|
|
157
|
+
].join("\n");
|
|
158
|
+
function ensureProcessHelper() {
|
|
159
|
+
const path = join(tmpdir(), "dsh-mcviseron-restart-helper.cjs");
|
|
160
|
+
writeFileSync(path, PROCESS_HELPER, "utf8");
|
|
161
|
+
return path;
|
|
162
|
+
}
|
|
163
|
+
function launchProcessRestart(target) {
|
|
164
|
+
if (target.mode === "supervisor-exit") {
|
|
165
|
+
writeRestartLog("host: supervised restart requested; exit 75");
|
|
166
|
+
setTimeout(() => process.exit(75), 300);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const helper = ensureProcessHelper();
|
|
171
|
+
const args = [helper, String(process.pid), target.cwd ?? process.cwd(), target.exePath, ...target.argv ?? []];
|
|
172
|
+
const child = spawn(process.execPath, args, { detached: true, stdio: "ignore", env: { ...process.env, DSH_MCVISERON_RESTARTED: "1" } });
|
|
173
|
+
child.unref();
|
|
174
|
+
writeRestartLog("host: detached re-exec helper started");
|
|
175
|
+
} catch (error) {
|
|
176
|
+
writeRestartLog("host: re-exec helper failed: " + (error instanceof Error ? error.message : String(error)));
|
|
177
|
+
throw new Error("cannot start the Linux restart helper", { cause: error });
|
|
178
|
+
}
|
|
179
|
+
setTimeout(() => process.exit(0), 300);
|
|
180
|
+
}
|
|
112
181
|
function launchRestart(target) {
|
|
113
|
-
launchHelper(target);
|
|
182
|
+
if (restartMode(target) === "desktop") launchHelper(target);
|
|
183
|
+
else launchProcessRestart(target);
|
|
114
184
|
}
|
|
115
185
|
function closeDesktop(target) {
|
|
116
|
-
const
|
|
186
|
+
const mainPid = target?.mainPid;
|
|
117
187
|
setTimeout(() => {
|
|
118
188
|
try {
|
|
119
|
-
if (target !== void 0
|
|
189
|
+
if (mainPid !== void 0 && target !== void 0 && restartMode(target) === "desktop") process.kill(mainPid);
|
|
120
190
|
else process.exit(0);
|
|
121
191
|
} catch {
|
|
122
192
|
try {
|
|
@@ -145,10 +215,12 @@ function launchHelper(target) {
|
|
|
145
215
|
`, "utf8");
|
|
146
216
|
throw new Error("cannot schedule the restart task: " + message, { cause: error });
|
|
147
217
|
}
|
|
218
|
+
const mainPid = target.mainPid;
|
|
219
|
+
if (mainPid === void 0) throw new Error("desktop restart target has no main PID");
|
|
148
220
|
setTimeout(() => {
|
|
149
221
|
try {
|
|
150
|
-
process.kill(
|
|
151
|
-
appendFileSync(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${
|
|
222
|
+
process.kill(mainPid);
|
|
223
|
+
appendFileSync(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill sent to ${mainPid}
|
|
152
224
|
`, "utf8");
|
|
153
225
|
} catch (error) {
|
|
154
226
|
appendFileSync(logFile, `${(/* @__PURE__ */ new Date()).toISOString()} host: kill failed: ${error instanceof Error ? error.message : String(error)}
|
|
@@ -186,7 +258,7 @@ function makeRestartRoutes(deps) {
|
|
|
186
258
|
if (req.method !== "GET" && req.method !== "POST") return json(res, 405, { ok: false, error: "method-not-allowed" });
|
|
187
259
|
if (!isLoopbackRequest(req)) return json(res, 403, { ok: false, error: "forbidden" });
|
|
188
260
|
const target = deps.target();
|
|
189
|
-
json(res, 200, target === void 0 ? { ok: true, available: false, reason: "
|
|
261
|
+
json(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 });
|
|
190
262
|
} catch (error) {
|
|
191
263
|
json(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
192
264
|
}
|
|
@@ -203,13 +275,16 @@ function makeRestartRoutes(deps) {
|
|
|
203
275
|
if (body === void 0 || typeof body !== "object" || body === null || body.confirm !== true) {
|
|
204
276
|
return json(res, 400, { ok: false, error: "confirmation-required" });
|
|
205
277
|
}
|
|
278
|
+
const action = body.action ?? "restart";
|
|
279
|
+
if (action !== "restart" && action !== "close") return json(res, 400, { ok: false, error: "action-invalid" });
|
|
206
280
|
const latest = now();
|
|
207
|
-
if (latest - lastLaunch < 5e3) return json(res, 429, { ok: false, error: "restart-already-scheduled" });
|
|
281
|
+
if (action === "restart" && latest - lastLaunch < 5e3) return json(res, 429, { ok: false, error: "restart-already-scheduled" });
|
|
208
282
|
const target = deps.target();
|
|
209
|
-
if (target === void 0) return json(res, 409, { ok: false, error: "
|
|
210
|
-
deps.launch(target);
|
|
211
|
-
|
|
212
|
-
|
|
283
|
+
if (action === "restart" && target === void 0) return json(res, 409, { ok: false, error: "restart-target-unavailable" });
|
|
284
|
+
if (action === "restart") deps.launch(target);
|
|
285
|
+
else (deps.close ?? closeDesktop)(target);
|
|
286
|
+
if (action === "restart") lastLaunch = latest;
|
|
287
|
+
json(res, 200, { ok: true, action, restarting: action === "restart", closing: action === "close", mode: target === void 0 ? null : restartMode(target) });
|
|
213
288
|
} catch (error) {
|
|
214
289
|
json(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
215
290
|
}
|
|
@@ -224,7 +299,8 @@ function apply(ctx, config) {
|
|
|
224
299
|
const appPath = typeof plain.appPath === "string" ? plain.appPath : "";
|
|
225
300
|
const routes = makeRestartRoutes({
|
|
226
301
|
target: () => resolveRestartTarget(process.execPath, process.ppid, existsSync, appPath, process.argv),
|
|
227
|
-
launch:
|
|
302
|
+
launch: launchRestart,
|
|
303
|
+
close: closeDesktop
|
|
228
304
|
});
|
|
229
305
|
ctx.effect(() => {
|
|
230
306
|
const disposers = routes.map((route) => ctx.webServer.register(route));
|
|
@@ -244,5 +320,7 @@ export {
|
|
|
244
320
|
launchRestart,
|
|
245
321
|
makeRestartRoutes,
|
|
246
322
|
makeTaskScript,
|
|
247
|
-
|
|
323
|
+
resolveProcessRestartTarget,
|
|
324
|
+
resolveRestartTarget,
|
|
325
|
+
restartMode
|
|
248
326
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mcviseron-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) master plugin — one package hosting MCviseron's DSH components as separate bundle entries: a time-based light/dark Appearance schedule, an Auto-review fix (shutdown preset guard + Chinese approval-reason translation), and a todo plan guard that keeps multi-stage work advancing, one-shot after-session restart/close actions with task-aware waiting, and automatic auth-cookie hygiene for repeated desktop restarts, and model-editable official automation tasks.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "node build.mjs",
|
|
80
80
|
"typecheck": "tsc --noEmit",
|
|
81
|
-
"test": "node --experimental-strip-types test/schedule.test.ts && node --experimental-strip-types test/routes.test.ts && node --experimental-strip-types test/config.test.ts && node --experimental-strip-types test/auto-review-fix.test.ts && node --experimental-strip-types test/auto-review-fix-cordis.test.ts && node --experimental-strip-types test/review-context.test.ts && node --experimental-strip-types test/global-notice.test.ts && node --experimental-strip-types test/task-guard.test.ts && node --experimental-strip-types test/task-guard-cordis.test.ts && node --experimental-strip-types test/session-end.test.ts && node --experimental-strip-types test/auth-cookie.test.ts && node --experimental-strip-types test/automation-tasks.test.ts && node --experimental-strip-types test/restart.test.ts && node --experimental-strip-types test/plugin.test.ts",
|
|
81
|
+
"test": "node --experimental-strip-types test/schedule.test.ts && node --experimental-strip-types test/routes.test.ts && node --experimental-strip-types test/config.test.ts && node --experimental-strip-types test/auto-review-fix.test.ts && node --experimental-strip-types test/auto-review-fix-cordis.test.ts && node --experimental-strip-types test/review-context.test.ts && node --experimental-strip-types test/global-notice.test.ts && node --experimental-strip-types test/task-guard.test.ts && node --experimental-strip-types test/task-guard-cordis.test.ts && node --experimental-strip-types test/session-end.test.ts && node --experimental-strip-types test/auth-cookie.test.ts && node --experimental-strip-types test/automation-tasks.test.ts && node --experimental-strip-types test/archive-integration.test.ts && node --experimental-strip-types test/restart.test.ts && node --experimental-strip-types test/plugin.test.ts",
|
|
82
82
|
"check": "pnpm typecheck && pnpm test && pnpm build",
|
|
83
83
|
"prepare": "pnpm build",
|
|
84
84
|
"prepublishOnly": "pnpm check",
|
|
@@ -86,12 +86,12 @@
|
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
89
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
90
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
91
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
92
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
93
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
94
|
-
"@deepseek-ai/dsh-settings": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3",
|
|
89
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
90
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
91
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
92
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
93
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
94
|
+
"@deepseek-ai/dsh-settings": "^0.2.0-rc.2 || ^0.2.1-rc.2 || ^0.2.1-rc.3 || ^0.2.1-rc.5 || ^0.2.2-rc.1 || ^0.2.2-rc.3 || ^0.2.2-rc.5",
|
|
95
95
|
"react": "^18.2.0",
|
|
96
96
|
"react-dom": "^18.2.0"
|
|
97
97
|
},
|
|
@@ -129,21 +129,22 @@
|
|
|
129
129
|
"@deepseek-ai/cordis-plugin-group": "^1.1.0",
|
|
130
130
|
"@deepseek-ai/cordis-plugin-include": "^1.1.0",
|
|
131
131
|
"@deepseek-ai/cordis-plugin-loader": "^1.1.0",
|
|
132
|
-
"@deepseek-ai/dsh-app-boot": "^0.2.2-rc.
|
|
133
|
-
"@deepseek-ai/dsh-brand": "^0.2.2-rc.
|
|
134
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.
|
|
135
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.
|
|
136
|
-
"@deepseek-ai/dsh-client-store": "^0.2.2-rc.
|
|
137
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.
|
|
138
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.
|
|
139
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.
|
|
140
|
-
"@deepseek-ai/dsh-config-editor": "^0.2.2-rc.
|
|
141
|
-
"@deepseek-ai/dsh-
|
|
142
|
-
"@deepseek-ai/dsh-
|
|
143
|
-
"@deepseek-ai/dsh-
|
|
144
|
-
"@deepseek-ai/dsh-
|
|
145
|
-
"@deepseek-ai/dsh-
|
|
146
|
-
"@deepseek-ai/dsh-
|
|
132
|
+
"@deepseek-ai/dsh-app-boot": "^0.2.2-rc.5",
|
|
133
|
+
"@deepseek-ai/dsh-brand": "^0.2.2-rc.5",
|
|
134
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.5",
|
|
135
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.5",
|
|
136
|
+
"@deepseek-ai/dsh-client-store": "^0.2.2-rc.5",
|
|
137
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.5",
|
|
138
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.5",
|
|
139
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.5",
|
|
140
|
+
"@deepseek-ai/dsh-config-editor": "^0.2.2-rc.5",
|
|
141
|
+
"@deepseek-ai/dsh-error": "^0.2.2-rc.5",
|
|
142
|
+
"@deepseek-ai/dsh-home-paths": "^0.2.2-rc.5",
|
|
143
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.5",
|
|
144
|
+
"@deepseek-ai/dsh-launch-environment": "^0.2.2-rc.5",
|
|
145
|
+
"@deepseek-ai/dsh-scope": "^0.2.2-rc.5",
|
|
146
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.5",
|
|
147
|
+
"@deepseek-ai/dsh-settings": "^0.2.2-rc.5",
|
|
147
148
|
"@deepseek-ai/schemastery": "^3.19.0",
|
|
148
149
|
"@types/node": "^22.20.0",
|
|
149
150
|
"@types/nodemailer": "^6.4.15",
|
package/src/api.ts
CHANGED
|
@@ -15,3 +15,8 @@ export const SESSION_END_API = {
|
|
|
15
15
|
export const AUTH_COOKIE_API = {
|
|
16
16
|
prune: '/api/dsh-mcviseron/auth-cookies/prune',
|
|
17
17
|
} as const
|
|
18
|
+
|
|
19
|
+
/** Optional third-party archive-plugin integration. */
|
|
20
|
+
export const ARCHIVE_API = {
|
|
21
|
+
status: '/api/dsh-mcviseron/archive-integration/status',
|
|
22
|
+
} as const
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
5
|
+
import { ARCHIVE_API } from '../api.ts'
|
|
6
|
+
import { isLoopbackRequest } from '../loopback.ts'
|
|
7
|
+
|
|
8
|
+
interface Ledger { version?: unknown; entries?: Record<string, { archivedAt?: unknown; source?: unknown }> }
|
|
9
|
+
interface ArchiveEntry { options?: { name?: unknown }; disabled?: boolean; fiber?: unknown }
|
|
10
|
+
|
|
11
|
+
function dshHome(): string {
|
|
12
|
+
const raw = process.env.DSH_HOME
|
|
13
|
+
if (raw !== undefined && raw.trim() !== '') return raw.trim().startsWith('~') ? join(homedir(), raw.trim().slice(1).replace(/^[\\/]/, '')) : raw.trim()
|
|
14
|
+
return join(homedir(), '.dsh')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function archiveAvailable(ctx: Context): boolean {
|
|
18
|
+
try {
|
|
19
|
+
const loader = (ctx as unknown as { loader?: { entries?: () => Iterable<ArchiveEntry> } }).loader
|
|
20
|
+
for (const entry of loader?.entries?.() ?? []) {
|
|
21
|
+
const name = String(entry.options?.name ?? '')
|
|
22
|
+
if (name.includes('session-archive') && entry.disabled !== true && entry.fiber !== undefined && entry.fiber !== null) return true
|
|
23
|
+
}
|
|
24
|
+
} catch { /* no loader */ }
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function archivedIds(ctx: Context): string[] {
|
|
29
|
+
try {
|
|
30
|
+
const registry = (ctx as unknown as { get?: (name: string) => unknown }).get?.('workspaceRegistry') as { archivedSessionIds?: unknown } | undefined
|
|
31
|
+
const value = registry?.archivedSessionIds
|
|
32
|
+
return Array.isArray(value) ? value.filter((id): id is string => typeof id === 'string' && id.length > 0) : []
|
|
33
|
+
} catch {
|
|
34
|
+
return []
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function makeArchiveStatus(ctx: Context): Record<string, unknown> {
|
|
39
|
+
const available = archiveAvailable(ctx)
|
|
40
|
+
const ledgerPath = join(dshHome(), 'dsh-session-archive', 'archive-ledger.json')
|
|
41
|
+
let ledger: Ledger | undefined
|
|
42
|
+
try { ledger = JSON.parse(readFileSync(ledgerPath, 'utf8')) as Ledger } catch { ledger = undefined }
|
|
43
|
+
const entries = ledger?.entries !== null && typeof ledger?.entries === 'object' ? ledger.entries : {}
|
|
44
|
+
const ids = archivedIds(ctx)
|
|
45
|
+
let observed = 0
|
|
46
|
+
let manual = 0
|
|
47
|
+
for (const entry of Object.values(entries)) {
|
|
48
|
+
if (entry.source === 'observed') observed++
|
|
49
|
+
else if (entry.source === 'manual') manual++
|
|
50
|
+
}
|
|
51
|
+
let unknown = 0
|
|
52
|
+
for (const id of ids) if (entries[id] === undefined) unknown++
|
|
53
|
+
return {
|
|
54
|
+
ok: true,
|
|
55
|
+
available,
|
|
56
|
+
ledgerPath,
|
|
57
|
+
ledgerExists: existsSync(ledgerPath),
|
|
58
|
+
entries: Object.keys(entries).length,
|
|
59
|
+
observed,
|
|
60
|
+
manual,
|
|
61
|
+
archivedCount: ids.length,
|
|
62
|
+
unknownCount: unknown,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const inject = ['webServer']
|
|
67
|
+
|
|
68
|
+
export function apply(ctx: Context): void {
|
|
69
|
+
ctx.effect(() => ctx.webServer.register({
|
|
70
|
+
kind: 'exact',
|
|
71
|
+
path: ARCHIVE_API.status,
|
|
72
|
+
handler: async (req, res): Promise<void> => {
|
|
73
|
+
const send = (status: number, value: unknown): void => {
|
|
74
|
+
res.statusCode = status
|
|
75
|
+
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
76
|
+
res.end(JSON.stringify(value))
|
|
77
|
+
}
|
|
78
|
+
if (req.method !== 'GET' && req.method !== 'POST') return send(405, { ok: false, error: 'method-not-allowed' })
|
|
79
|
+
if (!isLoopbackRequest(req)) return send(403, { ok: false, error: 'forbidden' })
|
|
80
|
+
try { send(200, makeArchiveStatus(ctx)) } catch (error) { send(500, { ok: false, error: error instanceof Error ? error.message : String(error) }) }
|
|
81
|
+
},
|
|
82
|
+
}), 'mcviseron: archive integration status')
|
|
83
|
+
}
|
|
@@ -16,8 +16,8 @@ export const DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
|
16
16
|
translateProvider: '',
|
|
17
17
|
translateModel: '',
|
|
18
18
|
reviewContextGuard: true,
|
|
19
|
-
reviewMaxHistoryChars:
|
|
20
|
-
reviewKeepRecentEntries:
|
|
19
|
+
reviewMaxHistoryChars: 200000,
|
|
20
|
+
reviewKeepRecentEntries: 32,
|
|
21
21
|
} as const
|
|
22
22
|
|
|
23
23
|
export const Config = z.object({
|
|
@@ -21,10 +21,11 @@ interface ScheduleRecord {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
interface ScheduleService {
|
|
24
|
-
list(filter
|
|
25
|
-
create(
|
|
26
|
-
update(
|
|
27
|
-
delete(
|
|
24
|
+
list(filter?: Record<string, unknown>): Promise<ScheduleRecord[] | { items: ScheduleRecord[] }>
|
|
25
|
+
create(...args: any[]): Promise<ScheduleRecord>
|
|
26
|
+
update?(...args: any[]): Promise<Record<string, unknown>>
|
|
27
|
+
delete?(...args: any[]): Promise<Record<string, unknown>>
|
|
28
|
+
edit?(...args: any[]): Promise<Record<string, unknown>>
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
interface ToolExecution {
|
|
@@ -61,6 +62,21 @@ function log(message: string): void {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
function isModernSchedule(schedule: ScheduleService): boolean {
|
|
66
|
+
return typeof schedule.edit === 'function'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function modernTiming(args: Record<string, unknown>): Record<string, unknown> | undefined {
|
|
70
|
+
if (args.after_seconds !== undefined) return { kind: 'after', after_seconds: args.after_seconds }
|
|
71
|
+
if (args.at !== undefined) return { kind: 'at', at: args.at }
|
|
72
|
+
if (args.every_seconds !== undefined) return { kind: 'every', every_seconds: args.every_seconds }
|
|
73
|
+
if (args.daily !== undefined) return { kind: 'daily', daily: args.daily }
|
|
74
|
+
if (args.weekly !== undefined) return { kind: 'weekly', weekly: args.weekly }
|
|
75
|
+
if (args.cron !== undefined) return { kind: 'cron', cron: args.cron }
|
|
76
|
+
if (args.rrule !== undefined) return { kind: 'rrule', rrule: args.rrule }
|
|
77
|
+
return undefined
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
function listRecords(result: ScheduleRecord[] | { items: ScheduleRecord[] }): ScheduleRecord[] {
|
|
65
81
|
return Array.isArray(result) ? result : result.items
|
|
66
82
|
}
|
|
@@ -193,7 +209,7 @@ export function makeAutomationTaskTools(schedule: ScheduleService): ToolDefiniti
|
|
|
193
209
|
const sessionId = sessionIdOf(exec)
|
|
194
210
|
if (sessionId === '') return { ok: false, code: 'no_session', error: 'no current session' }
|
|
195
211
|
try {
|
|
196
|
-
return { ok: true, tasks: listRecords(await schedule.list({ sessionId })) }
|
|
212
|
+
return { ok: true, tasks: listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })) }
|
|
197
213
|
} catch (error) {
|
|
198
214
|
return serviceFailure(error)
|
|
199
215
|
}
|
|
@@ -210,11 +226,23 @@ export function makeAutomationTaskTools(schedule: ScheduleService): ToolDefiniti
|
|
|
210
226
|
const invalidInput = validateCreate(args)
|
|
211
227
|
if (invalidInput !== undefined) return invalid(invalidInput)
|
|
212
228
|
try {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
229
|
+
let record: ScheduleRecord
|
|
230
|
+
if (isModernSchedule(schedule)) {
|
|
231
|
+
const timing = modernTiming(args)
|
|
232
|
+
if (timing === undefined) return invalid('timing is required')
|
|
233
|
+
record = await schedule.create({
|
|
234
|
+
title: String(args.title).trim(),
|
|
235
|
+
prompt: String(args.prompt).trim(),
|
|
236
|
+
timing,
|
|
237
|
+
target: { kind: 'session', sessionId },
|
|
238
|
+
}, sessionId, exec.signal)
|
|
239
|
+
} else {
|
|
240
|
+
record = await schedule.create(sessionId, {
|
|
241
|
+
...args,
|
|
242
|
+
title: String(args.title).trim(),
|
|
243
|
+
prompt: String(args.prompt).trim(),
|
|
244
|
+
}, exec.signal)
|
|
245
|
+
}
|
|
218
246
|
return { ok: true, task: record }
|
|
219
247
|
} catch (error) {
|
|
220
248
|
return serviceFailure(error)
|
|
@@ -233,10 +261,19 @@ export function makeAutomationTaskTools(schedule: ScheduleService): ToolDefiniti
|
|
|
233
261
|
if (invalidInput !== undefined) return invalid(invalidInput)
|
|
234
262
|
try {
|
|
235
263
|
const id = String(args.id)
|
|
236
|
-
const expected = listRecords(await schedule.list({ sessionId })).find(record => record.id === id)
|
|
237
|
-
if (expected === undefined) return { ok: false, code: 'schedule_not_found', error: 'automation task not found
|
|
264
|
+
const expected = listRecords(await schedule.list(isModernSchedule(schedule) ? {} : { sessionId })).find(record => record.id === id)
|
|
265
|
+
if (expected === undefined) return { ok: false, code: 'schedule_not_found', error: 'automation task not found: ' + id }
|
|
238
266
|
const change = timingChange(args)
|
|
239
|
-
|
|
267
|
+
if (isModernSchedule(schedule)) {
|
|
268
|
+
const patch: Record<string, unknown> = {}
|
|
269
|
+
if (args.title !== undefined) patch.title = String(args.title).trim()
|
|
270
|
+
if (args.prompt !== undefined) patch.prompt = String(args.prompt).trim()
|
|
271
|
+
const timing = modernTiming(args)
|
|
272
|
+
if (timing !== undefined) patch.timing = timing
|
|
273
|
+
const result = await schedule.edit!({ id, action: 'update', patch }, sessionId, exec.signal)
|
|
274
|
+
return { ok: true, task: result }
|
|
275
|
+
}
|
|
276
|
+
const result = await schedule.update!({
|
|
240
277
|
sessionId,
|
|
241
278
|
id,
|
|
242
279
|
expected,
|
|
@@ -263,7 +300,11 @@ export function makeAutomationTaskTools(schedule: ScheduleService): ToolDefiniti
|
|
|
263
300
|
return invalid('id must be a non-empty string without surrounding whitespace')
|
|
264
301
|
}
|
|
265
302
|
try {
|
|
266
|
-
|
|
303
|
+
if (isModernSchedule(schedule)) {
|
|
304
|
+
const result = await schedule.edit!({ id: String(args.id), action: 'delete' }, sessionId, exec.signal)
|
|
305
|
+
return { ok: true, ...result }
|
|
306
|
+
}
|
|
307
|
+
const result = await schedule.delete!({ sessionId, id: String(args.id) }, exec.signal)
|
|
267
308
|
return { ok: true, ...result }
|
|
268
309
|
} catch (error) {
|
|
269
310
|
return serviceFailure(error)
|
|
@@ -7,10 +7,11 @@ const EXECUTE = '/api/dsh-mcviseron/restart/execute'
|
|
|
7
7
|
|
|
8
8
|
type RestartState =
|
|
9
9
|
| { kind: 'loading' }
|
|
10
|
-
| { kind: 'ready'; appPath: string }
|
|
10
|
+
| { kind: 'ready'; appPath: string; mode: string }
|
|
11
11
|
| { kind: 'unavailable' }
|
|
12
12
|
| { kind: 'route-missing' }
|
|
13
13
|
| { kind: 'restarting' }
|
|
14
|
+
| { kind: 'closing' }
|
|
14
15
|
| { kind: 'failed'; message: string }
|
|
15
16
|
|
|
16
17
|
async function readError(response: Response): Promise<string> {
|
|
@@ -38,10 +39,10 @@ export function RestartCard({ t }: { t: (key: McviseronKey) => string }) {
|
|
|
38
39
|
return
|
|
39
40
|
}
|
|
40
41
|
if (!response.ok) throw new Error(await readError(response))
|
|
41
|
-
const body = await response.json() as { ok?: unknown; available?: unknown; appPath?: unknown }
|
|
42
|
+
const body = await response.json() as { ok?: unknown; available?: unknown; appPath?: unknown; mode?: unknown }
|
|
42
43
|
if (body.ok !== true) throw new Error('restart-status-rejected')
|
|
43
44
|
if (body.available === true) {
|
|
44
|
-
setState({ kind: 'ready', appPath: typeof body.appPath === 'string' ? body.appPath : '' })
|
|
45
|
+
setState({ kind: 'ready', appPath: typeof body.appPath === 'string' ? body.appPath : '', mode: typeof body.mode === 'string' ? body.mode : 'desktop' })
|
|
45
46
|
} else {
|
|
46
47
|
setState({ kind: 'unavailable' })
|
|
47
48
|
}
|
|
@@ -71,9 +72,32 @@ export function RestartCard({ t }: { t: (key: McviseronKey) => string }) {
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
const startClose = async (): Promise<void> => {
|
|
76
|
+
if (!window.confirm(t('page.restart.closeConfirm'))) return
|
|
77
|
+
setState({ kind: 'closing' })
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(EXECUTE, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'content-type': 'application/json' },
|
|
82
|
+
body: JSON.stringify({ confirm: true, action: 'close' }),
|
|
83
|
+
})
|
|
84
|
+
if (!response.ok) throw new Error(await readError(response))
|
|
85
|
+
const body = await response.json() as { ok?: unknown }
|
|
86
|
+
if (body.ok !== true) throw new Error('close-rejected')
|
|
87
|
+
} catch (error) {
|
|
88
|
+
setState({ kind: 'failed', message: error instanceof Error ? error.message : String(error) })
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
74
92
|
const status = state.kind === 'ready'
|
|
75
|
-
?
|
|
76
|
-
|
|
93
|
+
? state.mode === 'reexec'
|
|
94
|
+
? t('page.restart.modeProcess')
|
|
95
|
+
: state.mode === 'supervisor-exit'
|
|
96
|
+
? t('page.restart.modeSupervisor')
|
|
97
|
+
: t('page.restart.ready')
|
|
98
|
+
: state.kind === 'closing'
|
|
99
|
+
? t('page.restart.closing')
|
|
100
|
+
: state.kind === 'route-missing'
|
|
77
101
|
? t('page.restart.routeMissing')
|
|
78
102
|
: state.kind === 'restarting'
|
|
79
103
|
? t('page.restart.restarting')
|
|
@@ -84,6 +108,7 @@ export function RestartCard({ t }: { t: (key: McviseronKey) => string }) {
|
|
|
84
108
|
: t('page.restart.unavailable')
|
|
85
109
|
|
|
86
110
|
const canRestart = state.kind === 'ready' || state.kind === 'failed'
|
|
111
|
+
const canClose = state.kind === 'ready'
|
|
87
112
|
|
|
88
113
|
return (
|
|
89
114
|
<div style={pageStyles.card}>
|
|
@@ -102,6 +127,14 @@ export function RestartCard({ t }: { t: (key: McviseronKey) => string }) {
|
|
|
102
127
|
>
|
|
103
128
|
{state.kind === 'restarting' ? t('page.restart.restarting') : t('page.restart.button')}
|
|
104
129
|
</button>
|
|
130
|
+
<button
|
|
131
|
+
type="button"
|
|
132
|
+
disabled={!canClose}
|
|
133
|
+
onClick={() => { void startClose() }}
|
|
134
|
+
style={canClose ? styles.button : styles.buttonDisabled}
|
|
135
|
+
>
|
|
136
|
+
{state.kind === 'closing' ? t('page.restart.closing') : t('page.restart.close')}
|
|
137
|
+
</button>
|
|
105
138
|
</div>
|
|
106
139
|
</div>
|
|
107
140
|
)
|