dsh-mcviseron-plugin 0.0.0-stage → 0.6.2
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 +222 -0
- package/CONTRIBUTING.md +60 -0
- package/LICENSE +202 -0
- package/README.en.md +146 -0
- package/README.md +287 -2
- package/SECURITY.md +38 -0
- package/cordis.patch.yml +12 -0
- package/docs/automation-task.md +63 -0
- package/docs/migration-from-standalone.md +115 -0
- package/docs/release.md +85 -0
- package/lib/appearance.js +320 -0
- package/lib/auto-review-fix.js +453 -0
- package/lib/client.js +1266 -0
- package/lib/index.js +1701 -0
- package/lib/restart.js +226 -0
- package/lib/task-guard.js +736 -0
- package/package.json +148 -4
- package/scripts/repair-profile.mjs +77 -0
- package/src/api.ts +5 -0
- package/src/appearance/index.ts +103 -0
- package/src/auto-review-fix/index.ts +45 -0
- package/src/client/AppearanceScheduleRow.tsx +112 -0
- package/src/client/ConfigForm.tsx +284 -0
- package/src/client/FallbackRestartRow.tsx +23 -0
- package/src/client/RestartCard.tsx +108 -0
- package/src/client/SettingsSection.tsx +110 -0
- package/src/client/bridge.ts +131 -0
- package/src/client/driver.ts +166 -0
- package/src/client/index.ts +114 -0
- package/src/client/locales.ts +193 -0
- package/src/client/primitives.d.ts +15 -0
- package/src/client/section-presence.ts +33 -0
- package/src/client/styles.ts +154 -0
- package/src/components/auto-review-fix/index.ts +421 -0
- package/src/components/auto-review-fix/translate.ts +235 -0
- package/src/components/task-guard/index.ts +1077 -0
- package/src/index.ts +71 -0
- package/src/loopback.ts +48 -0
- package/src/namespace.ts +7 -0
- package/src/restart/index.ts +268 -0
- package/src/routes.ts +228 -0
- package/src/schedule.ts +125 -0
- package/src/task-guard/index.ts +52 -0
- package/src/volatile.ts +32 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
// src/auto-review-fix/index.ts
|
|
2
|
+
import z from "@deepseek-ai/schemastery";
|
|
3
|
+
|
|
4
|
+
// src/components/auto-review-fix/index.ts
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
// src/components/auto-review-fix/translate.ts
|
|
8
|
+
var TRANSLATION_LABEL = "\u3010\u5BA1\u67E5\u7406\u7531 \xB7 \u4E2D\u6587\u7FFB\u8BD1\u3011";
|
|
9
|
+
var SYSTEM_PROMPT = [
|
|
10
|
+
"You translate the internal reviewer notes of an AI tool-approval system into Simplified Chinese.",
|
|
11
|
+
"Rules:",
|
|
12
|
+
"- Output the translation only: no preamble, no quotes, no Markdown fences.",
|
|
13
|
+
"- Keep tool names, file paths, identifiers, URLs, JSON and code exactly as written.",
|
|
14
|
+
"- Preserve meaning and ordering; do not summarize, add or omit anything."
|
|
15
|
+
].join("\n");
|
|
16
|
+
var CACHE_LIMIT = 256;
|
|
17
|
+
var cache = /* @__PURE__ */ new Map();
|
|
18
|
+
var CHINESE_KEY = /^zh(?:[-_]|$)/i;
|
|
19
|
+
function chineseKey(display) {
|
|
20
|
+
if (typeof display["zh"] === "string") return "zh";
|
|
21
|
+
for (const key of Object.keys(display)) {
|
|
22
|
+
if (CHINESE_KEY.test(key) && typeof display[key] === "string") return key;
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
function englishText(display) {
|
|
27
|
+
if (typeof display["en"] === "string") return display["en"];
|
|
28
|
+
const key = chineseKey(display);
|
|
29
|
+
if (key !== void 0) return void 0;
|
|
30
|
+
for (const value of Object.values(display)) if (typeof value === "string") return value;
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
function isAutoReviewText(text) {
|
|
34
|
+
return /auto[\s\-_]*review/i.test(text);
|
|
35
|
+
}
|
|
36
|
+
function reviewerExcerpt(text) {
|
|
37
|
+
const match = /^\s*auto[\s\-_]*review\s+(?:denied\s+this\s+call|拒绝了此调用)\s*[::.]?\s*/i.exec(text);
|
|
38
|
+
if (match === null) return text.trim();
|
|
39
|
+
const rest = text.slice(match[0].length).trim();
|
|
40
|
+
return rest.length === 0 ? text.trim() : rest;
|
|
41
|
+
}
|
|
42
|
+
function withTranslation(original, translation) {
|
|
43
|
+
return original.length === 0 ? `${TRANSLATION_LABEL}
|
|
44
|
+
${translation}` : `${original}
|
|
45
|
+
|
|
46
|
+
${TRANSLATION_LABEL}
|
|
47
|
+
${translation}`;
|
|
48
|
+
}
|
|
49
|
+
function hasTranslation(value) {
|
|
50
|
+
return value.includes(TRANSLATION_LABEL);
|
|
51
|
+
}
|
|
52
|
+
function isPredominantlyChinese(text) {
|
|
53
|
+
const han = (text.match(/[\u3400-\u9fff\uf900-\ufaff]/g) ?? []).length;
|
|
54
|
+
if (han === 0) return false;
|
|
55
|
+
const englishWords = (text.match(/[A-Za-z][A-Za-z0-9_.-]*/g) ?? []).length;
|
|
56
|
+
return englishWords <= Math.max(2, Math.ceil(han / 2));
|
|
57
|
+
}
|
|
58
|
+
function cleanTranslation(raw) {
|
|
59
|
+
let text = raw.trim();
|
|
60
|
+
const fenced = /^\s*```[a-zA-Z]*\n([\s\S]*?)\n```\s*$/.exec(text);
|
|
61
|
+
const fencedBody = fenced?.[1];
|
|
62
|
+
if (fencedBody !== void 0) text = fencedBody.trim();
|
|
63
|
+
if (text.length >= 2) {
|
|
64
|
+
const first = text[0];
|
|
65
|
+
const last = text[text.length - 1];
|
|
66
|
+
if (first === '"' && last === '"' || first === "'" && last === "'" || first === "\u300C" && last === "\u300D") {
|
|
67
|
+
text = text.slice(1, -1).trim();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
function sessionRoute(request) {
|
|
73
|
+
try {
|
|
74
|
+
const agent = request?.agent;
|
|
75
|
+
const header = typeof agent?.session?.requestHeader === "function" ? agent.session.requestHeader() : void 0;
|
|
76
|
+
const config = header?.config;
|
|
77
|
+
const provider = config?.provider;
|
|
78
|
+
const model = config?.model;
|
|
79
|
+
if (typeof provider === "string" && provider.length > 0 && typeof model === "string" && model.length > 0) {
|
|
80
|
+
return { provider, model };
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
function translationRoute(settings, request) {
|
|
87
|
+
if (settings.provider.length > 0 && settings.model.length > 0) {
|
|
88
|
+
return { provider: settings.provider, model: settings.model };
|
|
89
|
+
}
|
|
90
|
+
return sessionRoute(request);
|
|
91
|
+
}
|
|
92
|
+
async function readStream(stream, controller) {
|
|
93
|
+
let text = "";
|
|
94
|
+
for await (const chunk of stream) {
|
|
95
|
+
if (controller.signal.aborted) return void 0;
|
|
96
|
+
const value = chunk;
|
|
97
|
+
if (value === null || typeof value !== "object") continue;
|
|
98
|
+
if (value.type === "text-delta" && typeof value.text === "string") {
|
|
99
|
+
text += value.text;
|
|
100
|
+
if (text.length > 16e3) break;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (value.type === "finish") {
|
|
104
|
+
const kind = value.reason?.kind;
|
|
105
|
+
if (typeof kind === "string" && kind !== "stop") return void 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
async function translateForDisplay(llm, settings, request, text) {
|
|
111
|
+
const source = text.trim();
|
|
112
|
+
if (source.length === 0 || source.length > settings.maxChars) return void 0;
|
|
113
|
+
const cached = cache.get(source);
|
|
114
|
+
if (cached !== void 0) return cached;
|
|
115
|
+
if (llm === void 0 || typeof llm.stream !== "function") return void 0;
|
|
116
|
+
const route = translationRoute(settings, request);
|
|
117
|
+
if (route === void 0) return void 0;
|
|
118
|
+
const controller = new AbortController();
|
|
119
|
+
const timer = setTimeout(() => controller.abort(new Error("translation timeout")), settings.timeoutMs);
|
|
120
|
+
try {
|
|
121
|
+
const stream = await llm.stream({
|
|
122
|
+
provider: route.provider,
|
|
123
|
+
model: route.model,
|
|
124
|
+
system: SYSTEM_PROMPT,
|
|
125
|
+
messages: [{ role: "user", content: [{ type: "text", text: source }] }],
|
|
126
|
+
temperature: 0,
|
|
127
|
+
signal: controller.signal
|
|
128
|
+
});
|
|
129
|
+
if (stream === null || typeof stream !== "object") return void 0;
|
|
130
|
+
const collected = await readStream(stream, controller);
|
|
131
|
+
if (collected === void 0) return void 0;
|
|
132
|
+
const cleaned = cleanTranslation(collected);
|
|
133
|
+
if (cleaned.length === 0) return void 0;
|
|
134
|
+
if (cache.size >= CACHE_LIMIT) {
|
|
135
|
+
const oldest = cache.keys().next();
|
|
136
|
+
if (oldest.done !== true) cache.delete(oldest.value);
|
|
137
|
+
}
|
|
138
|
+
cache.set(source, cleaned);
|
|
139
|
+
return cleaned;
|
|
140
|
+
} catch {
|
|
141
|
+
return void 0;
|
|
142
|
+
} finally {
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/components/auto-review-fix/index.ts
|
|
148
|
+
var FIBER_STATE_ACTIVE = 2;
|
|
149
|
+
var guardedPresets = /* @__PURE__ */ new WeakSet();
|
|
150
|
+
var guardedApproval = /* @__PURE__ */ new WeakSet();
|
|
151
|
+
function boolSetting(source, key, fallback) {
|
|
152
|
+
const value = source[key];
|
|
153
|
+
return typeof value === "boolean" ? value : fallback;
|
|
154
|
+
}
|
|
155
|
+
function stringSetting(source, key, fallback) {
|
|
156
|
+
const value = source[key];
|
|
157
|
+
return typeof value === "string" ? value.trim() : fallback;
|
|
158
|
+
}
|
|
159
|
+
function numberSetting(source, key, fallback, min, max) {
|
|
160
|
+
const value = source[key];
|
|
161
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
162
|
+
return Math.min(Math.max(Math.trunc(value), min), max);
|
|
163
|
+
}
|
|
164
|
+
function normalizeConfig(config) {
|
|
165
|
+
const source = config !== null && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
166
|
+
const translate = boolSetting(source, "translateApprovalReason", true);
|
|
167
|
+
return {
|
|
168
|
+
keepPresetGuard: boolSetting(source, "keepPresetGuard", true),
|
|
169
|
+
enabled: translate,
|
|
170
|
+
timeoutMs: numberSetting(source, "translateTimeoutMs", 6e3, 500, 6e4),
|
|
171
|
+
maxChars: numberSetting(source, "translateMaxChars", 4e3, 100, 2e4),
|
|
172
|
+
provider: stringSetting(source, "translateProvider", ""),
|
|
173
|
+
model: stringSetting(source, "translateModel", "")
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function whenService(ctx, name, run) {
|
|
177
|
+
try {
|
|
178
|
+
const inject = ctx.inject;
|
|
179
|
+
if (typeof inject === "function") {
|
|
180
|
+
inject.call(ctx, [name], run);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const get = ctx.get;
|
|
184
|
+
const service = typeof get === "function" ? get.call(ctx, name) : void 0;
|
|
185
|
+
if (service !== void 0) run(ctx);
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function serviceOf(scope, name) {
|
|
190
|
+
try {
|
|
191
|
+
const direct = scope[name];
|
|
192
|
+
if (direct !== void 0) return direct;
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const get = scope.get;
|
|
197
|
+
return typeof get === "function" ? get.call(scope, name) : void 0;
|
|
198
|
+
} catch {
|
|
199
|
+
return void 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function effectOf(scope, setup, label) {
|
|
203
|
+
try {
|
|
204
|
+
const effect = scope.effect;
|
|
205
|
+
if (typeof effect === "function") effect.call(scope, setup, label);
|
|
206
|
+
} catch {
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function rootIsActive(root) {
|
|
210
|
+
try {
|
|
211
|
+
const fiber = root?.fiber;
|
|
212
|
+
const state = fiber?.state;
|
|
213
|
+
if (typeof state !== "number") return true;
|
|
214
|
+
return state === FIBER_STATE_ACTIVE;
|
|
215
|
+
} catch {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function installPresetGuard(ctx) {
|
|
220
|
+
whenService(ctx, "permissionPresets", (scope) => {
|
|
221
|
+
const presets = serviceOf(scope, "permissionPresets");
|
|
222
|
+
if (presets === null || typeof presets !== "object") return;
|
|
223
|
+
if (typeof presets.set !== "function") return;
|
|
224
|
+
if (guardedPresets.has(presets)) return;
|
|
225
|
+
const original = presets.set;
|
|
226
|
+
const root = scope.root;
|
|
227
|
+
const wrapper = function(session, name) {
|
|
228
|
+
if (!rootIsActive(root)) return void 0;
|
|
229
|
+
return original.call(this, session, name);
|
|
230
|
+
};
|
|
231
|
+
try {
|
|
232
|
+
presets.set = wrapper;
|
|
233
|
+
guardedPresets.add(presets);
|
|
234
|
+
} catch {
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async function decorateApprovalRequest(scope, settings, request, translate = translateForDisplay) {
|
|
239
|
+
if (!settings.enabled || request === null || typeof request !== "object") return request;
|
|
240
|
+
const display = request.displayReason;
|
|
241
|
+
if (display === null || typeof display !== "object" || Array.isArray(display)) return request;
|
|
242
|
+
const record = display;
|
|
243
|
+
const key = chineseKey(record);
|
|
244
|
+
if (key === void 0) return request;
|
|
245
|
+
const english = englishText(record);
|
|
246
|
+
if (english === void 0 || !isAutoReviewText(english)) return request;
|
|
247
|
+
const localized = record[key];
|
|
248
|
+
if (typeof localized !== "string" || hasTranslation(localized)) return request;
|
|
249
|
+
const excerpt = reviewerExcerpt(english);
|
|
250
|
+
if (excerpt.length === 0 || excerpt.length > settings.maxChars) return request;
|
|
251
|
+
if (isPredominantlyChinese(excerpt)) return request;
|
|
252
|
+
if (translationRoute(settings, request) === void 0) return request;
|
|
253
|
+
const llm = serviceOf(scope, "llm");
|
|
254
|
+
const translated = await translate(llm, settings, request, excerpt);
|
|
255
|
+
if (translated === void 0) return request;
|
|
256
|
+
const cleaned = cleanTranslation(translated);
|
|
257
|
+
if (cleaned.length === 0 || !/[\u4e00-\u9fff]/.test(cleaned)) return request;
|
|
258
|
+
const reasonValue = request.reason;
|
|
259
|
+
const originalReason = typeof reasonValue === "string" ? reasonValue : "";
|
|
260
|
+
const reasonWithTranslation = originalReason !== "" && !originalReason.includes(TRANSLATION_LABEL) ? withTranslation(originalReason, cleaned) : originalReason;
|
|
261
|
+
return {
|
|
262
|
+
...request,
|
|
263
|
+
...reasonWithTranslation !== originalReason ? { reason: reasonWithTranslation } : {},
|
|
264
|
+
displayReason: { ...record, [key]: withTranslation(localized, cleaned) }
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function sessionIdOf(agent) {
|
|
268
|
+
const session = agent?.session;
|
|
269
|
+
return typeof session?.id === "string" ? session.id : "";
|
|
270
|
+
}
|
|
271
|
+
function sessionVersion(agent) {
|
|
272
|
+
const version = agent?.session?.header?.version;
|
|
273
|
+
return typeof version === "number" ? version : void 0;
|
|
274
|
+
}
|
|
275
|
+
function rejectionKey(agent, callId) {
|
|
276
|
+
if (typeof callId !== "string" || callId === "") return "";
|
|
277
|
+
const sessionId = sessionIdOf(agent);
|
|
278
|
+
return sessionId === "" ? "" : sessionId + ":" + callId;
|
|
279
|
+
}
|
|
280
|
+
function approvalReasonText(request) {
|
|
281
|
+
const record = request;
|
|
282
|
+
const display = record.displayReason;
|
|
283
|
+
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
284
|
+
const key = chineseKey(display);
|
|
285
|
+
if (key !== void 0) {
|
|
286
|
+
const value = display[key];
|
|
287
|
+
if (typeof value === "string" && value !== "") return value;
|
|
288
|
+
}
|
|
289
|
+
const english = englishText(display);
|
|
290
|
+
if (english !== void 0 && english !== "") return english;
|
|
291
|
+
}
|
|
292
|
+
return typeof record.reason === "string" ? record.reason : "";
|
|
293
|
+
}
|
|
294
|
+
function isAutoReviewApproval(request) {
|
|
295
|
+
const record = request;
|
|
296
|
+
if (typeof record.reason === "string" && isAutoReviewText(record.reason)) return true;
|
|
297
|
+
const display = record.displayReason;
|
|
298
|
+
if (display !== null && typeof display === "object" && !Array.isArray(display)) {
|
|
299
|
+
const english = englishText(display);
|
|
300
|
+
if (english !== void 0 && isAutoReviewText(english)) return true;
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
function rejectionSource(agent, summary) {
|
|
305
|
+
return sessionVersion(agent) === 3 ? { kind: "plugin", plugin: "auto-review-fix", form: "notice", summary } : { kind: "plugin:auto-review-fix", form: "notice", summary };
|
|
306
|
+
}
|
|
307
|
+
function buildRejectionNotice(agent, request) {
|
|
308
|
+
const reason = approvalReasonText(request);
|
|
309
|
+
if (reason === "") return void 0;
|
|
310
|
+
const toolName = typeof request.toolName === "string" && request.toolName !== "" ? request.toolName : "\u672A\u77E5\u5DE5\u5177";
|
|
311
|
+
const text = [
|
|
312
|
+
'\u3010\u5BA1\u6279\u88AB\u62D2\u3011\u5DE5\u5177 "' + toolName + '" \u7684\u4EBA\u5DE5\u5BA1\u6279\u88AB\u62D2\u7EDD\u3002',
|
|
313
|
+
"\u81EA\u52A8\u5BA1\u67E5\u7406\u7531\uFF1A",
|
|
314
|
+
reason,
|
|
315
|
+
"",
|
|
316
|
+
"\u8BF7\u6839\u636E\u8BE5\u7406\u7531\u8C03\u6574\u65B9\u6848\uFF0C\u4E0D\u8981\u91CD\u590D\u540C\u4E00\u64CD\u4F5C\u3002"
|
|
317
|
+
].join("\n");
|
|
318
|
+
return {
|
|
319
|
+
id: randomUUID(),
|
|
320
|
+
role: "user",
|
|
321
|
+
content: [{ type: "text", text }],
|
|
322
|
+
source: rejectionSource(agent, "\u5BA1\u6279\u88AB\u62D2 \xB7 " + toolName)
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function createRejectionRelay() {
|
|
326
|
+
const notes = /* @__PURE__ */ new Map();
|
|
327
|
+
const ttl = 12e4;
|
|
328
|
+
return {
|
|
329
|
+
remember(key, notice) {
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
for (const [oldKey, entry] of notes) if (now - entry.at > ttl) notes.delete(oldKey);
|
|
332
|
+
if (notes.size >= 50) {
|
|
333
|
+
const oldest = notes.keys().next().value;
|
|
334
|
+
if (oldest !== void 0) notes.delete(oldest);
|
|
335
|
+
}
|
|
336
|
+
notes.set(key, { notice, at: now });
|
|
337
|
+
},
|
|
338
|
+
take(key) {
|
|
339
|
+
const entry = notes.get(key);
|
|
340
|
+
if (entry === void 0) return void 0;
|
|
341
|
+
notes.delete(key);
|
|
342
|
+
return entry.notice;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
var relayedContexts = /* @__PURE__ */ new WeakSet();
|
|
347
|
+
function installRejectionRelay(ctx, relay) {
|
|
348
|
+
const target = ctx;
|
|
349
|
+
if (typeof target.on !== "function" || relayedContexts.has(ctx)) return;
|
|
350
|
+
relayedContexts.add(ctx);
|
|
351
|
+
target.on.call(ctx, "tools/post-execute", async (exec, result, next) => {
|
|
352
|
+
const downstream = await next() ?? { kind: "accept" };
|
|
353
|
+
if (result?.isError !== true) return downstream;
|
|
354
|
+
const key = rejectionKey(exec?.agent, exec?.callId);
|
|
355
|
+
if (key === "") return downstream;
|
|
356
|
+
const notice = relay.take(key);
|
|
357
|
+
if (notice === void 0) return downstream;
|
|
358
|
+
return {
|
|
359
|
+
...downstream,
|
|
360
|
+
additionalContexts: [
|
|
361
|
+
...Array.isArray(downstream.additionalContexts) ? downstream.additionalContexts : [],
|
|
362
|
+
notice
|
|
363
|
+
]
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function installApprovalTranslation(ctx, settings, relay) {
|
|
368
|
+
whenService(ctx, "approval", (scope) => {
|
|
369
|
+
const approval = serviceOf(scope, "approval");
|
|
370
|
+
if (approval === null || typeof approval !== "object") return;
|
|
371
|
+
const original = approval.request;
|
|
372
|
+
if (typeof original !== "function") return;
|
|
373
|
+
if (guardedApproval.has(approval)) return;
|
|
374
|
+
const call = original;
|
|
375
|
+
const wrapper = async function(request) {
|
|
376
|
+
let decorated = request;
|
|
377
|
+
try {
|
|
378
|
+
decorated = await decorateApprovalRequest(scope, settings, request);
|
|
379
|
+
} catch {
|
|
380
|
+
decorated = request;
|
|
381
|
+
}
|
|
382
|
+
const outcome = await call.call(this, decorated);
|
|
383
|
+
if (outcome === "rejected" && isAutoReviewApproval(decorated)) {
|
|
384
|
+
const request2 = decorated;
|
|
385
|
+
const key = rejectionKey(request2.agent, request2.callId);
|
|
386
|
+
const notice = buildRejectionNotice(request2.agent, decorated);
|
|
387
|
+
if (key !== "" && notice !== void 0) relay.remember(key, notice);
|
|
388
|
+
}
|
|
389
|
+
return outcome;
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
approval.request = wrapper;
|
|
393
|
+
guardedApproval.add(approval);
|
|
394
|
+
} catch {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
effectOf(scope, () => () => {
|
|
398
|
+
if (approval.request === wrapper) approval.request = call;
|
|
399
|
+
}, "mcviseron: restore approval.request");
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
function installAutoReview(ctx, config) {
|
|
403
|
+
const settings = normalizeConfig(config);
|
|
404
|
+
if (settings.keepPresetGuard) installPresetGuard(ctx);
|
|
405
|
+
if (settings.enabled) {
|
|
406
|
+
const relay = createRejectionRelay();
|
|
407
|
+
installRejectionRelay(ctx, relay);
|
|
408
|
+
installApprovalTranslation(ctx, settings, relay);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/volatile.ts
|
|
413
|
+
function isVolatileLike(value) {
|
|
414
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
415
|
+
if (typeof value.get !== "function") return false;
|
|
416
|
+
return Object.getOwnPropertySymbols(value).length > 0 || Object.keys(value).every((key) => key === "get");
|
|
417
|
+
}
|
|
418
|
+
function toPlain(value) {
|
|
419
|
+
if (isVolatileLike(value)) return toPlain(value.get());
|
|
420
|
+
if (Array.isArray(value)) return value.map((item) => toPlain(item));
|
|
421
|
+
if (value !== null && typeof value === "object") {
|
|
422
|
+
const result = {};
|
|
423
|
+
for (const [key, child] of Object.entries(value)) result[key] = toPlain(child);
|
|
424
|
+
return result;
|
|
425
|
+
}
|
|
426
|
+
return value;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/auto-review-fix/index.ts
|
|
430
|
+
var DEFAULT_AUTO_REVIEW_CONFIG = {
|
|
431
|
+
keepPresetGuard: true,
|
|
432
|
+
translateApprovalReason: true,
|
|
433
|
+
translateTimeoutMs: 6e3,
|
|
434
|
+
translateMaxChars: 4e3,
|
|
435
|
+
translateProvider: "",
|
|
436
|
+
translateModel: ""
|
|
437
|
+
};
|
|
438
|
+
var Config = z.object({
|
|
439
|
+
keepPresetGuard: z.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.keepPresetGuard).volatile(),
|
|
440
|
+
translateApprovalReason: z.boolean().default(DEFAULT_AUTO_REVIEW_CONFIG.translateApprovalReason).volatile(),
|
|
441
|
+
translateTimeoutMs: z.number().min(500).max(6e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateTimeoutMs).volatile(),
|
|
442
|
+
translateMaxChars: z.number().min(100).max(2e4).default(DEFAULT_AUTO_REVIEW_CONFIG.translateMaxChars).volatile(),
|
|
443
|
+
translateProvider: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateProvider).volatile(),
|
|
444
|
+
translateModel: z.string().default(DEFAULT_AUTO_REVIEW_CONFIG.translateModel).volatile()
|
|
445
|
+
}).default(DEFAULT_AUTO_REVIEW_CONFIG);
|
|
446
|
+
function apply(ctx, config) {
|
|
447
|
+
installAutoReview(ctx, toPlain(config));
|
|
448
|
+
}
|
|
449
|
+
export {
|
|
450
|
+
Config,
|
|
451
|
+
DEFAULT_AUTO_REVIEW_CONFIG,
|
|
452
|
+
apply
|
|
453
|
+
};
|