@feng0531/dsh-code-review 0.29.0 → 0.29.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # 变更记录
2
2
 
3
+ ## 0.29.2
4
+
5
+ - Git工作副本基线捕获不再全HEAD枚举,仅可审查变更基线路径literal非递归lookup,改名使用oldPath,删除/子模块边界不变。
6
+ - 11000无关文件大树4Shader工作变更及稳定hash/status不改回归,282测试通过;自动上下文tracked索引仍另行有界规划。
7
+
8
+ ## 0.29.1
9
+
10
+ - 参考核心selection核实新增凭据路径不可覆盖门禁:.env家族模板例外、.ssh/私钥/包管理凭据纯路径排除。
11
+ - Git改名旧新路径、SVN、历史blob、local context、规则与catalog统一拒绝,不读秘密正文,282测试通过。
12
+ - 继续核心逐文件差距核查;默认复用当前DSH模型不增加独立配置。
13
+
3
14
  ## 0.29.0
4
15
 
5
16
  - 重建固定源码能力对照任务,区分已读行为/待读核心/功能缺口/安全替代;恢复持续目标96总轮检查点。
package/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  ## 当前状态
6
6
 
7
- 当前代码版本为 0.29.0
7
+ 当前代码版本为 0.29.2
8
+
9
+ 凭据路径硬排除:.env及其后缀(.env.example/.env.sample/.env.template例外)、.ssh目录、SSH私钥及.netrc/_netrc/.npmrc/.pypirc/.dockercfg,大小写无关;显式选择不可绕过,上下文/规则同样拒绝。仅路径策略,不保证普通文件无秘密。
8
10
 
9
11
  检索支持find批准catalog路径字面子串查找,返回来源身份/版本侧/hash;仅导航不证明正文已读,不搜索仓库外路径。当前持续任务见[核心对照任务](CORE-ALIGNMENT-TASKS.md)。
10
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feng0531/dsh-code-review",
3
- "version": "0.29.0",
3
+ "version": "0.29.2",
4
4
  "private": false,
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
package/src/content.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { assertNonSecretPath } from './secret-path.mjs';
1
2
  import path from 'node:path';
2
3
  import { lstat, realpath, open } from 'node:fs/promises';
3
4
  import { createHash } from 'node:crypto';
@@ -17,6 +18,7 @@ export function decode(bytes) {
17
18
  }
18
19
  export async function readLocal(root, name, { maxFileBytes = 256 * 1024, signal } = {}) {
19
20
  relativePath(name);
21
+ assertNonSecretPath(name);
20
22
  if (!Number.isSafeInteger(maxFileBytes) || maxFileBytes < 1 || maxFileBytes > 16 * 1024 * 1024) throw new Error('Invalid file size limit');
21
23
  signal?.throwIfAborted();
22
24
  const canonicalRoot = await realpath(root);
@@ -1,3 +1,4 @@
1
+ import { isSecretPath, assertNonSecretPath } from './secret-path.mjs';
1
2
  import {captureProjectRules} from './project-rules.mjs';
2
3
  import {contextCandidates} from './context-candidates.mjs';
3
4
  import {realpath} from 'node:fs/promises';
@@ -25,7 +26,7 @@ export async function captureGitHistory(cwd, options={}) {
25
26
  // Literal, nonrecursive lookups cannot enumerate a supplied directory or wildcard.
26
27
  const lookup=async (oid,map,requested)=>{if(!oid)return;const pending=[...new Set(requested)].filter(p=>!map.has(p));for(let i=0;i<pending.length;i++){const paths=pending.slice(i,i+1);paths.forEach(relativePath);const records=utf8(await git(root,['--literal-pathspecs','ls-tree','-z','--full-tree',oid,'--',...paths])).split('\0').filter(Boolean);for(const r of records){const m=/^(\d{6}) (blob|commit|tree) ([a-f0-9]+)\t([\s\S]+)$/.exec(r);if(!m||!paths.includes(m[4]))throw new Error('Invalid historical path lookup');map.set(m[4],{mode:m[1],type:m[2],oid:m[3]});}}};
27
28
  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');
28
- 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');}
29
+ 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(isSecretPath(name)){item.eligibility='excluded';item.reason='Credential path excluded';continue;}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');}
29
30
  const rulePaths=options.rulePaths ?? [];
30
31
  const contextPaths=options.contextPaths ?? [], maxContextFiles=options.maxContextFiles ?? 20;
31
32
  if(!Array.isArray(contextPaths)||!Number.isSafeInteger(maxContextFiles)||maxContextFiles<1||maxContextFiles>20||contextPaths.length>maxContextFiles)throw new Error('Historical context file limit exceeded');
@@ -33,7 +34,7 @@ export async function captureGitHistory(cwd, options={}) {
33
34
  if(!Array.isArray(rulePaths)||rulePaths.length>4||rulePaths.some(p=>contextPaths.includes(p)))throw new Error('Rule paths must be separate from context paths');
34
35
  await lookup(target,right,[...contextPaths,...rulePaths]);await lookup(base,left,contextPaths);
35
36
  const context=[], regular=e=>e?.type==='blob'&&['100644','100755'].includes(e.mode);
36
- 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');const content=decode(await git(root,['cat-file','blob',entry.oid],maxFileBytes));const previous=left.get(name);return {path:name,...content,revision:target,...(regular(previous)?{oldText:decode(await git(root,['cat-file','blob',previous.oid],maxFileBytes)).text,oldRevision:base}:{})};};
37
+ const captureContext=async name=>{relativePath(name);assertNonSecretPath(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');const content=decode(await git(root,['cat-file','blob',entry.oid],maxFileBytes));const previous=left.get(name);return {path:name,...content,revision:target,...(regular(previous)?{oldText:decode(await git(root,['cat-file','blob',previous.oid],maxFileBytes)).text,oldRevision:base}:{})};};
37
38
  for(const name of [...new Set(contextPaths)].sort())context.push(await captureContext(name));
38
39
  const rules=await captureProjectRules(root,rulePaths,{signal,files,read:async (_root,name,{maxFileBytes:limit})=>{const entry=right.get(name);if(!regular(entry))throw new Error('Historical rule not a target regular blob');return decode(await git(root,['cat-file','blob',entry.oid],limit));}});
39
40
  let autoContext;
package/src/git.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { isSecretPath } from './secret-path.mjs';
1
2
  import { realpath } from 'node:fs/promises';
2
3
  import { run, checked } from './process.mjs';
3
4
  import { hash, decode, readLocal, relativePath } from './content.mjs';
@@ -21,14 +22,7 @@ export async function captureGit(cwd, options = {}) {
21
22
  if (ref.code !== 1) throw new Error('Cannot resolve Git HEAD');
22
23
  }
23
24
  const base = new Map();
24
- if (head) {
25
- const tree = text(await git(root, ['ls-tree', '-rz', '--full-tree', head], options));
26
- for (const record of tree.split('\0').filter(Boolean)) {
27
- const tab = record.indexOf('\t');
28
- const [mode, type, oid] = record.slice(0, tab).split(' ');
29
- base.set(record.slice(tab + 1), { mode, type, oid });
30
- }
31
- }
25
+ // Resolve only reviewable changed baselines below; never enumerate the HEAD tree.
32
26
  const records = text(before).split('\0');
33
27
  const changes = [];
34
28
  for (let i = 0; i < records.length; i++) {
@@ -41,11 +35,24 @@ export async function captureGit(cwd, options = {}) {
41
35
  if (changes.length > maxFiles) throw new Error('Change count limit exceeded; narrow repository scope');
42
36
  const known = new Set(changes.map(c => c.path));
43
37
  if (selectedPaths?.some(p => !known.has(p))) throw new Error('Selected path is not a current change');
38
+ if (head) {
39
+ const requested = [...new Set(changes.filter(c => !isSecretPath(c.path) && !isSecretPath(c.oldPath) && (!selectedPaths || selectedPaths.includes(c.path)) && (c.rawStatus !== '??' || selectedPaths?.includes(c.path))).map(c => relativePath(c.oldPath ?? c.path)))];
40
+ for (const name of requested) {
41
+ signal?.throwIfAborted();
42
+ const records = text(await git(root, ['--literal-pathspecs','ls-tree','-z','--full-tree',head,'--',name], options)).split('\0').filter(Boolean);
43
+ for (const record of records) {
44
+ const m = /^(\d{6}) (blob|tree|commit) ([a-f0-9]{40}|[a-f0-9]{64})\t([\s\S]+)$/.exec(record);
45
+ if (!m || m[4] !== name || base.has(name)) throw new Error('Invalid changed baseline lookup');
46
+ base.set(name,{mode:m[1],type:m[2],oid:m[3]});
47
+ }
48
+ }
49
+ }
44
50
  const files = [];
45
51
  for (const change of changes) {
46
52
  signal?.throwIfAborted();
47
53
  const item = { ...change, id: hash(change.path), eligibility: 'reviewable', properties: [] };
48
54
  files.push(item);
55
+ if (isSecretPath(change.path) || isSecretPath(change.oldPath)) { item.eligibility='excluded'; item.reason='Credential path excluded'; continue; }
49
56
  if ((selectedPaths && !selectedPaths.includes(change.path)) || (change.rawStatus === '??' && !selectedPaths?.includes(change.path))) {
50
57
  item.eligibility = 'excluded'; item.reason = 'Not explicitly selected'; continue;
51
58
  }
@@ -1,3 +1,4 @@
1
+ import { assertNonSecretPath } from './secret-path.mjs';
1
2
  import { readLocal, relativePath } from './content.mjs';
2
3
 
3
4
  // Explicit paths only. This helper neither authorizes sending nor follows includes.
@@ -6,6 +7,7 @@ export async function captureProjectRules(root, paths, { signal, files = [], rea
6
7
  const seen = new Set();
7
8
  for (const name of paths) {
8
9
  relativePath(name);
10
+ assertNonSecretPath(name);
9
11
  if (!/[.](md|txt)$/i.test(name)) throw new Error('Rules must be Markdown or text');
10
12
  if (seen.has(name)) throw new Error('Duplicate rule path');
11
13
  seen.add(name);
@@ -1,3 +1,4 @@
1
+ import { assertNonSecretPath } from './secret-path.mjs';
1
2
  import { createSnapshotReader } from './snapshot-reader.mjs';
2
3
 
3
4
  // Call only after authorization of this exact snapshot; this function grants nothing.
@@ -6,6 +7,7 @@ export function createRetrievalScope(snapshot, options) {
6
7
  const entries = [], catalog = [], paths = new Map(), identities = new Set();
7
8
  const add = (path, side, text, fileId) => {
8
9
  if (typeof text !== 'string') throw new Error('Missing retrieval text');
10
+ assertNonSecretPath(path);
9
11
  const id = 's' + (entries.length + 1);
10
12
  entries.push({ id, text, path, side });
11
13
  catalog.push({ id, path, side, ...(fileId ? { fileId } : {}) });
@@ -0,0 +1,9 @@
1
+ // Pure path policy; never inspect credential contents or infer safe contents.
2
+ export function isSecretPath(value) {
3
+ if(typeof value!=='string')return false;
4
+ const parts=value.replaceAll('\\','/').toLowerCase().split('/'),base=parts.at(-1);
5
+ if(parts.includes('.ssh'))return true;
6
+ if(['id_rsa','id_dsa','id_ecdsa','id_ed25519','.netrc','_netrc','.npmrc','.pypirc','.dockercfg'].includes(base))return true;
7
+ return (base==='.env'||base.startsWith('.env.'))&&!['.env.example','.env.sample','.env.template'].includes(base);
8
+ }
9
+ export function assertNonSecretPath(path){if(isSecretPath(path))throw new Error('Credential path excluded');}
package/src/svn.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { isSecretPath } from './secret-path.mjs';
1
2
  import { realpath, lstat } from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
  import { isDeepStrictEqual } from 'node:util';
@@ -39,6 +40,7 @@ export async function captureSvn(cwd, options = {}) {
39
40
  const state = entry['wc-status'], status = state['@_item'];
40
41
  const item = { id: hash(name), path: name, rawStatus: status, baseRevision: state['@_revision'], eligibility: 'reviewable', properties: [] };
41
42
  files.push(item);
43
+ if (isSecretPath(name)) { item.eligibility='excluded'; item.reason='Credential path excluded'; continue; }
42
44
  if ((selectedPaths && !selectedPaths.includes(name)) || (status === 'unversioned' && !selectedPaths?.includes(name))) {
43
45
  item.eligibility = 'excluded'; item.reason = 'Not explicitly selected'; continue;
44
46
  }