Metadata-Version: 2.5
Name: check-opencode-free-models
Version: 1.0.2
Summary: Small tool that keeps OpenCode's free chat models in sync with opencode.jsonc: drift report + --apply with a timestamped backup.
Project-URL: Homepage, https://github.com/mahirfatih/check-opencode-free-models
Project-URL: Repository, https://github.com/mahirfatih/check-opencode-free-models
Project-URL: Issues, https://github.com/mahirfatih/check-opencode-free-models/issues
Author: mahirfatih
License-Expression: MIT
License-File: LICENSE
Keywords: backup,chat-models,cli,config,desktop,drift,free-models,opencode
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# Check Opencode Free Models

![Python](https://img.shields.io/badge/Python-3.10%2B-blue)
![MCP](https://img.shields.io/badge/MCP-stdio-lightgrey)
![Client](https://img.shields.io/badge/client-OpenCode-green)
[![PyPI](https://img.shields.io/pypi/v/check-opencode-free-models)](https://pypi.org/project/check-opencode-free-models/)
![License](https://img.shields.io/badge/license-MIT-blue)

🌐 **English** · [Türkçe](./README.tr.md)

**check-opencode-free-models** is a tiny tool that keeps the free **chat**
models published by the OpenCode Console in sync with
`~/.config/opencode/opencode.jsonc`.

It fetches `https://opencode.ai/inference/v1/models` (no auth), filters free
chat models, compares them against `provider.opencode-api.models`, reports drift
(`added` / `removed`), and — with `--apply` — rewrites the block in place
after taking a timestamped backup.

## Source & references

- Free models documentation: https://opencode.ai/docs/models/#free-models
- OpenCode Desktop: https://opencode.ai/desktop
- Live endpoint used by the script: `https://opencode.ai/inference/v1/models`
  (no auth; `cost.text.input.price == 0 && cost.text.output.price == 0` and
  `type == "chat"`).

## What gets pulled from where

| Source | What | Target |
|---|---|---|
| `https://opencode.ai/inference/v1/models` (no auth) | Free chat models (`type == "chat"`, `cost.text.input/output.price == 0`) — `id` + `name` | `~/.config/opencode/opencode.jsonc` → `provider.opencode-api.models` |
| Existing config | Preserves already-stored `name` values on update | merged into the rewritten block |
| `--apply` | Rewrites the block; backup `opencode.jsonc.bak-YYYY-MM-DD-HH_MM_SS` | same file |

Nothing else is read or written. The example config
`opencode-free-models.config.example.jsonc` shows the shape of the `opencode-api`
block (redacted, no secrets).

## Current free chat models

As of 2026-11-20, the Console lists 11 free chat models (run the script
to refresh):

- `beam-free` — Beam Free
- `big-pickle` — Big Pickle
- `deepseek-v4.1-flash-free` — DeepSeek V4.1 Flash Free
- `flint-40b-free` — Flint 40B Free
- `hy4-flash-free` — Hy4 flash Free
- `iceman-free` — Iceman Free
- `longcat-2.5-free` — LongCat 2.5 Free
- `mimo-v2.6-flash-free` — MiMo-V2.6-Flash Free
- `nemotron-3.5-lightning-free` — Nemotron 3.5 Lightning Free
- `nemotron-3.5-super-vl-free` — Nemotron 3.5 Super VL Free
- `tidepool-alpha-free` — Tidepool Alpha Free

## How it works

1. **Fetch** — `fetch_free_ids()` reads every model from the source endpoint.
   Filter: `cost.text.input.price == 0 && cost.text.output.price == 0` and
   `type == "chat"`.
   - Decision models (`type: decision`, e.g. Jev `jev-1.13-free`) are not chat
     (`recommended_api: systemone`), so they are never written to the
     `opencode-api` block.
2. **Drift** — `read_config_models()` reads the `id -> name` map from
   `provider.opencode-api.models`. Diff against the live free list: `added`,
   `removed`.
3. **Apply** — with `--apply`:
   - Backup `opencode.jsonc.bak-YYYY-MM-DD-HH_MM_SS` (`shutil.copy2`,
     metadata preserved).
   - `build_block()` joins lines with commas (no trailing comma).
   - `pattern.subn` rewrites the `opencode-api` models block.
   - **Validate-before-write**: the rewritten text is parsed with
     `json.loads(new_text)` *before* the file is touched; on failure the config
     is left untouched.

Idempotent: re-running `--apply` reports no drift.

## Usage

```
python3 check-opencode-free-models.py            # drift report (exit 0: in sync, 1: drift)
python3 check-opencode-free-models.py --apply    # update, with backup
```

Example output:

```
canlı ücretsiz sohbet modeli: 11
config'deki model           : 11
eklenecek : -
kaldırılacak: -
SONUÇ: güncel, fark yok.
```

## OpenCode Desktop and crontab

This tool targets **OpenCode Desktop's** own
`~/.config/opencode/opencode.jsonc` — it never touches any other config file.

Apply updates automatically with `--apply`, or run a daily drift check from
crontab:

```
0 6 * * * /path/to/check-opencode-free-models/check-opencode-free-models.py
```

Exit code `1` on drift (`SONUÇ: drift var. --apply ile güncelle.`), `0` when
in sync (`SONUÇ: güncel, fark yok.`).

## Files

| File | Description |
|---|---|
| `check-opencode-free-models.py` | Working script (live endpoint, drift, apply + backup). |
| `opencode-free-models.config.example.jsonc` | Example `opencode-api` block (redacted, no secrets). |
| `README.md` | This file (English). |
| `README.tr.md` | Turkish tour. |
| `CHANGELOG.md` | Release history. |
| `CONTRIBUTING.md` | Development setup and checks. |
| `LICENSE` | MIT. |

## Project structure

```
check-opencode-free-models/
├── check-opencode-free-models.py
├── opencode-free-models.config.example.jsonc
├── README.md
├── README.tr.md
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── .gitignore
└── docs/
    └── README.md
```

## Testing & CI

There is no automated test suite yet. Before a change:

- `python3 -m py_compile check-opencode-free-models.py` — syntax.
- `python3 check-opencode-free-models.py` — drift report (exit `0` when in sync).

## Documentation

- [`README.tr.md`](./README.tr.md) — Turkish tour.
- [`docs/README.md`](./docs/README.md) — documentation map.
- [`CHANGELOG.md`](./CHANGELOG.md) — release history.
- [`CONTRIBUTING.md`](./CONTRIBUTING.md) — development setup.

## Future ideas

1. **Atomic write** — `tempfile` + `os.replace` after validation.
2. **Robust `type` filter** — `m.get("type") or "chat"`.
3. **Decision-model WARN** — report skipped `type=decision` models.
4. **Unit tests** — make `ENDPOINT`/`CONFIG` env-overridable and mock `urllib`.
5. **`--dry-run` alias**.
6. **`recommended_api` routing** — systemone endpoint is currently 404.

## License

MIT — see [`LICENSE`](./LICENSE).
