@feng0531/dsh-code-review 0.20.1 → 0.20.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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/anchor-correction.mjs +18 -0
- package/src/review.mjs +14 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 当前状态
|
|
6
6
|
|
|
7
|
-
当前代码版本为 0.20.
|
|
7
|
+
当前代码版本为 0.20.2
|
|
8
8
|
|
|
9
9
|
可在预览传入 `autoContext: true`,显式选择有界Git/SVN直接import/include上下文捕获;默认关闭。候选、阻塞、截断及实际路径在预览可见,正文仅在确认后发送,执行重新验证快照。仅当前侧导航非历史/调用图,SVN使用离线正常节点索引支持同样导航;不会自动引入未跟踪或排除变更。,包含有界覆盖预检、显式项目规则及候选证据与反证复核;发布状态以 npm 和 GitHub Release 为准。已通过真实临时 Git/SVN 仓库测试,以及隔离进程中的真实 DSH ToolRuntime 注册验证。当前开发会话的实际预览已返回0.6.0的plan/rules字段,空变更预览与默认关闭外发已验证;已进行经宿主审批的六次小规模真实试跑,累计12次模型调用;四组合成正负例与历史修复对照符合预期,历史引入方向检出候选但引用复核未完成(partial)。不是独立盲测或整体质量证明。详情见 [试跑结果](evaluation/PILOT-RESULTS.md)。
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Pure, single-attempt exact correction. Never searches another file or source side.
|
|
2
|
+
export function correctAnchor(raw, file, changes, {signal}={}) {
|
|
3
|
+
signal?.throwIfAborted();const a=raw?.anchor;
|
|
4
|
+
const result=(status,reason)=>({status,reason,originalCandidate:structuredClone(raw)});
|
|
5
|
+
if(!raw||raw.fileId!==file.id||a?.kind!=='line'||!['old','new'].includes(a.side)||!Number.isSafeInteger(a.start)||!Number.isSafeInteger(a.end)||a.start<1||a.end<a.start||typeof a.snippet!=='string'||!a.snippet.trim()||a.snippet.length>8000)return result('not-applicable','invalid-anchor');
|
|
6
|
+
const text=(a.side==='old'?file.left:file.right)?.text;if(typeof text!=='string'||Buffer.byteLength(text)>256*1024)return result('not-applicable','source-limit');
|
|
7
|
+
const source=text.replaceAll('\r\n','\n').split('\n'),snippet=a.snippet.replaceAll('\r\n','\n').split('\n');
|
|
8
|
+
if(source.slice(a.start-1,a.end).join('\n')===snippet.join('\n'))return result('unchanged','already-exact');
|
|
9
|
+
if(changes?.status!=='changed'||changes.precision!=='exact'||!Array.isArray(raw.attribution?.editIds)||!raw.attribution.editIds.length)return result('rejected','missing-exact-edit');
|
|
10
|
+
const edits=changes.edits.filter(e=>raw.attribution.editIds.includes(e.id));if(edits.length!==raw.attribution.editIds.length)return result('rejected','unknown-or-duplicate-edit');
|
|
11
|
+
// Bound CPU even for a long multiline snippet; no silent partial search acceptance.
|
|
12
|
+
if(source.length*snippet.length>2000000)return result('rejected','search-work-limit');
|
|
13
|
+
let match;for(let i=0;i+snippet.length<=source.length;i++){signal?.throwIfAborted();if(!snippet.every((line,j)=>source[i+j]===line))continue;if(match!==undefined)return result('rejected','ambiguous-exact-text');match=i;}
|
|
14
|
+
if(match===undefined)return result('rejected','no-exact-text');
|
|
15
|
+
const start=match+1,end=match+snippet.length;
|
|
16
|
+
if(!edits.some(e=>e[a.side].count>0&&start<e[a.side].start+e[a.side].count&&end>=e[a.side].start))return result('rejected','does-not-overlap-referenced-edit');
|
|
17
|
+
const candidate=structuredClone(raw);candidate.anchor={...a,start,end};return {...result('corrected','unique-exact-text-overlaps-edit'),candidate};
|
|
18
|
+
}
|
package/src/review.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { correctAnchor } from './anchor-correction.mjs';
|
|
1
2
|
import { BUSINESS_GROUP_INSTRUCTIONS, prepareBusinessGroups, validateBusinessGroups } from './business-groups.mjs';
|
|
2
3
|
import { RISK_PLAN_INSTRUCTIONS, validateRiskPlan } from './risk-plan.mjs';
|
|
3
4
|
import { prepareInteractionInput } from './interaction-input.mjs';
|
|
@@ -167,7 +168,19 @@ export async function reviewSnapshot(snapshot, model, options = {}) {
|
|
|
167
168
|
}
|
|
168
169
|
const request = { ...enclosingRequest, input: batchPayload };
|
|
169
170
|
const auditStart = state.retrievalAudit?.length ?? 0;
|
|
170
|
-
|
|
171
|
+
let response = await executor(request);
|
|
172
|
+
if (options.enableAnchorCorrection === true && !batch.interaction) {
|
|
173
|
+
if (Buffer.byteLength(typeof response === 'string' ? response : JSON.stringify(response)) > 128 * 1024) throw new Error('Review response too large');
|
|
174
|
+
const decoded = typeof response === 'string' ? JSON.parse(response) : structuredClone(response);
|
|
175
|
+
if (Array.isArray(decoded?.findings) && decoded.findings.length <= 50) {
|
|
176
|
+
decoded.findings = decoded.findings.map(raw => {
|
|
177
|
+
const correction = correctAnchor(raw, file, changes, { signal: request.signal });
|
|
178
|
+
if (!['unchanged','not-applicable'].includes(correction.status)) (state.anchorCorrections ??= []).push(correction);
|
|
179
|
+
return correction.status === 'corrected' ? correction.candidate : raw;
|
|
180
|
+
});
|
|
181
|
+
response = decoded;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
171
184
|
const generated = batch.interaction ? validateInteractionFindings(response, input, batch.interaction, (state.retrievalAudit ?? []).slice(auditStart), scope.catalog()) : validateResponse(response, file, changes);
|
|
172
185
|
if (batch.synthesis) validateSynthesisReads(generated.findings, changes, (state.retrievalAudit ?? []).slice(auditStart), scope.catalog(), file.id, input.id);
|
|
173
186
|
if (!batch.interaction && state.sourceMode === 'change-windows') validateWindowFindings(generated.findings, batch.synthesis ? prepared.synthesis.windows : JSON.parse(batch.payload).windows, batch.synthesis === true);
|