Repository navigation
feat(preset): 新增 botmux preset export 导出Agent预设 - #90
Merged
Merged
Conversation
新增 src/setup/agent-preset.ts:PRESET_VERSION、AgentPreset 接口、 buildPreset(逐字段挑选白名单、绝不 spread 输入以防泄露密钥)、 serializePreset、loadPreset(zod 校验版本与必填字段)、PRESET_GUIDE。 附 test/agent-preset.test.ts 覆盖白名单脱敏、版本/guide 盖章、 serialize↔load round-trip、以及坏 JSON/错版本/缺字段的拒绝。 Co-authored-by: Cursor <[email protected]>
接入 cmdPreset 分发 → cmdPresetExport:用 firstPositional + parseBotSelection 定位 bot,读取 cliId/model(bots.json)、能力标签、角色(默认 team 级, --from-chat 取某群角色内容),经 buildPreset 产出白名单预设。 支持 --out 文件 / 缺省 ./<name或appid>.botmux-preset.json / --out - 走 stdout; 导出前打印角色供确认(--yes 跳过,非交互无 --yes 直接报错); stdout 模式下提示与角色预览一律走 stderr 保持 JSON 纯净;help 增补一段说明。 Co-authored-by: Cursor <[email protected]>
config 在 import 时即固化 dataDir,导致 CLI 子命令在加载后再设的 SESSION_DATA_DIR(如 `SESSION_DATA_DIR ??= resolveDataDir()`)不生效, resolveTeamRoleFile / getBotCapability 可能静默读取包内默认 data 目录。 改成惰性 getter(与同文件 web/dashboard.externalHost 一致),裸终端与 agent 会话均读对目录。 Co-authored-by: Cursor <[email protected]>
- 新增 slugifyForFilename/presetFilename:优先 bot name、退回 appId,非法 字符统一替换为 -,绝不使用进程名;sourceName 仍保留原值仅用于展示。 - cmdPresetExport 默认输出路径改用 presetFilename,避免 name 含空格/斜杠 时生成非法/不稳定路径。 - --from-chat / --out 给了 flag 却缺 value 时直接报错,不再静默退回默认 (误导用户以为导出了某群角色或指定了路径)。 Co-authored-by: Cursor <[email protected]>
- agent-preset.test:slugifyForFilename 与 presetFilename 各分支。 - config-data-dir.test:验证 config.session.dataDir 为惰性 getter。 - preset-export-cli.test:仿 workflow-c0-isolation,跑 dist/cli.js 覆盖 默认文件名 slug、--out - --yes 仅 JSON / stderr 承载日志、非 TTY 无 --yes 失败、空 team role 仍 exit 0、缺值报错、未知 bot 列表。 Co-authored-by: Cursor <[email protected]>
回应评审第 3 点:原 CLI 测试预置了 SESSION_DATA_DIR(agent 会话路径), 未覆盖真正的 bug 场景。新增 runCliBare:不带 SESSION_DATA_DIR、由 resolveDataDir() 退回默认 ~/.botmux/data,断言 role/capability 确实从该 目录读出(无 getter 修复则会静默缺失)。并强化 --out - --yes:断言 stdout 仅为可 parse 的 JSON、提示文案只在 stderr。 Co-authored-by: Cursor <[email protected]>
上一版把 session.dataDir 改成 getter-only,打断了既有「直接赋值 config.session.dataDir」的契约,导致 test/peer-bot-operate.test.ts 5/5 报 TypeError(only a getter)。补一个 setter,把写入映射到 process.env.SESSION_DATA_DIR,既保留惰性读取、又恢复可赋值行为。 Co-authored-by: Cursor <[email protected]>
确认门原先只回显 teamRole,但 capability 同样可能含内部信息且会被导出。 现在 teamRole / capability 都展示,文案也不再误称「仅导出…capability」。 Co-authored-by: Cursor <[email protected]>
JadeInRain
force-pushed
the
feat/preset-export
branch
from
June 2, 2026 12:52
735019a to
931a964
Compare
This was referenced Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景 / 动机
有时想复用别人调好的 agent(CLI 选型 / 模型 / 角色人设 / 能力标签),但要跑在自己的飞书应用和模型上。
bots.json里大多是密钥和本地路径、不可分享,真正可分享的人设/能力又分散在team-roles/、bot-profiles/。本 PR 把这些"可安全分享"的部分导出成一个不含任何密钥的预设 JSON。本 PR 只做
export:导出物交给接收方的 agent 去帮他配置自己的 bot(见预设内嵌的guide字段)。改动
botmux preset export <bot> [--from-chat <chatId>] [--out <file>] [--yes]src/setup/agent-preset.ts:buildPreset(白名单组装,绝不展开输入,结构上不可能带出密钥)/serializePreset/loadPreset(zod 校验,留给将来的 import 工具)+ 给接收方 agent 的内嵌中文guidesrc/config.ts:session.dataDir改为惰性 getter,使 CLI 子命令在导入后设置的SESSION_DATA_DIR能被resolveTeamRoleFile/getBotCapability正确读到安全
cliId / model / teamRole / capability / sourceName / guide,永不含larkAppId / larkAppSecret / allowedUsers / allowedChatGroups / oncallChats / workingDir--yes跳过;非 TTY 缺--yes直接报错、不阻塞,保证可脚本化)--out -时 stdout 只输出 JSON,提示一律走 stderr用法
botmux preset export claude-main— 交互确认后写./claude-main.botmux-preset.jsonbotmux preset export claude-main --out -— 打到 stdout(脚本用,配--yes)botmux preset export claude-main --from-chat oc_xxx— 导出某群的角色内容Test plan
pnpm build通过(无类型错误)test/agent-preset.test.ts:白名单 / 防密钥泄漏(喂完整含密钥配置仍不漏值)/ 版本+guide / serialize↔load round-trip / 坏 JSON 与错版本拒绝test/preset-export-cli.test.ts:CLI 边界(默认文件名 slug 化、--out -只输出 JSON、非 TTY 无--yes快速失败、空角色 exit 0、--from-chat/--out缺值报错、裸终端读默认数据目录)test/config-data-dir.test.ts:惰性 getter