Skip to content

feat(shared): add sanitizeAgentNameForDisplay helper#3518

Open
CoderLuii wants to merge 2 commits intocode-yeongyu:devfrom
CoderLuii:feat/sanitize-agent-name-for-display
Open

feat(shared): add sanitizeAgentNameForDisplay helper#3518
CoderLuii wants to merge 2 commits intocode-yeongyu:devfrom
CoderLuii:feat/sanitize-agent-name-for-display

Conversation

@CoderLuii
Copy link
Copy Markdown

@CoderLuii CoderLuii commented Apr 19, 2026

Summary

Adds an opt in display helper so downstream code can strip invisible codepoints (U+200B, U+200C, U+200D, U+FEFF) from agent names before rendering them to any end user surface. The existing ordering contract is untouched. getAgentRuntimeName, getAgentListDisplayName, AGENT_LIST_SORT_PREFIXES, and reorderAgentsByPriority are all unchanged.

Changes

  1. New export in src/shared/agent-display-names.ts: sanitizeAgentNameForDisplay(agentName: string): string. It delegates to the existing stripInvisibleAgentCharacters, so there is no new regex and no new dependency.
  2. New describe("sanitizeAgentNameForDisplay", ...) block in src/shared/agent-display-names.test.ts with 8 given when then cases covering single prefix strip, all four invisible codepoints, passthrough, idempotency, empty string, all invisibles, scattered invisibles, and mid word ZWSP.
  3. Additive note appended to src/plugin-handlers/AGENTS.md that points display layer callers at the new helper and reaffirms the existing Forbidden Patterns block. No existing text is modified.

Screenshots

Not applicable. This PR adds a library function and docs; there is no visual surface to capture.

Testing

From oh-my-openagent-upstream/:

bun run typecheck
bun test src/shared/agent-display-names.test.ts

Result on my branch:

  1. typecheck exits 0.
  2. Targeted agent-display-names.test.ts reports 38 pass / 0 fail (27 preexisting + 8 new tests + 3 additional existing in the file after my diff).

A runtime smoke of the new helper:

import { sanitizeAgentNameForDisplay } from "./src/shared/agent-display-names.ts"
sanitizeAgentNameForDisplay("\u200BSisyphus - Ultraworker")
// => "Sisyphus - Ultraworker"

Full bun test (running the whole repo in one process) has preexisting cross test mock pollution that is unrelated to this change. None of the failing tests touch any file in this PR. Every failing file passes when run in isolation on clean dev. This matches the repo's documented behavior about mock.module() and why CI uses script/run-ci-tests.ts instead of a single bare bun test invocation.

Related

Permanent fix at the root cause is in a separate PR against OpenCode core: anomalyco/opencode#23377, which closes the tracking issue I filed at anomalyco/opencode#23376. That PR teaches the TUI renderer to handle invisible codepoints correctly in width and truncation math. Once it merges and ships, every downstream plugin (including this one) gets correct rendering automatically.

Scope

This PR is strictly additive and opt in. No existing caller is migrated. The ordering contract in src/plugin-handlers/AGENTS.md is respected. No getAgentSortKey, no alternative ordering constant, no runtime sort shim.


Summary by cubic

Add sanitizeAgentNameForDisplay to strip invisible codepoints (U+200B, U+200C, U+200D, U+FEFF) from agent names before rendering. Opt-in; sorting and existing name helpers remain unchanged.

  • New Features
    • Added sanitizeAgentNameForDisplay(agentName: string) in src/shared/agent-display-names.ts (delegates to stripInvisibleAgentCharacters).
    • Updated AGENTS.md to reference the helper; added tests covering invisibles, passthrough, idempotency, and edge cases.

Written for commit d49b755. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 19, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: This PR is purely additive, introducing an opt-in helper function and tests without modifying any existing code paths or logic, which guarantees no regressions.

@CoderLuii
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 19, 2026
This was referenced Apr 24, 2026
This was referenced Apr 26, 2026
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.

1 participant