@xinleibird/bridge-opencode 0.2.4 → 0.2.5

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,8 +1,27 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
2
  import crypto from "node:crypto";
3
3
  import { access } from "node:fs/promises";
4
- import { isAbsolute, join } from "node:path";
5
- import { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } from "./index.cjs";
4
+ import { basename, isAbsolute, join } from "node:path";
5
+
6
+ interface BufferStatus {
7
+ isCurrent: boolean;
8
+ hasUnsavedChanges: boolean;
9
+ }
10
+
11
+ interface EditorContext {
12
+ filePath: string;
13
+ startLine: number;
14
+ endLine: number;
15
+ cwd: string;
16
+ content: string;
17
+ }
18
+
19
+ const { checkBuffer, refreshBuffer, getVisualSelections, sendMessage } = require("./index.cjs") as {
20
+ checkBuffer: (filePath: string) => Promise<BufferStatus>;
21
+ refreshBuffer: (filePath: string) => Promise<void>;
22
+ getVisualSelections: () => Promise<EditorContext[]>;
23
+ sendMessage: (message: string, level?: string) => Promise<void>;
24
+ };
6
25
 
7
26
  type ToolName = "Edit" | "Write";
8
27
 
@@ -69,7 +88,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
69
88
  for (const filePath of call.filePaths) {
70
89
  const status = await checkBuffer(filePath);
71
90
  if (status.hasUnsavedChanges && status.isCurrent) {
72
- await sendMessage("⚠️ File has unsaved changes. Please save it first.");
91
+ await sendMessage("⚠️ File has unsaved changes. Please save it first.", "warn");
73
92
  throw new Error(
74
93
  "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.",
75
94
  );
@@ -86,11 +105,12 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
86
105
 
87
106
  for (const filePath of pending.filePaths) {
88
107
  await refreshBuffer(filePath);
108
+ await sendMessage("🔄 Reloaded by OpenCode.", "info");
89
109
  }
90
110
  },
91
111
 
92
112
  "chat.message": async (input, output) => {
93
- let selections;
113
+ let selections: Awaited<ReturnType<typeof getVisualSelections>>;
94
114
  try {
95
115
  selections = await getVisualSelections();
96
116
  } catch {
@@ -111,11 +131,13 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
111
131
  }
112
132
  if (!s.startLine) continue;
113
133
 
114
- const filename = s.filePath.startsWith(cwd + "/")
134
+ const filepath = s.filePath.startsWith(cwd + "/")
115
135
  ? "./" + s.filePath.slice(cwd.length + 1)
116
136
  : s.filePath;
117
- const displayFilename = `${filename}:${s.startLine}-${s.endLine}`;
118
- refs.push(displayFilename);
137
+
138
+ refs.push(filepath);
139
+
140
+ const filename = basename(s.filePath);
119
141
 
120
142
  output.parts.push({
121
143
  type: "file",
@@ -123,7 +145,7 @@ export const BridgePlugin: Plugin = async ({ directory }) => {
123
145
  sessionID: input.sessionID,
124
146
  messageID: input.messageID ?? "",
125
147
  mime: "text/plain",
126
- filename: displayFilename,
148
+ filename: filename,
127
149
  url: `file://${s.filePath}?start=${s.startLine}&end=${s.endLine}`,
128
150
  });
129
151
  attached++;
package/index.d.ts CHANGED
@@ -17,4 +17,4 @@ export interface EditorContext {
17
17
  export declare function checkBuffer(filePath: string): BufferStatus
18
18
  export declare function refreshBuffer(filePath: string): void
19
19
  export declare function getVisualSelections(): Array<EditorContext>
20
- export declare function sendMessage(message: string): void
20
+ export declare function sendMessage(message: string, level?: string | undefined | null): void
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,7 +21,8 @@
21
21
  "build": "napi build --platform --release --features napi --js index.cjs"
22
22
  },
23
23
  "devDependencies": {
24
- "@napi-rs/cli": "^2.18.0"
24
+ "@napi-rs/cli": "^2.18.0",
25
+ "@types/node": "^25.9.1"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "@opencode-ai/plugin": ">=1.0.0"
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "noImplicitAny": true,
8
+ "noEmit": true
9
+ },
10
+ "include": ["bridge.ts"]
11
+ }