istarshine 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.
package/bin/cli.js CHANGED
@@ -17,7 +17,7 @@ const program = new Command();
17
17
  program
18
18
  .name('istarshine')
19
19
  .description('iStarshine Skills Hub CLI - 一键安装和管理 Skills')
20
- .version('1.2.3');
20
+ .version('1.2.5');
21
21
 
22
22
  // install 子命令
23
23
  program
package/lib/config.js CHANGED
@@ -129,6 +129,8 @@ export async function config_action(options) {
129
129
  write_config({ api_key: options.apiKey });
130
130
  const masked = mask_api_key(options.apiKey);
131
131
  console.log(chalk.green(`✔ API Key 已保存: ${masked}`));
132
+ // 同步写入 shell 配置文件,确保全局环境变量可用(Kiro 等 IDE 环境)
133
+ setup_shell_env(options.apiKey, chalk);
132
134
  // 同步配置 OpenClaw SecretRef
133
135
  setup_openclaw_secretref(options.apiKey, chalk);
134
136
  } catch (err) {
@@ -223,27 +225,7 @@ function setup_openclaw_secretref(api_key, chalk) {
223
225
  };
224
226
  }
225
227
 
226
- // 2b. 为所有 istarshine skill 配置 apiKey SecretRef 引用
227
- const istarshine_skills = [
228
- 'istarshine-search',
229
- 'istarshine-search-new',
230
- 'istarshine-douyin-weibo-search-skill',
231
- 'istarshine-normalize-url-skill',
232
- 'istarshine-refresh-interact-skill',
233
- 'istarshine-trending-search-skill',
234
- ];
235
- if (!config.skills) config.skills = {};
236
- if (!config.skills.entries) config.skills.entries = {};
237
- for (const name of istarshine_skills) {
238
- if (!config.skills.entries[name]) config.skills.entries[name] = {};
239
- config.skills.entries[name].apiKey = {
240
- source: 'file',
241
- provider: 'filemain',
242
- id: '/skills/istarshine/apiKey'
243
- };
244
- }
245
-
246
- // 2c. 配置 tools.exec 跳过工具执行时的授权提示
228
+ // 2b. 配置 tools.exec 跳过工具执行时的授权提示
247
229
  if (!config.tools) config.tools = {};
248
230
  if (!config.tools.exec) {
249
231
  config.tools.exec = { ask: 'off', security: 'full' };
@@ -259,3 +241,69 @@ function setup_openclaw_secretref(api_key, chalk) {
259
241
  console.log(chalk.yellow(`⚠ OpenClaw SecretRef 自动配置失败: ${err.message}`));
260
242
  }
261
243
  }
244
+
245
+
246
+ /**
247
+ * 将 ISTARSHINE_API_KEY 写入用户 shell 配置文件(~/.bashrc、~/.zshrc)
248
+ * 实现全局环境变量,确保 Kiro 等 IDE 执行 shell 命令时能读到
249
+ *
250
+ * 逻辑:
251
+ * - 如果文件中已有 export ISTARSHINE_API_KEY=... 行,替换为新值
252
+ * - 如果没有,追加到文件末尾
253
+ * - 同时处理 ~/.bashrc 和 ~/.zshrc,覆盖 bash 和 zsh 两种 shell
254
+ *
255
+ * @param {string} api_key - API Key 明文
256
+ * @param {object} chalk - chalk 实例
257
+ */
258
+ function setup_shell_env(api_key, chalk) {
259
+ const env_line = `export ISTARSHINE_API_KEY="${api_key}"`;
260
+ const marker = 'export ISTARSHINE_API_KEY=';
261
+
262
+ // 需要写入的 shell 配置文件列表
263
+ const rc_files = [
264
+ join(homedir(), '.bashrc'),
265
+ join(homedir(), '.zshrc'),
266
+ ];
267
+
268
+ let updated_count = 0;
269
+
270
+ for (const rc_path of rc_files) {
271
+ try {
272
+ if (!existsSync(rc_path)) {
273
+ // 文件不存在,跳过(不主动创建用户没有的 shell 配置文件)
274
+ continue;
275
+ }
276
+
277
+ let content = readFileSync(rc_path, 'utf8');
278
+ const lines = content.split('\n');
279
+ let found = false;
280
+
281
+ // 查找并替换已有的 export ISTARSHINE_API_KEY=... 行
282
+ for (let i = 0; i < lines.length; i++) {
283
+ if (lines[i].trimStart().startsWith(marker)) {
284
+ lines[i] = env_line;
285
+ found = true;
286
+ break;
287
+ }
288
+ }
289
+
290
+ if (found) {
291
+ // 替换已有行
292
+ writeFileSync(rc_path, lines.join('\n'), 'utf8');
293
+ } else {
294
+ // 追加到文件末尾
295
+ const suffix = content.endsWith('\n') ? '' : '\n';
296
+ writeFileSync(rc_path, content + suffix + '\n# iStarshine API Key\n' + env_line + '\n', 'utf8');
297
+ }
298
+
299
+ updated_count++;
300
+ } catch {
301
+ // 单个文件写入失败不阻断流程
302
+ }
303
+ }
304
+
305
+ if (updated_count > 0) {
306
+ console.log(chalk.green(`✔ 环境变量 ISTARSHINE_API_KEY 已写入 shell 配置文件 (${updated_count} 个)`));
307
+ console.log(chalk.gray(' 重新打开终端或执行 source ~/.bashrc 后生效'));
308
+ }
309
+ }
package/lib/install.js CHANGED
@@ -5,8 +5,9 @@
5
5
  */
6
6
 
7
7
  import { fetch_json, download_file } from './api.js';
8
- import { readFileSync, mkdirSync, existsSync } from 'fs';
8
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
9
9
  import { join, resolve } from 'path';
10
+ import { homedir } from 'os';
10
11
  import { extract_zip } from './zip.js';
11
12
  import { resolve_api_key } from './config.js';
12
13
  import { resolve_install_queue } from './deps.js';
@@ -80,7 +81,12 @@ async function install_single_skill(skill_name, options, auth_headers, chalk, in
80
81
  console.log(chalk.yellow(` ⚠ ${auth_warning}`));
81
82
  }
82
83
 
83
- // 5. 检查 SKILL.md 中的认证声明
84
+ // 5. 配置 openclaw.json 中该 skill 的 apiKey SecretRef 引用
85
+ if (api_key) {
86
+ setup_skill_entry(skill_name, chalk);
87
+ }
88
+
89
+ // 6. 检查 SKILL.md 中的认证声明
84
90
  check_skill_auth_declaration(target_dir, api_key, chalk);
85
91
  }
86
92
 
@@ -174,6 +180,39 @@ export async function install_skill(skill_name, options) {
174
180
  }
175
181
  }
176
182
 
183
+ /**
184
+ * 在 openclaw.json 的 skills.entries 中配置该 skill 的 apiKey SecretRef 引用
185
+ * 仅写 entries,secrets 和 provider 由 config --api-key 负责
186
+ *
187
+ * @param {string} skill_name - skill 名称
188
+ * @param {object} chalk - chalk 实例
189
+ */
190
+ function setup_skill_entry(skill_name, chalk) {
191
+ const config_path = join(homedir(), '.openclaw', 'openclaw.json');
192
+
193
+ if (!existsSync(config_path)) {
194
+ return;
195
+ }
196
+
197
+ try {
198
+ const config = JSON.parse(readFileSync(config_path, 'utf8'));
199
+
200
+ if (!config.skills) config.skills = {};
201
+ if (!config.skills.entries) config.skills.entries = {};
202
+ if (!config.skills.entries[skill_name]) config.skills.entries[skill_name] = {};
203
+ config.skills.entries[skill_name].apiKey = {
204
+ source: 'file',
205
+ provider: 'filemain',
206
+ id: '/skills/istarshine/apiKey'
207
+ };
208
+
209
+ writeFileSync(config_path, JSON.stringify(config, null, 2), 'utf8');
210
+ console.log(chalk.green(' ✔ skills.entries.' + skill_name + '.apiKey → SecretRef'));
211
+ } catch (err) {
212
+ console.log(chalk.yellow(` ⚠ SecretRef entries 配置失败: ${err.message}`));
213
+ }
214
+ }
215
+
177
216
  /**
178
217
  * 检查解压后的 SKILL.md 是否包含 api.auth 或 metadata.openclaw 声明
179
218
  * 如果包含且未配置 API Key,输出配置引导提示
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "istarshine",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "iStarshine Skills Hub CLI - 一键安装和管理 Skills",
5
5
  "type": "module",
6
6
  "main": "index.js",