Commit Graph

17 Commits

Author SHA1 Message Date
Бородин Роман 930cb16495 fix: collect response text from event subscription instead of prompt return
session.prompt() non-blocking — возвращает объект-приём, а не текст.
Текст ответа приходит через ctx.event.subscribe() как live-only events.

Подход:
- pendingResponses Map: sessionID -> {resolve, reject, timer}
- Event subscription: парсит события, извлекает текст из assistant сообщений
- Message handler: создаёт Promise, ждёт события (timeout 30s)
- Парсим несколько структур событий на всякий случай
2026-09-26 01:56:43 +03:00
Бородин Роман e633558483 fix: don't pass id when creating session, let OpenCode generate ses_*
При создании сессии не передаём id — OpenCode сам генерирует ses_*.
Ключ мапы (roomId:threadRootId) используется только для поиска,
не передаётся в OpenCode.
2026-09-26 01:26:11 +03:00
Бородин Роман 5fa1fd2676 fix: proactively check session existence before use
Используем ctx.session.get({ sessionID }) для проверки существования
сессии в OpenCode ДО отправки prompt. Если сессия удалена/невалидна —
создаём новую. Убрана реактивная обработка Session.NotFoundError.
2026-09-26 01:16:19 +03:00
Бородин Роман c95ac899d2 feat: use ctx.app.log() for OpenCode logging with file fallback
Плагин теперь пытается использовать OpenCode API логирования
(ctx.app.log) для записи в ~/.local/share/opencode/log/.
При ошибке — fallback на файловый лог ~/.opencode-matrix-plugin/plugin.log.
2026-09-26 01:00:21 +03:00
Бородин Роман 1444100495 refactor: replace file logging with console.log (OpenCode V2 native)
- logger.ts теперь использует console.log/console.error с префиксом [matrix-plugin]
- Удалена запись в ~/.opencode-matrix-plugin/plugin.log
- Удалены setup-started.log и setup-error.log
- Ошибки пишутся через logError() в stderr
2026-09-26 00:47:20 +03:00
Бородин Роман bee794204b simplify logger: fixed path ~/.opencode-matrix-plugin/, no fallback
logger.ts теперь всегда пишет в ~/.opencode-matrix-plugin/plugin.log.
setLogDir() стал no-op, удалён из index.ts.
Нет больше /tmp и fallback-файлов.
2026-09-26 00:33:00 +03:00
Бородин Роман b5bc06e722 fix: call setLogDir() before loadConfig() so all logs go to storagePath
loadConfig() вызывал log() до setLogDir() — писался в /tmp.
Теперь setLogDir() вызывается в v2Setup() до loadConfig().
2026-09-26 00:30:23 +03:00
Бородин Роман e30bdd50e7 fix: move 'Plugin module loaded' log inside runPlugin
Раньше log() вызывался на уровне модуля, до setLogDir() — писался в /tmp.
Теперь лог внутри runPlugin() — после setLogDir(), только в storagePath.
2026-09-26 00:25:31 +03:00
Бородин Роман a43f4838ef fix: move plugin.log to storagePath via setLogDir()
logger.ts теперь поддерживает настраиваемый каталог логов.
runPlugin() вызывает setLogDir(dataDir) при старте.
Лог больше не пишется в /tmp.
2026-09-26 00:22:32 +03:00
Бородин Роман fff0213666 fix: keep lock file after cleanup so client always skips
Server holds the lock even after cleanup. Client always sees the lock
and skips bot startup. On crash, stale PID is detected and lock is
cleaned up automatically.
2026-09-26 00:20:51 +03:00
Бородин Роман bf61b1ef1f feat: use storagePath config for plugin data directory
All plugin files (lock, logs) now live under the configured storage
path (default ~/.local/share/opencode-matrix-bot/plugin-data),
matching matrix-client.ts behavior. No extra directories created.
2026-09-26 00:17:33 +03:00
Бородин Роман a5dda163ea fix: use fixed plugin data dir so mutex lock is shared across instances
mkdtemp creates unique dirs per process, breaking the mutex.
Use a fixed path ~/.opencode-matrix-plugin/ instead.
2026-09-26 00:13:56 +03:00
Бородин Роман e4ae5ff997 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).
2026-09-26 00:12:27 +03:00
Бородин Роман f981998ab8 fix: prevent double Matrix bot startup (server + client)
OpenCode V2 loads plugins in both the background server and the client.
Add a file-based mutex (/tmp/opencode-matrix-plugin.lock) so only the
first instance (server) starts the Matrix bot. The second instance
(client) detects the lock and returns a no-op cleanup.
2026-09-26 00:09:28 +03:00
Бородин Роман 51b98e02a5 refactor: remove V1 code, plugin is V2-only now
- Remove isV2Context() detection and all V1 branches
- Remove sdkClient parameter and V1 SDK polling logic
- Remove extractContent/formatMessage helpers (V1-only)
- Remove sentMessageIds dedup map (V1-only)
- Remove v1Server() entry point and server() export
- Remove encodeSessionId() from session-manager
- Remove crypto dependency
- Simplify help text (no mode info)
- Session ID now uses roomId:threadRootId directly
2026-09-25 23:24:12 +03:00
Бородин Роман 6199f75c4e fix: restore plugins/matrix-plugin/ path structure for OpenCode V2 plugin loading
- Add plugins/matrix-plugin/ directory with symlinks to root files
  (OpenCode V2 resolver appends path suffix after symlink resolution)
- Rename plugin id from 'opencode-matrix' to 'matrix-plugin'
2026-09-25 23:15:29 +03:00
Бородин Роман 5fdb2510b4 правильная организация директории плагина 2026-09-25 22:16:45 +03:00