# aero-library-core **Repository Path**: dongfangW/aero-library-core ## Basic Information - **Project Name**: aero-library-core - **Description**: 《空气动力学基础》多库清单契约:library.yaml 解析/校验/扫描/检索 - **Primary Language**: Unknown - **License**: AGPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-01 - **Last Updated**: 2026-11-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @dongfangw/library-core **内容库清单契约层。** 把一个"资料库"变成任何工具都能读的东西:一份 `library.yaml` 声明有哪些分组、怎么扫、怎么检索、对谁可见;本包负责解析、校验、扫描与过滤。 零运行时依赖(只用 Node 内置)。三套件(study / prep / sim)与内容仓都只依赖它,互不相识。 ## 30 秒 ```bash npx @dongfangw/library-core validate ./my-library # 体检一份内容库 npx @dongfangw/library-core catalog ./my-library # 打印目录树 npx @dongfangw/library-core catalog ./ws --viewer teacher ``` ```yaml # my-library/library.yaml schema: aero-library/1 id: my-notes title: 我的笔记库 kind: notes visibility: private groups: - { id: main, label: 笔记, dir: notes, exts: [md], maxDepth: 3 } ``` ## 两种模式 | 模式 | 触发条件 | 分组来源 | |---|---|---| | manifest | 库根有 `library.yaml`(或 `.json`) | 清单里的 `groups` | | legacy | 库根同时有 `textbook/` `teaching-case/` `lesson-plan/` | 内置的 11 个分组(与拆分前逐字节一致) | legacy 模式是**兼容层**:`test/fixtures/legacy-digest.json` 存着拆分前的目录树指纹, `test/legacy.test.ts` 每次都比对(学生 / 教师两个视图)。 ## 公开接口 ```ts import { buildCatalog, loadLibrary, loadWorkspace, resolveEntry, // 加载与目录树 buildLibraryCatalog, buildLegacyCatalog, // 单库 / legacy scanFiles, scanDecks, buildTreeFromFiles, flattenPaths, // 扫描原语 searchLibraries, readStatusField, tokenize, analyzeQuery, // 检索(在线全文扫) buildIndex, writeIndex, readIndex, queryIndex, // 分块索引(节 → 块) isIndexStale, workspaceFingerprint, docTitle, // 索引过期判定 / 节名提取 isInside, resolveSafe, dirExists, fileExists, // 路径 parseYamlSubset, readConfigFile, // 清单解析(YAML 子集 / JSON) } from '@dongfangw/library-core' ``` ### 检索与索引(两种粒度,别混用) | 入口 | 粒度 | 何时用 | |---|---|---| | `searchLibraries(libs, query, opts)` | 行级片段 | 永远最新(每次读全文);适合"某个词出现在哪一行" | | `buildIndex` + `queryIndex` | 块级证据(段落) | 需要"哪一节讲这个""式 C17.2-11 定义在哪";读索引,不碰正文 | `queryIndex` 的块带**行范围**而不是正文:索引才几 MB,取原文按 `path + startLine/endLine` 回文件读。索引落 `/.kb-index/kb-index.json`: ```bash aero-library index # 建/重建(默认跳过 kind: reference 的库) aero-library query "正激波 总压" --top 8 aero-library query "C17.2-11" # 式号直查 ``` 块的边界落在**小节标题**上(同级标题必断;下级标题只在当前块已够长时才断,标题与自己的正文 同块);节名取正文第一行标题(`docTitle`),取不到才退回文件名。`KbIndex.fingerprint` 记下 文件数与最新 mtime,`isIndexStale(index, workspace)` 判「要不要重建」——有正文比 `generatedAt` 新、或文件数变了,就算过期。宿主插件据此在打开资料面板时自动重建,学生不用碰 CLI。 两条纪律: 1. **索引是派生物**,永远允许回退到 `searchLibraries`——调用方不该因为"没建索引"就不可用。 2. **切词口径统一**:`tokenize` 返回**去重的词表**(不是词频),问句先过 `stripQueryNoise`; 词频自己数。多词查询按"任一切词命中"入选,`mode: 'all'` 要求全覆盖。 ### 可见性(两处,语义不同) - **库级 `visibility`**:`teacher` 的库只在教师视图出现;`private` 是学生自己的库; `public` 任何人可见(须写 `license`)。 - **分组级 `teacherOnly`**:同一个库里某些分组只给老师(如习题解答)。学生视图里换成 「(教师端内容 · 学习模式下隐藏)」占位分组 —— 与拆分前行为一致。 ### YAML 支持范围(故意不完整) 支持:`key: value`、嵌套映射、序列、行内 `[a, b]` / `{a: 1}`、引号、注释、数字/布尔/null。 **不支持**:锚点、多行块标量、标签、多文档。需要这些时写 `library.json`(JSON 也是合法 YAML)。 ## 门禁 ```bash npm test # 25 例:YAML / 路径 / 清单 / 目录树 / 检索 / legacy 黄金指纹 npm run test:node # 标准 runner(每文件一个子进程) ``` ## 许可 MIT。