Repository navigation
feat(session-manager): sender/mentions 搬进 hook envelope,用户输入只剩正文 - #998
Conversation
|
自动评审初步意见(最终以维护者审阅为准): 整体方向认可——把 sender/mentions 搬进 hook envelope、opening 复用同一套 sidecar/claim,inline 字节不变、fallback 纪律好。但有 3 处建议修改后再合: 1. CI 红(阻断): 2. opening + skill catalog 的指纹漂移建议补测:opening 的 sidecar 按「catalog 追加前」的 ptyText 写指纹,但 worker 的 3. 第 4 个 opening 调用点未接线: 另:除这 4 个 daemon 点外, |
|
自动评审初步意见(最终以维护者审阅为准)——针对新 commit 23a92b0 的复审: 三处意见都收到了,感谢及时修改。逐条确认(已在当前 master 上做 trial merge 实测:0 冲突、tsc 通过、相关测试套件全绿,CI 也已转绿):
整体方向认可,P0/P2 已闭合。以上为自动评审的初步意见,是否需要补充说明或如何取舍,最终以维护者审阅为准。 |
hook 的 system-reminder,并去掉 <user_message> 外壳,让用户输入框 只剩消息正文。模型经 hook envelope 仍看得到发送者与提及,--mention 决策与 A2A 归因不受影响。 - follow-up hook 模式:envelope 从 reminder/whiteboard 扩到 reminder/whiteboard/sender/mentions;userMessage 块在 hook 模式下 输出纯正文 - opening(新话题第一条):此前完全没走 hook,现复用同一套 sidecar/claim 机制。buildNewTopicPrompt 重构为 blocks 结构 (inline 输出字节不变),buildNewTopicCliInput 在 hook 模式下把 whiteboard/sender/mentions 写进 sidecar、PTY 文本只剩正文 - 调用点传入权威 turnId + sessionBackendType:buildReservedInitialInput (主 opening 路径)、card-handler repo-selection、live-worker empty-start 首轮。raw 命令冷启动的 buffered follow-up 走 raw_input IPC 延迟发送,turnId 权威流不同,暂保持 inline 影响面与权衡: - 会话发现(/adopt):主防线是 collectBotmuxSessionIdentities 按 文件名(=sessionId)排除,不依赖 transcript 内容,已关闭会话不会 漏进 picker。transcript 标记正则仍匹配 inline 模式与旧会话 - insight 发送者归因:hook 注入内容不落 transcript,hook 模式会话的 sender/mentions 归因降级为「未知用户」(正文与 @ 仍在) - 标题提取:extractBotmuxLarkNativeSessionTitlePrompt 有 ?? rawContent 兜底,不受影响 - 超限/无条件时回退 inline,行为与历史完全一致 测试:prompt-hook-injection(含新增 opening 4 例)、prompt-builder、 card-handler-repo-select、resumable-session-discovery、bridge-turn-queue 等相关套件全绿
…ng 调用点 P0:scheduler-silent-execute.test.ts 漏改的姊妹断言。该测试走 follow-up hook 路径(local pty + auto),原断言 PTY content 含 <user_message>, 与本 PR 核心改动(hook 模式剥掉外壳)冲突。镜像成 not.toContain。 P1:opening sidecar 指纹 vs skill catalog 追加。opening 是 CLI generation 首轮,prepareSessionSkillPrompt 会把 skill catalog 追加到 prompt 尾部, sidecar 按追加前的 ptyText 写指纹,hook 看到的是 ptyText+catalog,全量 指纹 miss、prefix 兜底(前 30 字符不变)救回。补「模拟 catalog 追加后仍能 claim」的测试锁住这条 fallback(消息需长于 30 字符)。 P2:补齐第 4 个 opening 调用点(daemon.ts worker-null refork opening, empty-start 丢 worker 后的首条真实用户 turn)。此前只接了 3 处,这条路径 保持 inline,UX 不一致。现传入 turnId(非 queued 时 = parsed.messageId, 与 forkWorker 权威 turnId 一致)+ sessionBackendType;queued dashboard 场景 turnId 是合成的,保持 inline。 同步更新 initial-user-turn-opening.test.ts:opening 现走 hook 模式, sidecar 是合法 opening envelope(claim 回含 sender、不含 follow-up reminder),PTY 内容只剩正文。HIGH-3(不写 speculative follow-up reminder sidecar)仍满足——opening 分支用 buildNewTopicCliInput,不跑 buildReforkCliInput。
23a92b0 to
7c651bc
Compare
已代为 rebase 到最新 master(
|
|
🚀 Released in v3.19.3 |
rebase 到含 deepcoldy#998 的主干时,opening 的分块从 `parts.push(文本)` 改成 `blocks.push({key, text})`,凭证边界块要跟着改并新增 `credentials` key。 这个落点原先零测试覆盖——`credential-boundary-prompt.test.ts` 的文件头写着 覆盖两条 prompt 路径,实际只 import 了 buildBotmuxSystemPromptText, inline 路径(codex/gemini 等)一条断言都没有。删掉 push 全套测试照样绿。 补三条走 buildNewTopicPrompt 的断言:开启时含 <botmux_credentials>、 关闭时不含、拿不到 bot 配置时不含。变异验证:删掉 push 立刻转红。 `credentials` 刻意不进 ENVELOPE_KEYS。当前这个选择是惰性的——hook 模式要求 supportsInvisiblePromptHook(仅 claude-code),而 claude-code 有 injectsSessionContext、根本不走这个分支,所以 hook 模式下永不产生 credentials 块(已实测)。仍然保留在 PTY 文本,是为了将来别的 CLI 具备 hook 能力时不至于静默丢块:envelope 读不到时不会报错,只是约束消失。 Co-Authored-By: Claude Code <[email protected]>
* feat(user-token): token 按 (app, 授权人) 存储,移除全局 env 旁路 原来 token 只按 appId 存一份,同一个 bot 里第二个人 /login 会直接覆盖第一个 人,之后所有人的操作都用最后授权那个人的权限——不报错,只是审计里写错了人。 目前没暴露只因实际只有一个人在 /login。 - 文件名加 openId:user-token-<appId>-<openId>.json - resolveUserToken/getTokenStatus/getFeedGroupAuthStatus 接受可选 openId; 按人取时只认属于那个人的文件,未标注归属的旧文件一律不认领(无法证明属于谁) - 归属以 user_info 回读的真实授权人为准,不信任发起人声明:/login 链接被转给 别人点时按真实授权人落盘并明确告知,绝不把 B 的凭证存到 A 名下 - refresh 写回原文件并保留 openId/userName,不落到 per-app 路径覆盖别的东西 - 新增 listAuthorizedUsers(),只报归属与有效期,不返回任何 token 内容 - openId 过 [A-Za-z0-9_-] 校验后才参与拼路径,挡住 ../ 逃出 token 目录 - 删掉 FEISHU_USER_ACCESS_TOKEN 全局覆盖:设一次就让所有 bot、所有会话、所有 人共用一个身份,且绕过时日志里没有任何痕迹 原有 17 个 user-token 测试全过(两处断言按新语义改写:env 旁路已移除、回调多 一次 user_info 调用),新增 10 个 per-user 测试。 Co-Authored-By: Claude Code <[email protected]> * feat(login): /login 归属到发起人,owner 个人功能走专用解析 /login 现在把发起人的 open_id 带进 OAuth state,回调按人落盘(回调本身仍用 user_info 复核真实授权人)。/login status 也改成按人查——报你自己授权了没, 别人的授权状态与你无关,也不该让你看见。 同时处理一个升级陷阱:飞书「消息分组」标签是 owner 自己收件箱侧边栏里的东西, bot 没有收件箱,所以它只能用 owner 本人的 token。但存量安装的 owner token 就 存在未标注归属的 per-app 文件里,严格按人取会让标签功能升级后静默失效。为此 新增 resolveOwnerUserToken():优先 owner 自己的文件,回落到未标注归属的旧文件。 这道口子只对 owner 开,且只放宽「哪个文件算 owner 的」,不放宽「可以借谁的身份」 ——另一个具名用户的文件依然拒绝。ownerOpenId 来自 bot 配置而非消息,因此不存在 借用别人凭证的路径。 - /login、/login tags、/subscribe-lark-doc 的授权链接都带上发起人 - feed-group 的 tagger / dashboard / IPC 三处改用 owner 口径 - getFeedGroupAuthStatus 同步该口径,否则升级后徽标会莫名变「未授权」 新增 3 个 owner-fallback 测试,user-token 全部 30 个测试通过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): 加 bot 级开关,默认关闭 新增 services/trigger-user-auth.ts 承载这条规则:CLI 调用用本轮消息发送者自己的 凭证,或者没有;唯一允许的降级是「bot 自己的 tenant 身份」(不属于任何人), 绝不退回到另一个人的登录态,owner 也不例外。 因此配置里刻意没有 device / machine-login 这个选项,而且写了它会被明确拒绝并 说明「永不可用」——留一个静默归一化会让操作者以为自己配上了。同理 tools 里出现 未知工具直接抛错:静默丢弃会让人相信边界已生效,实际没有,比没这个功能更糟。 记录两个 CLI 的能力不对称:lark-cli 有 --as bot(零登录可用),bytedcli 只有 SSO 个人登录,没有 service account 也没有 AK/SK。所以对 bytedcli,即使配了 fallback=bot-identity,unauthorizedOutcomeFor 也返回 fail——报 bot-identity 只会 产生一次注定失败的调用,还附带一个误导性的原因。 至于某条 lark-cli 命令到底能不能用 bot 身份,不在这里判断:CLI 自己会声明 (不支持时回 "--as bot is not supported, this command only supports: user")。 手工维护「哪些命令需要真人」的清单会过期、会漏。 - bots.json 加 triggerUserAuth 字段,缺失即关闭 - /botconfig set 与 Dashboard 走同一个 parser(照 mojo 的模式),两个门不会漂移, 拒绝原因原样透出 - effect: next-session 新增 16 个策略测试;bot-config-store / bot-registry 现有 219 个测试全过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): wrapper + 每轮发布当轮身份 凭证走文件而不是环境变量,这是本功能能成立的前提:一个会话是一个长驻 CLI 进程, 它的环境在 spawn 那一刻就被内核定死,daemon 之后改不了,子进程也改不了父进程的。 env 注入等于把身份冻结在起会话那个人身上,之后任何人发言都还在用他的权限。文件 则是每次 CLI 调用都重新读,所以生效的身份永远是 daemon 为当轮写的那一份,换人 零成本且不用重启会话(重启会丢掉 CLI 全部上下文,实际不可接受)。 - core/cli-identity.ts:身份文件读写 + wrapper 生成。值用单引号包裹,含引号/换行 的一律拒绝而不是清洗——被改过的 token 就是不能用的 token,静默截断会在很久之后 变成一个莫名的鉴权失败。7 个恶意值跑真实 /bin/sh 验证原样往返。 - core/turn-cli-identity.ts:策略 + token 存储 + 身份文件三者的汇合点。取不到当轮 发送者的 token 时**删除**旧文件,绝不留着——留着就等于下一条命令用上一个人的 身份跑,而且没有任何信号。无人类发送者的轮次(定时/hook/会议/bot 交接)同样删除, 不会去拿会话创建者或 owner 的凭证来补。 - 挂在 noteTurnReceived:它是源码注释里明确的 per-message acceptance point,每个 inbound turn 都经过,是唯一能保证「没有一轮带着上一个人的凭证跑」的位置。 - 发送者取自 daemon 自己的 per-turn 记录(pickTurnReplyTarget),worker 只能提供 turnId,无法选择这个 id 指向哪个人。 - wrapper 装在 per-session 目录而不是共享 ~/.botmux/bin:装在后者会让本机所有 bot 连没开这个功能的、以及操作者自己的 shell 都被 shadow。 - 真实二进制从即将交给子进程的 PATH 里解析并排除 wrapper 目录,构造上不可能自引用。 - 会话关闭时清掉全部身份文件:里面是活的 user token。 - 需要授权的提示每会话每工具只发一次。 新增 38 个测试(cli-identity 27 + turn-cli-identity 11),本功能累计 67 个全过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): 内部 token 消费点按人取 三处内部直接用 user token 的地方,加了 openId 维度后必须回答「用谁的」,漏掉会 静默失效。逐个查完发现它们的正确答案各不相同,也都已经有 fallback,所以不是重写: - 图片/文件下载(client.ts):现有逻辑本来就是「先 app token,400/403 才回退 user token」,bot 能下的就用 bot 身份。只把回退时那个 token 改成**发送者本人**的 ——他刚发的附件,用他的凭证下载天然正确,归因也归到他。 - 文档评论(doc-comment.ts):订阅是长期任务,没有「当轮发送者」——触发的评论可能 来自任何人,包括从没授权过这个 bot 的人。所以身份固定为**订阅创建者** (DocSubscription.ownerOpenId,字段本来就有),不取自评论人。 - feed 打标:已在上一个 commit 处理(owner 个人功能)。 doc-comment 的身份解析放在 driveApiCall 内部集中做,而不是把 userOpenId 穿过全部 9 个导出函数和约 20 个调用点:后者漏一个就静默退回 bot 级查找,而且看不出来。 开关关闭时三处都走原逻辑,一行行为不变。 user-token / doc-comment / cli-identity 相关 145 个测试全过,tsc 0 错误。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): 身份文件按会话授权,并如实报告 token 存储的保护程度 沙盒是 deny-by-default,所以 wrapper 要读的身份文件本来是被拒的。按**单个文件** 授予只读,绝不授予 cli-identity/ 父目录:那个目录里放着所有并发会话的文件,每份 都是不同的人的活 token,父目录授权等于让会话 A 能读会话 B 的凭证——正是这个功能 要防的跨人泄漏,而且对 spawn 之后新建的文件会 fail open。 只读也是刻意的:daemon 写、CLI 只读。可写就等于让 agent 自己发布身份,冒充任何 它能说出名字的人。no-transport(core-only)轮次一律不给——那种模式本身就是要关掉 飞书凭证面,给它 user token 等于把这道边界重新打开。 沙盒会 existence-filter 掉不存在的路径,所以 spawn 前预建空身份文件,否则 wrapper 读不到 daemon 之后写入的内容,会话会静默地不带发送者身份跑。空内容是正确初值: 第一轮解析出身份前本来就没有身份,wrapper 对空文件和不存在同样处理。 另外加 tokenStoreProtection(),如实说明保护程度而不是给个安心话术:token 是 0600, 但 agent 与 botmux 跑在同一个系统用户下,**不开文件沙盒时它有能力直接读取 ~/.botmux/data/ 里其他人的 token 文件**。按人存储解决的是归因和覆盖问题;要让隔离 由操作系统强制,必须开 sandbox。 这条只记日志、不拦:拒绝启动会把人从一个无论如何都更好的改动上推开,而声称我们 没有的隔离比两者都糟。措辞里写清 agent 实际能做什么,光说「不够安全」操作者无法 据此判断。 fs-policy 新增 4 个测试(含「会话 A 读不到会话 B 的身份」),本功能相关 154 个 测试全过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): git 推送归因到当轮操作人 git 走 HTTPS 推 Codebase 时用的是 Codebase JWT,由 GIT_ASKPASS 提供,它不读前面 那些身份 env。不做这块的话,替别人干的活推上去仍然挂着机器的身份——而「这个 MR 是谁提的」恰恰是这个功能最需要修的归因。 helper 问的是**被 wrapper 包过的** bytedcli,因此自动继承当轮身份:不用维护第二条 凭证链路,helper 自己也不需要知道当前是谁在说话。 - 每次调用现取 JWT,不落盘、不进 URL、不打日志。JWT 拼进 remote URL 会留在 .git/config 里,而且会出现在 git 打印的任何报错里。 - 解析真实响应结构 {"status":…,"data":{"jwt":"…"}}(实测 bytedcli 确认,字段是 jwt 不是 token)。 - 取不到凭证时返回空串,git 报成鉴权失败——而不是抛一个看起来像 botmux bug 的 shell 错误。 - 只在 bytedcli 已被 wrap 时安装:否则根本没法签 JWT,装一个必然失败的 helper 只会 把「没有凭证」变成一个难懂的 git 报错。 新增 6 个测试(含真实 /bin/sh 跑 askpass、以及「不得把 token 放进 URL」), cli-identity 共 33 个全过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): Dashboard 开关、自带凭证 MCP 警告、/status 身份行 Dashboard 放在「安全」tab,与 sandbox / Codex 凭证 / 授权管理并列——它们是同一类 设置:一个会话以谁的身份运行。形态照 SandboxSection:主开关 + 开启后才出现的细项; 工具用复选框而不是两个独立 toggle,因为它们是一个功能的作用范围,不是两个能力。 后端复用 codexAuthSync 那条三层链路,与 /botconfig set 共用 applyConfigField, 两个门的校验不会漂移,拒绝原因原样透出。 新增 services/credential-bearing-mcp.ts:找出自带凭证的 MCP server。这类 server 用自己的 app 凭证直连、从不 exec 被包装的 CLI,所以这套策略根本触达不到它——agent 仍可通过它以与当轮发送者无关的身份读写飞书。 按「声明了凭证形态的 env key」检测,而不是按已知 server 名单:名单在别人写出新 server 的那一刻就过期了,而且「botmux 没认出来」不是一条安全性质。APP_ID 不算凭证, 把它算进去会产生噪音、训练人忽略这条警告。 只警告不拦:硬拦会破坏合法用法(自配的飞书客户端有真实用途,botmux 也不拥有它), 但沉默比两者都糟——操作者会以为边界是完整的。假装覆盖了某样东西,比没覆盖更危险。 Dashboard 上把两条边界提示按 warning 样式显示(token 存储保护程度、自带凭证 MCP), 不混在普通 help text 里:不能让人一眼扫过「agent 能读到别人的 token」这句话。 /status 增加当前身份行,只报**问的这个人自己**的授权状态——谁还授权过是成员关系, 群成员没有理由从 /status 得知。 顺带修掉一处自己引入的问题:askpass 测试里写死了内部域名,被仓库自带的 audit:domains 守卫拦下,已改成 example.com。 新增 11 个 MCP 检测测试;npm run build 通过。 Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): 关闭时不引入 await 边界,并修好受影响的测试 mock 全量单测暴露两类问题,都是我引入的。 一、关闭状态下也改变了轮次时序(真 bug,不只是测试问题) noteTurnReceived 里我加的 `await refreshTurnCliIdentity(...)` 是无条件的,于是 **每个 bot 的每一轮**都会在后续同步记账之前多让出一个 microtask,重排了 single-flight 路径依赖的并发顺序——daemon-rename-route 的「并发 get-or-create 串行化」因此失败。 一个关闭的功能不该改变任何时序。改成先做同步的启用判断,只有真正开启的 bot 才 进入 await。 二、测试 mock 跟着实现签名更新 - feed-group 三个测试文件 mock 的是 resolveUserToken,但实现已改用 resolveOwnerUserToken(标签是 owner 自己收件箱里的东西),于是打到了未 mock 的 真实函数。 - command-handler 三处断言按旧的 3 参 generateAuthUrl 写死;新增的第五参正是本次 的重点,断言改成显式盯住发起人 open_id,而不是放宽成 any。 daemon-rename-route 79、command-handler 302、feed-group 三个文件、以及本功能自身 的测试合计 491 个全过。 另外确认 test/bun-shim-parity.test.ts 的 1 个失败在 origin/master 上同样存在 (已用干净 worktree 对比),与本改动无关,不在此处理。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): 吸收 Orchestra 的三条 git 归因加固 从 @byted/orchestra 二进制里读到的三条实践,都是我们原实现有同样暴露的: 1. 调 bytedcli 前置 GIT_CONFIG_COUNT=0 GIT_SSH_COMMAND=false。这个 helper 本身 是被 git 调起来的,而 bytedcli 又会 shell out 到 git 取仓库上下文——不重置的话 内层 git 会重新读到调用我们的那份 credential 配置,可能递归,也可能悄悄走 SSH 用机器身份完成认证。我们原来的 askpass 有完全相同的风险。 2. bytedcli 取不到 JWT 时,用 ByteCloud JWT 直接换 Codebase JWT 兜底。bytedcli 缺失或正在升级时,原实现会让每次 push 变成一个没有解释的鉴权失败。 3. url.<host>.insteadOf 把 SSH 远端改写成 HTTPS。SSH 是这条链路上最安静的逃逸口: 仓库一旦是 SSH clone 的,就继续用机器的 key,推送落在机器身份下,而且不报错。 两个新配置项 gitHost / gitTokenExchangeUrl 走配置而不是写死:端点是部署相关的, 而且本仓库有域名门禁,不允许把私有主机名写进源码。校验也因此收紧——host 必须是 裸主机名(它同时被插进 git config key 和 shell 脚本),exchange URL 必须 https (它承载的是活的 JWT)。 git 配置通过 GIT_CONFIG_* env 下发,只作用于本会话的 git,不碰用户自己的 ~/.gitconfig。 新增 7 个测试(含用桩 curl 跑真实 sh 验证兜底链路、以及 host 注入用例), 相关 230 个测试全过,build 与域名门禁通过。 Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): 加 agent 侧凭证边界,作为本期的明示约束 本期不做内核级隔离,所以这段提示词是唯一的防线——那就必须写清楚它防什么、 不防什么。 内容四条:本会话的凭证由 botmux 每轮注入(不需要自己找)、data/ 下别人的 user-token-* 不得读取列举复制输出、任何 token 不得进消息/日志/文档/提交、 鉴权失败时如实上报并提示 /login 而不是翻找其他凭证。 第一条和第四条是刻意加的:光说「不许读」会让一个正在排查鉴权失败的 agent 无路可走——而这恰恰是它最可能去翻 data 目录的时刻。给出替代路径才真正减少 翻找。 两条 prompt 链路共用同一个 buildCredentialBoundaryBlock:claude 系走 --append-system-prompt,codex/gemini 等走 session-manager 内联。只加一边的话, 另一边的 CLI 会完全没有约束——而这一期它是唯一防线,缺一边就是个静默的洞。 明确边界(注释和 commit 都写了):这是行为约束不是安全控制,挡不住有意的用户, 也挡不住 prompt injection。它针对的是最可能真实发生的那种情况——agent 排查问题 时顺手 grep 数据目录。实测过内核隔离能挡住这些(cat/tmp sidecar/后建文件全部 DENIED),但那条留到下一期。 关闭时不产生任何提示词;bot 配置读不到时按未开启处理,绝不凭空声称有边界。 新增 9 个测试;相关 87 个测试全过,build 与域名门禁通过。 Co-Authored-By: Claude Code <[email protected]> * fix(login): match auth prompt to the real callback mode The /login prompt hardcoded the manual paste-back steps: 'the browser will show ERR_CONNECTION_REFUSED, this is normal', 'copy the URL from the address bar, press F12 if you cannot see it'. With oauthRedirectBase configured the Dashboard completes the exchange on its own, so those steps describe a failure that never happens and send people hunting through DevTools for nothing. Branch the prompt on resolveOAuthRedirectUri(). The auto path keeps one fallback line about pasting the address bar, so a user who lands on an error page still has a way forward instead of a dead end. Applies to all three prompts (/login, /login tags, /subscribe-lark-doc), which had drifted into three copies of the same hardcoded steps. Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): refuse instead of falling back to the machine login Four fixes from PR review, the first of which defeated the feature entirely. **No credentials no longer means "run as the machine account."** The wrapper exec'd the real tool whenever no identity file was published, on the premise that lark-cli with no env runs as the bot. It does not. Measured: env -u LARKSUITE_CLI_APP_ID -u LARKSUITE_CLI_USER_ACCESS_TOKEN lark-cli whoami => identity: user, onBehalfOf: <the operator> lark-cli falls back to the operator's on-disk login, so every unauthorized turn ran with the machine owner's full permissions — silently, and under their name in the audit trail. The earlier `--as bot` check that seemed to confirm the premise had itself run on a logged-in machine. Running as the bot needs LARKSUITE_CLI_APP_ID + LARKSUITE_CLI_APP_SECRET, which does resolve `identity: bot` even with a user logged in on disk, and `--as user` on top of it then fails token_missing rather than reaching back to those credentials. So the file now carries an explicit mode: user, bot, or denied. Anything else — absent, empty, truncated mid-write, or an env-injected marker — is refused with exit 77. A denial names whose authorization is missing and says to send /login, because a bare refusal just gets retried. **A turn with no sender no longer borrows the last human who spoke.** `?? ds.session.lastCallerOpenId` meant a scheduled run or hook executed with the credentials of whoever last talked to the session. **A failed authorization read-back no longer guesses.** When user_info could not say who authorized, the token was filed under whoever requested the link — but a /login link can be forwarded, so that guess files B's credentials under A, after which A's every command runs as B. Now nothing is saved and the user is told to retry. Covers non-2xx, code != 0, missing open_id, and network failure. **/status reports each tool separately.** One combined verdict claimed "you are authorized" for bytedcli on the strength of a Lark token, which cannot authenticate it. Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): bind published credentials to the turn they were issued for The daemon publishes an identity when a message is ACCEPTED, but the CLI runs turns off its own queue. So while A's turn is still executing, B's message can arrive, overwrite the identity file, and A's remaining tool calls run with B's permissions — the exact misattribution this feature exists to prevent, reached by ordinary type-ahead rather than anything adversarial. The daemon cannot close this alone: input goes straight to the worker over IPC, and the worker does not wait for the daemon before starting a queued turn. Publishing on the worker's turn-start signal would shrink the window, not remove it. So both sides now state a turn and the wrapper compares them. Each identity carries the turn it was published for; the worker publishes the turn it is actually executing (riding writeCliPidMarker, which every site that changes currentBotmuxTurnId already calls — including the ones that bypass the normal queue); a mismatch refuses with exit 77 and says to retry after the current turn. Enforced only when both sides state a turn, so identities published before this change and sessions with no live turn still run. The cost is deliberate: tool calls in the tail of A's turn fail once B has spoken. A failed command is recoverable; one that silently ran as the wrong person is not. The turn file needs its own sandbox grant and placeholder — the fs-policy allow-list existence-filters at spawn, so without both a sandboxed session would read nothing and refuse every governed command. Verified against the repo's own buildSeatbeltProfile with canonicalized paths: this session's turn and identity files are readable, another session's are denied by the OS. Co-Authored-By: Claude Code <[email protected]> * feat(trigger-user-auth): per-person bytedcli authorization Closes the gap left by the earlier claim that bytedcli "only has SSO personal login" and therefore could not run as the triggering person. That was wrong, and I never tested it: bytedcli has a complete non-blocking device-code flow, and the env vars botmux already injects are ones the binary really reads. Measured, in a clean environment rather than on my logged-in machine: BYTEDCLI_USER_CLOUD_JWT=<bogus> bytedcli auth userinfo => HTTP 401 invalid jwt token (not a silent fall back to my login) HOME=<empty dir> bytedcli auth status => not logged in (while I am logged in on this machine) So HOME is a real isolation boundary, and each person gets their own under ~/.botmux/data/bytedcli-home/<openId>. /login bytedcli starts the flow and returns the link; /login bytedcli done resumes it with a token kept inside that person's own HOME, so nobody can complete somebody else's login. We store the directory, not the JWT. The ByteCloud JWT lives ~2 hours while the login behind it lives ~3 weeks, and bytedcli refreshes it internally — verified by crossing an expiry: a token that expired at 01:48:03 was replaced by a fresh one (iat 01:48:08) with no human involved. Storing the JWT would have sent everyone back to a QR code every two hours to renew something still valid. So the JWTs are minted per turn, and a person is interrupted only when the 3-week login genuinely ends — which lands on the existing refusal path. A refusal now names the right command: telling a refused bytedcli user to send /login would have sent them to authorize Feishu again and fail identically. The per-person HOMEs are deny-by-default under the file sandbox and stay that way: the daemon mints the JWTs, so the agent never needs to read them. Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): name the right provider, and stop printing open_ids at people Both found by running the real publication path against business-agent's actual config on an isolated daemon, rather than against test fixtures. A bytedcli refusal said "需要「…」本人的飞书授权" — the wrong identity provider. bytedcli authenticates against ByteCloud, so this sends the reader off to authorize Feishu, which cannot fix it. Same class of mistake as naming the wrong /login command, in the sentence right above that command. And the name it used comes from a stored Lark token, which someone being refused for lack of authorization generally does not have — so the fallback printed the raw open_id: 「ou_42edf6b433d3daf02916a039e41531ef」本人. That path is the common one here, not an edge case. With no name we now address the reader directly ("你自己的 ByteCloud 授权") instead of reading an id back at them. Co-Authored-By: Claude Code <[email protected]> * style(trigger-user-auth): space around the provider name in refusals '你自己的ByteCloud授权' ran the Latin name straight into the Chinese text. Visible in the real refusal on the E2E daemon. Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): survive path_helper, and say so when unprotected The feature did not work at all in production, and every unit test passed anyway. Found only by running it against a real bot with a real message. Prepending the wrapper dir to the child's PATH is not enough. The agent's tool calls run through a LOGIN shell (`bash -lc` / `zsh -lc`), which sources /etc/zprofile, which runs /usr/libexec/path_helper. That helper rebuilds PATH from /etc/paths + /etc/paths.d and APPENDS whatever was already there. Measured on this machine: the wrapper dir went from position 1 to position 12, while /opt/homebrew/bin — owned by /etc/paths.d/homebrew — landed at 10. So the real lark-cli won every time, and calls ran as the machine account. Against the real binary: zsh -lc 'lark-cli whoami' before: identity: user (the operator) after: identity: bot (appId cli_aacc…) The fix is our own startup file, re-prepending after path_helper has had its say: ZDOTDIR for zsh (.zprofile — a non-interactive login shell skips .zshrc, verified), BASH_ENV for bash. Both are per-process, so no dotfile is touched and no other shell on the machine changes. Each shim sources the user's real startup file first, so their PATH edits still apply and ours goes back in front after them. Why the tests missed it: they called the wrapper script directly, proving it BEHAVES correctly, never that the agent's invocation REACHES it. The new tests run actual bash and zsh login shells, and include the negative control — the same shell without the shim resolves the real tool — so the assertion cannot pass for the wrong reason. Also: when no wrapper could be installed at all, the session ran completely unprotected in silence. That is what made this so hard to see — the agent reported the machine identity as "normal". It now warns explicitly. Co-Authored-By: Claude Code <[email protected]> * fix(trigger-user-auth): forward identity vars to codex shell commands; drop the guessy notice Two problems, both found by running the feature against a real bot. **codex strips the identity vars before any shell command runs.** Codex does not hand its own environment to the shell subprocesses it spawns — our own comment says so (codex.ts:227) — and the `inherit="all"` that compensates is added only under read isolation, which this bot did not have. So the chain was: worker sets BOTMUX_IDENTITY_BIN / ZDOTDIR / BASH_ENV, tmux forwards them (fixed in the previous commit), codex drops them, and `lark-cli` resolves the machine owner's login. Three separate filters between the worker and the tool; this is the third. GIT_ASKPASS rode the same path, so git attribution had never worked in a tmux session either. Declared per key via `shell_environment_policy.set` rather than `inherit="all"`: the need is exactly these variables, and inheriting would hand every shell command the whole worker environment. **The chat notice guessed, and guessed wrong.** It fired at message-acceptance, before the agent had chosen a tool, and named every governed tool without credentials — ask for lark-cli, get told to authorize bytedcli too. Being once-per-session, it then stayed quiet on the one occasion it would have been right: when a bytedcli call is actually refused. Removed rather than narrowed. The wrapper's stderr already says which tool was refused and which command authorizes it, at the moment of refusal, every time — the notice was a worse copy of information we already produce at the right time. Co-Authored-By: Claude Code <[email protected]> * test(trigger-user-auth): skip login-shell cases when the shell is absent CI runners do not all ship zsh; spawnSync ENOENT failed the suite. The bash case still proves the mechanism. Co-Authored-By: Claude Code <[email protected]> * feat(login): request document read scopes by default, and support /login --scope "Read the doc I just linked" is table stakes for an assistant and did not work: the default scope set was three IM scopes picked when the only consumer was chat-image download, so an authorized person still hit `99991679 missing_scope` on their first document. Seven read-only scopes now ship in the default set — docx + legacy docs bodies, drive metadata and search, wiki resolution, and sheets. They are one closed loop rather than a pick-and-mix: a link opens, a name is findable, a wiki URL resolves to its token, and docs and sheets both read. Dropping any one produces a plausible-but-broken assistant — docx without wiki fails on the wiki links most internal documents actually use. Read-only on purpose. A write scope turns "the agent misread something" into "the agent edited your document", and nothing in this path writes. Contact (the whole company directory), calendar and file download are excluded for the same reason: not needed to read a document. For everything else there is `/login --scope <names>`. Feishu already returns a structured `missing_scopes` array, so the names can be copied straight from the refusal — no hand-kept mapping, no giant default set that makes people approve permissions they will never use. Names are validated against the same lark-scopes.json catalog `botmux setup` uses, because a typo does not degrade: it makes the whole authorize URL fail with 20043 and the person is handed a link that simply will not open. (That has happened here before — 487e297, a bare `docs:document.comment`, which is not a real scope. Writing these tests I reached for `docx:document`, which is not one either; the catalog caught it.) The agent gets one prompt line for the case too, because missing_scope is not "not authorized": sending someone through a plain /login re-grants the same scopes and fails identically. Co-Authored-By: Claude Code <[email protected]> * fix(user-token): let every reader find a per-person token (review F1) Per-person storage was only half done. `/login` writes `user-token-<app>-<openId>.json`, but five consumers looked tokens up WITHOUT the openId and therefore found nothing — the person authorizes, is told it worked, and the feature still reports "not logged in" with no error anywhere. Nor did it wait for the feature to be enabled: three of the five are on the default path. The legacy per-app file masks it until that file expires, so the breakage lands the first time someone re-authorizes — routine, not an edge case. `/subscribe-lark-doc` loops outright: authorize, retry, be asked to authorize. Fixed at the readers rather than by double-writing a per-app copy. A copy goes stale within hours (refreshToken only rewrites the per-person file), and for feed-group — the owner's own sidebar — it would operate that sidebar with whoever logged in last. client.ts pass senderOpenId unconditionally, not only when the policy is on: the openId is just a lookup key, and with the policy off it selects the same person it always meant command-handler.ts /subscribe-lark-doc precheck keys on message.senderId, the same person its authorize link is generated for doc-comment.ts resolve by subscription owner in both branches; the ungated one was a keyless lookup that silently degraded to the tenant identity, so attribution was quietly wrong while the API kept answering feed-groups.ts derive the owner via getOwnerOpenId(); `ownerOpenId` is a raw bots.json field almost nobody sets (0 of 55 bots in the reviewer's fleet), so it was passing undefined dashboard-ipc same for the badge and for the authorize link, which additionally restores the "was this link forwarded to someone else?" check the command path already had audio-transcribe thread the speaker through downloadMessageResource Tests cover the contract — a token written the way /login writes it is readable by the callers that consume it — rather than any one call site's arguments, which a refactor would drift away from. The reviewer noted this path had zero coverage: a double-write mutation left all 29 existing tests green. Also from review: lookupAuthorizedUserName now gets the bot's brand (a Lark-brand bot lost the person's name from refusals), a duplicated JSDoc block above renderGitAskpassScript is gone, hydrateTruncatedReplies passes fileTokenForIdentity, and the wiki get_node call documents why it cannot. The negative-control shell test now asserts "the wrapper did not win" instead of "resolved the real tool". botmux's fleet runs as root, where /etc/profile overwrites PATH and neither directory survives — the old assertion failed on exactly the machines the control matters most on, and skipping there would have switched it off precisely when it should run. Co-Authored-By: Claude Code <[email protected]> * test(trigger-user-auth): resolve the shell on PATH instead of spawning it The availability probe ran a real shell per shell per worker, on top of the login shell each case already spawns. bun-test then failed a DIFFERENT test on every CI run — child-env's node-pty child got empty output, tmux-startup-storm was SIGKILLed — while master stayed green and each failing test passed alone. That shape is resource exhaustion, not an assertion, and these were the newest process-spawning tests in the suite. A PATH lookup answers the same question for free. Co-Authored-By: Claude Code <[email protected]> * test(trigger-user-auth): 覆盖 inline 路径的凭证边界块 rebase 到含 #998 的主干时,opening 的分块从 `parts.push(文本)` 改成 `blocks.push({key, text})`,凭证边界块要跟着改并新增 `credentials` key。 这个落点原先零测试覆盖——`credential-boundary-prompt.test.ts` 的文件头写着 覆盖两条 prompt 路径,实际只 import 了 buildBotmuxSystemPromptText, inline 路径(codex/gemini 等)一条断言都没有。删掉 push 全套测试照样绿。 补三条走 buildNewTopicPrompt 的断言:开启时含 <botmux_credentials>、 关闭时不含、拿不到 bot 配置时不含。变异验证:删掉 push 立刻转红。 `credentials` 刻意不进 ENVELOPE_KEYS。当前这个选择是惰性的——hook 模式要求 supportsInvisiblePromptHook(仅 claude-code),而 claude-code 有 injectsSessionContext、根本不走这个分支,所以 hook 模式下永不产生 credentials 块(已实测)。仍然保留在 PTY 文本,是为了将来别的 CLI 具备 hook 能力时不至于静默丢块:envelope 读不到时不会报错,只是约束消失。 Co-Authored-By: Claude Code <[email protected]> --------- Co-authored-by: Claude Code <[email protected]> Co-authored-by: 申晗 <[email protected]>
改了什么
#794 后续:把
<sender>与<mentions>从 PTY 文本搬进 UserPromptSubmit hook 的 system-reminder,并去掉<user_message>外壳,让用户输入框只剩消息正文。模型经 hook envelope 仍看得到发送者与提及,--mention决策与 A2A 归因不受影响。userMessage块在 hook 模式下输出纯正文buildNewTopicPrompt重构为 blocks 结构(inline 输出字节不变),buildNewTopicCliInput在 hook 模式下把 whiteboard/sender/mentions 写进 sidecar、PTY 文本只剩正文buildReservedInitialInput(主 opening 路径)、card-handler repo-selection、live-worker empty-start 首轮、worker-null refork opening(empty-start 丢 worker 后的首条真实 turn)。raw 命令冷启动的 buffered follow-up 走 raw_input IPC 延迟发送,turnId 权威流不同,暂保持 inline;queued dashboard 场景 turnId 是合成的,同样保持 inline为什么
用户反馈输入框里
<user_message>/<sender>/<mentions>标签是噪音。reminder/whiteboard 已在 #794 搬进 hook,这次把剩余的 per-turn 归因元数据也搬进去,输入框只剩正文。影响面与权衡
collectBotmuxSessionIdentities()按文件名(=sessionId)排除,不依赖 transcript 内容,已关闭会话不会漏进 picker。transcript 标记正则仍匹配 inline 模式与旧会话,作为跨机/丢库的兜底prepareSessionSkillPrompt会把 skill catalog 追加到 prompt 尾部。sidecar 按「catalog 追加前」的 ptyText 写指纹,hook 看到的是 ptyText+catalog → 全量指纹失配 → 靠 prefix 兜底(前 30 归一字符)。当 ptyText 归一化后 ≥30 字符时 prefix 不受尾部追加影响,可靠救回;当正文 <30 字符且配了 priority skills 时,prefix 会被 catalog 头污染,该 opening 轮的 sender/mentions/whiteboard 静默丢失(fail-open,正文仍在,模型只是看不到这轮的发送者/提及)。可达条件窄(envelopeInjection=auto+ 配了 priority skills + 正文很短),属 latent。根治(hook 端剥掉尾部 catalog 再算指纹)或加 guard 留 follow-upextractBotmuxLarkNativeSessionTitlePrompt有?? rawContent兜底,不受影响envelopeInjection=auto+ hook 已装 时生效测试
pnpm build通过prompt-hook-injection(含 opening 5 例:hook 模式 PTY 只剩正文 / 缺 turnId 回退 inline / off 完全 inline / envelope 为空回退 inline / skill catalog 追加后 prefix 兜底仍能 claim)prompt-builder、card-handler-repo-select、resumable-session-discovery、bridge-turn-queue、session-title、prompt-context-store、ipc-prompt-ctx-claim-route、scheduler-silent-execute、initial-user-turn-opening等相关套件全绿(300+ 例)