Skip to content

Commit 902867c

Browse files
committed
feat: add doctor core report
1 parent f0ee771 commit 902867c

9 files changed

Lines changed: 642 additions & 186 deletions

File tree

cli.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const {
7575
executeTaskPlan
7676
} = require('./lib/task-orchestrator');
7777
const { buildConfigHealthReport: buildConfigHealthReportCore } = require('./cli/config-health');
78+
const { buildDoctorReport, buildDoctorLegacyPayload } = require('./cli/doctor-core');
7879
const {
7980
createAuthProfileController
8081
} = require('./cli/auth-profiles');
@@ -6414,6 +6415,77 @@ function cmdStatus() {
64146415
console.log();
64156416
}
64166417

6418+
function parseDoctorCommandArgs(argv = []) {
6419+
const options = {
6420+
json: false,
6421+
range: '7d',
6422+
targetApp: 'codex',
6423+
remote: true,
6424+
includeInstall: true,
6425+
includeUsage: true,
6426+
includeTasks: true,
6427+
includeSkills: true
6428+
};
6429+
let cursor = 0;
6430+
while (cursor < argv.length) {
6431+
const token = String(argv[cursor] || '');
6432+
if (token === '--json') {
6433+
options.json = true;
6434+
cursor += 1;
6435+
continue;
6436+
}
6437+
if (token === '--range') {
6438+
const value = String(argv[cursor + 1] || '').trim().toLowerCase();
6439+
if (!value || value.startsWith('--')) {
6440+
throw new Error('错误: --range 需要一个值(7d/30d/all)');
6441+
}
6442+
options.range = value === 'all' ? 'all' : (value === '30d' ? '30d' : '7d');
6443+
cursor += 2;
6444+
continue;
6445+
}
6446+
if (token === '--target-app') {
6447+
const value = String(argv[cursor + 1] || '').trim().toLowerCase();
6448+
if (!value || value.startsWith('--')) {
6449+
throw new Error('错误: --target-app 需要一个值(codex/claude)');
6450+
}
6451+
options.targetApp = value === 'claude' ? 'claude' : 'codex';
6452+
cursor += 2;
6453+
continue;
6454+
}
6455+
if (token === '--no-remote') {
6456+
options.remote = false;
6457+
cursor += 1;
6458+
continue;
6459+
}
6460+
if (token === '--no-install') {
6461+
options.includeInstall = false;
6462+
cursor += 1;
6463+
continue;
6464+
}
6465+
cursor += 1;
6466+
}
6467+
return options;
6468+
}
6469+
6470+
async function cmdDoctor(argv = []) {
6471+
try {
6472+
const options = parseDoctorCommandArgs(argv);
6473+
const report = await buildDoctorReport(options, {
6474+
getStatusPayload: buildMcpStatusPayload,
6475+
buildInstallStatusReport,
6476+
buildConfigHealthReport,
6477+
listSessionUsage,
6478+
buildTaskOverviewPayload,
6479+
listSkills
6480+
});
6481+
const json = JSON.stringify(report, null, 2);
6482+
process.stdout.write(json + '\n');
6483+
} catch (e) {
6484+
console.error('错误:', e && e.message ? e.message : e);
6485+
process.exitCode = 1;
6486+
}
6487+
}
6488+
64176489
// 列出所有提供商
64186490
function cmdList() {
64196491
const configResult = readConfigOrVirtualDefault();
@@ -8261,6 +8333,20 @@ function createWebServer({ htmlPath, assetsDir, webDir, host, port, openBrowser
82618333
case 'config-health-check':
82628334
result = await buildConfigHealthReport(params || {});
82638335
break;
8336+
case 'doctor':
8337+
{
8338+
const doctorParams = isPlainObject(params) ? params : {};
8339+
const report = await buildDoctorReport(doctorParams, {
8340+
getStatusPayload: buildMcpStatusPayload,
8341+
buildInstallStatusReport,
8342+
buildConfigHealthReport,
8343+
listSessionUsage,
8344+
buildTaskOverviewPayload,
8345+
listSkills
8346+
});
8347+
result = buildDoctorLegacyPayload(report);
8348+
}
8349+
break;
82648350
case 'get-agents-file':
82658351
result = readAgentsFile(params || {});
82668352
break;
@@ -13048,6 +13134,7 @@ async function main() {
1304813134
console.log('\nCodex Mate - Codex 提供商管理工具');
1304913135
console.log('\n用法:');
1305013136
console.log(' codexmate status 显示当前状态');
13137+
console.log(' codexmate doctor [--json] 输出诊断报告(JSON)');
1305113138
console.log(' codexmate setup 交互式配置向导');
1305213139
console.log(' codexmate list 列出所有提供商');
1305313140
console.log(' codexmate models 列出所有模型');
@@ -13109,6 +13196,7 @@ async function main() {
1310913196
switch (command) {
1311013197
case '__task-worker': await cmdTaskWorker(args.slice(1)); break;
1311113198
case 'status': cmdStatus(); break;
13199+
case 'doctor': await cmdDoctor(args.slice(1)); break;
1311213200
case 'setup': await cmdSetup(); break;
1311313201
case 'list': cmdList(); break;
1311413202
case 'models': await cmdModels(); break;

0 commit comments

Comments
 (0)