@longzai-intelligence-features/config 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,248 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ import * as z from "zod";
3
+ //#region src/schema/lzi-features-config.schema.d.ts
4
+ /**
5
+ * scope key 合法形态,kebab-case
6
+ */
7
+ declare const SCOPE_KEY_PATTERN: RegExp;
8
+ /**
9
+ * init 缺省注册表目录
10
+ */
11
+ declare const DEFAULT_REGISTRY_DIR = "docs/features";
12
+ /**
13
+ * 缺省单 root 注册面,开箱即用正形——ADR 0113 全局规定
14
+ *
15
+ * @remarks
16
+ * defineConfig 无参调用即接入,缺省零参数。无信息增量的单 root 注册面
17
+ * 内置为程序侧参数,显性化到配置文件违反开箱即用,仅真实信息增量的
18
+ * 配置项才显式填写
19
+ */
20
+ declare const DEFAULT_SCOPES: readonly ScopeEntry[];
21
+ /**
22
+ * 棘轮基线条目 schema,存量豁免逐条带理由登记——存量不追溯,豁免只许缩短
23
+ */
24
+ declare const baselineEntrySchema: z.ZodObject<{
25
+ file: z.ZodString;
26
+ rule: z.ZodString;
27
+ reason: z.ZodString;
28
+ }, z.core.$strict>;
29
+ /**
30
+ * 注册表排除条目 schema,存量子树保护——posix 相对注册表目录的路径前缀
31
+ */
32
+ declare const exclusionEntrySchema: z.ZodObject<{
33
+ path: z.ZodString;
34
+ reason: z.ZodString;
35
+ }, z.core.$strict>;
36
+ /**
37
+ * scope 注册条目 schema
38
+ */
39
+ declare const scopeSchema: z.ZodObject<{
40
+ key: z.ZodString;
41
+ title: z.ZodString;
42
+ paths: z.ZodArray<z.ZodString>;
43
+ registryDir: z.ZodString;
44
+ }, z.core.$strict>;
45
+ /**
46
+ * scope 注册条目,书写形态
47
+ */
48
+ type ScopeEntryInput = z.input<typeof scopeSchema>;
49
+ /**
50
+ * scope 注册条目,解析后形态
51
+ */
52
+ type ScopeEntry = z.output<typeof scopeSchema>;
53
+ /**
54
+ * lzi-features 配置根 schema
55
+ */
56
+ declare const lziFeaturesConfigSchema: z.ZodObject<{
57
+ scopes: z.ZodDefault<z.ZodArray<z.ZodObject<{
58
+ key: z.ZodString;
59
+ title: z.ZodString;
60
+ paths: z.ZodArray<z.ZodString>;
61
+ registryDir: z.ZodString;
62
+ }, z.core.$strict>>>;
63
+ check: z.ZodDefault<z.ZodObject<{
64
+ baseline: z.ZodDefault<z.ZodArray<z.ZodObject<{
65
+ file: z.ZodString;
66
+ rule: z.ZodString;
67
+ reason: z.ZodString;
68
+ }, z.core.$strict>>>;
69
+ exclusions: z.ZodDefault<z.ZodArray<z.ZodObject<{
70
+ path: z.ZodString;
71
+ reason: z.ZodString;
72
+ }, z.core.$strict>>>;
73
+ }, z.core.$strict>>;
74
+ }, z.core.$strict>;
75
+ /**
76
+ * lzi-features 配置,用户书写形态,可省略各默认值,无参即接入
77
+ */
78
+ type LziFeaturesConfigInput = z.input<typeof lziFeaturesConfigSchema>;
79
+ /**
80
+ * lzi-features 配置,解析后形态,默认值全部落定
81
+ */
82
+ type LziFeaturesConfig = z.output<typeof lziFeaturesConfigSchema>;
83
+ /**
84
+ * 棘轮基线条目
85
+ */
86
+ type CheckBaselineEntry = z.infer<typeof baselineEntrySchema>;
87
+ /**
88
+ * 注册表排除条目
89
+ */
90
+ type CheckExclusionEntry = z.infer<typeof exclusionEntrySchema>;
91
+ /**
92
+ * 解析并校验配置,非法即抛,加载即失败
93
+ *
94
+ * @param input - 配置原始对象,defineConfig 产物
95
+ * @returns 默认值落定的配置
96
+ * @throws {@link Error} 形态违规,消息聚合全部违规项,跨条目语义校验由
97
+ * validateLziFeaturesConfig 在加载链路上追加执行
98
+ */
99
+ declare function parseLziFeaturesConfig(input: unknown): LziFeaturesConfig;
100
+ /**
101
+ * 定义 lzi-features 配置,identity 工厂
102
+ *
103
+ * 类型透传,与 lzi-dev.config.ts 等 workspace 配置惯例同构:不在工厂层做任何
104
+ * 合并,默认值由本模块 schema 解析层统一落定。无参调用即接入,缺省单 root
105
+ * 注册面内置为程序侧参数——ADR 0113 开箱即用全局规定
106
+ *
107
+ * @param config - 配置对象,可省略,可省略各默认值
108
+ * @returns 原样返回传入的配置对象
109
+ */
110
+ declare function defineConfig(config?: LziFeaturesConfigInput): LziFeaturesConfigInput;
111
+ //#endregion
112
+ //#region src/baseline/render-baseline.renderer.d.ts
113
+ /**
114
+ * 棘轮契约注释头,再生文件头
115
+ */
116
+ declare const RATCHET_CONTRACT_HEADER: string;
117
+ /**
118
+ * 基线条目排序与去重,file 与 rule 组合唯一,file 升序、rule 次序
119
+ *
120
+ * @param entries - 原始条目列表
121
+ * @returns 排序去重后的条目列表
122
+ */
123
+ declare function deriveBaselineEntries(entries: readonly CheckBaselineEntry[]): CheckBaselineEntry[];
124
+ /**
125
+ * 渲染基线再生后的完整配置文件
126
+ *
127
+ * @param config - 当前解析后配置,其余节值原样保留
128
+ * @param baseline - 再生基线条目,通常为 deriveBaselineEntries 产物
129
+ * @returns 完整配置文件文本,棘轮契约头加 defineConfig 体
130
+ */
131
+ declare function renderBaselineRegeneratedConfig(config: LziFeaturesConfig, baseline: readonly CheckBaselineEntry[]): string;
132
+ //#endregion
133
+ //#region src/loader/load-features-config.utils.d.ts
134
+ /**
135
+ * 配置来源类型
136
+ */
137
+ type LziFeaturesConfigSource = 'standalone' | 'unified' | 'explicit';
138
+ /**
139
+ * 加载成功结果
140
+ */
141
+ type LoadLziFeaturesConfigSuccess = {
142
+ /**
143
+ * 加载成功标记
144
+ */
145
+ ok: true;
146
+ /**
147
+ * 解析并校验后的配置,默认值全部落定
148
+ */
149
+ config: LziFeaturesConfig;
150
+ /**
151
+ * 命中的配置文件绝对路径
152
+ */
153
+ configFilePath: string;
154
+ /**
155
+ * 配置来源
156
+ */
157
+ source: LziFeaturesConfigSource;
158
+ };
159
+ /**
160
+ * 加载失败结果,未找到配置
161
+ */
162
+ type LoadLziFeaturesConfigFailure = {
163
+ /**
164
+ * 加载成功标记
165
+ */
166
+ ok: false;
167
+ /**
168
+ * 失败原因
169
+ */
170
+ reason: string;
171
+ };
172
+ /**
173
+ * 加载结果
174
+ */
175
+ type LoadLziFeaturesConfigResult = LoadLziFeaturesConfigSuccess | LoadLziFeaturesConfigFailure;
176
+ /**
177
+ * 加载选项
178
+ */
179
+ type LoadLziFeaturesConfigOptions = {
180
+ /**
181
+ * 查找起点目录,缺省取当前工作目录
182
+ */
183
+ cwd?: string;
184
+ /**
185
+ * 显式配置文件路径,优先级最高,绕过向上查找
186
+ */
187
+ configPath?: string;
188
+ };
189
+ /**
190
+ * 加载 lzi-features 配置
191
+ *
192
+ * @param options - 加载选项
193
+ * @returns 加载结果:命中返回解析后配置,未找到返回失败,显式路径不存在也按失败处理
194
+ * @throws {@link Error} 命中配置但形态或跨条目非法,加载即失败语义
195
+ */
196
+ declare function loadLziFeaturesConfig(options?: LoadLziFeaturesConfigOptions): Promise<LoadLziFeaturesConfigResult>;
197
+ /**
198
+ * 按显式文件 URL 动态导入配置模块,测试与工具内部使用
199
+ *
200
+ * @param configPath - 配置文件绝对路径
201
+ * @returns 配置模块 default 导出
202
+ * @throws {@link Error} 导入失败或无 default 导出
203
+ */
204
+ declare function importConfigModule(configPath: string): Promise<unknown>;
205
+ //#endregion
206
+ //#region src/scaffold/render-scaffold.renderer.d.ts
207
+ /**
208
+ * lzi-features 配置脚手架渲染,init 命令落盘
209
+ *
210
+ * 正形为 defineConfig 无参调用——ADR 0113 开箱即用全局规定。旗标未显式给定时
211
+ * 渲染无参形态,显式给定时渲染单 scope 显式形态,幂等不覆盖由命令层守卫
212
+ */
213
+ /**
214
+ * 脚手架渲染入参
215
+ */
216
+ type ConfigScaffoldInput = {
217
+ /**
218
+ * scope key,kebab-case
219
+ */
220
+ scopeKey: string;
221
+ /**
222
+ * scope 人类可读名
223
+ */
224
+ scopeTitle: string;
225
+ /**
226
+ * 注册表目录,posix 相对仓库根
227
+ */
228
+ registryDir: string;
229
+ };
230
+ /**
231
+ * 渲染 lzi-features.config.ts 脚手架全文
232
+ *
233
+ * @param input - 脚手架入参,缺省渲染无参正形
234
+ * @returns 可直接落盘的配置文件全文
235
+ */
236
+ declare function renderConfigScaffold(input?: ConfigScaffoldInput): string;
237
+ //#endregion
238
+ //#region src/validation/validate-cross-entries.d.ts
239
+ /**
240
+ * 校验并透传配置,语义非法即抛,消息聚合全部违规项
241
+ *
242
+ * @param config - 形态解析后的配置
243
+ * @returns 原样透传,校验通过
244
+ * @throws {@link Error} 跨条目语义违规
245
+ */
246
+ declare function validateLziFeaturesConfig(config: LziFeaturesConfig): LziFeaturesConfig;
247
+ //#endregion
248
+ export { CheckBaselineEntry, CheckExclusionEntry, ConfigScaffoldInput, DEFAULT_REGISTRY_DIR, DEFAULT_SCOPES, LoadLziFeaturesConfigFailure, LoadLziFeaturesConfigOptions, LoadLziFeaturesConfigResult, LoadLziFeaturesConfigSuccess, LziFeaturesConfig, LziFeaturesConfigInput, LziFeaturesConfigSource, RATCHET_CONTRACT_HEADER, SCOPE_KEY_PATTERN, ScopeEntry, ScopeEntryInput, baselineEntrySchema, defineConfig, deriveBaselineEntries, exclusionEntrySchema, importConfigModule, loadLziFeaturesConfig, lziFeaturesConfigSchema, parseLziFeaturesConfig, renderBaselineRegeneratedConfig, renderConfigScaffold, validateLziFeaturesConfig };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import"./rolldown-runtime-BqT_7tdF.js";import*as e from"zod";import{loadUnifiedConfig as t}from"@longzai-intelligence-shared-config/core";import{existsSync as n}from"node:fs";import{resolve as r}from"node:path";import{pathToFileURL as i}from"node:url";const a=/^[a-z][a-z0-9-]*$/,o=`docs/features`,s=[{key:`root`,title:`全局`,paths:[`.`],registryDir:o}],c=e.strictObject({file:e.string().min(1),rule:e.string().min(1),reason:e.string().min(1)}),l=e.strictObject({path:e.string().min(1),reason:e.string().min(1)}),u=e.strictObject({key:e.string().regex(a),title:e.string().min(1),paths:e.array(e.string().min(1)).min(1),registryDir:e.string().min(1)}),d=e.strictObject({baseline:e.array(c).default([]),exclusions:e.array(l).default([])}),f=e.strictObject({scopes:e.array(u).min(1).default([...s]),check:d.default({baseline:[],exclusions:[]})});function p(e){let t=f.safeParse(e);if(!t.success){let e=t.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`,`);throw Error(`lzi-features 配置形态非法:${e}`)}return t.data}function m(e={}){return e}const h=[`/**`," * lzi-features 配置,由 `--write-baseline --reason <理由>` 再生",` *`,` * 棘轮基线语义:基线按 file 与 rule 精确命中豁免存量违规,基线外新增违规仍红,`,` * 基线条目无对应现行违规计陈旧,修复存量即须同步删除对应条目,棘轮只许缩短直至清零,`,` * 每条豁免必须携带收编理由`,` *`,` * 注意:再生以解析值重建本文件,节内手工注释不保留,长篇说明请写入 docs 目录`,` */`].join(`
2
+ `);function g(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=`${n.file}::${n.rule}`;t.has(e)||t.set(e,{...n})}return[...t.values()].sort((e,t)=>e.file===t.file?e.rule.localeCompare(t.rule):e.file.localeCompare(t.file))}function _(e,t){let n=JSON.stringify(e.scopes)===JSON.stringify(s),r=[`import { defineConfig } from '@longzai-intelligence-features/config';`,``,...h.split(`
3
+ `),`export default defineConfig({`];if(!n){r.push(` scopes: [`);for(let t of e.scopes){let e=t.paths.map(e=>`'${e}'`).join(`, `);r.push(` { key: '${t.key}', title: '${t.title}', paths: [${e}], registryDir: '${t.registryDir}' },`)}r.push(` ],`)}r.push(` check: {`,` baseline: [`);for(let e of t)r.push(` { file: '${e.file}', rule: '${e.rule}', reason: '${e.reason}' },`);r.push(` ],`,` exclusions: [`);for(let t of e.check.exclusions)r.push(` { path: '${t.path}', reason: '${t.reason}' },`);return r.push(` ],`,` },`,`});`,``),r.join(`
4
+ `)}function v(e){let t=[],n=/* @__PURE__ */ new Map;for(let t of e.scopes)n.set(t.key,(n.get(t.key)??0)+1);for(let[e,r]of n)r>1&&t.push(`scopes: key「${e}」重复登记 ${r} 次,scope key 必须唯一`);let r=/* @__PURE__ */ new Map;for(let t of e.scopes){let e=r.get(t.registryDir)??[];e.push(t.key),r.set(t.registryDir,e)}for(let[e,n]of r)n.length>1&&t.push(`scopes: 注册表目录「${e}」被 ${n.join(`、`)} 共用,一目录一 scope,否则识别与 lint 歧义`);for(let n of e.check.baseline)e.scopes.some(e=>n.file===e.registryDir||n.file.startsWith(`${e.registryDir}/`))||t.push(`check.baseline: 豁免条目「${n.file}」规则 ${n.rule} 不在任何 scope 注册表目录内`);let i=/* @__PURE__ */ new Map;for(let t of e.check.exclusions)i.set(t.path,(i.get(t.path)??0)+1);for(let[e,n]of i)n>1&&t.push(`check.exclusions: 排除路径「${e}」重复登记 ${n} 次`);for(let n of e.check.exclusions)e.scopes.some(e=>n.path===e.registryDir||n.path.startsWith(`${e.registryDir}/`))||t.push(`check.exclusions: 排除条目「${n.path}」不在任何 scope 注册表目录内`);if(t.length>0)throw Error(`lzi-features 配置跨条目语义非法:${t.join(`,`)}`);return e}function y(e,t){try{return v(p(e))}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`${n},配置文件:${t}`)}}async function b(e={}){if(e.configPath!==void 0){let t=r(e.cwd??process.cwd(),e.configPath);return n(t)?{ok:!0,config:y(await x(t),t),configFilePath:t,source:`explicit`}:{ok:!1,reason:`未找到配置文件:${t}`}}let i=await t({standaloneFile:`lzi-features.config.ts`,unifiedField:`features`,cwd:e.cwd});return i.success?{ok:!0,config:y(i.config,i.configFilePath),configFilePath:i.configFilePath,source:i.source}:{ok:!1,reason:`未找到 lzi-features.config.ts,且 lzi.config.ts 无 features 字段,可先执行 lzi-features init`}}async function x(e){let t=await import(i(e).href);if(t.default===void 0)throw Error(`配置文件缺少 default 导出:${e}`);return t.default}function S(e){return e===void 0?[`import { defineConfig } from '@longzai-intelligence-features/config';`,``,`/**`,` * lzi-features 配置`,` */`,`export default defineConfig();`,``].join(`
5
+ `):[`import { defineConfig } from '@longzai-intelligence-features/config';`,``,`/**`,` * lzi-features 配置`,` */`,`export default defineConfig({`,` scopes: [`,` { key: '${e.scopeKey}', title: '${e.scopeTitle}', paths: ['.'], registryDir: '${e.registryDir}' },`,` ],`,`});`,``].join(`
6
+ `)}export{o as DEFAULT_REGISTRY_DIR,s as DEFAULT_SCOPES,h as RATCHET_CONTRACT_HEADER,a as SCOPE_KEY_PATTERN,c as baselineEntrySchema,m as defineConfig,g as deriveBaselineEntries,l as exclusionEntrySchema,x as importConfigModule,b as loadLziFeaturesConfig,f as lziFeaturesConfigSchema,p as parseLziFeaturesConfig,_ as renderBaselineRegeneratedConfig,S as renderConfigScaffold,v as validateLziFeaturesConfig};
@@ -0,0 +1 @@
1
+ import"node:module";export{};
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-features/config",
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-shared-config/core": "^0.0.5",
33
+ "zod": "^4.4.3"
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.