@longzai-intelligence-situation-markdown/core 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.
- package/dist/index.d.ts +384 -0
- package/dist/index.js +30 -0
- package/package.json +38 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { ConfigLoadError } from "@longzai-intelligence-situation-markdown/config";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import { GitIdentity, HashDrift, RenderedDocument, Result } from "@longzai-intelligence-markdown/data-engine";
|
|
4
|
+
export * from "@longzai-intelligence-situation-markdown/config";
|
|
5
|
+
/**
|
|
6
|
+
* 现状记录仓根环境变量名(longzai-intelligence-situation 仓根,声明域只读消费,
|
|
7
|
+
* 渲染域机器写回)
|
|
8
|
+
*/
|
|
9
|
+
declare const ENV_SOURCE_ROOT = "LZI_SITUATION_MARKDOWN_SOURCE_ROOT";
|
|
10
|
+
/**
|
|
11
|
+
* 环境变量原始 schema(现状记录仓根必填非空;结构声明与引擎 EnvKit 同源)
|
|
12
|
+
*/
|
|
13
|
+
declare const situationMarkdownEnvSchema: z.ZodObject<{
|
|
14
|
+
LZI_SITUATION_MARKDOWN_SOURCE_ROOT: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/**
|
|
17
|
+
* 解析后的环境配置(绝对路径形态)
|
|
18
|
+
*/
|
|
19
|
+
type SituationMarkdownEnv = {
|
|
20
|
+
/**
|
|
21
|
+
* 现状记录仓根绝对路径(声明域只读消费,渲染域机器写回)
|
|
22
|
+
*/
|
|
23
|
+
readonly sourceRoot: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 环境配置错误(缺失/非法,附缺失变量名清单;引擎 EnvError 形态)
|
|
27
|
+
*/
|
|
28
|
+
type EnvError = {
|
|
29
|
+
/**
|
|
30
|
+
* 错误码
|
|
31
|
+
*/
|
|
32
|
+
readonly code: 'ENV_INVALID';
|
|
33
|
+
/**
|
|
34
|
+
* 人读错误信息
|
|
35
|
+
*/
|
|
36
|
+
readonly message: string;
|
|
37
|
+
/**
|
|
38
|
+
* 缺失或非法的变量名清单
|
|
39
|
+
*/
|
|
40
|
+
readonly missing: readonly string[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* 域环境工具族实例(变量声明 + 装配语义;机制由引擎承载)
|
|
44
|
+
*/
|
|
45
|
+
declare const envKit: import("@longzai-intelligence-markdown/data-engine").EnvKit<SituationMarkdownEnv>;
|
|
46
|
+
/**
|
|
47
|
+
* 从进程环境解析配置(zod 校验 + 绝对路径化;机制经引擎 EnvKit)
|
|
48
|
+
*
|
|
49
|
+
* @param processEnv - 进程环境(缺省 process.env;测试注入)
|
|
50
|
+
* @returns 解析成功为绝对路径形态 env;失败为缺失变量清单错误
|
|
51
|
+
*/
|
|
52
|
+
declare function resolveEnv(processEnv?: NodeJS.ProcessEnv): ReturnType<typeof envKit.resolveEnv>;
|
|
53
|
+
/**
|
|
54
|
+
* 供 env-template.utils 消费的域工具族实例(模板渲染与解析同源同族)
|
|
55
|
+
*/
|
|
56
|
+
declare const situationEnvKit: import("@longzai-intelligence-markdown/data-engine").EnvKit<SituationMarkdownEnv>;
|
|
57
|
+
/**
|
|
58
|
+
* .env 模板入参
|
|
59
|
+
*/
|
|
60
|
+
type EnvTemplateParams = {
|
|
61
|
+
/**
|
|
62
|
+
* 现状记录仓根路径(缺省取中性占位符;生成真实 .env 时应显式传入)
|
|
63
|
+
*/
|
|
64
|
+
readonly sourceRoot?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* 渲染 .env 文件内容
|
|
68
|
+
*
|
|
69
|
+
* @param params - 模板入参(sourceRoot 可选覆盖;空串路径表示留空待填)
|
|
70
|
+
* @returns .env 文件全文(单变量 + 注释行)
|
|
71
|
+
*/
|
|
72
|
+
declare function renderEnvTemplate(params?: EnvTemplateParams): string;
|
|
73
|
+
/**
|
|
74
|
+
* 解析命中通道
|
|
75
|
+
*/
|
|
76
|
+
type RuntimeEnvChannel = 'config-file';
|
|
77
|
+
/**
|
|
78
|
+
* 领域运行时环境形态(合并形态:dataRoot 出配置文件,sourceRoot 出 .env)
|
|
79
|
+
*/
|
|
80
|
+
type SituationEnv = {
|
|
81
|
+
/**
|
|
82
|
+
* 数据根绝对路径,配置文件承载,就地自指以文件所在目录绝对化
|
|
83
|
+
*/
|
|
84
|
+
readonly dataRoot: string;
|
|
85
|
+
/**
|
|
86
|
+
* 现状记录仓根绝对路径(.env 承载;声明域只读消费,渲染域机器写回)
|
|
87
|
+
*/
|
|
88
|
+
readonly sourceRoot: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* 解析成功结果
|
|
92
|
+
*/
|
|
93
|
+
type RuntimeEnvResolution = {
|
|
94
|
+
/**
|
|
95
|
+
* 命中通道(恒 config-file:配置文件必备后无整体 env 通道)
|
|
96
|
+
*/
|
|
97
|
+
readonly channel: RuntimeEnvChannel;
|
|
98
|
+
/**
|
|
99
|
+
* 合并后的运行时环境
|
|
100
|
+
*/
|
|
101
|
+
readonly env: SituationEnv;
|
|
102
|
+
/**
|
|
103
|
+
* 命中的配置文件绝对路径
|
|
104
|
+
*/
|
|
105
|
+
readonly configPath: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* 解析错误(配置文件缺失/非法 / env 缺失)
|
|
109
|
+
*/
|
|
110
|
+
type RuntimeEnvError = ConfigLoadError | EnvError;
|
|
111
|
+
/**
|
|
112
|
+
* 解析结果
|
|
113
|
+
*/
|
|
114
|
+
type RuntimeEnvResult = {
|
|
115
|
+
readonly ok: true;
|
|
116
|
+
readonly value: RuntimeEnvResolution;
|
|
117
|
+
} | {
|
|
118
|
+
readonly ok: false;
|
|
119
|
+
readonly error: RuntimeEnvError;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* 解析运行时环境(配置文件必备 + 现状记录仓根 env 字段级合并,见模块注释)
|
|
123
|
+
*
|
|
124
|
+
* @param explicitConfigPath - 显式配置文件路径,缺省走向上发现
|
|
125
|
+
* @returns 成功为合并形态运行时环境与配置文件路径;失败为可读错误
|
|
126
|
+
*/
|
|
127
|
+
declare function resolveRuntimeEnv(explicitConfigPath?: string): Promise<RuntimeEnvResult>;
|
|
128
|
+
/**
|
|
129
|
+
* 单文件装载结果
|
|
130
|
+
*/
|
|
131
|
+
type DeclarationImportOutcome = {
|
|
132
|
+
/**
|
|
133
|
+
* 声明文件绝对路径
|
|
134
|
+
*/
|
|
135
|
+
readonly file: string;
|
|
136
|
+
/**
|
|
137
|
+
* 装载结论
|
|
138
|
+
*/
|
|
139
|
+
readonly ok: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* 默认导出值(ok=true 时)
|
|
142
|
+
*/
|
|
143
|
+
readonly value?: unknown;
|
|
144
|
+
/**
|
|
145
|
+
* 导入错误信息(ok=false 时)
|
|
146
|
+
*/
|
|
147
|
+
readonly message?: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* 批量装载声明默认导出(单次子进程统一装载,逐文件独立成败)
|
|
151
|
+
*
|
|
152
|
+
* @param filePaths - 声明文件绝对路径列表
|
|
153
|
+
* @returns 文件路径到装载结果的映射
|
|
154
|
+
*/
|
|
155
|
+
declare function importDeclarationDefaults(filePaths: readonly string[]): Promise<Map<string, DeclarationImportOutcome>>;
|
|
156
|
+
/**
|
|
157
|
+
* 声明域目录名(相对记录仓根)
|
|
158
|
+
*/
|
|
159
|
+
declare const DECLARATION_DIR = "situations";
|
|
160
|
+
/**
|
|
161
|
+
* 声明文件后缀
|
|
162
|
+
*/
|
|
163
|
+
declare const DECLARATION_SUFFIX = ".situation.ts";
|
|
164
|
+
/**
|
|
165
|
+
* 源错误
|
|
166
|
+
*/
|
|
167
|
+
type SourceError = {
|
|
168
|
+
readonly code: 'SOURCE_ROOT_MISSING' | 'DECLARATION_DIR_MISSING';
|
|
169
|
+
readonly message: string;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* 扫描记录仓声明域的现状判断 slug 清单
|
|
173
|
+
*
|
|
174
|
+
* @param sourceRoot - 现状记录仓根绝对路径
|
|
175
|
+
* @returns 升序确定性的 slug 清单或源错误
|
|
176
|
+
*/
|
|
177
|
+
declare function scanSourceRoot(sourceRoot: string): Result<readonly string[], SourceError>;
|
|
178
|
+
/**
|
|
179
|
+
* 声明文件绝对路径
|
|
180
|
+
*
|
|
181
|
+
* @param sourceRoot - 现状记录仓根绝对路径
|
|
182
|
+
* @param slug - 现状判断 slug
|
|
183
|
+
* @returns 声明文件绝对路径
|
|
184
|
+
*/
|
|
185
|
+
declare function sourceEntryPath(sourceRoot: string, slug: string): string;
|
|
186
|
+
/**
|
|
187
|
+
* 现状判断状态
|
|
188
|
+
*/
|
|
189
|
+
declare const situationStatusSchema: z.ZodEnum<{
|
|
190
|
+
active: "active";
|
|
191
|
+
proposal: "proposal";
|
|
192
|
+
retired: "retired";
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* 现状判断声明
|
|
196
|
+
*/
|
|
197
|
+
declare const situationDeclarationSchema: z.ZodObject<{
|
|
198
|
+
slug: z.ZodString;
|
|
199
|
+
name: z.ZodString;
|
|
200
|
+
statement: z.ZodString;
|
|
201
|
+
semantics: z.ZodString;
|
|
202
|
+
levelSlug: z.ZodString;
|
|
203
|
+
depth: z.ZodInt;
|
|
204
|
+
status: z.ZodEnum<{
|
|
205
|
+
active: "active";
|
|
206
|
+
proposal: "proposal";
|
|
207
|
+
retired: "retired";
|
|
208
|
+
}>;
|
|
209
|
+
informsIntentionSlugs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
210
|
+
createdAt: z.ZodString;
|
|
211
|
+
}, z.core.$strip>;
|
|
212
|
+
/**
|
|
213
|
+
* 现状判断声明类型(schema 推断)
|
|
214
|
+
*/
|
|
215
|
+
type SituationDeclaration = z.infer<typeof situationDeclarationSchema>;
|
|
216
|
+
/**
|
|
217
|
+
* 现状判断声明工厂
|
|
218
|
+
*
|
|
219
|
+
* defineXXX 规范收口:声明域一律经工厂表达并裸导入本契约包,
|
|
220
|
+
* identity 语义类型收口,运行时结构校验由装载方 zod 权威执行
|
|
221
|
+
*
|
|
222
|
+
* @param declaration - 现状判断声明
|
|
223
|
+
* @returns 原样返回的现状判断声明
|
|
224
|
+
*/
|
|
225
|
+
declare function defineSituationDeclaration(declaration: SituationDeclaration): SituationDeclaration;
|
|
226
|
+
/**
|
|
227
|
+
* 条目采集产物
|
|
228
|
+
*/
|
|
229
|
+
type EntryInspection = {
|
|
230
|
+
/**
|
|
231
|
+
* 现状判断 slug(归档文件名 = <slug>.md)
|
|
232
|
+
*/
|
|
233
|
+
readonly name: string;
|
|
234
|
+
/**
|
|
235
|
+
* 装载校验后的现状判断声明
|
|
236
|
+
*/
|
|
237
|
+
readonly declaration: SituationDeclaration;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* 采集失败
|
|
241
|
+
*/
|
|
242
|
+
type InspectError = {
|
|
243
|
+
readonly name: string;
|
|
244
|
+
readonly message: string;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* 校验单条装载产物
|
|
248
|
+
*
|
|
249
|
+
* @param slug - 现状判断 slug,等于声明文件名 stem
|
|
250
|
+
* @param value - 子进程装载得到的默认导出值
|
|
251
|
+
* @returns 装载校验后的条目或采集失败
|
|
252
|
+
*/
|
|
253
|
+
declare function inspectLoadedDeclaration(slug: string, value: unknown): Result<EntryInspection, InspectError>;
|
|
254
|
+
/**
|
|
255
|
+
* 渲染条目档(平铺 <slug>.md)
|
|
256
|
+
*
|
|
257
|
+
* @param entry - 装载校验后的现状判断条目
|
|
258
|
+
* @param generatedAt - 生成时刻,ISO 8601 字符串
|
|
259
|
+
* @returns 条目档全文与正文哈希
|
|
260
|
+
*/
|
|
261
|
+
declare function renderEntryDocument(entry: EntryInspection, generatedAt: string): RenderedDocument;
|
|
262
|
+
/**
|
|
263
|
+
* 归档子文件夹名
|
|
264
|
+
*/
|
|
265
|
+
declare const ARCHIVE_DIR = "entries";
|
|
266
|
+
/**
|
|
267
|
+
* 目录册条目(name = 归档文件名去 .md)
|
|
268
|
+
*/
|
|
269
|
+
type CatalogEntry = {
|
|
270
|
+
readonly name: string;
|
|
271
|
+
readonly displayName: string;
|
|
272
|
+
readonly statement: string;
|
|
273
|
+
readonly levelSlug: string;
|
|
274
|
+
readonly depth: number;
|
|
275
|
+
readonly status: string;
|
|
276
|
+
readonly exists: true;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* 渲染目录册(hash 仅覆盖正文)
|
|
280
|
+
*
|
|
281
|
+
* @param entries - 目录册条目清单
|
|
282
|
+
* @param generatedAt - 生成时刻,ISO 8601 字符串
|
|
283
|
+
* @returns 目录册全文与正文哈希
|
|
284
|
+
*/
|
|
285
|
+
declare function renderCatalog(entries: readonly CatalogEntry[], generatedAt: string): RenderedDocument;
|
|
286
|
+
/**
|
|
287
|
+
* 数据区 README 骨架(仅缺失时写入)
|
|
288
|
+
*
|
|
289
|
+
* @returns 数据区 README 全文
|
|
290
|
+
*/
|
|
291
|
+
declare function renderDataRootReadme(): string;
|
|
292
|
+
/**
|
|
293
|
+
* 渲染记录仓渲染域的现状判断声明镜像档
|
|
294
|
+
*
|
|
295
|
+
* 一声明一档,供记录仓渲染域托管
|
|
296
|
+
*
|
|
297
|
+
* @param slug - 现状判断 slug
|
|
298
|
+
* @param displayName - 现状判断名称
|
|
299
|
+
* @param statement - 现状陈述
|
|
300
|
+
* @param semantics - 判断语义说明
|
|
301
|
+
* @param levelSlug - 级别 slug
|
|
302
|
+
* @param depth - 排序档位
|
|
303
|
+
* @param status - 现状判断状态
|
|
304
|
+
* @returns 镜像档全文
|
|
305
|
+
*/
|
|
306
|
+
declare function renderRegistryMirrorDocument(slug: string, displayName: string, statement: string, semantics: string, levelSlug: string, depth: number, status: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* 转换选择器
|
|
309
|
+
*/
|
|
310
|
+
type ConvertSelection = {
|
|
311
|
+
readonly all?: boolean;
|
|
312
|
+
readonly entry?: string;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* 转换选项
|
|
316
|
+
*/
|
|
317
|
+
type ConvertOptions = ConvertSelection & {
|
|
318
|
+
readonly dryRun?: boolean;
|
|
319
|
+
readonly commit?: boolean;
|
|
320
|
+
readonly gitIdentity?: GitIdentity;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* 单条目报告
|
|
324
|
+
*/
|
|
325
|
+
type ConvertEntryReport = {
|
|
326
|
+
readonly name: string;
|
|
327
|
+
readonly written: number;
|
|
328
|
+
readonly skipped: number;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* 转换总报告
|
|
332
|
+
*/
|
|
333
|
+
type ConvertReport = {
|
|
334
|
+
readonly entries: readonly ConvertEntryReport[];
|
|
335
|
+
readonly catalogWritten: boolean;
|
|
336
|
+
readonly registryMirrorWritten: number;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* 执行转换(--all 全量;机制全引擎)
|
|
340
|
+
*
|
|
341
|
+
* @param env - 域环境配置
|
|
342
|
+
* @param options - 转换选项
|
|
343
|
+
* @returns 转换总报告或错误信息
|
|
344
|
+
*/
|
|
345
|
+
declare function runConvert(env: SituationEnv, options: ConvertOptions): Promise<Result<ConvertReport, {
|
|
346
|
+
message: string;
|
|
347
|
+
}>>;
|
|
348
|
+
/**
|
|
349
|
+
* verify 体检(哈希漂移 + 声明与条目对账;机制 = data-engine)
|
|
350
|
+
*
|
|
351
|
+
* 体检报告形态
|
|
352
|
+
*/
|
|
353
|
+
type VerifyReport = {
|
|
354
|
+
/**
|
|
355
|
+
* 哈希漂移清单
|
|
356
|
+
*/
|
|
357
|
+
readonly hashDrifts: readonly HashDrift[];
|
|
358
|
+
/**
|
|
359
|
+
* 声明域有而条目缺的 slug 清单
|
|
360
|
+
*/
|
|
361
|
+
readonly missingEntries: readonly string[];
|
|
362
|
+
/**
|
|
363
|
+
* 条目有而声明域无的 slug 清单
|
|
364
|
+
*/
|
|
365
|
+
readonly orphanEntries: readonly string[];
|
|
366
|
+
/**
|
|
367
|
+
* 是否全量通过
|
|
368
|
+
*/
|
|
369
|
+
readonly ok: boolean;
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* 执行体检(只报告不阻断)
|
|
373
|
+
*
|
|
374
|
+
* @param env - 域环境配置
|
|
375
|
+
* @returns 体检结论,报告缺失时附错误信息
|
|
376
|
+
*/
|
|
377
|
+
declare function runVerify(env: SituationEnv): Promise<{
|
|
378
|
+
ok: boolean;
|
|
379
|
+
report?: VerifyReport;
|
|
380
|
+
error?: {
|
|
381
|
+
message: string;
|
|
382
|
+
};
|
|
383
|
+
}>;
|
|
384
|
+
export { ARCHIVE_DIR, CatalogEntry, ConvertEntryReport, ConvertOptions, ConvertReport, ConvertSelection, DECLARATION_DIR, DECLARATION_SUFFIX, DeclarationImportOutcome, ENV_SOURCE_ROOT, EntryInspection, EnvError, EnvTemplateParams, InspectError, RuntimeEnvChannel, RuntimeEnvError, RuntimeEnvResolution, RuntimeEnvResult, SituationDeclaration, SituationEnv, SituationMarkdownEnv, SourceError, VerifyReport, defineSituationDeclaration, importDeclarationDefaults, inspectLoadedDeclaration, renderCatalog, renderDataRootReadme, renderEntryDocument, renderEnvTemplate, renderRegistryMirrorDocument, resolveEnv, resolveRuntimeEnv, runConvert, runVerify, scanSourceRoot, situationDeclarationSchema, situationEnvKit, situationMarkdownEnvSchema, 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,failure as s,parseFrontmatterHead as c,pipelineFrontmatter as l,requireExactlyOne as u,stringifyFrontmatter as d,success as f}from"@longzai-intelligence-markdown/data-engine";import{join as p,resolve as m}from"node:path";import*as h from"zod";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";export*from"@longzai-intelligence-situation-markdown/config";const S=`LZI_SITUATION_MARKDOWN_SOURCE_ROOT`,C=h.object({[S]:h.string().min(1)}),w=a({variables:[{name:S,comment:`现状记录仓根:longzai-intelligence-situation 仓根目录(声明域只读消费,渲染域机器写回)`,placeholder:`/path/to/longzai-intelligence-situation`}],toEnvConfig:e=>({sourceRoot:m(e.LZI_SITUATION_MARKDOWN_SOURCE_ROOT??``)}),defaultTemplateTitle:`lzi-situation-markdown 环境配置`});function T(e=process.env){return w.resolveEnv(e)}const E=w;function D(e={}){let t={};return e.sourceRoot!==void 0&&(t[S]=e.sourceRoot),E.renderEnvTemplate({values:t})}async function O(t){let n=await e(t);if(!n.ok)return{ok:!1,error:n.error};let r=T();return r.ok?{ok:!0,value:{channel:`config-file`,env:{dataRoot:n.config.dataRoot,sourceRoot:r.value.sourceRoot},configPath:n.path}}:{ok:!1,error:r.error}}const k=h.object({file:h.string(),ok:h.boolean(),value:h.unknown().optional(),message:h.string().optional()});function A(){try{let e=import.meta.resolve(`@longzai-intelligence-situation-markdown/core`),t=x(e);if(g(t))return t}catch{}return[p(import.meta.dir,`../../..`,`dist/index.js`),p(import.meta.dir,`../../..`,`src/index.ts`)].find(e=>g(e))??`(situation-markdown-core-missing)`}async function j(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]),A()],{stdout:`pipe`,stderr:`pipe`}),r=new TextDecoder().decode(n.stdout),i=new TextDecoder().decode(n.stderr),a=h.array(k).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 M=`situations`,N=`.situation.ts`;function P(e){let t=p(e,M);if(!g(t))return s({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 f(n)}function F(e,t){return p(e,M,`${t}${N}`)}const I=h.enum([`proposal`,`active`,`retired`]),L=h.object({slug:h.string().min(1,`现状判断 slug 不能为空`).regex(/^[a-z][a-z-]*[a-z]$|^[a-z]$/,`现状判断 slug 须为纯字母 ASCII kebab 形态`),name:h.string().min(1,`现状判断名称不能为空`).max(100,`现状判断名称最多 100 个字符`),statement:h.string().min(1,`现状陈述不能为空`),semantics:h.string().min(1,`现状判断语义不能为空`),levelSlug:h.string().min(1,`级别 slug 不能为空`).regex(/^[a-z][a-z-]*[a-z]$|^[a-z]$/,`级别 slug 须为纯字母 ASCII kebab 形态`),depth:h.int(`排序档位必须为整数`).nonnegative(`排序档位不能为负数`),status:I,informsIntentionSlugs:h.array(h.string().min(1,`所证成意图 slug 不能为空`)).optional(),createdAt:h.string().min(1,`创建时间不能为空`)});function R(e){return e}function z(e,t){let n=L.safeParse(t);return n.success?n.data.slug===e?f({name:e,declaration:n.data}):s({name:e,message:`声明 slug ${n.data.slug} 与文件名 ${e} 不一致`}):s({name:e,message:`声明 ${e} 校验失败:${n.error.message}`})}function B(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:`${d(l({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 V=`entries`;function H(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:`${d(l({kind:`catalog`,feedPipelineId:`situation-markdown`,plugin:`situation`,sourceId:`situation-record`,generatedAt:t,hash:o,extra:{entry_total:e.length}}))}\n${a}`,hash:o}}function U(){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 W(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 G(e){let t=p(e,V),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=c(v(p(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 K(e,t,n){let r=p(e.sourceRoot,`registry/situations`);n||_(r,{recursive:!0});for(let e of t){let t=e.declaration;n||b(p(r,`${t.slug}.md`),W(t.slug,t.name,t.statement,t.semantics,t.levelSlug,t.depth,t.status),`utf-8`)}return n?0:t.length}async function q(e,t){if(!u({all:t.all===!0,entry:t.entry!==void 0}).ok)return{ok:!1,error:{message:`缺少选择器:--entry <slug> / --all 二选一`}};let n=P(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 j(a.map(t=>F(e.sourceRoot,t))),c=[];for(let t of a){let n=s.get(F(e.sourceRoot,t));if(n===void 0||!n.ok)return{ok:!1,error:{message:`声明 ${t} 装载失败:${n?.message??`结果缺失`}`}};let r=z(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:()=>p(e.dataRoot,V),entryRelPath:(e,t)=>`${V}/${t.name}.md`,renderEntry:B,sortEntries:e=>[...e].sort((e,t)=>e.declaration.depth-t.declaration.depth||(e.name<t.name?-1:1))}),d=[];for(let e of c){let n=await l.writePartition(`situation`,[e],{dryRun:t.dryRun});d.push({name:e.name,written:n.written,skipped:n.skipped})}let m=K(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:U()}],scan:async()=>G(e.dataRoot),renderCatalog:H,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 f({entries:d,catalogWritten:h.catalogWritten,registryMirrorWritten:m})}async function J(e){if(!g(e.dataRoot))return{ok:!1,error:{message:`数据根不存在:${e.dataRoot}`}};let n=[],r=p(e.dataRoot,V),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(p(r,e.name),v(p(r,e.name),`utf8`));a!==null&&n.push(a)}let a=P(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{V as ARCHIVE_DIR,M as DECLARATION_DIR,N as DECLARATION_SUFFIX,S as ENV_SOURCE_ROOT,R as defineSituationDeclaration,j as importDeclarationDefaults,z as inspectLoadedDeclaration,H as renderCatalog,U as renderDataRootReadme,B as renderEntryDocument,D as renderEnvTemplate,W as renderRegistryMirrorDocument,T as resolveEnv,O as resolveRuntimeEnv,q as runConvert,J as runVerify,P as scanSourceRoot,L as situationDeclarationSchema,E as situationEnvKit,C as situationMarkdownEnvSchema,I as situationStatusSchema,F as sourceEntryPath};
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-situation-markdown/core",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Longzai Intelligence 核心包",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"core",
|
|
7
|
+
"domain-model",
|
|
8
|
+
"longzai-intelligence"
|
|
9
|
+
],
|
|
10
|
+
"license": "UNLICENSED",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "lzi-builder",
|
|
25
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
26
|
+
"prepublishOnly": "bun run build:prod",
|
|
27
|
+
"typecheck": "lzi-typecheck",
|
|
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.8",
|
|
37
|
+
"@longzai-intelligence-situation-markdown/config": "0.0.2",
|
|
38
|
+
"zod": "^4.6.5"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/README.md
DELETED