opencode-diff-viewer 1.0.2 → 1.0.4
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.
- package/README.md +30 -73
- package/dist/index.js +28 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,84 +43,44 @@ cargo install lumen
|
|
|
43
43
|
git status # 查看修改的文件
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
##
|
|
46
|
+
## 安装(全局配置)
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### 1. 安装 npm 包
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
51
|
# npm
|
|
52
|
-
npm install opencode-diff-viewer
|
|
52
|
+
npm install -g opencode-diff-viewer
|
|
53
53
|
|
|
54
54
|
# pnpm
|
|
55
|
-
pnpm add opencode-diff-viewer
|
|
55
|
+
pnpm add -g opencode-diff-viewer
|
|
56
56
|
|
|
57
57
|
# bun
|
|
58
|
-
bun add opencode-diff-viewer
|
|
58
|
+
bun add -g opencode-diff-viewer
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### 2. 配置全局 opencode.json
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
1. 创建全局配置目录:
|
|
66
|
-
```bash
|
|
67
|
-
mkdir -p ~/.config/opencode
|
|
68
|
-
```
|
|
69
|
-
|
|
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` 目录(注意前面的点):
|
|
63
|
+
创建或编辑 `~/.config/opencode/opencode.json`:
|
|
82
64
|
|
|
83
65
|
```bash
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
mkdir -p .opencode/command
|
|
87
|
-
|
|
88
|
-
# 复制插件文件
|
|
89
|
-
cp node_modules/opencode-diff-viewer/dist .opencode/plugin/diff-viewer
|
|
90
|
-
cp node_modules/opencode-diff-viewer/command-diff.md .opencode/command/diff.md
|
|
91
|
-
|
|
92
|
-
# 或使用 npm link
|
|
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
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### 目录说明
|
|
100
|
-
|
|
101
|
-
| 目录 | 位置 | 作用 |
|
|
102
|
-
|------|------|------|
|
|
103
|
-
| `.opencode/` | 项目根目录 | 项目级别插件配置 |
|
|
104
|
-
| `~/.config/opencode/` | 用户主目录 | 全局插件配置(跨项目共享) |
|
|
105
|
-
|
|
106
|
-
**注意**:目录名称是 `.opencode`(带有点),不是 `opencode`。
|
|
107
|
-
|
|
108
|
-
## 配置 opencode.json
|
|
109
|
-
|
|
110
|
-
在项目的 `opencode.json` 中添加插件:
|
|
111
|
-
|
|
112
|
-
```json
|
|
66
|
+
mkdir -p ~/.config/opencode
|
|
67
|
+
cat > ~/.config/opencode/opencode.json << 'EOF'
|
|
113
68
|
{
|
|
114
69
|
"command": {
|
|
115
70
|
"diff": {
|
|
116
|
-
"template": "
|
|
71
|
+
"template": "View git diff using lumen TUI.",
|
|
117
72
|
"description": "View diff of modified files using lumen TUI"
|
|
118
73
|
}
|
|
119
74
|
},
|
|
120
75
|
"plugin": ["opencode-diff-viewer"]
|
|
121
76
|
}
|
|
77
|
+
EOF
|
|
122
78
|
```
|
|
123
79
|
|
|
80
|
+
### 3. 重启 OpenCode
|
|
81
|
+
|
|
82
|
+
安装完成后重启 OpenCode TUI,插件会自动加载。
|
|
83
|
+
|
|
124
84
|
## 使用方法
|
|
125
85
|
|
|
126
86
|
### 通过命令
|
|
@@ -130,7 +90,6 @@ ln -s /path/to/your/project/node_modules/opencode-diff-viewer/command-diff.md ./
|
|
|
130
90
|
```bash
|
|
131
91
|
/diff # 查看所有修改文件的 diff
|
|
132
92
|
/diff src/app.ts # 查看指定文件的 diff
|
|
133
|
-
/diff src/ # 查看目录下所有文件的 diff
|
|
134
93
|
```
|
|
135
94
|
|
|
136
95
|
### 通过 LLM
|
|
@@ -178,24 +137,22 @@ git add .
|
|
|
178
137
|
|
|
179
138
|
### 4. 插件未加载
|
|
180
139
|
|
|
181
|
-
|
|
140
|
+
检查全局配置文件是否正确:
|
|
182
141
|
```bash
|
|
183
|
-
|
|
184
|
-
ls -la .opencode/
|
|
185
|
-
|
|
186
|
-
# 检查 opencode.json 配置
|
|
187
|
-
cat opencode.json
|
|
142
|
+
cat ~/.config/opencode/opencode.json
|
|
188
143
|
```
|
|
189
144
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
145
|
+
确保配置正确,包含 `command` 和 `plugin` 两部分:
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"command": {
|
|
149
|
+
"diff": {
|
|
150
|
+
"template": "View git diff using lumen TUI.",
|
|
151
|
+
"description": "View diff of modified files using lumen TUI"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"plugin": ["opencode-diff-viewer"]
|
|
155
|
+
}
|
|
199
156
|
```
|
|
200
157
|
|
|
201
158
|
## 工作原理
|
|
@@ -238,8 +195,8 @@ npm run build
|
|
|
238
195
|
# 链接本地包
|
|
239
196
|
npm link
|
|
240
197
|
|
|
241
|
-
#
|
|
242
|
-
npm link opencode-diff-viewer
|
|
198
|
+
# 在全局使用
|
|
199
|
+
npm link -g opencode-diff-viewer
|
|
243
200
|
```
|
|
244
201
|
|
|
245
202
|
### 发布新版本
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ export const DiffViewerPlugin = async ({ project, client, $, directory, worktree
|
|
|
66
66
|
}
|
|
67
67
|
return { installed: false, message: `❌ ${result.error}` };
|
|
68
68
|
};
|
|
69
|
-
|
|
69
|
+
await ensureLumenInstalled();
|
|
70
70
|
const getModifiedFiles = async () => {
|
|
71
71
|
try {
|
|
72
72
|
const unstaged = await $ `git diff --name-only`.text();
|
|
@@ -81,41 +81,38 @@ export const DiffViewerPlugin = async ({ project, client, $, directory, worktree
|
|
|
81
81
|
return [];
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
-
const openDiffInNewTerminal = async (fileArgs) => {
|
|
85
|
-
const platform = process.platform;
|
|
86
|
-
if (platform === 'darwin') {
|
|
87
|
-
await $ `osascript -e 'tell application "Terminal" to do script "cd ${directory} && lumen diff ${fileArgs}; exit"'`;
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (platform === 'linux') {
|
|
91
|
-
try {
|
|
92
|
-
await $ `which gnome-terminal && gnome-terminal -- bash -c "cd ${directory} && lumen diff ${fileArgs}; read -p 'Press Enter to close...'"`;
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
try {
|
|
97
|
-
await $ `which xterm && xterm -e "cd ${directory} && lumen diff ${fileArgs}; read -p 'Press Enter to close...'"`;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
catch { }
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
await $ `lumen diff ${fileArgs}`;
|
|
104
|
-
};
|
|
105
84
|
const launchDiffViewer = async (files) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return lumenCheck.message || "❌ lumen is not installed and auto-install failed.";
|
|
85
|
+
if (!await isLumenInstalled()) {
|
|
86
|
+
return "❌ lumen is not installed.\n\nTo install:\n brew install jnsahaj/lumen/lumen\n # or\n cargo install lumen";
|
|
109
87
|
}
|
|
110
88
|
const modifiedFiles = files && files.length > 0 ? files : await getModifiedFiles();
|
|
111
89
|
if (modifiedFiles.length === 0) {
|
|
112
|
-
return "📝 No modified files to show diff for.";
|
|
90
|
+
return "📝 No modified files to show diff for.\n\nRun `git add .` to stage changes first.";
|
|
113
91
|
}
|
|
92
|
+
const platform = process.platform;
|
|
93
|
+
const fileArgs = modifiedFiles.map(f => `"${f}"`).join(' ');
|
|
94
|
+
const cmd = `cd "${directory}" && lumen diff ${fileArgs}`;
|
|
114
95
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
96
|
+
if (platform === 'darwin') {
|
|
97
|
+
await $ `osascript -e 'tell application "Terminal" to do script "${cmd}; exit"'`;
|
|
98
|
+
}
|
|
99
|
+
else if (platform === 'linux') {
|
|
100
|
+
try {
|
|
101
|
+
await $ `which gnome-terminal && gnome-terminal -- bash -c "${cmd}; read -p 'Press Enter to close...'" `;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
try {
|
|
105
|
+
await $ `which xterm && xterm -e "bash -c '${cmd}; read -p Press Enter to close...'" `;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return `❌ No terminal emulator found (gnome-terminal/xterm).\n\nPlease run manually:\n ${cmd}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
await $ `${cmd}`;
|
|
114
|
+
}
|
|
115
|
+
return `✅ Opened lumen diff viewer for ${modifiedFiles.length} file(s):
|
|
119
116
|
${modifiedFiles.map(f => ` • ${f}`).join('\n')}
|
|
120
117
|
|
|
121
118
|
Keybindings:
|
|
@@ -124,7 +121,7 @@ Keybindings:
|
|
|
124
121
|
q: Quit`;
|
|
125
122
|
}
|
|
126
123
|
catch (error) {
|
|
127
|
-
return `❌ Failed to launch diff viewer: ${error}`;
|
|
124
|
+
return `❌ Failed to launch diff viewer: ${error}\n\nTry running manually:\n ${cmd}`;
|
|
128
125
|
}
|
|
129
126
|
};
|
|
130
127
|
return {
|