minimax-status 1.0.7 → 1.0.9
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/cli/index.js +91 -118
- package/package.json +1 -1
package/cli/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { Command } = require("commander");
|
|
4
4
|
const chalk = require("chalk").default;
|
|
5
5
|
const ora = require("ora").default;
|
|
6
6
|
const MinimaxAPI = require("./api");
|
|
7
7
|
const StatusBar = require("./status");
|
|
8
|
+
const packageJson = require("../package.json");
|
|
8
9
|
|
|
9
10
|
const program = new Command();
|
|
10
11
|
const api = new MinimaxAPI();
|
|
@@ -12,7 +13,7 @@ const api = new MinimaxAPI();
|
|
|
12
13
|
program
|
|
13
14
|
.name("minimax-status")
|
|
14
15
|
.description("MiniMax Claude Code 使用状态监控工具")
|
|
15
|
-
.version(
|
|
16
|
+
.version(packageJson.version);
|
|
16
17
|
|
|
17
18
|
// Auth command
|
|
18
19
|
program
|
|
@@ -226,14 +227,11 @@ function calculateUsageTokens(usage) {
|
|
|
226
227
|
return 0;
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
// Statusline command -
|
|
230
|
+
// Statusline command - 单次输出模式
|
|
230
231
|
program
|
|
231
232
|
.command("statusline")
|
|
232
|
-
.description("Claude Code状态栏集成(从stdin
|
|
233
|
+
.description("Claude Code状态栏集成(从stdin读取数据,输出单行状态)")
|
|
233
234
|
.action(async () => {
|
|
234
|
-
let isActive = true;
|
|
235
|
-
let intervalId = null;
|
|
236
|
-
|
|
237
235
|
// 读取stdin数据(如果可用)
|
|
238
236
|
let stdinData = null;
|
|
239
237
|
if (!process.stdin.isTTY) {
|
|
@@ -272,136 +270,111 @@ program
|
|
|
272
270
|
return `${tokens}`;
|
|
273
271
|
};
|
|
274
272
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
try {
|
|
280
|
-
// 获取使用状态
|
|
281
|
-
const apiData = await api.getUsageStatus();
|
|
282
|
-
const usageData = api.parseUsageData(apiData);
|
|
283
|
-
|
|
284
|
-
// 构建状态信息
|
|
285
|
-
const { usage, modelName, remaining } = usageData;
|
|
286
|
-
const percentage = usage.percentage;
|
|
287
|
-
|
|
288
|
-
// 从stdin数据获取Claude Code信息
|
|
289
|
-
let displayModel = modelName;
|
|
290
|
-
let currentDir = null;
|
|
291
|
-
let modelId = null;
|
|
292
|
-
let contextSize = 200000; // 默认值
|
|
293
|
-
|
|
294
|
-
if (stdinData) {
|
|
295
|
-
// Claude Code传递的模型信息
|
|
296
|
-
if (stdinData.model && stdinData.model.display_name) {
|
|
297
|
-
displayModel = stdinData.model.display_name;
|
|
298
|
-
modelId = stdinData.model.id;
|
|
299
|
-
} else if (stdinData.model && stdinData.model.id) {
|
|
300
|
-
displayModel = stdinData.model.id;
|
|
301
|
-
modelId = stdinData.model.id;
|
|
302
|
-
}
|
|
273
|
+
try {
|
|
274
|
+
// 获取使用状态
|
|
275
|
+
const apiData = await api.getUsageStatus();
|
|
276
|
+
const usageData = api.parseUsageData(apiData);
|
|
303
277
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
278
|
+
// 构建状态信息
|
|
279
|
+
const { usage, modelName, remaining } = usageData;
|
|
280
|
+
const percentage = usage.percentage;
|
|
281
|
+
|
|
282
|
+
// 从stdin数据获取Claude Code信息
|
|
283
|
+
let displayModel = modelName;
|
|
284
|
+
let currentDir = null;
|
|
285
|
+
let modelId = null;
|
|
286
|
+
let contextSize = 200000; // 默认值
|
|
287
|
+
|
|
288
|
+
if (stdinData) {
|
|
289
|
+
// Claude Code传递的模型信息
|
|
290
|
+
if (stdinData.model && stdinData.model.display_name) {
|
|
291
|
+
displayModel = stdinData.model.display_name;
|
|
292
|
+
modelId = stdinData.model.id;
|
|
293
|
+
} else if (stdinData.model && stdinData.model.id) {
|
|
294
|
+
displayModel = stdinData.model.id;
|
|
295
|
+
modelId = stdinData.model.id;
|
|
311
296
|
}
|
|
312
297
|
|
|
313
|
-
//
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
for (const [key, value] of Object.entries(MODEL_CONTEXT_SIZES)) {
|
|
317
|
-
if (modelKey.includes(key.toLowerCase())) {
|
|
318
|
-
contextSize = value;
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
298
|
+
// 当前工作目录(从stdin获取)
|
|
299
|
+
if (stdinData.workspace && stdinData.workspace.current_directory) {
|
|
300
|
+
currentDir = stdinData.workspace.current_directory.split('/').pop();
|
|
322
301
|
}
|
|
302
|
+
} else {
|
|
303
|
+
// 如果没有stdin,使用API返回的模型名作为ID
|
|
304
|
+
modelId = modelName.toLowerCase().replace(/\s+/g, '-');
|
|
305
|
+
}
|
|
323
306
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
307
|
+
// 查找上下文窗口大小
|
|
308
|
+
if (modelId) {
|
|
309
|
+
const modelKey = modelId.toLowerCase();
|
|
310
|
+
for (const [key, value] of Object.entries(MODEL_CONTEXT_SIZES)) {
|
|
311
|
+
if (modelKey.includes(key.toLowerCase())) {
|
|
312
|
+
contextSize = value;
|
|
313
|
+
break;
|
|
331
314
|
}
|
|
332
315
|
}
|
|
316
|
+
}
|
|
333
317
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
318
|
+
// 尝试从转录文件获取真实token使用量(类似ccline)
|
|
319
|
+
let contextUsageTokens = null;
|
|
320
|
+
let contextUsagePercentage = null;
|
|
321
|
+
if (stdinData && stdinData.transcript_path) {
|
|
322
|
+
contextUsageTokens = await parseTranscriptUsage(stdinData.transcript_path);
|
|
323
|
+
if (contextUsageTokens) {
|
|
324
|
+
contextUsagePercentage = Math.round((contextUsageTokens / contextSize) * 100);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
339
327
|
|
|
340
|
-
|
|
341
|
-
const remainingText =
|
|
342
|
-
remaining.hours > 0
|
|
343
|
-
? `${remaining.hours}h${remaining.minutes}m`
|
|
344
|
-
: `${remaining.minutes}m`;
|
|
328
|
+
const contextSizeText = formatContextSize(contextSize);
|
|
345
329
|
|
|
346
|
-
|
|
347
|
-
|
|
330
|
+
// 状态图标(基于真实上下文使用情况,否则基于额度)
|
|
331
|
+
const displayPercentage = contextUsagePercentage || percentage;
|
|
332
|
+
const statusIcon = displayPercentage >= 85 ? "⚠" : displayPercentage >= 60 ? "⚡" : "✓";
|
|
348
333
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
334
|
+
// 剩余时间文本
|
|
335
|
+
const remainingText =
|
|
336
|
+
remaining.hours > 0
|
|
337
|
+
? `${remaining.hours}h${remaining.minutes}m`
|
|
338
|
+
: `${remaining.minutes}m`;
|
|
354
339
|
|
|
355
|
-
|
|
356
|
-
|
|
340
|
+
// 构建带图标的状态行
|
|
341
|
+
let statusLine = '';
|
|
357
342
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
343
|
+
// 显示目录(优先使用Claude Code的目录,否则显示CLI当前目录)
|
|
344
|
+
const displayDir = currentDir || cliCurrentDir || '';
|
|
345
|
+
if (displayDir) {
|
|
346
|
+
statusLine += `${chalk.blue('📁')} ${chalk.cyan(displayDir)} | `;
|
|
347
|
+
}
|
|
361
348
|
|
|
362
|
-
|
|
363
|
-
|
|
349
|
+
// 模型信息
|
|
350
|
+
statusLine += `${chalk.magenta('🤖')} ${chalk.magenta(displayModel)} | `;
|
|
364
351
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
statusLine += `${contextColor('⚡')} ${contextColor(displayPercentage + '%')} ${chalk.gray('·')} ${chalk.white(formatTokens(contextUsageTokens) + '/' + contextSizeText)} | `;
|
|
369
|
-
} else {
|
|
370
|
-
// 没有转录数据时,显示上下文窗口大小
|
|
371
|
-
statusLine += `${chalk.gray(contextSizeText)} | `;
|
|
372
|
-
}
|
|
352
|
+
// 账户使用额度百分比(根据使用率变色)
|
|
353
|
+
const usageColor = percentage >= 85 ? chalk.red : percentage >= 60 ? chalk.yellow : chalk.green;
|
|
354
|
+
statusLine += `${usageColor(percentage + '%')} | `;
|
|
373
355
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
statusLine += `${chalk.gray('⏱')} ${chalk.white(remainingText)} ${statusColor(statusIcon)}`;
|
|
356
|
+
// 剩余次数
|
|
357
|
+
statusLine += `${chalk.yellow('↻')} ${chalk.white(usage.remaining + '/' + usage.total)} | `;
|
|
377
358
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
359
|
+
// 上下文使用情况(参考ccline:⚡ 百分比 · token数/总大小)
|
|
360
|
+
if (contextUsageTokens) {
|
|
361
|
+
const contextColor = displayPercentage >= 85 ? chalk.red : displayPercentage >= 60 ? chalk.yellow : chalk.green;
|
|
362
|
+
statusLine += `${contextColor('⚡')} ${contextColor(displayPercentage + '%')} ${chalk.gray('·')} ${chalk.white(formatTokens(contextUsageTokens) + '/' + contextSizeText)} | `;
|
|
363
|
+
} else {
|
|
364
|
+
// 没有转录数据时,显示上下文窗口大小
|
|
365
|
+
statusLine += `${chalk.gray(contextSizeText)} | `;
|
|
383
366
|
}
|
|
384
|
-
};
|
|
385
367
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
console.log(chalk.yellow('\n状态栏已停止'));
|
|
397
|
-
process.exit(0);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// 处理进程退出
|
|
401
|
-
process.on('exit', () => {
|
|
402
|
-
isActive = false;
|
|
403
|
-
if (intervalId) clearInterval(intervalId);
|
|
404
|
-
});
|
|
368
|
+
// 剩余时间和状态图标
|
|
369
|
+
const statusColor = displayPercentage >= 85 ? chalk.red : displayPercentage >= 60 ? chalk.yellow : chalk.green;
|
|
370
|
+
statusLine += `${chalk.gray('⏱')} ${chalk.white(remainingText)} ${statusColor(statusIcon)}`;
|
|
371
|
+
|
|
372
|
+
// 输出单行状态(带颜色)
|
|
373
|
+
console.log(statusLine);
|
|
374
|
+
} catch (error) {
|
|
375
|
+
// 输出错误状态(纯文本)
|
|
376
|
+
console.log(`❌ MiniMax 错误: ${error.message}`);
|
|
377
|
+
}
|
|
405
378
|
});
|
|
406
379
|
|
|
407
380
|
function startWatching(api, statusBar) {
|