Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# OpenCode plugin for Obsidian

> ⚠️ **已知问题(重要)**
>
> 在 Windows 上使用 WSL 时,**同时在 Obsidian 中启动 OpenCode 和在 WSL 中启动 OpenCode 会导致 OpenCode 数据库损坏**。
>
> **请避免同时运行两个实例!** 如果需要在 WSL 中使用 OpenCode,请先关闭 Obsidian 中的 OpenCode 面板,反之亦然。
>
> 本插件已解决 WSL 上的 OpenCode 作为插件嵌入到 Windows 上的 Obsidian 中无法正常使用的问题,但上述并发问题仍需注意。

---

Give your notes AI capability by embedding Opencode [OpenCode](https://opencode.ai) AI assistant directly in Obsidian:

Expand Down
15 changes: 9 additions & 6 deletions src/server/ServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export class ServerManager extends EventEmitter {
// Determine execution mode and resolve executable path
let executablePath: string;
let spawnOptions: SpawnOptions;

if (this.settings.useCustomCommand) {
const useCustomCommand =
Boolean(this.settings.useCustomCommand) &&
this.settings.customCommand.trim().length > 0;

if (useCustomCommand) {
// Custom command mode: use custom command directly with shell
executablePath = this.settings.customCommand;
spawnOptions = {
Expand Down Expand Up @@ -101,15 +104,15 @@ export class ServerManager extends EventEmitter {
}

console.log("[OpenCode] Starting server:", {
mode: this.settings.useCustomCommand ? "custom" : "path",
mode: useCustomCommand ? "custom" : "path",
command: executablePath,
port: this.settings.port,
hostname: this.settings.hostname,
cwd: this.projectDirectory,
projectDirectory: this.projectDirectory,
});

if (this.settings.useCustomCommand) {
if (useCustomCommand) {
// Custom command mode: spawn with shell, no args appended
this.process = this.processImpl.start(
executablePath,
Expand Down Expand Up @@ -163,8 +166,8 @@ export class ServerManager extends EventEmitter {
this.process = null;

if (err.code === "ENOENT") {
const command = this.settings.useCustomCommand
? this.settings.customCommand
const command = useCustomCommand
? this.settings.customCommand
: this.settings.opencodePath;
this.setError(
`Executable not found: '${command}'`
Expand Down