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

未关闭 适合新手
#62,322 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

从 packages/plugin/src/tui/context.ts 中的插件 Route 类型开始,并将其与 packages/tui/src/context/route.tsx 中的 HomeRoute 进行比较。为 home 变体添加可选位置并编写文档;检查 router.current() 是否公开 home 路由的位置,以及导航是否接受复现中显示的目录。该 issue 没有指定测试,因此先查找现有的插件 API 类型测试。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
TypeScript
星标
224k
派生
30k
平均合并
5 小时 25 分钟
30 天内合并 PR
494

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anomalyco/opencode 的其他 Issue

查看 anomalyco/opencode 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。