[PR #9096] Fix null agent access in TUI #12976

Closed
opened 2026-02-16 18:17:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9096

State: closed
Merged: No


Summary

Fixed the undefined is not an object (evaluating 'local.agent.current().name') error by making the agent access defensive in the TUI code.

Changes Made

packages/opencode/src/cli/cmd/tui/context/local.tsx:

  1. Changed initial state from agents()[0].name to agents()[0]?.name ?? "" to handle empty agent list
  2. Changed current() to return agents().find(...) ?? agents()[0] instead of using non-null assertion !
  3. Added null checks in move() function for when agents list is empty
  4. Added early return guards in currentModel(), cycle(), cycleFavorite(), set(), and the agent change effect when agent is undefined

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx:

  • Changed all local.agent.current().name to local.agent.current()?.name ?? "coder" (4 occurrences)
  • Changed all local.agent.color(local.agent.current().name) to local.agent.color(local.agent.current()?.name ?? "coder") (2 occurrences)

packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx:

  • Changed local.agent.current().name to local.agent.current()?.name ?? "coder"

Duplicate Issues to Close

The following issues are duplicates and should be closed:

Closes #9082

New%20session%20-%202026-01-17T15%3A52%3A26.671Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9096 **State:** closed **Merged:** No --- ## Summary Fixed the `undefined is not an object (evaluating 'local.agent.current().name')` error by making the agent access defensive in the TUI code. ### Changes Made **`packages/opencode/src/cli/cmd/tui/context/local.tsx`:** 1. Changed initial state from `agents()[0].name` to `agents()[0]?.name ?? ""` to handle empty agent list 2. Changed `current()` to return `agents().find(...) ?? agents()[0]` instead of using non-null assertion `!` 3. Added null checks in `move()` function for when agents list is empty 4. Added early return guards in `currentModel()`, `cycle()`, `cycleFavorite()`, `set()`, and the agent change effect when agent is undefined **`packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx`:** - Changed all `local.agent.current().name` to `local.agent.current()?.name ?? "coder"` (4 occurrences) - Changed all `local.agent.color(local.agent.current().name)` to `local.agent.color(local.agent.current()?.name ?? "coder")` (2 occurrences) **`packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx`:** - Changed `local.agent.current().name` to `local.agent.current()?.name ?? "coder"` ### Duplicate Issues to Close The following issues are duplicates and should be closed: - #8018, #8894, #8800, #8834, #8858, #8853, #8648, #8637, #8628, #8579, #8672 Closes #9082 <a href="https://opencode.ai/s/hCKqcM3D"><img width="200" alt="New%20session%20-%202026-01-17T15%3A52%3A26.671Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI2LTAxLTE3VDE1OjUyOjI2LjY3MVo=.png?model=opencode/claude-opus-4-5&version=1.1.25&id=hCKqcM3D" /></a> [opencode session](https://opencode.ai/s/hCKqcM3D)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/anomalyco/opencode/actions/runs/21096940786)
yindo added the pull-request label 2026-02-16 18:17:51 -05:00
yindo closed this issue 2026-02-16 18:17:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12976