(args: string[])
| 315 | } |
| 316 | |
| 317 | async function runCodexCleanupInternalThreads(args: string[]) { |
| 318 | const i18n = createI18n(); |
| 319 | const options = parseCodexCleanupInternalThreadsArgs(args); |
| 320 | const stateDir = path.resolve(options.stateDir ?? defaultCodexBridgeStateDir()); |
| 321 | const defaultCwd = path.resolve(options.cwd ?? process.env.CODEXBRIDGE_DEFAULT_CWD ?? process.cwd()); |
| 322 | const repositories = createFileJsonRepositories(path.join(stateDir, 'runtime')); |
| 323 | const codexProfiles = loadCodexProfilesFromEnv(); |
| 324 | const runtime = createCodexBridgeRuntime({ |
| 325 | providerPlugins: [ |
| 326 | new OpenAINativeProviderPlugin(), |
| 327 | new OpenAICompatibleProviderPlugin(), |
| 328 | ], |
| 329 | providerProfiles: codexProfiles.profiles, |
| 330 | defaultProviderProfileId: codexProfiles.defaultProviderProfileId, |
| 331 | defaultCwd, |
| 332 | locale: i18n.locale, |
| 333 | repositories, |
| 334 | assistantAttachmentRoot: path.join(stateDir, 'assistant', 'attachments'), |
| 335 | codexAuthManager: createWeixinServeCodexAuthManager(stateDir), |
| 336 | codexGoalManager: createWeixinServeCodexGoalManager(stateDir), |
| 337 | }); |
| 338 | |
| 339 | process.stdout.write(`${i18n.t('cli.cleanupInternalThreads.starting')}\n`); |
| 340 | process.stdout.write(`mode: ${options.dryRun ? 'dry-run' : 'apply'}\n`); |
| 341 | process.stdout.write(`state_dir: ${stateDir}\n`); |
| 342 | process.stdout.write(`default_cwd: ${defaultCwd}\n`); |
| 343 | process.stdout.write(`limit: ${options.limit}\n`); |
| 344 | |
| 345 | try { |
| 346 | const reports = await runtime.services.bridgeCoordinator.cleanupInternalProviderThreads({ |
| 347 | dryRun: options.dryRun, |
| 348 | limit: options.limit, |
| 349 | }); |
| 350 | let totalScanned = 0; |
| 351 | let totalMatched = 0; |
| 352 | let totalArchived = 0; |
| 353 | let totalFailed = 0; |
| 354 | |
| 355 | for (const report of reports) { |
| 356 | const failed = Array.isArray(report.failed) ? report.failed : []; |
| 357 | const matches = Array.isArray(report.matches) ? report.matches : []; |
| 358 | totalScanned += Number(report.scanned ?? 0); |
| 359 | totalMatched += Number(report.matched ?? 0); |
| 360 | totalArchived += Number(report.archived ?? 0); |
| 361 | totalFailed += failed.length; |
| 362 | process.stdout.write(`\nprofile: ${report.providerProfileId}\n`); |
| 363 | process.stdout.write(`scanned: ${Number(report.scanned ?? 0)}\n`); |
| 364 | process.stdout.write(`matched: ${Number(report.matched ?? 0)}\n`); |
| 365 | process.stdout.write(`archived: ${Number(report.archived ?? 0)}\n`); |
| 366 | if (matches.length > 0) { |
| 367 | process.stdout.write('matches:\n'); |
| 368 | for (const match of matches.slice(0, 20)) { |
| 369 | process.stdout.write(` - ${match.threadId} ${match.title ?? ''}\n`); |
| 370 | } |
| 371 | if (matches.length > 20) { |
| 372 | process.stdout.write(` ... ${matches.length - 20} more\n`); |
| 373 | } |
| 374 | } |
no test coverage detected