Skip to content

Conversation

@wydrox
Copy link

@wydrox wydrox commented Jan 15, 2026

fix(tui): add null check for local.agent.current()

The local.agent.current() function can return undefined when no agents are
available (empty agents list). This caused a TypeError when trying to access
.name property on undefined.

Fix by adding optional chaining and nullish coalescing for safe access:

  • local.agent.current()?.name ?? "build" for agent names
  • local.agent.current()?.name ?? "" for UI display

Affected files:

  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx (6 locations)
  • packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx (1 location)

seilk and others added 2 commits January 15, 2026 16:00
…lity (anomalyco#8658)

Co-authored-by: Mark Henderson <Mark.Henderson99@hotmail.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
The `local.agent.current()` function can return undefined when no agents are
available (empty agents list). This caused a TypeError when trying to access
`.name` property on undefined.

Fix by adding optional chaining and nullish coalescing for safe access:
- `local.agent.current()?.name ?? "build"` for agent names
- `local.agent.current()?.name ?? ""` for UI display

Affected files:
- packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx (6 locations)
- packages/opencode/src/cli/cmd/tui/component/dialog-agent.tsx (1 location)
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

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

Potential Duplicate PRs Found

Several PRs address similar or overlapping issues with local.agent.current() null checks:

  1. PR fix(tui): handle undefined agent.current() to prevent fatal TypeError #7689 - fix(tui): handle undefined agent.current() to prevent fatal TypeError

    • Directly addresses the same TypeError issue from undefined agent.current()
  2. PR fix(tui): handle undefined agent.current() to prevent crash on startup #7748 - fix(tui): handle undefined agent.current() to prevent crash on startup

    • Handles undefined agent.current() to prevent crashes, similar scope to current PR
  3. PR fix(opencode): add null checks for agent.current() in prompt #7920 - fix(opencode): add null checks for agent.current() in prompt

    • Explicitly adds null checks for agent.current() in prompt component
  4. PR fix(tui): handle undefined agent during login/bootstrap transition #7940 - fix(tui): handle undefined agent during login/bootstrap transition

    • Addresses undefined agent handling in TUI context
  5. PR Fix TUI crashes from undefined values (#8588, #8579, #8580) #8635 - Fix TUI crashes from undefined values (#8588, #8579, #8580)

    • Broader fix for TUI crashes from undefined values, may include agent.current() handling
  6. PR fix(tui): guard local.agent.current() after oauth redirect (fixes #7727) #7747 - fix(tui): guard local.agent.current() after oauth redirect (fixes #7727)

    • Guards local.agent.current() in specific context

Recommendation: Check if PR #8745 is addressing a newly discovered case or if it's duplicating work from earlier PRs, particularly #7920 (prompt-specific) or #7748/#7689 (general agent.current() handling).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants