dsh-vscode-mode 0.35.0 → 0.36.0
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/README.md +16 -5
- package/lib/client.js +63 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +1388 -54
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/capture.ts +3 -0
- package/src/client/reviewBatch.ts +8 -0
- package/src/client/state/diffSummary.ts +6 -1
- package/src/client/state/reviewFeed.ts +35 -4
- package/src/client/ui/EditorView.ts +7 -0
- package/src/client/ui/McpSettings.ts +21 -0
- package/src/client/ui/OfficialReview.ts +20 -2
- package/src/fileOpenSettings.ts +29 -0
- package/src/index.ts +74 -6
- package/src/mcpManaged.ts +12 -3
- package/src/mcpManagerBridge.ts +5 -1
- package/src/mcpRuntime.ts +33 -4
- package/src/pending/capture.ts +32 -4
- package/src/pending/decide.ts +12 -3
- package/src/pending/externalAlign.ts +297 -0
- package/src/pending/externalCapture.ts +581 -0
- package/src/pending/kernel.ts +19 -1
- package/src/pending/persist.ts +114 -12
- package/src/pending/provenance.ts +239 -0
- package/src/pending/store.ts +30 -4
- package/src/pending/vcs.ts +122 -0
- package/src/pendingCompat.ts +13 -6
- package/src/pendingRpc.ts +19 -2
- package/src/rpc.ts +7 -2
- package/src/shared/pendingReview.ts +19 -1
- package/src/shared/review.ts +3 -1
- package/src/shared/rpc.ts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-vscode-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "DSH 上的类 VSCode 编码体验:Monaco 编辑器(文件页签/QuickOpen/状态栏,可驻 DSH 0.1.5+ 官方右侧 Sidebar 与对话同屏)+ 命令栏(Ctrl+Shift+P)与可扩展指令系统 + VS Code 兼容代码片段(.code-snippets 全局/项目,IntelliSense 展开)+ Agent 编辑差异审查(整文件差异/采纳/拒绝/归档/回滚)+ SVN 集成(侧栏变更面板/日志弹窗/并排差异)+ 语言服务器(LSP)智能(跳转定义/引用/hover/大纲 + VSIX 扩展市场安装),状态持久化到工作区旁车,界面状态(页签/光标/侧栏/编辑 Tab/导航历史)镜像到 DSH home 跨重启恢复",
|
|
5
5
|
"icon": "assets/icon.svg",
|
|
6
6
|
"keywords": [
|
package/src/capture.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { Registry } from './registry.js'
|
|
|
19
19
|
import { cwdOfSession } from './registry.js'
|
|
20
20
|
import { findRemoteWs, mirrorTargetOf } from './remoteWorkspace.js'
|
|
21
21
|
import { invalidateIndex } from './treeIndex.js'
|
|
22
|
+
import { pathKeyOf, windows } from './pending/provenance.js'
|
|
22
23
|
import { log } from './log.js'
|
|
23
24
|
|
|
24
25
|
/** 捕获所需的工具执行最小形状(DSH ToolExecution 的结构子集)。 */
|
|
@@ -154,6 +155,8 @@ async function syncMirrorFile(absPath: string, content: string): Promise<string
|
|
|
154
155
|
try {
|
|
155
156
|
await mkdir(dirname(absPath), { recursive: true })
|
|
156
157
|
await writeFile(absPath, content, 'utf8')
|
|
158
|
+
// 镜像写穿是本插件自己的写盘:打标记让 watch 采集别把它记成外部改动
|
|
159
|
+
windows.markSelf(pathKeyOf(absPath))
|
|
157
160
|
return null
|
|
158
161
|
} catch (error) {
|
|
159
162
|
return String(error)
|
|
@@ -8,6 +8,8 @@ export interface BatchPort {
|
|
|
8
8
|
decide: (detail: ReviewDetail, reject: boolean, operationId: string) => Promise<ReviewResult<{ revision: number }>>
|
|
9
9
|
guard: () => void
|
|
10
10
|
operation: (detail: ReviewDetail, reject: boolean) => string
|
|
11
|
+
/** 撤销里含非 agent 来源时的整批确认;缺省视为不允许(严格口径)。 */
|
|
12
|
+
confirmExternal?: (details: ReviewDetail[]) => boolean
|
|
11
13
|
}
|
|
12
14
|
export interface BatchResult { completed: number; total: number; paths: string[]; error: string }
|
|
13
15
|
|
|
@@ -59,6 +61,12 @@ export async function runReviewBatch(port: BatchPort, reject: boolean): Promise<
|
|
|
59
61
|
if (reject && !detail.capability.undo) throw new Error(`${item.display}:${detail.capability.reason}`)
|
|
60
62
|
details.push(detail)
|
|
61
63
|
}
|
|
64
|
+
// 非 agent 来源(编辑器保存 / 版本库基线 / 外部写入)先问一次,避免整批撤销误伤用户代码
|
|
65
|
+
if (reject && details.some((detail) => detail.capability.confirmUndo)) {
|
|
66
|
+
if (!port.confirmExternal || !port.confirmExternal(details.filter((detail) => detail.capability.confirmUndo))) {
|
|
67
|
+
throw new Error('已取消:这批修改里有非本会话工具写入的来源,撤销前需要确认')
|
|
68
|
+
}
|
|
69
|
+
}
|
|
62
70
|
// Reverse chronological snapshots allow a newer round's result to expose the previous round's endpoint.
|
|
63
71
|
details.sort((left, right) => right.capturedAt.localeCompare(left.capturedAt) || right.item.seq - left.item.seq)
|
|
64
72
|
for (const detail of details) {
|
|
@@ -12,6 +12,8 @@ export interface DiffFile extends FileSummary {
|
|
|
12
12
|
added?: number
|
|
13
13
|
/** 待审行的删除行数。 */
|
|
14
14
|
deleted?: number
|
|
15
|
+
/** 待审行的来源徽标(如「watch · 外部」);官方与历史行为空。 */
|
|
16
|
+
sourceLabel?: string
|
|
15
17
|
}
|
|
16
18
|
export interface DiffSummary extends Summary { files: DiffFile[]; pendingFiles: DiffFile[] }
|
|
17
19
|
|
|
@@ -101,14 +103,17 @@ function pendingRowsOf(page: ReviewPage | null): { rows: DiffFile[]; covered: Se
|
|
|
101
103
|
for (const item of page?.items ?? []) {
|
|
102
104
|
if (!item.id.startsWith(PENDING_PREFIX)) continue
|
|
103
105
|
const path = item.currentPath || item.path
|
|
106
|
+
const label = item.display || path
|
|
104
107
|
rows.push({
|
|
105
108
|
path,
|
|
106
|
-
|
|
109
|
+
// 非 agent 来源才在标签上带徽标:agent 行保持原样,面板不被新增文案刷屏
|
|
110
|
+
label: item.sourceLabel && !item.sourceLabel.endsWith('· agent') ? `${label} · ${item.sourceLabel}` : label,
|
|
107
111
|
recs: [],
|
|
108
112
|
pending: item.decision === 'pending' ? 1 : 0,
|
|
109
113
|
added: item.added,
|
|
110
114
|
deleted: item.deleted,
|
|
111
115
|
sourceKind: 'pending',
|
|
116
|
+
sourceLabel: item.sourceLabel,
|
|
112
117
|
})
|
|
113
118
|
}
|
|
114
119
|
return { rows, covered: pendingCoverKeys(page) }
|
|
@@ -4,8 +4,12 @@ import type { ReviewPage } from '../../shared/review.js'
|
|
|
4
4
|
|
|
5
5
|
export interface ReviewFeed { page: ReviewPage | null; error: string }
|
|
6
6
|
type Listener = (feed: ReviewFeed) => void
|
|
7
|
-
interface Entry { listeners: Set<Listener>; value: ReviewFeed; controller: AbortController; timer?: ReturnType<typeof setTimeout>; loading: boolean; again: boolean; onRefresh: () => void; onVisible?: () => void }
|
|
7
|
+
interface Entry { listeners: Set<Listener>; value: ReviewFeed; controller: AbortController; timer?: ReturnType<typeof setTimeout>; loading: boolean; again: boolean; onRefresh: () => void; onVisible?: () => void; version: number; versionTimer?: ReturnType<typeof setInterval> }
|
|
8
8
|
const feeds = new Map<string, Entry>()
|
|
9
|
+
/** 列表轮询间隔:版本号没变时不重读列表。 */
|
|
10
|
+
const POLL_MS = 5000
|
|
11
|
+
/** 待审版本号轮询间隔:只读 Host 内存计数,用来把「新记录出现」的延迟压到 1s 量级。 */
|
|
12
|
+
const VERSION_POLL_MS = 1000
|
|
9
13
|
|
|
10
14
|
/** @private @author ddj 2026年10月26号 @param entry Shared feed. Notify mounted observers only. */
|
|
11
15
|
function notify(entry: Entry): void { for (const listener of entry.listeners) listener(entry.value) }
|
|
@@ -33,18 +37,44 @@ async function refresh(sessionId: string, entry: Entry, force = false): Promise<
|
|
|
33
37
|
if (!force && JSON.stringify(previous) === JSON.stringify(entry.value)) entry.value = previous
|
|
34
38
|
else notify(entry)
|
|
35
39
|
if (entry.again) void refresh(sessionId, entry, true)
|
|
36
|
-
else entry.timer = setTimeout(() => { void refresh(sessionId, entry) },
|
|
40
|
+
else entry.timer = setTimeout(() => { void refresh(sessionId, entry) }, POLL_MS)
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @private
|
|
47
|
+
* @author ddj 2026年11月24号
|
|
48
|
+
* @description: 轮询待审版本号:只读 Host 内存计数,变号才触发整页重读。
|
|
49
|
+
* 这条通道把「agent 用 bash 改完文件」到「面板出现记录」的延迟从 5s 压到 1s 量级。
|
|
50
|
+
* @param sessionId 会话作用域
|
|
51
|
+
* @param entry 共享订阅
|
|
52
|
+
* @returns 无
|
|
53
|
+
*/
|
|
54
|
+
function pollVersion(sessionId: string, entry: Entry): void {
|
|
55
|
+
const controller = entry.controller
|
|
56
|
+
const tick = async (): Promise<void> => {
|
|
57
|
+
if (controller.signal.aborted || (typeof document !== 'undefined' && document.hidden)) return
|
|
58
|
+
try {
|
|
59
|
+
const result = await rpc('edrv.pending.version', { sessionId }, controller.signal)
|
|
60
|
+
if (controller.signal.aborted || !result.ok) return
|
|
61
|
+
if (entry.version === 0) { entry.version = result.version; return }
|
|
62
|
+
if (result.version === entry.version) return
|
|
63
|
+
entry.version = result.version
|
|
64
|
+
void refresh(sessionId, entry, true)
|
|
65
|
+
} catch { /* 版本探测失败不影响列表轮询 */ }
|
|
66
|
+
}
|
|
67
|
+
entry.versionTimer = setInterval(() => { void tick() }, VERSION_POLL_MS)
|
|
68
|
+
void tick()
|
|
69
|
+
}
|
|
70
|
+
|
|
41
71
|
/** @public @author ddj 2026年10月26号 @param sessionId Live scope. @param listener Mounted observer. @returns Cleanup cancelling requests and timers when unused. */
|
|
42
72
|
export function subscribeReview(sessionId: string, listener: Listener): () => void {
|
|
43
73
|
let entry = feeds.get(sessionId)
|
|
44
74
|
if (!entry) {
|
|
45
75
|
/** @private @author ddj 2026年10月26号 Refresh the shared official metadata after edits/decisions. */
|
|
46
76
|
const onRefresh = (): void => refreshReview(sessionId)
|
|
47
|
-
entry = { listeners: new Set(), value: { page: null, error: '' }, controller: new AbortController(), loading: false, again: false, onRefresh }
|
|
77
|
+
entry = { listeners: new Set(), value: { page: null, error: '' }, controller: new AbortController(), loading: false, again: false, onRefresh, version: 0 }
|
|
48
78
|
feeds.set(sessionId, entry)
|
|
49
79
|
if (typeof window !== 'undefined') window.addEventListener('edrv:refresh', onRefresh)
|
|
50
80
|
if (typeof document !== 'undefined') {
|
|
@@ -53,12 +83,13 @@ export function subscribeReview(sessionId: string, listener: Listener): () => vo
|
|
|
53
83
|
document.addEventListener('visibilitychange', entry.onVisible)
|
|
54
84
|
}
|
|
55
85
|
void refresh(sessionId, entry)
|
|
86
|
+
pollVersion(sessionId, entry)
|
|
56
87
|
}
|
|
57
88
|
entry.listeners.add(listener); listener(entry.value)
|
|
58
89
|
return () => {
|
|
59
90
|
entry.listeners.delete(listener)
|
|
60
91
|
if (entry.listeners.size || feeds.get(sessionId) !== entry) return
|
|
61
|
-
entry.controller.abort(); clearTimeout(entry.timer); feeds.delete(sessionId)
|
|
92
|
+
entry.controller.abort(); clearTimeout(entry.timer); clearInterval(entry.versionTimer); feeds.delete(sessionId)
|
|
62
93
|
if (typeof window !== 'undefined') window.removeEventListener('edrv:refresh', entry.onRefresh)
|
|
63
94
|
if (entry.onVisible && typeof document !== 'undefined') document.removeEventListener('visibilitychange', entry.onVisible)
|
|
64
95
|
}
|
|
@@ -3580,6 +3580,11 @@ export function EditorView(props) {
|
|
|
3580
3580
|
*/
|
|
3581
3581
|
async function submitOfficialDecision(detail, reject, blockId) {
|
|
3582
3582
|
const source = detail.item
|
|
3583
|
+
// 撤销白名单:非 agent 来源(编辑器保存 / 版本库基线 / 外部写入)先确认一次再写盘
|
|
3584
|
+
if (reject && detail.capability?.confirmUndo && !window.confirm(
|
|
3585
|
+
`「${source.display || source.path}」的改动来自 ${source.sourceLabel || '外部来源'},不是本会话工具写的。\n确认撤销并写回修改前内容?`)) {
|
|
3586
|
+
throw new Error('已取消撤销')
|
|
3587
|
+
}
|
|
3583
3588
|
const opKey = JSON.stringify([sessionId, source.id, source.seq, source.revision, blockId, reject])
|
|
3584
3589
|
let operationId = reviewOpsRef.current.get(opKey)
|
|
3585
3590
|
if (!operationId) { operationId = crypto.randomUUID(); reviewOpsRef.current.set(opKey, operationId) }
|
|
@@ -3844,6 +3849,8 @@ export function EditorView(props) {
|
|
|
3844
3849
|
snapshot: batchSnapshot,
|
|
3845
3850
|
detail: async (id) => { const res = await rpc('edrv.review.detail', { sessionId, id }); if (!res.ok) throw new Error(res.error); return res.detail },
|
|
3846
3851
|
decide: (detail, undo, operationId) => rpc('edrv.review.decide', { sessionId, id: detail.item.id, seq: detail.item.seq, revision: detail.item.revision, operationId, scope: 'file', decision: undo ? 'rejected' : 'accepted' }),
|
|
3852
|
+
confirmExternal: (details) => window.confirm(
|
|
3853
|
+
`这批修改里有 ${details.length} 条不是本会话工具写入的来源(例如编辑器保存、版本库基线或外部脚本)。\n确认整批撤销并写回修改前内容?`),
|
|
3847
3854
|
guard: () => guardReviewAll(true, token), operation: batchOperation,
|
|
3848
3855
|
}, true)
|
|
3849
3856
|
}
|
|
@@ -151,6 +151,8 @@ function GeneralSettings({ registry, getShortcuts }) {
|
|
|
151
151
|
const [nativeDraft, setNativeDraft] = React.useState(null) // 原生打开范围草稿(同上提交语义)
|
|
152
152
|
const [refIntakeOn, setRefIntakeOn] = React.useState(true) // 引用接入(拖拽/粘贴/复制 → 引用 chip)
|
|
153
153
|
const [searchReplaceOn, setSearchReplaceOn] = React.useState(true) // 搜索面板全局替换
|
|
154
|
+
const [extWatchOn, setExtWatchOn] = React.useState(true) // 外部改动实时捕获(watch)
|
|
155
|
+
const [extScanOn, setExtScanOn] = React.useState(true) // 外部改动补扫(启动对齐与定时)
|
|
154
156
|
const [kbMessage, setKbMessage] = React.useState('') // 打开官方快捷键弹窗的失败说明(空 = 未失败)
|
|
155
157
|
const settings = React.useContext(SettingsContext)
|
|
156
158
|
const snapshot = settings?.getSnapshot?.()
|
|
@@ -168,6 +170,8 @@ function GeneralSettings({ registry, getShortcuts }) {
|
|
|
168
170
|
setNativeSaved(typeof native === 'string' && native.trim() ? native : DEFAULT_NATIVE_CSV)
|
|
169
171
|
setRefIntakeOn(snap?.value?.refIntake !== false)
|
|
170
172
|
setSearchReplaceOn(snap?.value?.searchReplace !== false)
|
|
173
|
+
setExtWatchOn(snap?.value?.externalWatch !== false)
|
|
174
|
+
setExtScanOn(snap?.value?.externalScan !== false)
|
|
171
175
|
}
|
|
172
176
|
onChange()
|
|
173
177
|
return settings?.subscribe?.(onChange)
|
|
@@ -367,6 +371,23 @@ function GeneralSettings({ registry, getShortcuts }) {
|
|
|
367
371
|
})),
|
|
368
372
|
),
|
|
369
373
|
),
|
|
374
|
+
React.createElement('section', { className: 'vsm-panel' },
|
|
375
|
+
React.createElement('h3', { className: 'vsm-panel-title' }, '改动捕获'),
|
|
376
|
+
React.createElement('div', { className: 'vsm-panel-body' },
|
|
377
|
+
React.createElement(SettingRow, { label: '实时捕获', description: 'agent 用 shell 或脚本(node -e、prettier、生成器)写文件时,改动也会进审查面板;关闭后只认 edit/write 等写工具。' },
|
|
378
|
+
React.createElement('input', {
|
|
379
|
+
type: 'checkbox', checked: extWatchOn,
|
|
380
|
+
disabled: loading || unavailable || notReady || busy || snapshot?.writable === false,
|
|
381
|
+
onChange: (event) => saveToggle('externalWatch', event.target.checked, setExtWatchOn),
|
|
382
|
+
})),
|
|
383
|
+
React.createElement(SettingRow, { label: '补扫对齐', description: '启动时与每 10 分钟用版本库比对一次,把漏采的改动补录进来;关闭后仍可手动补扫。' },
|
|
384
|
+
React.createElement('input', {
|
|
385
|
+
type: 'checkbox', checked: extScanOn,
|
|
386
|
+
disabled: loading || unavailable || notReady || busy || snapshot?.writable === false,
|
|
387
|
+
onChange: (event) => saveToggle('externalScan', event.target.checked, setExtScanOn),
|
|
388
|
+
})),
|
|
389
|
+
),
|
|
390
|
+
),
|
|
370
391
|
React.createElement('section', { className: 'vsm-panel' },
|
|
371
392
|
React.createElement('h3', { className: 'vsm-panel-title' }, '快捷键'),
|
|
372
393
|
React.createElement('div', { className: 'vsm-panel-body' },
|
|
@@ -13,6 +13,8 @@ export function ReviewLedger(props: { sessionId: string; first: ReviewPage | nul
|
|
|
13
13
|
const [cursor, setCursor] = React.useState(0)
|
|
14
14
|
const [detail, setDetail] = React.useState<ReviewDetail | null>(null)
|
|
15
15
|
const [error, setError] = React.useState('')
|
|
16
|
+
const [aligning, setAligning] = React.useState(false)
|
|
17
|
+
const [alignNote, setAlignNote] = React.useState('')
|
|
16
18
|
const selected = React.useRef<AbortController | null>(null)
|
|
17
19
|
React.useEffect(() => () => selected.current?.abort(), [])
|
|
18
20
|
React.useEffect(() => {
|
|
@@ -38,9 +40,25 @@ export function ReviewLedger(props: { sessionId: string; first: ReviewPage | nul
|
|
|
38
40
|
else setError(result.error)
|
|
39
41
|
} catch (cause) { if (!controller.signal.aborted) setError(String(cause)) }
|
|
40
42
|
}
|
|
43
|
+
/** @private @author ddj 2026年11月24号 @description 手动补扫:用版本库基线与已知内容对齐一次,把漏采的改动补进列表。 */
|
|
44
|
+
async function align(): Promise<void> {
|
|
45
|
+
if (aligning) return
|
|
46
|
+
setAligning(true)
|
|
47
|
+
try {
|
|
48
|
+
const result = await rpc('edrv.pending.align', { sessionId: props.sessionId })
|
|
49
|
+
if (!result.ok) { setAlignNote(result.error); return }
|
|
50
|
+
setAlignNote(result.imported ? `补扫新增 ${result.imported} 条(版本库报告 ${result.changed} 个改动)` : `没有需要补录的改动(版本库报告 ${result.changed} 个改动)`)
|
|
51
|
+
refreshReview(props.sessionId)
|
|
52
|
+
} catch (cause) { setAlignNote(String(cause)) }
|
|
53
|
+
finally { setAligning(false) }
|
|
54
|
+
}
|
|
41
55
|
const gaps = page?.gaps ?? []
|
|
42
56
|
return h('div', { style: { marginTop: 8 } },
|
|
43
|
-
h('
|
|
57
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
58
|
+
h('label', null, h('input', { type: 'checkbox', checked: history, onChange: () => { setHistory(!history); setCursor(0) } }), '显示已处理及被替换的历史'),
|
|
59
|
+
h('button', { type: 'button', disabled: aligning, title: '用版本库基线与已知内容对齐一次,补录漏采的改动', onClick: () => { void align() } },
|
|
60
|
+
aligning ? '补扫中…' : '补扫一次')),
|
|
61
|
+
alignNote ? h('small', { role: 'status', style: { display: 'block', marginTop: 4 } }, alignNote) : null,
|
|
44
62
|
error ? h('div', { role: 'alert' }, error) : null,
|
|
45
63
|
!page ? h('p', { role: 'status' }, '正在读取官方审查记录…') : null,
|
|
46
64
|
page && !page.items.length ? h('p', null, history ? '暂无已落盘历史。' : '没有待处理的官方记录;可切换查看历史。') : null,
|
|
@@ -49,7 +67,7 @@ export function ReviewLedger(props: { sessionId: string; first: ReviewPage | nul
|
|
|
49
67
|
title: item.currentPath || item.path,
|
|
50
68
|
style: { display: 'block', width: '100%', textAlign: 'left', padding: '6px 4px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
51
69
|
}, item.id.startsWith(PENDING_PREFIX)
|
|
52
|
-
? `【待审】${item.display} +${item.added} −${item.deleted} · ${item.decision}${item.kind === 'oversized' ? ' · 过大' : ''}`
|
|
70
|
+
? `【待审】${item.display} +${item.added} −${item.deleted} · ${item.decision}${item.sourceLabel ? ' · ' + item.sourceLabel : ''}${item.kind === 'oversized' ? ' · 过大' : ''}`
|
|
53
71
|
: `轮次 ${item.turn} · ${item.display} +${item.added} −${item.deleted} · ${item.decision}${item.current ? '' : '(已被同轮新版本替换)'}`))),
|
|
54
72
|
cursor > 0 ? h('button', { type: 'button', onClick: () => setCursor(Math.max(0, cursor - 50)) }, '上一页') : null,
|
|
55
73
|
page?.nextCursor !== null && page?.nextCursor !== undefined ? h('button', { type: 'button', onClick: () => setCursor(page.nextCursor!) }, '下一页') : null,
|
package/src/fileOpenSettings.ts
CHANGED
|
@@ -41,6 +41,10 @@ export interface FileOpenSettings {
|
|
|
41
41
|
svnReadOnly?: boolean
|
|
42
42
|
/** AI 提交信息风格(默认 plain)。 */
|
|
43
43
|
aiCommitStyle?: 'plain' | 'conventional'
|
|
44
|
+
/** 外部改动实时捕获(watch,默认 true)。 */
|
|
45
|
+
externalWatch?: boolean
|
|
46
|
+
/** 外部改动补扫(启动对齐与定时,默认 true)。 */
|
|
47
|
+
externalScan?: boolean
|
|
44
48
|
}
|
|
45
49
|
export interface FileOpenSettingsState { value: string; revision?: number; update: (value: string, expectedRevision?: number) => Promise<void> }
|
|
46
50
|
|
|
@@ -462,6 +466,9 @@ export function buildSettingsSchema(z: SettingsDeps['z'], options?: { volatile?:
|
|
|
462
466
|
// 交互特性开关(默认开):拖拽/粘贴/复制的引用接入;搜索面板的全局替换
|
|
463
467
|
refIntake: withVol(z.boolean().default(true)),
|
|
464
468
|
searchReplace: withVol(z.boolean().default(true)),
|
|
469
|
+
// 外部改动捕获(默认开):watch 实时采集 / 版本库补扫。关掉即退回只认工具链路的行为。
|
|
470
|
+
externalWatch: withVol(z.boolean().default(true)),
|
|
471
|
+
externalScan: withVol(z.boolean().default(true)),
|
|
465
472
|
}
|
|
466
473
|
if (wantVolatile) configVolatile = { requested: true, marked, total: Object.keys(shape).length }
|
|
467
474
|
return z.object(shape)
|
|
@@ -652,6 +659,14 @@ export interface PluginAiUiSettings {
|
|
|
652
659
|
commitStyle: 'plain' | 'conventional'
|
|
653
660
|
}
|
|
654
661
|
|
|
662
|
+
/** 外部改动捕获开关视图(host 采集层与设置页共用)。 */
|
|
663
|
+
export interface PluginExternalSettings {
|
|
664
|
+
/** 实时监听工作区写事件并补记录。 */
|
|
665
|
+
watch: boolean
|
|
666
|
+
/** 启动对齐与定时补扫。 */
|
|
667
|
+
scan: boolean
|
|
668
|
+
}
|
|
669
|
+
|
|
655
670
|
/** setupOpenSettings 句柄(设置读写 + 分面视图读取)。 */
|
|
656
671
|
export interface OpenSettingsHandle extends FileOpenSettingsState {
|
|
657
672
|
/** AI 补全配置。 */
|
|
@@ -664,6 +679,8 @@ export interface OpenSettingsHandle extends FileOpenSettingsState {
|
|
|
664
679
|
svnCommitDefaults: () => PluginSvnCommitDefaults
|
|
665
680
|
/** AI 界面设置。 */
|
|
666
681
|
aiUi: () => PluginAiUiSettings
|
|
682
|
+
/** 外部改动捕获开关。 */
|
|
683
|
+
external: () => PluginExternalSettings
|
|
667
684
|
}
|
|
668
685
|
|
|
669
686
|
/**
|
|
@@ -703,6 +720,11 @@ export function setupOpenSettings(ctx: Ctx, config: unknown, onChange: (value: s
|
|
|
703
720
|
}
|
|
704
721
|
/** AI 界面设置当前值(提交信息风格 / 整理是否默认按勾选范围)。 */
|
|
705
722
|
let aiUiCurrent: PluginAiUiSettings = { commitStyle: commitStyleValueOf(config) }
|
|
723
|
+
/** 外部改动捕获开关当前值(settings 未就绪回退配置值)。 */
|
|
724
|
+
let externalCurrent: PluginExternalSettings = {
|
|
725
|
+
watch: boolValueOf(config, 'externalWatch', true),
|
|
726
|
+
scan: boolValueOf(config, 'externalScan', true),
|
|
727
|
+
}
|
|
706
728
|
const svnSync = (stored: unknown): void => {
|
|
707
729
|
svnCurrent = {
|
|
708
730
|
svnPath: svnPathValueOf(stored),
|
|
@@ -713,6 +735,10 @@ export function setupOpenSettings(ctx: Ctx, config: unknown, onChange: (value: s
|
|
|
713
735
|
autoDelete: boolValueOf(stored, 'svnAutoDeleteMissing', true),
|
|
714
736
|
}
|
|
715
737
|
aiUiCurrent = { commitStyle: commitStyleValueOf(stored) }
|
|
738
|
+
externalCurrent = {
|
|
739
|
+
watch: boolValueOf(stored, 'externalWatch', true),
|
|
740
|
+
scan: boolValueOf(stored, 'externalScan', true),
|
|
741
|
+
}
|
|
716
742
|
}
|
|
717
743
|
/** 读取 settings 存储值(describe 未就绪返回 undefined)。 */
|
|
718
744
|
const storedValue = (): unknown => {
|
|
@@ -729,6 +755,8 @@ export function setupOpenSettings(ctx: Ctx, config: unknown, onChange: (value: s
|
|
|
729
755
|
svnAutoDeleteMissing: svnCurrent.autoDelete,
|
|
730
756
|
svnReadOnly: svnCurrent.readOnly,
|
|
731
757
|
aiCommitStyle: aiUiCurrent.commitStyle,
|
|
758
|
+
externalWatch: externalCurrent.watch,
|
|
759
|
+
externalScan: externalCurrent.scan,
|
|
732
760
|
}, {
|
|
733
761
|
setSource: (source) => {
|
|
734
762
|
notify(source().fileOpenTool)
|
|
@@ -764,6 +792,7 @@ export function setupOpenSettings(ctx: Ctx, config: unknown, onChange: (value: s
|
|
|
764
792
|
svn: () => svnCurrent,
|
|
765
793
|
svnCommitDefaults: () => ({ autoAdd: svnCurrent.autoAdd, autoDelete: svnCurrent.autoDelete }),
|
|
766
794
|
aiUi: () => aiUiCurrent,
|
|
795
|
+
external: () => externalCurrent,
|
|
767
796
|
aiUpdate: async (patch: AiConfigPatch, expectedRevision?: number): Promise<AiConfigView> => {
|
|
768
797
|
const stored = { ...aiCurrent }
|
|
769
798
|
const body: Record<string, unknown> = {}
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,12 @@ import { captureToolResult } from './capture.js'
|
|
|
4
4
|
import { installCapture } from './officialCapture.js'
|
|
5
5
|
import { installEvidence } from './reviewCapture.js'
|
|
6
6
|
import { installPending } from './pending/capture.js'
|
|
7
|
+
import type { PendingWrite } from './pending/capture.js'
|
|
8
|
+
import { installExternalCapture, VCS_WRITE_METHODS, VCS_WRITE_TOOLS } from './pending/externalCapture.js'
|
|
9
|
+
import { windows } from './pending/provenance.js'
|
|
7
10
|
import { recordWrite } from './pending/store.js'
|
|
11
|
+
import { cwdOfSession } from './store.js'
|
|
12
|
+
import { resolveScope } from './registry.js'
|
|
8
13
|
import { trackPendingCover } from './pendingCompat.js'
|
|
9
14
|
import { closeArchiveDbs } from './archiveDb.js'
|
|
10
15
|
import { handleRpc, integrationBaseUrlOf } from './rpc.js'
|
|
@@ -64,7 +69,7 @@ function createRuntime(ctx: Ctx, config: unknown) {
|
|
|
64
69
|
const svnRpc = createSvnRpc({ ctx, settings })
|
|
65
70
|
const dapRpc = createDapRpc(ctx)
|
|
66
71
|
const fileVersions = createFileVersions(ctx)
|
|
67
|
-
return { registry, searcher, contentSearcher, lspManager, lspRpc, aiRpc, svnRpc, dapRpc, fileVersions }
|
|
72
|
+
return { registry, searcher, contentSearcher, lspManager, lspRpc, aiRpc, svnRpc, dapRpc, fileVersions, settings }
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
/**
|
|
@@ -73,14 +78,47 @@ function createRuntime(ctx: Ctx, config: unknown) {
|
|
|
73
78
|
* @param ctx Host context.
|
|
74
79
|
* @param runtime Managers created by this instance.
|
|
75
80
|
*/
|
|
76
|
-
function attachRuntime(ctx: Ctx, runtime: Runtime):
|
|
81
|
+
function attachRuntime(ctx: Ctx, runtime: Runtime): { external: ReturnType<typeof installExternalCapture> } {
|
|
77
82
|
const evidence = installEvidence(ctx)
|
|
78
83
|
const stopCapture = installCapture(ctx, (cwd, snapshot) => { evidence.persist(cwd, snapshot); return true })
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
/** @author ddj 2026年11月24号 @param write 已确认的一次写入 @returns 无;落库失败不打断用户工具调用 */
|
|
85
|
+
function recordPendingWrite(write: PendingWrite): void {
|
|
81
86
|
try { trackPendingCover(write.cwd, write.path, true, write.sessionId) } catch { /* 内存登记失败不阻断采集 */ }
|
|
82
87
|
try { recordWrite(write) } catch (error) { log.warn('待审差异落库失败:' + String(error)) }
|
|
88
|
+
}
|
|
89
|
+
// 待审累计基线:只有写后内容确实变化才落库,异常一律不打断用户工具调用
|
|
90
|
+
const pending = installPending(ctx, recordPendingWrite)
|
|
91
|
+
// 外部改动采集:非 DSH 文件工具(bash 里的 node -e、脚本、生成器)写盘也进审查面板
|
|
92
|
+
const external = installExternalCapture({
|
|
93
|
+
ctx,
|
|
94
|
+
settings: () => runtime.settings.external(),
|
|
95
|
+
record: recordPendingWrite,
|
|
83
96
|
})
|
|
97
|
+
/**
|
|
98
|
+
* @author ddj 2026年11月24号
|
|
99
|
+
* @description: 任一工具调用期间都是 agent 写入窗口:bash / python 写盘落在窗口内时归属 agent。
|
|
100
|
+
* 版本库写工具结束后再补扫一次,把命令造成的成片变化对齐进待审投影。
|
|
101
|
+
* @param exec 工具执行描述
|
|
102
|
+
* @param next 原始分发
|
|
103
|
+
* @returns 原始结果
|
|
104
|
+
*/
|
|
105
|
+
function aroundToolWindow(exec: { name?: unknown; agent?: { session?: unknown } }, next: () => Promise<unknown>): Promise<unknown> {
|
|
106
|
+
windows.enterTool()
|
|
107
|
+
return Promise.resolve()
|
|
108
|
+
.then(next)
|
|
109
|
+
.finally(() => {
|
|
110
|
+
windows.exitTool()
|
|
111
|
+
if (!VCS_WRITE_TOOLS.has(String(exec.name ?? ''))) return
|
|
112
|
+
const cwd = cwdOfSession(ctx, exec.agent?.session)
|
|
113
|
+
if (cwd) external.requestAlign(cwd)
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
/** @author ddj 2026年11月24号 @param session 新建会话 @returns 无;工作区可用即开始监听 */
|
|
117
|
+
function onCreated(session: { id?: unknown }): void {
|
|
118
|
+
if (typeof session.id !== 'string') return
|
|
119
|
+
const cwd = cwdOfSession(ctx, session)
|
|
120
|
+
if (cwd) external.ensure(cwd, session.id)
|
|
121
|
+
}
|
|
84
122
|
/** @author ddj 2026年09月28号 @param exec Tool execution. @param result Tool result. */
|
|
85
123
|
function onResult(exec: unknown, result: unknown): void {
|
|
86
124
|
void captureToolResult(ctx, runtime.registry, exec, result)
|
|
@@ -89,6 +127,7 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
89
127
|
function onDisposed(session: { id?: unknown }): void {
|
|
90
128
|
const cwd = cwdOf(session)
|
|
91
129
|
if (cwd) {
|
|
130
|
+
external.dismiss(cwd)
|
|
92
131
|
runtime.registry.delete(cwd)
|
|
93
132
|
runtime.searcher.dispose(cwd)
|
|
94
133
|
runtime.contentSearcher.dispose(cwd)
|
|
@@ -101,6 +140,8 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
101
140
|
await stopCapture()
|
|
102
141
|
evidence.dispose()
|
|
103
142
|
pending.dispose()
|
|
143
|
+
external.dispose()
|
|
144
|
+
windows.dispose()
|
|
104
145
|
runtime.fileVersions.dispose()
|
|
105
146
|
closeArchiveDbs()
|
|
106
147
|
disposeAllServers()
|
|
@@ -108,9 +149,14 @@ function attachRuntime(ctx: Ctx, runtime: Runtime): void {
|
|
|
108
149
|
await Promise.allSettled(tasks.map((run) => Promise.resolve().then(run)))
|
|
109
150
|
}
|
|
110
151
|
ctx.on('tools/result', onResult)
|
|
152
|
+
ctx.on('tools/execute', aroundToolWindow)
|
|
153
|
+
ctx.on('session/created', onCreated)
|
|
111
154
|
ctx.on('session/disposed', onDisposed)
|
|
155
|
+
// 启动时给已有会话的工作区各开一份监听(会话内 cd 后由 session/created 与 ensure 幂等补齐)
|
|
156
|
+
for (const session of ctx.get('sessions').list()) onCreated(session)
|
|
112
157
|
ctx.effect(() => cleanup, 'vscode-mode:runtime')
|
|
113
158
|
hookExitReclaim()
|
|
159
|
+
return { external }
|
|
114
160
|
}
|
|
115
161
|
|
|
116
162
|
/**
|
|
@@ -136,13 +182,35 @@ export async function apply(ctx: Ctx, config?: unknown): Promise<void> {
|
|
|
136
182
|
bindHostLog(ctx)
|
|
137
183
|
const runtime = createRuntime(ctx, config)
|
|
138
184
|
const warnings: string[] = []
|
|
139
|
-
attachRuntime(ctx, runtime)
|
|
185
|
+
const capture = attachRuntime(ctx, runtime)
|
|
140
186
|
installContent(ctx)
|
|
187
|
+
/** 版本库写操作后的补扫串行链:并发 RPC 也不会叠出多次补扫。 */
|
|
188
|
+
let alignChain: Promise<void> = Promise.resolve()
|
|
141
189
|
/** @author ddj 2026年09月28号 @param method RPC name. @param args Typed request. @returns RPC result. */
|
|
142
190
|
function dispatch<M extends RpcMethod>(method: M, args: RpcRequestMap[M]) {
|
|
143
191
|
const { registry, searcher, contentSearcher, lspRpc, aiRpc, fileVersions, svnRpc, dapRpc } = runtime
|
|
144
|
-
|
|
192
|
+
const pendingResult = handleRpc(ctx, registry, method, args, searcher, contentSearcher, lspRpc.handlers,
|
|
145
193
|
aiRpc.handlers, fileVersions, svnRpc.handlers as Partial<RpcHandlerMap>, dapRpc.handlers)
|
|
194
|
+
// 版本库写操作(提交/更新/还原/清理…)之后补扫一次:命令造成的成片变化要能进待审投影
|
|
195
|
+
if (!VCS_WRITE_METHODS.has(method)) return pendingResult
|
|
196
|
+
alignChain = alignChain.then(async () => {
|
|
197
|
+
const cwd = await workspaceOfSession((args as { sessionId?: string } | undefined)?.sessionId)
|
|
198
|
+
if (cwd) capture.external.requestAlign(cwd)
|
|
199
|
+
}).catch(() => {})
|
|
200
|
+
return pendingResult
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @author ddj 2026年11月24号
|
|
204
|
+
* @description: 取 RPC 参数里的会话工作区;取不到就跳过补扫,绝不影响 RPC 本身。
|
|
205
|
+
* @param sessionId 请求会话
|
|
206
|
+
* @returns 工作区路径或 null
|
|
207
|
+
*/
|
|
208
|
+
async function workspaceOfSession(sessionId: string | undefined): Promise<string | null> {
|
|
209
|
+
try {
|
|
210
|
+
if (!sessionId) return null
|
|
211
|
+
const scope = await resolveScope(ctx, sessionId)
|
|
212
|
+
return 'err' in scope ? null : scope.cwd
|
|
213
|
+
} catch { return null }
|
|
146
214
|
}
|
|
147
215
|
/** @author ddj 2026年09月28号 @param warning Startup compatibility diagnostic. */
|
|
148
216
|
function noteWarning(warning: string): void { warnings.push(warning) }
|
package/src/mcpManaged.ts
CHANGED
|
@@ -25,6 +25,10 @@ export interface ManagedState {
|
|
|
25
25
|
error?: string
|
|
26
26
|
/** 官方报告的 OAuth 授权阶段。 */
|
|
27
27
|
phase?: string
|
|
28
|
+
/** 官方报告的真连上时刻(epoch 毫秒,仅 connected 状态有)。 */
|
|
29
|
+
connectedAt?: number
|
|
30
|
+
/** 本条注册的挂载时刻(epoch 毫秒),供会话卡片算耗时。 */
|
|
31
|
+
since?: number
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** 一条托管注册的账目。 */
|
|
@@ -39,6 +43,8 @@ interface Held {
|
|
|
39
43
|
key: string
|
|
40
44
|
/** 需求计数:归零才真正注销。 */
|
|
41
45
|
refs: number
|
|
46
|
+
/** 注册时刻:会话卡片按它算本服务器的耗时。 */
|
|
47
|
+
mountedAt: number
|
|
42
48
|
/** 注销函数;注册失败时缺省。 */
|
|
43
49
|
dispose?: () => void
|
|
44
50
|
}
|
|
@@ -197,7 +203,7 @@ export class ManagedProject {
|
|
|
197
203
|
*/
|
|
198
204
|
private mount(path: string, server: string, def: ManagedDef, refs: number): void {
|
|
199
205
|
const name = managedName(path, server)
|
|
200
|
-
const record: Held = { name, path, server, key: keyOf(def), refs }
|
|
206
|
+
const record: Held = { name, path, server, key: keyOf(def), refs, mountedAt: Date.now() }
|
|
201
207
|
this.held.set(name, record)
|
|
202
208
|
const reason = this.conflictOf(name)
|
|
203
209
|
if (reason) {
|
|
@@ -269,7 +275,7 @@ export class ManagedProject {
|
|
|
269
275
|
}
|
|
270
276
|
|
|
271
277
|
/**
|
|
272
|
-
*
|
|
278
|
+
* 读一条托管的当前状态;挂载时刻与官方连上时刻一并带出。
|
|
273
279
|
* @public @author ddj 2026年11月23号
|
|
274
280
|
* @param path 工作区路径
|
|
275
281
|
* @param server 服务器名
|
|
@@ -277,12 +283,15 @@ export class ManagedProject {
|
|
|
277
283
|
*/
|
|
278
284
|
stateOf(path: string, server: string): ManagedState {
|
|
279
285
|
const name = managedName(path, server)
|
|
286
|
+
const held = this.held.get(name)
|
|
280
287
|
const view = this.views.get(name)
|
|
281
288
|
// 没注册过就不是 disabled:那是「按需、还没人用」,面板按 configured 显示。
|
|
282
|
-
if (!view) return { state:
|
|
289
|
+
if (!view) return held ? { state: 'unknown', since: held.mountedAt } : { state: 'idle' }
|
|
283
290
|
const state: ManagedState = { state: view.state }
|
|
291
|
+
if (held) state.since = held.mountedAt
|
|
284
292
|
if (view.error) state.error = view.error
|
|
285
293
|
if (view.phase) state.phase = view.phase
|
|
294
|
+
if (view.connectedAt !== undefined) state.connectedAt = view.connectedAt
|
|
286
295
|
return state
|
|
287
296
|
}
|
|
288
297
|
|
package/src/mcpManagerBridge.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface ManagerView {
|
|
|
33
33
|
state: string
|
|
34
34
|
error?: string
|
|
35
35
|
phase?: string
|
|
36
|
+
/** 官方报告的真连上时刻(epoch 毫秒,仅 connected 状态有)。 */
|
|
37
|
+
connectedAt?: number
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/** 官方 manager 的最小能力面;服务缺失即 available() === false。 */
|
|
@@ -56,7 +58,7 @@ interface HostLike { get: (name: string) => unknown }
|
|
|
56
58
|
interface RawView {
|
|
57
59
|
name?: unknown
|
|
58
60
|
configured?: unknown
|
|
59
|
-
status?: { state?: unknown; reason?: unknown; lastError?: unknown; result?: { message?: unknown } }
|
|
61
|
+
status?: { state?: unknown; reason?: unknown; lastError?: unknown; connectedAt?: unknown; result?: { message?: unknown } }
|
|
60
62
|
authorization?: { phase?: unknown }
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -165,6 +167,8 @@ export function toView(raw: unknown): ManagerView {
|
|
|
165
167
|
const result: ManagerView = { name, configured: view.configured === true, state }
|
|
166
168
|
if (message) result.error = message
|
|
167
169
|
if (phase) result.phase = phase
|
|
170
|
+
// 只有真连上才带这个时刻,会话卡片据此算本服务器的真实初始化耗时。
|
|
171
|
+
if (typeof status.connectedAt === 'number') result.connectedAt = status.connectedAt
|
|
168
172
|
return result
|
|
169
173
|
}
|
|
170
174
|
|