Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opencode-repath

Repair stale directory paths in the local OpenCode session database after a repository move or rename.

opencode-repath is a small Bash command with a Python standard-library SQLite helper. It reads OpenCode's database path through opencode db path; it does not need direct database configuration or third-party Python packages.

Install

git clone https://github.com/AlbertoOS/opencode-repath.git
cd opencode-repath
mkdir -p ~/.local/bin
ln -sfn "$(pwd)/bin/opencode-repath" ~/.local/bin/opencode-repath

The executable resolves its own symlink before locating its bundled helper, so this installation layout is supported. Ensure ~/.local/bin is on your PATH.

Requirements

  • Bash
  • Python 3.9 or later, with SQLite support
  • The opencode CLI on PATH and a local OpenCode database

Usage

# List active sessions whose saved directories no longer exist.
opencode-repath --broken

# Preview one active session selected by ID or exact title.
opencode-repath ses_abc123 ~/Developer/new-location
opencode-repath "Fix authentication flow" ~/Developer/new-location

# Apply the one-session change after reviewing the preview.
opencode-repath ses_abc123 ~/Developer/new-location --apply

# Preview all active sessions at or below an old directory prefix.
opencode-repath ~/Developer/old-project ~/Developer/new-project

# Apply the explicitly named bulk mode.
opencode-repath --prefix ~/Developer/old-project ~/Developer/new-project --apply

Safety model

  • Every mutation is a dry run unless --apply is supplied.
  • A non-path selector first matches an exact active session ID. If no ID matches, it matches an exact active title.
  • Duplicate titles are rejected and their candidate IDs are printed; use the ID to continue.
  • A path-prefix operation affects every active session at the exact old path or beneath it. Archived sessions are never changed.
  • The helper uses parameterized SQLite statements, escapes LIKE metacharacters, and performs writes in an immediate transaction. If the preview count and update count differ, it rolls the transaction back.
  • New paths must be absolute (or start with ~). The command does not create directories or require the replacement directory to exist, which supports repathing data before the working tree is restored.

Test

make test
make check

The offline fixture creates a temporary SQLite database and a fake opencode command. It covers targeted ID/title selection, title ambiguity, dry-run behavior, path validation, ID/title collision precedence, bulk-prefix boundaries, and archived-session preservation.

License

MIT. See LICENSE.

About

A companion utility for people who move source code and folders around a lot. :) Safely repair stale OpenCode session paths after repository moves.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages