feat: add project index and exact patch review
This commit is contained in:
+11
-5
@@ -1,6 +1,6 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { listFiles, readText, proposeFile, applyChange } from './files.mjs';
|
||||
import { listFiles, readText, proposeFile, proposePatch, applyChange } from './files.mjs';
|
||||
import { APP_VERSION, executionEnvironment, sessionSnapshot } from './diagnostics.mjs';
|
||||
import { inspectProject } from '../core/project-inspector.mjs';
|
||||
|
||||
@@ -71,7 +71,7 @@ return async (request, response) => {
|
||||
eventCursor: store.eventCursor, storage: store.storageInfo(), runtimeRoot: appDirectory,
|
||||
environment: executionEnvironment(),
|
||||
projects: store.projects, sessions: store.listSessions(), exampleProjectId: exampleProject?.id ?? null,
|
||||
capabilities: { fileChanges: 'review', commands: 'per-call-approval', recovery: 'durable-tool-results', model: 'chat-completions-compatible', execution: 'task-run-step', events: 'persistent-cursor', artifacts: 'sha256-verified', checks: 'npm-script-jobs', projectInspection: 'bounded-source-and-git', gitDelivery: 'reviewed-local-snapshot', deliveryReports: 'evidence-json-markdown' },
|
||||
capabilities: { fileChanges: 'review', exactPatches: 'sha256-unique-anchors', codeIndex: 'bounded-ast-and-candidates', commands: 'per-call-approval', recovery: 'durable-tool-results', model: 'chat-completions-compatible', execution: 'task-run-step', events: 'persistent-cursor', artifacts: 'sha256-verified', checks: 'npm-script-jobs', projectInspection: 'bounded-source-and-git', gitDelivery: 'reviewed-local-snapshot', deliveryReports: 'evidence-json-markdown' },
|
||||
});
|
||||
if (method === 'GET' && route === '/api/diagnostics') {
|
||||
const selected = url.searchParams.get('session');
|
||||
@@ -117,10 +117,15 @@ return async (request, response) => {
|
||||
if (typeof input.root !== 'string' || input.root.length > 2000) throw new Error('请输入项目文件夹的完整路径。');
|
||||
return json(response, store.addProject(input.root), 201);
|
||||
}
|
||||
const projectMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/(files|file|inspection)$/);
|
||||
const projectMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/(files|file|inspection|code-index|code-query)$/);
|
||||
if (method === 'GET' && projectMatch) {
|
||||
const project = store.project(projectMatch[1]);
|
||||
if (projectMatch[2] === 'inspection') return json(response, await inspectProject(project));
|
||||
if (['code-index', 'code-query'].includes(projectMatch[2])) {
|
||||
const indexer = runtime.projectIndexer(), index = await indexer.refresh(project);
|
||||
return json(response, projectMatch[2] === 'code-index' ? indexer.summary(index) : indexer.query(index,
|
||||
{ query: url.searchParams.get('query') ?? '', kind: url.searchParams.get('kind') ?? 'all', limit: url.searchParams.has('limit') ? Number(url.searchParams.get('limit')) : 30 }));
|
||||
}
|
||||
return json(response, projectMatch[2] === 'files'
|
||||
? listFiles(project, url.searchParams.get('path') || '', 7, 1200)
|
||||
: readText(project, url.searchParams.get('path') || ''));
|
||||
@@ -227,10 +232,11 @@ return async (request, response) => {
|
||||
}
|
||||
return json(response, store.publicSession(session));
|
||||
}
|
||||
if (method === 'POST' && action === 'proposals') {
|
||||
if (method === 'POST' && ['proposals', 'patch-proposals'].includes(action)) {
|
||||
const input = await body(request);
|
||||
if (runtime.checks?.projectActive(session.projectId) || runtime.deliveries?.projectActive(session.projectId)) throw Object.assign(new Error('工程检查或Git交付正在执行,请等待结束后再编辑文件。'), { status: 409 });
|
||||
proposeFile(store, session, input);
|
||||
if (action === 'patch-proposals') proposePatch(store, session, input);
|
||||
else proposeFile(store, session, input);
|
||||
return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user