Skip to content

feat(chat): offer plugin-defined primary agents in the mode picker - #2

Merged
doublepi123 merged 2 commits into
mainfrom
feat/opencode-custom-primary-agents
Oct 15, 2026
Merged

doublepi123 merged 2 commits into
mainfrom
feat/opencode-custom-primary-agents

Conversation

@doublepi123

Copy link
Copy Markdown
Owner

Summary

The chat mode chip only offered build/plan, so primary agents registered by OpenCode plugins
(e.g. oh-my-opencode-slim's orchestrator) were unreachable from the app even though the server
reported them and set them as default_agent.

  • OpenCodeAgent now decodes hidden.
  • New selectablePrimaryAgents() (non-hidden primary/all/unreported-mode agents, server order kept)
    and defaultAgentName() (first of those; OpenCode's GET /agent sorts default_agent first, or
    build when unset).
  • ModeChip, SettingsViewModel.agents, AppPreferencesRepository.reconcile and
    AssistantProfileResolver use them instead of hard-coding build.

Behavior note: a previously auto-saved build selection stays valid, so existing users keep build
until they pick another agent in the chip; new installs or invalid selections follow the server's
default_agent.

Testing

  • New OpenCodeAgentSelectionTest; added a default_agent case to AssistantProfileTest.
  • ktlint 1.2.1 passes on changed files. Gradle tests/detekt could not run on-device (no Android SDK) — relying on CI.

Pre-PR review

判定: APPROVE

ブロッカー

なし

提案(非ブロッキング)

  • data/settings/AppPreferencesRepository.kt:150-155: 既存ユーザーは旧 reconcile が自動保存した "build" が agentId に残っているため、サーバー default_agent が orchestrator でも更新後は build のまま。ユーザー選択と自動デフォルトを区別できない以上妥当な挙動だが、PR 説明に「新規/無効化時のみサーバーデフォルトに従う」と一言あると誤解が減る。
  • feature/chat/ChatHomeScreen.kt:1886: チップは widthIn(max = 92.dp) のため orchestrator 等の長い名前は省略表示になる。TextOverflow.Ellipsis 済みで破綻はしないが、実機で見切れ具合を確認推奨。
  • data/settings/AppPreferencesRepository.kt:132 の reconcile 自体には単体テストがない。ロジックの中心は defaultAgentName/selectablePrimaryAgents 側にあり OpenCodeAgentSelectionTest で網羅されているので必須ではない。
  • feature/assistant/AssistantProfile.kt:28: AssistantProfileResolver は main 側に呼び出し元がない(テストのみ)。今回の変更とは無関係で既存の状態。

チェック済み項目

  • ヘルパー(core/api/OpenCodeApiModels.kt:163-184): hidden はデフォルト false(省略 JSON でもデコード可、テスト 67-76 行で確認)。selectablePrimaryAgents は mode null/primary/all かつ非 hidden のみ、サーバー順を保持。defaultAgentName は firstOrNull()?.name のみで build フォールバック削除済み。
  • テストと実装の一致: 空リスト defaultAgentName() → null(OpenCodeAgentSelectionTest.kt:62-64)、stock サーバー(build, plan 順)→ build(50-59 行)、プラグイン構成で orchestrator 先頭・subagent/hidden(compaction/title/summary/councillor-gpt)除外を確認。AssistantProfileTest の 2 件(既存 build-only と新規 orchestrator 優先)も実装と整合。
  • ModeChip(ChatHomeScreen.kt:1862-1928): 旧実装の build/plan 限定+ラベル固定 "build" から、全 selectable primary の表示へ。ラベルは「有効な選択 → defaultAgentName() → "build"」で、最後の "build" はランタイム停止中の空リスト時のみ(旧挙動を維持)。コメント修正内容も実装と一致。
  • 呼び出し元整合: AndCodeApp.kt:612,1061,1064 は settingsState.agents(SettingsViewModel.kt:208 でフィルタ済み)を使用し、チップ・設定画面・selectConfiguration 検証が同一集合で一貫。CatalogReconcileInitializer.kt:19 → reconcile は生リストを渡すが内部でフィルタ。空リスト時の reconcile は selectAgent(null) となり旧挙動と同じ。
  • OpenCode 以外のランタイム: Codex(CodexModels.kt:39)、Claude Code(ClaudeCodeTarget.kt:358)、Antigravity(AntigravityTarget.kt:158)はいずれも mode="primary"・hidden 未指定で選択可能。Claude/Antigravity は ModeChip ではなく PermissionModeChip 分岐(ChatHomeScreen.kt:1579-1597)。Codex は単一エージェントがそのまま表示され、旧 ifEmpty { agents } 経由と同結果。
  • main との比較: /workspace/and-code 側の旧実装(AppPreferencesRepository.kt:147-151、AssistantProfile.kt:56、SettingsViewModel.kt:207、ChatHomeScreen.kt:1871-1875)と突き合わせ、意図しない後退がないことを確認。
  • i18n: 新規の表示文字列・リソースキーなし(エージェント名はサーバー由来の値)。
  • 秘密情報・DI: 秘密情報なし、DI/コンストラクタ変更なし。
  • 未確認: このレビュー環境では git が使えず branch diff は未実行(依頼の変更ファイル一覧と main ツリーとのファイル比較で範囲を確定)。ローカルに Android SDK がないため detekt/テストの実行結果は CI 依存。

The mode chip only listed build/plan, so primaries registered by OpenCode plugins (e.g. oh-my-opencode-slim's orchestrator) were unreachable from the app. List every non-hidden primary/all agent, and default to the agent the server sorts first (its default_agent) instead of hard-coding build.
@doublepi123
doublepi123 merged commit 28fdb22 into main Oct 15, 2026
5 checks passed
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