@longzai-intelligence-features/ledger 0.0.0-stage → 0.0.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.
@@ -0,0 +1,617 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ import { LziFeaturesConfig } from "@longzai-intelligence-features/config";
3
+ //#region src/parser/format.utils.d.ts
4
+ /**
5
+ * features 格式口径单一真源
6
+ *
7
+ * 全部格式口径集中于此模块:需求目录命名形态、正本文件名、头部元数据键与
8
+ * 状态五态词表、正文节标题。识别侧与写侧共用同一真源,create 产物在构造上
9
+ * 天然通过 lint。slug 消费 docs 平台共享基础模块的语义域形态,纯字母 kebab,
10
+ * 禁数字,全族同源
11
+ */
12
+ /**
13
+ * 需求目录 slug 合法形态,语义域为纯小写字母 kebab,禁数字
14
+ */
15
+ declare const FEATURE_SLUG_PATTERN: RegExp;
16
+ /**
17
+ * 需求正本文件名,每个需求目录内的唯一正典文件
18
+ */
19
+ declare const FEATURE_ENTRY_FILENAME = "feature.md";
20
+ /**
21
+ * 头部元数据行形态,加粗键加全角冒号加值
22
+ */
23
+ declare const METADATA_LINE_PATTERN: RegExp;
24
+ /**
25
+ * 头部元数据键:状态
26
+ */
27
+ declare const KEY_STATUS = "状态";
28
+ /**
29
+ * 头部元数据键:立案日期
30
+ */
31
+ declare const KEY_FILING_DATE = "立案日期";
32
+ /**
33
+ * 头部元数据键:所属域
34
+ */
35
+ declare const KEY_DOMAIN = "所属域";
36
+ /**
37
+ * 头部元数据键:来源
38
+ */
39
+ declare const KEY_SOURCE = "来源";
40
+ /**
41
+ * 头部元数据键:阻塞,可选,值为同注册表 slug 引用列表
42
+ */
43
+ declare const KEY_BLOCKING = "阻塞";
44
+ /**
45
+ * 头部元数据键:进展注记,实现中黄灯强制
46
+ */
47
+ declare const KEY_PROGRESS_NOTE = "进展注记";
48
+ /**
49
+ * 头部元数据键:裁定说明,冻结态强制,须含用户裁定字样
50
+ */
51
+ declare const KEY_ADJUDICATION = "裁定说明";
52
+ /**
53
+ * 头部元数据键:取消原因,取消态强制
54
+ */
55
+ declare const KEY_CANCEL_REASON = "取消原因";
56
+ /**
57
+ * 头部元数据键:沿革,可选,解冻等生命周期事件累计
58
+ */
59
+ declare const KEY_HISTORY = "沿革";
60
+ /**
61
+ * 状态标签:规划中
62
+ */
63
+ declare const STATUS_LABEL_PLANNING = "🔴 规划中";
64
+ /**
65
+ * 状态标签:实现中
66
+ */
67
+ declare const STATUS_LABEL_IMPLEMENTING = "🟡 实现中";
68
+ /**
69
+ * 状态标签:已交付
70
+ */
71
+ declare const STATUS_LABEL_DELIVERED = "🟢 已交付";
72
+ /**
73
+ * 状态标签:已冻结
74
+ */
75
+ declare const STATUS_LABEL_FROZEN = "⚪ 已冻结";
76
+ /**
77
+ * 状态标签:已取消
78
+ */
79
+ declare const STATUS_LABEL_CANCELED = "⚫ 已取消";
80
+ /**
81
+ * 状态五态语义种类
82
+ */
83
+ type FeatureStatusKind = 'planning' | 'implementing' | 'delivered' | 'frozen' | 'canceled';
84
+ /**
85
+ * 状态标签词表全集,渲染与识别共用
86
+ */
87
+ declare const STATUS_LABELS: readonly string[];
88
+ /**
89
+ * 解析状态标签为语义种类
90
+ *
91
+ * @param label - 状态行原文值
92
+ * @returns 语义种类,词表外为 null
93
+ */
94
+ declare function parseStatusLabel(label: string): FeatureStatusKind | null;
95
+ /**
96
+ * 立案日期形态,YYYY-MM-DD
97
+ */
98
+ declare const FILING_DATE_PATTERN: RegExp;
99
+ /**
100
+ * 正文节标题:需求动机
101
+ */
102
+ declare const SECTION_HEADING_MOTIVATION = "## 一、需求动机";
103
+ /**
104
+ * 正文节标题:现状与背景
105
+ */
106
+ declare const SECTION_HEADING_CONTEXT = "## 二、现状与背景";
107
+ /**
108
+ * 正文节标题:需求内容
109
+ */
110
+ declare const SECTION_HEADING_REQUIREMENTS = "## 三、需求内容";
111
+ /**
112
+ * 正文节标题:验收口径
113
+ */
114
+ declare const SECTION_HEADING_ACCEPTANCE = "## 四、验收口径";
115
+ /**
116
+ * 正文节标题:交付记录,已交付态强制
117
+ */
118
+ declare const SECTION_HEADING_DELIVERY = "## 五、交付记录";
119
+ /**
120
+ * 必备正文节标题全集,一至四节
121
+ */
122
+ declare const REQUIRED_SECTION_HEADINGS: readonly string[];
123
+ /**
124
+ * 占位符标记,正文待补充行前缀
125
+ */
126
+ declare const SECTION_PLACEHOLDER = "待补充";
127
+ /**
128
+ * 冻结裁定必含字样
129
+ */
130
+ declare const ADJUDICATION_PHRASE = "用户裁定";
131
+ /**
132
+ * 进展注记最小字数
133
+ */
134
+ declare const PROGRESS_NOTE_MIN_LENGTH = 4;
135
+ /**
136
+ * 切分多值元数据为引用列表,空值返回空数组
137
+ *
138
+ * @param value - 元数据原文值
139
+ * @returns 去空引用列表
140
+ */
141
+ declare function splitRefList(value: string): string[];
142
+ /**
143
+ * 判定日期字符串是否为真实存在的日历日期,YYYY-MM-DD
144
+ *
145
+ * @param date - 日期字符串
146
+ * @returns 真实日历日期为 true
147
+ */
148
+ declare function isRealCalendarDate(date: string): boolean;
149
+ /**
150
+ * 计算两个 YYYY-MM-DD 日期的间隔天数,to 减 from,按 UTC 日界
151
+ *
152
+ * @param from - 起始日期
153
+ * @param to - 结束日期
154
+ * @returns 间隔天数
155
+ */
156
+ declare function daysBetween(from: string, to: string): number;
157
+ //#endregion
158
+ //#region src/health/health.core.d.ts
159
+ /**
160
+ * 最老规划中观测
161
+ */
162
+ type OldestPlanning = {
163
+ /**
164
+ * slug
165
+ */
166
+ slug: string;
167
+ /**
168
+ * 立案日期
169
+ */
170
+ filingDate: string;
171
+ /**
172
+ * 账龄天数,相对巡检日
173
+ */
174
+ ageDays: number;
175
+ };
176
+ /**
177
+ * 单 scope 健康观测
178
+ */
179
+ type ScopeHealth = {
180
+ /**
181
+ * scope key
182
+ */
183
+ scopeKey: string;
184
+ /**
185
+ * 注册表目录
186
+ */
187
+ registryDir: string;
188
+ /**
189
+ * 需求总数,排除子树后
190
+ */
191
+ total: number;
192
+ /**
193
+ * 状态分布,五态键全量落位
194
+ */
195
+ byStatus: Record<FeatureStatusKind, number>;
196
+ /**
197
+ * 最老规划中,无规划中条目为 null
198
+ */
199
+ oldestPlanning: OldestPlanning | null;
200
+ };
201
+ /**
202
+ * health 结果
203
+ */
204
+ type FeaturesHealthResult = {
205
+ /**
206
+ * 巡检日,YYYY-MM-DD
207
+ */
208
+ today: string;
209
+ /**
210
+ * 逐 scope 健康观测
211
+ */
212
+ scopes: ScopeHealth[];
213
+ };
214
+ /**
215
+ * health 入参
216
+ */
217
+ type FeaturesHealthInput = {
218
+ /**
219
+ * 仓库根绝对路径
220
+ */
221
+ root: string;
222
+ /**
223
+ * 解析后配置
224
+ */
225
+ config: LziFeaturesConfig;
226
+ /**
227
+ * 巡检日,缺省今日,测试可显式注入
228
+ */
229
+ today?: string;
230
+ };
231
+ /**
232
+ * 运行 health 巡检,全 scope 注册表,只读零写入
233
+ *
234
+ * @param input - health 入参
235
+ * @returns health 结果
236
+ */
237
+ declare function runFeaturesHealth(input: FeaturesHealthInput): FeaturesHealthResult;
238
+ //#endregion
239
+ //#region src/lifecycle/freeze.core.d.ts
240
+ /**
241
+ * 冻结与解冻生命周期核,正本头部改写的唯一实现
242
+ *
243
+ * freeze 把状态行改写为已冻结并在状态行后落裁定说明行,unfreeze 把状态行恢复
244
+ * 为规划中、裁定说明移除、解冻事由并入沿革行。全部改写限定在头部元数据区,
245
+ * 正文一概不动
246
+ */
247
+ /**
248
+ * 冻结正本,状态改已冻结,裁定说明落在状态行后
249
+ *
250
+ * @param content - 正本全文
251
+ * @param reason - 裁定说明,调用侧保证含用户裁定字样
252
+ * @returns 改写后全文
253
+ * @throws {@link Error} 状态行缺失
254
+ */
255
+ declare function applyFreeze(content: string, reason: string): string;
256
+ /**
257
+ * 解冻正本,状态恢复规划中,裁定说明移除,事由并入沿革
258
+ *
259
+ * @param content - 正本全文
260
+ * @param note - 解冻事由,调用侧保证含用户裁定字样
261
+ * @param date - 解冻日期,YYYY-MM-DD
262
+ * @returns 改写后全文
263
+ * @throws {@link Error} 状态行缺失
264
+ */
265
+ declare function applyUnfreeze(content: string, note: string, date: string): string;
266
+ //#endregion
267
+ //#region src/lint/lint.core.d.ts
268
+ /**
269
+ * lint 违例条目
270
+ */
271
+ type FeaturesLintViolation = {
272
+ /**
273
+ * 规则名
274
+ */
275
+ rule: string;
276
+ /**
277
+ * 对象,posix 相对仓库根,目录或目录内文件
278
+ */
279
+ file: string;
280
+ /**
281
+ * 违例消息
282
+ */
283
+ message: string;
284
+ };
285
+ /**
286
+ * 单 scope 扫描观测
287
+ */
288
+ type ScopeScanStats = {
289
+ /**
290
+ * scope key,额外目录用 dir 前缀加路径
291
+ */
292
+ scopeKey: string;
293
+ /**
294
+ * 注册表目录
295
+ */
296
+ registryDir: string;
297
+ /**
298
+ * 识别需求条数,排除子树后
299
+ */
300
+ featureCount: number;
301
+ };
302
+ /**
303
+ * lint 结果
304
+ */
305
+ type FeaturesLintResult = {
306
+ /**
307
+ * 基线豁免后的违例列表
308
+ */
309
+ violations: FeaturesLintViolation[];
310
+ /**
311
+ * 豁免前违例总数
312
+ */
313
+ rawCount: number;
314
+ /**
315
+ * 豁免命中数,棘轮观测面
316
+ */
317
+ exemptedCount: number;
318
+ /**
319
+ * 逐 scope 扫描观测
320
+ */
321
+ stats: ScopeScanStats[];
322
+ };
323
+ /**
324
+ * lint 入参
325
+ */
326
+ type FeaturesLintInput = {
327
+ /**
328
+ * 仓库根绝对路径
329
+ */
330
+ root: string;
331
+ /**
332
+ * 解析后配置
333
+ */
334
+ config: LziFeaturesConfig;
335
+ /**
336
+ * 额外审计目录,posix 相对仓库根,按无排除裸注册表审计
337
+ */
338
+ extraDirs?: readonly string[];
339
+ };
340
+ /**
341
+ * 运行 lint,全 scope 注册表加额外目录,只读零写入
342
+ *
343
+ * @param input - lint 入参
344
+ * @returns lint 结果,违例空即通过
345
+ */
346
+ declare function runFeaturesLint(input: FeaturesLintInput): FeaturesLintResult;
347
+ //#endregion
348
+ //#region src/parser/feature-record.parser.d.ts
349
+ /**
350
+ * 头部元数据行解析结果
351
+ */
352
+ type ParsedMetadataLine = {
353
+ /**
354
+ * 元数据键,加粗原文键名
355
+ */
356
+ key: string;
357
+ /**
358
+ * 元数据值,全角冒号后的原文
359
+ */
360
+ value: string;
361
+ };
362
+ /**
363
+ * feature.md 解析结果
364
+ */
365
+ type ParsedFeatureRecord = {
366
+ /**
367
+ * 标题,首个一级标题行,缺失为 null
368
+ */
369
+ title: string | null;
370
+ /**
371
+ * 头部元数据行按出现顺序全集,含重复,供重复键检测
372
+ */
373
+ metadataLines: ParsedMetadataLine[];
374
+ /**
375
+ * 状态行原文值,缺失为 null
376
+ */
377
+ statusLabel: string | null;
378
+ /**
379
+ * 状态语义种类,词表外或缺失为 null
380
+ */
381
+ status: FeatureStatusKind | null;
382
+ /**
383
+ * 立案日期原文值,缺失为 null
384
+ */
385
+ filingDate: string | null;
386
+ /**
387
+ * 进展注记原文值,缺失为 null
388
+ */
389
+ progressNote: string | null;
390
+ /**
391
+ * 裁定说明原文值,缺失为 null
392
+ */
393
+ adjudicationNote: string | null;
394
+ /**
395
+ * 取消原因原文值,缺失为 null
396
+ */
397
+ cancelReason: string | null;
398
+ /**
399
+ * 阻塞引用列表,缺失或空值为空数组
400
+ */
401
+ blockingRefs: string[];
402
+ /**
403
+ * 在位正文节标题全集
404
+ */
405
+ sectionsPresent: Set<string>;
406
+ /**
407
+ * 交付记录节正文,节缺失为 null
408
+ */
409
+ deliverySectionBody: string | null;
410
+ };
411
+ /**
412
+ * 解析 feature.md 全文
413
+ *
414
+ * @param content - 正本全文
415
+ * @returns 解析结果
416
+ */
417
+ declare function parseFeatureRecord(content: string): ParsedFeatureRecord;
418
+ //#endregion
419
+ //#region src/recognizer/feature-recognizer.core.d.ts
420
+ /**
421
+ * 识别结果条目
422
+ */
423
+ type RecognizedFeature = {
424
+ /**
425
+ * 目录名,即 slug 键载体
426
+ */
427
+ dirname: string;
428
+ /**
429
+ * slug,命名违规时为 null
430
+ */
431
+ slug: string | null;
432
+ /**
433
+ * 命名形态合法标记,语义域纯字母 kebab
434
+ */
435
+ namingValid: boolean;
436
+ /**
437
+ * 正本在位标记
438
+ */
439
+ hasEntry: boolean;
440
+ /**
441
+ * 目录内文件清单,排序后
442
+ */
443
+ files: string[];
444
+ /**
445
+ * 补充材料清单,正本之外的文件
446
+ */
447
+ supplementary: string[];
448
+ /**
449
+ * 正本解析结果,正本缺失为 null
450
+ */
451
+ record: ParsedFeatureRecord | null;
452
+ };
453
+ /**
454
+ * 识别单个需求目录
455
+ *
456
+ * @param registryDirAbs - 注册表目录绝对路径
457
+ * @param dirname - 需求目录名
458
+ * @returns 识别结果
459
+ */
460
+ declare function recognizeFeatureDir(registryDirAbs: string, dirname: string): RecognizedFeature;
461
+ /**
462
+ * 扫描注册表目录并逐目录识别,只读,目录不存在返回空数组
463
+ *
464
+ * @param registryDirAbs - 注册表目录绝对路径
465
+ * @returns 识别结果列表,按目录名排序
466
+ */
467
+ declare function recognizeFeaturesDir(registryDirAbs: string): RecognizedFeature[];
468
+ /**
469
+ * 判定注册表内条目是否命中排除子树,posix 路径前缀匹配
470
+ *
471
+ * @param itemRelPath - 条目相对仓库根的 posix 路径
472
+ * @param exclusions - 排除条目路径列表,相对仓库根
473
+ * @returns 命中任一排除路径为 true
474
+ */
475
+ declare function isExcludedPath(itemRelPath: string, exclusions: readonly {
476
+ path: string;
477
+ }[]): boolean;
478
+ //#endregion
479
+ //#region src/template/feature-template.renderer.d.ts
480
+ /**
481
+ * feature.md 模板与注册表索引渲染器,唯一真源
482
+ *
483
+ * 标准格式两路共用本渲染器:template 命令的骨架展示与 create 的建档实例。
484
+ * 结构常量与格式单一真源共享,结构漂移在构造上不可能发生。渲染产物被识别器
485
+ * 与 lint 判定为合规态,渲染与识别的回环由测试守卫
486
+ *
487
+ * @remarks
488
+ * 注册表 README 为工具-owned 索引档:索引节由本渲染器整体再生,人工请在
489
+ * 索引节之外追加内容并自行维护,index 命令重写时不触碰索引节外的行
490
+ */
491
+ /**
492
+ * instance 模式渲染入参
493
+ */
494
+ type FeatureTemplateValues = {
495
+ /**
496
+ * 一句话标题
497
+ */
498
+ title: string;
499
+ /**
500
+ * 立案日期,YYYY-MM-DD
501
+ */
502
+ filingDate: string;
503
+ /**
504
+ * 所属域人类可读名
505
+ */
506
+ domain: string;
507
+ /**
508
+ * 需求来源,用户指令出处或渠道名
509
+ */
510
+ source: string;
511
+ };
512
+ /**
513
+ * 渲染 feature.md 全文,四节正文骨架,建档即骨架内容随工作回填
514
+ *
515
+ * @param values - 实际值入参
516
+ * @returns 可直接落盘的 feature.md 全文
517
+ */
518
+ declare function renderFeatureMd(values: FeatureTemplateValues): string;
519
+ /**
520
+ * 渲染骨架全文,供 template 命令做 text 输出,占位形态
521
+ *
522
+ * @returns feature.md 骨架全文
523
+ */
524
+ declare function renderSkeleton(): string;
525
+ /**
526
+ * 索引条目,注册表 README 索引行的数据形态
527
+ */
528
+ type IndexEntry = {
529
+ /**
530
+ * slug,目录名
531
+ */
532
+ slug: string;
533
+ /**
534
+ * 标题
535
+ */
536
+ title: string;
537
+ /**
538
+ * 状态标签原文
539
+ */
540
+ statusLabel: string;
541
+ /**
542
+ * 立案日期,YYYY-MM-DD
543
+ */
544
+ filingDate: string;
545
+ };
546
+ /**
547
+ * 索引节标题,工具 owned 产物的再生边界
548
+ */
549
+ declare const INDEX_SECTION_HEADING = "## 需求索引";
550
+ /**
551
+ * 渲染单条索引行
552
+ *
553
+ * @param entry - 索引条目
554
+ * @returns 索引行全文
555
+ */
556
+ declare function renderIndexLine(entry: IndexEntry): string;
557
+ /**
558
+ * 从 README 索引行提取 slug
559
+ *
560
+ * @param line - 索引行文本
561
+ * @returns slug,非索引行为 null
562
+ */
563
+ declare function extractIndexLineSlug(line: string): string | null;
564
+ /**
565
+ * 从 README 全文提取索引 slug 列表
566
+ *
567
+ * @param content - README 全文
568
+ * @returns 索引 slug 列表,按出现顺序
569
+ */
570
+ declare function extractIndexSlugs(content: string): string[];
571
+ /**
572
+ * 渲染注册表 README 存根,init 命令落盘
573
+ *
574
+ * @param scopeTitle - scope 人类可读名
575
+ * @returns README 存根全文
576
+ */
577
+ declare function renderRegistryReadmeStub(scopeTitle: string): string;
578
+ /**
579
+ * 渲染注册表 README 全文,索引节再生,索引节外行原样保留由调用侧拼装
580
+ *
581
+ * @param scopeTitle - scope 人类可读名
582
+ * @param entries - 索引条目列表,slug 升序
583
+ * @returns README 全文
584
+ */
585
+ declare function renderRegistryIndex(scopeTitle: string, entries: readonly IndexEntry[]): string;
586
+ /**
587
+ * 再生注册表 README,索引节重写,索引节外行原样保留
588
+ *
589
+ * @param existing - 现 README 全文,无 README 为 null,走全文渲染
590
+ * @param scopeTitle - scope 人类可读名
591
+ * @param entries - 索引条目列表
592
+ * @returns 再生后的 README 全文
593
+ */
594
+ declare function regenerateReadmeIndex(existing: string | null, scopeTitle: string, entries: readonly IndexEntry[]): string;
595
+ /**
596
+ * 模板字段说明条目,template --format json 载荷
597
+ */
598
+ type TemplateFieldDoc = {
599
+ /**
600
+ * 字段名
601
+ */
602
+ name: string;
603
+ /**
604
+ * 是否必填
605
+ */
606
+ required: boolean;
607
+ /**
608
+ * 字段说明
609
+ */
610
+ description: string;
611
+ };
612
+ /**
613
+ * 标准模板字段说明全集,供 agent 与使用者程序化消费
614
+ */
615
+ declare const TEMPLATE_FIELDS: readonly TemplateFieldDoc[];
616
+ //#endregion
617
+ export { ADJUDICATION_PHRASE, FEATURE_ENTRY_FILENAME, FEATURE_SLUG_PATTERN, FILING_DATE_PATTERN, FeatureStatusKind, FeatureTemplateValues, FeaturesHealthInput, FeaturesHealthResult, FeaturesLintInput, FeaturesLintResult, FeaturesLintViolation, INDEX_SECTION_HEADING, IndexEntry, KEY_ADJUDICATION, KEY_BLOCKING, KEY_CANCEL_REASON, KEY_DOMAIN, KEY_FILING_DATE, KEY_HISTORY, KEY_PROGRESS_NOTE, KEY_SOURCE, KEY_STATUS, METADATA_LINE_PATTERN, OldestPlanning, PROGRESS_NOTE_MIN_LENGTH, ParsedFeatureRecord, ParsedMetadataLine, REQUIRED_SECTION_HEADINGS, RecognizedFeature, SECTION_HEADING_ACCEPTANCE, SECTION_HEADING_CONTEXT, SECTION_HEADING_DELIVERY, SECTION_HEADING_MOTIVATION, SECTION_HEADING_REQUIREMENTS, SECTION_PLACEHOLDER, STATUS_LABELS, STATUS_LABEL_CANCELED, STATUS_LABEL_DELIVERED, STATUS_LABEL_FROZEN, STATUS_LABEL_IMPLEMENTING, STATUS_LABEL_PLANNING, ScopeHealth, ScopeScanStats, TEMPLATE_FIELDS, TemplateFieldDoc, applyFreeze, applyUnfreeze, daysBetween, extractIndexLineSlug, extractIndexSlugs, isExcludedPath, isRealCalendarDate, parseFeatureRecord, parseStatusLabel, recognizeFeatureDir, recognizeFeaturesDir, regenerateReadmeIndex, renderFeatureMd, renderIndexLine, renderRegistryIndex, renderRegistryReadmeStub, renderSkeleton, runFeaturesHealth, runFeaturesLint, splitRefList };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import"./rolldown-runtime-BqT_7tdF.js";import{join as e,relative as t}from"node:path";import{SEMANTIC_SLUG_PATTERN as n}from"@longzai-intelligence-docs/core";import{existsSync as r,readFileSync as i,readdirSync as a}from"node:fs";const o=n,s=`feature.md`,c=/^\*\*([^*:]+)\*\*:(.*)$/,l=`状态`,u=`立案日期`,d=`所属域`,f=`来源`,p=`阻塞`,m=`进展注记`,h=`裁定说明`,g=`取消原因`,_=`沿革`,v=`🔴 规划中`,y=`🟡 实现中`,b=`🟢 已交付`,x=`⚪ 已冻结`,S=`⚫ 已取消`,C=/* @__PURE__ */ new Map([[v,`planning`],[y,`implementing`],[b,`delivered`],[x,`frozen`],[S,`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=`## 五、交付记录`,ee=[D,O,k,A],M=`待补充`,N=`用户裁定`,te=4,ne=/[、,,]\s*/;function P(e){return e.split(ne).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 re(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=c.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(l),d=o(p),f=new Set(t.filter(e=>e.startsWith(`## `)));return{title:n,metadataLines:a,statusLabel:s,status:s===null?null:T(s),filingDate:o(u),progressNote:o(m),adjudicationNote:o(h),cancelReason:o(g),blockingRefs:d===null?[]:P(d),sectionsPresent:f,deliverySectionBody:re(t,j)}}function R(t,n){let r=e(t,n),c=[];try{c=a(r,{withFileTypes:!0}).filter(e=>e.isFile()).map(e=>e.name).sort()}catch{c=[]}let l=c.includes(s),u=null;if(l)try{u=L(i(e(r,s),`utf8`))}catch{u=null}return{dirname:n,slug:o.test(n)?n:null,namingValid:o.test(n),hasEntry:l,files:c,supplementary:c.filter(e=>e!==s),record:u}}function z(e){let t=[];try{t=a(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}return t.sort().map(t=>R(e,t))}function B(e,t){return t.some(t=>e===t.path||e.startsWith(`${t.path}/`))}function ie(t){let n=t.today??new Intl.DateTimeFormat(`en-CA`,{year:`numeric`,month:`2-digit`,day:`2-digit`}).format(/* @__PURE__ */ new Date),r=[];for(let i of t.config.scopes){let a=z(e(t.root,i.registryDir)).filter(n=>!B(e(i.registryDir,n.dirname),t.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??n,n)})).sort((e,t)=>t.ageDays-e.ageDays)[0];r.push({scopeKey:i.key,registryDir:i.registryDir,total:a.length,byStatus:o,oldestPlanning:s===void 0||s.filingDate===``?null:s})}return{today:n,scopes:r}}function V(e){let t=e.findIndex(e=>e.startsWith(`## `));return t===-1?e.length:t}function H(e,t,n){let r=V(e),i=[...e];for(let e=0;e<r;e+=1){let r=c.exec((i[e]??``).trim());if(r!==null&&r[1]===t){i[e]=`**${t}**:${n}`;break}}return i.join(`
4
+ `)}function U(e,t){let n=V(e);return e.filter((e,r)=>{if(r>=n)return!0;let i=c.exec(e.trim());return i===null||i[1]!==t})}function W(e,t,n){let r=V(e),i=r;for(let n=0;n<r;n+=1){let r=c.exec((e[n]??``).trim());if(r!==null&&r[1]===t){i=n+1;break}}return[...e.slice(0,i),n,...e.slice(i)]}function G(e,t){let n=V(e);for(let r=0;r<n;r+=1){let n=c.exec((e[r]??``).trim());if(n!==null&&n[1]===t)return(n[2]??``).trim()}return null}function ae(e,t){let n=e.split(`
5
+ `);if(G(n,`状态`)===null)throw Error(`LifecycleError: status-line-missing`);return W(U(H(n,l,x).split(`
6
+ `),h),l,`**${h}**:${t}`).join(`
7
+ `)}function oe(e,t,n){let r=e.split(`
8
+ `);if(G(r,`状态`)===null)throw Error(`LifecycleError: status-line-missing`);let i=U(H(r,l,v).split(`
9
+ `),h),a=G(i,_);return a===null?W(i,l,`**${_}**:${n} ${t}`).join(`
10
+ `):H(i,_,`${a},${n} ${t}`)}function K(e){return[`# ${e.title}`,``,`**${l}**:🔴 规划中`,`**${u}**:${e.filingDate}`,`**${d}**:${e.domain}`,`**${f}**:${e.source}`,``,D,``,`${M}:为什么做,动机与问题背景`,``,O,``,`${M}:现状描述与证据`,``,k,``,`${M}:需求条目,EARS 风格 Scenario 列表`,``,A,``,"```criteria",`${M}:一行一判据`,"```",``].join(`
11
+ `)}function se(){return K({title:`<一句话标题>`,filingDate:`<YYYY-MM-DD>`,domain:`<所属域人类可读名>`,source:`<需求来源>`})}const q=`## 需求索引`,J=`暂无条目`;function Y(e){return`- [${e.title}](${e.slug}/feature.md) | ${e.statusLabel} | 立案 ${e.filingDate}`}const ce=/\]\(([^()/\s]+)\/feature\.md\)/;function X(e){let t=ce.exec(e);return t===null?null:t[1]??null}function Z(e){return e.split(`
12
+ `).map(e=>X(e)).filter(e=>e!==null)}function le(e){return[`# ${e} features 注册表`,``,"本目录是 lzi-features 注册表,每个需求一个 `<slug>/` 目录,正本为目录内 `feature.md`。",``,`## 使用口径`,``,"- 立项:`lzi-features create --title <标题>`,slug 缺省由标题派生,中文标题须显式 `--slug`","- 审计:`lzi-features lint` 只读判定,豁免走配置基线棘轮,只许缩短",`- 索引:本 README 的「${q.slice(3)}」节由工具再生,人工内容请写在本节之外`,``,q,``,J,``].join(`
13
+ `)}function Q(e,t){let n=t.length===0?[J]:[...t].sort((e,t)=>e.slug.localeCompare(t.slug)).map(Y);return[`# ${e} features 注册表`,``,"本目录是 lzi-features 注册表,每个需求一个 `<slug>/` 目录,正本为目录内 `feature.md`。",``,`## 使用口径`,``,"- 立项:`lzi-features create --title <标题>`,slug 缺省由标题派生,中文标题须显式 `--slug`","- 审计:`lzi-features lint` 只读判定,豁免走配置基线棘轮,只许缩短",`- 索引:本 README 的「${q.slice(3)}」节由工具再生,人工内容请写在本节之外`,``,q,``,...n,``].join(`
14
+ `)}function ue(e,t,n){if(e===null)return Q(t,n);let r=n.length===0?[J]:[...n].sort((e,t)=>e.slug.localeCompare(t.slug)).map(Y),i=e.split(`
15
+ `),a=i.indexOf(q),o=a===-1?[...i]:i.slice(0,a);for(;o.length>0&&(o[o.length-1]?.trim()??`x`)===``;)o.pop();return[...o,``,q,``,...r,``].join(`
16
+ `)}const de=[{name:`dirname`,required:!0,description:`语义 slug,纯小写字母 kebab,禁数字,由 create 生成,禁止手工改目录名`},{name:`feature.md`,required:!0,description:`需求正本,四节正文:需求动机、现状与背景、需求内容、验收口径`},{name:`状态`,required:!0,description:`五态词表之一:${w.join(`、`)}`},{name:`立案日期`,required:!0,description:`YYYY-MM-DD,真实日历日,加粗键加全角冒号行`},{name:`所属域`,required:!0,description:`scope 人类可读名,加粗键加全角冒号行`},{name:`来源`,required:!0,description:`需求来源,用户指令出处或渠道名,加粗键加全角冒号行`},{name:`进展注记`,required:!1,description:`实现中黄灯强制,不少于 4 字`},{name:`裁定说明`,required:!1,description:`冻结态强制,须含用户裁定字样`},{name:`取消原因`,required:!1,description:`取消态强制`},{name:`阻塞`,required:!1,description:`同注册表 slug 引用列表,顿号分隔,引用未知目录计违规`},{name:`交付记录`,required:!1,description:`正文第五节「${j.slice(3)}」,已交付态强制且不得为占位内容`},{name:`补充材料`,required:!1,description:`需求目录内 feature.md 之外的文件,仅观测不判违规`}];function fe(e){return!e.split(`
17
+ `).some(e=>e.trim().length>0&&!e.trim().startsWith(`待补充`))}function pe(e,t,n){let r=[],i=`${n}/feature.md`,a=e.record;if(a===null)return r;if(a.statusLabel===null?r.push({rule:`status-line-missing`,file:i,message:`正本头部缺「**状态**:标签」元数据行`}):a.status===null&&r.push({rule:`status-label-unknown`,file:i,message:`状态标签「${a.statusLabel}」不在五态词表`}),a.filingDate===null||!E.test(a.filingDate)?r.push({rule:`filing-date-invalid`,file:i,message:`立案日期须为 YYYY-MM-DD 形态元数据行`}):F(a.filingDate)||r.push({rule:`filing-date-invalid`,file:i,message:`立案日期「${a.filingDate}」非真实日历日`}),a.status===`implementing`){let e=a.progressNote?.replaceAll(/\s/g,``).length??0;(a.progressNote===null||e<4)&&r.push({rule:`active-no-progress-note`,file:i,message:`实现中状态须附进展注记且不少于 4 字`})}a.status===`delivered`&&(a.sectionsPresent.has(`## 五、交付记录`)?(a.deliverySectionBody===null||fe(a.deliverySectionBody))&&r.push({rule:`delivered-placeholder`,file:i,message:`交付记录节不得为空或占位内容`}):r.push({rule:`delivered-no-section`,file:i,message:`已交付状态须有正文第五节交付记录`})),a.status===`frozen`&&(a.adjudicationNote===null||!a.adjudicationNote.includes(`用户裁定`))&&r.push({rule:`frozen-no-adjudication`,file:i,message:`冻结状态须附裁定说明且含「${N}」字样`}),a.status===`canceled`&&a.cancelReason===null&&r.push({rule:`canceled-no-reason`,file:i,message:`取消状态须附取消原因`});let o=/* @__PURE__ */ new Map;for(let e of a.metadataLines)o.set(e.key,(o.get(e.key)??0)+1);for(let[e,t]of o)t>1&&r.push({rule:`duplicate-metadata-key`,file:i,message:`元数据键「${e}」出现 ${t} 次,须唯一`});for(let e of a.blockingRefs)t.has(e)||r.push({rule:`blocking-ref-unknown`,file:i,message:`阻塞引用「${e}」不在本注册表合法 slug 集内`});return r}function $(t,n,a,o){let s=[],c=z(e(t,n)).filter(t=>!B(e(n,t.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 t of c){let r=e(n,t.dirname);t.namingValid?t.hasEntry?s.push(...pe(t,l,r)):s.push({rule:`feature-md-missing`,file:r,message:`需求目录缺正本 feature.md`}):s.push({rule:`slug-policy-violation`,file:r,message:`目录名须为语义 slug 形态,纯小写字母 kebab,禁数字`})}let d=e(t,n,`README.md`);if(!r(d))s.push({rule:`index-out-of-sync`,file:e(n,`README.md`),message:`注册表缺 README 索引档,可执行 lzi-features index 再生`});else{let t=Z(i(d,`utf8`));for(let r of u)t.includes(r)||s.push({rule:`index-out-of-sync`,file:e(n,`README.md`),message:`索引缺条目「${r}」,可执行 lzi-features index 再生`});for(let r of t)u.has(r)||s.push({rule:`index-out-of-sync`,file:e(n,`README.md`),message:`索引含失效条目「${r}」,可执行 lzi-features index 再生`})}return o.push({scopeKey:n,registryDir:n,featureCount:c.length}),s}function me(n){let r=[],i=[];for(let e of n.config.scopes)r.push(...$(n.root,e.registryDir,n.config.check.exclusions,i));for(let a of n.extraDirs??[]){let o=e(n.root,a);r.push(...$(o,t(n.root,o),[],i))}let a=new Set(n.config.check.baseline.map(e=>`${e.file}|${e.rule}`)),o=0;return{violations:r.filter(e=>{let t=a.has(`${e.file}|${e.rule}`);return t&&(o+=1),!t}),rawCount:r.length,exemptedCount:o,stats:i}}export{N as ADJUDICATION_PHRASE,s as FEATURE_ENTRY_FILENAME,o as FEATURE_SLUG_PATTERN,E as FILING_DATE_PATTERN,q as INDEX_SECTION_HEADING,h as KEY_ADJUDICATION,p as KEY_BLOCKING,g as KEY_CANCEL_REASON,d as KEY_DOMAIN,u as KEY_FILING_DATE,_ as KEY_HISTORY,m as KEY_PROGRESS_NOTE,f as KEY_SOURCE,l as KEY_STATUS,c as METADATA_LINE_PATTERN,te as PROGRESS_NOTE_MIN_LENGTH,ee 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,S as STATUS_LABEL_CANCELED,b as STATUS_LABEL_DELIVERED,x as STATUS_LABEL_FROZEN,y as STATUS_LABEL_IMPLEMENTING,v as STATUS_LABEL_PLANNING,de as TEMPLATE_FIELDS,ae as applyFreeze,oe as applyUnfreeze,I as daysBetween,X as extractIndexLineSlug,Z as extractIndexSlugs,B as isExcludedPath,F as isRealCalendarDate,L as parseFeatureRecord,T as parseStatusLabel,R as recognizeFeatureDir,z as recognizeFeaturesDir,ue as regenerateReadmeIndex,K as renderFeatureMd,Y as renderIndexLine,Q as renderRegistryIndex,le as renderRegistryReadmeStub,se as renderSkeleton,ie as runFeaturesHealth,me as runFeaturesLint,P as splitRefList};
@@ -0,0 +1 @@
1
+ import"node:module";export{};
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-features/ledger",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.2",
4
+ "license": "UNLICENSED",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "build": "lzi-builder",
19
+ "build:prod": "NODE_ENV=production bun run build",
20
+ "prepublishOnly": "bun run build:prod",
21
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
22
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
23
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
24
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
25
+ "lint": "oxlint && oxfmt --check",
26
+ "lint:fix": "oxlint --fix && oxfmt",
27
+ "test": "bun test",
28
+ "test:watch": "bun test --watch",
29
+ "test:coverage": "bun test --coverage"
30
+ },
31
+ "dependencies": {
32
+ "@longzai-intelligence-docs/core": "0.0.12",
33
+ "@longzai-intelligence-features/config": "0.0.2"
34
+ },
35
+ "devDependencies": {
36
+ "@types/bun": "latest"
37
+ }
38
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.