TUI plugin API: allow a location on the home route (router.navigate)

Aperta Adatta ai principianti
#62,322 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia dal tipo Route del plugin in packages/plugin/src/tui/context.ts e confrontalo con HomeRoute in packages/tui/src/context/route.tsx. Aggiungi la posizione facoltativa alla variante home e documentala; verifica che router.current() esponga la posizione della route home e che la navigazione accetti la directory mostrata nella riproduzione. L’issue non indica un test, quindi cerca prima i test di tipo esistenti dell’API del plugin.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

A TUI plugin cannot open the new-session screen for a specific directory with the typed plugin API. OpenCode's own code can.

Internally, HomeRoute carries an optional location (packages/tui/src/context/route.tsx):

export type HomeRoute = {
  type: "home"
  prompt?: PromptInfo
  // Location carried over from the previous session or project picker so a new session lands there.
  location?: LocationRef
}

The project picker (component/dialog-open.tsx) and the workspace move (component/prompt/move.tsx) both call route.navigate({ type: "home", location: { directory } }). Home then applies route.location (routes/home.tsx), so the next session is created in that directory.

The plugin API's Route type (packages/plugin/src/tui/context.ts) has only { readonly type: "home" }. ui.router.navigate passes a home destination straight through to the host (packages/tui/src/plugin/api.tsx), so navigate({ type: "home", location }) works at runtime. However, a plugin has to cast to reach it, and nothing guarantees it keeps working.

Proposal: add readonly location?: LocationRef to the home variant of the plugin Route type, and document it. router.current() would then also type the location of the current home route, which the host already returns.

Use case: opencode-switchboard, a side panel that lists sessions grouped by project, wants a "New session" action on a project. It should open that project's new-session screen, as picking the project in Ctrl+O does, without creating an empty session up front with session.create.

Happy to send a PR.

Plugins

opencode-switchboard

OpenCode version

2.2.5

Steps to reproduce
  1. In a TUI plugin, call ctx.ui.router.navigate({ type: "home", location: { directory: "/some/other/project" } }).
  2. TypeScript rejects location. With a cast, it works: the new-session screen opens in that directory.
Operating System

Ubuntu 24.04

Terminal

Ghostty

Lingua principale
TypeScript
Stelle
224k
Fork
30k
Merge medio
5h 25m
PR unite (30g)
494

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anomalyco/opencode

Tutte le issue di anomalyco/opencode

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.