更新 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

@@ -18,8 +18,8 @@ include:
stages:
- name: "task"
script: |
bun install
bun run agent/npc.ts
npm i -g @kevisual/cnb --registry=https://npm.cnb.cool/kevisual/registry/-/packages/
cloud-npc cnb npc
$:
vscode:
- docker:

View File

@@ -1,4 +1,4 @@
import { app } from './index.ts';
import { parse } from '@kevisual/router/src/commander.ts';
parse({ app: app as any, description: 'CNB控制台命令行工具', parse: true })
parse({ app: app, description: 'CNB控制台命令行工具', parse: true })

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 })

View File

@@ -30,9 +30,17 @@ app.route({
role: 'user',
content: ctx.args.question
}]
const routes = app.routes.filter(route => {
const tags = route.metadata?.tags || [];
if (tags.includes('notInNpcAgent')) {
return false;
}
return true
});
const result = await runAgent({
app,
messages: messages,
routes,
languageModel: cnbAi(model),
token: '',
// token: ctx.query.token as string,

2
bin/npc.js Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env bun
import '../dist/npc.js';

View File

@@ -3,4 +3,5 @@ await buildWithBun({ naming: 'opencode', entry: 'agent/opencode.ts', dts: true }
await buildWithBun({ naming: 'keep', entry: 'src/keep.ts', dts: true, target: 'node' });
await buildWithBun({ naming: 'routes', entry: 'agent/index.ts', dts: true });
await buildWithBun({ naming: 'npc', entry: 'agent/npc.ts', dts: true });
await buildWithBun({ naming: 'cli', entry: 'agent/commander.ts', dts: true, target: 'node' });

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cnb",
"version": "0.0.46",
"version": "0.0.47",
"description": "",
"main": "index.js",
"basename": "/root/cnb",
@@ -18,7 +18,8 @@
"keywords": [],
"bin": {
"cnb": "bin/index.js",
"cloud": "bin/index.js"
"cloud": "bin/index.js",
"cloud-npc": "bin/npc.js"
},
"files": [
"dist",
@@ -38,7 +39,7 @@
"@kevisual/dts": "^0.0.4",
"@kevisual/remote-app": "^0.0.7",
"@kevisual/types": "^0.0.12",
"@opencode-ai/plugin": "^1.2.25",
"@opencode-ai/plugin": "^1.2.27",
"@types/bun": "^1.3.10",
"@types/node": "^25.5.0",
"@types/ws": "^8.18.1",
@@ -55,11 +56,11 @@
},
"dependencies": {
"@kevisual/query": "^0.0.53",
"@kevisual/router": "^0.1.1",
"@kevisual/router": "^0.1.2",
"@kevisual/use-config": "^1.0.30",
"@opencode-ai/sdk": "^1.2.25",
"@opencode-ai/sdk": "^1.2.27",
"es-toolkit": "^1.45.1",
"nanoid": "^5.1.6",
"nanoid": "^5.1.7",
"unstorage": "^1.17.4",
"ws": "npm:@kevisual/ws",
"zod": "^4.3.6"
@@ -74,4 +75,4 @@
"./src/*": "./src/*",
"./agent/*": "./agent/*"
}
}
}