@xinleibird/bridge-opencode 0.1.9 → 0.2.1

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.
Binary file
Binary file
Binary file
package/bridge.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
- import { isAbsolute, join } from "node:path";
3
- import { checkBuffer, refreshBuffer, getVisualSelections } from "./index.cjs";
2
+ import { access } from "node:fs/promises";
3
+ import { extname, isAbsolute, join } from "node:path";
4
+ import { lookup } from "mime-types";
5
+ import { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } from "./index.cjs";
4
6
 
5
7
  type ToolName = "Edit" | "Write";
6
8
 
@@ -67,6 +69,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
67
69
  for (const filePath of call.filePaths) {
68
70
  const status = await checkBuffer(filePath);
69
71
  if (status.hasUnsavedChanges && status.isCurrent) {
72
+ await sendMessage("File has unsaved changes. Please save it first.");
70
73
  throw new Error(
71
74
  "STOP: Cannot apply changes — Neovim has unsaved edits. DO NOT attempt to resolve this yourself. Wait for the user to save or close the file. DO NOT use the Built-In Tools resolve this.",
72
75
  );
@@ -98,17 +101,41 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
98
101
  const filteredSelections = selections.filter((s) => !s.cwd || s.cwd === cwd);
99
102
  if (filteredSelections.length === 0) return;
100
103
 
101
- const textPart = output.parts.find((p: any) => p.type === "text") as any;
102
- if (!textPart || typeof textPart.text !== "string") return;
104
+ let attached = 0;
105
+ for (const s of filteredSelections) {
106
+ try {
107
+ await access(s.filePath);
108
+ } catch {
109
+ continue;
110
+ }
111
+
112
+ const filename = s.filePath.startsWith(cwd + "/")
113
+ ? "./" + s.filePath.slice(cwd.length + 1)
114
+ : s.filePath;
115
+
116
+ const url = s.startLine
117
+ ? `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`
118
+ : `file://${s.filePath}`;
119
+
120
+ const displayFilename = s.startLine
121
+ ? `${filename}:${s.startLine}-${s.endLine}`
122
+ : filename;
123
+
124
+ output.parts.push({
125
+ type: "file",
126
+ mime: lookup(extname(s.filePath)) || "text/plain",
127
+ filename: displayFilename,
128
+ url,
129
+ });
130
+ attached++;
131
+ }
103
132
 
104
- const lines = filteredSelections.map((s) => {
105
- const path = s.filePath.startsWith(cwd + "/")
106
- ? "- @" + s.filePath.slice(cwd.length + 1)
107
- : "- " + s.filePath;
108
- return `${path}:${s.startLine}-${s.endLine}`;
109
- });
133
+ if (attached === 0) return;
110
134
 
111
- textPart.text = `${lines.join("\n")}\n\n${textPart.text}`;
135
+ const textPart = output.parts.find((p: any) => p.type === "text") as any;
136
+ if (textPart && typeof textPart.text === "string") {
137
+ textPart.text = `[Attached ${attached} selection(s)]\n\n${textPart.text}`;
138
+ }
112
139
  },
113
140
  };
114
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/xinleibird/bridge-opencode"
@@ -22,6 +22,9 @@
22
22
  "devDependencies": {
23
23
  "@napi-rs/cli": "^2.18.0"
24
24
  },
25
+ "dependencies": {
26
+ "mime-types": "^3.0.2"
27
+ },
25
28
  "peerDependencies": {
26
29
  "@opencode-ai/plugin": ">=1.0.0"
27
30
  },