Skip to content

krumpstead/opencode-dosm

Repository files navigation

DOSM - Dirty Ol' Session Manager

npm version License: MIT OpenCode Plugin

OpenCode TUI plugin for browsing, filtering, sorting, and managing sessions across all projects from a unified interactive interface.

DOSM Terminal UI

Why?

  • The bloating of the opencode.db can get out of control. The nuclear option of deleting all the opencode.db files works but then you have no way of selectively going through each session and seeing who the worst offenders are.
  • You also may have had expensive sessions that you wanted to keep or archive so deleting the entire database isn't an option.
  • I was also sick of trying to remember which directories had OpenCode sessions associated with them.
  • I wanted to see the stats of each individual session across all projects and sort/filter them so I could decide what to keep and what to get rid of.
  • Even if you delete the sessions in the built-in session manager the database will never get smaller, because they don't auto-vacuum. it. So there is no point in deleting them.

WARNING

This plugin directly accesses the opencode.db. It queries for stats and calls VACUUM. Standard API calls are used for deletes. Make a backup of all three opencode.db files (opencode.db, opencode.db-shm, opencode.db-wal) before trying this plugin for the first time and getting used to how it works. The DB files are found in $HOME/.local/share/opencode.

YOU HAVE BEEN WARNED

Features

  • Browse ALL sessions
    • View sessions from every project, not just the current working directory
    • Shows token usage, costs, and model
    • Title shows total number of sessions, total input and output tokens used and total cost across all sessions
  • Filter & search
    • Quickly find sessions by typing to filter the list
  • Single session details
    • Now you can see the info for each session in one place
    • The list is sortable by each field, ascending/descending
    • Date - by modification date
    • Path - path of the working directory
    • Tokens - input and output tokens used
    • Cost - token cost of the session
    • Model - provider and model used
  • Read-only mode
    • Defaults to read-only so you can browse without accidental deletions
    • Toggle to write mode so you can delete individual sessions or all sessions at once
  • Delete sessions
    • Single or batch delete with confirmation (active sessions protected)
    • Delete all will be added as the topmost action in the list after toggling to write mode
    • To prevent accidentally removing the session you are working on, if a session is active, it will not appear in the list of sessions. Running the plugin from the home screen will display all sessions.
    • Runs VACUUM on the opencode.db so it shrinks the size of the database on the next client startup
  • 27 languages
    • Full internationalization with auto-detection
    • Persists between client sessions
  • Keyboard shortcuts
    • Full keyboard navigation and command palette integration
  • 100% coverage through Jest
    • There is no test framework for the OpenCode plugin API, so I wrote my own. Why not? I have unlimited free local open source tokens. Maybe more useful to some people than the actual plugin

Limitations

  • The DialogSelect provided through the TUI plugin API is strictly locked down.
  • You can't set the input value.
  • You can't add actions.
  • You can't alter the footer content.
  • You can't change the filtering function.
  • Similarly you can't change the default for the DialogConfirm to cancel. So be careful with those fast taps on deletes.
  • Because of this I couldn't implement what I wanted most which was a filtered delete, where you could search and delete everything currently in the list. The reason I can't implement this is because the default filtering function does a fuzzy match. If you type in exact keywords it may still match other things you don't want. The onFilter which is exposed does not pass into the internal filter store of the DialogSelect. I tried every hack I could think of and could not see any way around this horrible limitation.
  • For the same reason there was no way to prevent the actions in the list from being filtered out by the fuzzy match.
  • And to really beat this topic all the way to death, this also means you can only filter on the title. I really wanted to filter by date, path and all the stats so I could delete based on that.
  • The opencode.db is a SQLite DB that uses WAL (Write Ahead Logging) for its journaling. I did not want to mess with its lifecycle in case there are other transactions midflight. So to actually get the DB to shrink you have to close and reopen OpenCode. This will cause the WAL to commit and you should see the opencode.db get smaller after deleting.

Installation

From NPM (recommended)

Add to your OpenCode TUI plugin config (~/.config/opencode/tui.json):

{
  "plugin": ["opencode-dosm"]
}

Development (from source)

git clone https://github.com/krumpstead/opencode-dosm.git
cd opencode-dosm
npm install

Add to ~/.config/opencode/tui.json:

{
  "plugin": [
    "file:///<YOUR_PROJECT_DIR_HERE>/src/tui.ts"
  ]
}

Usage

Open the command palette and search for dosm or use the keybinding:

Action Keybinding
Slash command /dosm

Session List

The session picker shows:

  • Session title and directory path
  • Last updated time
  • Input/output token counts
  • Token cost
  • Model and Provider

Controls

Option Description
Toggle mode Switch between read-only and write mode
Language Change display language
Sort options Sort by date, path, tokens, cost, or model
Select Opens session in read mode, and deletes with confirmation on write
Delete all Batch delete all non-active sessions after confirming
Separator Return to session list

Requirements

  • OpenCode >= 1.18.2

NPM Dev Scripts

npm test              # Run all tests
npm run test:coverage # Run tests with coverage report
npm run lint          # Run ESLint
npm run build         # Builds to dist/index.js using esbuild
npm run clean         # Remove the dist directory and tarball
npm run deploy        # Deploy the NPM tarball to the locally installed OpenCode. This will overwrite the package from the registry.
npm run clean_deploy  # Remove the NPM package from the OpenCode install. This will remove the actual package from the registry OpenCode installed if it's there.

License

MIT

About

OpenCode TUI plugin for browsing, filtering, sorting, and managing sessions across all projects from a unified interactive interface.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages