tools-cc 1.0.10 → 1.0.12

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/AGENTS.md CHANGED
@@ -1,93 +1,116 @@
1
- # tools-cc 项目上下文
1
+ # tools-cc
2
2
 
3
- ## 项目概述
3
+ CLI 工具,用于统一管理多个 AI 编程工具(iflow、claude、codebuddy、opencode、codex 等)的 skills/commands/agents/rules 配置。通过符号链接机制,避免在多个工具间重复配置。
4
4
 
5
- tools-cc 是一个 CLI 工具,用于统一管理多个 AI 编程工具(iflow、claude、codebuddy、opencode 等)的 skills/commands/agents 配置。通过符号链接机制,避免在多个工具间重复配置。
5
+ ## 快速命令
6
6
 
7
- ## 技术栈
7
+ ```bash
8
+ # 安装依赖
9
+ npm install
8
10
 
9
- - **语言**: TypeScript (ES2020, strict mode)
10
- - **CLI 框架**: Commander.js
11
- - **文件操作**: fs-extra
12
- - **终端输出**: chalk
13
- - **交互式命令**: inquirer
14
- - **测试框架**: vitest
15
- - **运行时**: Node.js (CommonJS)
11
+ # 开发模式运行
12
+ npm run dev
13
+
14
+ # 编译 TypeScript
15
+ npm run build
16
+
17
+ # 运行测试
18
+ npm run test:run
19
+ ```
16
20
 
17
21
  ## 项目结构
18
22
 
19
23
  ```
20
- tools-cc/
21
- ├── src/
22
- ├── index.ts # CLI 入口,命令注册
23
- │ ├── commands/ # CLI 命令处理器
24
- ├── config.ts # 配置管理命令
25
- ├── help.ts # 帮助信息
26
- ├── source.ts # 源管理命令
27
- │ └── use.ts # 项目使用命令
28
- ├── core/ # 核心业务逻辑
29
- │ │ ├── config.ts # 配置读写
30
- ├── manifest.ts # manifest.json 解析
31
- ├── project.ts # 项目管理
32
- ├── source.ts # 源管理
33
- │ └── symlink.ts # 符号链接创建
34
- │ ├── types/ # TypeScript 类型定义
35
- └── config.ts # 核心接口定义
36
- │ └── utils/
37
- └── path.ts # 路径常量和工具函数
38
- ├── tests/ # 测试文件
39
- │ ├── core/ # 核心模块测试
40
- │ └── fixtures/ # 测试固件
41
- └── dist/ # 编译输出
24
+ src/
25
+ ├── index.ts # CLI 入口,Commander.js 命令注册
26
+ ├── commands/ # 命令处理器
27
+ │ ├── config.ts # 配置管理命令
28
+ │ ├── source.ts # 源管理命令
29
+ │ ├── use.ts # 项目使用命令
30
+ │ ├── template.ts # 模板管理命令
31
+ ├── export.ts # 导出命令
32
+ └── help.ts # 帮助信息
33
+ ├── core/ # 核心业务逻辑
34
+ │ ├── config.ts # 配置读写
35
+ │ ├── manifest.ts # manifest.json 解析
36
+ │ ├── project.ts # 项目管理
37
+ ├── source.ts # 源管理
38
+ │ ├── symlink.ts # 符号链接创建
39
+ │ └── template.ts # 模板管理
40
+ ├── types/
41
+ └── config.ts # TypeScript 类型定义
42
+ └── utils/
43
+ └── path.ts # 路径工具函数
42
44
  ```
43
45
 
44
- ## 构建和运行
46
+ ## 架构设计
45
47
 
46
- ```bash
47
- # 安装依赖
48
- npm install
48
+ ### 数据流
49
49
 
50
- # 开发模式运行
51
- npm run dev
50
+ 1. **全局配置** (`~/.tools-cc/config.json`) → 存储配置源位置和源列表
51
+ 2. **源存储** (`~/.tools-cc/sources/`) → 存储克隆/引用的配置源
52
+ 3. **项目配置** (`项目/.toolscc/config.json`) → 记录项目中启用的源和选择
52
53
 
53
- # 编译 TypeScript
54
- npm run build
54
+ ### 核心模块
55
55
 
56
- # 运行编译后的代码
57
- npm start
56
+ - **config**: 读写全局配置,管理 sourcesDir
57
+ - **source**: 添加/移除/更新配置源,支持 git clone 和本地路径
58
+ - **project**: 项目初始化,使用/移除源,符号链接管理
59
+ - **manifest**: 解析源的 manifest.json,支持自动扫描目录结构
60
+ - **template**: 模板保存和应用
58
61
 
59
- # 运行测试
60
- npm test
62
+ ### 配置文件
61
63
 
62
- # 运行测试(单次)
63
- npm run test:run
64
+ | 作用域 | 路径 | 说明 |
65
+ |--------|------|------|
66
+ | 全局 | `~/.tools-cc/config.json` | 源目录和源列表 |
67
+ | 项目 | `.toolscc/config.json` | 启用的源和链接 |
68
+ | 模板 | `~/.tools-cc/templates/` | 保存的项目配置 |
69
+
70
+ ## 命令速查
64
71
 
65
- # 全局安装(开发)
66
- npm link
72
+ ### 源管理 (全局)
73
+
74
+ ```bash
75
+ tools-cc -s add <name> <path-or-url> # 添加源
76
+ tools-cc -s list # 列出源
77
+ tools-cc -s remove <name> # 移除源
78
+ tools-cc -s update [name] # git pull 更新
79
+ tools-cc -s scan # 扫描目录发现源
67
80
  ```
68
81
 
69
- ## 核心命令
82
+ ### 项目命令
70
83
 
71
- ### 全局配置源管理
72
- - `tools-cc -s add <name> <path-or-url>` - 添加配置源
73
- - `tools-cc -s list` - 列出所有配置源
74
- - `tools-cc -s remove <name>` - 移除配置源
75
- - `tools-cc -s update [name]` - git pull 更新源代码
76
- - `tools-cc -s scan` - 扫描目录发现新源
84
+ ```bash
85
+ tools-cc use [sources...] # 启用源(支持部分导入)
86
+ tools-cc use my-skills -p iflow claude # 指定工具链接
87
+ tools-cc use source:skills/xxx # 部分导入
88
+ tools-cc use -c config.json # 从文件导入
89
+ tools-cc update [sources...] # 同步源内容
90
+ tools-cc list # 列出已启用源
91
+ tools-cc rm <source> # 移除源
92
+ tools-cc status # 查看项目状态
93
+ ```
77
94
 
78
- ### 项目配置
79
- - `tools-cc use [sources...] [-p tools...]` - 启用配置源并创建符号链接
80
- - `tools-cc update [sources...]` - 同步源内容到项目
81
- - `tools-cc list` - 列出已启用的配置源
82
- - `tools-cc rm <source>` - 禁用配置源
83
- - `tools-cc status` - 查看项目状态
95
+ ### 模板命令
84
96
 
85
- ### 配置管理
86
- - `tools-cc config set <key> <value>` - 设置配置
87
- - `tools-cc config get <key>` - 获取配置
88
- - `tools-cc config list` - 查看完整配置
97
+ ```bash
98
+ tools-cc template save [-n <name>] # 保存为模板
99
+ tools-cc template list # 列出模板
100
+ tools-cc template rm <name> # 删除模板
101
+ tools-cc template use [name] # 应用模板
102
+ tools-cc template use -p iflow # 应用并指定工具
103
+ ```
89
104
 
90
- ## 支持的 AI 工具
105
+ ### 配置命令
106
+
107
+ ```bash
108
+ tools-cc -c set <key> <value> # 设置配置
109
+ tools-cc -c get <key> # 获取配置
110
+ tools-cc config list # 查看全局配置
111
+ ```
112
+
113
+ ## 支持的工具
91
114
 
92
115
  | 工具 | 链接名称 |
93
116
  |------|----------|
@@ -95,14 +118,10 @@ npm link
95
118
  | claude | `.claude` |
96
119
  | codebuddy | `.codebuddy` |
97
120
  | opencode | `.opencode` |
121
+ | codex | `.codex` |
122
+ | qoder | `.qoder` |
98
123
 
99
- ## 配置文件位置
100
-
101
- - **全局配置**: `~/.tools-cc/config.json`
102
- - **项目配置**: `项目/.toolscc/config.json`
103
- - **源存储目录**: `~/.tools-cc/sources`(可配置)
104
-
105
- ## 核心类型
124
+ ## 类型定义
106
125
 
107
126
  ```typescript
108
127
  // 源配置
@@ -112,53 +131,42 @@ interface SourceConfig {
112
131
  path?: string;
113
132
  }
114
133
 
115
- // 全局配置
116
- interface GlobalConfig {
117
- sourcesDir: string;
118
- sources: Record<string, SourceConfig>;
134
+ // 源选择配置
135
+ interface SourceSelection {
136
+ skills: string[]; // ['*'] 或 ['skill-a', 'skill-b']
137
+ commands: string[];
138
+ agents: string[];
139
+ rules: string[];
119
140
  }
120
141
 
121
142
  // 项目配置
122
143
  interface ProjectConfig {
123
- sources: string[];
144
+ sources: Record<string, SourceSelection>;
124
145
  links: string[];
125
146
  }
126
147
 
127
- // Manifest 文件
148
+ // Manifest
128
149
  interface Manifest {
129
150
  name: string;
130
151
  version: string;
131
152
  skills?: string[];
132
153
  commands?: string[];
133
154
  agents?: string[];
155
+ rules?: string[];
134
156
  }
135
157
  ```
136
158
 
137
159
  ## 开发约定
138
160
 
139
- ### 代码风格
140
- - 使用 TypeScript strict 模式
141
- - 异步函数使用 async/await
142
- - 文件操作使用 fs-extra
143
- - 命令处理函数命名:`handle*`
144
-
145
- ### 测试
146
- - 测试文件放在 `tests/` 目录,镜像 `src/` 结构
147
- - 使用 vitest 框架
148
- - 测试固件放在 `tests/fixtures/`
149
-
150
- ### 命令添加
151
- 1. 在 `src/commands/` 创建或修改命令处理文件
152
- 2. 在 `src/index.ts` 注册新命令
153
- 3. 添加相应的测试
154
-
155
- ### 文档更新 [CHANGELOG.md](CHANGELOG.md)[README.md](README.md)
156
- - 更新文档时,请确保命令描述清晰、准确,并使用一致的格式
157
- - 添加新命令时,请更新命令列表和描述
158
- - 修改现有命令时,请更新相关命令的描述
161
+ - **TypeScript**: ES2020 target, CommonJS, strict mode
162
+ - **异步**: 使用 async/await
163
+ - **文件操作**: fs-extra
164
+ - **CLI**: Commander.js
165
+ - **测试**: vitest
166
+ - **命令处理**: `handle*` 命名约定
159
167
 
160
168
  ## 注意事项
161
169
 
162
- - 此项目运行在 Windows 系统,注意路径分隔符兼容性
163
- - 符号链接在 Windows 上可能需要管理员权限
164
- - 全局配置目录位于用户主目录下的 `.tools-cc`
170
+ - 运行在 Windows,注意路径分隔符兼容性
171
+ - Windows 上使用 junction 创建符号链接(不需要管理员权限)
172
+ - 全局配置目录: `~/.tools-cc`
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  本项目的所有重要变更都将记录在此文件中。
4
4
 
5
+ ## [1.0.12] - 2026-03-23
6
+
7
+ ### Added
8
+ - 添加 npm 包版本发布使用指南文档 (RELEASING.md)
9
+
10
+ ## [1.0.11] - 2026-03-06
11
+
12
+ ### Changed
13
+ - 完善项目配置的默认值和字段规范化
14
+
5
15
  ## [1.0.10] - 2026-03-05
6
16
 
7
17
  ### Added
package/CHANGELOG_en.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.0.11] - 2026-03-06
6
+
7
+ ### Changed
8
+ - Improved default values and field normalization for project configuration
9
+
5
10
  ## [1.0.10] - 2026-03-05
6
11
 
7
12
  ### Added
@@ -24,7 +24,8 @@ const SUPPORTED_TOOLS = {
24
24
  claude: '.claude',
25
25
  codebuddy: '.codebuddy',
26
26
  opencode: '.opencode',
27
- codex: '.codex'
27
+ codex: '.codex',
28
+ qoder: '.qoder'
28
29
  };
29
30
  /**
30
31
  * 处理 use 命令
@@ -37,6 +37,7 @@ export declare function isSourceSelection(value: unknown): value is SourceSelect
37
37
  /**
38
38
  * 将旧版项目配置转换为新版格式
39
39
  * 如果 sources 是字符串数组,转换为 Record 格式,每个源默认导入全部内容
40
+ * 同时确保所有 SourceSelection 对象字段完整
40
41
  */
41
42
  export declare function normalizeProjectConfig(config: LegacyProjectConfig | ProjectConfig): ProjectConfig;
42
43
  export interface Manifest {
@@ -14,23 +14,44 @@ function isSourceSelection(value) {
14
14
  Array.isArray(obj.agents) &&
15
15
  Array.isArray(obj.rules));
16
16
  }
17
+ /**
18
+ * 默认选择配置 - 导入所有内容
19
+ */
20
+ const DEFAULT_SOURCE_SELECTION = {
21
+ skills: ['*'],
22
+ commands: ['*'],
23
+ agents: ['*'],
24
+ rules: ['*']
25
+ };
26
+ /**
27
+ * 确保 SourceSelection 对象字段完整
28
+ */
29
+ function normalizeSourceSelection(selection) {
30
+ return {
31
+ skills: selection?.skills ?? DEFAULT_SOURCE_SELECTION.skills,
32
+ commands: selection?.commands ?? DEFAULT_SOURCE_SELECTION.commands,
33
+ agents: selection?.agents ?? DEFAULT_SOURCE_SELECTION.agents,
34
+ rules: selection?.rules ?? DEFAULT_SOURCE_SELECTION.rules
35
+ };
36
+ }
17
37
  /**
18
38
  * 将旧版项目配置转换为新版格式
19
39
  * 如果 sources 是字符串数组,转换为 Record 格式,每个源默认导入全部内容
40
+ * 同时确保所有 SourceSelection 对象字段完整
20
41
  */
21
42
  function normalizeProjectConfig(config) {
22
43
  // If sources is an array, convert to new format
23
44
  if (Array.isArray(config.sources)) {
24
45
  const newSources = {};
25
46
  for (const sourceName of config.sources) {
26
- newSources[sourceName] = {
27
- skills: ['*'],
28
- commands: ['*'],
29
- agents: ['*'],
30
- rules: ['*']
31
- };
47
+ newSources[sourceName] = { ...DEFAULT_SOURCE_SELECTION };
32
48
  }
33
49
  return { sources: newSources, links: config.links };
34
50
  }
35
- return config;
51
+ // If sources is an object, ensure all SourceSelection fields are complete
52
+ const normalizedSources = {};
53
+ for (const [sourceName, selection] of Object.entries(config.sources)) {
54
+ normalizedSources[sourceName] = normalizeSourceSelection(selection);
55
+ }
56
+ return { sources: normalizedSources, links: config.links };
36
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tools-cc",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "tools-cc [options] <command> [args]",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -0,0 +1,217 @@
1
+ ---
2
+ name: releasing
3
+ description: Use when preparing a new version release for npm packages with GitHub releases. Handles version bump, changelog updates, git tags, npm publish, and GitHub release creation.
4
+ ---
5
+
6
+ # Releasing
7
+
8
+ ## Overview
9
+
10
+ 版本发布助手,自动化 npm 包发布流程:版本号更新 → 文档同步 → Git Tag → GitHub Release → 提醒用户 npm 发布。
11
+
12
+ **核心原则:每个步骤必须验证成功,失败立即停止。**
13
+
14
+ ## When to Use
15
+
16
+ - 准备发布新版本时
17
+ - 需要更新 CHANGELOG 时
18
+ - 需要 npm publish 时
19
+ - 需要 GitHub release 时
20
+
21
+ **NOT for:**
22
+ - Hot fix 紧急修复(需要特殊流程)
23
+ - 私有包发布
24
+ - 非 npm 项目
25
+
26
+ ## Release Workflow
27
+
28
+ ```dot
29
+ digraph release {
30
+ rankdir=TB;
31
+
32
+ "Start" [shape=ellipse];
33
+ "Git Status Clean?" [shape=diamond];
34
+ "Tests Pass?" [shape=diamond];
35
+ "Choose Version" [shape=box];
36
+ "Update package.json" [shape=box];
37
+ "Update CHANGELOG" [shape=box];
38
+ "Update README" [shape=box];
39
+ "Build" [shape=box];
40
+ "Git Commit" [shape=box];
41
+ "Git Pull" [shape=box];
42
+ "Git Tag" [shape=box];
43
+ "Push Tag" [shape=box];
44
+ "gh release" [shape=box];
45
+ "Done (remind npm publish)" [shape=ellipse];
46
+ "STOP: Fix Issues" [shape=box style=filled fillcolor=red];
47
+
48
+ "Start" -> "Git Status Clean?";
49
+ "Git Status Clean?" -> "Tests Pass?" [label="yes"];
50
+ "Git Status Clean?" -> "STOP: Fix Issues" [label="no"];
51
+ "Tests Pass?" -> "Choose Version" [label="yes"];
52
+ "Tests Pass?" -> "STOP: Fix Issues" [label="no"];
53
+ "Choose Version" -> "Update package.json";
54
+ "Update package.json" -> "Update CHANGELOG";
55
+ "Update CHANGELOG" -> "Update README";
56
+ "Update README" -> "Build";
57
+ "Build" -> "Git Commit";
58
+ "Git Commit" -> "Git Pull";
59
+ "Git Pull" -> "Git Tag";
60
+ "Git Tag" -> "Push Tag";
61
+ "Push Tag" -> "gh release";
62
+ "gh release" -> "Done (remind npm publish)";
63
+ }
64
+ ```
65
+
66
+ ## Version Selection
67
+
68
+ | Type | Example | When to Use |
69
+ |------|---------|-------------|
70
+ | major | 1.0.0 → 2.0.0 | Breaking changes, incompatible API |
71
+ | minor | 1.0.0 → 1.1.0 | New features, backwards compatible |
72
+ | patch | 1.0.0 → 1.0.1 | Bug fixes, backwards compatible |
73
+
74
+ ## Step Details
75
+
76
+ ### 1. Pre-flight Checks
77
+
78
+ **MUST verify before starting:**
79
+
80
+ ```bash
81
+ # 检查 git 状态
82
+ git status --porcelain
83
+ # 如果有输出,必须先处理
84
+
85
+ # 检查测试
86
+ npm test
87
+ # 必须全部通过
88
+ ```
89
+
90
+ ### 2. Version Bump
91
+
92
+ ```bash
93
+ # 方式一:npm version 命令(自动 git commit + tag)
94
+ npm version patch|minor|major
95
+
96
+ # 方式二:手动更新 package.json(需要手动 commit)
97
+ # 编辑 package.json 中的 version 字段
98
+ ```
99
+
100
+ ### 3. Update CHANGELOG
101
+
102
+ 添加新版本条目到 CHANGELOG.md 和 CHANGELOG_en.md:
103
+
104
+ ```markdown
105
+ ## [X.Y.Z] - YYYY-MM-DD
106
+
107
+ ### Added
108
+ - 新增功能描述
109
+
110
+ ### Changed
111
+ - 变更描述
112
+
113
+ ### Fixed
114
+ - 修复描述
115
+ ```
116
+
117
+ ### 4. Update README
118
+
119
+ 检查 README.md 和 README_en.md 中是否有版本相关内容需要更新:
120
+ - 安装命令中的版本号
121
+ - 更新日志链接
122
+ - 其他版本引用
123
+
124
+ ### 5. Build & Commit
125
+
126
+ ```bash
127
+ npm run build
128
+ git add .
129
+ git commit -m "chore: release v$VERSION"
130
+ ```
131
+
132
+ ### 6. Sync & Tag
133
+
134
+ ```bash
135
+ # 先 pull 最新代码
136
+ git pull
137
+
138
+ # 创建 tag
139
+ git tag v$VERSION
140
+
141
+ # push commit 和 tag(使用实际分支名,如 master/main)
142
+ git push github <branch>
143
+ git push github v$VERSION
144
+ ```
145
+
146
+ ### 7. GitHub Release
147
+
148
+ ```bash
149
+ gh release create v$VERSION --title v$VERSION --generate-notes
150
+ ```
151
+
152
+ ### 8. npm Publish (最后提醒用户)
153
+
154
+ **完成所有自动化步骤后,在最终消息中提醒用户手动执行 npm publish。**
155
+
156
+ **不要使用 ask_user_question 工具询问,直接在完成消息中提示即可。**
157
+
158
+ 提示格式:
159
+ ```
160
+ **发布完成!请手动执行 `npm publish` 完成 npm 发布。**
161
+ ```
162
+
163
+ **用户执行前确认:**
164
+ - 已登录 npm (`npm whoami`)
165
+ - 有发布权限
166
+ - 网络连接正常
167
+
168
+ ## Common Mistakes
169
+
170
+ | Mistake | Consequence | Prevention |
171
+ |---------|-------------|------------|
172
+ | 跳过 git status 检查 | 发布错误代码 | 必须检查,有输出就停止 |
173
+ | 跳过测试 | 发布有 bug 的版本 | 测试必须通过 |
174
+ | 忘记更新 CHANGELOG | 用户不知道变更内容 | 更新后必须验证格式 |
175
+ | 忘记 build | 发布旧代码 | build 后检查 dist 目录 |
176
+ | 忘记 git pull | tag 冲突或覆盖他人提交 | 创建 tag 前必须 pull |
177
+ | 先 npm publish 再 tag/gh release | 无法回退 | 严格遵守顺序:先 tag 和 gh release,最后提醒 npm publish |
178
+ | 版本号格式错误 | tag 创建失败 | 使用 semver 格式 |
179
+
180
+ ## Red Flags - STOP and Fix
181
+
182
+ - 有未提交的更改
183
+ - 测试失败
184
+ - CHANGELOG 未更新
185
+ - 版本号已存在
186
+ - npm 未登录
187
+ - 网络连接问题
188
+
189
+ **任何步骤失败,立即停止,不要继续。**
190
+
191
+ ## Rationalization Table
192
+
193
+ | Excuse | Reality |
194
+ |--------|---------|
195
+ | "测试之前跑过,肯定没问题" | 代码变了,测试必须重跑 |
196
+ | "简单版本,不需要更新 CHANGELOG" | 用户需要知道变更内容 |
197
+ | "先发布再说,文档后面补" | 忘记补的概率 99% |
198
+ | "跳过 pull,本地肯定是最新的" | 远程可能有其他提交 |
199
+ | "手动测试过了,不需要跑测试" | 手动测试覆盖不全 |
200
+ | "npm version 命令会自动处理" | 不会自动更新 CHANGELOG/README |
201
+ | "先 npm publish,tag 后面补" | 发布失败无法回退,顺序应为 tag → gh release → npm publish |
202
+
203
+ ## Quick Reference
204
+
205
+ ```bash
206
+ # 完整发布流程
207
+ git status --porcelain # 1. 检查状态
208
+ npm test # 2. 运行测试
209
+ # 更新版本号、CHANGELOG、README
210
+ npm run build # 3. 构建
211
+ git add . && git commit -m "chore: release vX.Y.Z"
212
+ git pull # 4. 同步远程
213
+ git tag vX.Y.Z # 5. 创建 tag
214
+ git push github master && git push github vX.Y.Z
215
+ gh release create vX.Y.Z --title vX.Y.Z --generate-notes # 6. GitHub release
216
+ # 7. 在完成消息中提醒用户: 请手动执行 npm publish
217
+ ```
@@ -16,7 +16,8 @@ const SUPPORTED_TOOLS: Record<string, string> = {
16
16
  claude: '.claude',
17
17
  codebuddy: '.codebuddy',
18
18
  opencode: '.opencode',
19
- codex: '.codex'
19
+ codex: '.codex',
20
+ qoder: '.qoder'
20
21
  };
21
22
 
22
23
  /**
@@ -49,9 +49,32 @@ export function isSourceSelection(value: unknown): value is SourceSelection {
49
49
  );
50
50
  }
51
51
 
52
+ /**
53
+ * 默认选择配置 - 导入所有内容
54
+ */
55
+ const DEFAULT_SOURCE_SELECTION: SourceSelection = {
56
+ skills: ['*'],
57
+ commands: ['*'],
58
+ agents: ['*'],
59
+ rules: ['*']
60
+ };
61
+
62
+ /**
63
+ * 确保 SourceSelection 对象字段完整
64
+ */
65
+ function normalizeSourceSelection(selection: Partial<SourceSelection> | undefined): SourceSelection {
66
+ return {
67
+ skills: selection?.skills ?? DEFAULT_SOURCE_SELECTION.skills,
68
+ commands: selection?.commands ?? DEFAULT_SOURCE_SELECTION.commands,
69
+ agents: selection?.agents ?? DEFAULT_SOURCE_SELECTION.agents,
70
+ rules: selection?.rules ?? DEFAULT_SOURCE_SELECTION.rules
71
+ };
72
+ }
73
+
52
74
  /**
53
75
  * 将旧版项目配置转换为新版格式
54
76
  * 如果 sources 是字符串数组,转换为 Record 格式,每个源默认导入全部内容
77
+ * 同时确保所有 SourceSelection 对象字段完整
55
78
  */
56
79
  export function normalizeProjectConfig(
57
80
  config: LegacyProjectConfig | ProjectConfig
@@ -60,16 +83,18 @@ export function normalizeProjectConfig(
60
83
  if (Array.isArray(config.sources)) {
61
84
  const newSources: Record<string, SourceSelection> = {};
62
85
  for (const sourceName of config.sources) {
63
- newSources[sourceName] = {
64
- skills: ['*'],
65
- commands: ['*'],
66
- agents: ['*'],
67
- rules: ['*']
68
- };
86
+ newSources[sourceName] = { ...DEFAULT_SOURCE_SELECTION };
69
87
  }
70
88
  return { sources: newSources, links: config.links };
71
89
  }
72
- return config as ProjectConfig;
90
+
91
+ // If sources is an object, ensure all SourceSelection fields are complete
92
+ const normalizedSources: Record<string, SourceSelection> = {};
93
+ for (const [sourceName, selection] of Object.entries(config.sources as Record<string, Partial<SourceSelection>>)) {
94
+ normalizedSources[sourceName] = normalizeSourceSelection(selection);
95
+ }
96
+
97
+ return { sources: normalizedSources, links: config.links };
73
98
  }
74
99
 
75
100
  export interface Manifest {