dsh-mcviseron-plugin 0.7.2 → 0.7.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 +71 -0
- package/README.en.md +12 -8
- package/README.md +16 -12
- package/docs/archive-integration.md +29 -0
- package/docs/auto-review-context.md +25 -24
- package/docs/automation-task.md +1 -1
- package/docs/release.md +2 -2
- package/lib/auto-review-fix.js +135 -6
- package/lib/client.js +105 -1
- package/lib/index.js +327 -65
- 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 +59 -14
- package/src/client/SettingsSection.tsx +92 -3
- package/src/client/locales.ts +28 -0
- 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
|
@@ -54,7 +54,7 @@ function textOf(message: unknown): string | undefined {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/** Detect the exact one-message request shape Auto review sends to llm.stream. */
|
|
57
|
-
export function
|
|
57
|
+
export function isLegacyAutoReviewRequest(options: unknown): options is ReviewOptions {
|
|
58
58
|
if (!record(options)) return false
|
|
59
59
|
const system = options.system
|
|
60
60
|
if (typeof system !== 'string' || !system.includes(REVIEW_MARKER) || !system.includes(REVIEW_MARKER_2)) return false
|
|
@@ -173,7 +173,9 @@ function logTrim(originalChars: number, nextChars: number, originalEntries: numb
|
|
|
173
173
|
* byte-for-byte unchanged.
|
|
174
174
|
*/
|
|
175
175
|
export function trimReviewRequest<T extends ReviewOptions>(options: T, settings: ReviewContextSettings): T {
|
|
176
|
-
if (!settings.enabled
|
|
176
|
+
if (!settings.enabled) return options
|
|
177
|
+
if (isModernAutoReviewRequest(options)) return trimModernReviewRequest(options, settings)
|
|
178
|
+
if (!isLegacyAutoReviewRequest(options)) return options
|
|
177
179
|
const messages = options.messages as ReviewMessage[]
|
|
178
180
|
const message = messages[0]
|
|
179
181
|
const text = textOf(message)
|
|
@@ -209,6 +211,146 @@ export function trimReviewRequest<T extends ReviewOptions>(options: T, settings:
|
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
const MODERN_PURPOSE = 'auto-review'
|
|
215
|
+
const ENVIRONMENT_HEADER = 'ENVIRONMENT\n'
|
|
216
|
+
const MODERN_USER_ROLES = new Set(['user-instruction', 'direct-parent-instruction', 'constraint', 'checkpoint', 'human-instruction'])
|
|
217
|
+
const MODERN_USER_TEXT_CHARS = 8_000
|
|
218
|
+
const MODERN_TOOL_ARGUMENT_CHARS = 4_000
|
|
219
|
+
const MODERN_SCHEMA_DESCRIPTION_CHARS = 4_000
|
|
220
|
+
const MODERN_SCHEMA_PARAMETER_CHARS = 12_000
|
|
221
|
+
|
|
222
|
+
/** Detect the 0.2.2 review request: purpose auto-review, one message per retained item. */
|
|
223
|
+
export function isModernAutoReviewRequest(options: unknown): options is ReviewOptions & { purpose: 'auto-review' } {
|
|
224
|
+
if (!record(options) || options.purpose !== MODERN_PURPOSE) return false
|
|
225
|
+
if (typeof options.system !== 'string' || !options.system.includes(REVIEW_MARKER) || !options.system.includes(REVIEW_MARKER_2)) return false
|
|
226
|
+
if (!Array.isArray(options.messages) || options.messages.length < 2) return false
|
|
227
|
+
const first = textOf(options.messages[0])
|
|
228
|
+
return first !== undefined && first.startsWith(ENVIRONMENT_HEADER)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Detect either the 0.2.2 request or the older FILTERED_HISTORY request. */
|
|
232
|
+
export function isAutoReviewRequest(options: unknown): options is ReviewOptions {
|
|
233
|
+
return isModernAutoReviewRequest(options) || isLegacyAutoReviewRequest(options)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function modernRole(entry: unknown): string | undefined {
|
|
237
|
+
return record(entry) && typeof entry.role === 'string' ? entry.role : undefined
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function modernProtected(entry: unknown, index: number, lastIndex: number, schemaIndexes: ReadonlySet<number>): boolean {
|
|
241
|
+
if (index === lastIndex) return true
|
|
242
|
+
const role = modernRole(entry)
|
|
243
|
+
if (role !== undefined && MODERN_USER_ROLES.has(role)) return true
|
|
244
|
+
return schemaIndexes.has(index)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function compactModernContent(content: unknown, textLimit: number): unknown[] {
|
|
248
|
+
if (!Array.isArray(content)) return []
|
|
249
|
+
return content.map((block) => {
|
|
250
|
+
if (!record(block)) return { type: 'text', text: '[non-text history block omitted from reviewer context]' }
|
|
251
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
252
|
+
return { ...block, text: truncateText(block.text, textLimit) }
|
|
253
|
+
}
|
|
254
|
+
return { type: 'text', text: '[' + String(block.type ?? 'attachment') + ' omitted from reviewer context]' }
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function compactModernEntry(entry: unknown, pending: boolean): unknown {
|
|
259
|
+
if (!record(entry)) return { kind: 'summary', role: 'fact', content: [{ type: 'text', text: '[invalid history entry omitted]' }] }
|
|
260
|
+
if (pending) return entry
|
|
261
|
+
if (entry.kind === 'user-message') {
|
|
262
|
+
return { ...entry, content: compactModernContent(entry.content, MODERN_USER_TEXT_CHARS) }
|
|
263
|
+
}
|
|
264
|
+
if (entry.kind === 'tool-call') {
|
|
265
|
+
if (typeof entry.arguments === 'string') {
|
|
266
|
+
return { ...entry, arguments: truncateText(entry.arguments, MODERN_TOOL_ARGUMENT_CHARS) }
|
|
267
|
+
}
|
|
268
|
+
if (entry.arguments !== undefined) {
|
|
269
|
+
let rendered = ''
|
|
270
|
+
try { rendered = JSON.stringify(entry.arguments) ?? '' } catch { rendered = '' }
|
|
271
|
+
return { ...entry, arguments: truncateText(rendered, MODERN_TOOL_ARGUMENT_CHARS) }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (entry.kind === 'tool-schema') {
|
|
275
|
+
const description = typeof entry.description === 'string'
|
|
276
|
+
? truncateText(entry.description, MODERN_SCHEMA_DESCRIPTION_CHARS)
|
|
277
|
+
: entry.description
|
|
278
|
+
let parameters = entry.parameters
|
|
279
|
+
if (parameters !== undefined) {
|
|
280
|
+
try {
|
|
281
|
+
const rendered = JSON.stringify(parameters) ?? ''
|
|
282
|
+
if (rendered.length > MODERN_SCHEMA_PARAMETER_CHARS) parameters = truncateText(rendered, MODERN_SCHEMA_PARAMETER_CHARS)
|
|
283
|
+
} catch { parameters = '[unserializable schema parameters omitted]' }
|
|
284
|
+
}
|
|
285
|
+
return { ...entry, description, parameters }
|
|
286
|
+
}
|
|
287
|
+
return entry
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function modernSchemaIndexes(entries: unknown[]): Set<number> {
|
|
291
|
+
const indexes = new Map<string, number>()
|
|
292
|
+
entries.forEach((entry, index) => {
|
|
293
|
+
if (!record(entry) || entry.kind !== 'tool-schema') return
|
|
294
|
+
indexes.set(String(entry.mode) + '\0' + String(entry.name), index)
|
|
295
|
+
})
|
|
296
|
+
return new Set(indexes.values())
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Trim the 0.2.2 review request. The environment and pending action stay
|
|
301
|
+
* byte-identical; instruction entries and the latest schema per tool survive;
|
|
302
|
+
* recent entries and a bounded number of older facts are retained.
|
|
303
|
+
*/
|
|
304
|
+
export function trimModernReviewRequest<T extends ReviewOptions>(options: T, settings: ReviewContextSettings): T {
|
|
305
|
+
const messages = options.messages as ReviewMessage[]
|
|
306
|
+
const first = textOf(messages[0])
|
|
307
|
+
if (first === undefined || !first.startsWith(ENVIRONMENT_HEADER)) return options
|
|
308
|
+
const entries: unknown[] = []
|
|
309
|
+
for (const message of messages.slice(1)) {
|
|
310
|
+
const text = textOf(message)
|
|
311
|
+
if (text === undefined) return options
|
|
312
|
+
try { entries.push(JSON.parse(text)) } catch { return options }
|
|
313
|
+
}
|
|
314
|
+
if (entries.length === 0) return options
|
|
315
|
+
const lastIndex = entries.length - 1
|
|
316
|
+
const schemaIndexes = modernSchemaIndexes(entries)
|
|
317
|
+
const recentStart = Math.max(0, entries.length - Math.max(1, settings.keepRecentEntries))
|
|
318
|
+
const selected: number[] = []
|
|
319
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
320
|
+
if (index >= recentStart || modernProtected(entries[index], index, lastIndex, schemaIndexes)) selected.push(index)
|
|
321
|
+
}
|
|
322
|
+
let omitted = entries.length - selected.length
|
|
323
|
+
const compacted = selected.map(index => compactModernEntry(entries[index], index === lastIndex))
|
|
324
|
+
while (selected.length > 2 && jsonLength(compacted) > settings.maxHistoryChars) {
|
|
325
|
+
let at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1 && !modernProtected(entries[index], index, lastIndex, schemaIndexes))
|
|
326
|
+
if (at < 0) at = selected.findIndex((index, position) => index !== lastIndex && position < selected.length - 1)
|
|
327
|
+
if (at < 0) break
|
|
328
|
+
selected.splice(at, 1)
|
|
329
|
+
compacted.splice(at, 1)
|
|
330
|
+
omitted += 1
|
|
331
|
+
}
|
|
332
|
+
const summary = {
|
|
333
|
+
kind: 'summary',
|
|
334
|
+
role: 'fact',
|
|
335
|
+
content: [{
|
|
336
|
+
type: 'text',
|
|
337
|
+
text: '[auto-review-fix] ' + String(omitted)
|
|
338
|
+
+ ' earlier history entries omitted from the reviewer context (original history '
|
|
339
|
+
+ String(jsonLength(entries)) + ' chars). Current action, instructions and recent context are retained.',
|
|
340
|
+
}],
|
|
341
|
+
}
|
|
342
|
+
const nextMessages: ReviewMessage[] = [messages[0]]
|
|
343
|
+
if (omitted > 0) nextMessages.push({ role: 'user', content: [{ type: 'text', text: JSON.stringify(summary) }] })
|
|
344
|
+
selected.forEach((originalIndex, position) => {
|
|
345
|
+
const original = messages[originalIndex + 1]
|
|
346
|
+
if (originalIndex === lastIndex) nextMessages.push(original)
|
|
347
|
+
else nextMessages.push({ ...original, content: [{ type: 'text', text: JSON.stringify(compacted[position]) }] })
|
|
348
|
+
})
|
|
349
|
+
if (jsonLength(nextMessages) >= jsonLength(messages)) return options
|
|
350
|
+
logTrim(jsonLength(messages), jsonLength(nextMessages), entries.length, selected.length)
|
|
351
|
+
return { ...options, messages: nextMessages }
|
|
352
|
+
}
|
|
353
|
+
|
|
212
354
|
const guardedLlms = new WeakMap<object, { settings: ReviewContextSettings }>()
|
|
213
355
|
|
|
214
356
|
function whenService(ctx: Context, name: string, run: (scope: Context) => void): void {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis'
|
|
2
2
|
import z from '@deepseek-ai/schemastery'
|
|
3
3
|
import * as appearance from './appearance/index.ts'
|
|
4
|
+
import * as archiveIntegration from './archive-integration/index.ts'
|
|
4
5
|
import * as authCookie from './auth-cookie/index.ts'
|
|
5
6
|
import * as automationTasks from './automation-tasks/index.ts'
|
|
6
7
|
import * as autoReviewFix from './auto-review-fix/index.ts'
|
|
@@ -68,6 +69,7 @@ function mount(ctx: Context, component: unknown, config: unknown): void {
|
|
|
68
69
|
export function apply(ctx: Context, rawConfig?: MasterConfig): void {
|
|
69
70
|
const config = (toPlain(rawConfig) ?? {}) as MasterConfig
|
|
70
71
|
mount(ctx, automationTasks, {})
|
|
72
|
+
mount(ctx, archiveIntegration, {})
|
|
71
73
|
mount(ctx, authCookie, {})
|
|
72
74
|
mount(ctx, appearance, {
|
|
73
75
|
enabled: config.enabled ?? DEFAULT_SCHEDULE_CONFIG.enabled,
|