feat: add durable isolated Git workspaces and source-bound delivery

This commit is contained in:
Agent Workbench Dev
2026-10-29 23:22:30 +08:00
parent 7d60dc9c55
commit 7d9bfb85da
22 changed files with 1038 additions and 26 deletions
+4
View File
@@ -4,6 +4,7 @@ import { createHash, randomUUID } from 'node:crypto';
import { diffLines } from 'diff';
import { now } from './store.mjs';
import { assertChangeSetsResolved, assertProposalUnsealed } from '../shared/contracts/change-sets.mjs';
import { assertWorkspacePath, assertWorkspacesResolved } from '../shared/contracts/workspaces.mjs';
export const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const ignored = new Set(['node_modules', '.git', '.next', '.data', 'bin', 'obj', 'dist', 'dist-client', 'dist-server', '__pycache__']);
@@ -17,6 +18,7 @@ export function excludedFromInventory(relative) {
}
export function safePath(project, relative = '', allowMissing = false) {
assertWorkspacePath(project);
if (typeof relative !== 'string' || relative.includes('\0') || relative.includes(':') || path.isAbsolute(relative) || path.win32.isAbsolute(relative)) throw new Error('路径必须相对于项目文件夹。');
const portable = relative.replaceAll('\\', '/');
if (portable.split('/').includes('..') || secretName.test(portable) || portable.split('/').some(part => part.toLowerCase() === '.git')) throw new Error('该路径不在可读取的项目范围内。');
@@ -111,6 +113,7 @@ export function searchFiles(project, args) {
export function proposeFile(store, session, args, { patch = null } = {}) {
assertChangeSetsResolved(store, session.projectId);
assertWorkspacesResolved(store, session.projectId, { includePrepared: true });
if (typeof args.path !== 'string' || typeof args.content !== 'string') throw new Error('文件提案需要文本路径和完整文本内容。');
const project = store.project(session.projectId);
const target = safePath(project, args.path, true);
@@ -173,6 +176,7 @@ export function proposePatch(store, session, args) {
export function applyChange(store, session, id) {
assertChangeSetsResolved(store, session.projectId);
assertWorkspacesResolved(store, session.projectId, { includePrepared: true });
const change = session.changes.find(item => item.id === id);
if (!change || change.status !== 'pending') throw new Error('这项改动不处于待审查状态。');
assertProposalUnsealed(store, change);