diff --git a/.cnb.yml b/.cnb.yml index 534e489..edadcbc 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -19,7 +19,7 @@ include: - name: "task" script: | git clone https://cnb.cool/kevisual/cnb cnb - cd cnb && bun run agent/npc.ts cnb npc + cd cnb && bun run agent/npc.ts cnb npc --args owner="小熊猫呜呜呜" $: vscode: - docker: diff --git a/agent/npc.ts b/agent/npc.ts index 27c6d27..8961573 100644 --- a/agent/npc.ts +++ b/agent/npc.ts @@ -4,6 +4,7 @@ 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'; +import { useKey } from '@kevisual/context'; const writeToProcess = (message: string) => { if (process.send) { @@ -38,7 +39,7 @@ const getIssuesLabels = async () => { } -const main = async ({ exit }: { exit: (code: number) => void }) => { +const main = async ({ exit, question }: { exit: (code: number) => void, question?: string }) => { const repoInfoEnv = useRepoInfoEnv(); const commentEnv = useCommentEnv(); const issueEnv = useIssueEnv(); @@ -70,7 +71,7 @@ const main = async ({ exit }: { exit: (code: number) => void }) => { content: `相关变量:${JSON.stringify({ ...pickCommentEnv, ...pickIssueEnv, ...pickRepoInfoEnv })}` }, { role: 'user', - content: commentEnv.commentBody || pickIssueEnv.issueDescription || '无' + content: question || commentEnv.commentBody || pickIssueEnv.issueDescription || '无' } ] writeToProcess('输入消息:'); @@ -100,17 +101,25 @@ app.route({ metadata: { tags: ['notInNpcAgent'], args: { - needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程') + needExit: z.boolean().optional().describe('是否需要在执行完成后退出进程'), + owner: z.string().optional().describe('用户名称') } } }).define(async (ctx) => { const needExit = ctx.args.needExit ?? true; + const owner = ctx.args.owner || ''; const exit = (code: number) => { if (needExit) { process.exit(code); } } - await main({ exit }); + const buildUserNickName = useKey('CNB_BUILD_USER_NICKNAME') + let admins = owner.split(',').map(item => item.trim()); + if (owner && admins.includes(buildUserNickName)) { + await main({ exit }); + } else { + await main({ exit, question: `你是${owner}的专属助手,请生成一条评论,说明你不具备其他用户能访问的能力。同时你需要提示说明,fork当前仓库后,即可成为你的专属助手` }); + } }).addTo(app) parse({ app: app, description: 'CNB控制台命令行工具', parse: true }) diff --git a/package.json b/package.json index 2638832..00209b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.48", + "version": "0.0.50", "description": "", "main": "index.js", "basename": "/root/cnb", diff --git a/readme.md b/readme.md index 255bc71..bc2eca0 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,13 @@ # cnb.cool 能做什么 所有的代码仓库,只基于一个准则 `group/repo` + +## 环境变量 + +```sh +CNB_API_KEY +CNB_COOKIE +``` ## 简介 纯粹调用api的模式去使用cnb.cool,自动化方案。