@feng0531/dsh-code-review 0.21.1 → 0.22.1
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/CHANGELOG.md +10 -0
- package/README.md +3 -1
- package/index.mjs +2 -2
- package/package.json +1 -1
- package/src/git-history.mjs +10 -1
- package/src/review.mjs +2 -0
- package/src/service.mjs +2 -2
- package/src/snapshot.mjs +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.22.1
|
|
4
|
+
|
|
5
|
+
- 历史显式/自动直接导入上下文仅捕获目标树普通blob,20总量/原文件与快照预算、显式去重、阻塞可见;不读工作树。
|
|
6
|
+
- 未选/阻塞/删除变更不可重新作为上下文,历史规则继续拒绝。真实Git隔离/去重/哈希/限额及全量252、宿主离线通过。
|
|
7
|
+
|
|
8
|
+
## 0.22.0
|
|
9
|
+
|
|
10
|
+
- 工具注册Git指定提交/区间,预览及JSON/Markdown报告展示解析端点和精确树语义,原快照哈希/Agent再验证保留。
|
|
11
|
+
- 历史上下文/规则明确拒绝避免混入工作树,SVN明确不支持。真实服务零发送预览/脏树隔离执行、全量251及宿主离线通过。
|
|
12
|
+
|
|
3
13
|
## 0.21.1
|
|
4
14
|
|
|
5
15
|
- 新增低层不可变Git commit/range对象快照,不读工作树;根提交空侧,merge要求明确区间,端点树差异、重命名按增删表达。
|
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
## 当前状态
|
|
6
6
|
|
|
7
|
-
当前代码版本为 0.
|
|
7
|
+
当前代码版本为 0.22.1
|
|
8
|
+
|
|
9
|
+
Git历史审查预览传 `commit`(相对唯一父提交,根提交空旧侧;merge需区间),或 `baseRevision` 与 `targetRevision`(精确端点树差异,非merge-base);两类互斥。预览/报告显示解析对象ID,执行复捕获hash验证引用变化。历史显式/自动直接导入上下文只捕获目标提交树普通blob,默认20总量且排除变更不能再进入;历史规则暂明确拒绝,不混工作树,SVN不冒充此语义。
|
|
8
10
|
|
|
9
11
|
工具对错误行锚可进行一次同文件同侧唯一完整原文纠正,须重叠原引用精确编辑;原候选/状态保留JSON,Markdown提示。纠正后仍校验窗口、跨文件编辑及生成读取证据,不增调用、不猜歧义或跨文件迁移,不证明缺陷或因果。
|
|
10
12
|
|
package/index.mjs
CHANGED
|
@@ -11,8 +11,8 @@ export function apply(ctx, config = {}) {
|
|
|
11
11
|
render: (_args, value) => [{ type: 'text', text: value.markdown || value.json }],
|
|
12
12
|
};
|
|
13
13
|
ctx.tools.register({
|
|
14
|
-
name: 'code_review_preview', description: 'Preview Git/SVN working-copy review scope and model destination without sending source to a model. repositoryPath selects an explicit child repository relative to session workspace; file paths are repository-relative. Preview each repository separately. Show the preview before execution.',
|
|
15
|
-
parameters: { type: 'object', additionalProperties: false, properties: { repositoryPath: { type: 'string', description: 'Workspace-relative explicit child Git/SVN repository root, forward slashes; omit for current repository.' }, selectedPaths: { type: 'array', items: { type: 'string' }, maxItems: 200 }, autoContext: { type: 'boolean', description: 'Opt in to bounded direct tracked Git/SVN import/include context captured and shown in preview.' }, contextPaths: { type: 'array', items: { type: 'string' }, maxItems: 20 }, rulePaths: { type: 'array', items: { type: 'string' }, maxItems: 4 } } },
|
|
14
|
+
name: 'code_review_preview', description: 'Preview Git/SVN working-copy or Git commit/range review scope and model destination without sending source to a model. repositoryPath selects an explicit child repository relative to session workspace; file paths are repository-relative. Preview each repository separately. Show the preview before execution.',
|
|
15
|
+
parameters: { type: 'object', additionalProperties: false, properties: { commit: { type: 'string', description: 'Git commit versus sole parent; root empty, merge requires range.' }, baseRevision: { type: 'string', description: 'Git old endpoint; requires targetRevision, mutually exclusive with commit.' }, targetRevision: { type: 'string', description: 'Git new endpoint, exact tree endpoints not merge-base. Context is captured from target tree only; historical rules rejected.' }, repositoryPath: { type: 'string', description: 'Workspace-relative explicit child Git/SVN repository root, forward slashes; omit for current repository.' }, selectedPaths: { type: 'array', items: { type: 'string' }, maxItems: 200 }, autoContext: { type: 'boolean', description: 'Opt in to bounded direct tracked Git/SVN import/include context captured and shown in preview.' }, contextPaths: { type: 'array', items: { type: 'string' }, maxItems: 20 }, rulePaths: { type: 'array', items: { type: 'string' }, maxItems: 4 } } },
|
|
16
16
|
output,
|
|
17
17
|
async execute(args, exec) { const preview = await service.preview(args, exec); return { json: JSON.stringify(preview), markdown: '' }; },
|
|
18
18
|
});
|
package/package.json
CHANGED
package/src/git-history.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {contextCandidates} from './context-candidates.mjs';
|
|
1
2
|
import {realpath} from 'node:fs/promises';
|
|
2
3
|
import {checked} from './process.mjs';
|
|
3
4
|
import {hash,decode,relativePath} from './content.mjs';
|
|
@@ -17,5 +18,13 @@ export async function captureGitHistory(cwd, options={}) {
|
|
|
17
18
|
const left=await tree(base),right=await tree(target),names=[...new Set([...left.keys(),...right.keys()])].filter(p=>JSON.stringify(left.get(p))!==JSON.stringify(right.get(p))).sort();
|
|
18
19
|
if(names.length>maxFiles)throw new Error('Historical change count limit exceeded');if(selectedPaths?.some(p=>!names.includes(p)))throw new Error('Selected path is not a historical change');
|
|
19
20
|
const files=[];for(const name of names){signal?.throwIfAborted();const l=left.get(name),r=right.get(name),item={id:hash(name),path:name,rawStatus:!l?'A':!r?'D':'M',eligibility:'reviewable',properties:[]};files.push(item);if(selectedPaths&&!selectedPaths.includes(name)){item.eligibility='excluded';item.reason='Not explicitly selected';continue;}try{for(const e of [l,r].filter(Boolean))if(e.type!=='blob'||!['100644','100755'].includes(e.mode))throw new Error('Historical link or submodule excluded');const read=async e=>decode(e?await git(root,['cat-file','blob',e.oid],maxFileBytes):Buffer.alloc(0));item.left=await read(l);item.right=await read(r);item.rightExists=!!r;if(l&&r&&item.left.hash===item.right.hash){item.eligibility='excluded';item.reason='Mode-only historical change not analyzed';}}catch(error){signal?.throwIfAborted();item.eligibility='blocked';item.reason=error.message;delete item.left;delete item.right;}if(Buffer.byteLength(JSON.stringify(files))>maxSnapshotBytes)throw new Error('Historical snapshot limit exceeded');}
|
|
20
|
-
const
|
|
21
|
+
const contextPaths=options.contextPaths ?? [], maxContextFiles=options.maxContextFiles ?? 20;
|
|
22
|
+
if(!Array.isArray(contextPaths)||!Number.isSafeInteger(maxContextFiles)||maxContextFiles<1||maxContextFiles>20||contextPaths.length>maxContextFiles)throw new Error('Historical context file limit exceeded');
|
|
23
|
+
if(options.autoContext!==undefined&&typeof options.autoContext!=='boolean')throw new Error('Invalid autoContext option');
|
|
24
|
+
const context=[], regular=e=>e?.type==='blob'&&['100644','100755'].includes(e.mode);
|
|
25
|
+
const captureContext=async name=>{relativePath(name);const changed=files.find(f=>f.path===name);if(changed){if(changed.eligibility!=='reviewable'||changed.rightExists===false)throw new Error('Historical context is excluded blocked or deleted');return {path:name,...changed.right};}const entry=right.get(name);if(!regular(entry))throw new Error('Historical context not a target regular blob');return {path:name,...decode(await git(root,['cat-file','blob',entry.oid],maxFileBytes))};};
|
|
26
|
+
for(const name of [...new Set(contextPaths)].sort())context.push(await captureContext(name));
|
|
27
|
+
let autoContext;
|
|
28
|
+
if(options.autoContext===true){const plan=contextCandidates(files,[...right].filter(([,e])=>regular(e)).map(([p])=>p));autoContext={...plan,notice:'Direct target-tree import/include navigation only; no caller coverage, binding or working-tree reads.',target,candidates:plan.candidates.filter(c=>!contextPaths.includes(c.path)),capturedPaths:[]};for(const c of autoContext.candidates){signal?.throwIfAborted();if(context.length>=maxContextFiles){c.status='blocked';c.reason='Context file limit exceeded';continue;}try{context.push(await captureContext(c.path));c.status='captured';autoContext.capturedPaths.push(c.path);}catch(error){signal?.throwIfAborted();c.status='blocked';c.reason=error.message;}}}
|
|
29
|
+
const snapshot={context,...(autoContext?{autoContext}:{}),schemaVersion:1,vcs:'git',root,baseline:base,history:{mode:commit!==undefined?'commit':'range',base,target,semantics:'exact-tree-endpoints; renames represented as add/delete'},files};const serialized=JSON.stringify(snapshot);if(Buffer.byteLength(serialized)>maxSnapshotBytes)throw new Error('Historical snapshot limit exceeded');return {...snapshot,id:hash(serialized)};
|
|
21
30
|
}
|
package/src/review.mjs
CHANGED
|
@@ -93,6 +93,7 @@ export async function reviewSnapshot(snapshot, model, options = {}) {
|
|
|
93
93
|
report.autoContext = structuredClone(input.autoContext);
|
|
94
94
|
if (input.autoContext.truncated || input.autoContext.candidates.some(c => c.status === 'blocked')) report.limitations.push({ text: '自动上下文未完全捕获:存在截断或阻塞,仅实际捕获路径可用于证据。' });
|
|
95
95
|
}
|
|
96
|
+
if (input.history) report.history = structuredClone(input.history);
|
|
96
97
|
report.rules = (input.rules ?? []).map(({ path, hash }) => ({ path, hash }));
|
|
97
98
|
if (options.enableGrouping === true) report.grouping = buildReviewGroups(input.files, inferFileRelations(input.files));
|
|
98
99
|
report.interactions = [];
|
|
@@ -251,6 +252,7 @@ const safe = text => Array.from(String(text ?? '')).map(c => {
|
|
|
251
252
|
export function markdownReport(report) {
|
|
252
253
|
const output = ['# Code Review 报告', '', '状态:' + report.status, '快照:' + report.snapshotId, '', '## 覆盖情况'];
|
|
253
254
|
for (const file of report.files) for (const correction of file.anchorCorrections ?? []) output.push('- 定位纠正:' + safe(correction.originalCandidate.fileId) + ' · ' + safe(correction.status) + ' · ' + safe(correction.reason) + ';原完整候选保留JSON,仅定位不证明因果');
|
|
255
|
+
if (report.history) output.push('- Git历史审查:' + safe(report.history.mode) + ' · ' + safe(report.history.base ?? 'empty') + ' → ' + safe(report.history.target) + ';精确端点树差异,重命名按增删,不含工作树');
|
|
254
256
|
if (report.businessGrouping) output.push('- 业务分组:' + safe(report.businessGrouping.status) + (report.businessGrouping.reason ? ' — ' + safe(report.businessGrouping.reason) : '') + ';仅调度假设,不证明依赖或覆盖');
|
|
255
257
|
for (const file of report.files) for (const plan of file.riskPlans ?? []) output.push('- 风险计划:' + safe(file.path) + ' · ' + safe(plan.status) + ' · ' + plan.risks.length + '项待证假设;不表示缺陷成立或覆盖完成');
|
|
256
258
|
for (const file of report.files) output.push('- ' + safe(file.path) + ':' + file.status + (file.reason ? ' — ' + safe(file.reason) : ''));
|
package/src/service.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export function createReviewService(llm, { capture = captureSnapshot, now = Date
|
|
|
26
26
|
exec = bind(exec);
|
|
27
27
|
exec.signal.throwIfAborted();
|
|
28
28
|
if (busy) throw new Error('Review service busy');
|
|
29
|
-
if (!args || Object.keys(args).some(k => !['repositoryPath', 'selectedPaths', 'contextPaths', 'rulePaths', 'autoContext'].includes(k))) throw new Error('Unknown preview argument');
|
|
29
|
+
if (!args || Object.keys(args).some(k => !['repositoryPath', 'selectedPaths', 'contextPaths', 'rulePaths', 'autoContext', 'commit', 'baseRevision', 'targetRevision'].includes(k))) throw new Error('Unknown preview argument');
|
|
30
30
|
if (args.autoContext !== undefined && typeof args.autoContext !== 'boolean') throw new Error('Invalid autoContext option');
|
|
31
31
|
for (const key of ['selectedPaths', 'contextPaths', 'rulePaths']) if (args[key] !== undefined && (!Array.isArray(args[key]) || args[key].length > (key === 'rulePaths' ? 4 : 200) || args[key].some(p => typeof p !== 'string'))) throw new Error('Invalid path list');
|
|
32
32
|
const current = owner(exec);
|
|
@@ -42,7 +42,7 @@ export function createReviewService(llm, { capture = captureSnapshot, now = Date
|
|
|
42
42
|
while (previews.size >= maxPreviews) previews.delete(previews.keys().next().value);
|
|
43
43
|
const previewId = randomUUID();
|
|
44
44
|
previews.set(previewId, { ...current, target, options, snapshotId: snapshot.id, expires: now() + ttlMs });
|
|
45
|
-
return { previewId, plan, snapshotId: snapshot.id, repositoryRoot: snapshot.root, vcs: snapshot.vcs, model: current.route, modelSendingEnabled: allowModelSending, files: snapshot.files.map(f => ({ path: f.path, eligibility: f.eligibility, reason: f.reason })), contextPaths: snapshot.context.map(c => c.path), ...(snapshot.autoContext ? { autoContext: snapshot.autoContext } : {}), rules: (snapshot.rules ?? []).map(({ path, hash }) => ({ path, hash })), notice: (enableRiskPlanning ? '执行先制定风险假设计划,再审查并复核;计划不是证据,所有阶段共享原预算。' : '') + '执行会向上述模型提供方发送可审查文件两侧内容、预览列出的显式/自动上下文及所选项目规则全文。模型可在该快照范围内多轮只读检索,不读取范围外文件;候选生成后会进行证据与反证复核,两阶段各最多3轮检索,共享每文件120秒和总模型调用100次预算;复核不能证明缺陷成立。plan仅预检初始输入,ready不代表已审查;minimumCalls不含后续检索/复核/动态业务综合;多文件可先进行业务分组,分组失败保留原组并记录限制,动态综合数执行前未知,实际预算可能不足。请先向用户展示范围,获得确认后执行。' };
|
|
45
|
+
return { previewId, plan, snapshotId: snapshot.id, repositoryRoot: snapshot.root, vcs: snapshot.vcs, ...(snapshot.history ? { history: snapshot.history } : {}), model: current.route, modelSendingEnabled: allowModelSending, files: snapshot.files.map(f => ({ path: f.path, eligibility: f.eligibility, reason: f.reason })), contextPaths: snapshot.context.map(c => c.path), ...(snapshot.autoContext ? { autoContext: snapshot.autoContext } : {}), rules: (snapshot.rules ?? []).map(({ path, hash }) => ({ path, hash })), notice: (enableRiskPlanning ? '执行先制定风险假设计划,再审查并复核;计划不是证据,所有阶段共享原预算。' : '') + '执行会向上述模型提供方发送可审查文件两侧内容、预览列出的显式/自动上下文及所选项目规则全文。模型可在该快照范围内多轮只读检索,不读取范围外文件;候选生成后会进行证据与反证复核,两阶段各最多3轮检索,共享每文件120秒和总模型调用100次预算;复核不能证明缺陷成立。plan仅预检初始输入,ready不代表已审查;minimumCalls不含后续检索/复核/动态业务综合;多文件可先进行业务分组,分组失败保留原组并记录限制,动态综合数执行前未知,实际预算可能不足。请先向用户展示范围,获得确认后执行。' };
|
|
46
46
|
} finally { busy = false; }
|
|
47
47
|
},
|
|
48
48
|
async execute(args, exec) {
|
package/src/snapshot.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { gitContextIndex, svnContextIndex } from './tracked-context.mjs';
|
|
|
2
2
|
import { contextCandidates } from './context-candidates.mjs';
|
|
3
3
|
import { lstat, realpath } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { captureGitHistory } from './git-history.mjs';
|
|
5
6
|
import { captureGit } from './git.mjs';
|
|
6
7
|
import { captureProjectRules } from './project-rules.mjs';
|
|
7
8
|
import { captureSvn } from './svn.mjs';
|
|
@@ -29,6 +30,11 @@ export async function captureSnapshot(cwd, options = {}) {
|
|
|
29
30
|
for (const name of contextPaths) relativePath(name);
|
|
30
31
|
if (options.autoContext !== undefined && typeof options.autoContext !== 'boolean') throw new Error('Invalid autoContext option');
|
|
31
32
|
const type = await detectVcs(cwd);
|
|
33
|
+
if (['commit','baseRevision','targetRevision'].some(k => options[k] !== undefined)) {
|
|
34
|
+
if (type !== 'git') throw new Error('Git revision review is unsupported on SVN');
|
|
35
|
+
if (!Array.isArray(rulePaths) || rulePaths.length) throw new Error('Historical rules not yet supported; do not mix working-tree sources');
|
|
36
|
+
return captureGitHistory(cwd, options);
|
|
37
|
+
}
|
|
32
38
|
const capture = type === 'git' ? captureGit : captureSvn;
|
|
33
39
|
const snapshot = await capture(cwd, options);
|
|
34
40
|
if (!Array.isArray(rulePaths) || rulePaths.some(name => contextPaths.includes(name))) throw new Error('Rule paths must be separate from context paths');
|