Raven-1/docs/dev.md

93 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

2026-06-28 18:17:27 +08:00
# Raven Developer Guide
## Build & Run from Source
The project uses **Python + `uv`** with `hatchling` as the build backend.
feat(ppt-engine): deliver where the user named, one route onto a page, and the ten templates ## Summary This branch folds four merge requests and one unpushed commit into one, so that `main` takes one review, one approval and one merge instead of four, and so the eight-file overlap between them is resolved once. It carries, in this order: - **!602** `feat/ppt_deliver_to_named_path` -- `ppt_build` takes `deliver_to`; every publish writes the deck under `out/` and copies the same measured bytes to the path the user named, recording it with `role: "delivery"`. The PDF preview rides along only where its own `.pdf` name is free: a file already at that stem is the user's and is left alone, and the reply says the preview stayed under `out/`. - **!628** `feat/ppt_copy_route_and_page_isolation` -- `adapt` is removed, so cloning a template page and writing into it with `replace_text` is the only route; a page whose block raises loses only itself and the pages after it still build; a draft counts against the tier's build cap and one is released at it. - **!632** `feat/ship_templates_and_soffice_dep` -- the ten bundled deck templates are tracked in git with per-file sha256 pins, so a fresh clone can build a deck; the LibreOffice dependency is declared and resolved through one resolver. - **!642** `fix/ppt_copy_route_and_clone_typography` -- a copy-route lookup that finds nothing names the near miss before the inventory; a text frame with no paragraph at all can be written into; a cloned page's title size is said; `row_type_drift` compares the same structural slot across a run's units. - **D57's other-page clause, rewired.** D57 gave five refusals a "did you mean" hint, and one of them also answered "the string you named is on page N of this template". That clause needs the file a page was cloned out of, and the only refusal holding it was `adapt`'s, which !628 removed. It is restored by reading `PPT_TEMPLATE_SOURCE`, which the runner already sets in the author's own process and which this module already reads for `bundled()`; the two helpers behind the clause are unchanged. - **D60** `read the ground under each word, not across the whole box` -- the `unreadable` contrast gate also measures the render's own word boxes, as extra regions through the same guards, so a two-line block crossed by a narrow bright ridge can no longer elect the dark ground and read as legible. Decisions the union forced, none of which drops a behaviour: - The publish record is built !602's way, with its delivery `role`, and written the way D49 requires -- read back off the file, atomic, and refused rather than silent when the record cannot be written. - `clear_region`, `shapes_in`, `page_box` and the refusal of a bare four-number region survive `adapt`'s removal; so do `_heading_rows` and its helpers, which the row reading loads even though the call they were written for is gone. - The author-facing guidance names !628's single route and keeps D59's rule that a region must declare which reading it is. **The decision log carries a numbering collision, on purpose.** It is a set union with no wording changed, and the numbers are left exactly as each branch wrote them, so a reviewer meets this rather than discovers it: - !602 and !628 each wrote a **D37** and a **D38**, about different decisions. - !628's **D45** is not `main`'s D45; they are unrelated entries under one number. - !628's **D42** is `main`'s **D45** word for word, so the merged log carries one decision under two numbers. Renumbering touches every cross-reference in the log, and doing that inside a seventy-commit fold immediately before a merge is how a silent break gets in. The numbering is being fixed on a separate branch, which carries a script and a test that fails when a citation points at nothing. ## Type - [x] Feature - [x] Fix - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification Run on an interpreter carrying `python-pptx`, with `PYTHONPATH` at this worktree and its `plugins-dist/ppt-engine`, confirmed from a neutral working directory that `raven` and `raven_ppt` resolve out of the worktree and not the host repo. - `make test-python` (the whole suite, as CI runs it) -- 20826 passed, 49 skipped, and 26 failures this machine produces on any branch: it has no `/usr/share/zoneinfo`, so every cron timezone case raises `ValueError: unknown timezone 'Asia/Shanghai'`. Checked out plain `origin/main` in a clean worktree and ran the same two files: the same 6 failed and 20 errors, the ids identical character for character. Nothing on this branch touches cron or timezones. The stale `test_trunks_executor_would_have_dropped_that_output` that failed on the previous revision is retired on the new base and its replacement, `test_trunks_executor_preserves_output_on_timeout`, was run on its own and passes. The 6 failures and 20 errors are all cron timezone tests failing identically on plain `main` in a clean worktree, on a host with no `/usr/share/zoneinfo`. - `make check-commits` -- exit 0. - `make check-source-language` -- exit 0. - `make check-large-files` -- exit 0. - `make lint-imports` -- exit 0, 9 contracts kept, 0 broken. - `ruff check` and `ruff format --check` over the 80 changed Python files -- exit 0. - `pytest tests/test_ppt_engine_templates.py tests/test_utils_office.py tests/test_cli_doctor_commands.py` -- 97 passed; the ten templates are tracked and satisfy their pins, and the soffice resolver finds the local binary. - The delivery contract, the record read-back, the page isolation and the near miss were each run as a measurement rather than asserted; the `unreadable` gate was run through the real LibreOffice render chain on a delivered 12-page deck and reports BLOCKING on page 12 under one word at 1.6:1. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk User-visible changes: `ppt_build` gains `deliver_to` and delivers outside `out/`; `adapt` is gone from the author-facing template module, so a program calling it fails to import -- `title=` and `subtitle=` have no replacement and the heading is named by the words the template put there; a draft now counts against the tier's build cap; three gates that nothing measured against being wrong no longer refuse; and the ten templates are now bytes in the repository rather than a private registry fetch. Two pieces here are about not destroying something the user has. The delivery refuses to write its `.pdf` where a file the user already owns sits at the same stem, rather than replacing it; and the large-file roster moved out of the manifest inside the tree being checked and into the gate's own source, so a change can no longer grant itself the exception the gate exists to withhold. Rollback is per piece: each of the five sources is a contiguous run of commits on this branch, in the order listed above, so any one of them can be reverted as a range without touching the others. - [x] Backward compatibility considered - [x] Security impact considered - [x] Rollback path is clear for risky changes ## Related Issues N/A
2026-09-11 05:52:36 +00:00
### 0. System prerequisites
`uv` installs everything raven imports. One program it cannot: **LibreOffice**,
which converts a deck (or any Office source document) to PDF. The deck engine
renders, measures and previews through that conversion, and the gateway's PDF
viewer serves it, so without LibreOffice a deck still builds but nothing that
reads the rendered page runs, and several integration tests skip.
```bash
apt install libreoffice # Debian / Ubuntu
brew install --cask libreoffice # macOS
winget install TheDocumentFoundation.LibreOffice # Windows
```
The browser tool's chromium binary is also not a Python package: a source
checkout downloads it with
`uv sync --all-extras && uv run playwright install chromium`
(install.sh does this for tool installs).
feat(ppt-engine): deliver where the user named, one route onto a page, and the ten templates ## Summary This branch folds four merge requests and one unpushed commit into one, so that `main` takes one review, one approval and one merge instead of four, and so the eight-file overlap between them is resolved once. It carries, in this order: - **!602** `feat/ppt_deliver_to_named_path` -- `ppt_build` takes `deliver_to`; every publish writes the deck under `out/` and copies the same measured bytes to the path the user named, recording it with `role: "delivery"`. The PDF preview rides along only where its own `.pdf` name is free: a file already at that stem is the user's and is left alone, and the reply says the preview stayed under `out/`. - **!628** `feat/ppt_copy_route_and_page_isolation` -- `adapt` is removed, so cloning a template page and writing into it with `replace_text` is the only route; a page whose block raises loses only itself and the pages after it still build; a draft counts against the tier's build cap and one is released at it. - **!632** `feat/ship_templates_and_soffice_dep` -- the ten bundled deck templates are tracked in git with per-file sha256 pins, so a fresh clone can build a deck; the LibreOffice dependency is declared and resolved through one resolver. - **!642** `fix/ppt_copy_route_and_clone_typography` -- a copy-route lookup that finds nothing names the near miss before the inventory; a text frame with no paragraph at all can be written into; a cloned page's title size is said; `row_type_drift` compares the same structural slot across a run's units. - **D57's other-page clause, rewired.** D57 gave five refusals a "did you mean" hint, and one of them also answered "the string you named is on page N of this template". That clause needs the file a page was cloned out of, and the only refusal holding it was `adapt`'s, which !628 removed. It is restored by reading `PPT_TEMPLATE_SOURCE`, which the runner already sets in the author's own process and which this module already reads for `bundled()`; the two helpers behind the clause are unchanged. - **D60** `read the ground under each word, not across the whole box` -- the `unreadable` contrast gate also measures the render's own word boxes, as extra regions through the same guards, so a two-line block crossed by a narrow bright ridge can no longer elect the dark ground and read as legible. Decisions the union forced, none of which drops a behaviour: - The publish record is built !602's way, with its delivery `role`, and written the way D49 requires -- read back off the file, atomic, and refused rather than silent when the record cannot be written. - `clear_region`, `shapes_in`, `page_box` and the refusal of a bare four-number region survive `adapt`'s removal; so do `_heading_rows` and its helpers, which the row reading loads even though the call they were written for is gone. - The author-facing guidance names !628's single route and keeps D59's rule that a region must declare which reading it is. **The decision log carries a numbering collision, on purpose.** It is a set union with no wording changed, and the numbers are left exactly as each branch wrote them, so a reviewer meets this rather than discovers it: - !602 and !628 each wrote a **D37** and a **D38**, about different decisions. - !628's **D45** is not `main`'s D45; they are unrelated entries under one number. - !628's **D42** is `main`'s **D45** word for word, so the merged log carries one decision under two numbers. Renumbering touches every cross-reference in the log, and doing that inside a seventy-commit fold immediately before a merge is how a silent break gets in. The numbering is being fixed on a separate branch, which carries a script and a test that fails when a citation points at nothing. ## Type - [x] Feature - [x] Fix - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification Run on an interpreter carrying `python-pptx`, with `PYTHONPATH` at this worktree and its `plugins-dist/ppt-engine`, confirmed from a neutral working directory that `raven` and `raven_ppt` resolve out of the worktree and not the host repo. - `make test-python` (the whole suite, as CI runs it) -- 20826 passed, 49 skipped, and 26 failures this machine produces on any branch: it has no `/usr/share/zoneinfo`, so every cron timezone case raises `ValueError: unknown timezone 'Asia/Shanghai'`. Checked out plain `origin/main` in a clean worktree and ran the same two files: the same 6 failed and 20 errors, the ids identical character for character. Nothing on this branch touches cron or timezones. The stale `test_trunks_executor_would_have_dropped_that_output` that failed on the previous revision is retired on the new base and its replacement, `test_trunks_executor_preserves_output_on_timeout`, was run on its own and passes. The 6 failures and 20 errors are all cron timezone tests failing identically on plain `main` in a clean worktree, on a host with no `/usr/share/zoneinfo`. - `make check-commits` -- exit 0. - `make check-source-language` -- exit 0. - `make check-large-files` -- exit 0. - `make lint-imports` -- exit 0, 9 contracts kept, 0 broken. - `ruff check` and `ruff format --check` over the 80 changed Python files -- exit 0. - `pytest tests/test_ppt_engine_templates.py tests/test_utils_office.py tests/test_cli_doctor_commands.py` -- 97 passed; the ten templates are tracked and satisfy their pins, and the soffice resolver finds the local binary. - The delivery contract, the record read-back, the page isolation and the near miss were each run as a measurement rather than asserted; the `unreadable` gate was run through the real LibreOffice render chain on a delivered 12-page deck and reports BLOCKING on page 12 under one word at 1.6:1. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk User-visible changes: `ppt_build` gains `deliver_to` and delivers outside `out/`; `adapt` is gone from the author-facing template module, so a program calling it fails to import -- `title=` and `subtitle=` have no replacement and the heading is named by the words the template put there; a draft now counts against the tier's build cap; three gates that nothing measured against being wrong no longer refuse; and the ten templates are now bytes in the repository rather than a private registry fetch. Two pieces here are about not destroying something the user has. The delivery refuses to write its `.pdf` where a file the user already owns sits at the same stem, rather than replacing it; and the large-file roster moved out of the manifest inside the tree being checked and into the gate's own source, so a change can no longer grant itself the exception the gate exists to withhold. Rollback is per piece: each of the five sources is a contiguous run of commits on this branch, in the order listed above, so any one of them can be reverted as a range without touching the others. - [x] Backward compatibility considered - [x] Security impact considered - [x] Rollback path is clear for risky changes ## Related Issues N/A
2026-09-11 05:52:36 +00:00
`raven doctor` reports it under **External tools**.
2026-06-28 18:17:27 +08:00
### 1. Install dependencies
```bash
cd /path/to/raven
uv sync
```
This creates/updates `.venv` with all core dependencies from `uv.lock`.
For optional extras:
```bash
uv sync --extra channels # messaging integrations (Telegram, Slack, etc.)
uv sync --extra sandbox # boxlite sandbox execution
uv sync --extra tools # web/readability tools
# or all at once:
uv sync --all-extras
```
### 2. Install the package in editable mode
```bash
uv pip install -e .
```
This wires up the `raven` CLI script to your source code so changes take effect immediately.
### 3. Run the CLI
```bash
# via uv run (uses .venv automatically, no activation needed):
uv run raven --help
# or activate the venv first:
source .venv/bin/activate
raven --help
```
### 4. First-time setup
```bash
uv run raven onboard
```
Creates `~/.raven/config.json` and the workspace directory. Edit the config to add your API key (default provider: OpenRouter — get a key at https://openrouter.ai/keys).
### 5. Common commands
| Command | Description |
|---|---|
| `raven tui` | Start the interactive chat TUI |
2026-06-28 18:17:27 +08:00
| `raven agent -m "Hello"` | Send a single message and exit |
| `raven gateway` | Start full server (all channels + heartbeat + cron) |
| `raven status` | Show config path, workspace, and API key status |
| `raven channels status` | Show which messaging channels are enabled |
feat(providers): add MiniMax Global and CN OAuth (#209) ## Summary Add first-class MiniMax Token Plan OAuth support for both Global and CN regions. This change adds: - `minimax_global` and `minimax_cn` provider entries with curated MiniMax-M3 and M2.7 models. - OAuth 2.0 device authorization with PKCE S256 and strict state validation. - The shared MiniMax public client ID `coding-plan-cli` with the `openid profile coding_plan` scope. - Region-specific OAuth and Anthropic-compatible API endpoints. - Proactive access-token refresh with a five-minute buffer, cross-process locking, transient retry handling, and atomic refresh-token persistence. - Separate Global and CN credential files, isolated from existing Codex OAuth storage. - Runtime token refresh and MiniMax authentication headers for both normal and streaming requests. - CLI login commands, onboarding, provider status/test/reset support, TUI setup detection, and model-picker entries. - English and Chinese documentation updates. Public model references remain under `minimax-global/` and `minimax-cn/`. The runtime translates them to the Anthropic-compatible LiteLLM route only when sending a request, so provider selection continues to use the correct MiniMax OAuth credential. The implementation accepts MiniMax expiry values expressed as relative seconds, Unix epoch seconds, or Unix epoch milliseconds. OAuth-returned verification and resource URLs are restricted to the expected HTTPS hosts before use. ## Type - [ ] Fix - [x] Feature - [x] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification - `uv run pytest tests/test_minimax_oauth.py tests/test_cli_provider_commands.py tests/test_provider_catalog.py tests/test_config_update_providers.py tests/test_tui_rpc_model.py tests/test_tui_rpc_setup.py tests/test_cli_status_commands.py -q -x` - 143 passed. - Focused MiniMax onboarding tests - 3 passed. - `uv run ruff check raven tests` - passed. - `uv run ruff format --check raven tests` - 761 files already formatted. - `make check-large-files` - passed. - `make check-commits` - passed. - Two independent read-only reviews completed; the final review found no blocking issues. - The full test collection was not run because the local environment does not include the optional `dingtalk_stream` channel dependency. All provider, OAuth, onboarding, TUI setup, status, and configuration tests relevant to this change passed. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk - OAuth credentials are stored in region-specific files with restrictive permissions and atomic replacement. - Refresh operations use a cross-process lock and persist rotated refresh tokens before exposing them to the runtime. - OAuth verification and API resource URLs are validated against region-specific host allowlists. - Existing `minimax` API-key configuration remains unchanged; the new OAuth providers use separate slugs and storage. - Rollback consists of reverting this change. Existing API-key provider configuration and credentials are not migrated or modified. - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes ## Related Issues N/A - Live OAuth smoke test: MiniMax Global MiniMax-M3 returned "MiniMax OAuth works" successfully after normalizing the Anthropic-compatible resource URL. --------- Co-authored-by: Claude (claude-opus-5) <noreply@anthropic.com>
2026-07-28 11:14:54 +08:00
| `raven provider login <name>` | Authenticate with an OAuth provider (for example `openai-codex`, `minimax-global`, or `minimax-cn`) |
2026-06-28 18:17:27 +08:00
### 6. Run tests
```bash
uv run pytest tests/
```
feat(ppt-engine): deliver where the user named, one route onto a page, and the ten templates ## Summary This branch folds four merge requests and one unpushed commit into one, so that `main` takes one review, one approval and one merge instead of four, and so the eight-file overlap between them is resolved once. It carries, in this order: - **!602** `feat/ppt_deliver_to_named_path` -- `ppt_build` takes `deliver_to`; every publish writes the deck under `out/` and copies the same measured bytes to the path the user named, recording it with `role: "delivery"`. The PDF preview rides along only where its own `.pdf` name is free: a file already at that stem is the user's and is left alone, and the reply says the preview stayed under `out/`. - **!628** `feat/ppt_copy_route_and_page_isolation` -- `adapt` is removed, so cloning a template page and writing into it with `replace_text` is the only route; a page whose block raises loses only itself and the pages after it still build; a draft counts against the tier's build cap and one is released at it. - **!632** `feat/ship_templates_and_soffice_dep` -- the ten bundled deck templates are tracked in git with per-file sha256 pins, so a fresh clone can build a deck; the LibreOffice dependency is declared and resolved through one resolver. - **!642** `fix/ppt_copy_route_and_clone_typography` -- a copy-route lookup that finds nothing names the near miss before the inventory; a text frame with no paragraph at all can be written into; a cloned page's title size is said; `row_type_drift` compares the same structural slot across a run's units. - **D57's other-page clause, rewired.** D57 gave five refusals a "did you mean" hint, and one of them also answered "the string you named is on page N of this template". That clause needs the file a page was cloned out of, and the only refusal holding it was `adapt`'s, which !628 removed. It is restored by reading `PPT_TEMPLATE_SOURCE`, which the runner already sets in the author's own process and which this module already reads for `bundled()`; the two helpers behind the clause are unchanged. - **D60** `read the ground under each word, not across the whole box` -- the `unreadable` contrast gate also measures the render's own word boxes, as extra regions through the same guards, so a two-line block crossed by a narrow bright ridge can no longer elect the dark ground and read as legible. Decisions the union forced, none of which drops a behaviour: - The publish record is built !602's way, with its delivery `role`, and written the way D49 requires -- read back off the file, atomic, and refused rather than silent when the record cannot be written. - `clear_region`, `shapes_in`, `page_box` and the refusal of a bare four-number region survive `adapt`'s removal; so do `_heading_rows` and its helpers, which the row reading loads even though the call they were written for is gone. - The author-facing guidance names !628's single route and keeps D59's rule that a region must declare which reading it is. **The decision log carries a numbering collision, on purpose.** It is a set union with no wording changed, and the numbers are left exactly as each branch wrote them, so a reviewer meets this rather than discovers it: - !602 and !628 each wrote a **D37** and a **D38**, about different decisions. - !628's **D45** is not `main`'s D45; they are unrelated entries under one number. - !628's **D42** is `main`'s **D45** word for word, so the merged log carries one decision under two numbers. Renumbering touches every cross-reference in the log, and doing that inside a seventy-commit fold immediately before a merge is how a silent break gets in. The numbering is being fixed on a separate branch, which carries a script and a test that fails when a citation points at nothing. ## Type - [x] Feature - [x] Fix - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification Run on an interpreter carrying `python-pptx`, with `PYTHONPATH` at this worktree and its `plugins-dist/ppt-engine`, confirmed from a neutral working directory that `raven` and `raven_ppt` resolve out of the worktree and not the host repo. - `make test-python` (the whole suite, as CI runs it) -- 20826 passed, 49 skipped, and 26 failures this machine produces on any branch: it has no `/usr/share/zoneinfo`, so every cron timezone case raises `ValueError: unknown timezone 'Asia/Shanghai'`. Checked out plain `origin/main` in a clean worktree and ran the same two files: the same 6 failed and 20 errors, the ids identical character for character. Nothing on this branch touches cron or timezones. The stale `test_trunks_executor_would_have_dropped_that_output` that failed on the previous revision is retired on the new base and its replacement, `test_trunks_executor_preserves_output_on_timeout`, was run on its own and passes. The 6 failures and 20 errors are all cron timezone tests failing identically on plain `main` in a clean worktree, on a host with no `/usr/share/zoneinfo`. - `make check-commits` -- exit 0. - `make check-source-language` -- exit 0. - `make check-large-files` -- exit 0. - `make lint-imports` -- exit 0, 9 contracts kept, 0 broken. - `ruff check` and `ruff format --check` over the 80 changed Python files -- exit 0. - `pytest tests/test_ppt_engine_templates.py tests/test_utils_office.py tests/test_cli_doctor_commands.py` -- 97 passed; the ten templates are tracked and satisfy their pins, and the soffice resolver finds the local binary. - The delivery contract, the record read-back, the page isolation and the near miss were each run as a measurement rather than asserted; the `unreadable` gate was run through the real LibreOffice render chain on a delivered 12-page deck and reports BLOCKING on page 12 under one word at 1.6:1. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk User-visible changes: `ppt_build` gains `deliver_to` and delivers outside `out/`; `adapt` is gone from the author-facing template module, so a program calling it fails to import -- `title=` and `subtitle=` have no replacement and the heading is named by the words the template put there; a draft now counts against the tier's build cap; three gates that nothing measured against being wrong no longer refuse; and the ten templates are now bytes in the repository rather than a private registry fetch. Two pieces here are about not destroying something the user has. The delivery refuses to write its `.pdf` where a file the user already owns sits at the same stem, rather than replacing it; and the large-file roster moved out of the manifest inside the tree being checked and into the gate's own source, so a change can no longer grant itself the exception the gate exists to withhold. Rollback is per piece: each of the five sources is a contiguous run of commits on this branch, in the order listed above, so any one of them can be reverted as a range without touching the others. - [x] Backward compatibility considered - [x] Security impact considered - [x] Rollback path is clear for risky changes ## Related Issues N/A
2026-09-11 05:52:36 +00:00
Requires Python >= 3.12, and LibreOffice for the tests that render a deck (they skip without it).
Test configuration is in `pyproject.toml` (`asyncio_mode = "auto"`).