Skip to content

feat(messaging): token K/M/B units and toolfmt multiline garble fix#470

Merged
hotplex-ai merged 5 commits into
mainfrom
batch/codexcli-hardening-462
May 21, 2026
Merged

feat(messaging): token K/M/B units and toolfmt multiline garble fix#470
hotplex-ai merged 5 commits into
mainfrom
batch/codexcli-hardening-462

Conversation

@hrygo
Copy link
Copy Markdown
Owner

@hrygo hrygo commented May 21, 2026

Summary

  • FormatTokenCount 新增 M/B 单位支持,大 token 数值自动缩写(Go + TS 双端)
  • toolfmt 提取 firstLine() helper,全量防护多行内容在 Feishu tool_activity 区域的乱码问题

Test plan

  • TestFormatTokenCount 16 用例全部通过(含 M/B 边界值)
  • TestFormatCall 多行 Bash/Grep/Agent/WebSearch 用例通过
  • make check (quality + build) 通过

…oval deadlock (#462)

- Fix ExecWorker.Input() TOCTOU race condition by moving nil check into spawn()
- Pass session.AllowedTools to proc.Manager for security enforcement
- Enforce StartupTimeout in spawn() and startProcessLocked() (was configured but unused)
- Add JSONRPCFrame unified type to eliminate double unmarshal in dispatchFrame
- Handle server-initiated JSON-RPC requests (approvals) previously silently dropped
- Implement HandlePermissionResponse via RespondServerRequest to resolve approval deadlock
- Add approval method aliases (item/commandExecution/requestApproval, item/fileChange/requestApproval)
- Add messageTracker.Reset() and call on crash recovery to prevent memory leaks
- Replace AppServerWorker.Wait() 2s magic timeout with doneCh-based lifecycle binding
- Add 5s timeout protection for critical event sends to prevent goroutine leaks
- Register command with security.RegisterCommand in InitConfig
- Make personality configurable via config (default "friendly")
- Switch dev config feishu worker_type to codex_cli
- Remove accidentally appended memory context from AGENTS.md
- Extract defaultStartupTimeout and criticalEventSendTimeout constants
- Fix sendEnvelope time.After leak with time.NewTimer + Stop()
- Unify three write-mu+encode blocks into writeFrame()
- Remove personality double-default (trust config layer)
…lues

Token counts now display as K/M/B based on magnitude:
- <1K: raw number (999)
- >=1K: K suffix (76.3K, 200K)
- >=1M: M suffix (1.5M, 15M)
- >=1B: B suffix (2.5B)

Applied to both Go backend and webchat TS frontend.
Copy link
Copy Markdown
Contributor

@aaronwong1989 aaronwong1989 left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR adds K/M/B unit support to FormatTokenCount (Go + TS) and switches dev config worker_type.

Must Fix

None.

Suggested

  1. Edge case: 999999 produces "1000.0K" which is confusing in UI - user expects "1M". Consider rounding up at unit boundaries in formatCompact.

Nice to Have

  1. PR body mentions toolfmt/firstLine() changes but diff does not include them - may have been squashed into prior commit, consider updating PR description.

Good

  • Go/TS implementations aligned
  • formatCompact extracted as helper function
  • Test coverage for K/M/B boundaries
  • Numeric separators for readability

999999 now correctly shows "1M" instead of "1000.0K". Use 999_950
thresholds to bump up at unit boundaries, and round in formatCompact
to avoid stale ".0" suffixes (e.g. 9999 → "10K" not "10.0K").

Go and TS implementations updated in sync.
Copy link
Copy Markdown
Contributor

@aaronwong1989 aaronwong1989 left a comment

Choose a reason for hiding this comment

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

✅ 审查通过

审查要点

FormatTokenCount K/M/B 单位(Go + TS)

  • 🟢 使用 999,950 阈值实现单位自动晋升(K→M→B),边界处理正确:999999 → "1M",999949 → "999.9K"
  • 🟢 / 中 四舍五入 + 整数判断,消除旧版 ".0" 后缀(9999 → "10K" 而非 "10.0K")
  • 🟢 Go 和 TS 双端逻辑完全同步,实现一致
  • 🟢 测试从 10 个用例扩展到 16 个,覆盖 K/M/B 所有单位边界

config-dev.yaml

  • 🟢 worker_type 切换为 claude_code,仅影响开发环境,无风险

注意事项

  • PR 描述中提到的 toolfmt multiline garble fix(firstLine helper)未出现在本次 diff 中,可能已在之前的提交中包含或已移除,建议确认是否需要单独处理。

整体变更质量高,逻辑清晰,测试充分。👍

Copy link
Copy Markdown
Contributor

@aaronwong1989 aaronwong1989 left a comment

Choose a reason for hiding this comment

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

✅ 审查通过

审查要点

FormatTokenCount K/M/B 单位(Go + TS)

  • 🟢 使用 999,950 阈值实现单位自动晋升(K→M→B),边界处理正确:999999 → "1M",999949 → "999.9K"
  • 🟢 formatCompact / fmtCompact 中 math.Round(v*10)/10 四舍五入 + 整数判断,消除旧版 ".0" 后缀(9999 → "10K" 而非 "10.0K")
  • 🟢 Go 和 TS 双端逻辑完全同步,实现一致
  • 🟢 测试从 10 个用例扩展到 16 个,覆盖 K/M/B 所有单位边界

config-dev.yaml

  • 🟢 worker_type 切换为 claude_code,仅影响开发环境,无风险

注意事项

  • PR 描述中提到的 toolfmt multiline garble fix(firstLine helper)未出现在本次 diff 中,可能已在之前的提交中包含或已移除,建议确认是否需要单独处理。

整体变更质量高,逻辑清晰,测试充分。👍

@hotplex-ai hotplex-ai merged commit 375248c into main May 21, 2026
5 of 6 checks passed
@hrygo hrygo deleted the batch/codexcli-hardening-462 branch May 21, 2026 06:32
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.

3 participants