@longzai-intelligence-github-markdown/core 0.0.2 → 0.0.5
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 +0 -25
- package/dist/index.js +8 -4
- package/package.json +13 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
1
|
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
2
|
import * as z from "zod";
|
|
4
3
|
export * from "@longzai-intelligence-github-markdown/config";
|
|
5
|
-
//#region src/env/env.schema.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* 本地克隆根环境变量名(owner/repo 两层标准结构)
|
|
8
6
|
*/
|
|
@@ -54,8 +52,6 @@ declare function resolveEnv(processEnv?: NodeJS.ProcessEnv): ReturnType<typeof e
|
|
|
54
52
|
* 供 env-template.utils 消费的域工具族实例(模板渲染与解析同源同族)
|
|
55
53
|
*/
|
|
56
54
|
declare const githubEnvKit: import("@longzai-intelligence-markdown/data-engine").EnvKit<GithubMarkdownEnv>;
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/env/env-template.utils.d.ts
|
|
59
55
|
/**
|
|
60
56
|
* .env 模板入参
|
|
61
57
|
*/
|
|
@@ -76,8 +72,6 @@ type EnvTemplateParams = {
|
|
|
76
72
|
* @returns .env 文件全文(单变量 + 注释行)
|
|
77
73
|
*/
|
|
78
74
|
declare function renderEnvTemplate(params?: EnvTemplateParams): string;
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/source/clone-source.adapter.d.ts
|
|
81
75
|
/**
|
|
82
76
|
* 合法 owner 名模式(GitHub 用户/组织名:字母数字连字符,不以连字符开头/结尾)
|
|
83
77
|
*
|
|
@@ -176,8 +170,6 @@ declare function parseRepoSelector(selector: string): Result<{
|
|
|
176
170
|
}, {
|
|
177
171
|
readonly message: string;
|
|
178
172
|
}>;
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/source/git-inspect.utils.d.ts
|
|
181
173
|
/**
|
|
182
174
|
* 单仓采集产物(渲染层唯一输入;null = 该维度不可得/不适用)
|
|
183
175
|
*/
|
|
@@ -260,8 +252,6 @@ type GitInspectError = {
|
|
|
260
252
|
* @returns 成功为采集产物;健康探测失败为 INSPECT_FAILED 错误
|
|
261
253
|
*/
|
|
262
254
|
declare function inspectRepo(target: RepoTarget): Promise<Result<RepoInspection, GitInspectError>>;
|
|
263
|
-
//#endregion
|
|
264
|
-
//#region src/render/repo-document.mapper.d.ts
|
|
265
255
|
/**
|
|
266
256
|
* 渲染产物(完整文档内容 + 正文哈希)
|
|
267
257
|
*/
|
|
@@ -283,8 +273,6 @@ type RenderedDocument = {
|
|
|
283
273
|
* @returns 完整文档与正文哈希
|
|
284
274
|
*/
|
|
285
275
|
declare function renderRepoDocument(inspection: RepoInspection, generatedAt: string): RenderedDocument;
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/render/org-readme.mapper.d.ts
|
|
288
276
|
/**
|
|
289
277
|
* 渲染组织索引 README(组织概览 + 仓库索引表;hash 仅覆盖正文)
|
|
290
278
|
*
|
|
@@ -294,8 +282,6 @@ declare function renderRepoDocument(inspection: RepoInspection, generatedAt: str
|
|
|
294
282
|
* @returns 完整 README 文档与正文哈希
|
|
295
283
|
*/
|
|
296
284
|
declare function renderOrgReadme(org: string, inspections: readonly RepoInspection[], generatedAt: string): RenderedDocument;
|
|
297
|
-
//#endregion
|
|
298
|
-
//#region src/render/catalog.mapper.d.ts
|
|
299
285
|
/**
|
|
300
286
|
* 归档子文件夹名(仓库数据唯一归档容器,root 不平铺组织数据)
|
|
301
287
|
*/
|
|
@@ -334,8 +320,6 @@ declare function parseCatalogOrgs(catalogText: string): readonly string[];
|
|
|
334
320
|
* @returns 索引库 README 全文
|
|
335
321
|
*/
|
|
336
322
|
declare function renderDataRootReadme(): string;
|
|
337
|
-
//#endregion
|
|
338
|
-
//#region src/repo/org-index.service.d.ts
|
|
339
323
|
/**
|
|
340
324
|
* 管理器构造项
|
|
341
325
|
*/
|
|
@@ -412,8 +396,6 @@ declare class OrgIndexService {
|
|
|
412
396
|
*/
|
|
413
397
|
writeOrg(org: string, inspections: readonly RepoInspection[], options?: WriteOrgOptions): Promise<OrgWriteResult>;
|
|
414
398
|
}
|
|
415
|
-
//#endregion
|
|
416
|
-
//#region src/repo/catalog.service.d.ts
|
|
417
399
|
/**
|
|
418
400
|
* 管理器构造项
|
|
419
401
|
*/
|
|
@@ -482,8 +464,6 @@ declare class CatalogService {
|
|
|
482
464
|
*/
|
|
483
465
|
check(): Promise<readonly string[]>;
|
|
484
466
|
}
|
|
485
|
-
//#endregion
|
|
486
|
-
//#region src/runtime-env.utils.d.ts
|
|
487
467
|
/**
|
|
488
468
|
* 解析命中通道
|
|
489
469
|
*/
|
|
@@ -539,8 +519,6 @@ type RuntimeEnvResult = {
|
|
|
539
519
|
* @returns 成功为合并形态运行时环境与配置文件路径;失败为可读错误
|
|
540
520
|
*/
|
|
541
521
|
declare function resolveRuntimeEnv(explicitConfigPath?: string): Promise<RuntimeEnvResult>;
|
|
542
|
-
//#endregion
|
|
543
|
-
//#region src/convert.usecase.d.ts
|
|
544
522
|
/**
|
|
545
523
|
* 转换选择器(三选一:org | repo | all)
|
|
546
524
|
*/
|
|
@@ -655,8 +633,6 @@ type ConvertError = {
|
|
|
655
633
|
* @returns 转换总报告;失败为选择器/源/目标缺失错误
|
|
656
634
|
*/
|
|
657
635
|
declare function runConvert(env: RuntimeEnv, options: ConvertOptions): Promise<Result<ConvertReport, ConvertError | CloneSourceError>>;
|
|
658
|
-
//#endregion
|
|
659
|
-
//#region src/verify.usecase.d.ts
|
|
660
636
|
/**
|
|
661
637
|
* 单文档哈希漂移
|
|
662
638
|
*/
|
|
@@ -715,5 +691,4 @@ type VerifyError = {
|
|
|
715
691
|
* @returns 体检报告;数据根缺失为错误
|
|
716
692
|
*/
|
|
717
693
|
declare function runVerify(env: RuntimeEnv): Promise<Result<VerifyReport, VerifyError>>;
|
|
718
|
-
//#endregion
|
|
719
694
|
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
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
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);
|
|
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);a.length===0?n.push({entry:r.name,reason:`NO_VALID_REPOS`}):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
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
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
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
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
|
|
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}}};
|
|
8
|
-
|
|
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/`、`favorites/`、`tracking/`、`pending/`;组织数据不平铺 root。,- `favorites/` 为手工维护的关注点收藏区(区内一切皆关注点:文件夹与文件均为关注点;仓库仅作叶子档案内链接);机制规则自持于区内专属说明文件。,- `tracking/` 为手工维护的外部仓跟踪登记区(`tracking/日期/加入记录` 形态,纯 markdown 记录);库内禁止任何 clone 与 fork;机制规则自持于 `tracking/README.md`。,- `pending/` 为手工维护的外部仓待入库暂存区(`pending/日期/暂存记录` 形态,避免入库动作被阻塞);正式入库以 `tracking/` 为唯一正本;机制规则自持于 `pending/README.md`。,- `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/`/`favorites/`/`tracking/`/`pending/`;组织目录内 `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}}};function Y(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 X(e){return a({dataRoot:e.dataRoot,gitIdentity:e.gitIdentity,rootFiles:[{path:`.gitignore`,content:`# macOS
|
|
8
|
+
.DS_Store
|
|
9
|
+
|
|
10
|
+
# 机器本地配置(.env 本地实值;配置文件入库跟踪,不忽略)
|
|
11
|
+
.env
|
|
12
|
+
`},{path:`.env.example`,content:O({title:`lzi-github-markdown 就地环境配置模板`})},{path:`README.md`,content:q()}],scan:async()=>Y(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 Z=class{dataRoot;service;constructor(e){this.dataRoot=e.dataRoot,this.service=X(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 Q(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 $(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 ee(e,t){let n=Q(t);if(!n.ok)return l(n.error);let r=F(e.clonesRoot);if(!r.ok)return l(r.error);let i=$(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);e.ok?t.push(e.value):c.push({org:e.error.org,repo:e.error.repo,message:e.error.message})}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 Z({dataRoot:e.dataRoot,gitIdentity:t.gitIdentity}).refresh(o);return g({orgs:s,skippedRepos:c,scanSkipped:r.value.skipped,catalog:u})}async function te(e){if(!b(e.dataRoot)){let t=`数据根不存在:${e.dataRoot}`;return l({code:`DATA_ROOT_MISSING`,message:t})}let t=new Z({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 ne(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{Z 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,ne as resolveRuntimeEnv,ee as runConvert,te as runVerify,F as scanClonesRoot,m as splitDocument,h as stringifyFrontmatter,g as success};
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-github-markdown/core",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Longzai Intelligence
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Longzai Intelligence GitHub Markdown 业务核心实现",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"core",
|
|
7
|
+
"github-markdown",
|
|
8
|
+
"longzai-intelligence",
|
|
9
|
+
"rendering",
|
|
10
|
+
"scanning"
|
|
11
|
+
],
|
|
5
12
|
"license": "UNLICENSED",
|
|
6
13
|
"files": [
|
|
7
14
|
"dist"
|
|
@@ -17,23 +24,17 @@
|
|
|
17
24
|
"build": "lzi-builder",
|
|
18
25
|
"build:prod": "NODE_ENV=production bun run build",
|
|
19
26
|
"prepublishOnly": "bun run build:prod",
|
|
20
|
-
"typecheck": "
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
|
|
24
|
-
"lint": "oxlint && oxfmt --check",
|
|
25
|
-
"lint:fix": "oxlint --fix && oxfmt",
|
|
27
|
+
"typecheck": "lzi-typecheck",
|
|
28
|
+
"lint": "lzi-lint lint",
|
|
29
|
+
"lint:fix": "lzi-lint fix",
|
|
26
30
|
"test": "lzi-bun-cli test",
|
|
27
31
|
"test:watch": "lzi-bun-cli test --watch",
|
|
28
32
|
"test:coverage": "lzi-bun-cli test --coverage",
|
|
29
33
|
"clean": "lzi-dev-cli clean"
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
|
-
"@longzai-intelligence-github-markdown/config": "0.0.
|
|
36
|
+
"@longzai-intelligence-github-markdown/config": "0.0.5",
|
|
33
37
|
"@longzai-intelligence-markdown/data-engine": "^0.0.1",
|
|
34
38
|
"zod": "^4.4.3"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/bun": "^1.3.14"
|
|
38
39
|
}
|
|
39
40
|
}
|