From e4ae5ff997df43829dcec29cf082c57a130d5a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD?= Date: Sat, 26 Sep 2026 00:12:27 +0300 Subject: [PATCH] chore: move plugin files from /tmp to home directory Replace /tmp/opencode-matrix-plugin/* with ~/.opencode-matrix-plugin-* to support systems without /tmp (e.g. Termux on Android). --- index.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 8c301ca..6785b24 100644 --- a/index.ts +++ b/index.ts @@ -1,17 +1,22 @@ import fs from "fs" +import os from "os" import { MatrixBotClient } from "./matrix-client.js" import { SessionManager } from "./session-manager.js" import { loadConfig } from "./config-loader.js" import { log } from "./logger.js" +const PLUGIN_DATA_DIR = fs.mkdtempSync(`${os.homedir()}/.opencode-matrix-plugin-`) +const LOG_FILE = `${PLUGIN_DATA_DIR}/plugin.log` +const SETUP_STARTED_LOG = `${PLUGIN_DATA_DIR}/setup-started.log` +const SETUP_ERROR_LOG = `${PLUGIN_DATA_DIR}/setup-error.log` +const LOCK_FILE = `${PLUGIN_DATA_DIR}/lock` + log("Plugin module loaded") // ============================================================================= // Global mutex — prevents double startup (server + client both load plugins) // ============================================================================= -const LOCK_FILE = "/tmp/opencode-matrix-plugin.lock" - function tryAcquireLock(): boolean { try { // Check if an existing lock is stale (process no longer running) @@ -63,7 +68,7 @@ async function runPlugin(ctx: any, options: any) { try { const directory = ctx?.location?.directory || process.cwd() - fs.appendFileSync("/tmp/opencode-matrix-plugin/setup-started.log", `[${new Date().toISOString()}] setup() called, dir=${directory}\n`) + fs.appendFileSync(SETUP_STARTED_LOG, `[${new Date().toISOString()}] setup() called, dir=${directory}\n`) log(`Plugin setup started, directory=${directory}`) if (!options.homeserver) { @@ -265,7 +270,7 @@ async function runPlugin(ctx: any, options: any) { return cleanup } catch (err) { - fs.appendFileSync("/tmp/opencode-matrix-plugin/setup-error.log", `[${new Date().toISOString()}] ${String(err)}\n`) + fs.appendFileSync(SETUP_ERROR_LOG, `[${new Date().toISOString()}] ${String(err)}\n`) log(`Setup error: ${String(err)}`) releaseLock() return () => {} @@ -281,7 +286,7 @@ async function v2Setup(ctx: any) { const { options } = await loadConfig(ctx.options) return await runPlugin(ctx, options) } catch (err) { - fs.appendFileSync("/tmp/opencode-matrix-plugin/setup-error.log", `[${new Date().toISOString()}] ${String(err)}\n`) + fs.appendFileSync(SETUP_ERROR_LOG, `[${new Date().toISOString()}] ${String(err)}\n`) log(`V2 setup error: ${String(err)}`) return () => {} }