@longzai-intelligence-features/ledger 0.0.4 → 0.0.5
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/dist/index.js +21 -21
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{join as r,relative as i}from"node:path";import{SEMANTIC_SLUG_PATTERN as a}from"@longzai-intelligence-docs/core";const
|
|
2
|
-
`)}function
|
|
3
|
-
`),n=t.find(e=>e.startsWith(`# `)&&!e.startsWith(`## `))?.slice(2).trim()??null,r=t.findIndex(e=>e.startsWith(`## `)),i=r===-1?t.length:r,a=[];for(let e of t.slice(0,i)){let t=
|
|
4
|
-
`);return{sectionsPresent:new Set(t.filter(e=>e.startsWith(`## `))),deliverySectionBody:se(t,
|
|
5
|
-
`)}function
|
|
6
|
-
`);if(
|
|
7
|
-
`),
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{existsSync as e,readFileSync as t,readdirSync as n}from"node:fs";import{join as r,relative as i}from"node:path";import{SEMANTIC_SLUG_PATTERN as a,SLUG_MIN_WORDS as o,countKebabWords as s}from"@longzai-intelligence-docs/core";const c=a,l=[`README.md`,`spec.md`,`tasks.md`,`checklist.md`,`progress.md`],u=`README.md`,d=`spec.md`,f=/^\*\*([^*:]+)\*\*:(.*)$/,p=`状态`,m=`立案日期`,h=`所属域`,g=`来源`,_=`阻塞`,v=`进展注记`,y=`裁定说明`,ee=`取消原因`,b=`沿革`,x=`🔴 规划中`,te=`🟡 实现中`,ne=`🟢 已交付`,S=`⚪ 已冻结`,re=`⚫ 已取消`,C=/* @__PURE__ */ new Map([[x,`planning`],[te,`implementing`],[ne,`delivered`],[S,`frozen`],[re,`canceled`]]),w=[...C.keys()];function T(e){return C.get(e.trim())??null}const E=/^\d{4}-\d{2}-\d{2}$/,D=`## 一、需求动机`,O=`## 二、现状与背景`,k=`## 三、需求内容`,A=`## 四、验收口径`,j=`## 五、交付记录`,ie=[D,O,k,A],M=`待补充`,N=`用户裁定`,ae=4,oe=/[、,,]\s*/;function P(e){return e.split(oe).map(e=>e.trim()).filter(e=>e.length>0)}function F(e){let[t,n,r]=e.split(`-`).map(e=>Number.parseInt(e,10));if(t===void 0||n===void 0||r===void 0)return!1;let i=new Date(Date.UTC(t,n-1,r));return i.getUTCFullYear()===t&&i.getUTCMonth()===n-1&&i.getUTCDate()===r}function I(e,t){let n=Date.parse(`${e}T00:00:00Z`),r=Date.parse(`${t}T00:00:00Z`);return Math.round((r-n)/864e5)}function se(e,t){let n=e.indexOf(t);if(n===-1)return null;let r=e.length;for(let t=n+1;t<e.length;t+=1)if(e[t]?.startsWith(`## `)){r=t;break}return e.slice(n+1,r).join(`
|
|
2
|
+
`)}function L(e){let t=e.split(`
|
|
3
|
+
`),n=t.find(e=>e.startsWith(`# `)&&!e.startsWith(`## `))?.slice(2).trim()??null,r=t.findIndex(e=>e.startsWith(`## `)),i=r===-1?t.length:r,a=[];for(let e of t.slice(0,i)){let t=f.exec(e.trim());t!==null&&a.push({key:t[1]??``,value:(t[2]??``).trim()})}let o=e=>a.find(t=>t.key===e)?.value??null,s=o(p),c=o(_);return{title:n,metadataLines:a,statusLabel:s,status:s===null?null:T(s),filingDate:o(m),progressNote:o(v),adjudicationNote:o(y),cancelReason:o(ee),blockingRefs:c===null?[]:P(c)}}function R(e){let t=e.split(`
|
|
4
|
+
`);return{sectionsPresent:new Set(t.filter(e=>e.startsWith(`## `))),deliverySectionBody:se(t,j)}}function z(e,i){let a=r(e,i),o=[];try{o=n(a,{withFileTypes:!0}).filter(e=>e.isFile()).map(e=>e.name).sort()}catch{o=[]}let s=l.filter(e=>!o.includes(e)),f=null;if(o.includes(`README.md`)&&o.includes(`spec.md`))try{f={...L(t(r(a,u),`utf8`)),...R(t(r(a,d),`utf8`))}}catch{f=null}return{dirname:i,slug:c.test(i)?i:null,namingValid:c.test(i),hasEntry:s.length===0,files:o,missing:s,supplementary:o.filter(e=>!l.includes(e)),record:f}}function B(e){let t=[];try{t=n(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}return t.sort().map(t=>z(e,t))}function V(e,t){return t.some(t=>e===t.path||e.startsWith(`${t.path}/`))}const ce=1,le=/^\p{Extended_Pictographic}(?:\uFE0F)?\s*/u,ue=[p,m,h,g],de=(e,t)=>e.find(e=>e.key===t)?.value??``,fe=e=>{let t=/* @__PURE__ */ new Set,n=[];for(let r of e)r.value===``||ue.includes(r.key)||t.has(r.key)||(t.add(r.key),n.push({label:r.key,value:r.value}));return n},pe=e=>e.replace(le,``);function me(e){let n=e.scopeKey===void 0?e.config.scopes:e.config.scopes.filter(t=>t.key===e.scopeKey),i=[];for(let a of n){let n=B(r(e.root,a.registryDir));for(let o of n){let n=null;try{n=L(t(r(e.root,a.registryDir,o.dirname,u),`utf8`))}catch{}i.push({date:n?.filingDate??``,extras:n===null?[]:fe(n.metadataLines),note:n===null?``:de(n.metadataLines,g),number:``,path:r(a.registryDir,o.dirname,u),scopeKey:a.key,scopeTitle:a.title,slug:o.dirname,status:n?.status??``,statusLabel:n===null||n.statusLabel===null?``:pe(n.statusLabel),title:n?.title??``})}}return{domain:`features`,entries:i,schemaVersion:1}}function he(e){let t=e.today??new Intl.DateTimeFormat(`en-CA`,{year:`numeric`,month:`2-digit`,day:`2-digit`}).format(/* @__PURE__ */ new Date),n=[];for(let i of e.config.scopes){let a=B(r(e.root,i.registryDir)).filter(t=>!V(r(i.registryDir,t.dirname),e.config.check.exclusions)),o={planning:0,implementing:0,delivered:0,frozen:0,canceled:0};for(let e of a)e.record?.status!==null&&e.record?.status!==void 0&&(o[e.record.status]+=1);let s=a.filter(e=>e.record?.status===`planning`).map(e=>({slug:e.dirname,filingDate:e.record?.filingDate??``,ageDays:I(e.record?.filingDate??t,t)})).sort((e,t)=>t.ageDays-e.ageDays)[0];n.push({scopeKey:i.key,registryDir:i.registryDir,total:a.length,byStatus:o,oldestPlanning:s===void 0||s.filingDate===``?null:s})}return{today:t,scopes:n}}function H(e){let t=e.findIndex(e=>e.startsWith(`## `));return t===-1?e.length:t}function U(e,t,n){let r=H(e),i=[...e];for(let e=0;e<r;e+=1){let r=f.exec((i[e]??``).trim());if(r!==null&&r[1]===t){i[e]=`**${t}**:${n}`;break}}return i.join(`
|
|
5
|
+
`)}function W(e,t){let n=H(e);return e.filter((e,r)=>{if(r>=n)return!0;let i=f.exec(e.trim());return i===null||i[1]!==t})}function G(e,t,n){let r=H(e),i=r;for(let n=0;n<r;n+=1){let r=f.exec((e[n]??``).trim());if(r!==null&&r[1]===t){i=n+1;break}}return[...e.slice(0,i),n,...e.slice(i)]}function K(e,t){let n=H(e);for(let r=0;r<n;r+=1){let n=f.exec((e[r]??``).trim());if(n!==null&&n[1]===t)return(n[2]??``).trim()}return null}function ge(e,t){let n=e.split(`
|
|
6
|
+
`);if(K(n,`状态`)===null)throw Error(`LifecycleError: status-line-missing`);return G(W(U(n,p,S).split(`
|
|
7
|
+
`),y),p,`**${y}**:${t}`).join(`
|
|
8
8
|
`)}function _e(e,t,n){let r=e.split(`
|
|
9
|
-
`);if(
|
|
10
|
-
`),
|
|
11
|
-
`):
|
|
12
|
-
`)}function
|
|
13
|
-
`)}function
|
|
9
|
+
`);if(K(r,`状态`)===null)throw Error(`LifecycleError: status-line-missing`);let i=W(U(r,p,x).split(`
|
|
10
|
+
`),y),a=K(i,b);return a===null?G(i,p,`**${b}**:${n} ${t}`).join(`
|
|
11
|
+
`):U(i,b,`${a},${n} ${t}`)}function q(e){return[`# ${e.title}`,``,`**${p}**:🔴 规划中`,`**${m}**:${e.filingDate}`,`**${h}**:${e.domain}`,`**${g}**:${e.source}`,``,`## 导览`,``,`- [需求规格](spec.md)——动机、现状、需求内容与验收口径`,`- [任务分解](tasks.md)——阶段与任务 checkbox`,`- [验收清单](checklist.md)——按阶段分组验收项`,`- [进展流水](progress.md)——带日期的进展事件`,``].join(`
|
|
12
|
+
`)}function J(){return[D,``,`${M}:为什么做,动机与问题背景`,``,O,``,`${M}:现状描述与证据`,``,k,``,`${M}:需求条目,EARS 风格 Scenario 列表`,``,A,``,"```criteria",`${M}:一行一判据`,"```",``].join(`
|
|
13
|
+
`)}function Y(){return`# 任务分解
|
|
14
14
|
|
|
15
15
|
## 阶段一
|
|
16
16
|
|
|
17
17
|
- [ ] Task 1:<任务>
|
|
18
18
|
- [ ] <子任务>
|
|
19
|
-
`}function
|
|
19
|
+
`}function ve(){return`# 验收清单
|
|
20
20
|
|
|
21
21
|
## 阶段一
|
|
22
22
|
|
|
23
23
|
- [ ] <验收项>
|
|
24
|
-
`}function
|
|
25
|
-
`)}const
|
|
26
|
-
`)}const X=`## 需求索引`,Z=`暂无条目`;function Q(e){return`- [${e.title}](${e.slug}/README.md) | ${e.statusLabel} | 立案 ${e.filingDate}`}const
|
|
27
|
-
`).map(e
|
|
28
|
-
`)}function
|
|
29
|
-
`)}function
|
|
24
|
+
`}function ye(e){return[`# 进展流水`,``,`- ${e.filingDate} 立项`,``].join(`
|
|
25
|
+
`)}const be=[{name:`README.md`,render:q},{name:`spec.md`,render:()=>J()},{name:`tasks.md`,render:()=>Y()},{name:`checklist.md`,render:()=>ve()},{name:`progress.md`,render:ye}];function xe(){return be.map(e=>`===== ${e.name} =====\n${e.render({title:`<一句话标题>`,filingDate:`<YYYY-MM-DD>`,domain:`<所属域人类可读名>`,source:`<需求来源>`})}`).join(`
|
|
26
|
+
`)}const X=`## 需求索引`,Z=`暂无条目`;function Q(e){return`- [${e.title}](${e.slug}/README.md) | ${e.statusLabel} | 立案 ${e.filingDate}`}const Se=/\]\(([^()/\s]+)\/README\.md\)/;function Ce(e){let t=Se.exec(e);return t===null?null:t[1]??null}function $(e){return e.split(`
|
|
27
|
+
`).map(e=>Ce(e)).filter(e=>e!==null)}const we=["本目录是 lzi-features 注册表,每个需求一个 `<slug>/` 目录,条目为五件套:`README.md`、`spec.md`、`tasks.md`、`checklist.md`、`progress.md`。",``,`## 使用口径`,``,"- 立项:`lzi-features create --title <标题>`,slug 围绕单一需求拟定,中文标题须显式 `--slug`","- 审计:`lzi-features lint` 只读判定,豁免走配置基线棘轮,只许缩短",`- 索引:本 README 的「${X.slice(3)}」节由工具再生,人工内容请写在本节之外`];function Te(e){return[`# ${e} features 注册表`,``,...we,``,X,``,Z,``].join(`
|
|
28
|
+
`)}function Ee(e,t){let n=t.length===0?[Z]:[...t].sort((e,t)=>e.slug.localeCompare(t.slug)).map(Q);return[`# ${e} features 注册表`,``,...we,``,X,``,...n,``].join(`
|
|
29
|
+
`)}function De(e,t,n){if(e===null)return Ee(t,n);let r=n.length===0?[Z]:[...n].sort((e,t)=>e.slug.localeCompare(t.slug)).map(Q),i=e.split(`
|
|
30
30
|
`),a=i.indexOf(X),o=a===-1?[...i]:i.slice(0,a);for(;o.length>0&&(o[o.length-1]?.trim()??`x`)===``;)o.pop();return[...o,``,X,``,...r,``].join(`
|
|
31
|
-
`)}const
|
|
32
|
-
`).some(e=>e.trim().length>0&&!e.trim().startsWith(`待补充`))}function
|
|
31
|
+
`)}const Oe=[{name:`dirname`,required:!0,description:`语义 slug,纯小写字母 kebab,禁数字,围绕单一需求拟定,禁止手工改目录名`},{name:`README.md`,required:!0,description:`条目着陆页:标题、加粗键元数据行与五件导览`},{name:`spec.md`,required:!0,description:`需求规格四节:需求动机、现状与背景、需求内容、验收口径,交付记录为第五节`},{name:`tasks.md`,required:!0,description:`阶段到 Task 到 checkbox 任务分解`},{name:`checklist.md`,required:!0,description:`按阶段分组 checkbox 验收清单`},{name:`progress.md`,required:!0,description:`带日期的进展事件流水`},{name:`状态`,required:!0,description:`五态词表之一:${w.join(`、`)}`},{name:`立案日期`,required:!0,description:`YYYY-MM-DD,真实日历日,README 头部加粗键行`},{name:`所属域`,required:!0,description:`scope 人类可读名,README 头部加粗键行`},{name:`来源`,required:!0,description:`需求来源,用户指令出处或渠道名,README 头部加粗键行`},{name:`进展注记`,required:!1,description:`实现中黄灯强制,不少于 4 字,README 头部加粗键行`},{name:`裁定说明`,required:!1,description:`冻结态强制,须含用户裁定字样,README 头部加粗键行`},{name:`取消原因`,required:!1,description:`取消态强制,README 头部加粗键行`},{name:`阻塞`,required:!1,description:`同注册表 slug 引用列表,顿号分隔,引用未知目录计违规`},{name:`交付记录`,required:!1,description:`spec.md 第五节「${j.slice(3)}」,已交付态强制且不得为占位内容`},{name:`补充材料`,required:!1,description:`需求目录内五件之外的文件,仅观测不判违规`}];function ke(e){return!e.split(`
|
|
32
|
+
`).some(e=>e.trim().length>0&&!e.trim().startsWith(`待补充`))}function Ae(e,t,n){let r=[],i=`${n}/${u}`,a=`${n}/${d}`,c=e.record;if(c===null)return r;if(s(e.dirname)<o&&r.push({rule:`slug-words-insufficient`,file:n,message:`文件名 slug 段词数不足,请迁移为至少三个单词的语义命名`}),c.statusLabel===null?r.push({rule:`status-line-missing`,file:i,message:`README 头部缺「**状态**:标签」元数据行`}):c.status===null&&r.push({rule:`status-label-unknown`,file:i,message:`状态标签「${c.statusLabel}」不在五态词表`}),c.filingDate===null||!E.test(c.filingDate)?r.push({rule:`filing-date-invalid`,file:i,message:`立案日期须为 YYYY-MM-DD 形态元数据行`}):F(c.filingDate)||r.push({rule:`filing-date-invalid`,file:i,message:`立案日期「${c.filingDate}」非真实日历日`}),c.status===`implementing`){let e=c.progressNote?.replaceAll(/\s/g,``).length??0;(c.progressNote===null||e<4)&&r.push({rule:`active-no-progress-note`,file:i,message:`实现中状态须附进展注记且不少于 4 字`})}c.status===`delivered`&&(c.sectionsPresent.has(`## 五、交付记录`)?(c.deliverySectionBody===null||ke(c.deliverySectionBody))&&r.push({rule:`delivered-placeholder`,file:a,message:`交付记录节不得为空或占位内容`}):r.push({rule:`delivered-no-section`,file:a,message:`已交付状态须有 spec.md 第五节交付记录`})),c.status===`frozen`&&(c.adjudicationNote!==null&&c.adjudicationNote.includes(`用户裁定`)||r.push({rule:`frozen-no-adjudication`,file:i,message:`冻结状态须附裁定说明且含「${N}」字样`})),c.status===`canceled`&&c.cancelReason===null&&r.push({rule:`canceled-no-reason`,file:i,message:`取消状态须附取消原因`});let l=/* @__PURE__ */ new Map;for(let e of c.metadataLines)l.set(e.key,(l.get(e.key)??0)+1);for(let[e,t]of l)t>1&&r.push({rule:`duplicate-metadata-key`,file:i,message:`元数据键「${e}」出现 ${t} 次,须唯一`});for(let e of c.blockingRefs)t.has(e)||r.push({rule:`blocking-ref-unknown`,file:i,message:`阻塞引用「${e}」不在本注册表合法 slug 集内`});return r}function je(n,i,a,o){let s=[],c=B(r(n,i)).filter(e=>!V(r(i,e.dirname),a)),l=new Set(c.filter(e=>e.namingValid).map(e=>e.dirname)),u=new Set(c.filter(e=>e.namingValid&&e.hasEntry).map(e=>e.dirname));for(let e of c){let t=r(i,e.dirname);e.namingValid?e.hasEntry?s.push(...Ae(e,l,t)):s.push({rule:`entry-files-missing`,file:t,message:`五件套缺件:${e.missing.join(`、`)}`}):s.push({rule:`slug-policy-violation`,file:t,message:`目录名须为语义 slug 形态,纯小写字母 kebab,禁数字,围绕单一需求拟定`})}let d=r(n,i,`README.md`);if(!e(d))s.push({rule:`index-out-of-sync`,file:r(i,`README.md`),message:`注册表缺 README 索引档,可执行 lzi-features index 再生`});else{let e=$(t(d,`utf8`));for(let t of u)e.includes(t)||s.push({rule:`index-out-of-sync`,file:r(i,`README.md`),message:`索引缺条目「${t}」,可执行 lzi-features index 再生`});for(let t of e)u.has(t)||s.push({rule:`index-out-of-sync`,file:r(i,`README.md`),message:`索引含失效条目「${t}」,可执行 lzi-features index 再生`})}return o.push({scopeKey:i,registryDir:i,featureCount:c.length}),s}function Me(e){let t=[],n=[];for(let r of e.config.scopes)t.push(...je(e.root,r.registryDir,e.config.check.exclusions,n));for(let a of e.extraDirs??[]){let o=r(e.root,a);t.push(...je(o,i(e.root,o),[],n))}let a=new Set(e.config.check.baseline.map(e=>`${e.file}|${e.rule}`)),o=0;return{violations:t.filter(e=>{let t=a.has(`${e.file}|${e.rule}`);return t&&(o+=1),!t}),rawCount:t.length,exemptedCount:o,stats:n}}export{N as ADJUDICATION_PHRASE,u as ENTRY_METADATA_FILENAME,d as ENTRY_SPEC_FILENAME,ce as EXPORT_SCHEMA_VERSION,c as FEATURE_SLUG_PATTERN,E as FILING_DATE_PATTERN,X as INDEX_SECTION_HEADING,y as KEY_ADJUDICATION,_ as KEY_BLOCKING,ee as KEY_CANCEL_REASON,h as KEY_DOMAIN,m as KEY_FILING_DATE,b as KEY_HISTORY,v as KEY_PROGRESS_NOTE,g as KEY_SOURCE,p as KEY_STATUS,f as METADATA_LINE_PATTERN,ae as PROGRESS_NOTE_MIN_LENGTH,l as REQUIRED_ENTRY_FILES,ie as REQUIRED_SECTION_HEADINGS,A as SECTION_HEADING_ACCEPTANCE,O as SECTION_HEADING_CONTEXT,j as SECTION_HEADING_DELIVERY,D as SECTION_HEADING_MOTIVATION,k as SECTION_HEADING_REQUIREMENTS,M as SECTION_PLACEHOLDER,w as STATUS_LABELS,re as STATUS_LABEL_CANCELED,ne as STATUS_LABEL_DELIVERED,S as STATUS_LABEL_FROZEN,te as STATUS_LABEL_IMPLEMENTING,x as STATUS_LABEL_PLANNING,Oe as TEMPLATE_FIELDS,be as TEMPLATE_FILES,ge as applyFreeze,_e as applyUnfreeze,me as buildFeatureExport,I as daysBetween,Ce as extractIndexLineSlug,$ as extractIndexSlugs,V as isExcludedPath,F as isRealCalendarDate,L as parseEntryMetadata,R as parseSpecSections,T as parseStatusLabel,z as recognizeFeatureDir,B as recognizeFeaturesDir,De as regenerateReadmeIndex,ve as renderChecklistMd,q as renderEntryReadme,Q as renderIndexLine,ye as renderProgressMd,Ee as renderRegistryIndex,Te as renderRegistryReadmeStub,xe as renderSkeletonBundle,J as renderSpecMd,Y as renderTasksMd,he as runFeaturesHealth,Me as runFeaturesLint,P as splitRefList};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-features/ledger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test:coverage": "bun test --coverage"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@longzai-intelligence-docs/core": "0.0.
|
|
30
|
-
"@longzai-intelligence-features/config": "0.0.
|
|
29
|
+
"@longzai-intelligence-docs/core": "0.0.30",
|
|
30
|
+
"@longzai-intelligence-features/config": "0.0.5"
|
|
31
31
|
}
|
|
32
32
|
}
|