@longzai-intelligence-paper-report/config 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # 更新日志
2
+
3
+ 本项目的所有重要更改都将记录在此文件中。
4
+
5
+ 格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
6
+ 本项目遵循 [语义化版本](https://semver.org/lang-zh-CN/)。
7
+
8
+ ## [0.0.1] - 2026-10-23
9
+
10
+ ### 变更
11
+
12
+ - 升级 @longzai-intelligence-paper-report/config 至 0.0.1
@@ -0,0 +1,81 @@
1
+ import * as z from "zod";
2
+ import { ConfigLoadErr, ConfigLoadError, ConfigLoadOk, ConfigLoadResult, ConfigLoadResult as ConfigLoadResult$1 } from "@longzai-intelligence-shared-config/core";
3
+ /**
4
+ * 配置结构
5
+ */
6
+ declare const PaperReportConfigSchema: z.ZodObject<{
7
+ dataRoot: z.ZodDefault<z.ZodString>;
8
+ paperId: z.ZodString;
9
+ }, z.core.$strip>;
10
+ /**
11
+ * 配置类型
12
+ *
13
+ * @remarks
14
+ * schema 推断形态,`paperId` 未带版本后缀时以最新版为准
15
+ */
16
+ type PaperReportConfig = z.infer<typeof PaperReportConfigSchema>;
17
+ /**
18
+ * 配置工厂
19
+ *
20
+ * @remarks
21
+ * 类型收口用 identity 语义,运行时校验由加载方执行,导出名统一为
22
+ * `defineConfig`,全局 ADR 0097 决策 2,禁域前缀工厂名
23
+ * @param config - 就地配置取值
24
+ * @returns 原样返回的配置对象
25
+ */
26
+ declare function defineConfig(config: PaperReportConfig): PaperReportConfig;
27
+ /**
28
+ * 配置文件约定名
29
+ *
30
+ * @remarks
31
+ * 以工具命名,全局 ADR 0090,与 bin 名及 env 前缀三同源
32
+ */
33
+ declare const CONFIG_FILENAME = "lzi-paper-report.config.ts";
34
+ /**
35
+ * 自 cwd 向上查找配置文件
36
+ *
37
+ * @param explicitPath - 显式指定的配置文件路径,可空
38
+ * @returns 命中的绝对路径,未命中为 undefined
39
+ */
40
+ declare function discoverConfigPath(explicitPath?: string): string | undefined;
41
+ /**
42
+ * 加载并校验配置
43
+ *
44
+ * @remarks
45
+ * 相对路径以配置文件所在目录为基准绝对化
46
+ * @param explicitPath - 显式指定的配置文件路径,可空,缺省走向上发现
47
+ * @returns 成功为绝对路径形态配置与文件路径,失败为可读错误
48
+ */
49
+ declare function loadPaperReportConfig(explicitPath?: string): Promise<ConfigLoadResult$1<PaperReportConfig>>;
50
+ /**
51
+ * 配置骨架生成
52
+ *
53
+ * `config init` 用,`defineConfig` 工厂导出形态,全局 ADR 0097 决策 2,裸对象过渡
54
+ * 形态废止,禁 `version` 字段,代际由包 npm 版本承载,骨架依赖目标目录已安装
55
+ * config 包,依赖就绪门沿 ADR 0100 先例,本模块自持文本生成,域形态不走引擎
56
+ * `ScaffoldTemplate`,非引擎能力分叉
57
+ */
58
+ /**
59
+ * 骨架入参
60
+ */
61
+ type ScaffoldParams = {
62
+ /**
63
+ * 数据根
64
+ *
65
+ * @remarks
66
+ * 缺省 `.` 即就地自指
67
+ */
68
+ readonly dataRoot?: string;
69
+ /**
70
+ * arXiv 论文编号
71
+ */
72
+ readonly paperId?: string;
73
+ };
74
+ /**
75
+ * 生成配置骨架文本
76
+ *
77
+ * @param params - 骨架入参
78
+ * @returns 就地配置全文
79
+ */
80
+ declare function scaffoldConfigText(params?: ScaffoldParams): string;
81
+ export { CONFIG_FILENAME, type ConfigLoadErr, type ConfigLoadError, type ConfigLoadOk, type ConfigLoadResult, PaperReportConfig, PaperReportConfigSchema, ScaffoldParams, defineConfig, discoverConfigPath, loadPaperReportConfig, scaffoldConfigText };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import*as e from"zod";import{createDomainConfigLoader as t}from"@longzai-intelligence-shared-config/core";import{resolve as n}from"node:path";const r=e.object({dataRoot:e.string().min(1).default(`.`),paperId:e.string().regex(/^\d{4}\.\d{4,5}(v\d+)?$/,{message:`论文编号须为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀`})});function i(e){return e}const a=`lzi-paper-report.config.ts`,o=()=>t({configFilename:a,schema:r,shapeHint:`defineConfig 收口的 dataRoot 加 paperId,禁 version 字段,代际由包 npm 版本承载`,absolutize:(e,t)=>({...e,dataRoot:n(t,e.dataRoot)})});function s(e){return o().discoverConfigPath(e)}async function c(e){return o().loadConfig(e)}function l(e={}){let t=[];return e.dataRoot!==void 0&&e.dataRoot!==`.`&&t.push(`dataRoot: '${e.dataRoot}'`),e.paperId!==void 0&&t.push(`paperId: '${e.paperId}'`),[`// lzi-paper-report 就地配置,以工具命名,全局 ADR 0090,defineConfig 工厂收口,全局 ADR 0097 决策 2`,`// 相对路径以本文件所在目录为基准,放在数据根时工厂默认 dataRoot 为点号,零参调用即可`,`// 论文编号为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀`,`import { defineConfig } from '@longzai-intelligence-paper-report/config';`,``,t.length===0?`export default defineConfig();`:`export default defineConfig({ ${t.join(`, `)} });`,``].join(`
2
+ `)}export{a as CONFIG_FILENAME,r as PaperReportConfigSchema,i as defineConfig,s as discoverConfigPath,c as loadPaperReportConfig,l as scaffoldConfigText};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * tsdown 构建配置
3
+ *
4
+ * 生产构建配置(单入口,使用默认配置),`@/` 别名由 tsconfig 承载,构建链原生
5
+ * 解析,构建侧零别名声明
6
+ */
7
+ import { defineConfig } from '@longzai-intelligence-builder/esm';
8
+
9
+ export default defineConfig();
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from '@longzai-intelligence-dev-tools/config';
2
+
3
+ export default defineConfig({
4
+ clean: {
5
+ plugins: ['turbo', 'tsgo'],
6
+ },
7
+ });
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from '@longzai-intelligence-oxlint/presets/library';
2
+
3
+ export default defineConfig();
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-paper-report/config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "description": "Longzai Intelligence 配置包",
5
+ "keywords": [
6
+ "config",
7
+ "longzai-intelligence"
8
+ ],
9
+ "license": "UNLICENSED",
10
+ "type": "module",
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "lzi-builder",
21
+ "build:prod": "NODE_ENV=production lzi-builder",
22
+ "prepublishOnly": "bun run build:prod",
23
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
24
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
25
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
26
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
27
+ "lint": "lzi-lint lint",
28
+ "lint:fix": "lzi-lint fix",
29
+ "test": "lzi-bun-cli test",
30
+ "test:watch": "lzi-bun-cli test --watch",
31
+ "test:coverage": "lzi-bun-cli test --coverage",
32
+ "clean": "lzi-dev-cli clean"
33
+ },
34
+ "dependencies": {
35
+ "@longzai-intelligence-markdown/data-engine": "^0.0.5",
36
+ "@longzai-intelligence-shared-config/core": "^0.0.9",
37
+ "zod": "^4.6.5"
38
+ }
39
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 配置 Schema 单测:合法编号、版本后缀、旧式拒绝、dataRoot 缺省
3
+ */
4
+ import { describe, expect, it } from 'bun:test';
5
+
6
+ import { PaperReportConfigSchema } from '@/domain-config.schema';
7
+
8
+ describe('PaperReportConfigSchema', () => {
9
+ it('新式编号合法且 dataRoot 缺省为点号', () => {
10
+ const parsed = PaperReportConfigSchema.safeParse({ paperId: '2609.22068' });
11
+
12
+ expect(parsed.success).toBe(true);
13
+ if (parsed.success) {
14
+ expect(parsed.data.dataRoot).toBe('.');
15
+ expect(parsed.data.paperId).toBe('2609.22068');
16
+ }
17
+ });
18
+
19
+ it('带版本后缀的编号合法', () => {
20
+ const parsed = PaperReportConfigSchema.safeParse({ paperId: '2609.22068v1' });
21
+
22
+ expect(parsed.success).toBe(true);
23
+ if (parsed.success) {
24
+ expect(parsed.data.paperId).toBe('2609.22068v1');
25
+ }
26
+ });
27
+
28
+ it('旧式斜杠编号拒绝', () => {
29
+ expect(PaperReportConfigSchema.safeParse({ paperId: 'cs/0301012' }).success).toBe(false);
30
+ });
31
+
32
+ it('空编号拒绝', () => {
33
+ expect(PaperReportConfigSchema.safeParse({ paperId: '' }).success).toBe(false);
34
+ });
35
+ });
@@ -0,0 +1,155 @@
1
+ /**
2
+ * 配置加载器与骨架单测:显式路径、向上发现、相对路径绝对化、非法导出、骨架形态
3
+ */
4
+ import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
5
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
6
+ import { tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+
9
+ import { CONFIG_FILENAME, discoverConfigPath, loadPaperReportConfig } from '@/loader.utils';
10
+ import { scaffoldConfigText } from '@/scaffold.utils';
11
+
12
+ /**
13
+ * 临时工作区
14
+ */
15
+ let workspace: string;
16
+
17
+ beforeAll(() => {
18
+ workspace = mkdtempSync(join(tmpdir(), 'lzi-paper-report-config-'));
19
+ });
20
+
21
+ afterAll(() => {
22
+ rmSync(workspace, { recursive: true, force: true });
23
+ });
24
+
25
+ /**
26
+ * 在临时工作区写一份合法配置文件
27
+ *
28
+ * @returns 配置文件绝对路径
29
+ */
30
+ function writeValidConfig(): string {
31
+ /**
32
+ * 配置文件绝对路径
33
+ */
34
+ const configPath = join(workspace, CONFIG_FILENAME);
35
+
36
+ writeFileSync(configPath, "export default { dataRoot: '.', paperId: '2609.22068' };", 'utf8');
37
+
38
+ return configPath;
39
+ }
40
+
41
+ describe('discoverConfigPath', () => {
42
+ it('显式路径存在则直接采用', () => {
43
+ const configPath = writeValidConfig();
44
+
45
+ expect(discoverConfigPath(configPath)).toBe(configPath);
46
+ });
47
+
48
+ it('显式路径不存在返回 undefined', () => {
49
+ expect(discoverConfigPath(join(workspace, 'missing.config.ts'))).toBeUndefined();
50
+ });
51
+
52
+ it('自子目录向上发现', () => {
53
+ /**
54
+ * 配置文件路径
55
+ */
56
+ const configPath = writeValidConfig();
57
+
58
+ /**
59
+ * 子目录路径
60
+ */
61
+ const subDir = join(workspace, 'sources', '2609.22068');
62
+ mkdirSync(subDir, { recursive: true });
63
+
64
+ /**
65
+ * 原工作目录
66
+ */
67
+ const originalCwd = process.cwd();
68
+ process.chdir(subDir);
69
+ try {
70
+ /**
71
+ * 实符号路径,chdir 后 cwd 已解析符号链接,期望值同基比较
72
+ */
73
+ const resolvedPath = realpathSync(configPath);
74
+
75
+ expect(discoverConfigPath()).toBe(resolvedPath);
76
+ } finally {
77
+ process.chdir(originalCwd);
78
+ }
79
+ });
80
+ });
81
+
82
+ describe('loadPaperReportConfig', () => {
83
+ it('加载并绝对化 dataRoot', async () => {
84
+ /**
85
+ * 配置文件路径
86
+ */
87
+ const configPath = writeValidConfig();
88
+
89
+ /**
90
+ * 加载结果
91
+ */
92
+ const loaded = await loadPaperReportConfig(configPath);
93
+
94
+ expect(loaded.ok).toBe(true);
95
+ if (loaded.ok) {
96
+ expect(loaded.config.dataRoot).toBe(workspace);
97
+ expect(loaded.config.paperId).toBe('2609.22068');
98
+ expect(loaded.path).toBe(configPath);
99
+ }
100
+ });
101
+
102
+ it('缺失配置文件报未找到', async () => {
103
+ /**
104
+ * 空临时目录
105
+ */
106
+ const emptyDir = mkdtempSync(join(tmpdir(), 'lzi-paper-report-empty-'));
107
+ try {
108
+ const loaded = await loadPaperReportConfig(join(emptyDir, CONFIG_FILENAME));
109
+
110
+ expect(loaded.ok).toBe(false);
111
+ if (!loaded.ok) {
112
+ expect(loaded.error.code).toBe('CONFIG_NOT_FOUND');
113
+ }
114
+ } finally {
115
+ rmSync(emptyDir, { recursive: true, force: true });
116
+ }
117
+ });
118
+
119
+ it('非法导出报结构错误', async () => {
120
+ /**
121
+ * 非法配置文件路径
122
+ */
123
+ const badPath = join(workspace, 'bad.config.ts');
124
+ writeFileSync(badPath, 'export default 42;', 'utf8');
125
+
126
+ const loaded = await loadPaperReportConfig(badPath);
127
+
128
+ expect(loaded.ok).toBe(false);
129
+ if (!loaded.ok) {
130
+ expect(loaded.error.code).toBe('CONFIG_INVALID');
131
+ }
132
+ });
133
+ });
134
+
135
+ describe('scaffoldConfigText', () => {
136
+ it('缺省形态生成零参工厂调用', () => {
137
+ /**
138
+ * 骨架文本
139
+ */
140
+ const text = scaffoldConfigText();
141
+
142
+ expect(text).toContain('export default defineConfig();');
143
+ expect(text).toContain('@longzai-intelligence-paper-report/config');
144
+ });
145
+
146
+ it('带编号形态生成对应字段', () => {
147
+ /**
148
+ * 骨架文本
149
+ */
150
+ const text = scaffoldConfigText({ paperId: '2609.22068' });
151
+
152
+ expect(text).toContain("paperId: '2609.22068'");
153
+ expect(text).not.toContain("dataRoot: '");
154
+ });
155
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * 配置 Schema
3
+ *
4
+ * `lzi-paper-report.config.ts` 结构真源,就地配置置于数据仓根,领域形态为单篇论文
5
+ * 报告仓,配置承载 `dataRoot` 与 `paperId` 双字段,论文编号仅收 arXiv 新式形态即
6
+ * `YYMM.NNNNN` 可带 `v` 版本后缀,旧式斜杠形态不收,理由见本仓 ADR 0002
7
+ */
8
+ import * as z from 'zod';
9
+
10
+ /**
11
+ * arXiv 新式论文编号模式,形如 `2609.22068` 或 `2609.22068v1`
12
+ */
13
+ const PAPER_ID_PATTERN = /^\d{4}\.\d{4,5}(v\d+)?$/;
14
+
15
+ /**
16
+ * 配置结构
17
+ */
18
+ export const PaperReportConfigSchema = z.object({
19
+ /**
20
+ * 数据根
21
+ *
22
+ * @remarks
23
+ * 相对路径以配置文件所在目录为基准,就地配置可用 `.`
24
+ * @default
25
+ */
26
+ dataRoot: z.string().min(1).default('.'),
27
+
28
+ /**
29
+ * arXiv 论文编号
30
+ *
31
+ * @remarks
32
+ * 新式形态 `YYMM.NNNNN` 可带 `v` 版本后缀,旧式斜杠形态不收
33
+ */
34
+ paperId: z.string().regex(PAPER_ID_PATTERN, {
35
+ message: '论文编号须为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀',
36
+ }),
37
+ });
38
+
39
+ /**
40
+ * 配置类型
41
+ *
42
+ * @remarks
43
+ * schema 推断形态,`paperId` 未带版本后缀时以最新版为准
44
+ */
45
+ export type PaperReportConfig = z.infer<typeof PaperReportConfigSchema>;
46
+
47
+ /**
48
+ * 配置工厂
49
+ *
50
+ * @remarks
51
+ * 类型收口用 identity 语义,运行时校验由加载方执行,导出名统一为
52
+ * `defineConfig`,全局 ADR 0097 决策 2,禁域前缀工厂名
53
+ * @param config - 就地配置取值
54
+ * @returns 原样返回的配置对象
55
+ */
56
+ export function defineConfig(config: PaperReportConfig): PaperReportConfig {
57
+ return config;
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * config 包导出面
3
+ */
4
+ export * from './domain-config.schema';
5
+
6
+ export * from './loader.utils';
7
+
8
+ export * from './scaffold.utils';
@@ -0,0 +1,75 @@
1
+ import {
2
+ type ConfigLoadResult,
3
+ createDomainConfigLoader,
4
+ } from '@longzai-intelligence-shared-config/core';
5
+
6
+ /**
7
+ * 配置文件加载器
8
+ *
9
+ * 经 shared-config 的 `createDomainConfigLoader` 声明式装配,全局 ADR 0118:查找、
10
+ * 导入、zod 校验、显式路径、绝对化与错误码统一由共享设施承载,域只声明文件名、
11
+ * schema、结构提示与绝对化语义,配置文件必备,执行全局 ADR 0097 决策 9:未找到
12
+ * 即错误,env 不作整体替代,本工具的 env 通道仅承载 LLM 凭据,见 core 包
13
+ * `env/env.schema`
14
+ */
15
+ import { resolve } from 'node:path';
16
+
17
+ import { type PaperReportConfig, PaperReportConfigSchema } from './domain-config.schema';
18
+
19
+ /**
20
+ * 配置文件约定名
21
+ *
22
+ * @remarks
23
+ * 以工具命名,全局 ADR 0090,与 bin 名及 env 前缀三同源
24
+ */
25
+ export const CONFIG_FILENAME = 'lzi-paper-report.config.ts';
26
+
27
+ /**
28
+ * 惰性构造域配置加载器
29
+ *
30
+ * @remarks
31
+ * 引擎的向上发现以构造期 cwd 为基,故按调用时点惰性构造,保证自调用方当前
32
+ * 目录向上查找,文件名、schema、结构提示、绝对化四参数装配
33
+ * @returns 域配置加载器实例
34
+ */
35
+ const buildLoader = () =>
36
+ createDomainConfigLoader<PaperReportConfig>({
37
+ configFilename: CONFIG_FILENAME,
38
+ schema: PaperReportConfigSchema,
39
+ shapeHint: 'defineConfig 收口的 dataRoot 加 paperId,禁 version 字段,代际由包 npm 版本承载',
40
+ absolutize: (config, configDir) => ({
41
+ ...config,
42
+ dataRoot: resolve(configDir, config.dataRoot),
43
+ }),
44
+ });
45
+
46
+ /**
47
+ * 自 cwd 向上查找配置文件
48
+ *
49
+ * @param explicitPath - 显式指定的配置文件路径,可空
50
+ * @returns 命中的绝对路径,未命中为 undefined
51
+ */
52
+ export function discoverConfigPath(explicitPath?: string): string | undefined {
53
+ return buildLoader().discoverConfigPath(explicitPath);
54
+ }
55
+
56
+ /**
57
+ * 加载并校验配置
58
+ *
59
+ * @remarks
60
+ * 相对路径以配置文件所在目录为基准绝对化
61
+ * @param explicitPath - 显式指定的配置文件路径,可空,缺省走向上发现
62
+ * @returns 成功为绝对路径形态配置与文件路径,失败为可读错误
63
+ */
64
+ export async function loadPaperReportConfig(
65
+ explicitPath?: string,
66
+ ): Promise<ConfigLoadResult<PaperReportConfig>> {
67
+ return buildLoader().loadConfig(explicitPath);
68
+ }
69
+
70
+ export type {
71
+ ConfigLoadError,
72
+ ConfigLoadErr,
73
+ ConfigLoadOk,
74
+ ConfigLoadResult,
75
+ } from '@longzai-intelligence-shared-config/core';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 配置骨架生成
3
+ *
4
+ * `config init` 用,`defineConfig` 工厂导出形态,全局 ADR 0097 决策 2,裸对象过渡
5
+ * 形态废止,禁 `version` 字段,代际由包 npm 版本承载,骨架依赖目标目录已安装
6
+ * config 包,依赖就绪门沿 ADR 0100 先例,本模块自持文本生成,域形态不走引擎
7
+ * `ScaffoldTemplate`,非引擎能力分叉
8
+ */
9
+
10
+ /**
11
+ * 骨架入参
12
+ */
13
+ export type ScaffoldParams = {
14
+ /**
15
+ * 数据根
16
+ *
17
+ * @remarks
18
+ * 缺省 `.` 即就地自指
19
+ */
20
+ readonly dataRoot?: string;
21
+
22
+ /**
23
+ * arXiv 论文编号
24
+ */
25
+ readonly paperId?: string;
26
+ };
27
+
28
+ /**
29
+ * 生成配置骨架文本
30
+ *
31
+ * @param params - 骨架入参
32
+ * @returns 就地配置全文
33
+ */
34
+ export function scaffoldConfigText(params: ScaffoldParams = {}): string {
35
+ /**
36
+ * 工厂入参字段序列
37
+ */
38
+ const fields: string[] = [];
39
+ if (params.dataRoot !== undefined && params.dataRoot !== '.') {
40
+ fields.push(`dataRoot: '${params.dataRoot}'`);
41
+ }
42
+ if (params.paperId !== undefined) {
43
+ fields.push(`paperId: '${params.paperId}'`);
44
+ }
45
+
46
+ /**
47
+ * 工厂调用行
48
+ */
49
+ const configCall =
50
+ fields.length === 0
51
+ ? 'export default defineConfig();'
52
+ : `export default defineConfig({ ${fields.join(', ')} });`;
53
+
54
+ return [
55
+ '// lzi-paper-report 就地配置,以工具命名,全局 ADR 0090,defineConfig 工厂收口,全局 ADR 0097 决策 2',
56
+ '// 相对路径以本文件所在目录为基准,放在数据根时工厂默认 dataRoot 为点号,零参调用即可',
57
+ '// 论文编号为 arXiv 新式形态如 2609.22068 可带 v1 版本后缀',
58
+ "import { defineConfig } from '@longzai-intelligence-paper-report/config';",
59
+ '',
60
+ configCall,
61
+ '',
62
+ ].join('\n');
63
+ }