Start in the vault directory

This commit is contained in:
Mateusz Tymek
2026-01-03 16:35:22 +00:00
parent 5d6fcc3c41
commit 794317dbc7
2 changed files with 29 additions and 10 deletions

34
main.js
View File

@@ -347,7 +347,9 @@ var ProcessManager = class {
return this.state; return this.state;
} }
getUrl() { 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() { async start() {
var _a, _b; var _a, _b;
@@ -356,16 +358,23 @@ var ProcessManager = class {
} }
this.setState("starting"); this.setState("starting");
try { 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(); const alreadyRunning = await this.checkServerHealth();
if (alreadyRunning) { if (alreadyRunning) {
console.log("OpenCode server already running on port", this.settings.port); console.log("OpenCode server already running on port", this.settings.port);
this.setState("running"); this.setState("running");
return true; return true;
} }
console.log("[OpenCode] Starting server:", { console.log("[OpenCode] Starting server with vault:", {
path: this.settings.opencodePath, vaultDirectory: this.projectDirectory,
cwd: this.workingDirectory, workingDirectory: this.workingDirectory,
project: this.projectDirectory, opencodePath: this.settings.opencodePath,
port: this.settings.port, port: this.settings.port,
hostname: this.settings.hostname hostname: this.settings.hostname
}); });
@@ -490,12 +499,14 @@ var OpenCodePlugin = class extends import_obsidian4.Plugin {
async onload() { async onload() {
console.log("Loading OpenCode plugin"); console.log("Loading OpenCode plugin");
await this.loadSettings(); await this.loadSettings();
const vaultPath = this.getVaultPath();
this.processManager = new ProcessManager( this.processManager = new ProcessManager(
this.settings, this.settings,
this.getVaultPath(), vaultPath,
this.getVaultPath(), vaultPath,
(state) => this.notifyStateChange(state) (state) => this.notifyStateChange(state)
); );
console.log("[OpenCode] Configured with vault directory:", vaultPath);
this.registerView(OPENCODE_VIEW_TYPE, (leaf) => new OpenCodeView(leaf, this)); this.registerView(OPENCODE_VIEW_TYPE, (leaf) => new OpenCodeView(leaf, this));
this.addRibbonIcon("terminal", "OpenCode", () => { this.addRibbonIcon("terminal", "OpenCode", () => {
this.activateView(); this.activateView();
@@ -624,9 +635,14 @@ var OpenCodePlugin = class extends import_obsidian4.Plugin {
callback(state); 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() { getVaultPath() {
const adapter = this.app.vault.adapter; 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;
} }
}; };

View File

@@ -34,7 +34,10 @@ export class ProcessManager {
} }
getUrl(): string { 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<boolean> { async start(): Promise<boolean> {