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
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
2
|
import type { McviseronKey } from './locales.ts'
|
|
3
|
+
import { ARCHIVE_API } from '../api.ts'
|
|
3
4
|
import { AUTO_REVIEW_FIELDS, ConfigForm, SESSION_END_FIELDS, TASK_GUARD_FIELDS } from './ConfigForm.tsx'
|
|
4
5
|
import { RestartCard } from './RestartCard.tsx'
|
|
5
6
|
import { pageStyles } from './styles.ts'
|
|
6
7
|
|
|
7
|
-
type Tab = 'restart' | 'autoReview' | 'taskGuard' | 'sessionEnd' | 'components'
|
|
8
|
+
type Tab = 'restart' | 'autoReview' | 'taskGuard' | 'sessionEnd' | 'archive' | 'components'
|
|
9
|
+
|
|
10
|
+
interface ArchiveStatus {
|
|
11
|
+
available: boolean
|
|
12
|
+
ledgerPath: string
|
|
13
|
+
ledgerExists: boolean
|
|
14
|
+
entries: number
|
|
15
|
+
observed: number
|
|
16
|
+
manual: number
|
|
17
|
+
archivedCount: number
|
|
18
|
+
unknownCount: number
|
|
19
|
+
}
|
|
8
20
|
|
|
9
21
|
/** Props composed by the `settings.section` slot. */
|
|
10
22
|
export interface SettingsSectionProps {
|
|
@@ -19,6 +31,31 @@ export interface SettingsSectionProps {
|
|
|
19
31
|
*/
|
|
20
32
|
export function SettingsSection({ t }: SettingsSectionProps) {
|
|
21
33
|
const [tab, setTab] = useState<Tab>('restart')
|
|
34
|
+
const [archive, setArchive] = useState<ArchiveStatus | null>(null)
|
|
35
|
+
|
|
36
|
+
const loadArchive = async (): Promise<void> => {
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(ARCHIVE_API.status, { credentials: 'same-origin', cache: 'no-store' })
|
|
39
|
+
if (!response.ok) { setArchive(null); return }
|
|
40
|
+
const value = await response.json() as ArchiveStatus
|
|
41
|
+
if (value.available) {
|
|
42
|
+
try {
|
|
43
|
+
const inventoryResponse = await fetch('/api/dsh-session-archive/inventory', { credentials: 'same-origin', cache: 'no-store' })
|
|
44
|
+
if (inventoryResponse.ok) {
|
|
45
|
+
const inventory = await inventoryResponse.json() as { rows?: Array<{ archived?: boolean; archivedAt?: number }> }
|
|
46
|
+
const rows = Array.isArray(inventory.rows) ? inventory.rows : []
|
|
47
|
+
value.archivedCount = rows.filter(row => row.archived === true).length
|
|
48
|
+
value.unknownCount = rows.filter(row => row.archived === true && row.archivedAt === undefined).length
|
|
49
|
+
}
|
|
50
|
+
} catch { /* keep host counts */ }
|
|
51
|
+
}
|
|
52
|
+
setArchive(value.available ? value : null)
|
|
53
|
+
} catch {
|
|
54
|
+
setArchive(null)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
useEffect(() => { void loadArchive() }, [])
|
|
22
59
|
|
|
23
60
|
return (
|
|
24
61
|
<div style={pageStyles.page}>
|
|
@@ -61,6 +98,19 @@ export function SettingsSection({ t }: SettingsSectionProps) {
|
|
|
61
98
|
>
|
|
62
99
|
{t('page.tab.sessionEnd')}
|
|
63
100
|
</button>
|
|
101
|
+
{archive?.available
|
|
102
|
+
? (
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
role="tab"
|
|
106
|
+
aria-selected={tab === 'archive'}
|
|
107
|
+
onClick={() => { setTab('archive') }}
|
|
108
|
+
style={tab === 'archive' ? { ...pageStyles.tab, ...pageStyles.tabActive } : pageStyles.tab}
|
|
109
|
+
>
|
|
110
|
+
{t('page.tab.archive')}
|
|
111
|
+
</button>
|
|
112
|
+
)
|
|
113
|
+
: null}
|
|
64
114
|
<button
|
|
65
115
|
type="button"
|
|
66
116
|
role="tab"
|
|
@@ -101,7 +151,38 @@ export function SettingsSection({ t }: SettingsSectionProps) {
|
|
|
101
151
|
fields={SESSION_END_FIELDS}
|
|
102
152
|
/>
|
|
103
153
|
)
|
|
104
|
-
:
|
|
154
|
+
: tab === 'archive' && archive?.available
|
|
155
|
+
? (
|
|
156
|
+
<div style={pageStyles.card}>
|
|
157
|
+
<div style={pageStyles.cardTitle}>{t('page.archive.title')}</div>
|
|
158
|
+
<div style={pageStyles.componentRow}>
|
|
159
|
+
<span style={pageStyles.componentName}>{t('page.archive.available')}</span>
|
|
160
|
+
<span style={pageStyles.componentHint}>{archive.ledgerExists ? t('page.archive.ledger') : archive.ledgerPath}</span>
|
|
161
|
+
</div>
|
|
162
|
+
<div style={pageStyles.componentRow}>
|
|
163
|
+
<span style={pageStyles.componentName}>{t('page.archive.archived')}</span>
|
|
164
|
+
<span style={pageStyles.componentHint}>{archive.archivedCount}</span>
|
|
165
|
+
</div>
|
|
166
|
+
<div style={pageStyles.componentRow}>
|
|
167
|
+
<span style={pageStyles.componentName}>{t('page.archive.observed')}</span>
|
|
168
|
+
<span style={pageStyles.componentHint}>{archive.observed}</span>
|
|
169
|
+
</div>
|
|
170
|
+
<div style={pageStyles.componentRow}>
|
|
171
|
+
<span style={pageStyles.componentName}>{t('page.archive.manual')}</span>
|
|
172
|
+
<span style={pageStyles.componentHint}>{archive.manual}</span>
|
|
173
|
+
</div>
|
|
174
|
+
<div style={pageStyles.componentRow}>
|
|
175
|
+
<span style={pageStyles.componentName}>{t('page.archive.unknown')}</span>
|
|
176
|
+
<span style={pageStyles.componentHint}>{archive.unknownCount}</span>
|
|
177
|
+
</div>
|
|
178
|
+
<div style={pageStyles.componentRow}>
|
|
179
|
+
<span style={pageStyles.componentName}>{t('page.archive.ledger')}</span>
|
|
180
|
+
<span style={pageStyles.componentHint}>{archive.ledgerPath}</span>
|
|
181
|
+
</div>
|
|
182
|
+
<button type="button" onClick={() => { void loadArchive() }} style={pageStyles.tab}>{t('page.archive.refresh')}</button>
|
|
183
|
+
</div>
|
|
184
|
+
)
|
|
185
|
+
: (
|
|
105
186
|
<div style={pageStyles.card}>
|
|
106
187
|
<div style={pageStyles.cardTitle}>{t('page.components.title')}</div>
|
|
107
188
|
<div style={pageStyles.componentRow}>
|
|
@@ -128,6 +209,14 @@ export function SettingsSection({ t }: SettingsSectionProps) {
|
|
|
128
209
|
<span style={pageStyles.componentName}>{t('page.components.sessionEnd')}</span>
|
|
129
210
|
<span style={pageStyles.componentHint}>{t('page.components.sessionEndHint')}</span>
|
|
130
211
|
</div>
|
|
212
|
+
{archive?.available
|
|
213
|
+
? (
|
|
214
|
+
<div style={pageStyles.componentRow}>
|
|
215
|
+
<span style={pageStyles.componentName}>{t('page.components.archive')}</span>
|
|
216
|
+
<span style={pageStyles.componentHint}>{t('page.components.archiveHint')}</span>
|
|
217
|
+
</div>
|
|
218
|
+
)
|
|
219
|
+
: null}
|
|
131
220
|
<div style={pageStyles.cardStatus}>{t('page.components.note')}</div>
|
|
132
221
|
</div>
|
|
133
222
|
)}
|
package/src/client/locales.ts
CHANGED
|
@@ -38,12 +38,17 @@ export const zh = {
|
|
|
38
38
|
|
|
39
39
|
'page.title': 'MCviseron 插件',
|
|
40
40
|
'page.description': '总插件的组件设置。外观设置仍在「通用 → 外观」中。',
|
|
41
|
-
'page.tab.restart': '重启',
|
|
41
|
+
'page.tab.restart': '重启 / 关闭',
|
|
42
42
|
'page.tab.components': '组件',
|
|
43
|
-
'page.restart.title': '重启 DeepSeek Harness',
|
|
44
|
-
'page.restart.description': '
|
|
43
|
+
'page.restart.title': '重启 / 关闭 DeepSeek Harness',
|
|
44
|
+
'page.restart.description': '重启或关闭当前 DSH(桌面应用、Linux/Web 进程或云托管容器);正在运行的任务会被中断',
|
|
45
45
|
'page.restart.ready': '可用',
|
|
46
|
-
'page.restart.
|
|
46
|
+
'page.restart.modeProcess': 'Linux/Web 进程:将重新拉起当前 dsh 命令',
|
|
47
|
+
'page.restart.modeSupervisor': '由 systemd / Docker / Kubernetes 托管:退出后由托管器重启',
|
|
48
|
+
'page.restart.close': '关闭 DSH',
|
|
49
|
+
'page.restart.closing': '正在关闭…',
|
|
50
|
+
'page.restart.closeConfirm': '确定要关闭 DSH 吗?重启/关闭动作会中断正在运行的任务。',
|
|
51
|
+
'page.restart.unavailable': '当前环境没有可用的重启目标',
|
|
47
52
|
'page.restart.routeMissing': '重启接口未加载:请确认 mcviseron-restart 条目已启用',
|
|
48
53
|
'page.restart.appPath': '应用路径',
|
|
49
54
|
'page.restart.button': '重启',
|
|
@@ -57,8 +62,8 @@ export const zh = {
|
|
|
57
62
|
'page.components.autoReviewFixHint': '本页「Auto review 修复」子页',
|
|
58
63
|
'page.components.taskGuard': 'Todo 计划守卫',
|
|
59
64
|
'page.components.taskGuardHint': '本页「Todo 守卫」子页',
|
|
60
|
-
'page.components.restart': '重启
|
|
61
|
-
'page.components.restartHint': '
|
|
65
|
+
'page.components.restart': '重启 / 关闭 DSH',
|
|
66
|
+
'page.components.restartHint': '本页「重启 / 关闭」子页',
|
|
62
67
|
'page.components.note': '组件配置写入 master 条目(mcviseron)的 Config;若组件仍使用旧值,重启 DSH 后生效。',
|
|
63
68
|
'page.fallback.note': '设置分区未加载,重启入口暂时回退到通用设置。',
|
|
64
69
|
'page.tab.autoReview': 'Auto review 修复',
|
|
@@ -111,12 +116,26 @@ export const zh = {
|
|
|
111
116
|
'form.taskGuard.exclude': '不统计这些工具',
|
|
112
117
|
'form.taskGuard.listHint': '逗号分隔,支持 *;留空表示全部',
|
|
113
118
|
'page.tab.sessionEnd': '会话后动作',
|
|
119
|
+
'page.tab.archive': '归档时间',
|
|
120
|
+
'page.archive.title': '归档时间',
|
|
121
|
+
'page.archive.description': '第三方会话归档插件的归档时间状态。仅在检测到 @linxin666/dsh-session-archive 时显示,未安装时不会注册此页。',
|
|
122
|
+
'page.archive.available': '已检测到第三方归档插件',
|
|
123
|
+
'page.archive.ledger': '归档台账',
|
|
124
|
+
'page.archive.observed': '历史补记',
|
|
125
|
+
'page.archive.manual': '正常记录',
|
|
126
|
+
'page.archive.unknown': '未知归档时间',
|
|
127
|
+
'page.archive.archived': '已归档会话',
|
|
128
|
+
'page.archive.refresh': '刷新状态',
|
|
129
|
+
'page.archive.note': '历史未知归档在首次初始化时补记(补记);初始化后的新归档记录正常时间。自动删除仍由归档插件控制。',
|
|
130
|
+
|
|
114
131
|
'page.sessionEnd.title': '会话后动作',
|
|
115
132
|
'page.sessionEnd.description': '本轮最终回复完整显示后执行一次动作;重启会等待所有会话与后台任务结束,设置页的重启不受此约束。',
|
|
116
133
|
'page.components.authCookie': '认证 cookie 清理',
|
|
117
134
|
'page.components.authCookieHint': '自动运行,无设置',
|
|
118
135
|
'page.components.sessionEnd': '会话后动作',
|
|
119
136
|
'page.components.sessionEndHint': '输入框左侧的「会话后重启」下拉',
|
|
137
|
+
'page.components.archive': '归档时间(可选)',
|
|
138
|
+
'page.components.archiveHint': '检测到第三方归档插件时显示',
|
|
120
139
|
'form.sessionEnd.enabled': '启用会话后动作',
|
|
121
140
|
'form.sessionEnd.enabledHint': '在对话输入框显示「会话后重启」下拉,并允许 AI 设置',
|
|
122
141
|
'form.sessionEnd.grace': '最终回复显示等待(毫秒)',
|
|
@@ -169,12 +188,17 @@ export const en = {
|
|
|
169
188
|
|
|
170
189
|
'page.title': 'MCviseron plugin',
|
|
171
190
|
'page.description': 'Settings for the master plugin components. Appearance still lives under General → Appearance.',
|
|
172
|
-
'page.tab.restart': 'Restart',
|
|
191
|
+
'page.tab.restart': 'Restart / close',
|
|
173
192
|
'page.tab.components': 'Components',
|
|
174
|
-
'page.restart.title': 'Restart DeepSeek Harness',
|
|
175
|
-
'page.restart.description': '
|
|
193
|
+
'page.restart.title': 'Restart / close DeepSeek Harness',
|
|
194
|
+
'page.restart.description': 'Restart or close DSH (desktop app, Linux/Web process, or cloud container); running tasks are interrupted',
|
|
176
195
|
'page.restart.ready': 'Available',
|
|
177
|
-
'page.restart.
|
|
196
|
+
'page.restart.modeProcess': 'Linux/Web process: relaunch the current dsh command',
|
|
197
|
+
'page.restart.modeSupervisor': 'Managed by systemd / Docker / Kubernetes: exit and let the supervisor restart it',
|
|
198
|
+
'page.restart.close': 'Close DSH',
|
|
199
|
+
'page.restart.closing': 'Closing…',
|
|
200
|
+
'page.restart.closeConfirm': 'Close DSH? Restart/close interrupts running tasks.',
|
|
201
|
+
'page.restart.unavailable': 'No restart target is available in this environment',
|
|
178
202
|
'page.restart.routeMissing': 'The restart route is not loaded: check that the mcviseron-restart entry is enabled',
|
|
179
203
|
'page.restart.appPath': 'App path',
|
|
180
204
|
'page.restart.button': 'Restart',
|
|
@@ -188,8 +212,8 @@ export const en = {
|
|
|
188
212
|
'page.components.autoReviewFixHint': 'The Auto-review fix tab on this page',
|
|
189
213
|
'page.components.taskGuard': 'Todo plan guard',
|
|
190
214
|
'page.components.taskGuardHint': 'The Todo guard tab on this page',
|
|
191
|
-
'page.components.restart': 'Restart
|
|
192
|
-
'page.components.restartHint': 'The Restart tab on this page',
|
|
215
|
+
'page.components.restart': 'Restart / close DSH',
|
|
216
|
+
'page.components.restartHint': 'The Restart / close tab on this page',
|
|
193
217
|
'page.components.note': 'Component settings are written to the mcviseron entry config; restart DSH if a component still uses the old value.',
|
|
194
218
|
'page.fallback.note': 'The settings section is unavailable, so the restart entry falls back to General.',
|
|
195
219
|
'page.tab.autoReview': 'Auto-review fix',
|
|
@@ -242,12 +266,26 @@ export const en = {
|
|
|
242
266
|
'form.taskGuard.exclude': 'Exclude these tools',
|
|
243
267
|
'form.taskGuard.listHint': 'Comma-separated, * supported; empty means all',
|
|
244
268
|
'page.tab.sessionEnd': 'After-session action',
|
|
269
|
+
'page.tab.archive': 'Archive time',
|
|
270
|
+
'page.archive.title': 'Archive time',
|
|
271
|
+
'page.archive.description': 'Archive-time status of the third-party session archive plugin. Shown only when @linxin666/dsh-session-archive is detected; no page is registered when it is absent.',
|
|
272
|
+
'page.archive.available': 'Third-party archive plugin detected',
|
|
273
|
+
'page.archive.ledger': 'Archive ledger',
|
|
274
|
+
'page.archive.observed': 'Historical backfilled',
|
|
275
|
+
'page.archive.manual': 'Normal records',
|
|
276
|
+
'page.archive.unknown': 'Unknown archive times',
|
|
277
|
+
'page.archive.archived': 'Archived sessions',
|
|
278
|
+
'page.archive.refresh': 'Refresh status',
|
|
279
|
+
'page.archive.note': 'Historical unknown archives are backfilled on first initialization and marked (backfilled); new archives after initialization are recorded as normal times. Auto-delete remains controlled by the archive plugin.',
|
|
280
|
+
|
|
245
281
|
'page.sessionEnd.title': 'After-session action',
|
|
246
282
|
'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.',
|
|
247
283
|
'page.components.authCookie': 'Auth-cookie cleanup',
|
|
248
284
|
'page.components.authCookieHint': 'Runs automatically; no settings',
|
|
249
285
|
'page.components.sessionEnd': 'After-session action',
|
|
250
286
|
'page.components.sessionEndHint': 'The “Restart after session” dropdown left of the composer',
|
|
287
|
+
'page.components.archive': 'Archive time (optional)',
|
|
288
|
+
'page.components.archiveHint': 'Shown only when the third-party archive plugin is detected',
|
|
251
289
|
'form.sessionEnd.enabled': 'Enable after-session actions',
|
|
252
290
|
'form.sessionEnd.enabledHint': 'Show the “Restart after session” dropdown in the composer and let the AI arm it',
|
|
253
291
|
'form.sessionEnd.grace': 'Final-reply render grace (ms)',
|
|
@@ -91,8 +91,8 @@ export function normalizeConfig(config?: unknown): AutoReviewSettings {
|
|
|
91
91
|
model: stringSetting(source, 'translateModel', ''),
|
|
92
92
|
reviewContext: {
|
|
93
93
|
enabled: boolSetting(source, 'reviewContextGuard', true),
|
|
94
|
-
maxHistoryChars: numberSetting(source, 'reviewMaxHistoryChars',
|
|
95
|
-
keepRecentEntries: numberSetting(source, 'reviewKeepRecentEntries',
|
|
94
|
+
maxHistoryChars: numberSetting(source, 'reviewMaxHistoryChars', 200000, 20000, 600000),
|
|
95
|
+
keepRecentEntries: numberSetting(source, 'reviewKeepRecentEntries', 32, 4, 64),
|
|
96
96
|
},
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -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,
|