@longzai-intelligence-github-markdown/core 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/README.md +16 -0
- package/dist/index.d.ts +719 -0
- package/dist/index.js +8 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @longzai-intelligence-github-markdown/core
|
|
2
|
+
|
|
3
|
+
Longzai Intelligence Github Markdown 的索引引擎包,承载从本地克隆根到目标数据仓的全链索引转换。
|
|
4
|
+
|
|
5
|
+
## 简介
|
|
6
|
+
|
|
7
|
+
面向本地克隆仓的索引化治理:在只读纪律下扫描克隆根,采集 git 元数据,确定性渲染出组织与仓库两级索引文档及总目录册,写入目标数据仓;写入以整组织为原子单元,重复执行结果稳定一致。
|
|
8
|
+
|
|
9
|
+
## 能力
|
|
10
|
+
|
|
11
|
+
- 克隆根扫描:识别 owner/repo 两层标准结构,非标准条目跳过并报告
|
|
12
|
+
- git 元数据采集:只读采集远端、分支、提交、标签与工作区状态
|
|
13
|
+
- 索引渲染:生成一仓一档索引条目、组织索引表与总目录册
|
|
14
|
+
- 组织级写入:以整组织为原子单元写入目标数据仓,重复执行结果稳定
|
|
15
|
+
- 用例编排:convert(按组织/仓库/全量转换)与 verify(一致性体检)
|
|
16
|
+
- 配置接入:配置文件必备承载 dataRoot,跨项目路径克隆根走 `.env` 的字段级分工解析(仓 ADR 0009)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import { CatalogRefreshOptions, CatalogRefreshResult as CatalogRefreshResult$1, CommitResult, ConfigLoadError, GitIdentity, GitIdentity as GitIdentity$1, GitQueryResult, Result, SplitDocument, commitCount, commitPaths, contentHash, ensureGitRepo, failure, gitQuery, lastCommitShort, normalizeBody, parseFrontmatterHead, splitDocument, stringifyFrontmatter, success } from "@longzai-intelligence-markdown/data-engine";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
export * from "@longzai-intelligence-github-markdown/config";
|
|
5
|
+
//#region src/env/env.schema.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 本地克隆根环境变量名(owner/repo 两层标准结构)
|
|
8
|
+
*/
|
|
9
|
+
declare const ENV_CLONES_ROOT = "LZI_GITHUB_MARKDOWN_CLONES_ROOT";
|
|
10
|
+
/**
|
|
11
|
+
* 环境变量原始 schema(克隆根必填非空;结构声明与引擎 EnvKit 同源)
|
|
12
|
+
*/
|
|
13
|
+
declare const githubMarkdownEnvSchema: z.ZodObject<{
|
|
14
|
+
LZI_GITHUB_MARKDOWN_CLONES_ROOT: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/**
|
|
17
|
+
* 解析后的环境配置(绝对路径形态)
|
|
18
|
+
*/
|
|
19
|
+
type GithubMarkdownEnv = {
|
|
20
|
+
/**
|
|
21
|
+
* 本地克隆根绝对路径(owner/repo 两层标准结构;只读消费)
|
|
22
|
+
*/
|
|
23
|
+
readonly clonesRoot: 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<GithubMarkdownEnv>;
|
|
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 githubEnvKit: import("@longzai-intelligence-markdown/data-engine").EnvKit<GithubMarkdownEnv>;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/env/env-template.utils.d.ts
|
|
59
|
+
/**
|
|
60
|
+
* .env 模板入参
|
|
61
|
+
*/
|
|
62
|
+
type EnvTemplateParams = {
|
|
63
|
+
/**
|
|
64
|
+
* 本地克隆根路径(缺省取中性占位符;生成真实 .env 时应显式传入)
|
|
65
|
+
*/
|
|
66
|
+
readonly clonesRoot?: string;
|
|
67
|
+
/**
|
|
68
|
+
* 模板标题(缺省工具名)
|
|
69
|
+
*/
|
|
70
|
+
readonly title?: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* 渲染 .env 文件内容
|
|
74
|
+
*
|
|
75
|
+
* @param params - 模板入参(clonesRoot/title 可选覆盖;空串路径表示留空待填)
|
|
76
|
+
* @returns .env 文件全文(单变量 + 注释行)
|
|
77
|
+
*/
|
|
78
|
+
declare function renderEnvTemplate(params?: EnvTemplateParams): string;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/source/clone-source.adapter.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* 合法 owner 名模式(GitHub 用户/组织名:字母数字连字符,不以连字符开头/结尾)
|
|
83
|
+
*
|
|
84
|
+
* 域内唯一真源:convert.usecase 与 repo/org-index.service 经导入消费(收敛原三处定义)
|
|
85
|
+
*/
|
|
86
|
+
declare const ORG_PATTERN: RegExp;
|
|
87
|
+
/**
|
|
88
|
+
* 单个克隆仓库定位(分区键 = org/repo 目录名)
|
|
89
|
+
*/
|
|
90
|
+
type RepoTarget = {
|
|
91
|
+
/**
|
|
92
|
+
* 组织名(克隆根 depth-1 目录名)
|
|
93
|
+
*/
|
|
94
|
+
readonly org: string;
|
|
95
|
+
/**
|
|
96
|
+
* 仓库名(depth-2 目录名,含 .git)
|
|
97
|
+
*/
|
|
98
|
+
readonly repo: string;
|
|
99
|
+
/**
|
|
100
|
+
* 克隆目录绝对路径
|
|
101
|
+
*/
|
|
102
|
+
readonly path: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 单组织的目标仓库集合
|
|
106
|
+
*/
|
|
107
|
+
type OrgRepos = {
|
|
108
|
+
/**
|
|
109
|
+
* 组织名
|
|
110
|
+
*/
|
|
111
|
+
readonly org: string;
|
|
112
|
+
/**
|
|
113
|
+
* 该组织的仓库列表(按 repo 名升序)
|
|
114
|
+
*/
|
|
115
|
+
readonly repos: readonly RepoTarget[];
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* 跳过原因码
|
|
119
|
+
*/
|
|
120
|
+
type SkippedReason = 'TOP_LEVEL_REPO' | 'TOP_LEVEL_FILE' | 'OWNER_NAME_INVALID' | 'NO_VALID_REPOS';
|
|
121
|
+
/**
|
|
122
|
+
* 单条跳过报告(非标准条目,只报告不修复)
|
|
123
|
+
*/
|
|
124
|
+
type SkippedEntry = {
|
|
125
|
+
/**
|
|
126
|
+
* 克隆根下的顶层条目名
|
|
127
|
+
*/
|
|
128
|
+
readonly entry: string;
|
|
129
|
+
/**
|
|
130
|
+
* 跳过原因
|
|
131
|
+
*/
|
|
132
|
+
readonly reason: SkippedReason;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 扫描产物(有效组织集合 + 顶层异常报告)
|
|
136
|
+
*/
|
|
137
|
+
type CloneScan = {
|
|
138
|
+
/**
|
|
139
|
+
* 有效组织列表(按 org 名升序)
|
|
140
|
+
*/
|
|
141
|
+
readonly orgs: readonly OrgRepos[];
|
|
142
|
+
/**
|
|
143
|
+
* 顶层跳过条目(按条目名升序)
|
|
144
|
+
*/
|
|
145
|
+
readonly skipped: readonly SkippedEntry[];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* 源错误
|
|
149
|
+
*/
|
|
150
|
+
type CloneSourceError = {
|
|
151
|
+
/**
|
|
152
|
+
* 错误码
|
|
153
|
+
*/
|
|
154
|
+
readonly code: 'DIR_NOT_FOUND';
|
|
155
|
+
/**
|
|
156
|
+
* 人读错误信息
|
|
157
|
+
*/
|
|
158
|
+
readonly message: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* 扫描克隆根(owner/repo 两层标准;见模块注释确定性说明)
|
|
162
|
+
*
|
|
163
|
+
* @param clonesRoot - 本地克隆根绝对路径(只读消费)
|
|
164
|
+
* @returns 有效组织集合与顶层异常报告;目录不存在为 DIR_NOT_FOUND 错误
|
|
165
|
+
*/
|
|
166
|
+
declare function scanClonesRoot(clonesRoot: string): Result<CloneScan, CloneSourceError>;
|
|
167
|
+
/**
|
|
168
|
+
* 解析 --repo 选择器(owner/name 形态)
|
|
169
|
+
*
|
|
170
|
+
* @param selector - CLI 传入的选择器原文
|
|
171
|
+
* @returns 成功为 org/repo 二元组;格式非法为错误消息
|
|
172
|
+
*/
|
|
173
|
+
declare function parseRepoSelector(selector: string): Result<{
|
|
174
|
+
readonly org: string;
|
|
175
|
+
readonly repo: string;
|
|
176
|
+
}, {
|
|
177
|
+
readonly message: string;
|
|
178
|
+
}>;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/source/git-inspect.utils.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* 单仓采集产物(渲染层唯一输入;null = 该维度不可得/不适用)
|
|
183
|
+
*/
|
|
184
|
+
type RepoInspection = {
|
|
185
|
+
/**
|
|
186
|
+
* 组织名(分区键,克隆目录名)
|
|
187
|
+
*/
|
|
188
|
+
readonly org: string;
|
|
189
|
+
/**
|
|
190
|
+
* 仓库名(分区键,克隆目录名)
|
|
191
|
+
*/
|
|
192
|
+
readonly repo: string;
|
|
193
|
+
/**
|
|
194
|
+
* 克隆目录绝对路径
|
|
195
|
+
*/
|
|
196
|
+
readonly clonePath: string;
|
|
197
|
+
/**
|
|
198
|
+
* origin 远端原始 URL(无 origin 为 null)
|
|
199
|
+
*/
|
|
200
|
+
readonly remoteUrl: string | null;
|
|
201
|
+
/**
|
|
202
|
+
* 推导的 github 仓库页 URL(origin 可解析时取远端 owner/repo;origin 缺席时按本地
|
|
203
|
+
* 目录名兜底;origin 为非 github 远端时 null——不臆造)
|
|
204
|
+
*/
|
|
205
|
+
readonly repoUrl: string | null;
|
|
206
|
+
/**
|
|
207
|
+
* 当前分支名(detached/无提交为 null)
|
|
208
|
+
*/
|
|
209
|
+
readonly branch: string | null;
|
|
210
|
+
/**
|
|
211
|
+
* 是否 detached HEAD
|
|
212
|
+
*/
|
|
213
|
+
readonly detached: boolean;
|
|
214
|
+
/**
|
|
215
|
+
* 末次提交短哈希(无提交为 null)
|
|
216
|
+
*/
|
|
217
|
+
readonly lastCommitShort: string | null;
|
|
218
|
+
/**
|
|
219
|
+
* 末次提交时刻(%cI ISO 串;无提交为 null)
|
|
220
|
+
*/
|
|
221
|
+
readonly lastCommitAt: string | null;
|
|
222
|
+
/**
|
|
223
|
+
* HEAD 可达提交计数(无提交为 null)
|
|
224
|
+
*/
|
|
225
|
+
readonly commitCount: number | null;
|
|
226
|
+
/**
|
|
227
|
+
* 标签计数
|
|
228
|
+
*/
|
|
229
|
+
readonly tagCount: number;
|
|
230
|
+
/**
|
|
231
|
+
* 工作区是否有未提交变更(status --porcelain 非空)
|
|
232
|
+
*/
|
|
233
|
+
readonly isDirty: boolean;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* 采集错误(仓库健康探测失败——损坏的 .git 等)
|
|
237
|
+
*/
|
|
238
|
+
type GitInspectError = {
|
|
239
|
+
/**
|
|
240
|
+
* 错误码
|
|
241
|
+
*/
|
|
242
|
+
readonly code: 'INSPECT_FAILED';
|
|
243
|
+
/**
|
|
244
|
+
* 组织名(定位用)
|
|
245
|
+
*/
|
|
246
|
+
readonly org: string;
|
|
247
|
+
/**
|
|
248
|
+
* 仓库名(定位用)
|
|
249
|
+
*/
|
|
250
|
+
readonly repo: string;
|
|
251
|
+
/**
|
|
252
|
+
* 人读错误信息
|
|
253
|
+
*/
|
|
254
|
+
readonly message: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* 采集单仓元数据(只读;见模块注释降级策略)
|
|
258
|
+
*
|
|
259
|
+
* @param target - 仓库定位(org/repo/path)
|
|
260
|
+
* @returns 成功为采集产物;健康探测失败为 INSPECT_FAILED 错误
|
|
261
|
+
*/
|
|
262
|
+
declare function inspectRepo(target: RepoTarget): Promise<Result<RepoInspection, GitInspectError>>;
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/render/repo-document.mapper.d.ts
|
|
265
|
+
/**
|
|
266
|
+
* 渲染产物(完整文档内容 + 正文哈希)
|
|
267
|
+
*/
|
|
268
|
+
type RenderedDocument = {
|
|
269
|
+
/**
|
|
270
|
+
* 完整 markdown 文档(frontmatter + 正文)
|
|
271
|
+
*/
|
|
272
|
+
readonly content: string;
|
|
273
|
+
/**
|
|
274
|
+
* 正文规范化哈希(幂等键,不随 generated_at 等白名单字段变化)
|
|
275
|
+
*/
|
|
276
|
+
readonly hash: string;
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* 渲染仓库索引条目(确定性输出;hash 仅覆盖正文)
|
|
280
|
+
*
|
|
281
|
+
* @param inspection - 单仓采集产物
|
|
282
|
+
* @param generatedAt - 生成时刻(ISO8601,白名单字段,不参与 hash)
|
|
283
|
+
* @returns 完整文档与正文哈希
|
|
284
|
+
*/
|
|
285
|
+
declare function renderRepoDocument(inspection: RepoInspection, generatedAt: string): RenderedDocument;
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/render/org-readme.mapper.d.ts
|
|
288
|
+
/**
|
|
289
|
+
* 渲染组织索引 README(组织概览 + 仓库索引表;hash 仅覆盖正文)
|
|
290
|
+
*
|
|
291
|
+
* @param org - 组织名
|
|
292
|
+
* @param inspections - 该组织的采集产物列表(顺序原样入表)
|
|
293
|
+
* @param generatedAt - 生成时刻(ISO8601,白名单字段,不参与 hash)
|
|
294
|
+
* @returns 完整 README 文档与正文哈希
|
|
295
|
+
*/
|
|
296
|
+
declare function renderOrgReadme(org: string, inspections: readonly RepoInspection[], generatedAt: string): RenderedDocument;
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/render/catalog.mapper.d.ts
|
|
299
|
+
/**
|
|
300
|
+
* 归档子文件夹名(仓库数据唯一归档容器,root 不平铺组织数据)
|
|
301
|
+
*/
|
|
302
|
+
declare const REPOSITORIES_DIR = "repositories";
|
|
303
|
+
/**
|
|
304
|
+
* 目录册条目(由磁盘扫描产出,见 CatalogService.scan)
|
|
305
|
+
*/
|
|
306
|
+
type CatalogEntry = {
|
|
307
|
+
/**
|
|
308
|
+
* 组织名(同时是 repositories/ 下组织目录名)
|
|
309
|
+
*/
|
|
310
|
+
readonly org: string;
|
|
311
|
+
/**
|
|
312
|
+
* 该组织仓库索引条目数(repositories/<org>/<repo>/README.md 实测计数)
|
|
313
|
+
*/
|
|
314
|
+
readonly repoCount: number;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* 渲染总索引目录册(hash 仅覆盖正文)
|
|
318
|
+
*
|
|
319
|
+
* @param entries - 目录册条目(升序)
|
|
320
|
+
* @param generatedAt - 生成时刻(ISO8601,白名单字段,不参与 hash)
|
|
321
|
+
* @returns 完整目录册文档与正文哈希
|
|
322
|
+
*/
|
|
323
|
+
declare function renderCatalog(entries: readonly CatalogEntry[], generatedAt: string): RenderedDocument;
|
|
324
|
+
/**
|
|
325
|
+
* 解析目录册表行中的组织列表(`| [org](...) |` 首列链接文本;缺文件返回空)
|
|
326
|
+
*
|
|
327
|
+
* @param catalogText - 目录册全文
|
|
328
|
+
* @returns 组织名字符串列表(表行顺序)
|
|
329
|
+
*/
|
|
330
|
+
declare function parseCatalogOrgs(catalogText: string): readonly string[];
|
|
331
|
+
/**
|
|
332
|
+
* 渲染索引库 README(索引区说明;仅在缺失时写入,不参与幂等覆盖)
|
|
333
|
+
*
|
|
334
|
+
* @returns 索引库 README 全文
|
|
335
|
+
*/
|
|
336
|
+
declare function renderDataRootReadme(): string;
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/repo/org-index.service.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* 管理器构造项
|
|
341
|
+
*/
|
|
342
|
+
type OrgIndexServiceOptions = {
|
|
343
|
+
/**
|
|
344
|
+
* 数据根绝对路径
|
|
345
|
+
*/
|
|
346
|
+
readonly dataRoot: string;
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* 单组织写入行为开关
|
|
350
|
+
*/
|
|
351
|
+
type WriteOrgOptions = {
|
|
352
|
+
/**
|
|
353
|
+
* 干跑:只计算不落盘
|
|
354
|
+
*/
|
|
355
|
+
readonly dryRun?: boolean;
|
|
356
|
+
};
|
|
357
|
+
/**
|
|
358
|
+
* 单组织写入结果
|
|
359
|
+
*/
|
|
360
|
+
type OrgWriteResult = {
|
|
361
|
+
/**
|
|
362
|
+
* 组织名
|
|
363
|
+
*/
|
|
364
|
+
readonly org: string;
|
|
365
|
+
/**
|
|
366
|
+
* 组织目录绝对路径(dry-run 且目录不存在时为理论路径)
|
|
367
|
+
*/
|
|
368
|
+
readonly orgDir: string;
|
|
369
|
+
/**
|
|
370
|
+
* 本次写入文档数(含组织 README)
|
|
371
|
+
*/
|
|
372
|
+
readonly written: number;
|
|
373
|
+
/**
|
|
374
|
+
* 幂等跳过文档数(含组织 README)
|
|
375
|
+
*/
|
|
376
|
+
readonly skipped: number;
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* 组织索引管理器(引擎 PartitionWriter 委托;导出面保持)
|
|
380
|
+
*/
|
|
381
|
+
declare class OrgIndexService {
|
|
382
|
+
/**
|
|
383
|
+
* 数据根绝对路径
|
|
384
|
+
*/
|
|
385
|
+
readonly dataRoot: string;
|
|
386
|
+
/**
|
|
387
|
+
* 引擎分区写入器实例(目录档 + 组织 README profile)
|
|
388
|
+
*/
|
|
389
|
+
private readonly writer;
|
|
390
|
+
/**
|
|
391
|
+
* 构造管理器
|
|
392
|
+
*
|
|
393
|
+
* @param options - 构造项(dataRoot 必填)
|
|
394
|
+
* @returns 管理器实例
|
|
395
|
+
*/
|
|
396
|
+
constructor(options: OrgIndexServiceOptions);
|
|
397
|
+
/**
|
|
398
|
+
* 组织目录路径
|
|
399
|
+
*
|
|
400
|
+
* @param org - 目标组织名
|
|
401
|
+
* @returns 组织目录绝对路径
|
|
402
|
+
*/
|
|
403
|
+
orgDir(org: string): string;
|
|
404
|
+
/**
|
|
405
|
+
* 写入单组织:仓库索引条目 + 组织 README(幂等跳过;零 git)
|
|
406
|
+
*
|
|
407
|
+
* @param org - 目标组织名
|
|
408
|
+
* @param inspections - 该组织采集产物列表(内部按 repo 名升序落盘)
|
|
409
|
+
* @param options - 行为开关(dryRun)
|
|
410
|
+
* @returns 写入统计
|
|
411
|
+
* @throws {@link Error} 组织名非法或仓库名与保留字冲突时抛出
|
|
412
|
+
*/
|
|
413
|
+
writeOrg(org: string, inspections: readonly RepoInspection[], options?: WriteOrgOptions): Promise<OrgWriteResult>;
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/repo/catalog.service.d.ts
|
|
417
|
+
/**
|
|
418
|
+
* 管理器构造项
|
|
419
|
+
*/
|
|
420
|
+
type CatalogServiceOptions = {
|
|
421
|
+
/**
|
|
422
|
+
* 数据根绝对路径
|
|
423
|
+
*/
|
|
424
|
+
readonly dataRoot: string;
|
|
425
|
+
/**
|
|
426
|
+
* 提交身份(仅 --commit 时消费;测试/CI 注入)
|
|
427
|
+
*/
|
|
428
|
+
readonly gitIdentity?: GitIdentity$1;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* 刷新行为开关
|
|
432
|
+
*/
|
|
433
|
+
type RefreshOptions = CatalogRefreshOptions;
|
|
434
|
+
/**
|
|
435
|
+
* 刷新结果
|
|
436
|
+
*/
|
|
437
|
+
type CatalogRefreshResult = CatalogRefreshResult$1<CatalogEntry>;
|
|
438
|
+
/**
|
|
439
|
+
* 目录册管理器(引擎 CatalogService 委托;导出面保持)
|
|
440
|
+
*/
|
|
441
|
+
declare class CatalogService {
|
|
442
|
+
/**
|
|
443
|
+
* 数据根绝对路径
|
|
444
|
+
*/
|
|
445
|
+
readonly dataRoot: string;
|
|
446
|
+
/**
|
|
447
|
+
* 引擎目录册服务实例
|
|
448
|
+
*/
|
|
449
|
+
private readonly service;
|
|
450
|
+
/**
|
|
451
|
+
* 构造管理器
|
|
452
|
+
*
|
|
453
|
+
* @param options - 构造项(dataRoot 必填;gitIdentity 可选)
|
|
454
|
+
* @returns 管理器实例
|
|
455
|
+
*/
|
|
456
|
+
constructor(options: CatalogServiceOptions);
|
|
457
|
+
/**
|
|
458
|
+
* 扫描索引库组织目录(透传域扫描)
|
|
459
|
+
*
|
|
460
|
+
* @returns 目录册条目列表(升序)
|
|
461
|
+
*/
|
|
462
|
+
scan(): Promise<readonly CatalogEntry[]>;
|
|
463
|
+
/**
|
|
464
|
+
* 确保索引库骨架就绪(目录 + README/.gitignore/.env.example;零 git)
|
|
465
|
+
*
|
|
466
|
+
* @param dryRun - 干跑时不做任何落盘
|
|
467
|
+
* @returns 本次新建的根文件相对路径清单
|
|
468
|
+
*/
|
|
469
|
+
ensureRoot(dryRun: boolean): Promise<readonly string[]>;
|
|
470
|
+
/**
|
|
471
|
+
* 刷新目录册:扫描 → 与现存 catalog.md 比对 → 变更才写 →(仅显式 commit 时)提交
|
|
472
|
+
*
|
|
473
|
+
* @param options - 行为开关(dryRun/commit;commit 缺省 false 零 git)
|
|
474
|
+
* @returns 刷新结果(条目/写入状态/提交状态)
|
|
475
|
+
* @throws {@link Error} 显式 commit 且 git init 失败时抛出
|
|
476
|
+
*/
|
|
477
|
+
refresh(options?: RefreshOptions): Promise<CatalogRefreshResult>;
|
|
478
|
+
/**
|
|
479
|
+
* 对账现存 catalog.md 与磁盘实测(catalog check 语义;只报告不修复)
|
|
480
|
+
*
|
|
481
|
+
* @returns 问题清单(空 = 对账通过)
|
|
482
|
+
*/
|
|
483
|
+
check(): Promise<readonly string[]>;
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
486
|
+
//#region src/runtime-env.utils.d.ts
|
|
487
|
+
/**
|
|
488
|
+
* 解析命中通道
|
|
489
|
+
*/
|
|
490
|
+
type RuntimeEnvChannel = 'config-file';
|
|
491
|
+
/**
|
|
492
|
+
* 运行时环境(合并形态:dataRoot 出配置文件,clonesRoot 出 .env)
|
|
493
|
+
*/
|
|
494
|
+
type RuntimeEnv = {
|
|
495
|
+
/**
|
|
496
|
+
* 数据根绝对路径(配置文件承载;就地自指以文件所在目录绝对化)
|
|
497
|
+
*/
|
|
498
|
+
readonly dataRoot: string;
|
|
499
|
+
/**
|
|
500
|
+
* 本地克隆根绝对路径(.env 承载;只读消费)
|
|
501
|
+
*/
|
|
502
|
+
readonly clonesRoot: string;
|
|
503
|
+
};
|
|
504
|
+
/**
|
|
505
|
+
* 解析成功结果
|
|
506
|
+
*/
|
|
507
|
+
type RuntimeEnvResolution = {
|
|
508
|
+
/**
|
|
509
|
+
* 命中通道(恒 config-file:配置文件必备后无整体 env 通道)
|
|
510
|
+
*/
|
|
511
|
+
readonly channel: RuntimeEnvChannel;
|
|
512
|
+
/**
|
|
513
|
+
* 合并后的运行时环境
|
|
514
|
+
*/
|
|
515
|
+
readonly env: RuntimeEnv;
|
|
516
|
+
/**
|
|
517
|
+
* 命中的配置文件绝对路径
|
|
518
|
+
*/
|
|
519
|
+
readonly configPath: string;
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* 解析错误(配置文件缺失/非法 / env 缺失)
|
|
523
|
+
*/
|
|
524
|
+
type RuntimeEnvError = ConfigLoadError | EnvError;
|
|
525
|
+
/**
|
|
526
|
+
* 解析结果
|
|
527
|
+
*/
|
|
528
|
+
type RuntimeEnvResult = {
|
|
529
|
+
readonly ok: true;
|
|
530
|
+
readonly value: RuntimeEnvResolution;
|
|
531
|
+
} | {
|
|
532
|
+
readonly ok: false;
|
|
533
|
+
readonly error: RuntimeEnvError;
|
|
534
|
+
};
|
|
535
|
+
/**
|
|
536
|
+
* 解析运行时环境(配置文件必备 + 克隆根 env 字段级合并,见模块注释)
|
|
537
|
+
*
|
|
538
|
+
* @param explicitConfigPath - 显式配置文件路径(可选;缺省自 cwd 向上发现)
|
|
539
|
+
* @returns 成功为合并形态运行时环境与配置文件路径;失败为可读错误
|
|
540
|
+
*/
|
|
541
|
+
declare function resolveRuntimeEnv(explicitConfigPath?: string): Promise<RuntimeEnvResult>;
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/convert.usecase.d.ts
|
|
544
|
+
/**
|
|
545
|
+
* 转换选择器(三选一:org | repo | all)
|
|
546
|
+
*/
|
|
547
|
+
type ConvertSelection = {
|
|
548
|
+
/**
|
|
549
|
+
* 单组织名
|
|
550
|
+
*/
|
|
551
|
+
readonly org?: string;
|
|
552
|
+
/**
|
|
553
|
+
* 单仓库选择器(owner/name)
|
|
554
|
+
*/
|
|
555
|
+
readonly repo?: string;
|
|
556
|
+
/**
|
|
557
|
+
* 全量(克隆根内全部组织)
|
|
558
|
+
*/
|
|
559
|
+
readonly all?: boolean;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* 转换行为开关
|
|
563
|
+
*/
|
|
564
|
+
type ConvertOptions = ConvertSelection & {
|
|
565
|
+
/**
|
|
566
|
+
* 干跑:零落盘零提交
|
|
567
|
+
*/
|
|
568
|
+
readonly dryRun?: boolean;
|
|
569
|
+
/**
|
|
570
|
+
* 是否执行 git 提交(缺省 false——零 git;--commit 显式开启,数据根整体单仓)
|
|
571
|
+
*/
|
|
572
|
+
readonly commit?: boolean;
|
|
573
|
+
/**
|
|
574
|
+
* 提交身份(仅 --commit 时消费;缺省走用户 git 全局配置,测试/CI 注入)
|
|
575
|
+
*/
|
|
576
|
+
readonly gitIdentity?: GitIdentity;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* 单组织转换报告
|
|
580
|
+
*/
|
|
581
|
+
type ConvertOrgReport = {
|
|
582
|
+
/**
|
|
583
|
+
* 组织名
|
|
584
|
+
*/
|
|
585
|
+
readonly org: string;
|
|
586
|
+
/**
|
|
587
|
+
* 该组织采集成功的仓库数
|
|
588
|
+
*/
|
|
589
|
+
readonly repos: number;
|
|
590
|
+
/**
|
|
591
|
+
* 写入文档数(含组织 README)
|
|
592
|
+
*/
|
|
593
|
+
readonly written: number;
|
|
594
|
+
/**
|
|
595
|
+
* 幂等跳过文档数
|
|
596
|
+
*/
|
|
597
|
+
readonly skipped: number;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* 单仓库采集失败跳过报告
|
|
601
|
+
*/
|
|
602
|
+
type ConvertRepoSkip = {
|
|
603
|
+
/**
|
|
604
|
+
* 组织名
|
|
605
|
+
*/
|
|
606
|
+
readonly org: string;
|
|
607
|
+
/**
|
|
608
|
+
* 仓库名
|
|
609
|
+
*/
|
|
610
|
+
readonly repo: string;
|
|
611
|
+
/**
|
|
612
|
+
* 人读原因
|
|
613
|
+
*/
|
|
614
|
+
readonly message: string;
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* 转换总报告
|
|
618
|
+
*/
|
|
619
|
+
type ConvertReport = {
|
|
620
|
+
/**
|
|
621
|
+
* 逐组织报告(升序)
|
|
622
|
+
*/
|
|
623
|
+
readonly orgs: readonly ConvertOrgReport[];
|
|
624
|
+
/**
|
|
625
|
+
* 采集失败跳过的仓库清单
|
|
626
|
+
*/
|
|
627
|
+
readonly skippedRepos: readonly ConvertRepoSkip[];
|
|
628
|
+
/**
|
|
629
|
+
* 克隆根顶层非标准条目报告(只报告不修复)
|
|
630
|
+
*/
|
|
631
|
+
readonly scanSkipped: readonly SkippedEntry[];
|
|
632
|
+
/**
|
|
633
|
+
* 目录册刷新结果
|
|
634
|
+
*/
|
|
635
|
+
readonly catalog: CatalogRefreshResult;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* 转换编排错误
|
|
639
|
+
*/
|
|
640
|
+
type ConvertError = {
|
|
641
|
+
/**
|
|
642
|
+
* 错误码
|
|
643
|
+
*/
|
|
644
|
+
readonly code: 'SELECTION_INVALID' | 'ORG_INVALID' | 'REPO_SELECTOR_INVALID' | 'ORG_NOT_FOUND' | 'REPO_NOT_FOUND' | 'SOURCE_ERROR';
|
|
645
|
+
/**
|
|
646
|
+
* 人读错误信息
|
|
647
|
+
*/
|
|
648
|
+
readonly message: string;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* 执行转换(编排门面;见模块注释主流程)
|
|
652
|
+
*
|
|
653
|
+
* @param env - 解析后的环境配置
|
|
654
|
+
* @param options - 选择器与行为开关
|
|
655
|
+
* @returns 转换总报告;失败为选择器/源/目标缺失错误
|
|
656
|
+
*/
|
|
657
|
+
declare function runConvert(env: RuntimeEnv, options: ConvertOptions): Promise<Result<ConvertReport, ConvertError | CloneSourceError>>;
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region src/verify.usecase.d.ts
|
|
660
|
+
/**
|
|
661
|
+
* 单文档哈希漂移
|
|
662
|
+
*/
|
|
663
|
+
type HashDrift = {
|
|
664
|
+
/**
|
|
665
|
+
* 文档绝对路径
|
|
666
|
+
*/
|
|
667
|
+
readonly file: string;
|
|
668
|
+
/**
|
|
669
|
+
* frontmatter 登记值
|
|
670
|
+
*/
|
|
671
|
+
readonly expected: string;
|
|
672
|
+
/**
|
|
673
|
+
* 正文复算值
|
|
674
|
+
*/
|
|
675
|
+
readonly actual: string;
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* 体检报告
|
|
679
|
+
*/
|
|
680
|
+
type VerifyReport = {
|
|
681
|
+
/**
|
|
682
|
+
* 哈希漂移清单(空 = 全部一致)
|
|
683
|
+
*/
|
|
684
|
+
readonly hashDrifts: readonly HashDrift[];
|
|
685
|
+
/**
|
|
686
|
+
* 一致性问题清单(组织 README 计数/目录册对账)
|
|
687
|
+
*/
|
|
688
|
+
readonly issues: readonly string[];
|
|
689
|
+
/**
|
|
690
|
+
* 克隆根顶层非标准条目报告(信息性,不参与 ok 判定)
|
|
691
|
+
*/
|
|
692
|
+
readonly cloneSkipped: readonly SkippedEntry[];
|
|
693
|
+
/**
|
|
694
|
+
* 是否全部通过
|
|
695
|
+
*/
|
|
696
|
+
readonly ok: boolean;
|
|
697
|
+
};
|
|
698
|
+
/**
|
|
699
|
+
* 数据根缺失错误
|
|
700
|
+
*/
|
|
701
|
+
type VerifyError = {
|
|
702
|
+
/**
|
|
703
|
+
* 错误码
|
|
704
|
+
*/
|
|
705
|
+
readonly code: 'DATA_ROOT_MISSING';
|
|
706
|
+
/**
|
|
707
|
+
* 人读错误信息
|
|
708
|
+
*/
|
|
709
|
+
readonly message: string;
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* 执行体检(见模块注释三项检查)
|
|
713
|
+
*
|
|
714
|
+
* @param env - 解析后的环境配置
|
|
715
|
+
* @returns 体检报告;数据根缺失为错误
|
|
716
|
+
*/
|
|
717
|
+
declare function runVerify(env: RuntimeEnv): Promise<Result<VerifyReport, VerifyError>>;
|
|
718
|
+
//#endregion
|
|
719
|
+
export { CatalogEntry, CatalogRefreshResult, CatalogService, CatalogServiceOptions, CloneScan, CloneSourceError, type CommitResult, ConvertError, ConvertOptions, ConvertOrgReport, ConvertRepoSkip, ConvertReport, ConvertSelection, ENV_CLONES_ROOT, EnvError, EnvTemplateParams, type GitIdentity, GitInspectError, type GitQueryResult, GithubMarkdownEnv, HashDrift, ORG_PATTERN, OrgIndexService, OrgIndexServiceOptions, OrgRepos, OrgWriteResult, REPOSITORIES_DIR, RefreshOptions, RenderedDocument, RepoInspection, RepoTarget, type Result, RuntimeEnv, RuntimeEnvChannel, RuntimeEnvError, RuntimeEnvResolution, RuntimeEnvResult, SkippedEntry, SkippedReason, type SplitDocument, VerifyError, VerifyReport, WriteOrgOptions, commitCount, commitPaths, contentHash, ensureGitRepo, failure, gitQuery, githubEnvKit, githubMarkdownEnvSchema, inspectRepo, lastCommitShort, normalizeBody, parseCatalogOrgs, parseFrontmatterHead, parseRepoSelector, renderCatalog, renderDataRootReadme, renderEnvTemplate, renderOrgReadme, renderRepoDocument, resolveEnv, resolveRuntimeEnv, runConvert, runVerify, scanClonesRoot, splitDocument, stringifyFrontmatter, success };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{loadGithubMarkdownConfig as e}from"@longzai-intelligence-github-markdown/config";import{commitCount as t,commitPaths as n,contentHash as r,createCatalogReconciler as i,createCatalogService as a,createEnvKit as o,createPartitionWriter as s,ensureGitRepo as c,failure as l,gitQuery as u,lastCommitShort as d,normalizeBody as f,parseFrontmatterHead as p,splitDocument as m,stringifyFrontmatter as h,success as g}from"@longzai-intelligence-markdown/data-engine";import{join as _,resolve as v}from"node:path";import*as y from"zod";import{existsSync as b,readFileSync as x,readdirSync as S}from"node:fs";export*from"@longzai-intelligence-github-markdown/config";const C=`LZI_GITHUB_MARKDOWN_CLONES_ROOT`,w=y.object({[C]:y.string().min(1)}),T=o({variables:[{name:C,comment:`本地克隆根:owner/repo 两层标准结构的克隆目录(工具只读消费,不写不抓取)`,placeholder:`/path/to/github-com-clones`}],toEnvConfig:e=>({clonesRoot:v(e.LZI_GITHUB_MARKDOWN_CLONES_ROOT??``)}),defaultTemplateTitle:`lzi-github-markdown 环境配置`});function E(e=process.env){return T.resolveEnv(e)}const D=T;function O(e={}){let t={};return e.clonesRoot!==void 0&&(t[C]=e.clonesRoot),D.renderEnvTemplate({values:t,title:e.title})}const k=/^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/,A=/^[A-Za-z0-9_][A-Za-z0-9._-]*$/,j=`README.md`;function M(e,t){return e.name<t.name?-1:+(e.name>t.name)}function N(e){return b(_(e,`.git`))}function P(e,t){let n=[];for(let r of[...S(t,{withFileTypes:!0})].sort(M)){if(!r.isDirectory()||r.name.startsWith(`.`)||!A.test(r.name)||r.name===j)continue;let i=_(t,r.name);N(i)&&n.push({org:e,repo:r.name,path:i})}return n}function F(e){if(!b(e))return l({code:`DIR_NOT_FOUND`,message:`克隆根不存在:${e}(应为 owner/repo 两层标准结构的克隆目录)`});let t=[],n=[];for(let r of[...S(e,{withFileTypes:!0})].sort(M)){if(r.name.startsWith(`.`))continue;if(!r.isDirectory()){n.push({entry:r.name,reason:`TOP_LEVEL_FILE`});continue}let i=_(e,r.name);if(N(i)){n.push({entry:r.name,reason:`TOP_LEVEL_REPO`});continue}if(!k.test(r.name)){n.push({entry:r.name,reason:`OWNER_NAME_INVALID`});continue}let a=P(r.name,i);if(a.length===0){n.push({entry:r.name,reason:`NO_VALID_REPOS`});continue}t.push({org:r.name,repos:a})}return g({orgs:t,skipped:n})}function I(e){let t=e.split(`/`),n=t[0],r=t[1];return t.length!==2||n===void 0||r===void 0||n===``||r===``?l({message:`--repo 格式非法:${e}(应为 <owner>/<name>)`}):!k.test(n)||!A.test(r)||r===j?l({message:`--repo 名非法:${e}(owner/repo 含不支持字符或保留字)`}):g({org:n,repo:r})}function L(e){let t=e.match(/github\.com[:/]([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+?)(?:\.git)?\/?$/i);if(t===null)return null;let n=t[1],r=t[2];return n===void 0||r===void 0?null:{owner:n,repo:r}}async function R(e){let t=await u(e.path,[`rev-parse`,`--git-dir`]);if(!t.ok)return l({code:`INSPECT_FAILED`,org:e.org,repo:e.repo,message:`仓库健康探测失败:${e.path}(${t.stderr})`});let n=await u(e.path,[`remote`,`get-url`,`origin`]),r=n.ok&&n.stdout!==``?n.stdout:null,i=r===null?null:L(r),a=i===null?r===null?`https://github.com/${e.org}/${e.repo}`:null:`https://github.com/${i.owner}/${i.repo}`,o=await u(e.path,[`branch`,`--show-current`]),s=o.ok&&o.stdout!==``?o.stdout:null,c=await u(e.path,[`rev-parse`,`--abbrev-ref`,`HEAD`]),d=c.ok&&c.stdout===`HEAD`,f=await u(e.path,[`rev-parse`,`--short`,`HEAD`]),p=await u(e.path,[`log`,`-1`,`--format=%cI`]),m=await u(e.path,[`rev-list`,`--count`,`HEAD`]),h=await u(e.path,[`tag`,`--list`]),_=await u(e.path,[`status`,`--porcelain`]);return g({org:e.org,repo:e.repo,clonePath:e.path,remoteUrl:r,repoUrl:a,branch:s,detached:d,lastCommitShort:f.ok?f.stdout:null,lastCommitAt:p.ok?p.stdout:null,commitCount:m.ok?Number.parseInt(m.stdout,10):null,tagCount:h.ok?h.stdout.split(`
|
|
2
|
+
`).filter(e=>e!==``).length:0,isDirty:_.ok?_.stdout!==``:!1})}function z(e,t,n){return{feed_pipeline_id:`github-markdown`,plugin:`github`,source_id:`clones-root`,generated_at:t,content_hash:n,tags:[],org:e.org,repo:e.repo,remote_url:e.remoteUrl,repo_url:e.repoUrl,branch:e.branch,detached:e.detached,last_commit_short:e.lastCommitShort,last_commit_at:e.lastCommitAt,commit_count:e.commitCount,tag_count:e.tagCount,is_dirty:e.isDirty}}function B(e){let t=e.branch??(e.detached?`HEAD(detached)`:`(无提交)`),n=[];return n.push(`# ${e.org}/${e.repo}`,``),n.push(`## 概览`,``),n.push(e.repoUrl===null?`- 仓库:${e.org}/${e.repo}`:`- 仓库:[${e.org}/${e.repo}](${e.repoUrl})`),n.push(`- 远端:${e.remoteUrl??`(无 origin)`}`),n.push(`- 分支:${t}`),n.push(`- 提交数:${e.commitCount??`-`}`),n.push(e.lastCommitShort===null?`- 最近提交:-`:`- 最近提交:${e.lastCommitShort}${e.lastCommitAt===null?``:`(${e.lastCommitAt})`}`),n.push(`- 标签:${e.tagCount} 个`),n.push(`- 工作区:${e.isDirty?`有未提交变更`:`干净`}`),n.push(``),`${n.join(`
|
|
3
|
+
`)}\n`}function V(e,t){let n=B(e),i=r(n);return{content:`${h(z(e,t,i))}\n${n}`,hash:i}}function H(e){return e.replaceAll(`|`,`\\|`).replaceAll(`
|
|
4
|
+
`,` `)}function U(e,t,n){let i=[];i.push(`# GitHub Repos ${e}`,``),i.push(`共 ${t.length} 仓。`,``),i.push(`| 仓库 | 分支 | 提交数 | 最近提交 |`),i.push(`| --- | --- | --- | --- |`);for(let e of t){let t=e.branch??(e.detached?`HEAD(detached)`:`(无提交)`),n=`| [${H(e.repo)}](${e.repo}/README.md) | ${H(t)} | ${e.commitCount??`-`} | ${e.lastCommitShort??`-`} |`;i.push(n)}i.push(``);let a=i.join(`
|
|
5
|
+
`),o=r(a);return{content:`${h({feed_pipeline_id:`github-markdown`,plugin:`github`,source_id:`clones-root`,generated_at:n,content_hash:o,tags:[],org:e,repo_count:t.length})}\n${a}`,hash:o}}const W=`repositories`;function G(e,t){let n=e.reduce((e,t)=>e+t.repoCount,0),i=[];i.push(`# GitHub 索引目录册`,``),i.push(`共 ${e.length} 个组织 / ${n} 个仓库。`,``),i.push(`| 组织 | 仓库数 | 目录 |`),i.push(`| --- | --- | --- |`);for(let t of e){let e=`| [${t.org}](${W}/${t.org}/) | ${t.repoCount} | ${W}/${t.org}/ |`;i.push(e)}i.push(``);let a=i.join(`
|
|
6
|
+
`),o=r(a);return{content:`${h({kind:`catalog`,feed_pipeline_id:`github-markdown`,plugin:`github`,source_id:`clones-root`,generated_at:t,content_hash:o,tags:[],org_count:e.length,repo_total:n})}\n${a}`,hash:o}}function K(e){let t=[];for(let n of e.matchAll(/\| \[([A-Za-z0-9-]+)\]\([^)]*\) \|/g)){let e=n[1];e!==void 0&&t.push(e)}return t}function q(){return(/* @__PURE__ */ '# longzai-intelligence-github-data,,GitHub 克隆仓索引库:由 `lzi-github-markdown`(longzai-intelligence-github-markdown 仓)从本地克隆根(owner/repo 两层标准)只读扫描生成并维护。,,## 组织规则,,- 本目录是索引库:只存索引信息(git 元数据 + 指向链接),不复制任何项目内容。,- root 只保留索引库元信息(README.md/catalog.md/.gitignore)与唯一归档子文件夹 `repositories/`;组织数据不平铺 root。,- `repositories/<org>/<repo>/README.md` 一仓一档索引条目;`repositories/<org>/README.md` 组织索引表。,- 本库内部无任何嵌套 git 仓库(与按日一仓类数据区不同);如需版本化,整体作为单一 git 仓、且仅在显式 `--commit` 时提交。,- 跨库检索与统计走 `catalog.md`;单个组织目录自包含,可独立消费。,,## 基础配置(数据区自持,参考 lzi-insight 标准件),,- `lzi-github-markdown.config.ts`:就地配置(以工具命名,全局 ADR 0090);仅 `dataRoot: "."` 自指单字段(禁 version——代际由包 npm 版本承载,全局 ADR 0097 决策 10);机器无关、入库跟踪(决策 8);配置文件必备、缺失即报错(决策 9);在本目录直接执行 convert/verify/catalog。,- `.env` / `.env.example`:跨项目路径唯一 env 通道 LZI_GITHUB_MARKDOWN_CLONES_ROOT(本地克隆根);.example 为中性占位符模板(可入库),.env 为机器本地实值(gitignored)。,- `lzi-env.config.ts`:本数据区环境变量显式白名单(lzi-env-cli check 门禁消费;type-only import 零依赖可加载)。,- 以上配置均为机器无关或中性模板,不携带索引数据;`repositories/` 与目录册之外不新增数据类文件。,,## 存储纪律,,- 元数据一律随 markdown frontmatter(YAML),库内禁任何 `.json` 元数据文件。,- 纯索引库:无 UI 代码、无 package.json、无 devDeps。,- 幂等:`content_hash`(正文规范化 SHA-256)相同跳过、不同覆盖;重跑 `convert` 零变更时零新写入。,- 保留字:root 级 `README.md`/`catalog.md`/`.gitignore`/`repositories/`;组织目录内 `README.md`(仓库名冲突拒绝)。,- 本地克隆根只读消费(不写不抓取);非标准克隆条目(顶层仓库/非法 owner 名/空 owner)跳过并报告,不修复。,'.split(`,`)).join(`
|
|
7
|
+
`)}var J=class{dataRoot;writer;constructor(e){this.dataRoot=e.dataRoot,this.writer=s({dataRoot:this.dataRoot,partitionDir:e=>_(this.dataRoot,W,e),entryRelPath:(e,t)=>`${W}/${e}/${t.repo}/README.md`,renderEntry:V,sortEntries:e=>[...e].sort((e,t)=>e.repo<t.repo?-1:+(e.repo>t.repo)),renderPartitionReadme:U,validatePartition:e=>{if(!k.test(e))throw Error(`组织名非法:${e}(应为 GitHub 用户/组织名字符集)`)},validateEntry:(e,t)=>{if(t.repo===`README.md`)throw Error(`仓库名与组织目录保留字冲突:${e}/${t.repo}(README.md 为组织索引文件名)`)}})}orgDir(e){return _(this.dataRoot,W,e)}async writeOrg(e,t,n={}){let r=await this.writer.writePartition(e,t,{dryRun:n.dryRun});return{org:e,orgDir:this.orgDir(e),written:r.written,skipped:r.skipped}}};const Y=[`# macOS`,`.DS_Store`,``,`# 机器本地配置(.env 本地实值;配置文件入库跟踪,不忽略)`,`.env`,``].join(`
|
|
8
|
+
`);function X(e){let t=_(e,W);if(!b(t))return[];let n=[],r=[...S(t,{withFileTypes:!0})].sort((e,t)=>e.name<t.name?-1:1);for(let e of r){if(!e.isDirectory()||e.name.startsWith(`.`))continue;let r=_(t,e.name);if(!b(_(r,`README.md`)))continue;let i=0;for(let e of S(r,{withFileTypes:!0}))e.isDirectory()&&!e.name.startsWith(`.`)&&b(_(r,e.name,`README.md`))&&(i+=1);n.push({org:e.name,repoCount:i})}return n}function Z(e){return a({dataRoot:e.dataRoot,gitIdentity:e.gitIdentity,rootFiles:[{path:`.gitignore`,content:Y},{path:`.env.example`,content:O({title:`lzi-github-markdown 就地环境配置模板`})},{path:`README.md`,content:q()}],scan:async()=>X(e.dataRoot),renderCatalog:G,reconcile:i({countFields:[{headKey:`org_count`,actual:e=>e.length},{headKey:`repo_total`,actual:e=>e.reduce((e,t)=>e+t.repoCount,0)}],rowPattern:/\| \[([A-Za-z0-9-]+)\]\([^)]*\) \|/g,keyOfEntry:e=>e.org,keyNoun:`组织`}),commit:{defaultEnabled:!1,message:e=>{let t=e.reduce((e,t)=>e+t.repoCount,0);return`data(catalog): 更新索引目录册(${e.length} 组织 / ${t} 仓)`}}})}var Q=class{dataRoot;service;constructor(e){this.dataRoot=e.dataRoot,this.service=Z(e)}async scan(){return this.service.scan()}async ensureRoot(e){return this.service.ensureRoot(e)}async refresh(e={}){return this.service.refresh(e)}async check(){return this.service.check()}};function $(e){let t=e.org!==void 0,n=e.repo!==void 0,r=[t,n,e.all===!0].filter(Boolean).length;if(r===0)return l({code:`SELECTION_INVALID`,message:`缺少选择器:--org <name> / --repo <owner>/<name> / --all 三选一`});if(r>1)return l({code:`SELECTION_INVALID`,message:`选择器互斥:--org / --repo / --all 只能选一种`});if(t){let t=e.org;if(t===void 0||!k.test(t)){let e=`--org 格式非法:${t??`(空)`}(应为 GitHub 用户/组织名)`;return l({code:`ORG_INVALID`,message:e})}return g({kind:`org`,org:t})}if(n){let t=e.repo;if(t===void 0)return l({code:`SELECTION_INVALID`,message:`--repo 缺值(应为 <owner>/<name>)`});let n=I(t);return n.ok?g({kind:`repo`,org:n.value.org,repo:n.value.repo}):l({code:`REPO_SELECTOR_INVALID`,message:n.error.message})}return g({kind:`all`})}function ee(e,t){if(e.kind===`all`)return g(t);let n=t.find(t=>t.org===e.org);if(n===void 0){let t=e.kind===`org`?`克隆根不存在组织 ${e.org}(可用组织见 catalog list 或检查克隆目录)`:`克隆根不存在组织 ${e.org}(--repo ${e.org}/${e.repo})`;return l({code:e.kind===`org`?`ORG_NOT_FOUND`:`REPO_NOT_FOUND`,message:t})}if(e.kind===`org`)return g([n]);if(n.repos.find(t=>t.repo===e.repo)===void 0){let t=`组织 ${e.org} 下不存在仓库 ${e.repo}(--repo ${e.org}/${e.repo})`;return l({code:`REPO_NOT_FOUND`,message:t})}return g([n])}async function te(e,t){let n=$(t);if(!n.ok)return l(n.error);let r=F(e.clonesRoot);if(!r.ok)return l(r.error);let i=ee(n.value,r.value.orgs);if(!i.ok)return l(i.error);let a=new J({dataRoot:e.dataRoot}),o={dryRun:t.dryRun===!0,commit:t.commit===!0},s=[],c=[];for(let e of i.value){let t=[];for(let n of e.repos){let e=await R(n);if(!e.ok){c.push({org:e.error.org,repo:e.error.repo,message:e.error.message});continue}t.push(e.value)}let n=await a.writeOrg(e.org,t,{dryRun:o.dryRun});s.push({org:n.org,repos:t.length,written:n.written,skipped:n.skipped})}let u=await new Q({dataRoot:e.dataRoot,gitIdentity:t.gitIdentity}).refresh(o);return g({orgs:s,skippedRepos:c,scanSkipped:r.value.skipped,catalog:u})}async function ne(e){if(!b(e.dataRoot)){let t=`数据根不存在:${e.dataRoot}`;return l({code:`DATA_ROOT_MISSING`,message:t})}let t=new Q({dataRoot:e.dataRoot}),n=await t.scan(),i=[],a=[];for(let t of n){let n=_(e.dataRoot,W,t.org),o=S(n,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).sort((e,t)=>e.name<t.name?-1:1),s=0;for(let e of o){let t=_(n,e.name,`README.md`);if(!b(t))continue;s+=1;let{head:a,body:o}=m(x(t,`utf8`)),c=r(o);a.content_hash!==void 0&&a.content_hash!==c&&i.push({file:t,expected:a.content_hash,actual:c})}let c=_(n,`README.md`);if(b(c)){let{head:e}=m(x(c,`utf8`));e.repo_count!==void 0&&e.repo_count!==String(s)&&a.push(`${W}/${t.org}/README.md 登记仓库数 ${e.repo_count} 与实测 ${s} 不符`)}else a.push(`${W}/${t.org} 缺 README.md`)}let o=await t.check();a.push(...o);let s=F(e.clonesRoot),c=s.ok?s.value.skipped:[];return g({hashDrifts:i,issues:a,cloneSkipped:c,ok:i.length===0&&a.length===0})}async function re(t){let n=await e(t);if(!n.ok)return{ok:!1,error:n.error};let r=E();return r.ok?{ok:!0,value:{channel:`config-file`,env:{dataRoot:n.config.dataRoot,clonesRoot:r.value.clonesRoot},configPath:n.path}}:{ok:!1,error:r.error}}export{Q as CatalogService,C as ENV_CLONES_ROOT,k as ORG_PATTERN,J as OrgIndexService,W as REPOSITORIES_DIR,t as commitCount,n as commitPaths,r as contentHash,c as ensureGitRepo,l as failure,u as gitQuery,D as githubEnvKit,w as githubMarkdownEnvSchema,R as inspectRepo,d as lastCommitShort,f as normalizeBody,K as parseCatalogOrgs,p as parseFrontmatterHead,I as parseRepoSelector,G as renderCatalog,q as renderDataRootReadme,O as renderEnvTemplate,U as renderOrgReadme,V as renderRepoDocument,E as resolveEnv,re as resolveRuntimeEnv,te as runConvert,ne as runVerify,F as scanClonesRoot,m as splitDocument,h as stringifyFrontmatter,g as success};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-github-markdown/core",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Longzai Intelligence Github Markdown core - 本地克隆仓只读扫描与 git 采集/确定性渲染/按组织 git 仓写入/目录册",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "lzi-builder",
|
|
18
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
19
|
+
"prepublishOnly": "bun run build:prod",
|
|
20
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
21
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
22
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
23
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
24
|
+
"lint": "oxlint && oxfmt --check",
|
|
25
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
26
|
+
"test": "lzi-bun-cli test",
|
|
27
|
+
"test:watch": "lzi-bun-cli test --watch",
|
|
28
|
+
"test:coverage": "lzi-bun-cli test --coverage",
|
|
29
|
+
"clean": "lzi-dev-cli clean"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@longzai-intelligence-github-markdown/config": "0.0.2",
|
|
33
|
+
"@longzai-intelligence-markdown/data-engine": "^0.0.1",
|
|
34
|
+
"zod": "^4.4.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/bun": "^1.3.14"
|
|
38
|
+
}
|
|
39
|
+
}
|