更新 NPC 相关逻辑,重构命令行工具,添加新的 CLI 入口,升级依赖版本

This commit is contained in:
xiongxiao
2026-03-16 21:45:37 +08:00
committed by cnb
parent fe89bdee5b
commit ae5565cda7
7 changed files with 48 additions and 15 deletions

View File

@@ -1,7 +1,9 @@
import { app } from './index.ts';
import { parse } from '@kevisual/router/src/commander.ts';
import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
import { pick } from 'es-toolkit';
import z from 'zod';
const writeToProcess = (message: string) => {
if (process.send) {
@@ -36,7 +38,7 @@ const getIssuesLabels = async () => {
}
const main = async () => {
const main = async ({ exit }: { exit: (code: number) => void }) => {
const repoInfoEnv = useRepoInfoEnv();
const commentEnv = useCommentEnv();
const issueEnv = useIssueEnv();
@@ -56,7 +58,7 @@ const main = async () => {
envList.forEach(item => writeToProcess(item));
if (!isComment && !issueLabelsNames.includes('Run')) {
writeToProcess('当前 Issue 不包含 Run 标签,跳过执行');
process.exit(0);
return exit(0);
}
const messages = [
{
@@ -84,11 +86,30 @@ const main = async () => {
let _message = result.data.message || []
writeToProcess('执行完成')
writeToProcess(JSON.stringify(_message, null, 2))
process.exit(0)
exit(0);
} else {
writeToProcess(result.message || '执行错误')
process.exit(1)
exit(1);
}
}
main();
app.route({
path: 'cnb',
key: 'npc',
description: 'CNB智能助手,提供智能建议和帮助, 程序入口',
metadata: {
tags: ['notInNpcAgent'],
args: {
needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程')
}
}
}).define(async (ctx) => {
const exit = (code: number) => {
if (ctx.args.needExit) {
process.exit(code);
}
}
await main({ exit });
}).addTo(app)
parse({ app: app, description: 'CNB控制台命令行工具', parse: true })