@openclaw-cn/cli 1.2.3 → 1.2.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.
@@ -3,9 +3,26 @@ import path from 'path';
3
3
  import matter from 'gray-matter';
4
4
  import chalk from 'chalk';
5
5
  import ora from 'ora';
6
+ import ignore from 'ignore';
6
7
  import { getClient, formatError } from '../config.js';
7
8
  import os from 'os';
8
9
 
10
+ // 内置排除规则(始终排除)
11
+ const BUILTIN_IGNORE_RULES = [
12
+ '.git',
13
+ '.DS_Store',
14
+ 'node_modules',
15
+ '__pycache__',
16
+ '.venv',
17
+ '*.pyc',
18
+ '*.pyo',
19
+ '.env',
20
+ '.env.*',
21
+ '!.env.example',
22
+ '*.lock',
23
+ 'SKILL.md',
24
+ ];
25
+
9
26
  async function installSkill(client, skillId) {
10
27
  // 1. Get Metadata
11
28
  const res = await client.get(`/skills/${encodeURIComponent(skillId)}`);
@@ -74,8 +91,34 @@ async function installSkill(client, skillId) {
74
91
  return { installDir, version: skill.version };
75
92
  }
76
93
 
77
- // 递归收集目录下所有文件
78
- function collectFiles(dir, baseDir = dir) {
94
+ /**
95
+ * 创建 ignore 实例,加载内置规则 + .clawignore / .gitignore
96
+ */
97
+ function createIgnoreFilter(baseDir) {
98
+ const ig = ignore();
99
+
100
+ // 内置排除规则
101
+ ig.add(BUILTIN_IGNORE_RULES);
102
+
103
+ // 优先读取 .clawignore,回退 .gitignore
104
+ const clawignorePath = path.join(baseDir, '.clawignore');
105
+ const gitignorePath = path.join(baseDir, '.gitignore');
106
+
107
+ if (fs.existsSync(clawignorePath)) {
108
+ ig.add(fs.readFileSync(clawignorePath, 'utf8'));
109
+ } else if (fs.existsSync(gitignorePath)) {
110
+ ig.add(fs.readFileSync(gitignorePath, 'utf8'));
111
+ }
112
+
113
+ return ig;
114
+ }
115
+
116
+ // 递归收集目录下所有文件(支持 .clawignore 排除)
117
+ function collectFiles(dir, baseDir = dir, ig = null) {
118
+ if (!ig) {
119
+ ig = createIgnoreFilter(baseDir);
120
+ }
121
+
79
122
  const files = {};
80
123
  const entries = fs.readdirSync(dir, { withFileTypes: true });
81
124
 
@@ -83,13 +126,13 @@ function collectFiles(dir, baseDir = dir) {
83
126
  const fullPath = path.join(dir, entry.name);
84
127
  const relativePath = path.relative(baseDir, fullPath);
85
128
 
86
- // 跳过隐藏文件、node_modules、.git
87
- if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === '__pycache__') {
129
+ // 使用 ignore 规则判断是否排除
130
+ if (ig.ignores(relativePath)) {
88
131
  continue;
89
132
  }
90
133
 
91
134
  if (entry.isDirectory()) {
92
- Object.assign(files, collectFiles(fullPath, baseDir));
135
+ Object.assign(files, collectFiles(fullPath, baseDir, ig));
93
136
  } else {
94
137
  // 跳过二进制文件和过大的文件
95
138
  const ext = path.extname(entry.name).toLowerCase();
@@ -150,10 +193,17 @@ export default function(program) {
150
193
  .replace(/^-|-$/g, '')
151
194
  .toLowerCase() || 'skill';
152
195
 
153
- // 收集目录下所有文件
196
+ // 收集目录下所有文件(应用 .clawignore 排除规则)
154
197
  spinner.text = 'Collecting files...';
155
198
  const files = collectFiles(process.cwd());
156
199
 
200
+ // README.md 优先作为技能介绍,回退到 SKILL.md 正文
201
+ let readmeContent = content;
202
+ const readmeMdPath = path.join(process.cwd(), 'README.md');
203
+ if (fs.existsSync(readmeMdPath)) {
204
+ readmeContent = fs.readFileSync(readmeMdPath, 'utf8');
205
+ }
206
+
157
207
  spinner.text = 'Publishing to OpenClaw...';
158
208
 
159
209
  const client = getClient();
@@ -164,7 +214,7 @@ export default function(program) {
164
214
  version: data.version,
165
215
  icon: icon,
166
216
  metadata: JSON.stringify(metadata), // Send as JSON string
167
- readme: content,
217
+ readme: readmeContent,
168
218
  files: JSON.stringify(files)
169
219
  });
170
220
 
package/lib/config.js CHANGED
@@ -33,7 +33,7 @@ export const getClient = () => {
33
33
  return axios.create({
34
34
  baseURL: getApiUrl(),
35
35
  timeout: 30000, // 30s timeout
36
- maxBodyLength: 100 * 1024, // 100KB max request body
36
+ maxBodyLength: 5 * 1024 * 1024, // 5MB max request body
37
37
  headers: token ? { Authorization: `Bearer ${token}` } : {}
38
38
  });
39
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw-cn/cli",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "The official CLI for OpenClaw-CN Agent ecosystem",
5
5
  "bin": {
6
6
  "claw": "./bin/claw.js"
@@ -17,6 +17,7 @@
17
17
  "gray-matter": "^4.0.3",
18
18
  "inquirer": "^9.2.12",
19
19
  "marked": "^11.1.1",
20
+ "ignore": "^6.0.2",
20
21
  "marked-terminal": "^6.1.0",
21
22
  "ora": "^8.0.1"
22
23
  }