Skip to content

feat(auth): 支持飞书私聊完成 TRAE 企业重登 - #3955

Merged
deepcoldy merged 4 commits into
deepcoldy:masterfrom
fangyeqing:feat/lark-trae-login
Nov 28, 2026
Merged

deepcoldy merged 4 commits into
deepcoldy:masterfrom
fangyeqing:feat/lark-trae-login

Conversation

@fangyeqing

Copy link
Copy Markdown
Contributor

TRAE 凭证无法刷新时,AI 会话本身无法执行重登请求。新增 /dashboard trae-login,由 daemon 通过既有 sessionless 管理员入口发起原生企业登录:私聊发送授权链接,用户完成网页 SSO 后在同一机器人私聊提交完整 loopback 回调,CLI 验证并保存登录;status 查看结果,cancel 取消。登录成功后用户恢复原话题并重发消息。

请求绑定应用、管理员、随机请求 ID 和 TRAE_HOME;发布链接、提交回调、终态以及等待期间复核权限和配置。Linux 原生进程继承内核 flock 锁,并通过 setpriv 的父进程死亡信号处理 daemon/supervisor 崩溃。敏感回调(包括格式错误、富文本和历史 REST 重复正文)在控制路径校验,排除模型输入、日志、hooks、durable Inbox 和恢复重放。

支持范围为 Linux 宿主的原生 TRAE CLI,需要 flock/setpriv。共享 TRAE_HOME 的会话使用同一账号;远程后端、wrapper/Forge、沙箱和设备凭证隔离使用各自登录入口。

验证记录:

  • 上游 PR 分支:bun run build 通过。25 个文件回归共 2420 项通过、2 项跳过;首轮两个超时用例在 bun run test --maxWorkers 1 test/env-policy-cli.test.ts test/revoke-trigger-user-auth.test.ts 中重跑通过(25 项)。剩余 3 条 DSH 路径断言在未修改的 ac56aaf 基线也失败。
  • 真实独立 TRAE_HOME 上验证登录协议;daemon 和 supervisor 分别 SIGKILL 后 native 退出并释放锁,第二请求互斥成立。
  • 取消、撤权、配置切换、迟到私聊失败、deadline、并发 complete、SQLite 关闭重开及 DEBUG/hook 隐私探针通过;移除三处关键守卫得到对应 4 个预期失败。
  • 完整账号 SSO 闭环需要账户本人操作。

上游移植验证:2,592 组既有路由与基线一致,callback 的控制路由、capture journal、hooks 和 DEBUG 隐私探针通过。Linux 本机已部署同一功能实现,并确认 daemon 入口和会话恢复。

实际运行的广泛回归命令
bun run test --maxWorkers 4 test/trae-login.test.ts test/trae-login-message.test.ts test/dashboard-trae-login.test.ts test/dashboard-command-c1.test.ts test/dashboard-command-link.test.ts test/command-handler.test.ts test/command-router-oracle-diff.test.ts test/command-router-cascade.test.ts test/command-router-dash.test.ts test/command-schema.test.ts test/slash-commands-doc-sync.test.ts test/cli-adapters.test.ts test/env-policy.test.ts test/env-policy-cli.test.ts test/child-env.test.ts test/file-lock.test.ts test/trigger-user-auth.test.ts test/trigger-user-auth-status.test.ts test/revoke-trigger-user-auth.test.ts test/event-dispatcher.test.ts test/durable-inbox-shadow.test.ts test/durable-lark-primary-ingress.test.ts test/durable-inbox-shadow-consumer.test.ts test/durable-inbox-primary-consumer.test.ts test/hook-runner.test.ts

- event-dispatcher 增加 primary/shadow 两条用例:TRAE 登录回调不进
  durable primary inbox、不进 shadow Inbox,但仍走活路由;普通消息照常
  入队作阳性对照。摘掉任一门控对应用例即红(变异验证)。
- dashboard 帮助卡片 en/zh 的 trae-login 条目各重复一行,删掉重复项。

Co-Authored-By: Claude Fable 5 <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:发现 2 个阻断项,暂不建议合并

复审 head:9678734c7ef1ffb76bf04937b09f145a2ec0b107(包含追加的 9678734c)。

[P1] 群回调在进入 private_only 拒绝前,仍会写入群上下文并进入秘书观察链

src/im/lark/event-dispatcher.ts:6210 的 ingestGroupContextEvent(...) 和 :6212 的 observeGroupSecretaryMessage(...) 位于命令处理之前;而群回调的拒绝发生在更后面的 src/core/dashboard-command/trae-login.ts:60。因此这两条旁路仍会看到完整回调 URL。编辑事件还有同类入口:src/im/lark/event-dispatcher.ts:7827。

实机探针使用真实 ingestGroupContextEvent + group-context-store,在 group context 开启时提交带合成 secret 的群 complete 消息,结果为:

outcome=stored
persistedSecret=true
text=/dashboard trae-login complete req-1 http://127.0.0.1:1234/authorize?token=GROUP_CONTEXT_CALLBACK_SECRET

这直接违反“群聊拒收且不写持久化存储”的安全边界;秘书链还可能把正文保留为后续上下文。建议在 receive、updated/历史恢复的所有群上下文与秘书观察入口之前统一排除该敏感控制输入,同时保留它到 live 命令处理器的路由以返回 private_only。回归测试需开启真实 group context,并用普通群消息作阳性对照。

[P1] 回调识别与实际消息解析不一致,可绕过 primary/shadow/recovery 门控及 DEBUG 打码

src/services/trae-login-message.ts:10-31 独立递归收集字符串后用空格连接,并且只在 mention key 后有空白时剥离;实际 parser 对同段相邻 post 节点是无空格拼接(src/im/lark/message-parser.ts:1153-1155),stripLeadingMentions 也不要求 mention 后有空白(:852-871)。所以“实际会被识别为 complete 命令”的输入,隐私谓词却可能返回 false。

已用真实 parser + durableLarkMessageEvent 复现两种形状:

  1. post 同段相邻 text 节点把 complete 拆成 comp + lete:parsed.content 是正常的 /dashboard trae-login complete ...,但 isTraeLoginCallbackEvent(...) === false,序列化后的 durable 行仍含合成 secret。
  2. text 事件以 @_user_1/dashboard trae-login complete ... 开头且带对应 mention 元数据:stripLeadingMentions(parseEventMessage(...)) 得到正常 complete 命令,但隐私谓词为 false,durable 行同样保留 secret。

由于 dispatcher 门控和 src/services/durable-inbox-shadow.ts:133 的兜底共用这一谓词,两处会一起漏判;src/im/lark/message-parser.ts:565 的富文本 DEBUG 打码也会漏掉第一种形状。建议让隐私分类与路由复用同一个 canonical command-text 提取实现,而不是维护第二套递归文本拼接/mention 规则;上述两种形状都应同时覆盖 live 路由、durable 序列化和 DEBUG 日志测试。

验证与 CI

  • 本地 bun run build 通过。
  • PR 相关 4 个 Vitest 文件:834 项通过;共享路由/持久化等 9 个文件:326 项通过;额外命令与 test-hygiene 回归:82 项通过。
  • 3 个 Bun 兼容的 PR 新测试文件:46 项通过(event-dispatcher 因 vi.hoisted 属现有 Bun deferred 集合,由 Vitest 覆盖)。
  • CI attempt 1 已结束:Vitest test 4/4、build、各二进制与 network-boundary 均通过;Bun 2/4、3/4、4/4 通过,但 1/4 在既有 test/plugin-supervisor.integration.test.ts:340 失败(期望进程退出时仍为 alive)。该文件不在本 PR diff 中,本地同文件重跑 19/19 通过;仍需重跑 CI 恢复全绿。

- 用依赖自由的文本/AST 分类替代不一致的递归拼接:post 无空格拼接相邻节点并只剥离真实前导 at,text 只剥离可证明的 mention;malformed 输入不再 fail-open,普通紧贴 mention 的讨论不误伤。
- 在 input-capture、group-context live/edit/REST history/publication、secretary 实时/backfill 的共用入口排除敏感回调,保留 durable 既有门控与群命令的 private_only 拒绝。
- 补 canonical 路由一致性、真实 capture journal、REST 回填后下一 turn、durable/群存储不落地及普通消息阳性对照;相关守卫的变异验证均咬红。

Co-Authored-By: Kimi <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

追加修复:ab9e5e058d

已按 fast-forward 推到作者分支,未改历史提交、未同步 master。

修复内容

  • 回调分类:改为依赖自由的文本/AST 分类。post 同段相邻节点无空格拼接,前导 mention 只按真实 at AST 剥离;text 只剥离可证明的 structured mention / @_user_N / 完整 <at>。对无元数据的紧贴命令使用窄回退,不再用会吞掉普通正文的通用 @\S+。
  • 异常 fail-closed:post null 节点、缺失 mention 名称等 malformed 形状仍可识别并打码,不再把解析异常等同于普通消息。
  • input-capture:在同步 pre-ACK 入口排除回调,durable claim 后的同一 capture 实现也复用该边界。
  • 群背景:live receive/edit、chat/thread REST history、publication 共用敏感输入过滤,避免“live 跳过、回填又写入”。
  • secretary:实时观察与重启 backfill 共用转换入口过滤;普通讨论仍保留,群 complete 仍由命令层返回 private_only。

对抗探针复验

  • 真实 input-capture runtime + JSON journal:claimed=false、inputCount=0、journalHasSecret=false。
  • 真实 REST preparer + SQLite:storedAfterBackfill=false,首轮及清空 REST 后的下一 turn 均无 secret。
  • malformed post / mentions:redaction 与 durable payload 均无 secret。
  • inline mention 正负对照:回调从 durable/secretary 排除;@Bot请解释 /dashboard ... 普通讨论不误判、不打码。

本地验证

  • bun run build:通过。
  • 相关 Vitest:20 个文件、1361 项通过。
  • Bun 兼容扩展集:7 个文件、138 项通过。
  • 变异验证:隐私分类、pre-ACK capture、group live ingest、REST history、secretary、parser DEBUG、inline AST、窄 text 回退等守卫摘除后均咬红,现已全部还原并复跑通过。
  • 完整 Vitest unit 正在后台运行,尚未计入通过项;新 head 的 CI 已触发。

@deepcoldy

Copy link
Copy Markdown
Owner

完整本地 unit 补充结果(非通过)

上一条所述完整 Vitest unit 已结束,不能记为全绿:

Test Files  54 failed | 3327 passed | 18 skipped
Tests       130 failed | 66296 passed | 202 skipped
Errors      1

日志中可确认大量宿主相关失败,包括 tmux socket File name too long、/tmp 与真实缓存路径的软链接规范化差异,以及 worker/integration 超时。失败文件均不是本次追加提交修改的文件;本次新增及相关 20 个文件的定向回归仍为 1361/1361 通过。

为避免把失败一概归为并发,另抽取 grok-transcript、host-terminal、turn-idle-version-skew、pi-transcript-locate、workspace-recycle 做隔离复跑,仍有 7 项失败(含软链接路径断言与 turn-idle 断言)。因此本地全量结果只作为未通过的环境/基线信号披露,不作为本修复的全量通过证据,也不宣称已完成完整基线对照。新 head 的 CI 结果仍需单独等待。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

合并树增量确认:17efd90fb9

合并树未发现异常,可按计划继续等待新 head CI。

Git 结构与自动合并一致性

  • GitHub API 确认 PR head 为 17efd90fb98ec15a5ee864d1ee8eb02150aec3d6。
  • parents 逐项匹配:p1=ab9e5e058dd48b9eca9d4548d2d0fed4335191b3,p2=64ada8a24ee7317b976ccfc826ca6cade2cd8521;两者均为 head 祖先。
  • commit tree 为 9283b4c153e676cacb77f0dab18ba26bc8c641dd。
  • 本地从 merge-base ac56aaf7f4 独立执行 git merge-tree --write-tree ab9e5e058d 64ada8a24e,预测树与上述落地 tree 逐字一致。
  • git show --remerge-diff 只有 commit 头,没有额外冲突解决或手工编辑内容。

交集与 src/cli.ts

实际变更文件交集为:src/cli.ts、src/daemon.ts、src/i18n/en.ts、src/i18n/zh.ts。

最终合并 diff 的 runner hunk 头为 @@ -22849,6 +22859,10 @@,与所述 22859 一致;其中 else if (__entrySubcommand === 'trae-login-runner') 的实际代码行是 22862。#3953 的 cmdSend 变更仍位于前面的独立 hunk(最终统一 diff 覆盖 14406–17343 一带),与 runner hunk 不相邻。

本地实测

本地工作区已 fast-forward 到 17efd90fb9,并确认 build 后 tree 未变、工作区干净:

  • bun run build(含 tsc/typecheck):通过。
  • PR 与 master 两侧 12 个文件:1029/1029 通过,包含 TRAE 回调隐私/input-capture/REST 回填/secretary、card-reply-text、cli-send-turn-reply-relay、worker-scheduled-deferred-retain 和 owner-actor-strict-owner。
  • 本次仅本地 fast-forward 与验证,未创建或推送新提交。

CI 状态

新 head 首跑中,目前 build、network-boundary、bun-binary-darwin、bun-binary-musl 已通过,其余测试与二进制项仍 pending;本确认不等同于 CI 全绿结论。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

73211965d6 核对通过,但 master 已再次前进,不能直接套用

对指定合并树的独立核验

  • merge commit 9beb58c982271007cc0eb4c54506d3deedc15f71 的 parents 为 17efd90fb9 + ff23ee10c,tree 为 73211965d6748ad9e193ab8ea41446e3b4e55648。
  • 独立执行 git merge-tree --write-tree 17efd90fb9 ff23ee10c 得到同一 tree;--remerge-diff 无额外冲突解决内容。
  • PR 与这段 master delta 的实际交集只有 src/cli.ts。
  • 最终 hunk 行号匹配:master cmdSend hunk 为 src/cli.ts:14889,PR runner hunk 为 :22863,相隔 7974 行;runner 的 else if 实际代码行为 22866。
  • 当前 worktree 使用独立 node_modules(非共享 symlink)。fast-forward 到该合并后执行 bun install --frozen-lockfile:成功,778 个安装项检查完成、无依赖变更。
  • bun run build(含 tsc/typecheck):通过。
  • 两批互不重叠的 PR/master 回归共 14 文件:1463 通过 / 3 跳过 / 0 失败,包含全部 TRAE 登录与隐私边界、merged-turn-reply-card、dashboard-ipc、desktop bundled runtime、card-reply-text 和 CLI relay。
  • 验证后工作区干净,HEAD tree 仍为 73211965d6;未推送该 merge。

阻断直接 squash 的新情况

复核期间 origin/master 已从 ff23ee10c 前进到 fb2c57d1bb332db27dcfa062a6bf199c9e266f8d(#3956),GitHub API 也确认该 tip。因此按约定,上述旧树结论不能直接用于 squash。

补算最新结构:

merge-tree(17efd90fb9, fb2c57d1bb) = 464b47d602b9071e6a49565801ac33c83c6d1685

该预测合并无冲突;#3956 单独的 17 个变更文件与 PR 自身 32 文件无交集。但这不替代新合并树的落地 tree、build 与测试核对。请以最新 master 重做合并后再按同一套确认,不要用 73211965d6 直接放行。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新合并树确认:464b47d6

指定合并树未发现异常,可按所述流程继续;我没有推送或合码。

结构与交集

  • 合并 commit:0903c5a9df111737d4930985a808729a8747c58d。
  • parents 逐项匹配:17efd90fb98ec15a5ee864d1ee8eb02150aec3d6 + fb2c57d1bb332db27dcfa062a6bf199c9e266f8d。
  • 独立执行 git merge-tree --write-tree 17efd90fb9 fb2c57d1bb,预测树与 commit 落地 tree 均为 464b47d602b9071e6a49565801ac33c83c6d1685;--remerge-diff 无额外冲突解决内容。
  • 以 PR 原始文件集对原始基线 ac56aaf7f4 以来的全部 master 变化核对,累计交集为 src/cli.ts、src/daemon.ts、en/zh i18n;从上一合并基线 64ada8a24e 到当前 master 的本段交集只有 src/cli.ts。#3956 最新段与 PR 零文件交集。
  • 最终 src/cli.ts hunk 为 master :14889、PR runner :22863,相隔 7974 行;runner 的 else if 实际代码行为 22866。

独立验证命令与结果

当前 worktree 使用独立 node_modules。切到 0903c5a9 后执行:

  • bun install --frozen-lockfile:通过,778 installs 检查完成、无变更。
  • bun run build(含 tsc/typecheck):通过。
  • 16 个 PR/master 回归文件:1517 通过 / 4 跳过 / 0 失败。覆盖全部 TRAE 登录与隐私边界,以及 #3956 的 traex-turn-completion、session-store-sqlite,#3959 的 merged-turn-reply-card,#3969 的 dashboard/desktop 相关测试,和此前的 card-reply-text、CLI relay、deferred-retain 回归。

验证后工作区干净,HEAD tree 仍为 464b47d602b9071e6a49565801ac33c83c6d1685。

最终基线复核

发布前已再次执行 git fetch origin master:FETCH_HEAD 与 origin/master 均仍为 fb2c57d1bb332db27dcfa062a6bf199c9e266f8d。可按你的计划在实际 squash 前再确认 tip,并在落地后核对 squash commit tree 与同一预测树。

@deepcoldy
deepcoldy merged commit f60e2d5 into deepcoldy:master Nov 28, 2026
37 of 43 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

感谢 @fangyeqing 的贡献,PR 已 squash 合入 master(commit f60e2d5,保留你的作者署名)。

这是自动评审的初步意见落地后的最终结果,最终以维护者审阅为准。评审过程中补齐了两处凭据边界(敏感回调在群旁听/input-capture/REST 历史回填等 sink 的隔离,以及富文本/mention 规范化与真实 parser 的一致性)和相应测试,均已包含在合入提交中。

未尽 follow-up(不阻塞本 PR):

欢迎继续贡献。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.37

Wait845 added a commit to Wait845/botmux that referenced this pull request Nov 30, 2026
上游 deepcoldy#3955 在旧群秘书的观察路径里排除了带凭证的 TRAE 登录回调;旧群秘书已删除,v2 读取群/话题现场时同样把这类消息替换为占位文字。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants