feat: add reviewed Task Git delivery and verified evidence reports

This commit is contained in:
Agent Workbench Dev
2026-10-29 16:41:03 +08:00
parent 3781591f97
commit 73758985ee
50 changed files with 1964 additions and 69 deletions
+16 -8
View File
@@ -1,17 +1,18 @@
import fs from 'node:fs';
import path from 'node:path';
import { execFile } from 'node:child_process';
import { createHash } from 'node:crypto';
import { listFiles, safePath, readText } from '../server/files.mjs';
import { runGit } from './git-process.mjs';
const hash = value => createHash('sha256').update(value).digest('hex');
const languages = { '.js': 'JavaScript', '.mjs': 'JavaScript', '.cjs': 'JavaScript', '.ts': 'TypeScript', '.tsx': 'TypeScript', '.jsx': 'JavaScript', '.py': 'Python', '.go': 'Go', '.rs': 'Rust', '.cs': 'C#', '.vue': 'Vue', '.html': 'HTML', '.css': 'CSS' };
const recognizedScripts = /^(test(?::[a-z0-9_-]+)?|typecheck|check|lint|build)$/i;
function gitCommand(root, args) {
const env = { ...process.env, GIT_OPTIONAL_LOCKS: '0' };
for (const key of Object.keys(env)) if (/^GIT_(DIR|WORK_TREE|INDEX_FILE|CONFIG|COMMON_DIR|OBJECT_DIRECTORY|ALTERNATE_OBJECT_DIRECTORIES)/i.test(key) || key === 'AGENT_WORKBENCH_API_KEY') delete env[key];
return new Promise(resolve => execFile('git', ['--no-optional-locks', '-C', root, ...args], { windowsHide: true, timeout: 5000, maxBuffer: 512000, env, encoding: 'utf8' }, (error, stdout) => resolve({ ok: !error, output: stdout || '', error: error?.code ?? null })));
async function gitCommand(root, args) {
try {
const result = await runGit(root, args, { timeoutMs: 5000, maximumBytes: 512000 });
return { ok: result.ok, output: result.text, error: result.ok ? null : result.code };
} catch (error) { return { ok: false, output: '', error: error.code ?? 'git-unavailable' }; }
}
export async function gitBaseline(project) {
@@ -56,13 +57,18 @@ export async function inspectProject(project) {
let bytes = 0, complete = git.complete && !inventory?.truncated && candidates.length <= 1000;
for (const relative of candidates.slice(0, 1000)) {
try {
const file = safePath(project, relative), info = fs.lstatSync(file);
const file = safePath(project, relative, true);
if (!fs.existsSync(file)) { fingerprints.push([relative, 'missing']); continue; }
const info = fs.lstatSync(file);
if (!info.isFile() || info.isSymbolicLink()) { excluded.push(relative); continue; }
names.push(relative);
const language = languages[path.extname(relative).toLowerCase()]; if (language) detected.add(language);
if (info.size > 1024 * 1024 || bytes + info.size > 16 * 1024 * 1024) { complete = false; fingerprints.push([relative, info.size, 'outside-read-budget']); continue; }
const contents = fs.readFileSync(file); bytes += contents.length; fingerprints.push([relative, hash(contents)]);
} catch { excluded.push(relative); }
} catch (error) {
excluded.push(relative);
if (error.message !== '该路径不在可读取的项目范围内。') { complete = false; fingerprints.push([relative, 'unreadable']); }
}
}
const packageFile = declaration(project, 'package.json');
let manifest = null;
@@ -85,11 +91,13 @@ export async function inspectProject(project) {
}
const fingerprint = hash(JSON.stringify({ projectId: project.id, root, files: fingerprints, packageSha256: packageFile?.sha256 ?? null,
head: git.head, gitStatus: git.statusSha256 ?? null, complete }));
const sourceFingerprint = hash(JSON.stringify({ projectId: project.id, root, files: fingerprints,
packageSha256: packageFile?.sha256 ?? null, complete }));
const { paths, ...visibleGit } = git;
return { projectId: project.id, name: typeof manifest?.name === 'string' ? manifest.name.slice(0, 150) : project.name,
languages: [...detected].sort(), packageManager, scripts, rules, declarations,
entryPoints: [manifest?.main, typeof manifest?.bin === 'string' ? manifest.bin : null, names.includes('src/index.ts') ? 'src/index.ts' : null, names.includes('src/index.mjs') ? 'src/index.mjs' : null].filter(value => typeof value === 'string').slice(0, 5),
git: visibleGit, fingerprint, inspectedAt: new Date().toISOString(),
git: visibleGit, fingerprint, sourceFingerprint, inspectedAt: new Date().toISOString(),
scope: { complete, scannedFiles: fingerprints.length, bytes, excludedFiles: excluded.length, maximumFiles: 1000, maximumBytes: 16 * 1024 * 1024,
note: '有界快照;Git工程遵循ignore并包含未跟踪源码,跳过依赖、链接和常见凭据路径。' } };
}