opencode-diff-viewer 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +212 -41
  2. package/package.json +10 -2
package/README.md CHANGED
@@ -1,74 +1,141 @@
1
1
  # OpenCode Diff Viewer Plugin
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/opencode-diff-viewer.svg)](https://www.npmjs.com/package/opencode-diff-viewer)
4
+ [![npm downloads](https://img.shields.io/npm/dm/opencode-diff-viewer.svg)](https://www.npmjs.com/package/opencode-diff-viewer)
5
+
3
6
  一个 OpenCode 插件,使用 [lumen](https://github.com/jnsahaj/lumen) 提供美观的 TUI diff 查看功能。
4
7
 
5
- ## 功能
8
+ ## 功能特性
9
+
10
+ - ✨ **自动安装 lumen** - 插件会自动检测并安装 lumen 依赖
11
+ - 🚀 **一键查看 diff** - 使用 `/diff` 命令快速查看代码变更
12
+ - 🔧 **智能终端适配** - 自动检测操作系统,打开新终端窗口展示 diff
13
+ - 🤖 **LLM 工具集成** - LLM 可自动调用 `view_diff` 工具
14
+
15
+ ## 前置条件
16
+
17
+ ### 1. 安装 lumen
18
+
19
+ 插件会自动尝试安装 lumen,如果自动安装失败,需要手动安装:
20
+
21
+ **macOS / Linux (Homebrew)**:
22
+ ```bash
23
+ brew install jnsahaj/lumen/lumen
24
+ ```
25
+
26
+ **macOS / Linux (Bun)**:
27
+ ```bash
28
+ bun install jnsahaj/lumen/lumen
29
+ ```
30
+
31
+ **Cargo (Rust)**:
32
+ ```bash
33
+ cargo install lumen
34
+ ```
35
+
36
+ **Windows**:
37
+ 下载 [lumen releases](https://github.com/jnsahaj/lumen/releases) 并添加到 PATH
6
38
 
7
- - `/diff` 命令查看所有修改的文件
8
- - `/diff <file>` 命令查看指定文件的 diff
9
- - LLM 可调用的 `view_diff` 工具
10
- - 自动安装 lumen(如果未安装)
11
- - 自动在新终端窗口中打开
39
+ ### 2. Git 仓库
40
+
41
+ 确保项目是 git 仓库,并且有修改的文件:
42
+ ```bash
43
+ git status # 查看修改的文件
44
+ ```
12
45
 
13
46
  ## 安装
14
47
 
15
- ### 方式一:npm 安装(推荐)
48
+ ### 方式一:npm / pnpm / bun 安装(推荐)
16
49
 
17
50
  ```bash
51
+ # npm
18
52
  npm install opencode-diff-viewer
19
- # 或
53
+
54
+ # pnpm
20
55
  pnpm add opencode-diff-viewer
21
- # 或
22
- yarn add opencode-diff-viewer
56
+
57
+ # bun
58
+ bun add opencode-diff-viewer
23
59
  ```
24
60
 
25
- 然后在 `opencode.json` 中添加插件:
61
+ ### 方式二:全局配置(适用于所有项目)
26
62
 
27
- ```json
28
- {
29
- "plugin": ["opencode-diff-viewer"]
30
- }
31
- ```
63
+ 如果你想在所有项目中使用此插件,可以配置全局插件:
32
64
 
33
- ### 方式二:本地开发
65
+ 1. 创建全局配置目录:
66
+ ```bash
67
+ mkdir -p ~/.config/opencode
68
+ ```
34
69
 
35
- 将插件复制到你的项目:
70
+ 2. 创建 `~/.config/opencode/opencode.json`:
71
+ ```json
72
+ {
73
+ "plugin": ["opencode-diff-viewer"]
74
+ }
75
+ ```
76
+
77
+ 3. 重启 OpenCode,插件会自动加载
78
+
79
+ ### 方式三:项目级别配置
80
+
81
+ 在项目根目录创建 `.opencode` 目录(注意前面的点):
36
82
 
37
83
  ```bash
84
+ # 项目根目录
85
+ mkdir -p .opencode/plugin
86
+ mkdir -p .opencode/command
87
+
38
88
  # 复制插件文件
39
- cp -r node_modules/opencode-diff-viewer/dist .opencode/plugin/diff-viewer
89
+ cp node_modules/opencode-diff-viewer/dist .opencode/plugin/diff-viewer
40
90
  cp node_modules/opencode-diff-viewer/command-diff.md .opencode/command/diff.md
41
91
 
42
92
  # 或使用 npm link
43
93
  npm link opencode-diff-viewer
94
+ cd ~/.config/opencode
95
+ ln -s /path/to/your/project/node_modules/opencode-diff-viewer/dist ./plugin/diff-viewer
96
+ ln -s /path/to/your/project/node_modules/opencode-diff-viewer/command-diff.md ./command/diff.md
44
97
  ```
45
98
 
46
- ## 前置条件
99
+ ### 目录说明
47
100
 
48
- 插件会自动安装 lumen。如果自动安装失败,需要手动安装:
101
+ | 目录 | 位置 | 作用 |
102
+ |------|------|------|
103
+ | `.opencode/` | 项目根目录 | 项目级别插件配置 |
104
+ | `~/.config/opencode/` | 用户主目录 | 全局插件配置(跨项目共享) |
49
105
 
50
- ```bash
51
- # macOS / Linux (Homebrew)
52
- brew install jnsahaj/lumen/lumen
106
+ **注意**:目录名称是 `.opencode`(带有点),不是 `opencode`。
53
107
 
54
- # 或使用 Cargo (Rust)
55
- cargo install lumen
108
+ ## 配置 opencode.json
109
+
110
+ 在项目的 `opencode.json` 中添加插件:
111
+
112
+ ```json
113
+ {
114
+ "command": {
115
+ "diff": {
116
+ "template": "Open the lumen diff viewer to show visual git diffs for modified files.",
117
+ "description": "View diff of modified files using lumen TUI"
118
+ }
119
+ },
120
+ "plugin": ["opencode-diff-viewer"]
121
+ }
56
122
  ```
57
123
 
58
124
  ## 使用方法
59
125
 
60
- ### 通过 / 命令
126
+ ### 通过命令
61
127
 
62
- 在 OpenCode TUI 中输入:
128
+ 在 OpenCode TUI 中直接输入:
63
129
 
64
- ```
65
- /diff # 查看所有修改文件的 diff
130
+ ```bash
131
+ /diff # 查看所有修改文件的 diff
66
132
  /diff src/app.ts # 查看指定文件的 diff
133
+ /diff src/ # 查看目录下所有文件的 diff
67
134
  ```
68
135
 
69
- ### 通过 LLM 工具调用
136
+ ### 通过 LLM
70
137
 
71
- LLM 可以自动调用 `view_diff` 工具来展示代码变更。
138
+ LLM 可以自动调用 `view_diff` 工具来展示代码变更。无需手动操作,LLM 会根据对话上下文智能判断何时需要展示 diff。
72
139
 
73
140
  ## lumen 快捷键
74
141
 
@@ -76,22 +143,126 @@ LLM 可以自动调用 `view_diff` 工具来展示代码变更。
76
143
 
77
144
  | 快捷键 | 功能 |
78
145
  |--------|------|
79
- | `j/k` 或 `↑/↓` | 导航 |
80
- | `{` / `}` | 跳转到上/下一个 hunk |
146
+ | `j` / `k` 或 `↑` / `↓` | 上/下移动 |
147
+ | `{` / `}` | 跳转到上/下一个变更块 |
81
148
  | `Tab` | 切换侧边栏 |
82
149
  | `e` | 在编辑器中打开文件 |
83
150
  | `q` | 退出 |
84
151
 
85
- ## 发布到 npm
152
+ ## 故障排除
153
+
154
+ ### 1. lumen 未安装
86
155
 
156
+ ```
157
+ ❌ lumen is not installed
158
+ ```
159
+
160
+ **解决方案**: 手动安装 lumen(见上方前置条件)
161
+
162
+ ### 2. 没有修改的文件
163
+
164
+ ```
165
+ 📝 No modified files to show diff for
166
+ ```
167
+
168
+ **解决方案**: 确保文件已修改并暂存:
87
169
  ```bash
88
- # 登录 npm
89
- npm login
170
+ git add .
171
+ ```
90
172
 
91
- # 发布包
92
- npm publish
173
+ ### 3. 新终端未打开
174
+
175
+ 检查终端模拟器是否支持:
176
+ - macOS: Terminal.app
177
+ - Linux: gnome-terminal 或 xterm
178
+
179
+ ### 4. 插件未加载
180
+
181
+ 检查配置文件是否正确:
182
+ ```bash
183
+ # 检查 .opencode 目录是否存在
184
+ ls -la .opencode/
185
+
186
+ # 检查 opencode.json 配置
187
+ cat opencode.json
188
+ ```
189
+
190
+ ### 5. 全局配置不生效
191
+
192
+ 确保全局配置路径正确:
193
+ ```bash
194
+ # macOS / Linux
195
+ ls -la ~/.config/opencode/
93
196
 
94
- # 发布新版本
95
- npm version patch|minor|major
197
+ # 检查配置内容
198
+ cat ~/.config/opencode/opencode.json
199
+ ```
200
+
201
+ ## 工作原理
202
+
203
+ 1. **检测修改文件** - 插件使用 `git diff` 获取已暂存和未暂存的修改
204
+ 2. **启动 lumen** - 在新终端窗口中运行 `lumen diff --file <files>`
205
+ 3. **自动安装** - 插件启动时检查 lumen,未安装则自动安装
206
+
207
+ ## 项目结构
208
+
209
+ ```
210
+ opencode-diff-viewer/
211
+ ├── src/
212
+ │ ├── index.ts # 插件主逻辑
213
+ │ └── command-diff.md # /diff 命令定义
214
+ ├── dist/ # 编译输出(发布用)
215
+ ├── package.json # npm 配置
216
+ └── tsconfig.json # TypeScript 配置
217
+ ```
218
+
219
+ ## 开发
220
+
221
+ ### 本地开发
222
+
223
+ ```bash
224
+ # 克隆项目
225
+ git clone https://github.com/AruNi-01/opencode-diff-viewer.git
226
+ cd opencode-diff-viewer
227
+
228
+ # 安装依赖
229
+ npm install
230
+ # 或
231
+ pnpm install
232
+ # 或
233
+ bun install
234
+
235
+ # 构建
236
+ npm run build
237
+
238
+ # 链接本地包
239
+ npm link
240
+
241
+ # 在测试项目中
242
+ npm link opencode-diff-viewer
243
+ ```
244
+
245
+ ### 发布新版本
246
+
247
+ ```bash
248
+ # 更新版本号
249
+ npm version patch # 1.0.0 -> 1.0.1
250
+ npm version minor # 1.0.0 -> 1.1.0
251
+ npm version major # 1.0.0 -> 2.0.0
252
+
253
+ # 发布
96
254
  npm publish
97
255
  ```
256
+
257
+ ## 依赖
258
+
259
+ - [lumen](https://github.com/jnsahaj/lumen) - TUI Diff 查看器
260
+ - [@opencode-ai/plugin](https://www.npmjs.com/package/@opencode-ai/plugin) - OpenCode 插件 SDK
261
+
262
+ ## License
263
+
264
+ MIT
265
+
266
+ ## 作者
267
+
268
+ [AarynLu](https://github.com/AruNi-01)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-diff-viewer",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "OpenCode plugin for viewing git diffs using lumen TUI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,8 +18,16 @@
18
18
  "lumen",
19
19
  "git"
20
20
  ],
21
- "author": "",
21
+ "author": "AarynLu",
22
22
  "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/AruNi-01/opencode-diff-viewer"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/AruNi-01/opencode-diff-viewer/issues"
29
+ },
30
+ "homepage": "https://github.com/AruNi-01/opencode-diff-viewer#readme",
23
31
  "peerDependencies": {
24
32
  "@opencode-ai/plugin": "^1.0.0"
25
33
  },