Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,31 @@ opencode-db costs --total # total token costs
- OpenCode (must have been run at least once — the database is created automatically)
- macOS / Linux

### Database location

By default, `opencode-db` looks for OpenCode's database at:

```
~/.local/share/opencode/opencode.db
```

If your OpenCode stores the database at a custom path, you have two options:

**1. Environment variable** — set it once in your shell profile (`.zshrc`, `.bashrc`):

```bash
export OPENCODE_DB=/path/to/opencode.db
```

**2. Global `--db-path` flag** — for ad-hoc use or inspecting another database:

```bash
opencode-db --db-path /path/to/opencode.db list
opencode-db --db-path /path/to/opencode.db stats
```

The `--db-path` flag takes precedence over the environment variable.

### One-command install (recommended)

```bash
Expand Down
25 changes: 25 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ opencode-db costs --total # общие расходы
- OpenCode (должен быть хотя бы раз запущен — создаётся БД)
- macOS / Linux

### Расположение базы данных

По умолчанию `opencode-db` ищет БД OpenCode в стандартном пути:

```
~/.local/share/opencode/opencode.db
```

Если твой OpenCode хранит БД в другом месте — есть два способа указать путь:

**1. Переменная окружения** — задаётся один раз в профиле (`.zshrc`, `.bashrc`):

```bash
export OPENCODE_DB=/путь/к/opencode.db
```

**2. Глобальный флаг `--db-path`** — для разовых задач или просмотра другой БД:

```bash
opencode-db --db-path /путь/к/opencode.db list
opencode-db --db-path /путь/к/opencode.db stats
```

Флаг `--db-path` имеет приоритет над переменной окружения.

### Быстрая установка

```bash
Expand Down
10 changes: 10 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import argparse
import os
import sys
from typing import Any, Literal

Expand All @@ -28,6 +29,12 @@ def build_parser() -> argparse.ArgumentParser:
default=None,
help="Output language / язык вывода (en/ru)",
)
parser.add_argument(
"--db-path",
type=str,
default=None,
help="Path to opencode.db (default: ~/.local/share/opencode/opencode.db)",
)

subparsers = parser.add_subparsers(dest="command", required=True)
for _name, mod in commands.get_all().items():
Expand Down Expand Up @@ -58,6 +65,9 @@ def main(argv=None) -> Any | Literal[0] | Literal[1]:
if args.lang:
set_lang(args.lang)

if args.db_path:
os.environ["OPENCODE_DB"] = args.db_path

db = get_db()

try:
Expand Down
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

# --- Пути ---
# База данных opencode. Стандартное расположение для Linux/macOS.
OPENCODE_DB = os.path.expanduser("~/.local/share/opencode/opencode.db")
OPENCODE_DB = os.environ.get("OPENCODE_DB") or os.path.expanduser(
"~/.local/share/opencode/opencode.db"
)

# Директории, игнорируемые при сборе snapshot'а проекта
IGNORE_DIRS = {".git", "node_modules", ".venv", "__pycache__", ".opencode"}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "opencode-db"
version = "0.6.0"
version = "0.6.1"
description = "OpenCode database CLI manager — browse, export, analyze, clean up sessions"
readme = "README_PYPI.md"
requires-python = ">=3.12"
Expand Down