@xinleibird/bridge-opencode 0.2.0 → 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.
Files changed (3) hide show
  1. package/bridge.ts +36 -10
  2. package/package.json +4 -1
  3. package/rustfmt.toml +0 -0
package/bridge.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
- import { isAbsolute, join } from "node:path";
2
+ import { access } from "node:fs/promises";
3
+ import { extname, isAbsolute, join } from "node:path";
4
+ import { lookup } from "mime-types";
3
5
  import { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } from "./index.cjs";
4
6
 
5
7
  type ToolName = "Edit" | "Write";
@@ -99,17 +101,41 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
99
101
  const filteredSelections = selections.filter((s) => !s.cwd || s.cwd === cwd);
100
102
  if (filteredSelections.length === 0) return;
101
103
 
102
- const textPart = output.parts.find((p: any) => p.type === "text") as any;
103
- 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
+ }
104
132
 
105
- const lines = filteredSelections.map((s) => {
106
- const path = s.filePath.startsWith(cwd + "/")
107
- ? "- @" + s.filePath.slice(cwd.length + 1)
108
- : "- " + s.filePath;
109
- return `${path}:${s.startLine}-${s.endLine}`;
110
- });
133
+ if (attached === 0) return;
111
134
 
112
- 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
+ }
113
139
  },
114
140
  };
115
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.2.0",
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
  },
package/rustfmt.toml DELETED
File without changes