Skip to content

Commit e37dcf1

Browse files
authored
Merge pull request #26 from Hotakus/refactor/v2-dual-entry
feat: opencode2 (V2) 适配壳 —— 共享核心 + 双入口架构
2 parents dff9517 + fef0501 commit e37dcf1

25 files changed

Lines changed: 2903 additions & 1253 deletions

‎.github/workflows/publish-v2.yml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish v2 (oc2)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "版本号(如 1.7.0-oc2,格式 x.y.z-oc2)"
8+
required: true
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
registry-url: 'https://registry.npmjs.org'
24+
cache: npm
25+
26+
- run: npm install -g npm@11
27+
28+
- run: npm ci
29+
30+
# 改写 package.json 为 v2 版本(version + exports["./tui"] → tui/index.js + files 加 tui/)
31+
- run: node scripts/prepare-v2-publish.mjs ${{ inputs.version }}
32+
33+
# 生成 _version.ts(对齐 oc2 版本号,注入 v2.js)
34+
- run: npm run version
35+
36+
# 构建(v2.js 注入版本号;external 用宿主 @opentui/solid——renderer 相通)
37+
- run: npm run build
38+
39+
# 校验 v2.js 已注入版本号 + tui/index.js 存在
40+
- run: node -e "const c=require('fs').readFileSync('dist/v2.js','utf8'); if(!c.includes(process.argv[1])) { console.error('dist/v2.js 未注入版本号'); process.exit(1) }" ${{ inputs.version }}
41+
- run: node -e "if(!require('fs').existsSync('tui/index.js')) { console.error('tui/index.js 缺失'); process.exit(1) }"
42+
43+
# 发布到 oc2 通道(dist-tag 用 oc2——"v2" 是合法 SemVer range 会被 npm 拒绝;
44+
# --access public 与主线 publish.yml 一致;认证用 OIDC/trusted publishing(id-token: write),无 token)
45+
- run: npm publish --access public --tag oc2
46+
47+
# 校验 dist-tag
48+
- run: npm dist-tag ls opencode-visual-cache

‎README.md‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,45 @@
6060

6161
## 3. 安装
6262

63-
### 3.1 方式一:OpenCode 命令安装(推荐)
63+
本插件同时支持 opencode 1.x 与 2.x。
64+
65+
### 3.1 opencode 2.x
66+
67+
opencode 2.x 的 TUI 插件由 `cli.json` 的 `plugins` 管理;添加条目后,下次启动 opencode 时会自动安装并加载。
68+
69+
创建或编辑 `~/.config/opencode/cli.json`,在 `plugins` 数组中追加以下条目:
70+
71+
```json
72+
{
73+
"plugins": [
74+
{
75+
"package": "opencode-visual-cache@latest",
76+
"options": {
77+
"enabled": true
78+
}
79+
}
80+
]
81+
}
82+
```
83+
84+
若文件中已有其他插件或配置,只需在现有 `plugins` 数组末尾追加这个对象条目。
85+
86+
> **注意**:不要使用 `opencode plugin add` 安装本插件。该命令会把条目写入 `opencode.jsonc`(用于 server 插件),而本插件是 TUI 插件,会导致 server 插件加载报错:
87+
>
88+
> ```
89+
> Plugin must export a default definition with an id and an effect or setup function.
90+
> ```
91+
>
92+
> 如果已经用该命令安装过,请:
93+
> 1. 打开 `~/.config/opencode/opencode.jsonc`,从 `plugins` 数组中删除本插件条目
94+
> 2. 按上述方式在 `cli.json` 的 `plugins` 中声明
95+
> 3. 重启 opencode
96+
97+
> **排障**:若插件未生效,可清理插件缓存后重启。V2 缓存在 `~/.cache/opencode/npm`,V1 在 `~/.cache/opencode/packages`。
98+
99+
### 3.2 opencode 1.x
100+
101+
**方式一:命令安装(推荐)**
64102
65103
在 OpenCode 中按 **`Ctrl + P`** 打开命令面板,搜索 **`install plugin`**,输入:
66104
@@ -70,17 +108,15 @@ opencode-visual-cache@latest
70108
71109
回车即可完成安装与配置。
72110
73-
### 3.2 方式二:手动安装
111+
**方式二:手动安装**
74112
75-
**1. 安装插件**
113+
1. 安装插件
76114
77115
```bash
78116
npm install -g opencode-visual-cache@latest
79117
```
80118

81-
**2. 配置 TUI 插件**
82-
83-
创建或编辑 `~/.config/opencode/tui.jsonc`:
119+
2. 配置 TUI 插件 —— 创建或编辑 `~/.config/opencode/tui.jsonc`:
84120

85121
```jsonc
86122
{

‎README_EN.md‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,45 @@ Interested in sub-agent monitoring? Check out [opencode-subagent-magazine](https
6060

6161
## 3. Installation
6262

63-
### 3.1 Option 1: OpenCode Command (recommended)
63+
This plugin supports both opencode 1.x and 2.x.
64+
65+
### 3.1 opencode 2.x
66+
67+
opencode 2.x manages TUI plugins through the `plugins` array in `cli.json`; after adding an entry, it is installed and loaded automatically on the next start.
68+
69+
Create or edit `~/.config/opencode/cli.json` and append the following entry to the `plugins` array:
70+
71+
```json
72+
{
73+
"plugins": [
74+
{
75+
"package": "opencode-visual-cache@latest",
76+
"options": {
77+
"enabled": true
78+
}
79+
}
80+
]
81+
}
82+
```
83+
84+
If the file already contains other plugins or settings, just append this object entry to the existing `plugins` array.
85+
86+
> **Note**: Do not install this plugin with `opencode plugin add`. That command writes the entry to `opencode.jsonc` (used for server plugins), which makes the server fail to load it:
87+
>
88+
> ```
89+
> Plugin must export a default definition with an id and an effect or setup function.
90+
> ```
91+
>
92+
> If you already installed it that way:
93+
> 1. Open `~/.config/opencode/opencode.jsonc` and remove this plugin from the `plugins` array
94+
> 2. Declare it in the `plugins` array of `cli.json` as described above
95+
> 3. Restart opencode
96+
97+
> **Troubleshooting**: If the plugin does not take effect, clear the plugin cache and restart. The V2 cache lives in `~/.cache/opencode/npm`, and the V1 cache in `~/.cache/opencode/packages`.
98+
99+
### 3.2 opencode 1.x
100+
101+
**Option 1: Command (recommended)**
64102
65103
Press **`Ctrl + P`** in OpenCode to open the command palette, search **`install plugin`**, then type:
66104
@@ -70,17 +108,15 @@ opencode-visual-cache@latest
70108
71109
Press Enter to install and configure automatically.
72110
73-
### 3.2 Option 2: Manual
111+
**Option 2: Manual**
74112
75-
**1. Install the plugin**
113+
1. Install the plugin
76114
77115
```bash
78116
npm install -g opencode-visual-cache@latest
79117
```
80118

81-
**2. Configure TUI plugin**
82-
83-
Create or edit `~/.config/opencode/tui.jsonc`:
119+
2. Configure the TUI plugin — create or edit `~/.config/opencode/tui.jsonc`:
84120

85121
```jsonc
86122
{

‎build.tui.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ await esbuild.build({
2020
external: ["@opencode-ai/*", "@opentui/*", "solid-js"],
2121
plugins: [solidPlugin({ solid: { moduleName: "@opentui/solid", generate: "universal" } })],
2222
})
23+
24+
// V2 (opencode2) 入口:{ id, setup } 协议,独立产物。
25+
// @opentui/* + solid-js 保持 external:必须用 V2 宿主的同一实例(renderer 上下文相通——
26+
// self-contained 内联会导致 "No renderer found");@opencode-ai/* 为 type-only(编译擦除)。
27+
await esbuild.build({
28+
entryPoints: ["src/v2/index.tsx"],
29+
outfile: "dist/v2.js",
30+
format: "esm",
31+
platform: "node",
32+
bundle: true,
33+
external: ["@opencode-ai/*", "@opentui/*", "solid-js"],
34+
plugins: [solidPlugin({ solid: { moduleName: "@opentui/solid", generate: "universal" } })],
35+
})

0 commit comments

Comments
 (0)