From 794317dbc77caea2f4885fd743398341b76739e3 Mon Sep 17 00:00:00 2001 From: Mateusz Tymek Date: Sat, 3 Jan 2026 16:35:22 +0000 Subject: [PATCH] Start in the vault directory --- main.js | 34 +++++++++++++++++++++++++--------- src/ProcessManager.ts | 5 ++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 28c877a..b5f917b 100644 --- a/main.js +++ b/main.js @@ -347,7 +347,9 @@ var ProcessManager = class { return this.state; } getUrl() { - return `http://${this.settings.hostname}:${this.settings.port}`; + const baseUrl = `http://${this.settings.hostname}:${this.settings.port}`; + const encodedPath = btoa(this.projectDirectory); + return `${baseUrl}/${encodedPath}`; } async start() { var _a, _b; @@ -356,16 +358,23 @@ var ProcessManager = class { } this.setState("starting"); try { + if (!this.projectDirectory) { + const error = "Project directory (vault) not configured"; + console.error("[OpenCode Error]", error); + new import_obsidian3.Notice(`Failed to start OpenCode: ${error}`); + this.setState("error"); + return false; + } const alreadyRunning = await this.checkServerHealth(); if (alreadyRunning) { console.log("OpenCode server already running on port", this.settings.port); this.setState("running"); return true; } - console.log("[OpenCode] Starting server:", { - path: this.settings.opencodePath, - cwd: this.workingDirectory, - project: this.projectDirectory, + console.log("[OpenCode] Starting server with vault:", { + vaultDirectory: this.projectDirectory, + workingDirectory: this.workingDirectory, + opencodePath: this.settings.opencodePath, port: this.settings.port, hostname: this.settings.hostname }); @@ -490,12 +499,14 @@ var OpenCodePlugin = class extends import_obsidian4.Plugin { async onload() { console.log("Loading OpenCode plugin"); await this.loadSettings(); + const vaultPath = this.getVaultPath(); this.processManager = new ProcessManager( this.settings, - this.getVaultPath(), - this.getVaultPath(), + vaultPath, + vaultPath, (state) => this.notifyStateChange(state) ); + console.log("[OpenCode] Configured with vault directory:", vaultPath); this.registerView(OPENCODE_VIEW_TYPE, (leaf) => new OpenCodeView(leaf, this)); this.addRibbonIcon("terminal", "OpenCode", () => { this.activateView(); @@ -624,9 +635,14 @@ var OpenCodePlugin = class extends import_obsidian4.Plugin { callback(state); } } - // Get the vault path + // Get the vault path - this is the root directory of the Obsidian vault + // which will be passed to OpenCode as the project directory getVaultPath() { const adapter = this.app.vault.adapter; - return adapter.basePath || ""; + const vaultPath = adapter.basePath || ""; + if (!vaultPath) { + console.warn("[OpenCode] Warning: Could not determine vault path"); + } + return vaultPath; } }; diff --git a/src/ProcessManager.ts b/src/ProcessManager.ts index d2ce487..3c2658f 100644 --- a/src/ProcessManager.ts +++ b/src/ProcessManager.ts @@ -34,7 +34,10 @@ export class ProcessManager { } getUrl(): string { - return `http://${this.settings.hostname}:${this.settings.port}`; + const baseUrl = `http://${this.settings.hostname}:${this.settings.port}`; + // Encode the project directory path as base64 for the URL + const encodedPath = btoa(this.projectDirectory); + return `${baseUrl}/${encodedPath}`; } async start(): Promise {