更新 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: stages:
- name: "task" - name: "task"
script: | script: |
bun install npm i -g @kevisual/cnb --registry=https://npm.cnb.cool/kevisual/registry/-/packages/
bun run agent/npc.ts cloud-npc cnb npc
$: $:
vscode: vscode:
- docker: - docker:

View File

@@ -1,4 +1,4 @@
import { app } from './index.ts'; import { app } from './index.ts';
import { parse } from '@kevisual/router/src/commander.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 { app } from './index.ts';
import { parse } from '@kevisual/router/src/commander.ts';
import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts' import { useIssueEnv, useCommentEnv, useRepoInfoEnv, IssueLabel } from '../src/index.ts'
import { pick } from 'es-toolkit'; import { pick } from 'es-toolkit';
import z from 'zod';
const writeToProcess = (message: string) => { const writeToProcess = (message: string) => {
if (process.send) { 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 repoInfoEnv = useRepoInfoEnv();
const commentEnv = useCommentEnv(); const commentEnv = useCommentEnv();
const issueEnv = useIssueEnv(); const issueEnv = useIssueEnv();
@@ -56,7 +58,7 @@ const main = async () => {
envList.forEach(item => writeToProcess(item)); envList.forEach(item => writeToProcess(item));
if (!isComment && !issueLabelsNames.includes('Run')) { if (!isComment && !issueLabelsNames.includes('Run')) {
writeToProcess('当前 Issue 不包含 Run 标签,跳过执行'); writeToProcess('当前 Issue 不包含 Run 标签,跳过执行');
process.exit(0); return exit(0);
} }
const messages = [ const messages = [
{ {
@@ -84,11 +86,30 @@ const main = async () => {
let _message = result.data.message || [] let _message = result.data.message || []
writeToProcess('执行完成') writeToProcess('执行完成')
writeToProcess(JSON.stringify(_message, null, 2)) writeToProcess(JSON.stringify(_message, null, 2))
process.exit(0) exit(0);
} else { } else {
writeToProcess(result.message || '执行错误') 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', role: 'user',
content: ctx.args.question 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({ const result = await runAgent({
app, app,
messages: messages, messages: messages,
routes,
languageModel: cnbAi(model), languageModel: cnbAi(model),
token: '', token: '',
// token: ctx.query.token as string, // 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: 'keep', entry: 'src/keep.ts', dts: true, target: 'node' });
await buildWithBun({ naming: 'routes', entry: 'agent/index.ts', dts: true }); 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' }); await buildWithBun({ naming: 'cli', entry: 'agent/commander.ts', dts: true, target: 'node' });

View File

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