Skip to content

Add TuiTui platform support#849

Open
zzl360 wants to merge 1 commit into
chenhg5:mainfrom
zzl360:add-tuitui-platform
Open

Add TuiTui platform support#849
zzl360 wants to merge 1 commit into
chenhg5:mainfrom
zzl360:add-tuitui-platform

Conversation

@zzl360

@zzl360 zzl360 commented May 5, 2026

Copy link
Copy Markdown

Summary

  • add the TuiTui platform adapter with WebSocket callbacks, text/media delivery, access policies, and reply-context reconstruction
  • add TuiTui history reading, attachment download, and channel-post CLI commands
  • register TuiTui in selective builds, example configuration, documentation, and the Web UI
  • retain unmentioned TuiTui messages as context and consume them only when the engine accepts the next mentioned message for an agent turn

Scope

This PR is now a single TuiTui-only commit. Unrelated Codex prompt injection, send-command safeguards, cron, session, and general config changes were removed from the branch history.

The small core.Message.OnAccepted callback is platform-neutral infrastructure required by TuiTui so cached chat context is not consumed by slash commands, rejected messages, or queue failures.

Testing

  • golangci-lint v2.11.4 run --new-from-rev HEAD ./... (0 issues)
  • go test ./...
  • go test -race ./platform/tuitui
  • pnpm build / npm run build in web
  • make build PLATFORMS_INCLUDE=tuitui
  • make build PLATFORMS_INCLUDE=feishu

Review fixes

  • handle all cleanup return values and replace the conditional chain with a tagged switch
  • suppress outbound echoes by exact API-returned message IDs, including media messages
  • preserve explicit channel thread parents
  • use concurrency-safe WebSocket close control frames and keep event processing off the reader loop
  • paginate descending channel history toward older posts
  • redact TuiTui credentials from transport errors
  • reject ambiguous TuiTui project selection in CLI commands

Copilot AI review requested due to automatic review settings May 5, 2026 09:01
@zzl360

zzl360 commented May 5, 2026

Copy link
Copy Markdown
Author

tuitui是360集团自研IM,主要服务于360员工和相关生态伙伴

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class TuiTui platform support to cc-connect, covering runtime integration, build registration, web config metadata, and end-user setup docs so TuiTui can behave like the existing chat-platform adapters.

Changes:

  • Add a new platform/tuitui adapter with WebSocket ingest, policy checks, media handling, reply-context reconstruction, and tests.
  • Register TuiTui in build/config surfaces and add a plugin stub for selective builds.
  • Add web-form metadata, locale strings, and documentation links/setup guidance for TuiTui.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
web/src/lib/platformMeta.ts Adds manual-form metadata for TuiTui in the web UI.
web/src/i18n/locales/zh.json Adds new TuiTui-related field labels in Simplified Chinese.
web/src/i18n/locales/zh-TW.json Adds new TuiTui-related field labels in Traditional Chinese.
web/src/i18n/locales/ja.json Adds new TuiTui-related field labels in Japanese.
web/src/i18n/locales/es.json Adds new TuiTui-related field labels in Spanish.
web/src/i18n/locales/en.json Adds new TuiTui-related field labels in English.
README.zh-CN.md Lists TuiTui in the supported-platform table.
README.md Lists TuiTui in the supported-platform table.
platform/tuitui/tuitui.go Implements the TuiTui platform adapter and policy/media/session logic.
platform/tuitui/tuitui_test.go Adds unit tests and an opt-in real-connection smoke test.
Makefile Registers TuiTui in the selective platform build list.
docs/tuitui.md Adds the TuiTui setup and behavior guide.
config.example.toml Adds example TuiTui configuration.
cmd/cc-connect/plugin_platform_tuitui.go Adds the build-tagged platform registration stub.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web/src/lib/platformMeta.ts Outdated
Comment thread platform/tuitui/tuitui.go Outdated
Comment thread platform/tuitui/tuitui.go
Comment thread platform/tuitui/tuitui.go Outdated
Comment thread Makefile Outdated
Comment thread platform/tuitui/tuitui.go Outdated
@zzl360

zzl360 commented May 5, 2026

Copy link
Copy Markdown
Author

Addressed the Copilot review feedback in 81e3cc22:

  • added TuiTui to both web UI platform selection lists
  • changed TuiTui session keys to the core platform:channel[:user] format and updated docs/tests
  • kept channel posts gated by group_allow_from/explicit allow_from even with group_policy = "open"
  • added startup validation for group_policy
  • fixed mention parsing so trailing punctuation is not included in user IDs
  • documented no_tuitui in build-tag docs

Local verification:

  • go test ./platform/tuitui ./cmd/cc-connect
  • go test ./platform/...
  • npm run build in web
  • make build PLATFORMS_INCLUDE=feishu
  • make build PLATFORMS_INCLUDE=tuitui

@chenhg5 chenhg5 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.

Review Summary

Clean, well-structured new platform adapter following all established cc-connect platform patterns. CI is green across all 5 checks. MERGEABLE.

What's good:

  • init() + core.RegisterPlatform("tuitui", New) wiring ✓
  • app_id / app_secret validated at New() startup ✓
  • no_tuitui build tag for selective compilation ✓
  • All 5 i18n locale files updated (en/zh/zh-TW/ja/es) ✓
  • Web UI integration via platformMeta.ts
  • Documentation in docs/tuitui.md
  • 326 lines of tests covering DM, group, channel, and access policy paths ✓
  • TUITUI_APP_SECRET env var substitution in config.example.toml

💭 Nit (optional): Consider adding compile-time interface assertions at the package level (var _ core.Platform = (*Platform)(nil)) — other newer platform adapters include these and they catch drift immediately if the interface changes.

APPROVED.

@chenhg5 chenhg5 added P3 P3: 低优先级 / 建议 enhancement New feature or request pr-conflicting PR has merge conflicts and needs rebase or closure pr-needs-review PR needs maintainer or QA review labels Jun 6, 2026
@zzl360 zzl360 force-pushed the add-tuitui-platform branch 2 times, most recently from e0d5daa to e21864a Compare July 15, 2026 09:21

@chenhg5 chenhg5 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.

结论: Request changes

总体判断: PR 自 chenhg5 2026-05-05 approve 后, author zzl360 在 2026-07-15 09:21 / 10:11 / 10:39 推了 3 个新 commit (e21864a + 1871189 + 762c251),在 platform/tuitui/tuitui.go 引入了 5 个 lint violation (run 29408915690) — 其中 4 个 errcheck (Close calls) 阻塞 merge,1 个 staticcheck QF1003 是 P3 nit。需要修这 4 个 errcheck 才能进入下一轮评估。

Review 范围:

  • 对比旧 approve (7f1c9df) → 当前 head (762c251) 的 author 新 commit。
  • 跑了 gh CI API 看哪个 job 失败。
  • 提取 762c251 (last commit) 的文件清单。
  • 重点关注 CI gating (lint fail) 而非 exhaustive review (PR diff vs main 也很大, 但实际 author 新增 commit 只是 3 个小幅修改)。

🚨 P1 必须处理:

  • 4 个 errcheck violations 在 platform/tuitui/tuitui.go (lint, blocking merge):
    • 影响: lint job fail → 后续 4 个 jobs 全部 skipping。PR 在 lint fix 前无法 merge。
    • 证据 (run 29408915690, job 87331048242, 2026-07-15T10:41:57Z):
      platform/tuitui/tuitui.go:325:18: Error return value of `conn.Close` is not checked (errcheck)
      platform/tuitui/tuitui.go:689:23: Error return value of `resp.Body.Close` is not checked (errcheck)
      platform/tuitui/tuitui.go:756:23: Error return value of `resp.Body.Close` is not checked (errcheck)
      platform/tuitui/tuitui.go:829:23: Error return value of `resp.Body.Close` is not checked (errcheck)
      
    • 建议: 参考仓库惯例把 Close 错误处理掉 (slog / _ = / if err { ... }) 。conn.Close() (line 325) 通常用 defer + 如果想简化为 _ = conn.Close(),因为是 cleanup。resp.Body.Close() 三处都在 HTTP 路径, 可以保留 (e.g., _ = resp.Body.Close()) 或读 body 完成后用 io.Copy(io.Discard, resp.Body) + close 模式, 不过 _ = 就够了。
    • 验证: 在本地跑 golangci-lint run platform/tuitui/... 确认零 errcheck 输出,然后 push。

🔵 可选 (P3):

  • staticcheck QF1003platform/tuitui/tuitui.go:579:
    platform/tuitui/tuitui.go:579:2: QF1003: could use tagged switch on rctx.chatType (staticcheck)
    
    • 不阻塞,但建议改成 switch rctx.chatType { case "x": ...; case "y": ... } 让代码更易读。这个 nit 通常可以一次 PR 顺手清掉。

🟠 建议改进 (P2, 非阻塞):

  • TuiTui 平台历史注入 (feat(tuitui): prefer injected recent history) 是平台适配层的小改动, 我没深入 review。lint 修完后下一轮可以补一轮 correctness review。

❓ 需要确认:

  • (空)

Testing / Risk:

  • 已看到的验证: 5 jobs 中只有 lint 跑过, 其他 4 skipping。lint 失败行号见上。3 个新 commit 文件清单: 762c251 只动 platform/tuitui/tuitui.go (+6/-1) + tuitui_test.go (+14/-0),前两个 commit 累积改动需要再翻。
  • 未覆盖风险: 整个 PR vs main 的 diff 也有 300+ files (主要是 main 同步, 不是 author 主动添加),实际 author 改动只集中在 platform/tuitui/。我只看了 last commit 的 +/- 30 行,前两个 commit 的代码 diff 没逐行看过。

Next step:

  • @zzl360 需要修这 4 个 errcheck 后 push 触发 CI 重跑 → 等 5/5 全绿后,QA 会再过一遍 platform/tuitui/ 的功能 correctness (尤其是 1871189 提到的 restore tuitui runtime safeguards)。

@chenhg5

chenhg5 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

@zzl360 lint 失败在 platform/tuitui/tuitui.go 的 4 个 errcheck (Close calls, lines 325/689/756/829),以及 1 个 P3 staticcheck QF1003 on line 579 — 麻烦修一下让 5/5 CI 全绿,详见 review 留言。

@zzl360 zzl360 force-pushed the add-tuitui-platform branch from 762c251 to 073eb1a Compare July 16, 2026 02:57
@zzl360

zzl360 commented Jul 16, 2026

Copy link
Copy Markdown
Author

已按 review 意见更新:

  • 修复 4 个 errcheckQF1003,本地使用 CI 同版本 golangci-lint v2.11.4 验证为 0 issues
  • 将分支重写为单提交 073eb1a,移除了 Codex prompt 注入、send guard、cron/session 等与 TuiTui 无关的修改
  • 当前提交只包含 TuiTui 平台、CLI、配置/文档/WebUI,以及 TuiTui 历史上下文正确消费所需的最小通用 OnAccepted 回调
  • correctness review 中额外修复了精确 msgid 回声去重、媒体回声、channel parent、WebSocket 并发写/读阻塞、倒序历史分页、secret 错误脱敏和多项目歧义选择

验证结果:

  • golangci-lint run --new-from-rev HEAD ./...: 0 issues
  • go test ./...: pass
  • go test -race ./platform/tuitui: pass
  • Web UI build: pass
  • TuiTui-only / Feishu-only selective build: pass

@zzl360 zzl360 requested a review from chenhg5 July 16, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request P3 P3: 低优先级 / 建议 pr-conflicting PR has merge conflicts and needs rebase or closure pr-needs-review PR needs maintainer or QA review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants