Skip to content

feat(opencode): dynamic session ID completion for --session, export, and session delete#27001

Open
wakamori wants to merge 2 commits into
anomalyco:devfrom
wakamori:feat/dynamic-session-completion
Open

feat(opencode): dynamic session ID completion for --session, export, and session delete#27001
wakamori wants to merge 2 commits into
anomalyco:devfrom
wakamori:feat/dynamic-session-completion

Conversation

@wakamori
Copy link
Copy Markdown

@wakamori wakamori commented May 12, 2026

Issue for this PR

Contributes to #1515

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds dynamic value completion for session IDs. When a user presses <TAB> after flags or commands that accept a session ID, the shell now suggests actual session IDs (with titles) from the local database.

This applies to:

  • opencode --session <TAB> / opencode -s <TAB>
  • opencode session delete <TAB>
  • opencode export <TAB>

The implementation adds a FallbackCompletionFunction to the existing .completion() call in index.ts. It checks the previous token to determine whether a session ID is expected, queries the session table via drizzle, and returns the results. For all other contexts it falls back to yargs default completions.

How did you verify your code works?

Ran --get-yargs-completions directly to confirm session IDs are returned in the right contexts and default completions still work elsewhere. All 260 existing CLI tests pass.

Screenshots / recordings

N/A — CLI only change.

Checklist

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

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

wakamori added 2 commits May 12, 2026 14:45
…etion

Add a custom completion callback to suggest session IDs from the local
database when completing --session/-s, 'session delete', and 'export'
commands. Uses yargs FallbackCompletionFunction to preserve default
completions for all other contexts.

Ref: anomalyco#1515
…used param

- Escape colons in session titles to prevent zsh completion format breakage
- Wrap DB query in try-catch and fall back to default completions on failure
- Rename unused 'current' parameter to '_current'
@wakamori wakamori force-pushed the feat/dynamic-session-completion branch from 5d17a62 to 7d03450 Compare May 12, 2026 05:45
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