opencode-diff-viewer 1.0.5 → 1.0.7
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 +3 -3
- package/dist/index.d.ts +0 -5
- package/dist/index.js +28 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
brew install jnsahaj/lumen/lumen
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
**
|
|
26
|
+
**Bun**:
|
|
27
27
|
```bash
|
|
28
28
|
bun install jnsahaj/lumen/lumen
|
|
29
29
|
```
|
|
@@ -121,7 +121,7 @@ LLM 可以自动调用 `view_diff` 工具来展示代码变更。无需手动操
|
|
|
121
121
|
### 2. 没有修改的文件
|
|
122
122
|
|
|
123
123
|
```
|
|
124
|
-
📝 No modified files
|
|
124
|
+
📝 No modified files
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
**解决方案**: 确保文件已修改并暂存:
|
|
@@ -142,7 +142,7 @@ git add .
|
|
|
142
142
|
cat ~/.config/opencode/opencode.json
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
确保配置正确:
|
|
146
146
|
```json
|
|
147
147
|
{
|
|
148
148
|
"command": {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { tool } from "@opencode-ai/plugin";
|
|
2
|
-
/**
|
|
3
|
-
* OpenCode Diff Viewer Plugin
|
|
4
|
-
* Uses lumen (https://github.com/jnsahaj/lumen) for visual git diffs.
|
|
5
|
-
* Automatically installs lumen if not present.
|
|
6
|
-
*/
|
|
7
2
|
export const DiffViewerPlugin = async ({ project, client, $, directory, worktree }) => {
|
|
8
3
|
const isLumenInstalled = async () => {
|
|
9
4
|
try {
|
|
@@ -83,46 +78,55 @@ export const DiffViewerPlugin = async ({ project, client, $, directory, worktree
|
|
|
83
78
|
};
|
|
84
79
|
const launchDiffViewer = async (files) => {
|
|
85
80
|
if (!await isLumenInstalled()) {
|
|
86
|
-
return
|
|
81
|
+
return `❌ lumen is not installed.
|
|
82
|
+
|
|
83
|
+
To install:
|
|
84
|
+
brew install jnsahaj/lumen/lumen
|
|
85
|
+
# or
|
|
86
|
+
cargo install lumen
|
|
87
|
+
|
|
88
|
+
Then restart OpenCode.`;
|
|
87
89
|
}
|
|
88
90
|
const modifiedFiles = files && files.length > 0 ? files : await getModifiedFiles();
|
|
89
91
|
if (modifiedFiles.length === 0) {
|
|
90
|
-
return "📝 No modified files
|
|
92
|
+
return "📝 No modified files.\n\nRun \`git add .\` to stage changes first.";
|
|
91
93
|
}
|
|
92
|
-
const
|
|
94
|
+
const fileList = modifiedFiles.map(f => ` • ${f}`).join('\n');
|
|
93
95
|
const fileArgs = modifiedFiles.map(f => `"${f}"`).join(' ');
|
|
94
96
|
const cmd = `cd "${directory}" && lumen diff ${fileArgs}`;
|
|
97
|
+
const platform = process.platform;
|
|
98
|
+
// Try to launch in new terminal
|
|
99
|
+
let launched = false;
|
|
100
|
+
let errorMsg = "";
|
|
95
101
|
try {
|
|
96
102
|
if (platform === 'darwin') {
|
|
97
103
|
await $ `osascript -e 'tell application "Terminal" to do script "${cmd}; exit"'`;
|
|
104
|
+
launched = true;
|
|
98
105
|
}
|
|
99
106
|
else if (platform === 'linux') {
|
|
100
107
|
try {
|
|
101
108
|
await $ `which gnome-terminal && gnome-terminal -- bash -c "${cmd}; read -p 'Press Enter to close...'" `;
|
|
109
|
+
launched = true;
|
|
102
110
|
}
|
|
103
111
|
catch {
|
|
104
112
|
try {
|
|
105
113
|
await $ `which xterm && xterm -e "bash -c '${cmd}; read -p Press Enter to close...'" `;
|
|
114
|
+
launched = true;
|
|
106
115
|
}
|
|
107
|
-
catch {
|
|
108
|
-
|
|
116
|
+
catch (e) {
|
|
117
|
+
errorMsg = "No terminal emulator found (gnome-terminal/xterm)";
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
120
|
}
|
|
112
|
-
else {
|
|
113
|
-
await $ `${cmd}`;
|
|
114
|
-
}
|
|
115
|
-
return `✅ Opened lumen diff viewer for ${modifiedFiles.length} file(s):
|
|
116
|
-
${modifiedFiles.map(f => ` • ${f}`).join('\n')}
|
|
117
|
-
|
|
118
|
-
Keybindings:
|
|
119
|
-
j/k or ↑/↓: Navigate {/}: Jump between hunks
|
|
120
|
-
tab: Toggle sidebar e: Open in editor
|
|
121
|
-
q: Quit`;
|
|
122
121
|
}
|
|
123
|
-
catch (
|
|
124
|
-
|
|
122
|
+
catch (e) {
|
|
123
|
+
errorMsg = e.message || "Unknown error";
|
|
124
|
+
}
|
|
125
|
+
if (launched) {
|
|
126
|
+
return `✅ Opened lumen diff viewer:\n${fileList}\n\nKeybindings:\n j/k: Navigate {/}: Jump hunks tab: Sidebar e: Edit q: Quit`;
|
|
125
127
|
}
|
|
128
|
+
// If we couldn't launch, show manual instructions
|
|
129
|
+
return `📺 Could not open terminal automatically.\n\nTo view diffs in lumen:\n1. Open a new terminal\n2. Run:\n ${cmd}\n\nModified files:\n${fileList}`;
|
|
126
130
|
};
|
|
127
131
|
return {
|
|
128
132
|
"tui.command.execute": async (input, output) => {
|
|
@@ -137,9 +141,9 @@ Keybindings:
|
|
|
137
141
|
},
|
|
138
142
|
tool: {
|
|
139
143
|
view_diff: tool({
|
|
140
|
-
description: "Open the lumen diff viewer to show git diff for modified files.
|
|
144
|
+
description: "Open the lumen diff viewer to show git diff for modified files.",
|
|
141
145
|
args: {
|
|
142
|
-
file: tool.schema.string().optional().describe("Optional: specific file path
|
|
146
|
+
file: tool.schema.string().optional().describe("Optional: specific file path"),
|
|
143
147
|
},
|
|
144
148
|
async execute(args, ctx) {
|
|
145
149
|
return await launchDiffViewer(args.file ? [args.file] : undefined);
|