@longzai-intelligence-situation-markdown/core 0.0.0-stage → 0.0.1
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.d.ts +308 -0
- package/dist/index.js +30 -0
- package/package.json +41 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { GitIdentity, HashDrift, RenderedDocument, Result, RuntimeEnvError, RuntimeEnvResolution as RuntimeEnvResolution$1 } from "@longzai-intelligence-markdown/data-engine";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
export * from "@longzai-intelligence-situation-markdown/config";
|
|
4
|
+
/**
|
|
5
|
+
* 数据根环境变量名
|
|
6
|
+
*/
|
|
7
|
+
declare const ENV_DATA_ROOT = "LZI_SITUATION_MARKDOWN_DATA_ROOT";
|
|
8
|
+
/**
|
|
9
|
+
* 数据源根环境变量名
|
|
10
|
+
*/
|
|
11
|
+
declare const ENV_SOURCE_ROOT = "LZI_SITUATION_MARKDOWN_SOURCE_ROOT";
|
|
12
|
+
/**
|
|
13
|
+
* 域环境配置形态
|
|
14
|
+
*/
|
|
15
|
+
type SituationEnv = {
|
|
16
|
+
readonly dataRoot: string;
|
|
17
|
+
readonly sourceRoot: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 从进程环境解析配置
|
|
21
|
+
*
|
|
22
|
+
* @param processEnv - 进程环境变量表
|
|
23
|
+
* @returns 域环境配置解析结果
|
|
24
|
+
*/
|
|
25
|
+
declare function resolveEnv(processEnv?: NodeJS.ProcessEnv): import("@longzai-intelligence-markdown/data-engine").Result<SituationEnv, import("@longzai-intelligence-markdown/data-engine").EnvError>;
|
|
26
|
+
/**
|
|
27
|
+
* 域环境工具族(模板渲染复用)
|
|
28
|
+
*/
|
|
29
|
+
declare const domainEnvKit: import("@longzai-intelligence-markdown/data-engine").EnvKit<SituationEnv>;
|
|
30
|
+
/**
|
|
31
|
+
* 渲染 .env 文件内容
|
|
32
|
+
*
|
|
33
|
+
* @param params - 环境变量取值与模板标题
|
|
34
|
+
* @returns .env 文件全文
|
|
35
|
+
*/
|
|
36
|
+
declare function renderEnvTemplate(params?: {
|
|
37
|
+
dataRoot?: string;
|
|
38
|
+
sourceRoot?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
}): string;
|
|
41
|
+
/**
|
|
42
|
+
* 解析成功结果
|
|
43
|
+
*/
|
|
44
|
+
type RuntimeEnvResolution = RuntimeEnvResolution$1<SituationEnv>;
|
|
45
|
+
/**
|
|
46
|
+
* 解析运行时环境
|
|
47
|
+
*
|
|
48
|
+
* @param explicitConfigPath - 显式配置文件路径,缺省走发现通道
|
|
49
|
+
* @returns 运行时环境解析结果
|
|
50
|
+
*/
|
|
51
|
+
declare function resolveRuntimeEnv(explicitConfigPath?: string): Promise<import("@longzai-intelligence-markdown/data-engine").Result<RuntimeEnvResolution$1<SituationEnv>, RuntimeEnvError>>;
|
|
52
|
+
/**
|
|
53
|
+
* 单文件装载结果
|
|
54
|
+
*/
|
|
55
|
+
type DeclarationImportOutcome = {
|
|
56
|
+
/**
|
|
57
|
+
* 声明文件绝对路径
|
|
58
|
+
*/
|
|
59
|
+
readonly file: string;
|
|
60
|
+
/**
|
|
61
|
+
* 装载结论
|
|
62
|
+
*/
|
|
63
|
+
readonly ok: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* 默认导出值(ok=true 时)
|
|
66
|
+
*/
|
|
67
|
+
readonly value?: unknown;
|
|
68
|
+
/**
|
|
69
|
+
* 导入错误信息(ok=false 时)
|
|
70
|
+
*/
|
|
71
|
+
readonly message?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 批量装载声明默认导出(单次子进程统一装载,逐文件独立成败)
|
|
75
|
+
*
|
|
76
|
+
* @param filePaths - 声明文件绝对路径列表
|
|
77
|
+
* @returns 文件路径到装载结果的映射
|
|
78
|
+
*/
|
|
79
|
+
declare function importDeclarationDefaults(filePaths: readonly string[]): Promise<Map<string, DeclarationImportOutcome>>;
|
|
80
|
+
/**
|
|
81
|
+
* 声明域目录名(相对记录仓根)
|
|
82
|
+
*/
|
|
83
|
+
declare const DECLARATION_DIR = "situations";
|
|
84
|
+
/**
|
|
85
|
+
* 声明文件后缀
|
|
86
|
+
*/
|
|
87
|
+
declare const DECLARATION_SUFFIX = ".situation.ts";
|
|
88
|
+
/**
|
|
89
|
+
* 源错误
|
|
90
|
+
*/
|
|
91
|
+
type SourceError = {
|
|
92
|
+
readonly code: 'SOURCE_ROOT_MISSING' | 'DECLARATION_DIR_MISSING';
|
|
93
|
+
readonly message: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* 扫描记录仓声明域的现状判断 slug 清单
|
|
97
|
+
*
|
|
98
|
+
* @param sourceRoot - 现状记录仓根绝对路径
|
|
99
|
+
* @returns 升序确定性的 slug 清单或源错误
|
|
100
|
+
*/
|
|
101
|
+
declare function scanSourceRoot(sourceRoot: string): Result<readonly string[], SourceError>;
|
|
102
|
+
/**
|
|
103
|
+
* 声明文件绝对路径
|
|
104
|
+
*
|
|
105
|
+
* @param sourceRoot - 现状记录仓根绝对路径
|
|
106
|
+
* @param slug - 现状判断 slug
|
|
107
|
+
* @returns 声明文件绝对路径
|
|
108
|
+
*/
|
|
109
|
+
declare function sourceEntryPath(sourceRoot: string, slug: string): string;
|
|
110
|
+
/**
|
|
111
|
+
* 现状判断状态
|
|
112
|
+
*/
|
|
113
|
+
declare const situationStatusSchema: z.ZodEnum<{
|
|
114
|
+
active: "active";
|
|
115
|
+
proposal: "proposal";
|
|
116
|
+
retired: "retired";
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* 现状判断声明
|
|
120
|
+
*/
|
|
121
|
+
declare const situationDeclarationSchema: z.ZodObject<{
|
|
122
|
+
slug: z.ZodString;
|
|
123
|
+
name: z.ZodString;
|
|
124
|
+
statement: z.ZodString;
|
|
125
|
+
semantics: z.ZodString;
|
|
126
|
+
levelSlug: z.ZodString;
|
|
127
|
+
depth: z.ZodInt;
|
|
128
|
+
status: z.ZodEnum<{
|
|
129
|
+
active: "active";
|
|
130
|
+
proposal: "proposal";
|
|
131
|
+
retired: "retired";
|
|
132
|
+
}>;
|
|
133
|
+
informsIntentionSlugs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
|
+
createdAt: z.ZodString;
|
|
135
|
+
}, z.core.$strip>;
|
|
136
|
+
/**
|
|
137
|
+
* 现状判断声明类型(schema 推断)
|
|
138
|
+
*/
|
|
139
|
+
type SituationDeclaration = z.infer<typeof situationDeclarationSchema>;
|
|
140
|
+
/**
|
|
141
|
+
* 现状判断声明工厂
|
|
142
|
+
*
|
|
143
|
+
* defineXXX 规范收口:声明域一律经工厂表达并裸导入本契约包,
|
|
144
|
+
* identity 语义类型收口,运行时结构校验由装载方 zod 权威执行
|
|
145
|
+
*
|
|
146
|
+
* @param declaration - 现状判断声明
|
|
147
|
+
* @returns 原样返回的现状判断声明
|
|
148
|
+
*/
|
|
149
|
+
declare function defineSituationDeclaration(declaration: SituationDeclaration): SituationDeclaration;
|
|
150
|
+
/**
|
|
151
|
+
* 条目采集产物
|
|
152
|
+
*/
|
|
153
|
+
type EntryInspection = {
|
|
154
|
+
/**
|
|
155
|
+
* 现状判断 slug(归档文件名 = <slug>.md)
|
|
156
|
+
*/
|
|
157
|
+
readonly name: string;
|
|
158
|
+
/**
|
|
159
|
+
* 装载校验后的现状判断声明
|
|
160
|
+
*/
|
|
161
|
+
readonly declaration: SituationDeclaration;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* 采集失败
|
|
165
|
+
*/
|
|
166
|
+
type InspectError = {
|
|
167
|
+
readonly name: string;
|
|
168
|
+
readonly message: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* 校验单条装载产物
|
|
172
|
+
*
|
|
173
|
+
* @param slug - 现状判断 slug,等于声明文件名 stem
|
|
174
|
+
* @param value - 子进程装载得到的默认导出值
|
|
175
|
+
* @returns 装载校验后的条目或采集失败
|
|
176
|
+
*/
|
|
177
|
+
declare function inspectLoadedDeclaration(slug: string, value: unknown): Result<EntryInspection, InspectError>;
|
|
178
|
+
/**
|
|
179
|
+
* 渲染条目档(平铺 <slug>.md)
|
|
180
|
+
*
|
|
181
|
+
* @param entry - 装载校验后的现状判断条目
|
|
182
|
+
* @param generatedAt - 生成时刻,ISO 8601 字符串
|
|
183
|
+
* @returns 条目档全文与正文哈希
|
|
184
|
+
*/
|
|
185
|
+
declare function renderEntryDocument(entry: EntryInspection, generatedAt: string): RenderedDocument;
|
|
186
|
+
/**
|
|
187
|
+
* 归档子文件夹名
|
|
188
|
+
*/
|
|
189
|
+
declare const ARCHIVE_DIR = "entries";
|
|
190
|
+
/**
|
|
191
|
+
* 目录册条目(name = 归档文件名去 .md)
|
|
192
|
+
*/
|
|
193
|
+
type CatalogEntry = {
|
|
194
|
+
readonly name: string;
|
|
195
|
+
readonly displayName: string;
|
|
196
|
+
readonly statement: string;
|
|
197
|
+
readonly levelSlug: string;
|
|
198
|
+
readonly depth: number;
|
|
199
|
+
readonly status: string;
|
|
200
|
+
readonly exists: true;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* 渲染目录册(hash 仅覆盖正文)
|
|
204
|
+
*
|
|
205
|
+
* @param entries - 目录册条目清单
|
|
206
|
+
* @param generatedAt - 生成时刻,ISO 8601 字符串
|
|
207
|
+
* @returns 目录册全文与正文哈希
|
|
208
|
+
*/
|
|
209
|
+
declare function renderCatalog(entries: readonly CatalogEntry[], generatedAt: string): RenderedDocument;
|
|
210
|
+
/**
|
|
211
|
+
* 数据区 README 骨架(仅缺失时写入)
|
|
212
|
+
*
|
|
213
|
+
* @returns 数据区 README 全文
|
|
214
|
+
*/
|
|
215
|
+
declare function renderDataRootReadme(): string;
|
|
216
|
+
/**
|
|
217
|
+
* 渲染记录仓渲染域的现状判断声明镜像档
|
|
218
|
+
*
|
|
219
|
+
* 一声明一档,供记录仓渲染域托管
|
|
220
|
+
*
|
|
221
|
+
* @param slug - 现状判断 slug
|
|
222
|
+
* @param displayName - 现状判断名称
|
|
223
|
+
* @param statement - 现状陈述
|
|
224
|
+
* @param semantics - 判断语义说明
|
|
225
|
+
* @param levelSlug - 级别 slug
|
|
226
|
+
* @param depth - 排序档位
|
|
227
|
+
* @param status - 现状判断状态
|
|
228
|
+
* @returns 镜像档全文
|
|
229
|
+
*/
|
|
230
|
+
declare function renderRegistryMirrorDocument(slug: string, displayName: string, statement: string, semantics: string, levelSlug: string, depth: number, status: string): string;
|
|
231
|
+
/**
|
|
232
|
+
* 转换选择器
|
|
233
|
+
*/
|
|
234
|
+
type ConvertSelection = {
|
|
235
|
+
readonly all?: boolean;
|
|
236
|
+
readonly entry?: string;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* 转换选项
|
|
240
|
+
*/
|
|
241
|
+
type ConvertOptions = ConvertSelection & {
|
|
242
|
+
readonly dryRun?: boolean;
|
|
243
|
+
readonly commit?: boolean;
|
|
244
|
+
readonly gitIdentity?: GitIdentity;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* 单条目报告
|
|
248
|
+
*/
|
|
249
|
+
type ConvertEntryReport = {
|
|
250
|
+
readonly name: string;
|
|
251
|
+
readonly written: number;
|
|
252
|
+
readonly skipped: number;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* 转换总报告
|
|
256
|
+
*/
|
|
257
|
+
type ConvertReport = {
|
|
258
|
+
readonly entries: readonly ConvertEntryReport[];
|
|
259
|
+
readonly catalogWritten: boolean;
|
|
260
|
+
readonly registryMirrorWritten: number;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* 执行转换(--all 全量;机制全引擎)
|
|
264
|
+
*
|
|
265
|
+
* @param env - 域环境配置
|
|
266
|
+
* @param options - 转换选项
|
|
267
|
+
* @returns 转换总报告或错误信息
|
|
268
|
+
*/
|
|
269
|
+
declare function runConvert(env: SituationEnv, options: ConvertOptions): Promise<Result<ConvertReport, {
|
|
270
|
+
message: string;
|
|
271
|
+
}>>;
|
|
272
|
+
/**
|
|
273
|
+
* verify 体检(哈希漂移 + 声明与条目对账;机制 = data-engine)
|
|
274
|
+
*
|
|
275
|
+
* 体检报告形态
|
|
276
|
+
*/
|
|
277
|
+
type VerifyReport = {
|
|
278
|
+
/**
|
|
279
|
+
* 哈希漂移清单
|
|
280
|
+
*/
|
|
281
|
+
readonly hashDrifts: readonly HashDrift[];
|
|
282
|
+
/**
|
|
283
|
+
* 声明域有而条目缺的 slug 清单
|
|
284
|
+
*/
|
|
285
|
+
readonly missingEntries: readonly string[];
|
|
286
|
+
/**
|
|
287
|
+
* 条目有而声明域无的 slug 清单
|
|
288
|
+
*/
|
|
289
|
+
readonly orphanEntries: readonly string[];
|
|
290
|
+
/**
|
|
291
|
+
* 是否全量通过
|
|
292
|
+
*/
|
|
293
|
+
readonly ok: boolean;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* 执行体检(只报告不阻断)
|
|
297
|
+
*
|
|
298
|
+
* @param env - 域环境配置
|
|
299
|
+
* @returns 体检结论,报告缺失时附错误信息
|
|
300
|
+
*/
|
|
301
|
+
declare function runVerify(env: SituationEnv): Promise<{
|
|
302
|
+
ok: boolean;
|
|
303
|
+
report?: VerifyReport;
|
|
304
|
+
error?: {
|
|
305
|
+
message: string;
|
|
306
|
+
};
|
|
307
|
+
}>;
|
|
308
|
+
export { ARCHIVE_DIR, CatalogEntry, ConvertEntryReport, ConvertOptions, ConvertReport, ConvertSelection, DECLARATION_DIR, DECLARATION_SUFFIX, DeclarationImportOutcome, ENV_DATA_ROOT, ENV_SOURCE_ROOT, EntryInspection, InspectError, type RuntimeEnvError, RuntimeEnvResolution, SituationDeclaration, SituationEnv, SourceError, VerifyReport, defineSituationDeclaration, domainEnvKit, importDeclarationDefaults, inspectLoadedDeclaration, renderCatalog, renderDataRootReadme, renderEntryDocument, renderEnvTemplate, renderRegistryMirrorDocument, resolveEnv, resolveRuntimeEnv, runConvert, runVerify, scanSourceRoot, situationDeclarationSchema, situationStatusSchema, sourceEntryPath };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import{loadSituationConfig as e}from"@longzai-intelligence-situation-markdown/config";import{computeHashDrift as t,contentHash as n,createCatalogReconciler as r,createCatalogService as i,createEnvKit as a,createPartitionWriter as o,createRuntimeEnvResolver as s,failure as c,parseFrontmatterHead as l,pipelineFrontmatter as u,requireExactlyOne as d,stringifyFrontmatter as f,success as p}from"@longzai-intelligence-markdown/data-engine";import{join as m,resolve as h}from"node:path";import{existsSync as g,mkdirSync as _,readFileSync as v,readdirSync as y,writeFileSync as b}from"node:fs";import{fileURLToPath as x}from"node:url";import*as S from"zod";export*from"@longzai-intelligence-situation-markdown/config";const C=`LZI_SITUATION_MARKDOWN_DATA_ROOT`,w=`LZI_SITUATION_MARKDOWN_SOURCE_ROOT`,T=a({variables:[{name:C,comment:`数据根(数据区目录)`,placeholder:`/path/to/longzai-intelligence-intention-data`},{name:w,comment:`现状判断记录仓根(声明域只读消费,渲染域机器写回)`,placeholder:`/path/to/longzai-intelligence-intention`}],toEnvConfig:e=>({dataRoot:h(e.LZI_SITUATION_MARKDOWN_DATA_ROOT??``),sourceRoot:h(e.LZI_SITUATION_MARKDOWN_SOURCE_ROOT??``)}),defaultTemplateTitle:`lzi-situation-markdown 环境配置`});function E(e=process.env){return T.resolveEnv(e)}const D=T;function O(e={}){let t={};return e.dataRoot!==void 0&&(t[C]=e.dataRoot),e.sourceRoot!==void 0&&(t[w]=e.sourceRoot),D.renderEnvTemplate({values:t,title:e.title})}const k=s({loadConfig:e,resolveEnv:()=>E(),configToEnv:e=>({dataRoot:e.dataRoot,sourceRoot:e.sourceRoot})});async function A(e){return k.resolveRuntimeEnv(e)}const j=S.object({file:S.string(),ok:S.boolean(),value:S.unknown().optional(),message:S.string().optional()});function M(){try{let e=import.meta.resolve(`@longzai-intelligence-situation-markdown/core`),t=x(e);if(g(t))return t}catch{}return[m(import.meta.dir,`../../..`,`dist/index.js`),m(import.meta.dir,`../../..`,`src/index.ts`)].find(e=>g(e))??`(situation-markdown-core-missing)`}async function N(e){let t=/* @__PURE__ */ new Map;if(e.length===0)return t;let n=Bun.spawnSync([`bun`,`-e`,`const coreModulePath = process.argv[3];
|
|
2
|
+
Bun.plugin({
|
|
3
|
+
name: 'situation-contract-self-resolution',
|
|
4
|
+
setup(builder) {
|
|
5
|
+
builder.module('@longzai-intelligence-situation-markdown/core', async () => {
|
|
6
|
+
const module = await import(coreModulePath);
|
|
7
|
+
return { exports: module, loader: 'object' };
|
|
8
|
+
});
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
const files = JSON.parse(process.argv[2] ?? '[]');
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const file of files) {
|
|
14
|
+
try {
|
|
15
|
+
const module = await import(file);
|
|
16
|
+
out.push({ file, ok: true, value: module.default });
|
|
17
|
+
} catch (error) {
|
|
18
|
+
out.push({ file, ok: false, message: error instanceof Error ? error.message : String(error) });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
console.log(JSON.stringify(out));`,`situation-declaration-import`,JSON.stringify([...e]),M()],{stdout:`pipe`,stderr:`pipe`}),r=new TextDecoder().decode(n.stdout),i=new TextDecoder().decode(n.stderr),a=S.array(j).safeParse(r.trim().length===0?void 0:JSON.parse(r));if(!a.success||a.data.length!==e.length){for(let n of e)t.set(n,{file:n,ok:!1,message:`声明子进程装载失败:${i.trim().length>0?i.trim():r.trim()}`});return t}for(let e of a.data)t.set(e.file,e);return t}const P=`situations`,F=`.situation.ts`;function I(e){let t=m(e,P);if(!g(t))return c({code:`DECLARATION_DIR_MISSING`,message:`声明域目录不存在:${t}`});let n=y(t,{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(`.situation.ts`)).map(e=>e.name.slice(0,-13)).sort((e,t)=>e<t?-1:1);return p(n)}function L(e,t){return m(e,P,`${t}${F}`)}const R=S.enum([`proposal`,`active`,`retired`]),z=S.object({slug:S.string().min(1,`现状判断 slug 不能为空`).regex(/^[a-z][a-z-]*[a-z]$|^[a-z]$/,`现状判断 slug 须为纯字母 ASCII kebab 形态`),name:S.string().min(1,`现状判断名称不能为空`).max(100,`现状判断名称最多 100 个字符`),statement:S.string().min(1,`现状陈述不能为空`),semantics:S.string().min(1,`现状判断语义不能为空`),levelSlug:S.string().min(1,`级别 slug 不能为空`).regex(/^[a-z][a-z-]*[a-z]$|^[a-z]$/,`级别 slug 须为纯字母 ASCII kebab 形态`),depth:S.int(`排序档位必须为整数`).nonnegative(`排序档位不能为负数`),status:R,informsIntentionSlugs:S.array(S.string().min(1,`所证成意图 slug 不能为空`)).optional(),createdAt:S.string().min(1,`创建时间不能为空`)});function B(e){return e}function V(e,t){let n=z.safeParse(t);return n.success?n.data.slug===e?p({name:e,declaration:n.data}):c({name:e,message:`声明 slug ${n.data.slug} 与文件名 ${e} 不一致`}):c({name:e,message:`声明 ${e} 校验失败:${n.error.message}`})}function H(e,t){let r=e.declaration,i=[`# ${r.name}`,``,`> ${r.statement}`,``,r.semantics,``,`## 声明信息`,``,`| 字段 | 取值 |`,`| --- | --- |`,`| slug | \`${r.slug}\` |`,`| 级别 | \`${r.levelSlug}\` |`,`| 档位 | ${r.depth} |`,`| 状态 | ${r.status} |`,`| 创建时间 | ${r.createdAt} |`,``];if(r.informsIntentionSlugs!==void 0&&r.informsIntentionSlugs.length>0){i.push(`## 所证成的意图`,``);for(let e of r.informsIntentionSlugs)i.push(`- \`${e}\``);i.push(``)}let a=i.join(`
|
|
22
|
+
`);return{content:`${f(u({kind:`document`,feedPipelineId:`situation-markdown`,plugin:`situation`,sourceId:`situation-record`,generatedAt:t,hash:n(a),extra:{slug:r.slug,name:r.name,statement:r.statement,level_slug:r.levelSlug,depth:r.depth,status:r.status,informs_intention_slugs:r.informsIntentionSlugs??[]}}))}${a}`,hash:n(a)}}const U=`entries`;function W(e,t){let r=[...e].sort((e,t)=>e.depth-t.depth||(e.name<t.name?-1:1)),i=[`# situation 索引目录册`,``,`共 ${e.length} 条。机器生成禁手工编辑,真源为现状记录仓声明域,重生成经 \`lzi-situation-markdown convert\`。`,``,`| slug | 名称 | 陈述 | 级别 | 档位 | 状态 |`,`| --- | --- | --- | --- | --- | --- |`];for(let e of r)i.push(`| ${e.name} | ${e.displayName} | ${e.statement.replaceAll(`|`,`\\|`)} | ${e.levelSlug} | ${e.depth} | ${e.status} |`);i.push(``);let a=i.join(`
|
|
23
|
+
`),o=n(a);return{content:`${f(u({kind:`catalog`,feedPipelineId:`situation-markdown`,plugin:`situation`,sourceId:`situation-record`,generatedAt:t,hash:o,extra:{entry_total:e.length}}))}\n${a}`,hash:o}}function G(){return`# longzai-intelligence-situation-data
|
|
24
|
+
|
|
25
|
+
现状判断 markdown 数据仓(data repository):由 \`lzi-situation-markdown\` 生成并维护(markdown-data-repository-spec,markdown 仓 ADR 0001/0002)。
|
|
26
|
+
|
|
27
|
+
条目组织为 \`entries/<slug>.md\` 一篇一档,frontmatter 为唯一元数据载体,禁手工编辑;人工内容不落本仓。
|
|
28
|
+
`}function K(e,t,n,r,i,a,o){return[`---`,`slug: ${e}`,`kind: situation-declaration`,`level_slug: ${i}`,`depth: ${a}`,`status: ${o}`,`---`,``,`# ${t}`,``,`> ${n}`,``,r,``,`- 级别:${i}`,`- 档位:${a}`,`- 状态:${o}`,``].join(`
|
|
29
|
+
`)}async function q(e){let t=m(e,U),n=[],r=[];try{r=y(t).filter(e=>e.endsWith(`.md`))}catch{return n}for(let e of r.sort((e,t)=>e<t?-1:1)){let r=l(v(m(t,e),`utf-8`));n.push({name:e.slice(0,-3),displayName:r.name??e,statement:r.statement??``,levelSlug:r.level_slug??`unknown`,depth:Number(r.depth??0),status:r.status??`proposal`,exists:!0})}return n}function J(e,t,n){let r=m(e.sourceRoot,`registry/situations`);n||_(r,{recursive:!0});for(let e of t){let t=e.declaration;n||b(m(r,`${t.slug}.md`),K(t.slug,t.name,t.statement,t.semantics,t.levelSlug,t.depth,t.status),`utf-8`)}return n?0:t.length}async function Y(e,t){if(!d({all:t.all===!0,entry:t.entry!==void 0}).ok)return{ok:!1,error:{message:`缺少选择器:--entry <slug> / --all 二选一`}};let n=I(e.sourceRoot);if(!n.ok)return{ok:!1,error:{message:n.error.message}};let a=t.entry===void 0?n.value:[t.entry],s=await N(a.map(t=>L(e.sourceRoot,t))),c=[];for(let t of a){let n=s.get(L(e.sourceRoot,t));if(n===void 0||!n.ok)return{ok:!1,error:{message:`声明 ${t} 装载失败:${n?.message??`结果缺失`}`}};let r=V(t,n.value);if(!r.ok)return{ok:!1,error:{message:r.error.message}};c.push(r.value)}let l=o({dataRoot:e.dataRoot,partitionDir:()=>m(e.dataRoot,U),entryRelPath:(e,t)=>`${U}/${t.name}.md`,renderEntry:H,sortEntries:e=>[...e].sort((e,t)=>e.declaration.depth-t.declaration.depth||(e.name<t.name?-1:1))}),u=[];for(let e of c){let n=await l.writePartition(`situation`,[e],{dryRun:t.dryRun});u.push({name:e.name,written:n.written,skipped:n.skipped})}let f=J(e,c,t.dryRun===!0),h=await i({dataRoot:e.dataRoot,gitIdentity:t.gitIdentity,rootFiles:[{path:`.gitignore`,content:`.DS_Store
|
|
30
|
+
`},{path:`README.md`,content:G()}],scan:async()=>q(e.dataRoot),renderCatalog:W,reconcile:r({countFields:[],rowPattern:/^\| ([a-z][a-z-]*) \| [^|]+ \| [^|]+ \| [a-z][a-z-]* \| \d+ \| [a-z]+ \|$/gm,keyOfEntry:e=>e.name,keyNoun:`条目`}),commit:{defaultEnabled:!1,message:()=>`data(catalog): 更新现状判断目录册`}}).refresh({dryRun:t.dryRun,commit:t.commit});return p({entries:u,catalogWritten:h.catalogWritten,registryMirrorWritten:f})}async function X(e){if(!g(e.dataRoot))return{ok:!1,error:{message:`数据根不存在:${e.dataRoot}`}};let n=[],r=m(e.dataRoot,U),i=[];if(g(r))for(let e of y(r,{withFileTypes:!0}).sort((e,t)=>e.name<t.name?-1:1)){if(!e.isFile()||!e.name.endsWith(`.md`))continue;i.push(e.name.slice(0,-3));let a=t(m(r,e.name),v(m(r,e.name),`utf8`));a!==null&&n.push(a)}let a=I(e.sourceRoot);if(!a.ok)return{ok:!1,error:{message:a.error.message}};let o=new Set(a.value),s=new Set(i),c=a.value.filter(e=>!s.has(e)),l=i.filter(e=>!o.has(e));return{ok:!0,report:{hashDrifts:n,missingEntries:c,orphanEntries:l,ok:n.length===0&&c.length===0&&l.length===0}}}export{U as ARCHIVE_DIR,P as DECLARATION_DIR,F as DECLARATION_SUFFIX,C as ENV_DATA_ROOT,w as ENV_SOURCE_ROOT,B as defineSituationDeclaration,D as domainEnvKit,N as importDeclarationDefaults,V as inspectLoadedDeclaration,W as renderCatalog,G as renderDataRootReadme,H as renderEntryDocument,O as renderEnvTemplate,K as renderRegistryMirrorDocument,E as resolveEnv,A as resolveRuntimeEnv,Y as runConvert,X as runVerify,I as scanSourceRoot,z as situationDeclarationSchema,R as situationStatusSchema,L as sourceEntryPath};
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-situation-markdown/core",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Longzai Intelligence 核心包",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"core",
|
|
7
|
+
"domain-model",
|
|
8
|
+
"longzai-intelligence"
|
|
9
|
+
],
|
|
10
|
+
"license": "UNLICENSED",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "lzi-builder",
|
|
22
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
23
|
+
"prepublishOnly": "bun run build:prod",
|
|
24
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
25
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
26
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
27
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
28
|
+
"lint": "oxlint && oxfmt --check",
|
|
29
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
30
|
+
"test": "lzi-bun test",
|
|
31
|
+
"test:watch": "lzi-bun test --watch",
|
|
32
|
+
"test:coverage": "lzi-bun test --coverage",
|
|
33
|
+
"clean": "lzi-dev-tools clean"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@longzai-intelligence-markdown/data-engine": "0.0.6",
|
|
37
|
+
"@longzai-intelligence-situation-markdown/config": "0.0.1",
|
|
38
|
+
"zod": "^4.6.5"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist"
|
|
42
|
+
]
|
|
43
|
+
}
|
package/README.md
DELETED