@aiyiran/myclaw 1.1.212 → 1.1.213

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/find-config.js CHANGED
@@ -22,15 +22,24 @@ const CONFIG_FILENAME = 'openclaw.json';
22
22
  /**
23
23
  * 查找 openclaw.json 的路径
24
24
  * 按优先级尝试:
25
- * 1. ~/.openclaw/openclaw.json(标准路径)
26
- * 2. 环境变量 OPENCLAW_HOME 指定的目录
25
+ * 1. OPENCLAW_CONFIG_PATH 指定的配置文件
26
+ * 2. OPENCLAW_STATE_DIR 或 OPENCLAW_HOME 指定的目录
27
+ * 3. ~/.openclaw/openclaw.json(标准路径)
27
28
  *
28
29
  * @returns {string|null} 配置文件路径,未找到返回 null
29
30
  */
30
31
  function findConfig() {
31
32
  const candidates = [];
32
33
 
33
- // 1. 环境变量优先
34
+ const configOverride = process.env.OPENCLAW_CONFIG_PATH?.trim();
35
+ const stateOverride = process.env.OPENCLAW_STATE_DIR?.trim();
36
+ if (configOverride || stateOverride) {
37
+ const configuredPath = configOverride || path.join(stateOverride, CONFIG_FILENAME);
38
+ const resolvedPath = path.resolve(configuredPath.replace(/^~(?=[/\\]|$)/, os.homedir()));
39
+ return fs.existsSync(resolvedPath) ? resolvedPath : null;
40
+ }
41
+
42
+ // 保留 myclaw 旧版 OPENCLAW_HOME 路径约定。
34
43
  if (process.env.OPENCLAW_HOME) {
35
44
  candidates.push(path.join(process.env.OPENCLAW_HOME, CONFIG_FILENAME));
36
45
  }
@@ -62,7 +71,7 @@ function findConfig() {
62
71
  function readConfig() {
63
72
  const configPath = findConfig();
64
73
  if (!configPath) {
65
- throw new Error('未找到 openclaw.json,请确认 OpenClaw 已安装');
74
+ throw new Error('未找到 OpenClaw 配置,请用 openclaw config file 核对当前用户的配置路径');
66
75
  }
67
76
 
68
77
  const raw = fs.readFileSync(configPath, 'utf8');
package/index.js CHANGED
@@ -1178,6 +1178,8 @@ function runPatch() {
1178
1178
  // manifest 加载失败,跳过
1179
1179
  }
1180
1180
 
1181
+ require('./injects/inject-minimax').reapplyManaged();
1182
+
1181
1183
  if (uiResult.success || skillResult.success || (agentResult && agentResult.success)) {
1182
1184
  console.log('');
1183
1185
  console.log(bar);
@@ -4,9 +4,9 @@
4
4
  * inject-minimax.js
5
5
  *
6
6
  * 注入 MiniMax 模型配置到 openclaw.json,并为所有 agent 写入 API Key。
7
- * 这是 myclaw 自己的部署配置。默认型号、生成预算、API 地址和内置备用凭据随插件版本维护,
8
- * 运行时不读取开发者电脑的全局 MiniMax 接入标准。显式传入的密钥、环境变量或目标机器已有的
9
- * 凭据按下面的逻辑优先使用。max 思考深度来自 MiniMax API 对 adaptive 请求的默认行为。
7
+ * 这是 myclaw 自己的部署配置。默认型号、生成预算、API 地址和内置凭据随插件版本维护,
8
+ * 运行时不读取开发者电脑的全局 MiniMax 接入标准。替换模式使用插件内置凭据,
9
+ * 可通过 --key 或 --key-from-env 显式覆盖。max 思考深度来自 MiniMax API 的默认行为。
10
10
  *
11
11
  * 用法:
12
12
  * myclaw inject-minimax # 更新 minimax provider,迁移旧 MiniMax 引用
@@ -55,7 +55,33 @@ function migrateModelSelection(selection) {
55
55
  return updated;
56
56
  }
57
57
 
58
- function run(cliArgs) {
58
+ function readPolicy(configPath) {
59
+ try {
60
+ const policy = JSON.parse(fs.readFileSync(configPath + '.myclaw-minimax.json', 'utf8'));
61
+ if (policy.version !== 1 || (policy.apiKey !== undefined &&
62
+ (typeof policy.apiKey !== 'string' || !policy.apiKey.trim()))) {
63
+ throw new Error('无法识别 myclaw 的 MiniMax 持久配置');
64
+ }
65
+ return policy;
66
+ } catch (err) {
67
+ if (err.code === 'ENOENT') return null;
68
+ throw err;
69
+ }
70
+ }
71
+
72
+ function writePolicy(configPath, apiKey) {
73
+ const policyPath = configPath + '.myclaw-minimax.json';
74
+ const staging = fs.mkdtempSync(path.join(path.dirname(configPath), '.myclaw-minimax-'));
75
+ try {
76
+ const file = path.join(staging, 'policy.json');
77
+ fs.writeFileSync(file, JSON.stringify({ version: 1, apiKey }) + '\n', { mode: 0o600 });
78
+ fs.renameSync(file, policyPath);
79
+ } finally {
80
+ fs.rmSync(staging, { recursive: true, force: true });
81
+ }
82
+ }
83
+
84
+ function run(cliArgs, { reapply = false } = {}) {
59
85
  // ── 解析参数 ──
60
86
  let apiKey = null;
61
87
  let setDefault = false;
@@ -63,9 +89,13 @@ function run(cliArgs) {
63
89
  let betaMode = false;
64
90
 
65
91
  for (let i = 0; i < cliArgs.length; i++) {
66
- if (cliArgs[i] === '--key' && cliArgs[i + 1]) {
67
- apiKey = cliArgs[i + 1];
92
+ if (cliArgs[i] === '--key') {
93
+ apiKey = cliArgs[i + 1]?.trim();
94
+ if (!apiKey || apiKey.startsWith('--')) throw new Error('--key 需要提供 MiniMax API Key');
68
95
  i++;
96
+ } else if (cliArgs[i] === '--key-from-env') {
97
+ apiKey = process.env.MINIMAX_API_KEY?.trim();
98
+ if (!apiKey) throw new Error('--key-from-env 需要设置 MINIMAX_API_KEY');
69
99
  } else if (cliArgs[i] === '--default') {
70
100
  setDefault = true;
71
101
  } else if (cliArgs[i] === '--only') {
@@ -87,10 +117,15 @@ function run(cliArgs) {
87
117
  process.exit(1);
88
118
  }
89
119
 
120
+ const policy = readPolicy(configPath);
121
+ if (reapply && !policy) return;
122
+ const managedKey = apiKey || policy?.apiKey;
90
123
  const configuredKey = config.models?.providers?.minimax?.apiKey;
91
124
  const existingKey = typeof configuredKey === 'string' && !configuredKey.startsWith('$')
92
125
  ? configuredKey : undefined;
93
- apiKey ||= process.env.MINIMAX_API_KEY || existingKey;
126
+ apiKey = setDefault || policy
127
+ ? managedKey || DEFAULT_MINIMAX_KEY
128
+ : apiKey || process.env.MINIMAX_API_KEY || existingKey;
94
129
 
95
130
  console.log('📍 找到配置: ' + configPath);
96
131
  console.log('📌 模式: ' + (betaMode ? '--beta (独占+6.X兼容)' : onlyMode ? '--only (独占)' : setDefault ? '--default (设默认)' : '追加'));
@@ -138,6 +173,10 @@ function run(cliArgs) {
138
173
  if (!config.auth) config.auth = {};
139
174
  if (!config.auth.profiles) config.auth.profiles = {};
140
175
  config.auth.profiles["minimax:cn"] = { provider: "minimax", mode: "api_key" };
176
+ if (setDefault || policy) {
177
+ config.auth.order ||= {};
178
+ config.auth.order.minimax = ['minimax:cn'];
179
+ }
141
180
 
142
181
  if (!config.models) config.models = {};
143
182
  if (!config.models.mode) config.models.mode = "merge";
@@ -156,8 +195,8 @@ function run(cliArgs) {
156
195
  maxTokens: OUTPUT_BUDGET
157
196
  }]
158
197
  };
159
- if (existingKey) minimaxProvider.apiKey = apiKey;
160
- if (!setDefault) minimaxProvider.authHeader = true;
198
+ if (setDefault || policy || existingKey) minimaxProvider.apiKey = apiKey;
199
+ if (!setDefault && !policy) minimaxProvider.authHeader = true;
161
200
  config.models.providers.minimax = minimaxProvider;
162
201
 
163
202
  if (!config.agents) config.agents = {};
@@ -202,7 +241,12 @@ function run(cliArgs) {
202
241
  console.log('');
203
242
  console.log('🔑 [Step 4] 写入 API Key 到所有 agent...');
204
243
 
205
- const stateDir = process.env.OPENCLAW_STATE_DIR || path.dirname(configPath);
244
+ const stateDirOverride = process.env.OPENCLAW_STATE_DIR?.trim();
245
+ const stateDir = stateDirOverride
246
+ ? path.resolve(stateDirOverride.replace(/^~(?=[/\\]|$)/, os.homedir()))
247
+ : process.env.OPENCLAW_CONFIG_PATH?.trim()
248
+ ? path.join(os.homedir(), '.openclaw')
249
+ : path.dirname(configPath);
206
250
  const DEFAULT_MAIN_DIR = path.join(stateDir, 'agents', 'main', 'agent');
207
251
  const agentList = (config.agents && config.agents.list) || [];
208
252
 
@@ -216,7 +260,7 @@ function run(cliArgs) {
216
260
 
217
261
  // 6.X loads agent credentials from SQLite. Legacy clients use auth-profiles.json.
218
262
  let DatabaseSync;
219
- if (setDefault) {
263
+ if (setDefault || policy) {
220
264
  try {
221
265
  ({ DatabaseSync } = require('node:sqlite'));
222
266
  } catch (err) {
@@ -259,6 +303,9 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
259
303
  state.lastGood ||= {};
260
304
  const prior = store.profiles[state.lastGood.minimax] || store.profiles[profileId];
261
305
  key = apiKey || prior?.key || key || DEFAULT_MINIMAX_KEY;
306
+ if (store.profiles[profileId]?.key !== key && state.usageStats) {
307
+ delete state.usageStats[profileId];
308
+ }
262
309
  store.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key };
263
310
  state.lastGood.minimax = profileId;
264
311
  const now = Date.now();
@@ -272,20 +319,25 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
272
319
  }
273
320
  }
274
321
 
275
- profiles.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key: key || DEFAULT_MINIMAX_KEY };
322
+ key ||= DEFAULT_MINIMAX_KEY;
323
+ if (profiles.profiles[profileId]?.key !== key && profiles.usageStats) {
324
+ delete profiles.usageStats[profileId];
325
+ }
326
+ profiles.profiles[profileId] = { type: 'api_key', provider: PROVIDER_ID, key };
276
327
  profiles.lastGood.minimax = profileId;
277
328
  fs.writeFileSync(profilesPath, JSON.stringify(profiles, null, 2) + '\n', { mode: 0o600 });
278
329
  console.log(' ✅ ' + agentId + (DatabaseSync ? ' (json+sqlite)' : ' (json)'));
279
330
  okCount++;
280
331
  }
281
332
 
333
+ if (setDefault && !reapply) writePolicy(configPath, managedKey);
282
334
  writeConfig(config, configPath);
283
335
  console.log('✅ openclaw.json 已更新');
284
336
 
285
337
  // ── Step 5:迁移旧 MiniMax 会话,设默认模式沿用全部会话迁移 ──
286
338
  let sessionOk = 0, sessionSkip = 0, sessionChanged = 0;
287
339
 
288
- for (const [agentDir] of agentDirs) {
340
+ for (const [agentDir] of reapply ? [] : agentDirs) {
289
341
  const sessionsPath = path.join(agentDir, '..', 'sessions', 'sessions.json');
290
342
  if (!fs.existsSync(sessionsPath)) continue;
291
343
  try {
@@ -331,4 +383,8 @@ CREATE TABLE IF NOT EXISTS auth_profile_state (
331
383
  console.log('');
332
384
  }
333
385
 
334
- module.exports = { run };
386
+ function reapplyManaged() {
387
+ if (require('../find-config').findConfig()) run(['--default'], { reapply: true });
388
+ }
389
+
390
+ module.exports = { run, reapplyManaged };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.212",
3
+ "version": "1.1.213",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -11,6 +11,8 @@ myclaw inject-minimax --default
11
11
 
12
12
  该命令将 OpenClaw 的唯一可选聊天模型及全局默认设为 `minimax/MiniMax-M3.1-Flash`,生成预算为 131072 token。OpenClaw 2026.6.9 使用 adaptive thinking,思考深度由 MiniMax API 默认设为 max。命令在注入后重启 Gateway。
13
13
 
14
- 模型、生成预算、API 地址和内置备用凭据由 myclaw 自己维护。插件运行不依赖开发者电脑的全局模型配置。可以在目标机器上复用已有凭据,也可以通过 `MINIMAX_API_KEY` 提供凭据。
14
+ 模型、生成预算、API 地址和内置凭据由 myclaw 自己维护。插件运行不依赖开发者电脑的全局模型配置。`--default` 会为当前 OpenClaw 配置启用 myclaw 管理,默认使用内置凭据。容器中的 `MINIMAX_API_KEY` 仅在指定 `--key-from-env` 时用于此模式,也可通过 `--key` 显式指定。显式凭据保存在配置文件旁的受限权限文件中。
15
+
16
+ 启用后,`mc patch` 会在其他补丁完成后重新应用此设置。`mc up` 使用新版的 `mc patch`,同样会读回此设置。容器部署请让 OpenClaw 配置及其旁边的 `.myclaw-minimax.json` 配置文件后缀一起留在持久卷中。
15
17
 
16
18
  兼容入口 `node scripts/inject.js` 调用同一条命令。