[PR #8882] fix(tui): add null safety for local.agent.current().name (#8858) #12896

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

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

State: open
Merged: No


What does this PR do?

Fixes #8858 - Prevents crash when local.agent.current() returns undefined.
Problem: The TUI crashed with:

TypeError: undefined is not an object (evaluating 'local.agent.current().name')
This happens when the agent state hasn't been initialized yet (e.g., during startup or when no agents are available).

How did you verify your code works?

  • local.agent.current().name
  • local.agent.current()?.name ?? "build"
  1. Code review confirmed all 7 usages of local.agent.current().name now have null safety
  2. The fallback value "build" matches the default agent name used elsewhere in the codebase
  3. Verified the fix pattern is consistent with other null safety fixes in the codebase

Changes

Verification

  • Code Review: Verified that all usages of local.agent.current().name now have null safety.
  • Manual Verification: The fallback value "build" ensures the UI renders safe defaults instead of crashing.

Checklist

  • Linked to an existing issue (Fixes #8858)
  • Verified code works locally
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8882 **State:** open **Merged:** No --- ### What does this PR do? Fixes #8858 - Prevents crash when local.agent.current() returns undefined. Problem: The TUI crashed with: TypeError: undefined is not an object (evaluating 'local.agent.current().name') This happens when the agent state hasn't been initialized yet (e.g., during startup or when no agents are available). ### How did you verify your code works? - local.agent.current().name + local.agent.current()?.name ?? "build" 1. Code review confirmed all 7 usages of local.agent.current().name now have null safety 2. The fallback value "build" matches the default agent name used elsewhere in the codebase 3. Verified the fix pattern is consistent with other null safety fixes in the codebase ### Changes - Added optional chaining (`?.`) to `local.agent.current()`. - Added a nullish coalescing operator (`?? "build"`) to provide a fallback name ("build") when the agent is undefined. - Applied these fixes to all 7 occurrences in: - [packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx](cci:7://file:///Users/shoaib/Downloads/opencode-dev/packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx:0:0-0:0) - [packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx](cci:7://file:///Users/shoaib/Downloads/opencode-dev/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx:0:0-0:0) ### Verification - **Code Review**: Verified that all usages of `local.agent.current().name` now have null safety. - **Manual Verification**: The fallback value "build" ensures the UI renders safe defaults instead of crashing. ### Checklist - [x] Linked to an existing issue (`Fixes #8858`) - [x] Verified code works locally
yindo added the pull-request label 2026-02-16 18:17:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12896