## Summary Two things arrive together because the second is what made the first usable. **Run raven from a container.** A Dockerfile builds the page, the Python environment and the engine into one image; `cd docker && docker compose up` serves it. nginx serves the built page and proxies the RPC socket to the engine over the loopback they share -- the engine binds 127.0.0.1 only, so a proxy in a second container would have no address to dial. Compose publishes on 127.0.0.1, and the entrypoint prints a one-time sign-in link on boot. **A first run is no longer a dead end.** The gateway used to refuse to start until a provider was configured, while being the thing that serves the page where a provider gets configured. It now starts, says what is missing, and picks up a key saved in Settings on the next turn without a restart. The onboarding overlay no longer takes the page either: New chat, the model chip and Send send the reader to Settings > Models instead, and an empty model list is marked on the control that fills it. Also carried: the provider catalogue registry (capabilities, modalities and context windows per model), the reworked Settings > Models pane, and four fixes found in review of that work -- a sibling catalogue answering 200 with a non-catalogue body no longer crashes the whole fetch; adding a tag no longer erases the label and description already stored for that model; `authenticated` no longer demands a bearer token from a local provider reached by address; and registry rows are keyed by the spelling every lookup produces, which recovers 593 rows that no reader could reach. ## Type - [ ] Fix - [x] Feature - [x] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification Commands run on the branch head, with their results: - `uv run pytest tests -q -k "provider or registry or catalog or model or rpc or gateway or docker or i18n"` -- 4389 passed, 46 skipped - `npx vitest run` in `ui-web` -- 1573 passed (101 files) - `npx vitest run` in `ui-tui` -- 2037 passed (142 files) - `uv run ruff check raven scripts tests` and `ruff format --check` -- clean - `npx tsc --noEmit` in `ui-web` and `npm run type-check` in `ui-tui` -- clean - `npm run lint:rpc` in `ui-tui` -- generated.ts in sync - `make check-source-language`, `make check-large-files` -- clean Each of the four review fixes was checked by reverting it and watching a named test go red, then restoring it. The container image itself has not been built by CI or by me -- no Docker daemon was available on the machine this was written on. It has been built and run by the author of the branch. - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk Two deliberate security trade-offs in the container deployment, both documented in `docker/README.md`: - nginx rewrites the `Origin` header, because the engine accepts only an Origin naming its own loopback port and no browser reaching a published port can send one. This drops a defence-in-depth layer. The session cookie is SameSite=Strict, so an unauthenticated socket is still refused -- but SameSite ignores ports, so another page on localhost counts as same-site. - `RAVEN_AUTO_LOGIN=1` is the default: nginx attaches the session cookie to every page load, so anyone who can reach the published port is signed in. It is contained by Compose publishing on 127.0.0.1 only. Set it to 0 for any deployment reachable from elsewhere. These are two settings that must agree, and nothing warns when they do not. Behaviour changes outside the container: the gateway now starts without a configured provider rather than exiting 1, and the first-run onboarding overlay no longer opens by default (`?onboard=1` still forces it). Rollback is by revert; nothing here migrates state or changes an on-disk format. - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes ## Related Issues N/A
140 lines
4.9 KiB
Python
140 lines
4.9 KiB
Python
"""Factories for the tool face code-flow contributes (raven-plugin.toml names them).
|
|
|
|
Every factory reads the flow slice's ``tools`` section and declines (returns
|
|
None) when that section leaves the face off or the slice does not parse, so a
|
|
product that wants the host's own tools simply says so and gets them.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
from loguru import logger
|
|
from pydantic import ValidationError
|
|
|
|
from code_flow.config import FlowConfig, ToolsConfig
|
|
from code_flow.tools.exec import SPILL_SUBDIR, CodeExecTool, CodeExecutor
|
|
from code_flow.tools.filesystem import EditFileTool, ListDirTool, ReadFileTool, WriteFileTool
|
|
from code_flow.tools.read_state import owner_for
|
|
from code_flow.tools.search import GlobTool
|
|
from code_flow.tools.todo import STORES, TodoTool
|
|
|
|
if TYPE_CHECKING:
|
|
from raven.plugins.context import PluginContext
|
|
|
|
|
|
def _face(ctx: "PluginContext", seat: str) -> ToolsConfig | None:
|
|
"""The tool face's own section of the flow slice, or None to decline."""
|
|
try:
|
|
flow = FlowConfig.from_slice(dict(ctx.config or {}))
|
|
except ValidationError as exc:
|
|
logger.warning("code-flow: config slice is malformed; declining {}: {}", seat, exc)
|
|
return None
|
|
if not flow.tools.enabled:
|
|
return None
|
|
return flow.tools
|
|
|
|
|
|
def _fence(ctx: "PluginContext", cfg: ToolsConfig) -> tuple[Path, ...]:
|
|
"""The roots these tools may reach, mirroring what the host grants its own.
|
|
|
|
The host computes ``allowed_dirs = (workspace,) if restrict_to_workspace``
|
|
(raven/agent/loop/wiring.py) and an empty tuple means the fence is OFF --
|
|
which is what these replacements used to pass, whatever the product asked
|
|
for. The section carries the answer because a plugin factory cannot read
|
|
the host field; the launcher renders it in.
|
|
"""
|
|
return (Path(ctx.services.workspace),) if cfg.restrict_to_workspace else ()
|
|
|
|
|
|
def make_read_file(ctx: "PluginContext") -> ReadFileTool | None:
|
|
cfg = _face(ctx, "read_file")
|
|
if not cfg:
|
|
return None
|
|
return ReadFileTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg), read_owner=owner_for(ctx))
|
|
|
|
|
|
def make_write_file(ctx: "PluginContext") -> WriteFileTool | None:
|
|
cfg = _face(ctx, "write_file")
|
|
if not cfg:
|
|
return None
|
|
return WriteFileTool(
|
|
workspace=ctx.services.workspace,
|
|
allowed_dirs=_fence(ctx, cfg),
|
|
syntax_note=cfg.python_syntax_note,
|
|
read_owner=owner_for(ctx),
|
|
)
|
|
|
|
|
|
def make_edit_file(ctx: "PluginContext") -> EditFileTool | None:
|
|
cfg = _face(ctx, "edit_file")
|
|
if not cfg:
|
|
return None
|
|
return EditFileTool(
|
|
workspace=ctx.services.workspace,
|
|
allowed_dirs=_fence(ctx, cfg),
|
|
syntax_note=cfg.python_syntax_note,
|
|
read_owner=owner_for(ctx),
|
|
require_read=cfg.require_read_before_edit,
|
|
)
|
|
|
|
|
|
def make_list_dir(ctx: "PluginContext") -> ListDirTool | None:
|
|
cfg = _face(ctx, "list_dir")
|
|
if not cfg:
|
|
return None
|
|
return ListDirTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg))
|
|
|
|
|
|
def make_glob(ctx: "PluginContext") -> GlobTool | None:
|
|
cfg = _face(ctx, "glob")
|
|
if not cfg:
|
|
return None
|
|
return GlobTool(workspace=ctx.services.workspace, allowed_dirs=_fence(ctx, cfg))
|
|
|
|
|
|
def make_exec(ctx: "PluginContext") -> CodeExecTool | None:
|
|
"""The shell, with the clamped ceiling, the partial-output marker and the
|
|
30,000-character budget with spill. Served only where the host's own exec
|
|
would run on the host too (``tools.sandbox.backend == "none"``): the
|
|
replacement runs on the host, and a configured sandbox must not be
|
|
bypassed by a same-name tool -- so under any other backend this declines
|
|
and the host's exec keeps the shell."""
|
|
cfg = _face(ctx, "exec")
|
|
if not cfg:
|
|
return None
|
|
if cfg.exec.sandbox_backend != "none":
|
|
logger.info(
|
|
"code-flow: tools.sandbox.backend is {!r}; the host's exec keeps the shell", cfg.exec.sandbox_backend
|
|
)
|
|
return None
|
|
home = Path(ctx.services.workspace)
|
|
executor = CodeExecutor(max_timeout=cfg.exec.max_timeout, spill_dir=home / SPILL_SUBDIR)
|
|
return CodeExecTool(
|
|
timeout=cfg.exec.timeout,
|
|
working_dir=str(home),
|
|
restrict_to_workspace=cfg.restrict_to_workspace,
|
|
path_append=cfg.exec.path_append,
|
|
executor=executor,
|
|
extra_allowed_dirs=(home,),
|
|
max_timeout=cfg.exec.max_timeout,
|
|
)
|
|
|
|
|
|
def make_todo(ctx: "PluginContext") -> TodoTool | None:
|
|
"""The checklist, on the store the flow hook binds per session: one store
|
|
per Agent home, so the hook factory and this one meet on the same object."""
|
|
return TodoTool(STORES.for_home(ctx.services.workspace)) if _face(ctx, "todo") else None
|
|
|
|
|
|
__all__ = [
|
|
"make_edit_file",
|
|
"make_exec",
|
|
"make_glob",
|
|
"make_list_dir",
|
|
"make_read_file",
|
|
"make_todo",
|
|
"make_write_file",
|
|
]
|