@xinleibird/bridge-opencode 0.2.0 → 0.2.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 (3) hide show
  1. package/bridge.ts +35 -10
  2. package/package.json +1 -1
  3. package/rustfmt.toml +0 -0
package/bridge.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
+ import crypto from "node:crypto";
3
+ import { access } from "node:fs/promises";
2
4
  import { isAbsolute, join } from "node:path";
3
5
  import { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } from "./index.cjs";
4
6
 
@@ -87,7 +89,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
87
89
  }
88
90
  },
89
91
 
90
- "chat.message": async (_input, output) => {
92
+ "chat.message": async (input, output) => {
91
93
  let selections;
92
94
  try {
93
95
  selections = await getVisualSelections();
@@ -99,17 +101,40 @@ 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
+ const refs: string[] = [];
105
+ let attached = 0;
106
+ for (const s of filteredSelections) {
107
+ try {
108
+ await access(s.filePath);
109
+ } catch {
110
+ continue;
111
+ }
112
+ if (!s.startLine) continue;
113
+
114
+ const filename = s.filePath.startsWith(cwd + "/")
115
+ ? "./" + s.filePath.slice(cwd.length + 1)
116
+ : s.filePath;
117
+ const displayFilename = `${filename}:${s.startLine}-${s.endLine}`;
118
+ refs.push(displayFilename);
119
+
120
+ output.parts.push({
121
+ type: "file",
122
+ id: crypto.randomUUID(),
123
+ sessionID: input.sessionID,
124
+ messageID: input.messageID ?? "",
125
+ mime: "text/plain",
126
+ filename: displayFilename,
127
+ url: `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`,
128
+ });
129
+ attached++;
130
+ }
104
131
 
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
- });
132
+ if (attached === 0) return;
111
133
 
112
- textPart.text = `${lines.join("\n")}\n\n${textPart.text}`;
134
+ const textPart = output.parts.find((p: any) => p.type === "text") as any;
135
+ if (textPart && typeof textPart.text === "string") {
136
+ textPart.text = `${refs.join("\n")}\n\n${textPart.text}`;
137
+ }
113
138
  },
114
139
  };
115
140
  };
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.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/xinleibird/bridge-opencode"
package/rustfmt.toml DELETED
File without changes