Repository navigation
Releases
Releases · EnerJizeIT/opencode-session-manager
v1.1.0 — audit-driven rewrite
Major rewrite after a full code audit. Breaking: none — all changes are backwards-compatible additions and bug fixes.
Critical bug fixes
backupDirsetting now honoured everywhere — previously hardcoded toDEFAULT_BACKUP_DIR; users who configured a custom backup directory silently had backups written to the wrong location.sm_restore force=trueis now safe — a safety backup of the existing session is created automatically before deletion. If the subsequent import fails, the user still has a recovery file. Previously the original was deleted first and could be lost irreversibly.sm_full_backupnow finds the plugin on npm-installs — searches local-dev + three npm-cache layouts. Previously it only looked at~/.config/opencode/plugins/session-manager.ts, which does not exist for end users who installed via theplugin[]array.- Removed
truncateId()— the helper was hiding full session IDs from the agent (ses_060358f5...), making subsequent tool calls fail with "Session not found".
P0 — current session support
- New hook
tool.execute.beforecapturescurrentSessionIdin-memory on every tool call. sm_pin/sm_unpin/sm_backup:sessionIdis now optional — defaults to the current session. "Pin this session" finally works in one call.- New tool
sm_current_sessionfor introspection. sm_pinnow updates the note on an already-pinned session instead of returning "Already pinned".
P1 — quality of life
findSessionByQuery— git-like prefix matching (≥4 chars). Distinguishesfound/not_found/ambiguous/error(the previousfindSessionByIdswallowed all errors asnull).sm_list—scope: pinned | recent | all(defaultpinned).- New tool
sm_list_backups— enumerate backup files with metadata (filename, session, title, date, corrupt flag). sm_cleanup/sm_cleanup_backups—dry_run=trueby default. Destructive operations now require explicitdry_run=false.sm_search—search_in: title | title+note, capped at 50 results to avoid OOM on large session DBs.
Refactor — modular structure
session-manager.ts shrank from 1293 to 646 lines (-50%). Logic moved into focused modules:
| Module | Responsibility |
|---|---|
src/state.ts |
paths + loadStateDefault / saveStateDefault / getBackupDir / logHookEvent |
src/types.ts |
shared interfaces |
src/format.ts |
pure helpers (formatDate, findPluginSourcePath) |
src/cli.ts |
opencode CLI wrappers + findSessionByQuery + searchSessions |
src/backup.ts |
backup / cleanup / retention / restore / full-backup |
Quality
tsconfig.json:strict: true+noUncheckedIndexedAccess: true.package.json: newtypecheckscript;prepublishOnlynow runstypecheck && test && build.- GitHub Actions CI:
typecheck + test + buildon every push/PR. - Tests:
afterAllcleanup for.tmp-test-*artifacts (was leaving 5+ dirs in the working tree). install.sh:rm -rf dist/beforecp -r— fixes a bug where repeated installs created a nesteddist/dist/and left opencode loading a staleplugin.js.- Diagnostic log: hook invocations are logged to
~/.local/share/opencode/session-manager-hooks.logto verify whether opencode actually firessession.idle/session.deleted.
Stats
13 files changed, +1201 / −566 lines. 22 tests pass, typecheck clean.
Full Changelog: v1.0.7...v1.1.0
v1.0.7 — OpenCode Session Manager
Pin, back up & restore your opencode AI sessions
Never lose a valuable AI conversation again. This plugin adds 12 tools + 2 hooks to opencode for session management — all through natural language.
Features
- 📌 Pin/unpin — protect important sessions from cleanup
- 💾 Backup — individual or all pinned sessions (JSON, survives reinstalls)
- ♻️ Restore — bring a session back from backup
- 🧹 Auto-cleanup — old sessions backed up then deleted (pinned always safe)
- 🔍 Search — find sessions by title
- ⚙️ Configurable — cleanup/retention settings, set and forget
Install
// ~/.config/opencode/opencode.json
{ "plugin": ["@enerjizeit/opencode-session-manager"] }