✨ feat(vscode): 提交代码按钮实时显示进度并预检 git 身份

- spawnClaude 新增 onProgress 回调,给了回调就改走 stream-json 逐行输出,按行解析出工具调用 / 回复文本
- 新增 claudeProgress 把每行 NDJSON 压成可读进度短语
- 提交前先读 git user.name / user.email,缺失直接提示,不再让 claude 白跑
- 运行期间用带转圈的 toast 滚动显示进度,完成后带上 claude 的结果摘要

Claude-Session: https://claude.ai/code/session_01HTMgwaE3woqM5yvsHiuSAa
This commit is contained in:
cruldra committed 2026-08-31 22:11:09 +08:00
1 parent 443a8e472a
commit 73a0c46f9f
6 files changed
+322 -25

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest'
import { missingGitIdentityKeys } from './identity'
describe('missingGitIdentityKeys', () => {
it('两项都有时返回空', () => {
expect(missingGitIdentityKeys({ name: 'cruldra', email: 'a@b.c' })).toEqual([])
})
it('缺 name', () => {
expect(missingGitIdentityKeys({ name: '', email: 'a@b.c' })).toEqual(['user.name'])
})
it('缺 email', () => {
expect(missingGitIdentityKeys({ name: 'cruldra', email: '' })).toEqual(['user.email'])
})
it('两项都缺,顺序固定', () => {
expect(missingGitIdentityKeys({ name: '', email: '' })).toEqual(['user.name', 'user.email'])
})
it('只有空白也算缺失', () => {
expect(missingGitIdentityKeys({ name: ' \n', email: '\t' })).toEqual(['user.name', 'user.email'])
})
})
+46
View File
@@ -0,0 +1,46 @@
/**
* 读取当前仓库生效的 git 提交者身份(user.name / user.email)。
*
* 提交代码前先查一遍:身份缺失时 git commit 会直接失败,与其让后台 claude
* 跑十几分钟后才报错,不如一开始就把话说清楚。
*/
import { execFile } from 'node:child_process'
export interface GitIdentity {
name: string
email: string
}
export type GitIdentityKey = 'user.name' | 'user.email'
export function missingGitIdentityKeys(identity: GitIdentity): GitIdentityKey[] {
const missing: GitIdentityKey[] = []
if (!identity.name.trim())
missing.push('user.name')
if (!identity.email.trim())
missing.push('user.email')
return missing
}
function readGitConfig(cwd: string, key: GitIdentityKey): Promise<string> {
return new Promise<string>((resolve) => {
execFile(
'git',
['-C', cwd, 'config', '--get', key],
{ timeout: 10_000, encoding: 'utf8' },
(err, stdout) => {
// 未设置该项时 git 以退出码 1 结束且无输出,视同空串即可
resolve(err ? '' : (stdout ?? '').trim())
},
)
})
}
export async function readGitIdentity(cwd: string): Promise<GitIdentity> {
const [name, email] = await Promise.all([
readGitConfig(cwd, 'user.name'),
readGitConfig(cwd, 'user.email'),
])
return { name, email }
}