dsh-vscode-mode 0.38.0 → 0.40.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 +38 -33
- package/lib/client.js +87 -68
- package/lib/client.js.map +1 -1
- package/lib/index.js +11406 -4920
- package/lib/index.js.map +1 -1
- package/package.json +3 -2
- package/skills/dsh-vscodemode-html-plan/SKILL.md +44 -42
- package/skills/dsh-vscodemode-test-check/SKILL.md +82 -0
- package/src/archiveDb.ts +24 -0
- package/src/attachmentBytes.ts +84 -0
- package/src/client/htmlPlan/HtmlPlanModeChip.ts +181 -0
- package/src/client/htmlPlan/HtmlPlanPanel.ts +230 -61
- package/src/client/htmlPlan/planActions.ts +38 -8
- package/src/client/htmlPlan/planPage.ts +111 -9
- package/src/client/index.ts +9 -0
- package/src/client/openReceipt.ts +5 -2
- package/src/client/planBridge.ts +27 -2
- package/src/client/planState.ts +51 -4
- package/src/client/sidebar/panels/TestCheckPanel.ts +485 -0
- package/src/client/sidebar/panels/useTestCheckData.ts +414 -0
- package/src/client/sidebar/types.ts +2 -0
- package/src/client/state/diffSummary.ts +3 -0
- package/src/client/styles/editor.css +91 -0
- package/src/client/testCheck/TestCheckChip.ts +181 -0
- package/src/client/testCheck/TestCheckPanel.ts +339 -0
- package/src/client/testCheckPanelState.ts +173 -0
- package/src/client/ui/EditorView.ts +77 -7
- package/src/client/ui/McpSettings.ts +2 -2
- package/src/client/ui/OfficialReview.ts +6 -4
- package/src/htmlPlanAttachments.ts +4 -1
- package/src/htmlPlanCommand.ts +87 -235
- package/src/htmlPlanGuidance.ts +67 -0
- package/src/htmlPlanMode.ts +547 -0
- package/src/index.ts +28 -55
- package/src/officialCapture.ts +58 -9
- package/src/pending/externalCapture.ts +195 -401
- package/src/pending/kernel.ts +24 -1
- package/src/pending/persist.ts +109 -22
- package/src/pending/provenance.ts +5 -28
- package/src/pending/store.ts +109 -100
- package/src/pending/tracking.ts +81 -0
- package/src/pendingCompat.ts +26 -1
- package/src/pendingRpc.ts +8 -56
- package/src/planAutoPage.ts +306 -0
- package/src/planPagePack.ts +148 -0
- package/src/registry.ts +7 -2
- package/src/reviewDb.ts +1 -1
- package/src/reviewRpc.ts +14 -6
- package/src/rpc.ts +34 -0
- package/src/shared/htmlPlanMode.ts +26 -0
- package/src/shared/pendingReview.ts +15 -7
- package/src/shared/review.ts +5 -0
- package/src/shared/rpc.ts +53 -7
- package/src/shared/testCheck.ts +759 -0
- package/src/shared/testCheckHtml.ts +276 -0
- package/src/shared/testCheckPolicyDefault.ts +37 -0
- package/src/shared/testCheckSnippets.ts +197 -0
- package/src/store.ts +17 -1
- package/src/testCheckCommand.ts +287 -0
- package/src/testCheckGuidance.ts +79 -0
- package/src/testCheckMode.ts +654 -0
- package/src/testCheckPolicy.ts +141 -0
- package/src/testCheckRpc.ts +196 -0
- package/src/testCheckStore.ts +822 -0
- package/src/pending/externalAlign.ts +0 -297
- package/src/pending/vcs.ts +0 -584
package/src/pending/vcs.ts
DELETED
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 版本库导入:把工作副本相对基线的改动读成待审条目,来源对齐 dsh-diff-approval 的 vcs 内核(MIT)。
|
|
3
|
-
* 只读命令,不修改工作副本;基线读取失败一律上报,不猜"文件不存在"。
|
|
4
|
-
* @author ddj 2026年10月30号
|
|
5
|
-
*/
|
|
6
|
-
import { readFile, stat } from 'node:fs/promises'
|
|
7
|
-
import { dirname, join, resolve, sep } from 'node:path'
|
|
8
|
-
import { pathKeyOf } from './provenance.js'
|
|
9
|
-
|
|
10
|
-
/** 支持的版本库种类。 */
|
|
11
|
-
export type VcsKind = 'git' | 'svn' | 'p4'
|
|
12
|
-
|
|
13
|
-
/** 探测结果。 */
|
|
14
|
-
export interface VcsRoot {
|
|
15
|
-
kind: VcsKind
|
|
16
|
-
root: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** 一条导入改动:相对基线的旧内容与当前内容(删除时当前内容为 null)。 */
|
|
20
|
-
export interface VcsChange {
|
|
21
|
-
path: string
|
|
22
|
-
earlierVersion: 'file' | 'none'
|
|
23
|
-
oldText: string
|
|
24
|
-
newText: string | null
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** 工作副本相对基线的一条状态(补扫只关心这三类)。 */
|
|
28
|
-
export type VcsEntryStatus = 'modified' | 'added' | 'deleted'
|
|
29
|
-
|
|
30
|
-
/** 一条状态条目:绝对路径与归一状态。 */
|
|
31
|
-
export interface VcsEntry {
|
|
32
|
-
path: string
|
|
33
|
-
status: VcsEntryStatus
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** 一次状态探测结果:根目录、种类与「相对基线有改动」的路径集合。 */
|
|
37
|
-
export interface VcsStatus {
|
|
38
|
-
kind: VcsKind
|
|
39
|
-
root: string
|
|
40
|
-
/** 绝对路径比较键 → 状态条目(键由 pathKeyFor 生成,调用方直接比对)。 */
|
|
41
|
-
entries: Map<string, VcsEntry>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 导入选项。 */
|
|
45
|
-
export interface VcsImportOptions {
|
|
46
|
-
includeUntracked?: boolean
|
|
47
|
-
path?: string
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** shell 能力最小面(便于单测注入)。 */
|
|
51
|
-
export interface ShellLike {
|
|
52
|
-
resolve(request: { command: string; workdir?: string; timeoutMs?: number; stdoutMaxBytes?: number; sandboxPolicy?: unknown }): unknown
|
|
53
|
-
execute(spec: unknown): Promise<{ result(): Promise<{ exitCode: number | null; timedOut: boolean; aborted: boolean; stdout: { text: string }; stderr: { text: string } }> }>
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** 命令超时:与上游一致,避免大仓 status 卡死。 */
|
|
57
|
-
const COMMAND_TIMEOUT = 60_000
|
|
58
|
-
/** stdout 预算:够放一个常见源文件,超出交给上游判断为超大。 */
|
|
59
|
-
const STDOUT_BUDGET = 8 * 1024 * 1024
|
|
60
|
-
/** 只有这些 git 报错才算"该版本不存在",其余一律抛出。 */
|
|
61
|
-
const ABSENT_AT_REVISION = /does not exist in|exists on disk, but not in|not a valid object name|invalid object name|unknown revision|bad revision/i
|
|
62
|
-
/** 只有这些 P4 报错才算"该版本不存在",其余一律抛出。 */
|
|
63
|
-
const P4_ABSENT_AT_REVISION = /no such file|not opened|does not exist|no file\(s\) to print|invalid file|no revisions/i
|
|
64
|
-
/** git 相对路径用正斜杠。 */
|
|
65
|
-
const GIT_SEPARATOR = '/'
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @author ddj 2026年10月30号
|
|
69
|
-
* @description: 向上查找版本库根目录,同目录 git 优先于 svn,最后才是 Perforce 配置。
|
|
70
|
-
* @param cwd 工作区
|
|
71
|
-
* @returns 探测结果,未找到时 undefined
|
|
72
|
-
*/
|
|
73
|
-
export async function detectVcsRoot(cwd: string): Promise<VcsRoot | undefined> {
|
|
74
|
-
let current = resolve(cwd)
|
|
75
|
-
for (;;) {
|
|
76
|
-
const git = await exists(join(current, '.git'))
|
|
77
|
-
if (git) return { kind: 'git', root: current }
|
|
78
|
-
if (await exists(join(current, '.svn'))) return { kind: 'svn', root: current }
|
|
79
|
-
if (await isP4Root(current)) return { kind: 'p4', root: current }
|
|
80
|
-
const parent = dirname(current)
|
|
81
|
-
if (parent === current) return undefined
|
|
82
|
-
current = parent
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @author ddj 2026年10月30号
|
|
88
|
-
* @description: 判断目录是否是 Perforce 工作区根(P4CONFIG 文件所在目录)。
|
|
89
|
-
* @param dir 目录
|
|
90
|
-
* @returns 是否 P4 根
|
|
91
|
-
*/
|
|
92
|
-
async function isP4Root(dir: string): Promise<boolean> {
|
|
93
|
-
return (await exists(join(dir, '.p4config'))) || (await exists(join(dir, '.p4config.txt')))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @author ddj 2026年10月30号
|
|
98
|
-
* @description: 读出当前工作副本相对基线的改动,只返回给定范围(含未跟踪按选项)。
|
|
99
|
-
* @param shell shell 能力
|
|
100
|
-
* @param cwd 工作区
|
|
101
|
-
* @param options 导入选项
|
|
102
|
-
* @returns 改动列表
|
|
103
|
-
*/
|
|
104
|
-
export async function importVcsChanges(shell: ShellLike, cwd: string, options: VcsImportOptions = {}): Promise<VcsChange[]> {
|
|
105
|
-
const detected = await detectVcsRoot(cwd)
|
|
106
|
-
if (!detected) return []
|
|
107
|
-
const changes = await readChanges(shell, detected, cwd, options)
|
|
108
|
-
const only = options.path ? resolve(cwd, options.path) : undefined
|
|
109
|
-
return changes.filter((change) => !only || samePath(change.path, only))
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @author ddj 2026年10月30号
|
|
114
|
-
* @description: 按探测到的种类取改动,新增种类只在这里分流。
|
|
115
|
-
* @param shell shell 能力
|
|
116
|
-
* @param detected 版本库种类与根目录
|
|
117
|
-
* @param cwd 工作区
|
|
118
|
-
* @param options 导入选项
|
|
119
|
-
* @returns 改动列表
|
|
120
|
-
*/
|
|
121
|
-
async function readChanges(shell: ShellLike, detected: VcsRoot, cwd: string, options: VcsImportOptions): Promise<VcsChange[]> {
|
|
122
|
-
if (detected.kind === 'git') return gitChanges(shell, cwd, detected.root, options)
|
|
123
|
-
if (detected.kind === 'svn') return svnChanges(shell, cwd, detected.root, options)
|
|
124
|
-
return p4Changes(shell, cwd, detected.root, options)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @author ddj 2026年10月30号
|
|
129
|
-
* @description: git 改动:status -z 解析状态,基线取 HEAD 版本,未跟踪可按选项导入为新建。
|
|
130
|
-
* @param shell shell 能力
|
|
131
|
-
* @param cwd 工作区
|
|
132
|
-
* @param root 仓库根
|
|
133
|
-
* @param options 导入选项
|
|
134
|
-
* @returns 改动列表
|
|
135
|
-
*/
|
|
136
|
-
async function gitChanges(shell: ShellLike, cwd: string, root: string, options: VcsImportOptions): Promise<VcsChange[]> {
|
|
137
|
-
const command = 'git -c status.renames=false status --porcelain=v1 -z --untracked-files=all'
|
|
138
|
-
const status = await runCommand(shell, command, root)
|
|
139
|
-
if (!status.ok) throw new Error('git status 失败:' + status.stderr.slice(0, 200))
|
|
140
|
-
const changes: VcsChange[] = []
|
|
141
|
-
for (const entry of parseGitStatus(status.stdout)) {
|
|
142
|
-
if (entry.status === '??' && !options.includeUntracked) continue
|
|
143
|
-
const absolute = join(root, ...entry.path.split(GIT_SEPARATOR))
|
|
144
|
-
if (!insideRoot(root, absolute)) continue
|
|
145
|
-
const current = await readTextOf(absolute)
|
|
146
|
-
if (entry.status === '??' || entry.status === 'A ') {
|
|
147
|
-
changes.push({ path: absolute, earlierVersion: 'none', oldText: '', newText: current })
|
|
148
|
-
continue
|
|
149
|
-
}
|
|
150
|
-
// 版本里确实没有该文件时按新建导入(earlierVersion='none'),不能丢掉这条改动
|
|
151
|
-
const baseline = await gitBaseline(shell, root, entry.path)
|
|
152
|
-
changes.push({
|
|
153
|
-
path: absolute,
|
|
154
|
-
earlierVersion: baseline === null ? 'none' : 'file',
|
|
155
|
-
oldText: baseline ?? '',
|
|
156
|
-
newText: current,
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
return changes
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @author ddj 2026年10月30号
|
|
164
|
-
* @description: svn 改动:status --xml 解析状态,基线取 BASE 版本。
|
|
165
|
-
* @param shell shell 能力
|
|
166
|
-
* @param cwd 工作区
|
|
167
|
-
* @param root 工作副本根
|
|
168
|
-
* @param options 导入选项
|
|
169
|
-
* @returns 改动列表
|
|
170
|
-
*/
|
|
171
|
-
async function svnChanges(shell: ShellLike, cwd: string, root: string, options: VcsImportOptions): Promise<VcsChange[]> {
|
|
172
|
-
const status = await runCommand(shell, 'svn status --xml', root)
|
|
173
|
-
if (!status.ok) throw new Error('svn status 失败:' + status.stderr.slice(0, 200))
|
|
174
|
-
const changes: VcsChange[] = []
|
|
175
|
-
for (const entry of parseSvnStatus(status.stdout)) {
|
|
176
|
-
if (entry.status === 'unversioned' && !options.includeUntracked) continue
|
|
177
|
-
const absolute = resolve(root, entry.path)
|
|
178
|
-
if (!insideRoot(root, absolute)) continue
|
|
179
|
-
const current = await readTextOf(absolute)
|
|
180
|
-
if (entry.status === 'added' || entry.status === 'unversioned' || entry.status === 'replaced') {
|
|
181
|
-
changes.push({ path: absolute, earlierVersion: 'none', oldText: '', newText: current })
|
|
182
|
-
continue
|
|
183
|
-
}
|
|
184
|
-
const baseline = await svnBaseline(shell, root, entry.path)
|
|
185
|
-
changes.push({ path: absolute, earlierVersion: 'file', oldText: baseline, newText: current })
|
|
186
|
-
}
|
|
187
|
-
return changes
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* @author ddj 2026年10月30号
|
|
192
|
-
* @description: 取 HEAD 版本内容;仅"该版本确实没有此文件"时返回 null,其余失败抛出。
|
|
193
|
-
* @param shell shell 能力
|
|
194
|
-
* @param root 仓库根
|
|
195
|
-
* @param relative 仓库相对路径(正斜杠)
|
|
196
|
-
* @returns 基线内容或 null
|
|
197
|
-
*/
|
|
198
|
-
async function gitBaseline(shell: ShellLike, root: string, relative: string): Promise<string | null> {
|
|
199
|
-
const size = await runCommand(shell, `git cat-file -s HEAD:${quote(relative)}`, root)
|
|
200
|
-
const budget = size.ok ? Number(size.stdout.trim()) + 1024 : STDOUT_BUDGET
|
|
201
|
-
const shown = await runCommand(shell, `git show HEAD:${quote(relative)}`, root, Math.min(budget, STDOUT_BUDGET))
|
|
202
|
-
if (shown.ok) return shown.stdout
|
|
203
|
-
if (ABSENT_AT_REVISION.test(shown.stderr)) return null
|
|
204
|
-
throw new Error('读取 git 基线失败:' + shown.stderr.slice(0, 200))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* @author ddj 2026年10月30号
|
|
209
|
-
* @description: 取 svn BASE 版本内容;失败一律抛出(svn 没有可靠的"不存在"判据)。
|
|
210
|
-
* @param shell shell 能力
|
|
211
|
-
* @param root 工作副本根
|
|
212
|
-
* @param relative 相对路径
|
|
213
|
-
* @returns 基线内容
|
|
214
|
-
*/
|
|
215
|
-
async function svnBaseline(shell: ShellLike, root: string, relative: string): Promise<string> {
|
|
216
|
-
const shown = await runCommand(shell, `svn cat -r BASE ${quote(relative)}`, root)
|
|
217
|
-
if (!shown.ok) throw new Error('读取 svn 基线失败:' + shown.stderr.slice(0, 200))
|
|
218
|
-
return shown.stdout
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @author ddj 2026年10月30号
|
|
223
|
-
* @description: Perforce 改动:opened(含 status 的未跟踪项)解析 depot 路径,再折成本地路径。
|
|
224
|
-
* @param shell shell 能力
|
|
225
|
-
* @param cwd 工作区
|
|
226
|
-
* @param root P4 工作区根
|
|
227
|
-
* @param options 导入选项
|
|
228
|
-
* @returns 改动列表
|
|
229
|
-
*/
|
|
230
|
-
async function p4Changes(shell: ShellLike, cwd: string, root: string, options: VcsImportOptions): Promise<VcsChange[]> {
|
|
231
|
-
const depotPaths = new Set<string>()
|
|
232
|
-
const opened = await runCommand(shell, 'p4 opened', root)
|
|
233
|
-
if (!opened.ok) throw new Error('p4 opened 失败:' + opened.stderr.slice(0, 200))
|
|
234
|
-
for (const path of parseP4Opened(opened.stdout)) depotPaths.add(path)
|
|
235
|
-
if (options.includeUntracked) {
|
|
236
|
-
const status = await runCommand(shell, 'p4 status', root)
|
|
237
|
-
if (!status.ok) throw new Error('p4 status 失败:' + status.stderr.slice(0, 200))
|
|
238
|
-
for (const path of parseP4Status(status.stdout)) depotPaths.add(path)
|
|
239
|
-
}
|
|
240
|
-
const changes: VcsChange[] = []
|
|
241
|
-
for (const depot of depotPaths) {
|
|
242
|
-
const absolute = await p4LocalPath(shell, root, depot)
|
|
243
|
-
if (!absolute || !insideRoot(root, absolute)) continue
|
|
244
|
-
const current = await readTextOf(absolute)
|
|
245
|
-
const baseline = await p4Baseline(shell, root, depot)
|
|
246
|
-
changes.push({
|
|
247
|
-
path: absolute,
|
|
248
|
-
earlierVersion: baseline === null ? 'none' : 'file',
|
|
249
|
-
oldText: baseline ?? '',
|
|
250
|
-
newText: current,
|
|
251
|
-
})
|
|
252
|
-
}
|
|
253
|
-
return changes
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @author ddj 2026年10月30号
|
|
258
|
-
* @description: 解析 `p4 opened` 输出,只取 depot 路径(`//depot/x#3 - edit ...`)。
|
|
259
|
-
* @param text 输出
|
|
260
|
-
* @returns depot 路径列表
|
|
261
|
-
*/
|
|
262
|
-
function parseP4Opened(text: string): string[] {
|
|
263
|
-
const paths: string[] = []
|
|
264
|
-
for (const line of text.split(/\r?\n/)) {
|
|
265
|
-
const match = /^(\/\/[^#\s]+)#\d+/.exec(line.trim())
|
|
266
|
-
if (match) paths.push(match[1]!)
|
|
267
|
-
}
|
|
268
|
-
return paths
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @author ddj 2026年10月30号
|
|
273
|
-
* @description: 解析 `p4 status` 输出;每行以本地路径或 depot 路径开头,取路径本身。
|
|
274
|
-
* @param text 输出
|
|
275
|
-
* @returns depot 或本地路径列表
|
|
276
|
-
*/
|
|
277
|
-
function parseP4Status(text: string): string[] {
|
|
278
|
-
const paths: string[] = []
|
|
279
|
-
for (const line of text.split(/\r?\n/)) {
|
|
280
|
-
const trimmed = line.trim()
|
|
281
|
-
if (!trimmed || trimmed.startsWith('-')) continue
|
|
282
|
-
const head = trimmed.split(/\s+-\s+/)[0]?.trim()
|
|
283
|
-
if (!head) continue
|
|
284
|
-
paths.push(head)
|
|
285
|
-
}
|
|
286
|
-
return paths
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* @author ddj 2026年10月30号
|
|
291
|
-
* @description: `p4 where` 把小写 depot 路径折成本地绝对路径。
|
|
292
|
-
* @param shell shell 能力
|
|
293
|
-
* @param root P4 工作区根
|
|
294
|
-
* @param depot depot 路径
|
|
295
|
-
* @returns 本地路径,失败时 undefined
|
|
296
|
-
*/
|
|
297
|
-
async function p4LocalPath(shell: ShellLike, root: string, depot: string): Promise<string | undefined> {
|
|
298
|
-
if (depot.startsWith('//')) {
|
|
299
|
-
const where = await runCommand(shell, `p4 where ${quote(depot)}`, root)
|
|
300
|
-
if (!where.ok) return undefined
|
|
301
|
-
// 形如 "//depot/x //client/x C:\work\x"
|
|
302
|
-
const tokens = where.stdout.trim().split(/\s+/)
|
|
303
|
-
return tokens[tokens.length - 1] ?? undefined
|
|
304
|
-
}
|
|
305
|
-
return resolve(root, depot)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* @author ddj 2026年10月30号
|
|
310
|
-
* @description: 取 `#have` 版本内容;只有明确"没有该版本"时返回 null,其余失败抛出。
|
|
311
|
-
* @param shell shell 能力
|
|
312
|
-
* @param root P4 工作区根
|
|
313
|
-
* @param depot depot 路径
|
|
314
|
-
* @returns 基线内容或 null
|
|
315
|
-
*/
|
|
316
|
-
async function p4Baseline(shell: ShellLike, root: string, depot: string): Promise<string | null> {
|
|
317
|
-
if (!depot.startsWith('//')) return null
|
|
318
|
-
const printed = await runCommand(shell, `p4 print -q ${quote(depot + '#have')}`, root)
|
|
319
|
-
if (printed.ok) return printed.stdout
|
|
320
|
-
if (P4_ABSENT_AT_REVISION.test(printed.stderr)) return null
|
|
321
|
-
throw new Error('读取 p4 基线失败:' + printed.stderr.slice(0, 200))
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* @author ddj 2026年10月30号
|
|
326
|
-
* @description: 解析 git status -z 输出;重命名/复制记录按目标路径处理。
|
|
327
|
-
* @param text -z 输出
|
|
328
|
-
* @returns 状态与仓库相对路径
|
|
329
|
-
*/
|
|
330
|
-
function parseGitStatus(text: string): Array<{ status: string; path: string }> {
|
|
331
|
-
const parts = text.split('\0').filter((part) => part.length > 2)
|
|
332
|
-
const entries: Array<{ status: string; path: string }> = []
|
|
333
|
-
for (let index = 0; index < parts.length; index++) {
|
|
334
|
-
const part = parts[index]!
|
|
335
|
-
const status = part.slice(0, 2)
|
|
336
|
-
const path = part.slice(3)
|
|
337
|
-
// 重命名/复制后紧跟原路径,跳过它
|
|
338
|
-
if (status.includes('R') || status.includes('C')) index++
|
|
339
|
-
entries.push({ status, path })
|
|
340
|
-
}
|
|
341
|
-
return entries
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* @author ddj 2026年10月30号
|
|
346
|
-
* @description: 解析 svn status --xml 输出。
|
|
347
|
-
* @param xml xml 文本
|
|
348
|
-
* @returns 条目状态与相对路径
|
|
349
|
-
*/
|
|
350
|
-
function parseSvnStatus(xml: string): Array<{ status: string; path: string }> {
|
|
351
|
-
const entries: Array<{ status: string; path: string }> = []
|
|
352
|
-
const pattern = /<entry\s+path="([^"]+)"([\s\S]*?)<\/entry>/g
|
|
353
|
-
for (const match of xml.matchAll(pattern)) {
|
|
354
|
-
const status = /<wc-status[^>]*\sitem="([^"]+)"/.exec(match[2] ?? '')?.[1]
|
|
355
|
-
if (status) entries.push({ status, path: decodeXml(match[1]!) })
|
|
356
|
-
}
|
|
357
|
-
return entries
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* @author ddj 2026年10月30号
|
|
362
|
-
* @description: 执行一条只读命令并收集输出;超时/取消/非零退出都回 ok=false,不抛出。
|
|
363
|
-
* @param shell shell 能力
|
|
364
|
-
* @param command 命令
|
|
365
|
-
* @param workdir 工作目录
|
|
366
|
-
* @param stdoutMaxBytes stdout 预算
|
|
367
|
-
* @returns 输出与状态
|
|
368
|
-
*/
|
|
369
|
-
async function runCommand(
|
|
370
|
-
shell: ShellLike, command: string, workdir: string, stdoutMaxBytes = STDOUT_BUDGET,
|
|
371
|
-
): Promise<{ ok: boolean; stdout: string; stderr: string }> {
|
|
372
|
-
try {
|
|
373
|
-
const spec = shell.resolve({ command, workdir, timeoutMs: COMMAND_TIMEOUT, stdoutMaxBytes })
|
|
374
|
-
const execution = await shell.execute(spec)
|
|
375
|
-
const result = await execution.result()
|
|
376
|
-
return {
|
|
377
|
-
ok: result.exitCode === 0 && !result.timedOut && !result.aborted,
|
|
378
|
-
stdout: result.stdout.text,
|
|
379
|
-
stderr: result.stderr.text,
|
|
380
|
-
}
|
|
381
|
-
} catch (error) {
|
|
382
|
-
return { ok: false, stdout: '', stderr: String(error) }
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* @author ddj 2026-11-24
|
|
388
|
-
* @description: 只读一条状态命令,取「工作副本相对基线有改动」的路径集合。补扫用它当候选与
|
|
389
|
-
* 「干净」判据:不在集合里的路径,其内容变化只能来自版本库同步,不该记成 agent 改动。
|
|
390
|
-
* 非 git/svn(含 Perforce 与无版本库)一律返回 null,由调用方降级为「只对齐已记录条目」。
|
|
391
|
-
* @param shell shell 能力
|
|
392
|
-
* @param cwd 工作区
|
|
393
|
-
* @param onFailure 失败原因回调(可选):调用方用它把「为什么没有状态」写进采集缺口
|
|
394
|
-
* @returns 状态集合或 null
|
|
395
|
-
*/
|
|
396
|
-
export async function vcsStatus(
|
|
397
|
-
shell: ShellLike, cwd: string, onFailure?: (reason: string) => void,
|
|
398
|
-
): Promise<VcsStatus | null> {
|
|
399
|
-
const detected = await detectVcsRoot(cwd)
|
|
400
|
-
if (!detected) {
|
|
401
|
-
onFailure?.('不是 git/svn 工作副本')
|
|
402
|
-
return null
|
|
403
|
-
}
|
|
404
|
-
if (detected.kind === 'p4') {
|
|
405
|
-
onFailure?.('Perforce 工作副本不支持状态探测')
|
|
406
|
-
return null
|
|
407
|
-
}
|
|
408
|
-
return detected.kind === 'git' ? gitStatus(shell, detected.root, onFailure) : svnStatus(shell, detected.root, onFailure)
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* @private
|
|
413
|
-
* @author ddj 2026-11-24
|
|
414
|
-
* @description: git 状态:一条 status 命令解析出改动集合。
|
|
415
|
-
* @param shell shell 能力
|
|
416
|
-
* @param root 仓库根
|
|
417
|
-
* @param onFailure 失败原因回调(可选)
|
|
418
|
-
* @returns 状态集合或 null(命令失败)
|
|
419
|
-
*/
|
|
420
|
-
async function gitStatus(shell: ShellLike, root: string, onFailure?: (reason: string) => void): Promise<VcsStatus | null> {
|
|
421
|
-
const status = await runCommand(shell, 'git -c status.renames=false status --porcelain=v1 -z --untracked-files=all', root)
|
|
422
|
-
if (!status.ok) {
|
|
423
|
-
onFailure?.('git status 失败:' + status.stderr.slice(0, 200))
|
|
424
|
-
return null
|
|
425
|
-
}
|
|
426
|
-
const entries = new Map<string, VcsEntry>()
|
|
427
|
-
for (const entry of parseGitStatus(status.stdout)) {
|
|
428
|
-
const absolute = join(root, ...entry.path.split(GIT_SEPARATOR))
|
|
429
|
-
if (!insideRoot(root, absolute)) continue
|
|
430
|
-
entries.set(pathKeyOf(absolute), { path: absolute, status: gitStatusOf(entry.status) })
|
|
431
|
-
}
|
|
432
|
-
return { kind: 'git', root, entries }
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* @private
|
|
437
|
-
* @author ddj 2026-11-24
|
|
438
|
-
* @description: svn 状态:一条 status --xml 解析出改动集合。
|
|
439
|
-
* @param shell shell 能力
|
|
440
|
-
* @param root 工作副本根
|
|
441
|
-
* @param onFailure 失败原因回调(可选)
|
|
442
|
-
* @returns 状态集合或 null(命令失败)
|
|
443
|
-
*/
|
|
444
|
-
async function svnStatus(shell: ShellLike, root: string, onFailure?: (reason: string) => void): Promise<VcsStatus | null> {
|
|
445
|
-
const status = await runCommand(shell, 'svn status --xml', root)
|
|
446
|
-
if (!status.ok) {
|
|
447
|
-
onFailure?.('svn status 失败:' + status.stderr.slice(0, 200))
|
|
448
|
-
return null
|
|
449
|
-
}
|
|
450
|
-
const entries = new Map<string, VcsEntry>()
|
|
451
|
-
for (const entry of parseSvnStatus(status.stdout)) {
|
|
452
|
-
const absolute = resolve(root, entry.path)
|
|
453
|
-
if (!insideRoot(root, absolute)) continue
|
|
454
|
-
entries.set(pathKeyOf(absolute), { path: absolute, status: svnStatusOf(entry.status) })
|
|
455
|
-
}
|
|
456
|
-
return { kind: 'svn', root, entries }
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* @private
|
|
461
|
-
* @author ddj 2026-11-24
|
|
462
|
-
* @description: git 状态码归一:删除优先,其次新增/未跟踪,其余按修改。
|
|
463
|
-
* @param status 两位状态码
|
|
464
|
-
* @returns 归一状态
|
|
465
|
-
*/
|
|
466
|
-
function gitStatusOf(status: string): VcsEntryStatus {
|
|
467
|
-
if (status.includes('D')) return 'deleted'
|
|
468
|
-
if (status === '??' || status.includes('A')) return 'added'
|
|
469
|
-
return 'modified'
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* @private
|
|
474
|
-
* @author ddj 2026-11-24
|
|
475
|
-
* @description: svn 条目状态归一。
|
|
476
|
-
* @param status wc-status 的 item 值
|
|
477
|
-
* @returns 归一状态
|
|
478
|
-
*/
|
|
479
|
-
function svnStatusOf(status: string): VcsEntryStatus {
|
|
480
|
-
if (status === 'deleted' || status === 'missing') return 'deleted'
|
|
481
|
-
if (status === 'added' || status === 'unversioned' || status === 'replaced') return 'added'
|
|
482
|
-
return 'modified'
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* @author ddj 2026-11-24
|
|
487
|
-
* @description: 读某路径的版本库基线内容;只用于补录记录的修改前内容。
|
|
488
|
-
* @param shell shell 能力
|
|
489
|
-
* @param status 已探测的状态(给根目录与种类)
|
|
490
|
-
* @param absolute 绝对路径
|
|
491
|
-
* @returns 基线内容;读不到返回 null
|
|
492
|
-
*/
|
|
493
|
-
export async function vcsBaselineOf(
|
|
494
|
-
shell: ShellLike, status: Pick<VcsStatus, 'kind' | 'root'>, absolute: string,
|
|
495
|
-
): Promise<string | null> {
|
|
496
|
-
const root = status.root
|
|
497
|
-
const relative = absolute.slice(root.length).replace(/^[\\/]+/, '').split(sep).join(GIT_SEPARATOR)
|
|
498
|
-
if (!relative) return null
|
|
499
|
-
try {
|
|
500
|
-
if (status.kind === 'git') return await gitBaseline(shell, root, relative)
|
|
501
|
-
const shown = await runCommand(shell, `svn cat -r BASE ${quote(absolute)}`, root)
|
|
502
|
-
return shown.ok ? shown.stdout : null
|
|
503
|
-
} catch {
|
|
504
|
-
return null
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* @author ddj 2026年10月30号
|
|
510
|
-
* @description: 读单元格文本,不存在时返回 null。
|
|
511
|
-
* @param path 文件路径
|
|
512
|
-
* @returns 内容或 null
|
|
513
|
-
*/
|
|
514
|
-
async function readTextOf(path: string): Promise<string | null> {
|
|
515
|
-
try {
|
|
516
|
-
const fileStat = await stat(path)
|
|
517
|
-
if (!fileStat.isFile()) return null
|
|
518
|
-
return await readFile(path, 'utf8')
|
|
519
|
-
} catch {
|
|
520
|
-
return null
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* @author ddj 2026年10月30号
|
|
526
|
-
* @description: 判断路径是否存在。
|
|
527
|
-
* @param path 路径
|
|
528
|
-
* @returns 是否存在
|
|
529
|
-
*/
|
|
530
|
-
async function exists(path: string): Promise<boolean> {
|
|
531
|
-
try {
|
|
532
|
-
await stat(path)
|
|
533
|
-
return true
|
|
534
|
-
} catch {
|
|
535
|
-
return false
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* @author ddj 2026年10月30号
|
|
541
|
-
* @description: 判断目标是否位于仓库根之内(Windows 下按大小写不敏感比较)。
|
|
542
|
-
* @param root 仓库根
|
|
543
|
-
* @param target 目标绝对路径
|
|
544
|
-
* @returns 是否在根内
|
|
545
|
-
*/
|
|
546
|
-
function insideRoot(root: string, target: string): boolean {
|
|
547
|
-
const normalize = (value: string) => (process.platform === 'win32' ? value.toLowerCase() : value)
|
|
548
|
-
const rootKey = normalize(resolve(root)).replace(/[\\/]+$/, '') + sep
|
|
549
|
-
return normalize(resolve(target)).startsWith(rootKey)
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* @author ddj 2026年10月30号
|
|
554
|
-
* @description: 比较两个路径是否同一文件(Windows 下大小写不敏感)。
|
|
555
|
-
* @param left 路径
|
|
556
|
-
* @param right 路径
|
|
557
|
-
* @returns 是否相同
|
|
558
|
-
*/
|
|
559
|
-
function samePath(left: string, right: string): boolean {
|
|
560
|
-
const normalize = (value: string) => (process.platform === 'win32' ? value.toLowerCase() : value)
|
|
561
|
-
return normalize(resolve(left)) === normalize(resolve(right))
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* @author ddj 2026年10月30号
|
|
566
|
-
* @description: 为 shell 命令参数加引号,避免空格与特殊字符改变命令含义。
|
|
567
|
-
* @param value 参数
|
|
568
|
-
* @returns 加引号后的参数
|
|
569
|
-
*/
|
|
570
|
-
function quote(value: string): string {
|
|
571
|
-
return '"' + value.replace(/"/g, '\\"') + '"'
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* @author ddj 2026年10月30号
|
|
576
|
-
* @description: 还原 xml 实体(svn status 会转义非 ASCII 与空格)。
|
|
577
|
-
* @param value 属性值
|
|
578
|
-
* @returns 解码后的路径
|
|
579
|
-
*/
|
|
580
|
-
function decodeXml(value: string): string {
|
|
581
|
-
return value
|
|
582
|
-
.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
583
|
-
.replace(/'/g, "'").replace(/&/g, '&')
|
|
584
|
-
}
|