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).
This commit is contained in:
Бородин Роман 2026-09-26 00:12:27 +03:00
parent f981998ab8
commit e4ae5ff997
1 changed files with 10 additions and 5 deletions

View File

@ -1,17 +1,22 @@
import fs from "fs" import fs from "fs"
import os from "os"
import { MatrixBotClient } from "./matrix-client.js" import { MatrixBotClient } from "./matrix-client.js"
import { SessionManager } from "./session-manager.js" import { SessionManager } from "./session-manager.js"
import { loadConfig } from "./config-loader.js" import { loadConfig } from "./config-loader.js"
import { log } from "./logger.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") log("Plugin module loaded")
// ============================================================================= // =============================================================================
// Global mutex — prevents double startup (server + client both load plugins) // Global mutex — prevents double startup (server + client both load plugins)
// ============================================================================= // =============================================================================
const LOCK_FILE = "/tmp/opencode-matrix-plugin.lock"
function tryAcquireLock(): boolean { function tryAcquireLock(): boolean {
try { try {
// Check if an existing lock is stale (process no longer running) // Check if an existing lock is stale (process no longer running)
@ -63,7 +68,7 @@ async function runPlugin(ctx: any, options: any) {
try { try {
const directory = ctx?.location?.directory || process.cwd() 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}`) log(`Plugin setup started, directory=${directory}`)
if (!options.homeserver) { if (!options.homeserver) {
@ -265,7 +270,7 @@ async function runPlugin(ctx: any, options: any) {
return cleanup return cleanup
} catch (err) { } 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)}`) log(`Setup error: ${String(err)}`)
releaseLock() releaseLock()
return () => {} return () => {}
@ -281,7 +286,7 @@ async function v2Setup(ctx: any) {
const { options } = await loadConfig(ctx.options) const { options } = await loadConfig(ctx.options)
return await runPlugin(ctx, options) return await runPlugin(ctx, options)
} catch (err) { } 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)}`) log(`V2 setup error: ${String(err)}`)
return () => {} return () => {}
} }