dsh-spec-collab 0.2.0 → 0.2.2
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 +35 -0
- package/docs/experience-review-checklist-2026-08-24.md +115 -0
- package/lib/client.js +1391 -388
- package/lib/index.js +408 -50
- package/lib/types/client/SpecWorkbench.d.ts +69 -0
- package/lib/types/client/SpecWorkbench.d.ts.map +1 -1
- package/lib/types/client/mount.d.ts.map +1 -1
- package/lib/types/client/review-anchors.d.ts +21 -0
- package/lib/types/client/review-anchors.d.ts.map +1 -0
- package/lib/types/client/workflow.d.ts +1 -0
- package/lib/types/client/workflow.d.ts.map +1 -1
- package/lib/types/engine.d.ts.map +1 -1
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/prompts.d.ts +18 -0
- package/lib/types/prompts.d.ts.map +1 -0
- package/lib/types/protocol.d.ts +7 -0
- package/lib/types/protocol.d.ts.map +1 -1
- package/lib/types/review-context.d.ts +10 -1
- package/lib/types/review-context.d.ts.map +1 -1
- package/lib/types/review-runtime.d.ts +4 -1
- package/lib/types/review-runtime.d.ts.map +1 -1
- package/lib/types/workspace-context.d.ts +2 -0
- package/lib/types/workspace-context.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/client/SpecWorkbench.tsx +456 -47
- package/src/client/mount.tsx +31 -5
- package/src/client/review-anchors.ts +134 -0
- package/src/client/workbench.module.css +234 -45
- package/src/client/workflow.ts +7 -7
- package/src/engine.ts +46 -3
- package/src/index.ts +21 -3
- package/src/prompts.ts +100 -0
- package/src/protocol.ts +4 -2
- package/src/review-context.ts +25 -7
- package/src/review-runtime.ts +53 -34
- package/src/tools.ts +3 -3
- package/src/workspace-context.ts +114 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { readdir, readFile, stat } from 'node:fs/promises'
|
|
2
|
+
import { extname, isAbsolute, relative, resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
const MAX_FILES = 20
|
|
5
|
+
const MAX_FILE_BYTES = 16 * 1024
|
|
6
|
+
const MAX_TOTAL_BYTES = 64 * 1024
|
|
7
|
+
const MAX_DIRECTORY_DEPTH = 4
|
|
8
|
+
const MAX_ROOT_ENTRIES = 80
|
|
9
|
+
|
|
10
|
+
const PROJECT_CONTEXT_FILES = new Set([
|
|
11
|
+
'agents.md', 'context.md', 'contributing.md', 'package.json', 'pyproject.toml', 'cargo.toml',
|
|
12
|
+
'go.mod', 'pom.xml', 'build.gradle', 'build.gradle.kts', 'requirements.txt', 'gemfile',
|
|
13
|
+
])
|
|
14
|
+
const TEXT_EXTENSIONS = new Set([
|
|
15
|
+
'.md', '.mdx', '.txt', '.json', '.jsonc', '.yaml', '.yml', '.toml', '.xml', '.ini', '.cfg',
|
|
16
|
+
'.conf', '.properties', '.gradle', '.kts', '.mod', '.rst', '.adoc',
|
|
17
|
+
])
|
|
18
|
+
const SKIP_DIRECTORIES = new Set(['.git', 'node_modules', 'dist', 'build', 'lib', 'coverage', '.next', '.cache'])
|
|
19
|
+
|
|
20
|
+
interface CandidateFile { path: string; displayPath: string }
|
|
21
|
+
|
|
22
|
+
export async function readWorkspaceSnapshot(workspaceRoot: string, documentPaths: string[]): Promise<string> {
|
|
23
|
+
const root = resolve(workspaceRoot)
|
|
24
|
+
const rows = ['## 插件已读取的工作区快照', `工作区根目录:\`${root}\``]
|
|
25
|
+
const notices: string[] = []
|
|
26
|
+
const candidates: CandidateFile[] = []
|
|
27
|
+
const seen = new Set<string>()
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const rootEntries = await readdir(root, { withFileTypes: true })
|
|
31
|
+
const visibleEntries = rootEntries
|
|
32
|
+
.filter(entry => !SKIP_DIRECTORIES.has(entry.name))
|
|
33
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
34
|
+
.slice(0, MAX_ROOT_ENTRIES)
|
|
35
|
+
.map(entry => entry.isDirectory() ? `${entry.name}/` : entry.name)
|
|
36
|
+
rows.push(`根目录条目:${visibleEntries.join('、') || '空目录'}`)
|
|
37
|
+
for (const entry of rootEntries) {
|
|
38
|
+
if (!entry.isFile() || !isProjectContextFile(entry.name)) continue
|
|
39
|
+
addCandidate(candidates, seen, resolve(root, entry.name), entry.name)
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
rows.push('根目录条目:无法读取')
|
|
43
|
+
notices.push(`- 工作区根目录无法读取:${errorMessage(error)}`)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const configuredPath of documentPaths) {
|
|
47
|
+
const path = isAbsolute(configuredPath) ? resolve(configuredPath) : resolve(root, configuredPath)
|
|
48
|
+
const displayPath = displayWorkspacePath(root, path)
|
|
49
|
+
try {
|
|
50
|
+
const value = await stat(path)
|
|
51
|
+
if (value.isFile()) addCandidate(candidates, seen, path, displayPath)
|
|
52
|
+
else if (value.isDirectory()) await collectDirectory(path, root, candidates, seen, 0)
|
|
53
|
+
else notices.push(`- 无法读取 \`${displayPath}\`:不是普通文件或目录。`)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
notices.push(`- 无法读取 \`${displayPath}\`:${errorMessage(error)}`)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let totalBytes = 0
|
|
60
|
+
let renderedFiles = 0
|
|
61
|
+
for (const candidate of candidates) {
|
|
62
|
+
if (renderedFiles >= MAX_FILES || totalBytes >= MAX_TOTAL_BYTES) break
|
|
63
|
+
try {
|
|
64
|
+
const buffer = await readFile(candidate.path)
|
|
65
|
+
if (buffer.subarray(0, Math.min(buffer.length, 4096)).includes(0)) {
|
|
66
|
+
notices.push(`- 跳过二进制文件 \`${candidate.displayPath}\`。`)
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const availableBytes = Math.min(MAX_FILE_BYTES, MAX_TOTAL_BYTES - totalBytes)
|
|
70
|
+
const content = buffer.subarray(0, availableBytes).toString('utf8')
|
|
71
|
+
const truncated = buffer.length > availableBytes
|
|
72
|
+
rows.push('', `### \`${candidate.displayPath}\``, '<workspace-file>', content, truncated ? '\n[内容已截断]' : '', '</workspace-file>')
|
|
73
|
+
totalBytes += Buffer.byteLength(content)
|
|
74
|
+
renderedFiles += 1
|
|
75
|
+
} catch (error) {
|
|
76
|
+
notices.push(`- 无法读取 \`${candidate.displayPath}\`:${errorMessage(error)}`)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (candidates.length > renderedFiles) notices.push(`- 工作区快照达到上限,仅注入前 ${renderedFiles} 个可读文本文件。`)
|
|
80
|
+
if (renderedFiles === 0) rows.push('', '未发现可注入的标准项目上下文文件。')
|
|
81
|
+
if (notices.length > 0) rows.push('', '### 读取说明', ...notices)
|
|
82
|
+
return rows.join('\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function collectDirectory(directory: string, root: string, candidates: CandidateFile[], seen: Set<string>, depth: number): Promise<void> {
|
|
86
|
+
if (depth > MAX_DIRECTORY_DEPTH || candidates.length >= MAX_FILES) return
|
|
87
|
+
const entries = await readdir(directory, { withFileTypes: true })
|
|
88
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
89
|
+
if (candidates.length >= MAX_FILES) return
|
|
90
|
+
const path = resolve(directory, entry.name)
|
|
91
|
+
if (entry.isDirectory() && !SKIP_DIRECTORIES.has(entry.name)) await collectDirectory(path, root, candidates, seen, depth + 1)
|
|
92
|
+
else if (entry.isFile() && isTextFile(entry.name)) addCandidate(candidates, seen, path, displayWorkspacePath(root, path))
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function addCandidate(candidates: CandidateFile[], seen: Set<string>, path: string, displayPath: string): void {
|
|
97
|
+
if (seen.has(path) || candidates.length >= MAX_FILES) return
|
|
98
|
+
seen.add(path)
|
|
99
|
+
candidates.push({ path, displayPath })
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function isProjectContextFile(name: string): boolean {
|
|
103
|
+
const lower = name.toLowerCase()
|
|
104
|
+
return PROJECT_CONTEXT_FILES.has(lower) || lower === 'readme' || lower.startsWith('readme.')
|
|
105
|
+
}
|
|
106
|
+
function isTextFile(name: string): boolean { return isProjectContextFile(name) || TEXT_EXTENSIONS.has(extname(name).toLowerCase()) }
|
|
107
|
+
function displayWorkspacePath(root: string, path: string): string {
|
|
108
|
+
const value = relative(root, path)
|
|
109
|
+
return value !== '' && !value.startsWith('..') ? value : path
|
|
110
|
+
}
|
|
111
|
+
function errorMessage(error: unknown): string {
|
|
112
|
+
if (error instanceof Error && 'code' in error && typeof error.code === 'string') return error.code
|
|
113
|
+
return error instanceof Error ? error.message : String(error)
|
|
114
|
+
}
|