@longzai-intelligence-ledger/core 0.0.1 → 0.0.3

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.
Files changed (2) hide show
  1. package/dist/index.js +8 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{dirname as r,isAbsolute as i,join as a,normalize as o,relative as s,resolve as c,sep as l}from"node:path";const u=400,d=100,f=16e3,p=`docs/ledgers`,m=[`待建档`,`待启动`,`进行中`,`已收口`,`不适用`],h=e=>({repoRoot:e.repoRoot,ledgersRoot:e.ledgersRoot??`docs/ledgers`,maxLineLength:e.maxLineLength??400,maxWorkstreamLines:e.maxWorkstreamLines??100,maxWorkstreamBytes:e.maxWorkstreamBytes??16e3,statusVocabulary:[...m,...e.extraStatusVocabulary??[]],sizeExemptGlobs:e.sizeExemptGlobs??[],tmpPathAllowGlobs:e.tmpPathAllowGlobs??[],hashExemptGlobs:e.hashExemptGlobs??[]}),g=e=>{let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r===`*`){if(e.startsWith(`**`,n)){t+=`.*`,n+=2;continue}t+=`[^/]*`,n+=1;continue}if(r===`?`){t+=`[^/]`,n+=1;continue}t+=r.replace(/[\\^$.+()[\]{}|]/gu,`\\$&`),n+=1}return RegExp(`^(?:${t})$`,`u`)},_=(e,t)=>t.some(t=>g(t).test(e)),v=e=>{let t=[],n=!1;for(let r of e){if(/^\s*```/.test(r)){t.push(!1),n=!n;continue}t.push(n)}return t},y=e=>Array.from(e).length,b=e=>{let t=[],n=e.replaceAll(/`[^`]*`/gu,``);for(let e of n.matchAll(/\]\(([^)]*)\)/gu)){let n=e[1]?.trim()??``;n===``||n.startsWith(`#`)||t.push(n)}return t},x=/* @__PURE__ */ new Set([`archives`,`node_modules`,`dist`,`.turbo`,`.git`,`out`,`coverage`]),S=(e,r)=>{let i=a(e,r),o=[],c=r=>{for(let i of n(r,{withFileTypes:!0})){if(i.isDirectory()){if(x.has(i.name))continue;c(a(r,i.name));continue}if(!i.name.endsWith(`.md`))continue;let n=a(r,i.name);o.push({absolutePath:n,relativePath:s(e,n).split(l).join(`/`),content:t(n,`utf8`)})}};return c(i),{indexFiles:o.filter(e=>C(e.relativePath,r)),workstreamFiles:o.filter(e=>w(e.relativePath,r)),allFiles:o}},C=(e,t)=>{let n=T(e,t);return n===null?!1:/^[^/]+\/ledger\.md$/.test(n)?!0:/^[^/]+\/workstreams\/[^/]+\.md$/.test(n)},w=(e,t)=>{let n=T(e,t);return n!==null&&/^[^/]+\/workstreams\/\d{3}[^/]*\.md$/.test(n)},T=(e,t)=>{let n=`${t.replace(/\/$/u,``)}/`;return e.startsWith(n)?e.slice(n.length):null},E=/\b(?=[0-9a-f]{7,40}\b)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b/gu,D=(e,t,n)=>{let r=e.relativePath.startsWith(`${t}/`)?e.relativePath.slice(t.length+1):e.relativePath;if(_(r,n))return[];let i=[],a=e.content.split(`
2
- `),o=v(a);return a.forEach((t,n)=>{if(o[n]===!0)return;let r=t.match(E)??[];for(let t of r)i.push({file:e.relativePath,line:n+1,ruleId:`commit-hash`,message:`索引面出现提交哈希 ${t},证据指针请归逐仓档`})}),i},O=(e,t)=>{let n=[],r=e.content.split(`
3
- `),i=v(r);return r.forEach((r,a)=>{if(i[a]===!0)return;let o=y(r);o>t&&n.push({file:e.relativePath,line:a+1,ruleId:`line-width`,message:`单行 ${o} 字符超过上限 ${t} 字符,请拆条或下沉明细`})}),n},k=(e,t)=>{let n=[],r=e.content.split(`
4
- `),i=v(r);return r.forEach((r,a)=>{if(i[a]!==!0)for(let i of b(r)){if(A(i))continue;let r=i.split(`#`)[0]?.trim()??``;r!==``&&(j(r,e.relativePath,t)||n.push({file:e.relativePath,line:a+1,ruleId:`link-resolution`,message:`链接目标 ${r} 不存在,请修正或改为指针文本`}))}}),n},A=e=>/^(https?:|mailto:|tel:)/iu.test(e)?!0:e.includes(`xxx`),j=(t,n,a)=>{let s=c(a,r(n),t);if(e(s))return!0;let l=i(t)?c(a,`.${t}`):c(a,t);return l.startsWith(`${a}${a.endsWith(`/`)?``:`/`}`)===!1||e(l)||o(s)===o(l)},M=/^已并入 \d{3}$/u,N=/* @__PURE__ */ new Set([``,`—`,`——`]),P=(e,t)=>{let n=[],r=e.content.split(`
5
- `),i=null;return r.forEach((r,a)=>{if(!r.trimStart().startsWith(`|`)){i=null;return}let o=F(r);if(i===null){let e=o.findIndex(e=>e.trim()===`状态`);e!==-1&&!I(o)&&(i=e);return}if(I(o))return;let s=o[i]?.trim()??``;L(s,t)||n.push({file:e.relativePath,line:a+1,ruleId:`status-vocabulary`,message:`聚合表状态值「${s}」未命中词表,详细状态描述请归逐仓档`})}),n},F=e=>e.trim().replace(/^\|/u,``).replace(/\|$/u,``).split(`|`),I=e=>e.every(e=>/^[-: ]*$/.test(e.trim())),L=(e,t)=>N.has(e)||M.test(e)?!0:t.includes(e),R=[`/tmp/`,`/private/tmp/`,`/var/folders/`],z=(e,t,n)=>{let r=e.relativePath.startsWith(`${t}/`)?e.relativePath.slice(t.length+1):e.relativePath;if(_(r,n))return[];let i=[];return e.content.split(`
6
- `).forEach((t,n)=>{let r=R.find(e=>t.includes(e));r!==void 0&&i.push({file:e.relativePath,line:n+1,ruleId:`temp-path`,message:`引用临时目录路径 ${r},临时产物路径不入台账`})}),i},B=(e,t)=>{let n=e.relativePath.startsWith(`${t.ledgersRoot}/`)?e.relativePath.slice(t.ledgersRoot.length+1):e.relativePath;if(_(n,t.sizeExemptGlobs))return[];let r=[],i=e.content.split(`
7
- `).length,a=Buffer.byteLength(e.content,`utf8`);return i>t.maxWorkstreamLines&&r.push({file:e.relativePath,line:null,ruleId:`workstream-size`,message:`工作流档 ${i} 行超过上限 ${t.maxWorkstreamLines} 行,请拆分下沉`}),a>t.maxWorkstreamBytes&&r.push({file:e.relativePath,line:null,ruleId:`workstream-size`,message:`工作流档 ${a} 字节超过上限 ${t.maxWorkstreamBytes} 字节,请拆分下沉`}),r},V=e=>{let t=S(e.repoRoot,e.ledgersRoot),n=[];for(let r of t.indexFiles)n.push(...O(r,e.maxLineLength)),n.push(...D(r,e.ledgersRoot,e.hashExemptGlobs)),n.push(...k(r,e.repoRoot));for(let r of t.workstreamFiles)n.push(...B(r,{ledgersRoot:e.ledgersRoot,maxWorkstreamLines:e.maxWorkstreamLines,maxWorkstreamBytes:e.maxWorkstreamBytes,sizeExemptGlobs:e.sizeExemptGlobs}));for(let r of t.allFiles)r.relativePath.endsWith(`/ledger.md`)&&n.push(...P(r,e.statusVocabulary)),n.push(...z(r,e.ledgersRoot,e.tmpPathAllowGlobs));return n.sort((e,t)=>e.file===t.file?(e.line??0)-(t.line??0):e.file<t.file?-1:1),{violations:n,summary:{files:t.allFiles.length,indexFiles:t.indexFiles.length,errors:n.length}}},H=(e,t={})=>{let n=[];if(e.violations.length===0)return n.push(`台账形态门禁通过:扫描 ${e.summary.files} 份 markdown,索引位 ${e.summary.indexFiles} 份,零违例`),n.join(`
1
+ import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{dirname as r,isAbsolute as i,join as a,normalize as o,relative as s,resolve as c,sep as l}from"node:path";const u=400,d=100,f=16e3,p=`docs/ledgers`,m=[`待建档`,`待启动`,`进行中`,`已收口`,`不适用`],h=e=>({repoRoot:e.repoRoot,ledgersRoot:e.ledgersRoot??`docs/ledgers`,maxLineLength:e.maxLineLength??400,maxWorkstreamLines:e.maxWorkstreamLines??100,maxWorkstreamBytes:e.maxWorkstreamBytes??16e3,statusVocabulary:[...m,...e.extraStatusVocabulary??[]],sizeExemptGlobs:e.sizeExemptGlobs??[],tmpPathAllowGlobs:e.tmpPathAllowGlobs??[],hashExemptGlobs:e.hashExemptGlobs??[]}),g=e=>{let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r===`*`){if(e.startsWith(`**`,n)){t+=`.*`,n+=2;continue}t+=`[^/]*`,n+=1;continue}if(r===`?`){t+=`[^/]`,n+=1;continue}t+=r.replace(/[\\^$.+()[\]{}|]/gu,`\\$&`),n+=1}return RegExp(`^(?:${t})$`,`u`)},_=(e,t)=>t.some(t=>g(t).test(e)),v=e=>{let t=[],n=!1;for(let r of e){if(/^\s*```/.test(r)){t.push(!1),n=!n;continue}t.push(n)}return t},y=e=>Array.from(e).length,b=e=>e.replaceAll(/`[^`]*`/gu,``),x=e=>{let t=[],n=b(e);for(let e of n.matchAll(/\]\(([^)]*)\)/gu)){let n=e[1]?.trim()??``;n===``||n.startsWith(`#`)||t.push(n)}return t},S=/* @__PURE__ */ new Set([`archives`,`node_modules`,`dist`,`.turbo`,`.git`,`out`,`coverage`]),C=(e,r)=>{let i=a(e,r),o=[],c=r=>{for(let i of n(r,{withFileTypes:!0})){if(i.isDirectory()){if(S.has(i.name))continue;c(a(r,i.name));continue}if(!i.name.endsWith(`.md`))continue;let n=a(r,i.name);o.push({absolutePath:n,relativePath:s(e,n).split(l).join(`/`),content:t(n,`utf8`)})}};return c(i),{indexFiles:o.filter(e=>w(e.relativePath,r)),workstreamFiles:o.filter(e=>T(e.relativePath,r)),allFiles:o}},w=(e,t)=>{let n=E(e,t);return n===null?!1:/^[^/]+\/ledger\.md$/.test(n)?!0:/^[^/]+\/workstreams\/[^/]+\.md$/.test(n)},T=(e,t)=>{let n=E(e,t);return n!==null&&/^[^/]+\/workstreams\/\d{3}[^/]*\.md$/.test(n)},E=(e,t)=>{let n=`${t.replace(/\/$/u,``)}/`;return e.startsWith(n)?e.slice(n.length):null},D=/\b(?=[0-9a-f]{7,40}\b)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b/gu,O=(e,t,n)=>{let r=e.relativePath.startsWith(`${t}/`)?e.relativePath.slice(t.length+1):e.relativePath;if(_(r,n))return[];let i=[],a=e.content.split(`
2
+ `),o=v(a);return a.forEach((t,n)=>{if(o[n]===!0)return;let r=b(t).match(D)??[];for(let t of r)i.push({file:e.relativePath,line:n+1,ruleId:`commit-hash`,message:`索引面出现提交哈希 ${t},证据指针请归逐仓档`})}),i},k=(e,t)=>{let n=[],r=e.content.split(`
3
+ `),i=v(r);return r.forEach((r,a)=>{if(i[a]===!0)return;let o=y(r);o>t&&n.push({file:e.relativePath,line:a+1,ruleId:`line-width`,message:`单行 ${o} 字符超过上限 ${t} 字符,请拆条或下沉明细`})}),n},A=(e,t)=>{let n=[],r=e.content.split(`
4
+ `),i=v(r);return r.forEach((r,a)=>{if(i[a]!==!0)for(let i of x(r)){if(j(i))continue;let r=i.split(`#`)[0]?.trim()??``;r!==``&&(M(r,e.relativePath,t)||n.push({file:e.relativePath,line:a+1,ruleId:`link-resolution`,message:`链接目标 ${r} 不存在,请修正或改为指针文本`}))}}),n},j=e=>/^(https?:|mailto:|tel:)/iu.test(e)?!0:e.includes(`xxx`),M=(t,n,a)=>{let s=c(a,r(n),t);if(e(s))return!0;let l=i(t)?c(a,`.${t}`):c(a,t);return l.startsWith(`${a}${a.endsWith(`/`)?``:`/`}`)===!1||e(l)||o(s)===o(l)},N=/^已并入 \d{3}$/u,P=/* @__PURE__ */ new Set([``,`—`,`——`]),F=(e,t)=>{let n=[],r=e.content.split(`
5
+ `),i=null;return r.forEach((r,a)=>{if(!r.trimStart().startsWith(`|`)){i=null;return}let o=I(r);if(i===null){let e=o.findIndex(e=>e.trim()===`状态`);e!==-1&&!L(o)&&(i=e);return}if(L(o))return;let s=o[i]?.trim()??``;R(s,t)||n.push({file:e.relativePath,line:a+1,ruleId:`status-vocabulary`,message:`聚合表状态值「${s}」未命中词表,详细状态描述请归逐仓档`})}),n},I=e=>e.trim().replace(/^\|/u,``).replace(/\|$/u,``).split(`|`),L=e=>e.every(e=>/^[-: ]*$/.test(e.trim())),R=(e,t)=>P.has(e)||N.test(e)?!0:t.includes(e),z=[`/tmp/`,`/private/tmp/`,`/var/folders/`],B=(e,t,n)=>{let r=e.relativePath.startsWith(`${t}/`)?e.relativePath.slice(t.length+1):e.relativePath;if(_(r,n))return[];let i=[];return e.content.split(`
6
+ `).forEach((t,n)=>{let r=z.find(e=>t.includes(e));r!==void 0&&i.push({file:e.relativePath,line:n+1,ruleId:`temp-path`,message:`引用临时目录路径 ${r},临时产物路径不入台账`})}),i},V=(e,t)=>{let n=e.relativePath.startsWith(`${t.ledgersRoot}/`)?e.relativePath.slice(t.ledgersRoot.length+1):e.relativePath;if(_(n,t.sizeExemptGlobs))return[];let r=[],i=e.content.split(`
7
+ `).length,a=Buffer.byteLength(e.content,`utf8`);return i>t.maxWorkstreamLines&&r.push({file:e.relativePath,line:null,ruleId:`workstream-size`,message:`工作流档 ${i} 行超过上限 ${t.maxWorkstreamLines} 行,请拆分下沉`}),a>t.maxWorkstreamBytes&&r.push({file:e.relativePath,line:null,ruleId:`workstream-size`,message:`工作流档 ${a} 字节超过上限 ${t.maxWorkstreamBytes} 字节,请拆分下沉`}),r},H=e=>{let t=C(e.repoRoot,e.ledgersRoot),n=[];for(let r of t.indexFiles)n.push(...k(r,e.maxLineLength)),n.push(...O(r,e.ledgersRoot,e.hashExemptGlobs)),n.push(...A(r,e.repoRoot));for(let r of t.workstreamFiles)n.push(...V(r,{ledgersRoot:e.ledgersRoot,maxWorkstreamLines:e.maxWorkstreamLines,maxWorkstreamBytes:e.maxWorkstreamBytes,sizeExemptGlobs:e.sizeExemptGlobs}));for(let r of t.allFiles)r.relativePath.endsWith(`/ledger.md`)&&n.push(...F(r,e.statusVocabulary)),n.push(...B(r,e.ledgersRoot,e.tmpPathAllowGlobs));return n.sort((e,t)=>e.file===t.file?(e.line??0)-(t.line??0):e.file<t.file?-1:1),{violations:n,summary:{files:t.allFiles.length,indexFiles:t.indexFiles.length,errors:n.length}}},U=(e,t={})=>{let n=[];if(e.violations.length===0)return n.push(`台账形态门禁通过:扫描 ${e.summary.files} 份 markdown,索引位 ${e.summary.indexFiles} 份,零违例`),n.join(`
8
8
  `);for(let t of e.violations){let e=t.line===null?t.file:`${t.file}:${t.line}`;n.push(`${e} [${t.ruleId}] ${t.message}`)}return t.rootLabel!==void 0&&n.push(`仓库根:${t.rootLabel}`),n.push(`台账形态门禁未通过:违例 ${e.summary.errors} 项,扫描 ${e.summary.files} 份 markdown,索引位 ${e.summary.indexFiles} 份`),n.join(`
9
- `)};export{p as DEFAULT_LEDGERS_ROOT,u as DEFAULT_MAX_LINE_LENGTH,d as DEFAULT_MAX_WORKSTREAM_LINES,m as DEFAULT_STATUS_VOCABULARY,f as DEFAULT_WORKSTREAM_BYTES,D as checkCommitHash,O as checkLineWidth,k as checkLinkResolution,P as checkStatusVocabulary,z as checkTempPath,B as checkWorkstreamSize,S as collectLedgerFileSet,y as countLineLength,b as extractLinkTargets,H as formatLedgerCheckReport,C as isIndexFile,w as isWorkstreamFile,v as markFencedLines,_ as matchesAnyGlob,h as resolveLedgerCheckOptions,V as runLedgerCheck};
9
+ `)};export{p as DEFAULT_LEDGERS_ROOT,u as DEFAULT_MAX_LINE_LENGTH,d as DEFAULT_MAX_WORKSTREAM_LINES,m as DEFAULT_STATUS_VOCABULARY,f as DEFAULT_WORKSTREAM_BYTES,O as checkCommitHash,k as checkLineWidth,A as checkLinkResolution,F as checkStatusVocabulary,B as checkTempPath,V as checkWorkstreamSize,C as collectLedgerFileSet,y as countLineLength,x as extractLinkTargets,U as formatLedgerCheckReport,w as isIndexFile,T as isWorkstreamFile,v as markFencedLines,_ as matchesAnyGlob,h as resolveLedgerCheckOptions,H as runLedgerCheck};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-ledger/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Longzai Intelligence Ledger 台账形态校验引擎",
5
5
  "keywords": [
6
6
  "ledger",