Skip to content

feat(opencode): add order field to agent config for explicit list sorting#22343

Open
Zireael wants to merge 5 commits intoanomalyco:devfrom
Zireael:feat/agent-order-field
Open

feat(opencode): add order field to agent config for explicit list sorting#22343
Zireael wants to merge 5 commits intoanomalyco:devfrom
Zireael:feat/agent-order-field

Conversation

@Zireael
Copy link
Copy Markdown

@Zireael Zireael commented Apr 13, 2026

Issue for this PR

I did not raise issue - opening this PR to propose a small enhancement. I can create a tracking issue if required.

Type of change

  • New feature

What does this PR do?

Adds an optional order field to the Agent config schema so users and plugins can explicitly control agent display order in the TUI.

Currently, the only way to influence agent position is through alphabetical name sorting (after the default agent). Plugins like oh-my-opencode work around this by prefixing agent names with zero-width space characters (\u200B) to force sort order, which causes rendering corruption in Windows Terminal (missing characters, shifted UI elements).

This change adds a clean, explicit mechanism:

  • order: z.number().int().optional() on both Config.Agent and Agent.Info schemas
  • Primary sort key in Agent.list(): order (asc), then default_agent (desc), then name (asc)
  • Agents without an explicit order fall back to Number.MAX_SAFE_INTEGER, preserving existing alphabetical behavior

How did you verify your code works?

  • Typecheck passes with zero errors on all changed files
  • Added 2 new tests:
    • Agent.list respects order field as primary sort key — verifies order overrides default_agent placement
    • agent order can be set from config — verifies config → runtime merge
  • Existing test Agent.list keeps the default agent first and sorts the rest by name still passes (agents without order tie at MAX_SAFE_INTEGER, then default_agent breaks the tie)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Files changed

  • packages/opencode/src/agent/agent.ts — Agent.Info schema, merge loop, list() sort
  • packages/opencode/src/config/config.ts — Config.Agent schema, transform knownKeys
  • packages/opencode/test/agent/agent.test.ts — 2 new tests

…ting

Adds an optional `order` field to Agent.Info and Config.Agent schemas
so users and plugins can control agent display order without relying on
name-based alphabetical sorting or invisible Unicode characters.

Sort precedence: order (asc), default_agent (desc), name (asc).
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #19127: feat(agent): add order field for configurable agent cycling order
#19127

Why it's related: This PR appears to directly address the same feature—adding an order field to agent configuration for controlling agent order. The current PR (22343) may be implementing the same or very similar functionality. You should check if #19127 is already merged, closed, or addresses a different use case (e.g., cycling order vs. display order in TUI).

@Zireael
Copy link
Copy Markdown
Author

Zireael commented Apr 13, 2026

What's the point of test/e2e (windows)? It runs the code through playwright in browser then times out. Looks like misconfigured test.

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