# UI token estimation routed through core messaging facade

> Fixed a dependency-layer violation where the UI imported tunacode.utils.messaging directly by routing message token estimation through the tunacode.core.ui_api.messaging facade.

- Skill: `tools-only/ui-token-estimation-routed-through-core-messaging-facade` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add tools-only/ui-token-estimation-routed-through-core-messaging-facade`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tools-only/ui-token-estimation-routed-through-core-messaging-facade/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tools-only (https://skillmd.com/u/tools-only)
- Updated: 2026-09-29
- Page: https://skillmd.com/skills/tools-only/ui-token-estimation-routed-through-core-messaging-facade

---


# UI token estimation routed through core messaging facade

## Summary

Fixed a dependency-layer violation where the UI imported `tunacode.utils.messaging` directly by routing message token estimation through the `tunacode.core.ui_api.messaging` facade.

## Context

`tests/test_dependency_layers.py::test_no_new_layer_violations` flagged:

- `tunacode.ui.app -> tunacode.utils.messaging` (ui -> utils)

## Root Cause

The UI layer is only allowed to depend on `core` (per the dependency layer rules), but `TextualReplApp._update_resource_bar()` imported `estimate_messages_tokens` from `utils`.

## Changes

- `src/tunacode/core/ui_api/messaging.py`
  - Re-exported `estimate_messages_tokens()` from `tunacode.utils.messaging`.
- `src/tunacode/ui/app.py`
  - Switched import to `from tunacode.core.ui_api.messaging import estimate_messages_tokens`.
  - Reordered imports to satisfy first-party import-order tests.

## Behavioral Impact

No user-visible behavior change; token estimation remains the same. The UI now respects the enforced dependency direction.

## Related Cards

- [[dependency-layers]]

