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,320 @@
|
|
|
1
|
+
// src/appearance/index.ts
|
|
2
|
+
import z from "@deepseek-ai/schemastery";
|
|
3
|
+
|
|
4
|
+
// src/loopback.ts
|
|
5
|
+
function isIPv4Loopback(value) {
|
|
6
|
+
const parts = value.split(".");
|
|
7
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
|
|
8
|
+
}
|
|
9
|
+
function isLoopbackAddress(address) {
|
|
10
|
+
if (address === void 0) return false;
|
|
11
|
+
const normalized = address.toLowerCase();
|
|
12
|
+
if (normalized === "::1") return true;
|
|
13
|
+
if (normalized.startsWith("::ffff:")) return isIPv4Loopback(normalized.slice("::ffff:".length));
|
|
14
|
+
return isIPv4Loopback(normalized);
|
|
15
|
+
}
|
|
16
|
+
function isLoopbackHostname(hostname) {
|
|
17
|
+
if (hostname === "localhost" || hostname === "[::1]") return true;
|
|
18
|
+
return isIPv4Loopback(hostname);
|
|
19
|
+
}
|
|
20
|
+
function isLoopbackRequest(request) {
|
|
21
|
+
if (!isLoopbackAddress(request.socket.remoteAddress)) return false;
|
|
22
|
+
const host = request.headers.host;
|
|
23
|
+
if (typeof host !== "string") return false;
|
|
24
|
+
let hostUrl;
|
|
25
|
+
try {
|
|
26
|
+
hostUrl = new URL("http://" + host);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (!isLoopbackHostname(hostUrl.hostname)) return false;
|
|
31
|
+
if (request.headers["sec-fetch-site"] === "cross-site") return false;
|
|
32
|
+
const origin = request.headers.origin;
|
|
33
|
+
if (origin === void 0) return true;
|
|
34
|
+
try {
|
|
35
|
+
return new URL(origin).host === hostUrl.host;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/routes.ts
|
|
42
|
+
import { SettingsConflictError } from "@deepseek-ai/dsh-settings";
|
|
43
|
+
|
|
44
|
+
// src/api.ts
|
|
45
|
+
var MCVISERON_API = {
|
|
46
|
+
describe: "/api/dsh-mcviseron/settings/describe",
|
|
47
|
+
mutate: "/api/dsh-mcviseron/settings/mutate"
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/namespace.ts
|
|
51
|
+
var MCVISERON_SETTINGS_NAMESPACE = "mcviseron";
|
|
52
|
+
|
|
53
|
+
// src/schedule.ts
|
|
54
|
+
var DEFAULT_SCHEDULE_CONFIG = {
|
|
55
|
+
enabled: false,
|
|
56
|
+
lightStart: "08:00",
|
|
57
|
+
lightEnd: "23:00"
|
|
58
|
+
};
|
|
59
|
+
var TIME_OF_DAY = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
60
|
+
function parseTimeOfDay(value) {
|
|
61
|
+
const match = TIME_OF_DAY.exec(value);
|
|
62
|
+
if (match === null) return void 0;
|
|
63
|
+
return Number(match[1]) * 60 + Number(match[2]);
|
|
64
|
+
}
|
|
65
|
+
function normalizeScheduleConfig(input) {
|
|
66
|
+
const record = input !== null && typeof input === "object" ? input : {};
|
|
67
|
+
const lightStart = typeof record.lightStart === "string" && parseTimeOfDay(record.lightStart) !== void 0 ? record.lightStart : DEFAULT_SCHEDULE_CONFIG.lightStart;
|
|
68
|
+
const lightEnd = typeof record.lightEnd === "string" && parseTimeOfDay(record.lightEnd) !== void 0 ? record.lightEnd : DEFAULT_SCHEDULE_CONFIG.lightEnd;
|
|
69
|
+
const enabled = typeof record.enabled === "boolean" ? record.enabled : DEFAULT_SCHEDULE_CONFIG.enabled;
|
|
70
|
+
return { enabled, lightStart, lightEnd };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/volatile.ts
|
|
74
|
+
function isVolatileLike(value) {
|
|
75
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
76
|
+
if (typeof value.get !== "function") return false;
|
|
77
|
+
return Object.getOwnPropertySymbols(value).length > 0 || Object.keys(value).every((key) => key === "get");
|
|
78
|
+
}
|
|
79
|
+
function toPlain(value) {
|
|
80
|
+
if (isVolatileLike(value)) return toPlain(value.get());
|
|
81
|
+
if (Array.isArray(value)) return value.map((item) => toPlain(item));
|
|
82
|
+
if (value !== null && typeof value === "object") {
|
|
83
|
+
const result = {};
|
|
84
|
+
for (const [key, child] of Object.entries(value)) result[key] = toPlain(child);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/routes.ts
|
|
91
|
+
var MAX_BODY_BYTES = 8 * 1024;
|
|
92
|
+
var FIELD_RULES = {
|
|
93
|
+
enabled: { type: "boolean" },
|
|
94
|
+
lightStart: { type: "time" },
|
|
95
|
+
lightEnd: { type: "time" },
|
|
96
|
+
"autoReviewFix.keepPresetGuard": { type: "boolean" },
|
|
97
|
+
"autoReviewFix.translateApprovalReason": { type: "boolean" },
|
|
98
|
+
"autoReviewFix.translateTimeoutMs": { type: "number", min: 500, max: 6e4 },
|
|
99
|
+
"autoReviewFix.translateMaxChars": { type: "number", min: 100, max: 2e4 },
|
|
100
|
+
"autoReviewFix.translateProvider": { type: "string" },
|
|
101
|
+
"autoReviewFix.translateModel": { type: "string" },
|
|
102
|
+
"taskGuard.enabled": { type: "boolean" },
|
|
103
|
+
"taskGuard.locale": { type: "enum", values: ["zh", "en"] },
|
|
104
|
+
"taskGuard.staleAfterCalls": { type: "number", min: 1, max: 1e3 },
|
|
105
|
+
"taskGuard.repeatEveryCalls": { type: "number", min: 0, max: 1e3 },
|
|
106
|
+
"taskGuard.blockAfterCalls": { type: "number", min: 0, max: 1e4 },
|
|
107
|
+
"taskGuard.rejectMissingActive": { type: "boolean" },
|
|
108
|
+
"taskGuard.sourceKind": { type: "enum", values: ["auto", "v3", "v4"] },
|
|
109
|
+
"taskGuard.maxListItems": { type: "number", min: 1, max: 100 },
|
|
110
|
+
"taskGuard.detectStepIntent": { type: "boolean" },
|
|
111
|
+
"taskGuard.translateTodoContent": { type: "boolean" },
|
|
112
|
+
"taskGuard.todoTranslationTimeoutMs": { type: "number", min: 500, max: 15e3 },
|
|
113
|
+
"taskGuard.include": { type: "strings" },
|
|
114
|
+
"taskGuard.exclude": { type: "strings" },
|
|
115
|
+
"restart.enabled": { type: "boolean" },
|
|
116
|
+
"restart.appPath": { type: "string" }
|
|
117
|
+
};
|
|
118
|
+
function ruleFor(path) {
|
|
119
|
+
if (!Array.isArray(path) || path.length === 0 || path.length > 2) return void 0;
|
|
120
|
+
if (!path.every((part) => typeof part === "string")) return void 0;
|
|
121
|
+
return FIELD_RULES[path.join(".")];
|
|
122
|
+
}
|
|
123
|
+
function validFieldValue(rule, value) {
|
|
124
|
+
switch (rule.type) {
|
|
125
|
+
case "boolean":
|
|
126
|
+
return typeof value === "boolean";
|
|
127
|
+
case "time":
|
|
128
|
+
return typeof value === "string" && parseTimeOfDay(value) !== void 0;
|
|
129
|
+
case "string":
|
|
130
|
+
return typeof value === "string";
|
|
131
|
+
case "number":
|
|
132
|
+
return typeof value === "number" && Number.isFinite(value) && Number.isInteger(value) && value >= rule.min && value <= rule.max;
|
|
133
|
+
case "enum":
|
|
134
|
+
return typeof value === "string" && rule.values.includes(value);
|
|
135
|
+
case "strings":
|
|
136
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function isRecord(value) {
|
|
140
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
141
|
+
}
|
|
142
|
+
function json(res, status, body) {
|
|
143
|
+
res.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store", "referrer-policy": "no-referrer" });
|
|
144
|
+
res.end(JSON.stringify(body));
|
|
145
|
+
}
|
|
146
|
+
async function readJsonBody(req) {
|
|
147
|
+
const chunks = [];
|
|
148
|
+
let size = 0;
|
|
149
|
+
for await (const chunk of req) {
|
|
150
|
+
const buffer = chunk;
|
|
151
|
+
size += buffer.length;
|
|
152
|
+
if (size > MAX_BODY_BYTES) return void 0;
|
|
153
|
+
chunks.push(buffer);
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
157
|
+
} catch {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function isSettingsConflict(error) {
|
|
162
|
+
if (error instanceof SettingsConflictError) return true;
|
|
163
|
+
return error?.code === "SETTINGS_CONFLICT";
|
|
164
|
+
}
|
|
165
|
+
function unwrapValue(value) {
|
|
166
|
+
if (value === null || value === void 0) return value;
|
|
167
|
+
if (typeof value === "object" && typeof value.get === "function") {
|
|
168
|
+
try {
|
|
169
|
+
return value.get();
|
|
170
|
+
} catch {
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
function toPluginView(descriptor) {
|
|
177
|
+
const plain = toPlain(unwrapValue(descriptor.value));
|
|
178
|
+
const record = isRecord(plain) ? plain : {};
|
|
179
|
+
return {
|
|
180
|
+
ns: String(descriptor.ns),
|
|
181
|
+
value: {
|
|
182
|
+
...normalizeScheduleConfig(plain),
|
|
183
|
+
autoReviewFix: isRecord(record.autoReviewFix) ? record.autoReviewFix : {},
|
|
184
|
+
taskGuard: isRecord(record.taskGuard) ? record.taskGuard : {},
|
|
185
|
+
restart: isRecord(record.restart) ? record.restart : {}
|
|
186
|
+
},
|
|
187
|
+
revision: descriptor.revision
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function findView(settings) {
|
|
191
|
+
return settings.describe({ redactSecrets: true }).find((descriptor) => String(descriptor.ns) === MCVISERON_SETTINGS_NAMESPACE);
|
|
192
|
+
}
|
|
193
|
+
function makeSettingsRoutes(settings) {
|
|
194
|
+
const describe = {
|
|
195
|
+
kind: "exact",
|
|
196
|
+
path: MCVISERON_API.describe,
|
|
197
|
+
handler: async (req, res) => {
|
|
198
|
+
if (req.method !== "POST") return json(res, 405, { ok: false, error: "method-not-allowed" });
|
|
199
|
+
if (!isLoopbackRequest(req)) return json(res, 403, { ok: false, error: "forbidden" });
|
|
200
|
+
const descriptor = findView(settings);
|
|
201
|
+
json(res, 200, {
|
|
202
|
+
ok: true,
|
|
203
|
+
value: {
|
|
204
|
+
namespaces: descriptor === void 0 ? [] : [toPluginView(descriptor)],
|
|
205
|
+
writable: settings.writable !== false
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const mutate = {
|
|
211
|
+
kind: "exact",
|
|
212
|
+
path: MCVISERON_API.mutate,
|
|
213
|
+
handler: async (req, res) => {
|
|
214
|
+
if (req.method !== "POST") return json(res, 405, { ok: false, error: "method-not-allowed" });
|
|
215
|
+
if (!isLoopbackRequest(req)) return json(res, 403, { ok: false, error: "forbidden" });
|
|
216
|
+
const body = await readJsonBody(req);
|
|
217
|
+
if (body === void 0 || typeof body !== "object" || body === null) {
|
|
218
|
+
return json(res, 400, { ok: false, code: "settings-rejected", message: "unreadable JSON body" });
|
|
219
|
+
}
|
|
220
|
+
const record = body;
|
|
221
|
+
if (record.ns !== MCVISERON_SETTINGS_NAMESPACE || !Array.isArray(record.ops)) {
|
|
222
|
+
return json(res, 400, { ok: false, code: "settings-rejected", message: "malformed settings request" });
|
|
223
|
+
}
|
|
224
|
+
const ops = record.ops;
|
|
225
|
+
const valid = ops.every((op) => {
|
|
226
|
+
if (op.op !== "set" && op.op !== "unset") return false;
|
|
227
|
+
const rule = ruleFor(op.path);
|
|
228
|
+
if (rule === void 0) return false;
|
|
229
|
+
if (op.op === "unset") return true;
|
|
230
|
+
return validFieldValue(rule, op.value);
|
|
231
|
+
});
|
|
232
|
+
if (!valid) {
|
|
233
|
+
return json(res, 400, { ok: false, code: "settings-rejected", message: "malformed settings operation" });
|
|
234
|
+
}
|
|
235
|
+
const expectedRevision = typeof record.expectedRevision === "number" ? record.expectedRevision : void 0;
|
|
236
|
+
try {
|
|
237
|
+
await settings.mutate(MCVISERON_SETTINGS_NAMESPACE, ops, expectedRevision);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (isSettingsConflict(error)) {
|
|
240
|
+
return json(res, 200, { ok: false, code: "settings-conflict", message: error instanceof Error ? error.message : "settings conflict" });
|
|
241
|
+
}
|
|
242
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
243
|
+
return json(res, 200, { ok: false, code: "settings-rejected", message });
|
|
244
|
+
}
|
|
245
|
+
const descriptor = findView(settings);
|
|
246
|
+
if (descriptor === void 0) {
|
|
247
|
+
return json(res, 200, { ok: false, code: "internal", message: "mcviseron settings namespace was disposed" });
|
|
248
|
+
}
|
|
249
|
+
json(res, 200, { ok: true, value: toPluginView(descriptor) });
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return [describe, mutate];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/appearance/index.ts
|
|
256
|
+
var Config = z.object({
|
|
257
|
+
enabled: z.boolean().default(DEFAULT_SCHEDULE_CONFIG.enabled).volatile(),
|
|
258
|
+
lightStart: z.string().pattern(/^([01]\d|2[0-3]):[0-5]\d$/).default(DEFAULT_SCHEDULE_CONFIG.lightStart).volatile(),
|
|
259
|
+
lightEnd: z.string().pattern(/^([01]\d|2[0-3]):[0-5]\d$/).default(DEFAULT_SCHEDULE_CONFIG.lightEnd).volatile()
|
|
260
|
+
}).default({ ...DEFAULT_SCHEDULE_CONFIG });
|
|
261
|
+
var DIAGNOSTICS_PATH = "/api/dsh-mcviseron/diagnostics";
|
|
262
|
+
var inject = ["webServer"];
|
|
263
|
+
function apply(ctx, _config) {
|
|
264
|
+
ctx.effect(() => ctx.webServer.register({
|
|
265
|
+
kind: "exact",
|
|
266
|
+
path: DIAGNOSTICS_PATH,
|
|
267
|
+
handler: async (req, res) => {
|
|
268
|
+
try {
|
|
269
|
+
if (req.method !== "GET" && req.method !== "POST") return json(res, 405, { ok: false, error: "method-not-allowed" });
|
|
270
|
+
if (!isLoopbackRequest(req)) return json(res, 403, { ok: false, error: "forbidden" });
|
|
271
|
+
const modules = ctx.get?.("clientModules");
|
|
272
|
+
const graph = typeof modules?.graph === "function" ? modules.graph() : void 0;
|
|
273
|
+
const batches = Array.isArray(graph?.batches) ? graph.batches : [];
|
|
274
|
+
const rows = [];
|
|
275
|
+
const batchSummary = [];
|
|
276
|
+
for (const batch of batches) {
|
|
277
|
+
const entries = batch?.descriptor?.entries ?? batch?.entries ?? [];
|
|
278
|
+
batchSummary.push({ phase: batch?.descriptor?.phase, count: entries.length });
|
|
279
|
+
for (const row of entries) rows.push(row);
|
|
280
|
+
}
|
|
281
|
+
const mcviseronRows = rows.filter((row) => JSON.stringify(row).includes("mcviseron"));
|
|
282
|
+
const loaderEntries = [];
|
|
283
|
+
const loader = ctx.loader;
|
|
284
|
+
for (const entry of loader?.entries?.() ?? []) {
|
|
285
|
+
if (String(entry.options?.name ?? "").includes("mcviseron")) {
|
|
286
|
+
loaderEntries.push({ name: entry.options?.name, disabled: Boolean(entry.disabled), fiber: Boolean(entry.fiber) });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
json(res, 200, {
|
|
290
|
+
ok: true,
|
|
291
|
+
clientPath: modules?.clientPath?.("dsh-mcviseron-plugin") ?? null,
|
|
292
|
+
graphKeys: graph !== void 0 ? Object.keys(graph) : null,
|
|
293
|
+
batches: batchSummary,
|
|
294
|
+
mcviseronRows,
|
|
295
|
+
loaderEntries,
|
|
296
|
+
release: modules?.release ?? null
|
|
297
|
+
});
|
|
298
|
+
} catch (error) {
|
|
299
|
+
json(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}), "mcviseron-appearance: client diagnostics");
|
|
303
|
+
ctx.inject(["settings"], (sctx) => {
|
|
304
|
+
const settings = sctx.settings;
|
|
305
|
+
if (typeof settings.configure === "function") {
|
|
306
|
+
ctx.effect(() => settings.configure({ auto: false }), "mcviseron-appearance: settings page policy");
|
|
307
|
+
}
|
|
308
|
+
sctx.effect(() => {
|
|
309
|
+
const disposers = makeSettingsRoutes(settings).map((route) => ctx.webServer.register(route));
|
|
310
|
+
return () => {
|
|
311
|
+
for (const dispose of disposers) dispose();
|
|
312
|
+
};
|
|
313
|
+
}, "mcviseron-appearance: settings bridge");
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
export {
|
|
317
|
+
Config,
|
|
318
|
+
apply,
|
|
319
|
+
inject
|
|
320
|
+
};
|