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/auto-review-fix.js
CHANGED
|
@@ -7,6 +7,224 @@ import z from "@deepseek-ai/schemastery";
|
|
|
7
7
|
// src/components/auto-review-fix/index.ts
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
9
|
|
|
10
|
+
// src/components/auto-review-fix/review-context.ts
|
|
11
|
+
import { appendFileSync } from "node:fs";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
var REVIEW_MARKER = "REVIEW_POLICY";
|
|
15
|
+
var REVIEW_MARKER_2 = "final authorization reviewer";
|
|
16
|
+
var HISTORY_HEADER = "FILTERED_HISTORY\n\n";
|
|
17
|
+
var PROJECT_HEADER = "PROJECT_INSTRUCTIONS\n\n";
|
|
18
|
+
var ACTION_HEADER = "\n\nPENDING_ACTION\n\n";
|
|
19
|
+
var USER_TEXT_CHARS = 4e3;
|
|
20
|
+
var TOOL_ARGUMENT_CHARS = 2e3;
|
|
21
|
+
var PROJECT_MAX_CHARS = 4e4;
|
|
22
|
+
function record(value) {
|
|
23
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function textOf(message) {
|
|
26
|
+
if (!record(message) || !Array.isArray(message.content)) return void 0;
|
|
27
|
+
const texts = [];
|
|
28
|
+
for (const block of message.content) {
|
|
29
|
+
if (!record(block) || block.type !== "text" || typeof block.text !== "string") return void 0;
|
|
30
|
+
texts.push(block.text);
|
|
31
|
+
}
|
|
32
|
+
return texts.join("");
|
|
33
|
+
}
|
|
34
|
+
function isAutoReviewRequest(options) {
|
|
35
|
+
if (!record(options)) return false;
|
|
36
|
+
const system = options.system;
|
|
37
|
+
if (typeof system !== "string" || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false;
|
|
38
|
+
if (!Array.isArray(options.messages) || options.messages.length === 0) return false;
|
|
39
|
+
const text = textOf(options.messages[0]);
|
|
40
|
+
return text !== void 0 && text.includes(HISTORY_HEADER) && text.includes(ACTION_HEADER);
|
|
41
|
+
}
|
|
42
|
+
function truncateText(text, limit) {
|
|
43
|
+
if (text.length <= limit) return text;
|
|
44
|
+
return text.slice(0, limit) + "\n\u2026[" + String(text.length - limit) + " characters omitted]";
|
|
45
|
+
}
|
|
46
|
+
function compactBlock(block) {
|
|
47
|
+
if (!record(block)) return { type: "text", text: "[non-text history block omitted from reviewer context]" };
|
|
48
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
49
|
+
return { ...block, text: truncateText(block.text, USER_TEXT_CHARS) };
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: "text",
|
|
53
|
+
text: "[" + String(block.type ?? "attachment") + " omitted from reviewer context]"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function compactEntry(entry) {
|
|
57
|
+
if (!record(entry)) return { kind: "summary", role: "fact", content: [{ type: "text", text: "[invalid history entry omitted]" }] };
|
|
58
|
+
if (entry.kind === "user-message" && Array.isArray(entry.content)) {
|
|
59
|
+
return { ...entry, content: entry.content.map(compactBlock) };
|
|
60
|
+
}
|
|
61
|
+
if (entry.kind === "tool-call") {
|
|
62
|
+
const value = entry.arguments;
|
|
63
|
+
if (typeof value === "string") {
|
|
64
|
+
return { ...entry, arguments: truncateText(value, TOOL_ARGUMENT_CHARS) };
|
|
65
|
+
}
|
|
66
|
+
if (value !== void 0) {
|
|
67
|
+
let rendered;
|
|
68
|
+
try {
|
|
69
|
+
rendered = JSON.stringify(value) ?? "";
|
|
70
|
+
} catch {
|
|
71
|
+
rendered = "";
|
|
72
|
+
}
|
|
73
|
+
return { ...entry, arguments: truncateText(rendered, TOOL_ARGUMENT_CHARS) };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return entry;
|
|
77
|
+
}
|
|
78
|
+
function protectedEntry(entry) {
|
|
79
|
+
if (!record(entry)) return false;
|
|
80
|
+
return entry.role === "human-instruction" || entry.role === "direct-parent-instruction";
|
|
81
|
+
}
|
|
82
|
+
function summaryEntry(omitted, originalChars) {
|
|
83
|
+
return {
|
|
84
|
+
kind: "summary",
|
|
85
|
+
role: "fact",
|
|
86
|
+
content: [{
|
|
87
|
+
type: "text",
|
|
88
|
+
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."
|
|
89
|
+
}]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function jsonLength(value) {
|
|
93
|
+
try {
|
|
94
|
+
return JSON.stringify(value)?.length ?? 0;
|
|
95
|
+
} catch {
|
|
96
|
+
return Number.MAX_SAFE_INTEGER;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function boundEntries(entries, maxChars, keepRecent) {
|
|
100
|
+
const normalized = entries.map(compactEntry);
|
|
101
|
+
const originalChars = jsonLength(normalized);
|
|
102
|
+
const recentStart = Math.max(0, normalized.length - Math.max(1, keepRecent));
|
|
103
|
+
const selected = normalized.filter((entry, index) => protectedEntry(entry) || index >= recentStart);
|
|
104
|
+
let omitted = normalized.length - selected.length;
|
|
105
|
+
while (selected.length > 1 && jsonLength(selected) > maxChars) {
|
|
106
|
+
const at = selected.findIndex((entry) => !protectedEntry(entry));
|
|
107
|
+
if (at < 0) selected.shift();
|
|
108
|
+
else selected.splice(at, 1);
|
|
109
|
+
omitted += 1;
|
|
110
|
+
}
|
|
111
|
+
if (omitted > 0) selected.unshift(summaryEntry(omitted, originalChars));
|
|
112
|
+
return selected;
|
|
113
|
+
}
|
|
114
|
+
function parseArray(text) {
|
|
115
|
+
try {
|
|
116
|
+
const value = JSON.parse(text);
|
|
117
|
+
return Array.isArray(value) ? value : void 0;
|
|
118
|
+
} catch {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function logTrim(originalChars, nextChars, originalEntries, nextEntries) {
|
|
123
|
+
try {
|
|
124
|
+
appendFileSync(
|
|
125
|
+
join(tmpdir(), "dsh-mcviseron-auto-review.log"),
|
|
126
|
+
(/* @__PURE__ */ new Date()).toISOString() + " review context trimmed: " + String(originalChars) + " -> " + String(nextChars) + " chars, history " + String(originalEntries) + " -> " + String(nextEntries) + "\n",
|
|
127
|
+
"utf8"
|
|
128
|
+
);
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function trimReviewRequest(options, settings) {
|
|
133
|
+
if (!settings.enabled || !isAutoReviewRequest(options)) return options;
|
|
134
|
+
const messages = options.messages;
|
|
135
|
+
const message = messages[0];
|
|
136
|
+
const text = textOf(message);
|
|
137
|
+
if (text === void 0) return options;
|
|
138
|
+
const projectAt = text.indexOf(PROJECT_HEADER);
|
|
139
|
+
const historyAt = text.indexOf(HISTORY_HEADER, projectAt + 1);
|
|
140
|
+
const actionAt = text.indexOf(ACTION_HEADER, historyAt + 1);
|
|
141
|
+
if (projectAt < 0 || historyAt < 0 || actionAt < 0) return options;
|
|
142
|
+
const projectJson = text.slice(projectAt + PROJECT_HEADER.length, historyAt - 2);
|
|
143
|
+
const historyJson = text.slice(historyAt + HISTORY_HEADER.length, actionAt);
|
|
144
|
+
const project = parseArray(projectJson);
|
|
145
|
+
const history = parseArray(historyJson);
|
|
146
|
+
if (project === void 0 || history === void 0) return options;
|
|
147
|
+
const nextProject = boundEntries(project, PROJECT_MAX_CHARS, 4);
|
|
148
|
+
const nextHistory = boundEntries(history, settings.maxHistoryChars, settings.keepRecentEntries);
|
|
149
|
+
const nextText = text.slice(0, projectAt) + PROJECT_HEADER + JSON.stringify(nextProject) + HISTORY_HEADER + JSON.stringify(nextHistory) + text.slice(actionAt);
|
|
150
|
+
if (nextText === text) return options;
|
|
151
|
+
logTrim(text.length, nextText.length, history.length, nextHistory.length);
|
|
152
|
+
const content = [{ type: "text", text: nextText }];
|
|
153
|
+
return {
|
|
154
|
+
...options,
|
|
155
|
+
messages: [
|
|
156
|
+
{ ...message, content },
|
|
157
|
+
...messages.slice(1)
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
var guardedLlms = /* @__PURE__ */ new WeakMap();
|
|
162
|
+
function whenService(ctx, name, run) {
|
|
163
|
+
try {
|
|
164
|
+
const inject = ctx.inject;
|
|
165
|
+
if (typeof inject === "function") {
|
|
166
|
+
inject.call(ctx, [name], run);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const get = ctx.get;
|
|
170
|
+
if (typeof get === "function" && get.call(ctx, name) !== void 0) run(ctx);
|
|
171
|
+
} catch {
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function serviceOf(scope, name) {
|
|
175
|
+
try {
|
|
176
|
+
const direct = scope[name];
|
|
177
|
+
if (direct !== void 0) return direct;
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const get = scope.get;
|
|
182
|
+
return typeof get === "function" ? get.call(scope, name) : void 0;
|
|
183
|
+
} catch {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function effectOf(scope, setup, label) {
|
|
188
|
+
try {
|
|
189
|
+
const effect = scope.effect;
|
|
190
|
+
if (typeof effect === "function") effect.call(scope, setup, label);
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function installReviewContextGuard(ctx, settings) {
|
|
195
|
+
if (!settings.enabled) return;
|
|
196
|
+
whenService(ctx, "llm", (scope) => {
|
|
197
|
+
const llm = serviceOf(scope, "llm");
|
|
198
|
+
if (llm === null || typeof llm !== "object" || typeof llm.stream !== "function") return;
|
|
199
|
+
const existing = guardedLlms.get(llm);
|
|
200
|
+
if (existing !== void 0) {
|
|
201
|
+
existing.settings = settings;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const original = llm.stream;
|
|
205
|
+
const state = { settings };
|
|
206
|
+
const wrapper = function(options) {
|
|
207
|
+
let next = options;
|
|
208
|
+
try {
|
|
209
|
+
next = trimReviewRequest(options, state.settings);
|
|
210
|
+
} catch {
|
|
211
|
+
next = options;
|
|
212
|
+
}
|
|
213
|
+
return original.call(this, next);
|
|
214
|
+
};
|
|
215
|
+
try {
|
|
216
|
+
llm.stream = wrapper;
|
|
217
|
+
guardedLlms.set(llm, state);
|
|
218
|
+
} catch {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
effectOf(scope, () => () => {
|
|
222
|
+
if (llm.stream === wrapper) llm.stream = original;
|
|
223
|
+
guardedLlms.delete(llm);
|
|
224
|
+
}, "mcviseron: restore llm.stream");
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
10
228
|
// src/components/auto-review-fix/translate.ts
|
|
11
229
|
var TRANSLATION_LABEL = "\u3010\u5BA1\u67E5\u7406\u7531 \xB7 \u4E2D\u6587\u7FFB\u8BD1\u3011";
|
|
12
230
|
var SYSTEM_PROMPT = [
|
|
@@ -173,10 +391,15 @@ function normalizeConfig(config) {
|
|
|
173
391
|
timeoutMs: numberSetting(source, "translateTimeoutMs", 6e3, 500, 6e4),
|
|
174
392
|
maxChars: numberSetting(source, "translateMaxChars", 4e3, 100, 2e4),
|
|
175
393
|
provider: stringSetting(source, "translateProvider", ""),
|
|
176
|
-
model: stringSetting(source, "translateModel", "")
|
|
394
|
+
model: stringSetting(source, "translateModel", ""),
|
|
395
|
+
reviewContext: {
|
|
396
|
+
enabled: boolSetting(source, "reviewContextGuard", true),
|
|
397
|
+
maxHistoryChars: numberSetting(source, "reviewMaxHistoryChars", 12e4, 2e4, 6e5),
|
|
398
|
+
keepRecentEntries: numberSetting(source, "reviewKeepRecentEntries", 16, 4, 64)
|
|
399
|
+
}
|
|
177
400
|
};
|
|
178
401
|
}
|
|
179
|
-
function
|
|
402
|
+
function whenService2(ctx, name, run) {
|
|
180
403
|
try {
|
|
181
404
|
const inject = ctx.inject;
|
|
182
405
|
if (typeof inject === "function") {
|
|
@@ -189,7 +412,7 @@ function whenService(ctx, name, run) {
|
|
|
189
412
|
} catch {
|
|
190
413
|
}
|
|
191
414
|
}
|
|
192
|
-
function
|
|
415
|
+
function serviceOf2(scope, name) {
|
|
193
416
|
try {
|
|
194
417
|
const direct = scope[name];
|
|
195
418
|
if (direct !== void 0) return direct;
|
|
@@ -202,7 +425,7 @@ function serviceOf(scope, name) {
|
|
|
202
425
|
return void 0;
|
|
203
426
|
}
|
|
204
427
|
}
|
|
205
|
-
function
|
|
428
|
+
function effectOf2(scope, setup, label) {
|
|
206
429
|
try {
|
|
207
430
|
const effect = scope.effect;
|
|
208
431
|
if (typeof effect === "function") effect.call(scope, setup, label);
|
|
@@ -220,8 +443,8 @@ function rootIsActive(root) {
|
|
|
220
443
|
}
|
|
221
444
|
}
|
|
222
445
|
function installPresetGuard(ctx) {
|
|
223
|
-
|
|
224
|
-
const presets =
|
|
446
|
+
whenService2(ctx, "permissionPresets", (scope) => {
|
|
447
|
+
const presets = serviceOf2(scope, "permissionPresets");
|
|
225
448
|
if (presets === null || typeof presets !== "object") return;
|
|
226
449
|
if (typeof presets.set !== "function") return;
|
|
227
450
|
if (guardedPresets.has(presets)) return;
|
|
@@ -242,18 +465,18 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
242
465
|
if (!settings.enabled || request === null || typeof request !== "object") return request;
|
|
243
466
|
const display = request.displayReason;
|
|
244
467
|
if (display === null || typeof display !== "object" || Array.isArray(display)) return request;
|
|
245
|
-
const
|
|
246
|
-
const key = chineseKey(
|
|
468
|
+
const record2 = display;
|
|
469
|
+
const key = chineseKey(record2);
|
|
247
470
|
if (key === void 0) return request;
|
|
248
|
-
const english = englishText(
|
|
471
|
+
const english = englishText(record2);
|
|
249
472
|
if (english === void 0 || !isAutoReviewText(english)) return request;
|
|
250
|
-
const localized =
|
|
473
|
+
const localized = record2[key];
|
|
251
474
|
if (typeof localized !== "string" || hasTranslation(localized)) return request;
|
|
252
475
|
const excerpt = reviewerExcerpt(english);
|
|
253
476
|
if (excerpt.length === 0 || excerpt.length > settings.maxChars) return request;
|
|
254
477
|
if (isPredominantlyChinese(excerpt)) return request;
|
|
255
478
|
if (translationRoute(settings, request) === void 0) return request;
|
|
256
|
-
const llm =
|
|
479
|
+
const llm = serviceOf2(scope, "llm");
|
|
257
480
|
const translated = await translate(llm, settings, request, excerpt);
|
|
258
481
|
if (translated === void 0) return request;
|
|
259
482
|
const cleaned = cleanTranslation(translated);
|
|
@@ -264,7 +487,7 @@ async function decorateApprovalRequest(scope, settings, request, translate = tra
|
|
|
264
487
|
return {
|
|
265
488
|
...request,
|
|
266
489
|
...reasonWithTranslation !== originalReason ? { reason: reasonWithTranslation } : {},
|
|
267
|
-
displayReason: { ...
|
|
490
|
+
displayReason: { ...record2, [key]: withTranslation(localized, cleaned) }
|
|
268
491
|
};
|
|
269
492
|
}
|
|
270
493
|
function sessionIdOf(agent) {
|
|
@@ -281,8 +504,8 @@ function rejectionKey(agent, callId) {
|
|
|
281
504
|
return sessionId === "" ? "" : sessionId + ":" + callId;
|
|
282
505
|
}
|
|
283
506
|
function approvalReasonText(request) {
|
|
284
|
-
const
|
|
285
|
-
const display =
|
|
507
|
+
const record2 = request;
|
|
508
|
+
const display = record2.displayReason;
|
|
286
509
|
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
287
510
|
const key = chineseKey(display);
|
|
288
511
|
if (key !== void 0) {
|
|
@@ -292,12 +515,12 @@ function approvalReasonText(request) {
|
|
|
292
515
|
const english = englishText(display);
|
|
293
516
|
if (english !== void 0 && english !== "") return english;
|
|
294
517
|
}
|
|
295
|
-
return typeof
|
|
518
|
+
return typeof record2.reason === "string" ? record2.reason : "";
|
|
296
519
|
}
|
|
297
520
|
function isAutoReviewApproval(request) {
|
|
298
|
-
const
|
|
299
|
-
if (typeof
|
|
300
|
-
const display =
|
|
521
|
+
const record2 = request;
|
|
522
|
+
if (typeof record2.reason === "string" && isAutoReviewText(record2.reason)) return true;
|
|
523
|
+
const display = record2.displayReason;
|
|
301
524
|
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
302
525
|
const english = englishText(display);
|
|
303
526
|
if (english !== void 0 && isAutoReviewText(english)) return true;
|
|
@@ -368,8 +591,8 @@ function installRejectionRelay(ctx, relay) {
|
|
|
368
591
|
});
|
|
369
592
|
}
|
|
370
593
|
function installApprovalTranslation(ctx, settings, relay) {
|
|
371
|
-
|
|
372
|
-
const approval =
|
|
594
|
+
whenService2(ctx, "approval", (scope) => {
|
|
595
|
+
const approval = serviceOf2(scope, "approval");
|
|
373
596
|
if (approval === null || typeof approval !== "object") return;
|
|
374
597
|
const original = approval.request;
|
|
375
598
|
if (typeof original !== "function") return;
|
|
@@ -397,7 +620,7 @@ function installApprovalTranslation(ctx, settings, relay) {
|
|
|
397
620
|
} catch {
|
|
398
621
|
return;
|
|
399
622
|
}
|
|
400
|
-
|
|
623
|
+
effectOf2(scope, () => () => {
|
|
401
624
|
if (approval.request === wrapper) approval.request = call;
|
|
402
625
|
}, "mcviseron: restore approval.request");
|
|
403
626
|
});
|
|
@@ -405,6 +628,7 @@ function installApprovalTranslation(ctx, settings, relay) {
|
|
|
405
628
|
function installAutoReview(ctx, config) {
|
|
406
629
|
const settings = normalizeConfig(config);
|
|
407
630
|
if (settings.keepPresetGuard) installPresetGuard(ctx);
|
|
631
|
+
if (settings.reviewContext.enabled) installReviewContextGuard(ctx, settings.reviewContext);
|
|
408
632
|
if (settings.enabled) {
|
|
409
633
|
const relay = createRejectionRelay();
|
|
410
634
|
installRejectionRelay(ctx, relay);
|
|
@@ -436,7 +660,10 @@ var DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
|
436
660
|
translateTimeoutMs: 6e3,
|
|
437
661
|
translateMaxChars: 4e3,
|
|
438
662
|
translateProvider: "",
|
|
439
|
-
translateModel: ""
|
|
663
|
+
translateModel: "",
|
|
664
|
+
reviewContextGuard: true,
|
|
665
|
+
reviewMaxHistoryChars: 12e4,
|
|
666
|
+
reviewKeepRecentEntries: 16
|
|
440
667
|
};
|
|
441
668
|
var Config = z.object({
|
|
442
669
|
keepPresetGuard: z.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.keepPresetGuard).volatile(),
|
|
@@ -444,7 +671,10 @@ var Config = z.object({
|
|
|
444
671
|
translateTimeoutMs: z.number().min(500).max(6e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateTimeoutMs).volatile(),
|
|
445
672
|
translateMaxChars: z.number().min(100).max(2e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateMaxChars).volatile(),
|
|
446
673
|
translateProvider: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateProvider).volatile(),
|
|
447
|
-
translateModel: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile()
|
|
674
|
+
translateModel: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile(),
|
|
675
|
+
reviewContextGuard: z.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.reviewContextGuard).volatile(),
|
|
676
|
+
reviewMaxHistoryChars: z.number().min(2e4).max(6e5).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewMaxHistoryChars).volatile(),
|
|
677
|
+
reviewKeepRecentEntries: z.number().min(4).max(64).default(DEFAULT_AUTO_REVIEW_CONFIG.reviewKeepRecentEntries).volatile()
|
|
448
678
|
}).default(DEFAULT_AUTO_REVIEW_CONFIG);
|
|
449
679
|
function apply(ctx, config) {
|
|
450
680
|
installAutoReview(ctx, toPlain(config));
|
package/lib/client.js
CHANGED
|
@@ -32,6 +32,20 @@ __export(index_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(index_exports);
|
|
34
34
|
|
|
35
|
+
// src/api.ts
|
|
36
|
+
var MCVISERON_API = {
|
|
37
|
+
describe: "/api/dsh-mcviseron/settings/describe",
|
|
38
|
+
mutate: "/api/dsh-mcviseron/settings/mutate"
|
|
39
|
+
};
|
|
40
|
+
var SESSION_END_API = {
|
|
41
|
+
state: "/api/dsh-mcviseron/session-end/state",
|
|
42
|
+
set: "/api/dsh-mcviseron/session-end/set",
|
|
43
|
+
global: "/api/dsh-mcviseron/session-end/global"
|
|
44
|
+
};
|
|
45
|
+
var AUTH_COOKIE_API = {
|
|
46
|
+
prune: "/api/dsh-mcviseron/auth-cookies/prune"
|
|
47
|
+
};
|
|
48
|
+
|
|
35
49
|
// src/client/AppearanceScheduleRow.tsx
|
|
36
50
|
var import_react = require("react");
|
|
37
51
|
|
|
@@ -458,15 +472,156 @@ function FallbackRestartRow({ t }) {
|
|
|
458
472
|
var import_react4 = require("react");
|
|
459
473
|
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
460
474
|
|
|
461
|
-
// src/
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
475
|
+
// src/client/SessionEndGlobalNotice.ts
|
|
476
|
+
var HOST_ID = "mcviseron-session-end-global";
|
|
477
|
+
var FALLBACK_TOP = 56;
|
|
478
|
+
var MIN_TOP = 120;
|
|
479
|
+
function globalNoticeText(action) {
|
|
480
|
+
const name = action.label.trim() !== "" ? action.label : "\u4F1A\u8BDD \u2026" + action.sessionId.slice(-6);
|
|
481
|
+
const mode = action.mode === "restart" ? "\u81EA\u52A8\u91CD\u542F" : action.mode === "close" ? "\u81EA\u52A8\u5173\u95ED DSH" : "\u5173\u95ED\u7535\u8111";
|
|
482
|
+
return "\u300C" + name + "\u300D\u5DF2\u542F\u7528 AI \u4F1A\u8BDD" + mode;
|
|
483
|
+
}
|
|
484
|
+
function globalNoticeKey(action) {
|
|
485
|
+
return action.sessionId + ":" + action.mode + ":" + String(action.armedAt);
|
|
486
|
+
}
|
|
487
|
+
function navigationBottom() {
|
|
488
|
+
for (const selector of ["header", '[role="banner"]']) {
|
|
489
|
+
const element = document.querySelector(selector);
|
|
490
|
+
if (element === null) continue;
|
|
491
|
+
const rect = element.getBoundingClientRect();
|
|
492
|
+
if (rect.height > 0 && rect.top <= 8) return Math.round(rect.bottom);
|
|
493
|
+
}
|
|
494
|
+
return FALLBACK_TOP;
|
|
495
|
+
}
|
|
496
|
+
function placeBelowNavigation(host) {
|
|
497
|
+
const measured = navigationBottom();
|
|
498
|
+
const nav = measured > 0 && measured < 240 ? measured : 56;
|
|
499
|
+
host.style.top = String(Math.max(nav + 48, MIN_TOP)) + "px";
|
|
500
|
+
}
|
|
501
|
+
function ensureHost() {
|
|
502
|
+
if (typeof document === "undefined") return void 0;
|
|
503
|
+
const existing = document.getElementById(HOST_ID);
|
|
504
|
+
if (existing !== null) return existing;
|
|
505
|
+
const host = document.createElement("div");
|
|
506
|
+
host.id = HOST_ID;
|
|
507
|
+
host.setAttribute("role", "status");
|
|
508
|
+
host.setAttribute("aria-live", "polite");
|
|
509
|
+
host.style.cssText = [
|
|
510
|
+
"position:fixed",
|
|
511
|
+
"top:56px",
|
|
512
|
+
"right:12px",
|
|
513
|
+
"z-index:10000",
|
|
514
|
+
"display:flex",
|
|
515
|
+
"flex-direction:column",
|
|
516
|
+
"gap:8px",
|
|
517
|
+
"max-width:min(380px,calc(100vw - 24px))",
|
|
518
|
+
"pointer-events:none"
|
|
519
|
+
].join(";");
|
|
520
|
+
placeBelowNavigation(host);
|
|
521
|
+
document.body.appendChild(host);
|
|
522
|
+
return host;
|
|
523
|
+
}
|
|
524
|
+
function card(action, dismiss) {
|
|
525
|
+
const element = document.createElement("div");
|
|
526
|
+
element.style.cssText = [
|
|
527
|
+
"pointer-events:auto",
|
|
528
|
+
"display:flex",
|
|
529
|
+
"align-items:flex-start",
|
|
530
|
+
"gap:9px",
|
|
531
|
+
"padding:10px 11px",
|
|
532
|
+
"border-radius:12px",
|
|
533
|
+
"border:1px solid var(--dsw-alias-state-warn-primary, rgba(227,179,65,.65))",
|
|
534
|
+
"background:var(--dsw-alias-bg-layer-2, #1f2023)",
|
|
535
|
+
"color:var(--dsw-alias-label-primary, #f2f3f5)",
|
|
536
|
+
"box-shadow:var(--dsw-elevation-prominent, 0 8px 28px rgba(0,0,0,.35))",
|
|
537
|
+
"font-size:12px",
|
|
538
|
+
"line-height:1.45"
|
|
539
|
+
].join(";");
|
|
540
|
+
const dot = document.createElement("span");
|
|
541
|
+
dot.setAttribute("aria-hidden", "true");
|
|
542
|
+
dot.style.cssText = "flex:none;width:8px;height:8px;margin-top:4px;border-radius:50%;background:var(--dsw-alias-state-warn-primary,#e3b341)";
|
|
543
|
+
const body = document.createElement("div");
|
|
544
|
+
body.style.cssText = "flex:1;min-width:0";
|
|
545
|
+
const title = document.createElement("div");
|
|
546
|
+
title.textContent = globalNoticeText(action);
|
|
547
|
+
title.style.cssText = "font-weight:600";
|
|
548
|
+
const hint = document.createElement("div");
|
|
549
|
+
hint.textContent = action.waiting ? "\u6B63\u5728\u7B49\u5F85\u4EFB\u52A1\u7ED3\u675F" + (action.runningAgents + action.runningJobs > 0 ? " \xB7 " + String(action.runningAgents) + " \u4E2A\u4F1A\u8BDD / " + String(action.runningJobs) + " \u4E2A\u4EFB\u52A1" : "") : "\u672C\u8F6E\u6700\u7EC8\u56DE\u590D\u540E\u6267\u884C";
|
|
550
|
+
hint.style.cssText = "margin-top:2px;color:var(--dsw-alias-label-secondary,#a8adb7);font-size:11px";
|
|
551
|
+
body.append(title, hint);
|
|
552
|
+
const close = document.createElement("button");
|
|
553
|
+
close.type = "button";
|
|
554
|
+
close.setAttribute("aria-label", "\u5173\u95ED\u63D0\u793A");
|
|
555
|
+
close.textContent = "\xD7";
|
|
556
|
+
close.style.cssText = [
|
|
557
|
+
"flex:none",
|
|
558
|
+
"border:0",
|
|
559
|
+
"background:transparent",
|
|
560
|
+
"color:var(--dsw-alias-label-tertiary,#8b919c)",
|
|
561
|
+
"cursor:pointer",
|
|
562
|
+
"font-size:16px",
|
|
563
|
+
"line-height:1",
|
|
564
|
+
"padding:0 2px"
|
|
565
|
+
].join(";");
|
|
566
|
+
close.addEventListener("click", dismiss);
|
|
567
|
+
element.append(dot, body, close);
|
|
568
|
+
return element;
|
|
569
|
+
}
|
|
570
|
+
function startSessionEndGlobalNotice() {
|
|
571
|
+
if (typeof document === "undefined" || typeof fetch !== "function") return () => {
|
|
572
|
+
};
|
|
573
|
+
let stopped = false;
|
|
574
|
+
let timer;
|
|
575
|
+
const dismissed = /* @__PURE__ */ new Set();
|
|
576
|
+
const clear = () => {
|
|
577
|
+
document.getElementById(HOST_ID)?.remove();
|
|
578
|
+
};
|
|
579
|
+
const render = (actions) => {
|
|
580
|
+
const active = new Set(actions.map(globalNoticeKey));
|
|
581
|
+
for (const key of dismissed) if (!active.has(key)) dismissed.delete(key);
|
|
582
|
+
const visible = actions.filter((action) => !dismissed.has(globalNoticeKey(action)));
|
|
583
|
+
if (visible.length === 0) {
|
|
584
|
+
clear();
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const host = ensureHost();
|
|
588
|
+
if (host === void 0) return;
|
|
589
|
+
placeBelowNavigation(host);
|
|
590
|
+
host.replaceChildren(...visible.map((action) => card(action, () => {
|
|
591
|
+
dismissed.add(globalNoticeKey(action));
|
|
592
|
+
render(actions);
|
|
593
|
+
})));
|
|
594
|
+
};
|
|
595
|
+
const poll = async () => {
|
|
596
|
+
try {
|
|
597
|
+
const response = await fetch(SESSION_END_API.global, {
|
|
598
|
+
method: "POST",
|
|
599
|
+
credentials: "same-origin",
|
|
600
|
+
cache: "no-store"
|
|
601
|
+
});
|
|
602
|
+
if (stopped) return;
|
|
603
|
+
const body = await response.json();
|
|
604
|
+
if (stopped || body.ok !== true || !Array.isArray(body.actions)) return;
|
|
605
|
+
render(body.actions.filter((action) => action.requestedBy === "ai"));
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
const onResize = () => {
|
|
610
|
+
const host = document.getElementById(HOST_ID);
|
|
611
|
+
if (host !== null) placeBelowNavigation(host);
|
|
612
|
+
};
|
|
613
|
+
window.addEventListener("resize", onResize);
|
|
614
|
+
void poll();
|
|
615
|
+
timer = setInterval(() => {
|
|
616
|
+
void poll();
|
|
617
|
+
}, 2e3);
|
|
618
|
+
return () => {
|
|
619
|
+
stopped = true;
|
|
620
|
+
if (timer !== void 0) clearInterval(timer);
|
|
621
|
+
window.removeEventListener("resize", onResize);
|
|
622
|
+
clear();
|
|
623
|
+
};
|
|
624
|
+
}
|
|
470
625
|
|
|
471
626
|
// src/client/SessionEndControl.tsx
|
|
472
627
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -577,6 +732,7 @@ function SessionEndControl(props) {
|
|
|
577
732
|
clearInterval(timer);
|
|
578
733
|
};
|
|
579
734
|
}, [sessionId]);
|
|
735
|
+
(0, import_react4.useEffect)(() => startSessionEndGlobalNotice(), []);
|
|
580
736
|
if (sessionId === void 0 || sessionId === "") return null;
|
|
581
737
|
const change = (mode) => {
|
|
582
738
|
setOpen(false);
|
|
@@ -999,6 +1155,9 @@ function ConfigForm({ t, title, description, fields }) {
|
|
|
999
1155
|
] });
|
|
1000
1156
|
}
|
|
1001
1157
|
var AUTO_REVIEW_FIELDS = [
|
|
1158
|
+
{ path: ["autoReviewFix", "reviewContextGuard"], label: "form.autoReview.reviewGuard", hint: "form.autoReview.reviewGuardHint", kind: "switch" },
|
|
1159
|
+
{ path: ["autoReviewFix", "reviewMaxHistoryChars"], label: "form.autoReview.reviewMaxHistory", hint: "form.autoReview.reviewMaxHistoryHint", kind: "number", min: 2e4, max: 6e5 },
|
|
1160
|
+
{ path: ["autoReviewFix", "reviewKeepRecentEntries"], label: "form.autoReview.reviewKeepRecent", kind: "number", min: 4, max: 64 },
|
|
1002
1161
|
{ path: ["autoReviewFix", "translateApprovalReason"], label: "form.autoReview.translate", hint: "form.autoReview.translateHint", kind: "switch" },
|
|
1003
1162
|
{ path: ["autoReviewFix", "keepPresetGuard"], label: "form.autoReview.keepPreset", hint: "form.autoReview.keepPresetHint", kind: "switch" },
|
|
1004
1163
|
{ path: ["autoReviewFix", "translateTimeoutMs"], label: "form.autoReview.timeout", kind: "number", min: 500, max: 6e4 },
|
|
@@ -1162,6 +1321,10 @@ function SettingsSection({ t }) {
|
|
|
1162
1321
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentName, children: t("page.components.restart") }),
|
|
1163
1322
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentHint, children: t("page.components.restartHint") })
|
|
1164
1323
|
] }),
|
|
1324
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: pageStyles.componentRow, children: [
|
|
1325
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentName, children: t("page.components.authCookie") }),
|
|
1326
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentHint, children: t("page.components.authCookieHint") })
|
|
1327
|
+
] }),
|
|
1165
1328
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: pageStyles.componentRow, children: [
|
|
1166
1329
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentName, children: t("page.components.sessionEnd") }),
|
|
1167
1330
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: pageStyles.componentHint, children: t("page.components.sessionEndHint") })
|
|
@@ -1366,6 +1529,11 @@ var zh = {
|
|
|
1366
1529
|
"form.failed": "\u4FDD\u5B58\u5931\u8D25",
|
|
1367
1530
|
"form.unavailable": "\u65E0\u6CD5\u8BFB\u53D6\u63D2\u4EF6\u8BBE\u7F6E\uFF1A\u8BF7\u786E\u8BA4 profile \u4E2D\u7684\u63D2\u4EF6\u6761\u76EE id \u4E3A mcviseron",
|
|
1368
1531
|
"form.autoSave": "\u4FEE\u6539\u540E\u81EA\u52A8\u4FDD\u5B58",
|
|
1532
|
+
"form.autoReview.reviewGuard": "\u88C1\u526A Auto review \u4E0A\u4E0B\u6587",
|
|
1533
|
+
"form.autoReview.reviewGuardHint": "\u53EA\u538B\u7F29 reviewer \u7684\u5386\u53F2\uFF1B\u5F53\u524D\u52A8\u4F5C\u3001\u5DE5\u7A0B\u7EA6\u675F\u548C\u4EBA\u7C7B\u6307\u4EE4\u4FDD\u7559\uFF0C\u907F\u514D\u957F\u4F1A\u8BDD\u628A\u5BA1\u67E5\u6A21\u578B\u6491\u7206",
|
|
1534
|
+
"form.autoReview.reviewMaxHistory": "\u5BA1\u67E5\u5386\u53F2\u4E0A\u9650\uFF08\u5B57\u7B26\uFF09",
|
|
1535
|
+
"form.autoReview.reviewMaxHistoryHint": "\u9ED8\u8BA4 120000\uFF1B\u8D85\u51FA\u540E\u65E7\u5DE5\u5177\u8C03\u7528\u4F1A\u6298\u53E0\u6210\u6458\u8981",
|
|
1536
|
+
"form.autoReview.reviewKeepRecent": "\u4FDD\u7559\u6700\u8FD1\u5386\u53F2\u6761\u6570",
|
|
1369
1537
|
"form.autoReview.translate": "\u7FFB\u8BD1\u5BA1\u6279\u7406\u7531",
|
|
1370
1538
|
"form.autoReview.translateHint": "\u82F1\u6587\u5BA1\u67E5\u7406\u7531\u4F1A\u9644\u4E0A\u4E2D\u6587\u7FFB\u8BD1\uFF0C\u5E76\u5199\u5165\u5BA1\u6279\u4E8B\u4EF6\uFF1B\u8F6C\u624B\u52A8\u540E\u88AB\u62D2\u65F6\uFF0C\u81EA\u52A8\u5BA1\u67E5\u7406\u7531\u4F1A\u4F5C\u4E3A notice \u4EA4\u56DE AI",
|
|
1371
1539
|
"form.autoReview.keepPreset": "\u9000\u51FA\u65F6\u4FDD\u6301\u6743\u9650\u9884\u8BBE",
|
|
@@ -1401,6 +1569,8 @@ var zh = {
|
|
|
1401
1569
|
"page.tab.sessionEnd": "\u4F1A\u8BDD\u540E\u52A8\u4F5C",
|
|
1402
1570
|
"page.sessionEnd.title": "\u4F1A\u8BDD\u540E\u52A8\u4F5C",
|
|
1403
1571
|
"page.sessionEnd.description": "\u672C\u8F6E\u6700\u7EC8\u56DE\u590D\u5B8C\u6574\u663E\u793A\u540E\u6267\u884C\u4E00\u6B21\u52A8\u4F5C\uFF1B\u91CD\u542F\u4F1A\u7B49\u5F85\u6240\u6709\u4F1A\u8BDD\u4E0E\u540E\u53F0\u4EFB\u52A1\u7ED3\u675F\uFF0C\u8BBE\u7F6E\u9875\u7684\u91CD\u542F\u4E0D\u53D7\u6B64\u7EA6\u675F\u3002",
|
|
1572
|
+
"page.components.authCookie": "\u8BA4\u8BC1 cookie \u6E05\u7406",
|
|
1573
|
+
"page.components.authCookieHint": "\u81EA\u52A8\u8FD0\u884C\uFF0C\u65E0\u8BBE\u7F6E",
|
|
1404
1574
|
"page.components.sessionEnd": "\u4F1A\u8BDD\u540E\u52A8\u4F5C",
|
|
1405
1575
|
"page.components.sessionEndHint": "\u8F93\u5165\u6846\u5DE6\u4FA7\u7684\u300C\u4F1A\u8BDD\u540E\u91CD\u542F\u300D\u4E0B\u62C9",
|
|
1406
1576
|
"form.sessionEnd.enabled": "\u542F\u7528\u4F1A\u8BDD\u540E\u52A8\u4F5C",
|
|
@@ -1487,6 +1657,11 @@ var en = {
|
|
|
1487
1657
|
"form.failed": "Save failed",
|
|
1488
1658
|
"form.unavailable": "Cannot read the plugin settings: check that the profile entry id is mcviseron",
|
|
1489
1659
|
"form.autoSave": "Changes save automatically",
|
|
1660
|
+
"form.autoReview.reviewGuard": "Trim the Auto-review context",
|
|
1661
|
+
"form.autoReview.reviewGuardHint": "Compacts only the reviewer history; the pending action, project constraints and human instructions stay",
|
|
1662
|
+
"form.autoReview.reviewMaxHistory": "Reviewer history limit (chars)",
|
|
1663
|
+
"form.autoReview.reviewMaxHistoryHint": "Defaults to 120000; older tool calls collapse into a summary",
|
|
1664
|
+
"form.autoReview.reviewKeepRecent": "Recent entries to keep",
|
|
1490
1665
|
"form.autoReview.translate": "Translate the approval reason",
|
|
1491
1666
|
"form.autoReview.translateHint": "Appends a Chinese translation to the reviewer note and writes it into the approval event; a manual rejection returns the auto-review reason to the AI",
|
|
1492
1667
|
"form.autoReview.keepPreset": "Keep the permission preset on shutdown",
|
|
@@ -1522,6 +1697,8 @@ var en = {
|
|
|
1522
1697
|
"page.tab.sessionEnd": "After-session action",
|
|
1523
1698
|
"page.sessionEnd.title": "After-session action",
|
|
1524
1699
|
"page.sessionEnd.description": "One action after the final reply is fully displayed. A restart waits for every running conversation and background job; the Settings restart button is not delayed.",
|
|
1700
|
+
"page.components.authCookie": "Auth-cookie cleanup",
|
|
1701
|
+
"page.components.authCookieHint": "Runs automatically; no settings",
|
|
1525
1702
|
"page.components.sessionEnd": "After-session action",
|
|
1526
1703
|
"page.components.sessionEndHint": "The \u201CRestart after session\u201D dropdown left of the composer",
|
|
1527
1704
|
"form.sessionEnd.enabled": "Enable after-session actions",
|
|
@@ -1537,6 +1714,7 @@ var en = {
|
|
|
1537
1714
|
|
|
1538
1715
|
// src/client/index.ts
|
|
1539
1716
|
var NS = "mcviseron";
|
|
1717
|
+
var authCookiePruneStarted = false;
|
|
1540
1718
|
var inject = ["slots", "locale"];
|
|
1541
1719
|
function registerSafely(ctx, name, options, component, onRegistered, onFailed) {
|
|
1542
1720
|
const slots = ctx.slots;
|
|
@@ -1559,6 +1737,18 @@ function registerSafely(ctx, name, options, component, onRegistered, onFailed) {
|
|
|
1559
1737
|
}
|
|
1560
1738
|
}
|
|
1561
1739
|
function apply(ctx) {
|
|
1740
|
+
if (!authCookiePruneStarted) {
|
|
1741
|
+
authCookiePruneStarted = true;
|
|
1742
|
+
try {
|
|
1743
|
+
void fetch(AUTH_COOKIE_API.prune, {
|
|
1744
|
+
method: "POST",
|
|
1745
|
+
credentials: "same-origin",
|
|
1746
|
+
cache: "no-store"
|
|
1747
|
+
}).catch(() => {
|
|
1748
|
+
});
|
|
1749
|
+
} catch {
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1562
1752
|
try {
|
|
1563
1753
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "mcviseron: dictionaries");
|
|
1564
1754
|
} catch (error) {
|