18 Commits

Author SHA1 Message Date
Tong Li
0a1a711123
feat(*): add bounded Python diagnostics after code edits (#967)
## Summary

Raven-Code reports Python syntax errors after file edits but misses
unresolved names and equivalent feedback after shell edits. Add advisory
Pyflakes F821/F822/F823 checks to the existing tool result; optional
F401 notices remain off by default. No additional model call or code
execution is involved.

```text
write_file / edit_file
  -> inspect final source, compare with a baseline that can be read and analyzed
  -> retain syntax warnings; suppress existing name findings
exec
  -> require checkpoint visibility for the working directory
  -> read the changed files from the host's write record for the command
  -> ask visibility in batches of 256, select at most 8, check up to 4 concurrently
  -> append ordered diagnostics, preserving exit status and file metadata
```

Existing syntax failures remain visible after unrelated edits and
identical rewrites. A baseline that cannot be read, parsed or analyzed
is marked unknown; overwriting non-UTF-8 source still checks the known
replacement. Source nested too deeply for the parser or checker, and a
changed file that cannot be read, report diagnostics unavailable for
that file rather than passing as clean. Every check reads a file as the
bytes Python runs: text a write or edit stores is checked as its UTF-8
bytes, the content it replaced included, and a file from disk as its
bytes, each decoded as Python decodes source, by its coding declaration
or as UTF-8. Bytes that do not decode are reported as a syntax error at
the line where decoding stops, so a declaration the written text cannot
satisfy is reported however the file was changed. Noqa comments are read
as Ruff reads them, including after other comment directives and never
inside string literals: a file-level `ruff: noqa` / `flake8: noqa`
counts only on a line of its own, and a marker counts only when codes
follow its colon or, with no colon, whitespace, another comment or the
end of the comment follows it. Unlike Ruff, which takes the first
directive in a comment, every directive in it counts. The seeded tool
guide gives the syntax note's own advice. With no checkpoint or no
visibility verdict, exec diagnostics do not inspect changed file
contents; direct file checks remain available.

Pyflakes is imported when the tool face loads, not by whichever check
first needs it: imported lazily, its cold import fell inside that
check's one-second wait, and on a slow Windows runner the one test that
paid it reported diagnostics unavailable for a plain syntax error.
Private workers bound reads and checks to four active jobs per process.
Saturated capacity rejects new work without queuing, and
timeout/cancellation retains each slot until the actual work finishes.
Name checks are capped at 256 KiB of source and the syntax check at 2
MiB, and a check skipped for size says so in one line. Findings are
capped at eight per file, and exec diagnostic text at 6,000 characters
plus omission notices.

Runtime changes stay inside the Raven-Code code-flow plugin, except for
one fix to `CheckpointService.trackable`, the visibility verdict that
exec diagnostics and the host's exec write record both rely on. On
macOS, git precomposes a file name it reads off the disk before matching
an ignore rule, but takes the paths `trackable` sends to `git
check-ignore --stdin` as written. A file stored with a decomposed (NFD)
name under a `.gitignore` rule written precomposed (NFC) is therefore
left out of the checkpoint, yet main vouches for it, so the write
record's diff carries its text, and exec diagnostics would quote its
source lines to the model. Nor is git's precomposition NFC: it composes
only neighbouring characters, by Unicode 3.2's table, and reorders
nothing, so a name whose combining marks are out of canonical order
comes out as neither the name as given nor its NFC. `trackable` now asks
about each name as given, as NFC and in git's macOS spelling, and
withholds it when any spelling is ignored. Other shared
file/shell/snapshot implementations are unchanged.

Raven-Code has no separate dependency manifest, so Pyflakes uses the
existing root dependencies. It is the only added package; uv normalized
existing lockfile markers without changing other package versions.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- **Before:** on main, Raven-Code's file tools report Python syntax
errors only, and its exec reports nothing about the Python files a
command changed. On macOS, main's `CheckpointService.trackable` vouches
for a file stored as `secret_cafe` + U+0301 + `.py` under the rule
`secret_caf` + U+00E9 + `.py`: the user's own git ignores it and the
checkpoint's staged tree leaves it out, yet its text reaches the exec
write record's stored diff.
- **After:** on macOS 26.6.2 / arm64 with Apple Git 2.54.0, the command
below passes 364 tests on Python 3.12.13 and on 3.14.6. The full default
suite on 3.12.13 has 32283 passed, 169 skipped, 20 failed and 3 errors
over 22 test ids: 21 of them also fail on the exact base in the same
environment, and the other, a remote process-tree cancel test that
missed its deadline under the suite's load, passes when run alone. Tests
cover actual worker overlap, retained capacity after
timeout/cancellation, host-tool isolation, hidden-file quotas,
visibility batching through the host's write-record wiring, baseline
handling, parser-limit failures, the size bounds and their skip notes,
undecodable bytes placed where decoding stops, coding declarations in
written and edited text, the baseline read staying on a worker, the
checker loaded with its module, the file each unavailable note names,
comment directives and their marker boundary, the tool guide's agreement
with the syntax note, portable commands in paths with spaces/non-ASCII
characters, and the checkpoint's verdict on decomposed names and on
names git spells as neither given nor NFC, held against its own staged
tree. Removing any of the three spellings from the query fails the cases
that pin it, as does removing the marker boundary, the parser-limit
report, the unknown-baseline handling, the syntax check past the
name-check bound and the decoding report, checking written text as its
stored bytes, the worker around the baseline read, loading the checker
with its module, or the file name in an unavailable note; restoring the
guide's earlier advice fails its agreement test. git's macOS spelling is
what libiconv's UTF-8-MAC conversion returns, which git precomposes
with: composing neighbours by Unicode 3.2's table reproduced it for all
281,928 names built from every decomposable character's decomposition
(reordered, partly composed, or with a mark added), and across 784,220
further mixed names and pairs no name was spelled outside the three
asked; the same held under Python 3.13 and 3.14. The decomposed-name
check asserts the macOS outcome only where git precomposes names, so it
also passes with `core.precomposeunicode = false` set through
`GIT_CONFIG_GLOBAL`. Across 102 noqa comment variants the reported lines
match Ruff 0.15.12, except the three that hold several directives in one
comment. Through the real `AgentLoop`, code-flow tool face,
`CodeExecutor` and checkpoint, with the working directory under `/tmp`,
under `$TMPDIR` and in a path with spaces and CJK characters, exec
diagnostics report created, modified and decomposed-name files, follow
`working_dir`, report an undecodable file at the line where decoding
stops, a syntax error past 256 KiB and a skip past 2 MiB, and withhold
`.gitignore`d files, including decomposed names and names git spells as
neither given nor NFC; across repeated runs on both interpreters, a file
near the 256 KiB cap is checked in 52-135 ms (117-128 ms against a
baseline), the syntax of a file near 2 MiB in 318-371 ms, and 600
ignored files plus one visible file take 73-90 ms with the event loop
held at most 20 ms. At this head CI passes the unit suite on
Linux/Python 3.12 (32619 tests over four shards), and its two Windows
steps pass the diagnostic files on native Windows/Python 3.13: 122
file/worker tests, and 27 exec diagnostic tests with 17 pre-existing
executor tests deselected; the symlink fixture skips only where the host
cannot create links.

```sh
env -u SERPER_API_KEY -u RAVEN_MIRRORED_SERPER_API_KEY uv run --no-sync pytest tests/test_agents_code_diagnostic_workers.py tests/test_agents_code_tools_plugin.py tests/test_agents_code_flow_exec.py tests/test_agents_code_flow_plugin.py tests/test_agents_code_flow_read_state.py tests/test_agents_code_launcher.py tests/test_workdir_snapshot.py tests/test_shell_command_writes.py tests/test_runtime_checkpoint.py tests/test_trajectory_upload.py::test_blocked_upload_hits_the_deadline -o addopts= -q --tb=short --maxfail=3
uv run --no-sync ruff check raven/agent/loop/checkpoint.py agents/raven-code/plugins/code-flow/code_flow/tools agents/raven-code/plugins/code-flow/code_flow/config.py tests/test_runtime_checkpoint.py tests/test_agents_code_flow_exec.py tests/test_agents_code_tools_plugin.py tests/test_agents_code_diagnostic_workers.py
uv run --no-sync ty check raven/agent/loop/checkpoint.py agents/raven-code/plugins/code-flow/code_flow/tools agents/raven-code/plugins/code-flow/code_flow/config.py
uv run --no-sync lint-imports
uv run --no-sync ruff format --check raven/agent/loop/checkpoint.py agents/raven-code/plugins/code-flow/code_flow/tools agents/raven-code/plugins/code-flow/code_flow/config.py tests/test_runtime_checkpoint.py tests/test_agents_code_flow_exec.py tests/test_agents_code_tools_plugin.py
```

Native Windows CI commands:

```sh
uv run --frozen --python 3.13 --no-sync pytest tests/test_agents_code_diagnostic_workers.py tests/test_agents_code_tools_plugin.py -q -n 0 --tb=short
uv run --frozen --python 3.13 --no-sync pytest tests/test_agents_code_flow_exec.py -k test_exec_ -q -n 0 --tb=short
```

Ruff, format and type checks passed; all 10 import contracts kept; the
commit-message, large-file and source-language checks pass over the
branch. The launcher tests unset inherited search API keys to keep the
expected tool list deterministic.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

Scope: Raven-Code's enabled code-flow tool face; installing Pyflakes
does not activate checks in other agents. The change is reversible and
never fixes/removes code or rolls back edits. Static diagnostics can
need judgment for dynamic names, target Python versions, and project
lint configuration; only explicit noqa directives are honored. Passing
diagnostics do not replace tests.

The `trackable` fix reaches every exec write record, not only
Raven-Code: a file whose name, as given, as NFC or in git's macOS
spelling, matches an ignore rule keeps its counts and loses its diff and
removal body. Where git matches another of those spellings, as off macOS
for a decomposed name under a precomposed rule, the checkpoint stores
the file but it is still withheld; its counts remain.

Exec diagnostics now require an active checkpoint. Noninteractive runs
using the default interactive checkpoint policy must explicitly enable
checkpoints to receive this feedback. Visibility is checked in batches
of up to 256 files and stops once eight visible files are found; each
batch holds the event loop while the host resolves its paths, about 130
ms for a full batch on native Windows. Each file-check wait is one
second, and post-command diagnostics have a three-second wait budget;
past it, or when they fail as a whole, they are dropped and the
command's result is kept. These are caller budgets, not hard I/O
deadlines: running OS reads and inherited synchronous host callbacks
cannot be forcibly interrupted. Private worker capacity remains bounded.
Between 256 KiB and 2 MiB only syntax is checked: near 2 MiB that took
0.3-0.4 s and about 190 MiB here, up to four checks run at once, and on
slower hardware such a check can outlast the one-second wait and report
diagnostics unavailable. Python's GIL means concurrency does not promise
a CPU speedup.

Windows CI exercises the diagnostics layer with the real native
DirectExecutor. The existing CodeExecutor environment probe uses POSIX
quoting and already fails on Windows at the base; this PR neither
changes that probe nor claims end-to-end compatibility for it. Symlink
setup is skipped only if the host cannot create the fixture.

Disable `pythonLint` for syntax-only feedback, `execPythonDiagnostics`
for no post-command checks, or `pythonSyntaxNote` for no diagnostics,
under `plugins.config["code-flow"].tools`. The PR can also be reverted
as a unit.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Dizhan Xue <xuedizhan17@mails.ucas.ac.cn>
Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
2026-10-18 20:21:04 +08:00
Handsome-wzw
b2ae7f759b
fix(*): show the head of a line longer than a read_file page instead of an empty page (#959)
## Summary

A page of `read_file` is cut to whole lines within its 128k-character
budget. A file whose first line is over the budget by itself (a minified
script, a one-line JSON, a long CSV row) left nothing within it: the
page came back empty, and its footer said to continue at the very line
it had just not shown, so the reader went round for ever. Measured
before the change: `(Showing lines 1-0 of 1. Use offset=1 to continue.)`
for a single 200k-character line, and `(Showing lines 2-1 of 3. Use
offset=2 to continue.)` once a shorter first line had filled page one.

Such a line is now shown by its head, as much as the budget holds,
followed by a note that says how long the line is, how much of it is
shown, and that `offset` moves by lines and cannot reach the rest:
`grep` tells whether a piece is in it, and a shell command that cuts by
bytes (such as `cut -c`) shows another stretch. The paging footer then
points at the next line, so paging moves on. A first line that just fits
(the line break the budget counts put it over) is shown whole, without a
note. Pages that fit are unchanged.

The node runs the same tool for a file on a registered machine, so the
remote read reads the same; one of the new tests goes through the real
node behind the stand-in ssh.

Raven-Code's `read_file` (the code-flow plugin) cuts every line to 2000
characters. It had its own way round the empty page: whenever trunk
answered with no numbered line it re-read the whole file itself, and
otherwise it cut the lines after trunk had counted the page, so a dozen
10k-character lines filled a page. Trunk's read now offers a hook,
`_cut_line`, applied to each line before the page's budget counts it
(trunk's own is a no-op); the plugin cuts on it, so minified lines share
a page, each cut once, and its whole-file re-read is removed. Its cut
after the read now runs only for a page a registered machine's node
answered (the node runs trunk's tool, without the plugin's hook); a page
read here was cut on the hook and is not looked at again. The first head
told a cut line apart by its ending, so a line whose own text ends like
the mark came back whole (both reviewers reproduced it); whether a line
was cut is now decided by where the read ran, never by its text.

Changed: `raven/agent/tools/filesystem.py` (the trim loop and the hook
in `ReadFileTool`),
`agents/raven-code/plugins/code-flow/code_flow/tools/filesystem.py` (the
plugin's read), tests in `tests/test_filesystem_tools.py`,
`tests/test_remote_file_tools.py` and
`tests/test_agents_code_tools_plugin.py`.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- The six new tests fail on `origin/main` (the four about the page with
the empty pages quoted above; the two about the hook with a dozen lines
per page) and pass after the change: `pytest
tests/test_filesystem_tools.py tests/test_remote_file_tools.py
tests/test_agents_code_tools_plugin.py -k "longer_than_a_page or
just_fills_the_page or going_round or cut_per_line or minified_lines"`.
- Second commit:
`test_a_line_whose_own_text_ends_like_the_mark_is_cut_like_any_other`
fails on the first head (the line comes back whole) and passes now;
`test_a_page_a_registered_machine_s_node_answered_is_cut_after_the_read`
pins the pass after the read for a page a node answered, through a
stand-in pool.
- `pytest tests/test_agents_code_tools_plugin.py
tests/test_filesystem_tools.py tests/test_remote_file_tools.py
tests/test_node_server.py tests/test_read_file_image.py
tests/test_tools_workdir.py tests/test_tool_registry_execute.py -n 4`:
356 passed.
- `scripts/coverage_gate.py diff --base-ref origin/main`: 100% of the 11
changed executable lines.
- `ruff check`, `ruff format --check`, `ty check` on both changed
modules: clean.
- `scripts/check_commit_messages.py`,
`scripts/check_source_language.py`, `scripts/check_large_files.py` over
`origin/main..HEAD`: clean.
- Full suite (`pytest -n 6`), run again at the second commit: 31623
passed, 233 skipped; the 3 failures are the ones main has on this
machine (a LibreOffice-less host, two simulation cases), unrelated to
this change.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed (checked
CONTEXT.md, docs-site and the plugin's own text: nothing describes the
page footer or the plugin's cut; both tools' descriptions still hold)

## Risk

- [x] Security impact considered: nothing new is read, and the note
names no path.
- [x] Backward compatibility considered: a page that fits is unchanged,
and the existing paging tests still hold; the hook is a no-op unless a
subclass overrides it. In Raven-Code the page of a file with minified
lines holds more lines than before (the cut lands before the budget) and
the one mark reads as it did.
- [x] Rollback path is clear for risky changes: revert the one commit.

## Related Issues

N/A

---------

Co-authored-by: Claude (claude-fable-5-1) <noreply@anthropic.com>
2026-10-15 21:05:17 +08:00
Zuyi Zhou
a40e911ddb
fix(agent): bound every tree walk and take it off the event loop (#566)
## Summary

On 2026-09-20 one `find` call froze the whole gateway for 2h21m. The
model asked for `find(pattern="**/gps_trilateration/index.html",
path="/Users/admin")`, and `FindTool` ran `Path.glob` synchronously on
the event loop, filtered the noise directories only after walking them,
and had no deadline. The registry's 300s ceiling is an
`asyncio.wait_for`, which cannot preempt synchronous code, so every
session and every subagent on the gateway stopped until the walk came
back (`gateway.log`: `Tool result: find duration=8476519ms`). `list_dir`
with `recursive=true` had the same shape through `rglob`.

The fix gives the three tree-walking tools one walk,
`raven.agent.tools.tree_walk`, with these bounds:

- noise directories (`node_modules`, `.git`, ...) are pruned before they
are entered, not filtered afterwards -- the pruning tests spy on
`os.scandir` and assert the noise directory is never opened;
- the walk yields one entry at a time and checks a 20s wall-clock budget
(the value grep's fallback already used) before every entry, so whatever
the caller does with one entry -- the `stat` per `find` match, the read
per grep file -- is covered by the check on the next. The budget cannot
be overrun by one large or slow directory: the probe with eight matches,
a 30ms stat each and a 50ms budget returns 2 matches and the notice.
When the budget is hit, `find` and `list_dir` append a `PARTIAL result:
... traversal budget ...` clause to their trailer, and a deadline that
fires before any match is not reported as a clean `No files found` /
`Directory is empty`;
- every caller runs the walk in `asyncio.to_thread`, so the loop keeps
serving other sessions while the walk runs. Cancelling the thread does
not stop the worker, which is why the deadline lives inside the walk.
The pure-Python `grep` fallback already had the prune and the deadline;
it moves onto the shared walk and off the loop with the others.

`find` matches each path component with `fnmatch.translate`, with a
component that is exactly `**` spanning any number of components; the
matcher is a position-set simulation (`_advance`), linear in components
times segments, so a pattern carrying many `**` cannot make one match
call slow. A pattern's leading literal components decide where the walk
starts: `src/**/*.py` begins inside `src` and never lists a sibling of
it, a pattern that is all literal (`src/lib/c.py`, `src/lib`) names
exactly one path and answers without a walk, and the prefix itself is a
match when the rest of the pattern can match nothing (`src/**` still
lists `src/`). It answers exactly what `Path.glob` answered for the same
pattern: pinned by a parametrized oracle test over twenty-seven patterns
on a fixture and nineteen on a fixture with links (a directory link out
of the tree, a link cycle, a file link, a noise directory beneath a
link), and checked by hand against `Path.glob` over `raven/` for 27
patterns including bracket edge cases and trailing slashes, 0
mismatches. Two deliberate differences: a trailing `**` also lists files
beneath its prefix (3.12's `Path.glob` listed only directories there),
and a pattern with `..` or a leading `/` is refused instead of followed,
since a pattern must not reach outside the directory the fence resolved.
A trailing slash keeps `Path.glob`'s directory-only meaning (`*/`,
`src/**/`). A symbolic link to a directory is entered where a single
component names or matches it and never under `**`, which is how
`Path.glob` read a pattern: `*/util/helper.py` reaches through a linked
`vendor`, `**/helper.py` does not, and a link cycle is entered once per
component the pattern spends on it, so `*/*/*/b.py` enters `src/loop ->
src` twice and stops. The walker asks its caller per link (`follow`),
`find` answers from the pattern and hands the link positions of a path
to the matcher so `**` cannot claim them, and `list_dir` and the grep
fallback never ask, staying as `rglob` and `os.walk` left them. A third
deliberate difference from the merge base: a noise directory inside a
pattern's literal prefix (`node_modules/*.js`, `src/node_modules/*.js`)
is walked, since the pattern asked for it, where `Path.glob`'s filter
dropped it; one met below the prefix is pruned as before
(`*/node_modules/*.js` answers nothing), `list_dir` on such a path lists
it, and the `find`, `list_dir` and code-flow `glob` descriptions state
that rule instead of an unconditional "skipped". Review found an earlier
wording of the two `find` descriptions one component short ("except one
the pattern starts with"), while the oracle helper already pruned below
the prefix; the sentences now say what the helper checks, and the oracle
has the `src/node_modules` shape on both sides.

The raven-code `glob` tool (`agents/raven-code/.../tools/search.py`)
parses trunk `find` output line by line and strips the trailer before
merging brace alternatives. It learns the new clause, so a cut-short
child is reported as cut short rather than as a tree that lacks the
files; its `is_notice` grammar covers the new line so it is never pasted
into a listing as a path. The code-flow tool guide
(`prompts/TOOLS_CODE.md`), the wrapper's description and its `limit`
parameter told the model that a PARTIAL `glob` result means "raise
`limit` or narrow the pattern"; a traversal-budget PARTIAL is now a
result `glob` can return and a higher limit does nothing for it, so all
three now tell the two notices apart. The seeded copy of the guide
refreshes through the receipt `seed_guide` keeps beside it, so no legacy
digest is added.

Fixed in passing, and now pinned: recursive `list_dir` filtered `rglob`
results on the components of the absolute path, so a workspace beneath a
directory named `build`, `dist`, `venv` or another noise name listed as
"Directory ... is empty" (reproduced at the merge base under
`<tmp>/build/proj`; this head lists it). The shared walk prunes below
the listed path only; `find` and the grep fallback already did.

Not changed: the 20s value. It is the budget grep's fallback already ran
under; this PR does not re-measure it, it makes it hold for every entry
of every walk.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

At head 8dade176, on origin/main at d50a13c1 (nine commits: the walk,
the grep pin, the changelog, the per-entry budget with the prefix start,
the literal-directory case, the symbolic-link reading with the
noise-prefix wording, the noise-name-above-the-path pin, the guide
wording, and the prefix-rule wording; `git range-diff` against bb836988:
all nine replayed `=` onto the moved main, which conflicted only at the
changelog anchor and touches no file this PR touches):

```
uv run pytest tests/test_file_search_traversal_guard.py tests/test_agents_code_tools_plugin.py \
  tests/test_search_tools.py tests/test_tools_workdir.py tests/test_tool_registry_execute.py tests/test_filesystem_tools.py -q
# 203 passed
COLORTERM=truecolor uv run --frozen --python 3.12 --all-extras pytest -q --ignore=tests/integration   # in a throwaway worktree
# 24652 passed, 110 skipped in 382.30s (0:06:22) at head 8dade176, in a throwaway worktree with COLORTERM=truecolor
uv run pytest tests/test_agents_code_launcher.py tests/test_agents_code_tools_plugin.py -q   # the guide's seeding and wording tests, the glob wrapper
# 119 passed
make lint-python lint-imports lint-types lint-deps          # all pass
git diff --check origin/main...HEAD                         # clean
scripts/check_source_language.py origin/main...HEAD         # exit 0
scripts/check_large_files.py origin/main...HEAD             # exit 0
git merge-tree --write-tree HEAD origin/main                # clean
```

Revert-to-red, with the tests kept (101 tests in
`test_file_search_traversal_guard.py` +
`test_agents_code_tools_plugin.py`):

```
the three production files reverted to the previously reviewed head (fd5663ee)   19 failed
file_search.py + filesystem.py reverted to origin/main, tree_walk.py removed      collection error
```

Mutation, each mutant applied alone, control restored between runs:

```
deadline checked once per directory (the reviewed placement)   10 failed
walk starts at the root instead of the pattern's prefix          2 failed
trailing slash matches files too                                 4 failed
a pattern naming one file still walks                            1 failed
the prefix itself is never a match                               7 failed
a pattern naming one directory walks beneath it                  1 failed
control (nothing mutated)                                      101 passed
```

From the first review round (still holding at this head): find without
`to_thread` 1 failed; list_dir without `to_thread` 1 failed; grep
fallback without `to_thread` 1 failed; pruning removed 6 failed; fork
drops the PARTIAL clause 1 failed.

Fourth round, the symbolic-link reading
(`test_file_search_traversal_guard.py` +
`test_agents_code_tools_plugin.py`, 128 tests, `-n 0`; a mutant that
lets `**` sweep a link, or forgets the link positions, re-enters the
cycle until the OS refuses the path and answers paths `Path.glob` never
did):

```
baseline                                                 128 passed
MUTANT  ** may sweep a link                                8 failed   (7 oracle cases, and the link the pattern ends at is opened)
MUTANT  find never asks to enter a link                    6 failed   (the six oracle patterns that pass through a link)
MUTANT  a link is entered even when the pattern ends at it 1 failed   (scandir spy on **/vendor)
MUTANT  ancestor links forgotten (links_of empty)          1 failed   (a cycle case answers a path Path.glob never did)
MUTANT  the walker consults follow but never enters        7 failed
MUTANT  each followed root gets a fresh deadline           9 failed   (every deadline test, and the walker's one-budget test)
REVERT  production files to reviewed head d67184c8         7 failed
CONTROL restored                                         128 passed
```

Revert-to-red for the noise-name pin: with
`raven/agent/tools/filesystem.py` at the merge base and the test kept,
`test_a_noise_name_above_the_searched_path_hides_nothing` fails on the
`Directory ... is empty` answer (1 failed); at this head it passes. The
`agents/**` change is two prose strings and a guide line, outside the
coverage gate's `raven/**` and `plugins-dist/**` pathspecs; the guide's
name-list test and its seeding tests (`test_agents_code_launcher.py`)
cover the file.

The prefix rule is pinned by mutation, the other policy (prune a noise
directory inside the prefix) against the two guard files (131 tests, `-n
0`):

```
baseline                                                 131 passed
MUTANT  a noise directory inside the prefix is pruned    5 failed
      test_find_matches_what_path_glob_matched[node_modules/**/*.py], test_find_matches_what_path_glob_matched[node_modules/*/], test_find_matches_what_path_glob_matched[node_modules/*/d.py], test_find_matches_what_path_glob_matched[node_modules/x/d.py], test_find_matches_what_path_glob_matched[src/node_modules/*.py]
CONTROL restored                                         131 passed
```

The symlink oracle is the reviewer's own test shape over a fixture with
links: `vendor -> outside/real`, `src/loop -> src`, `alias.py -> a.py`,
a `node_modules` beneath the link; 19 patterns, 0 mismatches against
`Path.glob` on 3.12, plus a scandir spy pinning that `**/vendor` never
opens the link, a walker test pinning that the default walk yields a
link and does not enter it while a `follow`ed link is walked after the
tree under one deadline, and a `list_dir` and grep test pinning
`rglob`/`os.walk` parity through a link.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed (CHANGELOG
`Unreleased / Fixed` entry)

## Risk

User-visible behaviour changes, all in tool output the model reads:

- `find` and `list_dir` (recursive) can now return a partial listing
with a `PARTIAL result` clause in the trailer where they previously
either returned everything or hung. The clause tells the model the
absence of a match is not conclusive and to narrow the search.
- A path-prefixed `find` pattern spends its budget only inside its
prefix, so on a large tree it finds what a root-anchored walk used to
miss.
- `find` refuses patterns containing `..` or starting with `/` with an
`Error running find:` line; `Path.glob` used to raise on the second and
could climb on the first.
- `find` with a trailing `**` lists files as well as directories beneath
the prefix; a trailing `/` lists directories only, as before.
- `find` reaches through a symbolic link to a directory where a literal
or single-wildcard component names or matches it, as it did at the merge
base; the earlier revisions of this PR had lost that and returned a
clean miss with no notice. `**` never enters a link, as before.
- A noise directory inside a `find` pattern's literal prefix, or named
as the `list_dir` path, is walked: `find('node_modules/*.js')` and
`find('src/node_modules/*.js')` answer its files and
`list_dir('node_modules', recursive=true)` lists it, where the merge
base answered nothing and "empty". One met below the prefix is pruned as
before. Both descriptions state the rule.
- Recursive `list_dir` on a workspace beneath a directory named like a
noise directory (`/tmp/build/proj`) lists it instead of answering "is
empty".
- The code-flow `glob` description, its `limit` parameter and the tool
guide tell a limit cut from a traversal-budget PARTIAL; the notices
themselves are unchanged.
- `list_dir` flat listings are unchanged; the empty-directory message is
unchanged.

Rollback: revert the squash commit. The new module has no other
consumers, and no state or schema is involved.

- [x] Security impact considered (a pattern can no longer climb out of
the fenced directory via `..`; a directory link is entered exactly where
`Path.glob` entered it at the merge base, one non-`**` component, and
never under `**`, so the fence's reach is what it was and not wider;
`list_dir` and grep never enter one)
- [x] Backward compatibility considered (the fork's trailer grammar is
extended, not changed; existing fork tests pass unchanged)
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: Claude (claude-fable-5-1) <noreply@anthropic.com>
2026-09-22 10:59:01 +08:00
0xKT
7a0b5dd311 feat(acp): a prompt is held open while the agent sleeps on an armed wake, and takes a steer
## Summary

An on-call agent submits a job, arms a wake and ends its turn saying so; the wake runs a later turn on the session on its own clock. Over ACP that turn's `end_turn` read as "finished" to the caller: a DAG judging its node spent every continuation on "still watching, wake at 13:13" while the job ran fine (ar-r4, 2026-09-08), and the main agent re-dispatched the work by hand. ACP has no stop reason for "waiting". Replaces the closed !573: **no DAG code changes**, no new node status. The node is `running` because a turn is genuinely in flight.

- **The signal.** The loop-hooks paper gains one key the ACP layer reads for itself: `acp_meta["raven.holdTurn"]` (`{"untilMs", "why"}`). oncall-flow files it at the send fire when the window's campaign is claimed, not concluded, and has one pending wake -- read the same way the owner's answer pulls that wake forward. No campaign, a wake that stood down, or a concluded campaign files nothing and the turn ends as before.
- **The hold** (`raven/acp/methods.py`). A turn that ended `end_turn` with the key filed is not answered. One `tool_call` stands for the wait (its title names the campaign and the next look), with a `tool_call_update` heartbeat every `HOLD_HEARTBEAT_S` (60 s) so a client that clocks liveness by frames sees the agent alive while its model sleeps. The turn slot is reopened with no id to correlate on, so whichever turn ends next on the session -- the wake's, a steer's -- settles it, and the handler decides again from that turn's stash. A wake that arms again keeps the hold; a turn ending with nothing pending answers `end_turn`; a cancel answers `cancelled` as before. The key itself is not passed to the client.
- **Steer.** `_raven/session/steer` is served and advertised under `agentCapabilities._meta` as `raven.steer` (the names raven's own client already uses). Accepted while a prompt is open on the session, held or running: the text is shown on the wire as the person's own line, then sent with `turn.send`'s new `busy: "inject"`. Answers `injected` / `no_turn`.
- **Wire.** `turn.send` gains the optional `busy` param (`const "inject"`): an ordinary send on an idle lane, `BusyPolicy.INJECT` into the running turn otherwise -- the merge a channel's mid-turn message already gets (`gateway_commands.py`). No slot is bound for an injected message; the running turn keeps the lane's. `openrpc.json` and both generated clients moved together.

What raven's client side already does, unchanged: the DAG stall watcher resets on any frame (the heartbeat keeps it quiet, and a stopped heartbeat raises the existing stall notice after ten minutes); a sub-agent process that dies fails the request and the node takes its ordinary path; the pool's `_responsive` treats a prompt in flight as busy.

## Review round 1 (2026-09-09, on !600, superseded by this MR)

- **`busy: inject` reads the scheduler's lane state too.** `is_turn_active` knows only the turns `turn.send` started; an armed wake is submitted to the scheduler directly (`make_on_session_wake`) and never binds that map, so a steer during a running wake queued a second turn and answered `injected`. `turn.send` now asks `Scheduler.has_inflight(lane)` as well, and merges (`BusyPolicy.INJECT`) when either record says the lane is running. Pinned: `test_busy_inject_merges_into_a_wake_the_real_scheduler_is_running` -- the reviewer's reproduction on the real `Scheduler`, a turn submitted the way `make_on_session_wake` submits one; with the lane check bypassed it reads `pending=1, inject_mailbox=0`, with it `(1, 0)` in the mailbox and the running turn drains the text.
- Branch renamed to snake_case and both commits carry the `Co-authored-by: Claude (<model-id>)` trailer, per AGENTS.md §2–3; that is why this MR replaces !600 rather than continuing it.

## Review round 2 (2026-09-10)

- **A wake re-armed during its own run survives the writeback.** `CronService._writeback_locked` reloaded the store after the run and, for a one-shot with `delete_after_run`, overwrote the id with the finished run's state and removed it -- but the turn the wake ran had just called `schedule_wake` under the same key, so the id now named the *next* look. It vanished, and the held prompt had nothing left to settle it. A stored job under the fired id whose `at` schedule the run never had is treated as the new wake it is: claim cleared, run recorded, schedule kept, not deleted. Pinned on the real service: `test_a_wake_re_armed_during_its_own_run_survives_the_writeback` (reads `[]` without the fix, the reviewer's state) and the unchanged one-shot deletion beside it. Cron, proactive, sentinel and on-call suites: 968 passed.

## Review round 3 (2026-09-10)

- **An undrained inject stays visible and cancellable.** `busy: inject` dropped the scheduler's handle; when the host turn ended past its last drain, the spine's fallback ran the text as a turn nothing owned -- `turn.cancel` a no-op, no `message.start`. The handle is now kept per lane under an id minted for the text; `turn.cancel` / `session.interrupt` reach it when the active slot is empty (mailbox, queued fallback, or running); and when the fallback turn starts, the RPC sink (`on_turn_start`, wired from bootstrap) binds the lane to it and opens it on the wire with the person's words. `turn.send` answers the inject's own id. Pinned through `build_rpc_spine` with the reviewer's shape (a loop that drains once, an inject after it): `test_an_undrained_inject_runs_as_a_turn_the_surface_can_see_and_cancel` and `test_a_pending_inject_can_be_cancelled_before_it_merges_or_falls_back`; both read the reviewer's state (`turn_ids` empty, cancel finding nothing) with the fix bypassed.
- **Line ceiling.** The contract comment is five lines; `raven/contracts` is 2,519 against 2,520, one line of headroom on the current `main` (2,514).
- Non-blocking items taken: `SchedulerDrainingError` on the inject path exits as `turn_failed`; the title is announced before the hold; the steer constants sit below the cancel constant's docstring; three edges pinned (a held prompt settled by a wake turn's uncorrelated ending through `send_frame`, the hold key never in the client's `_meta`, `raven.toolName` on the wait row).
- Focused suite (reviewer's list plus the touched files): 948 passed on Python 3.12.

## Review round 4 (2026-09-10)

- **Every pending inject is kept, per lane and per id.** One replaceable record per lane kept only the newest steer; two steers after the host's last drain fall back in turn, and the first started unowned while a cancel took out the second. The record is now `lane -> {inject id: (handle, text)}` in arrival order: each fallback promotes its own handle, and a cancel with no active turn reaches the oldest pending one -- the one the spine runs next. Pinned: `test_two_undrained_injects_each_get_their_own_turn_promoted_and_cancelled` (both promoted with their own ids and `message.start`, cancelled one after the other; runner saw all three turns). Focused suite: 949 passed.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

```
uv run pytest tests/test_acp_methods.py tests/test_acp_protocol.py tests/test_rpc_turn_send.py \
  tests/test_rpc_schema_match.py tests/test_acp_updates.py tests/test_acp_server.py -q      # 766 passed
uv run pytest tests/test_agents_oncall_flow_hooks.py tests/test_agents_oncall_flow_actions.py \
  tests/test_agents_oncall_flow_budget.py tests/test_agents_oncall_flow_readings.py \
  tests/test_agents_oncall_flow_escalation_tools.py -q                                       # 99 passed
uv run ruff check raven tests agents && uv run ruff format --check raven tests agents        # clean
uv run lint-imports                                                                          # 9 kept, 0 broken
cd ui-tui && npm run lint:rpc && npx tsc --noEmit; cd ui-web && npm run gen:check && npx tsc --noEmit   # in sync, clean
```

New tests: `TestHeldTurn` (held across an armed wake, held again on a re-arm, heartbeat on the wait call, cancel while held, a non-`end_turn` stop is not held; every frame validated against the ACP schema), `TestSteer` (advertised, `no_turn` when idle, a held prompt takes the words as a turn with `busy: inject`, refusals), `busy: inject` on a busy and an idle lane in `test_rpc_turn_send.py`, and the plugin's hold stamping through the real `CronService` grant (filed with a pending wake; not filed without one, after the wake stands down, or once the campaign concluded).

Not done: no end-to-end run of a real on-call wake through a held prompt yet -- unit tests only.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed (the hold is invisible to a person except as a "waiting for ..." tool row)

## Risk

- [x] Backward compatibility considered: a turn that files no `raven.holdTurn` is answered exactly as before; `busy` is optional and absent from every existing caller; the steer method and capability are additive.
- [x] Rollback path is clear: revert the two commits.

A held prompt holds one `max_concurrent_subagents` slot (default 8) for the wait's duration on the caller's side; raised in config if it bites.

## Related

Replaces !573 (closed). Follows !518 (stall notice) and !520 (unprompted-turn route; a wake that runs under a held prompt no longer takes it for DAG nodes).
2026-09-11 02:37:55 +00:00
silverLXT
83aac42909 feat(acp): a prompt is held open while the agent sleeps on an armed wake, and takes a steer
## Summary

An on-call agent submits a job, arms a wake and ends its turn saying so; the wake runs a later turn on the session on its own clock. Over ACP that turn's `end_turn` read as "finished" to the caller: a DAG judging its node spent every continuation on "still watching, wake at 13:13" while the job ran fine (ar-r4, 2026-09-08), and the main agent re-dispatched the work by hand. ACP has no stop reason for "waiting". Replaces the closed !573: **no DAG code changes**, no new node status. The node is `running` because a turn is genuinely in flight.

- **The signal.** The loop-hooks paper gains one key the ACP layer reads for itself: `acp_meta["raven.holdTurn"]` (`{"untilMs", "why"}`). oncall-flow files it at the send fire when the window's campaign is claimed, not concluded, and has one pending wake -- read the same way the owner's answer pulls that wake forward. No campaign, a wake that stood down, or a concluded campaign files nothing and the turn ends as before.
- **The hold** (`raven/acp/methods.py`). A turn that ended `end_turn` with the key filed is not answered. One `tool_call` stands for the wait (its title names the campaign and the next look), with a `tool_call_update` heartbeat every `HOLD_HEARTBEAT_S` (60 s) so a client that clocks liveness by frames sees the agent alive while its model sleeps. The turn slot is reopened with no id to correlate on, so whichever turn ends next on the session -- the wake's, a steer's -- settles it, and the handler decides again from that turn's stash. A wake that arms again keeps the hold; a turn ending with nothing pending answers `end_turn`; a cancel answers `cancelled` as before. The key itself is not passed to the client.
- **Steer.** `_raven/session/steer` is served and advertised under `agentCapabilities._meta` as `raven.steer` (the names raven's own client already uses). Accepted while a prompt is open on the session, held or running: the text is shown on the wire as the person's own line, then sent with `turn.send`'s new `busy: "inject"`. Answers `injected` / `no_turn`.
- **Wire.** `turn.send` gains the optional `busy` param (`const "inject"`): an ordinary send on an idle lane, `BusyPolicy.INJECT` into the running turn otherwise -- the merge a channel's mid-turn message already gets (`gateway_commands.py`). No slot is bound for an injected message; the running turn keeps the lane's. `openrpc.json` and both generated clients moved together.

What raven's client side already does, unchanged: the DAG stall watcher resets on any frame (the heartbeat keeps it quiet, and a stopped heartbeat raises the existing stall notice after ten minutes); a sub-agent process that dies fails the request and the node takes its ordinary path; the pool's `_responsive` treats a prompt in flight as busy.

## Review round 1 (2026-09-09, on !600, superseded by this MR)

- **`busy: inject` reads the scheduler's lane state too.** `is_turn_active` knows only the turns `turn.send` started; an armed wake is submitted to the scheduler directly (`make_on_session_wake`) and never binds that map, so a steer during a running wake queued a second turn and answered `injected`. `turn.send` now asks `Scheduler.has_inflight(lane)` as well, and merges (`BusyPolicy.INJECT`) when either record says the lane is running. Pinned: `test_busy_inject_merges_into_a_wake_the_real_scheduler_is_running` -- the reviewer's reproduction on the real `Scheduler`, a turn submitted the way `make_on_session_wake` submits one; with the lane check bypassed it reads `pending=1, inject_mailbox=0`, with it `(1, 0)` in the mailbox and the running turn drains the text.
- Branch renamed to snake_case and both commits carry the `Co-authored-by: Claude (<model-id>)` trailer, per AGENTS.md §2–3; that is why this MR replaces !600 rather than continuing it.

## Review round 2 (2026-09-10)

- **A wake re-armed during its own run survives the writeback.** `CronService._writeback_locked` reloaded the store after the run and, for a one-shot with `delete_after_run`, overwrote the id with the finished run's state and removed it -- but the turn the wake ran had just called `schedule_wake` under the same key, so the id now named the *next* look. It vanished, and the held prompt had nothing left to settle it. A stored job under the fired id whose `at` schedule the run never had is treated as the new wake it is: claim cleared, run recorded, schedule kept, not deleted. Pinned on the real service: `test_a_wake_re_armed_during_its_own_run_survives_the_writeback` (reads `[]` without the fix, the reviewer's state) and the unchanged one-shot deletion beside it. Cron, proactive, sentinel and on-call suites: 968 passed.

## Review round 3 (2026-09-10)

- **An undrained inject stays visible and cancellable.** `busy: inject` dropped the scheduler's handle; when the host turn ended past its last drain, the spine's fallback ran the text as a turn nothing owned -- `turn.cancel` a no-op, no `message.start`. The handle is now kept per lane under an id minted for the text; `turn.cancel` / `session.interrupt` reach it when the active slot is empty (mailbox, queued fallback, or running); and when the fallback turn starts, the RPC sink (`on_turn_start`, wired from bootstrap) binds the lane to it and opens it on the wire with the person's words. `turn.send` answers the inject's own id. Pinned through `build_rpc_spine` with the reviewer's shape (a loop that drains once, an inject after it): `test_an_undrained_inject_runs_as_a_turn_the_surface_can_see_and_cancel` and `test_a_pending_inject_can_be_cancelled_before_it_merges_or_falls_back`; both read the reviewer's state (`turn_ids` empty, cancel finding nothing) with the fix bypassed.
- **Line ceiling.** The contract comment is five lines; `raven/contracts` is 2,519 against 2,520, one line of headroom on the current `main` (2,514).
- Non-blocking items taken: `SchedulerDrainingError` on the inject path exits as `turn_failed`; the title is announced before the hold; the steer constants sit below the cancel constant's docstring; three edges pinned (a held prompt settled by a wake turn's uncorrelated ending through `send_frame`, the hold key never in the client's `_meta`, `raven.toolName` on the wait row).
- Focused suite (reviewer's list plus the touched files): 948 passed on Python 3.12.

## Review round 4 (2026-09-10)

- **Every pending inject is kept, per lane and per id.** One replaceable record per lane kept only the newest steer; two steers after the host's last drain fall back in turn, and the first started unowned while a cancel took out the second. The record is now `lane -> {inject id: (handle, text)}` in arrival order: each fallback promotes its own handle, and a cancel with no active turn reaches the oldest pending one -- the one the spine runs next. Pinned: `test_two_undrained_injects_each_get_their_own_turn_promoted_and_cancelled` (both promoted with their own ids and `message.start`, cancelled one after the other; runner saw all three turns). Focused suite: 949 passed.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

```
uv run pytest tests/test_acp_methods.py tests/test_acp_protocol.py tests/test_rpc_turn_send.py \
  tests/test_rpc_schema_match.py tests/test_acp_updates.py tests/test_acp_server.py -q      # 766 passed
uv run pytest tests/test_agents_oncall_flow_hooks.py tests/test_agents_oncall_flow_actions.py \
  tests/test_agents_oncall_flow_budget.py tests/test_agents_oncall_flow_readings.py \
  tests/test_agents_oncall_flow_escalation_tools.py -q                                       # 99 passed
uv run ruff check raven tests agents && uv run ruff format --check raven tests agents        # clean
uv run lint-imports                                                                          # 9 kept, 0 broken
cd ui-tui && npm run lint:rpc && npx tsc --noEmit; cd ui-web && npm run gen:check && npx tsc --noEmit   # in sync, clean
```

New tests: `TestHeldTurn` (held across an armed wake, held again on a re-arm, heartbeat on the wait call, cancel while held, a non-`end_turn` stop is not held; every frame validated against the ACP schema), `TestSteer` (advertised, `no_turn` when idle, a held prompt takes the words as a turn with `busy: inject`, refusals), `busy: inject` on a busy and an idle lane in `test_rpc_turn_send.py`, and the plugin's hold stamping through the real `CronService` grant (filed with a pending wake; not filed without one, after the wake stands down, or once the campaign concluded).

Not done: no end-to-end run of a real on-call wake through a held prompt yet -- unit tests only.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed (the hold is invisible to a person except as a "waiting for ..." tool row)

## Risk

- [x] Backward compatibility considered: a turn that files no `raven.holdTurn` is answered exactly as before; `busy` is optional and absent from every existing caller; the steer method and capability are additive.
- [x] Rollback path is clear: revert the two commits.

A held prompt holds one `max_concurrent_subagents` slot (default 8) for the wait's duration on the caller's side; raised in config if it bites.

## Related

Replaces !573 (closed). Follows !518 (stall notice) and !520 (unprompted-turn route; a wake that runs under a held prompt no longer takes it for DAG nodes).
2026-09-11 02:37:55 +00:00
0xKT
cfe806a6e0 feat(cli): onboard spends one real search on the web_search key
## Summary

The onboard wizard stored the web_search vendor's key without checking it, so a mistyped or revoked key surfaced as the tool's first failure inside a conversation. Step 5 now spends one real query on the key right after the prompt and before anything is written.

- `WebSearchTool.probe()` runs the same provider request `execute()` uses, asking for one result, and returns `(ok, detail)`. The detail carries vendor and HTTP status only. Exception text is never echoed: SerpApi puts the key in the request URL, and an unusable proxy URL can carry its own credentials, so that branch reports the exception class alone.
- Interactive step 5 loops the key prompt through the probe. On failure the user picks re-enter, retry, or continue anyway. A stored key kept with Enter is probed too, since it may have been revoked. An empty slot is not probed, since leaving web_search off is a choice, not a failure.
- The flag path (`--search-api-key`, `--serper-api-key`) writes first and then probes, warning on failure without dropping the write, because a scripted run has nobody to re-enter the key. Only the active search vendor's key is probed there.
- The page reader is not probed. Jina works with no key, and a keyed reader whose key does not resolve is replaced by Jina at registration. A keyed reader with a wrong key still fails at call time; that is unchanged and out of scope here.
- All wizard strings reuse existing zh catalog entries; README step 5 and the `--search-api-key` help mention the check.

Deliberately not done, for the reviewer: the web settings page writes the same key slot and does not probe; a key supplied only through the vendor's env var is not probed; step 5 does not feed the wizard's end-of-run warnings list. A vendor that answers 200 with zero results passes, since only HTTP status and a Firecrawl refusal count as failure.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

```
uv run pytest tests/test_agent_tools_web_providers.py tests/test_cli_onboard_commands.py \
  tests/test_i18n_boundary.py tests/test_agent_loop_web_tools.py    410 passed
make lint-python                                                     clean
make check-source-language                                           exit 0
uv run python scripts/check_commit_messages.py origin/main..HEAD     exit 0
```

Revert-the-fix check: with the onboard change reverted, the five new step 5 tests error out on the missing probe seam. No test reaches the network: an autouse fixture in the onboard tests replaces the probe, and the provider tests patch the HTTP client. `make lint-tui` fails on a stale generated i18n file that is identical on `main`; `make lint-bridge` needs `tsc`, which this box lacks.

Not verified: a live run against a real vendor key.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

User-visible change: onboarding spends one search query per key check against the chosen vendor, and a rejected key adds one prompt. The key still goes only to its own vendor's endpoint, through the configured `tools.web.proxy`. Nothing in config changes shape. Rollback is reverting the commit; no data migration.

## Related Issues

N/A
2026-09-11 02:35:44 +00:00
userName20260323
62aefbd1e5 feat(cli): onboard spends one real search on the web_search key
## Summary

The onboard wizard stored the web_search vendor's key without checking it, so a mistyped or revoked key surfaced as the tool's first failure inside a conversation. Step 5 now spends one real query on the key right after the prompt and before anything is written.

- `WebSearchTool.probe()` runs the same provider request `execute()` uses, asking for one result, and returns `(ok, detail)`. The detail carries vendor and HTTP status only. Exception text is never echoed: SerpApi puts the key in the request URL, and an unusable proxy URL can carry its own credentials, so that branch reports the exception class alone.
- Interactive step 5 loops the key prompt through the probe. On failure the user picks re-enter, retry, or continue anyway. A stored key kept with Enter is probed too, since it may have been revoked. An empty slot is not probed, since leaving web_search off is a choice, not a failure.
- The flag path (`--search-api-key`, `--serper-api-key`) writes first and then probes, warning on failure without dropping the write, because a scripted run has nobody to re-enter the key. Only the active search vendor's key is probed there.
- The page reader is not probed. Jina works with no key, and a keyed reader whose key does not resolve is replaced by Jina at registration. A keyed reader with a wrong key still fails at call time; that is unchanged and out of scope here.
- All wizard strings reuse existing zh catalog entries; README step 5 and the `--search-api-key` help mention the check.

Deliberately not done, for the reviewer: the web settings page writes the same key slot and does not probe; a key supplied only through the vendor's env var is not probed; step 5 does not feed the wizard's end-of-run warnings list. A vendor that answers 200 with zero results passes, since only HTTP status and a Firecrawl refusal count as failure.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

```
uv run pytest tests/test_agent_tools_web_providers.py tests/test_cli_onboard_commands.py \
  tests/test_i18n_boundary.py tests/test_agent_loop_web_tools.py    410 passed
make lint-python                                                     clean
make check-source-language                                           exit 0
uv run python scripts/check_commit_messages.py origin/main..HEAD     exit 0
```

Revert-the-fix check: with the onboard change reverted, the five new step 5 tests error out on the missing probe seam. No test reaches the network: an autouse fixture in the onboard tests replaces the probe, and the provider tests patch the HTTP client. `make lint-tui` fails on a stale generated i18n file that is identical on `main`; `make lint-bridge` needs `tsc`, which this box lacks.

Not verified: a live run against a real vendor key.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

User-visible change: onboarding spends one search query per key check against the chosen vendor, and a rejected key adds one prompt. The key still goes only to its own vendor's endpoint, through the configured `tools.web.proxy`. Nothing in config changes shape. Rollback is reverting the commit; no data migration.

## Related Issues

N/A
2026-09-11 02:35:44 +00:00
0xKT
cf9a0a8b5a chore(*): a cyclomatic complexity ceiling that only stops the untestable
## Summary

Ruff carried no complexity rule, so nothing bounded the number of paths through
a function. This adds `C901` with a ceiling chosen to stop the untestable and
nothing else.

**What the number means.** Cyclomatic complexity is the count of linearly
independent paths through a function, which makes it the floor on how many cases
a suite needs to walk them all. A body with a hundred of them has paths nobody
will ever write a case for, and those paths are first executed in production.
That is the failure this rule prevents; it is not a style preference.

Two properties of the metric matter for reading the numbers below. A nested
function's score is counted into its enclosing function as well as reported on
its own, so an outer function with no branches of its own scores one more than
the inner function it holds. And Ruff reports `C901` only when the score is
*greater* than `max-complexity`, so a function at exactly 40 passes a ceiling of
40 and needs no suppression.

**Where 40 comes from.** The measured distribution, not McCabe's recommendation
of 10:

| max-complexity | functions flagged |
|---|---|
| 10 | 253 |
| 25 | 26 |
| 30 | 17 |
| **40** | **9** |
| 50 | 5 |

Ten would flag 253 functions and be switched off within the week. Forty is not a
claim that 39 is fine -- it is where a function stops being complex and starts
being untestable. Tightening later means lowering the number, which is a
reviewed edit to `pyproject.toml`.

**The nine over the ceiling.** Each carries a `noqa: C901` naming its actual
score. Seven are in `raven/`, two in the oncall-flow plugin under `agents/`:

```
100  raven/agent/loop/turn_path.py                             _run_agent_loop
 87  raven/cli/gateway_commands.py                             register
 86  raven/cli/gateway_commands.py                             gateway
 69  agents/raven-oncall/.../oncall_flow/tools/ops.py           execute
 68  raven/cli/gateway_commands.py                             run
 54  agents/raven-oncall/.../oncall_flow/tools/ops.py           execute
 47  raven/agent/loop/turn_path.py                             _process_message
 46  raven/config/loader.py                                    _migrate_config
 41  raven/agent/loop/turn_path.py                             _run_turn
```

A tenth suppression sits on `benchmarks/proactivity_eval/runners/_common/longrun_adapters.py`
(`tick_to`, 41). `benchmarks/` is outside `PYTHON_LINT_TARGETS` and so outside
CI, but inside what the pre-commit Ruff hook sees on a changed file -- marking it
means the gate does not ambush whoever next edits that adapter.

**Nine entries, fewer distinct problems.** In `gateway_commands.py` the three
are nested inside each other at indent 0, 4 and 8: `run` at 68 is the body,
`gateway` adds its own branches on top, and `register` contributes about one. In
`turn_path.py` the three are sibling methods, but `_run_turn` holds ten nested
callbacks (`on_token`, `on_tool`, `on_progress` and so on) which is most of its
41. The one that is a large body by itself is `_run_agent_loop`: 1134 lines with
only two nested functions, so its 100 is its own.

Per-function rather than per-file, on purpose: a whole-file ignore on
`gateway_commands.py` would let a new 80-path function in the same file through,
while these entries do not. The score is in the comment so the debt is visible
where the code is, not parked in a config file.

Nothing has to be refactored to land this. Normal work is undisturbed unless
someone writes a forty-one-path function.

**Why the PLR09xx rules are left out.** They count arguments (230 occurrences
here), branches (125), statements (78) and returns (81). All four are proxies
for what `C901` measures directly, so adding them would report one fact four
times and bury the signal under 230 argument-count warnings.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

Other: a lint gate plus the `noqa` entries that let it land green. No runtime
code changes; every production edit is an end-of-line comment.

## Verification

Verified against the lint roster read out of the Makefile
(`PYTHON_LINT_TARGETS = raven evolver agents plugins-dist tests scripts`) rather
than a chosen subset, and then against the whole tree. The first revision of
this MR checked only `raven/` and went red in CI on the two `agents/` functions;
that is what the roster-wide check exists to prevent.

```
$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache \
    raven evolver agents plugins-dist tests scripts
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache .
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache \
    --extend-select RUF100 raven evolver agents plugins-dist tests scripts
(no unused C901 directive)

$ uv run --frozen --python 3.12 --extra dev ruff format --check \
    raven evolver agents plugins-dist tests scripts
1886 files already formatted

$ uv run --frozen --python 3.12 pytest tests/ -q -k "turn_path or gateway or loader or console or config_precedence"
511 passed, 19 skipped

$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

The 19 skips are pre-existing and environmental: `test_provider_resolution_invariants.py`
skips its gateway-only cases when no gateway is configured.

Checked in the failing direction, since a gate never seen red is not known to
work. A fresh forty-branch function appended to `config/loader.py` is reported,
and the `noqa` on `_migrate_config` in the same file keeps holding rather than
being swallowed by it:

```
raven/config/loader.py:1088:5: C901 `_probe_over_ceiling` is too complex (41 > 40)
Found 1 error.
```

The probe was reverted. Note for the reviewer: reverting that file also reverted
its `noqa`, which the roster-wide check caught immediately.

One entry was removed after review rather than kept: `settings_usage` scores
exactly 40, which a ceiling of 40 does not flag, so its suppression was dead.
`--extend-select RUF100` reports such a directive as unused, and keeping it would
have defeated the documented tightening path -- lowering the number later would
have left that function exempt with nothing to show it.

The production diff is comment-only and can be read as such:

```
-    async def _run_agent_loop(
+    async def _run_agent_loop(  # noqa: C901 (cc 100: pre-existing, above the ceiling)
```

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No behaviour change: every production edit is an end-of-line comment, and the
diff can be verified as such. The risk this carries is a false sense of
coverage, which is why the rationale in `pyproject.toml` states what the ceiling
does not mean. Two limits of the metric are worth a reviewer knowing: it does
not see nesting depth (five sequential `if`s and five nested ones both score 6),
and in Ruff's implementation boolean operators, ternaries and comprehension
conditions do not count at all. It is a filter for the untestable, not a
readability score.

Rollback is reverting the commits. Loosening instead of reverting is a one-line
change to `max-complexity`, which is the intended escape if the gate turns out
to obstruct real work.

## Related Issues

N/A
2026-09-11 02:35:31 +00:00
gloryfromca
4f94ad43cc chore(*): a cyclomatic complexity ceiling that only stops the untestable
## Summary

Ruff carried no complexity rule, so nothing bounded the number of paths through
a function. This adds `C901` with a ceiling chosen to stop the untestable and
nothing else.

**What the number means.** Cyclomatic complexity is the count of linearly
independent paths through a function, which makes it the floor on how many cases
a suite needs to walk them all. A body with a hundred of them has paths nobody
will ever write a case for, and those paths are first executed in production.
That is the failure this rule prevents; it is not a style preference.

Two properties of the metric matter for reading the numbers below. A nested
function's score is counted into its enclosing function as well as reported on
its own, so an outer function with no branches of its own scores one more than
the inner function it holds. And Ruff reports `C901` only when the score is
*greater* than `max-complexity`, so a function at exactly 40 passes a ceiling of
40 and needs no suppression.

**Where 40 comes from.** The measured distribution, not McCabe's recommendation
of 10:

| max-complexity | functions flagged |
|---|---|
| 10 | 253 |
| 25 | 26 |
| 30 | 17 |
| **40** | **9** |
| 50 | 5 |

Ten would flag 253 functions and be switched off within the week. Forty is not a
claim that 39 is fine -- it is where a function stops being complex and starts
being untestable. Tightening later means lowering the number, which is a
reviewed edit to `pyproject.toml`.

**The nine over the ceiling.** Each carries a `noqa: C901` naming its actual
score. Seven are in `raven/`, two in the oncall-flow plugin under `agents/`:

```
100  raven/agent/loop/turn_path.py                             _run_agent_loop
 87  raven/cli/gateway_commands.py                             register
 86  raven/cli/gateway_commands.py                             gateway
 69  agents/raven-oncall/.../oncall_flow/tools/ops.py           execute
 68  raven/cli/gateway_commands.py                             run
 54  agents/raven-oncall/.../oncall_flow/tools/ops.py           execute
 47  raven/agent/loop/turn_path.py                             _process_message
 46  raven/config/loader.py                                    _migrate_config
 41  raven/agent/loop/turn_path.py                             _run_turn
```

A tenth suppression sits on `benchmarks/proactivity_eval/runners/_common/longrun_adapters.py`
(`tick_to`, 41). `benchmarks/` is outside `PYTHON_LINT_TARGETS` and so outside
CI, but inside what the pre-commit Ruff hook sees on a changed file -- marking it
means the gate does not ambush whoever next edits that adapter.

**Nine entries, fewer distinct problems.** In `gateway_commands.py` the three
are nested inside each other at indent 0, 4 and 8: `run` at 68 is the body,
`gateway` adds its own branches on top, and `register` contributes about one. In
`turn_path.py` the three are sibling methods, but `_run_turn` holds ten nested
callbacks (`on_token`, `on_tool`, `on_progress` and so on) which is most of its
41. The one that is a large body by itself is `_run_agent_loop`: 1134 lines with
only two nested functions, so its 100 is its own.

Per-function rather than per-file, on purpose: a whole-file ignore on
`gateway_commands.py` would let a new 80-path function in the same file through,
while these entries do not. The score is in the comment so the debt is visible
where the code is, not parked in a config file.

Nothing has to be refactored to land this. Normal work is undisturbed unless
someone writes a forty-one-path function.

**Why the PLR09xx rules are left out.** They count arguments (230 occurrences
here), branches (125), statements (78) and returns (81). All four are proxies
for what `C901` measures directly, so adding them would report one fact four
times and bury the signal under 230 argument-count warnings.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

Other: a lint gate plus the `noqa` entries that let it land green. No runtime
code changes; every production edit is an end-of-line comment.

## Verification

Verified against the lint roster read out of the Makefile
(`PYTHON_LINT_TARGETS = raven evolver agents plugins-dist tests scripts`) rather
than a chosen subset, and then against the whole tree. The first revision of
this MR checked only `raven/` and went red in CI on the two `agents/` functions;
that is what the roster-wide check exists to prevent.

```
$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache \
    raven evolver agents plugins-dist tests scripts
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache .
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff check --no-cache \
    --extend-select RUF100 raven evolver agents plugins-dist tests scripts
(no unused C901 directive)

$ uv run --frozen --python 3.12 --extra dev ruff format --check \
    raven evolver agents plugins-dist tests scripts
1886 files already formatted

$ uv run --frozen --python 3.12 pytest tests/ -q -k "turn_path or gateway or loader or console or config_precedence"
511 passed, 19 skipped

$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

The 19 skips are pre-existing and environmental: `test_provider_resolution_invariants.py`
skips its gateway-only cases when no gateway is configured.

Checked in the failing direction, since a gate never seen red is not known to
work. A fresh forty-branch function appended to `config/loader.py` is reported,
and the `noqa` on `_migrate_config` in the same file keeps holding rather than
being swallowed by it:

```
raven/config/loader.py:1088:5: C901 `_probe_over_ceiling` is too complex (41 > 40)
Found 1 error.
```

The probe was reverted. Note for the reviewer: reverting that file also reverted
its `noqa`, which the roster-wide check caught immediately.

One entry was removed after review rather than kept: `settings_usage` scores
exactly 40, which a ceiling of 40 does not flag, so its suppression was dead.
`--extend-select RUF100` reports such a directive as unused, and keeping it would
have defeated the documented tightening path -- lowering the number later would
have left that function exempt with nothing to show it.

The production diff is comment-only and can be read as such:

```
-    async def _run_agent_loop(
+    async def _run_agent_loop(  # noqa: C901 (cc 100: pre-existing, above the ceiling)
```

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No behaviour change: every production edit is an end-of-line comment, and the
diff can be verified as such. The risk this carries is a false sense of
coverage, which is why the rationale in `pyproject.toml` states what the ceiling
does not mean. Two limits of the metric are worth a reviewer knowing: it does
not see nesting depth (five sequential `if`s and five nested ones both score 6),
and in Ruff's implementation boolean operators, ternaries and comprehension
conditions do not count at all. It is a filter for the untestable, not a
readability score.

Rollback is reverting the commits. Loosening instead of reverting is a one-line
change to `max-complexity`, which is the intended escape if the gate turns out
to obstruct real work.

## Related Issues

N/A
2026-09-11 02:35:31 +00:00
0xKT
02ea26aa6f refactor(permissions): the shell command policy seats where it is enforced
## Summary

`raven.permissions` imported `raven.agent.tools.shell_policy` for
`CommandDecision` and `ShellCommandPolicy`, while the agent side imports
`raven.permissions` from the loop, the turn path and the `raven_loop` backend.
Four edges down, one edge back up, and a cycle between two top-level packages.

The one edge back was the misplaced one. `shell_policy` answers whether a
command may run and whether it needs approval -- which is what the permissions
package is for. It sat under `agent/tools` because that is where the shell tool
that consumes it lives, not because the policy belongs to the tool.

Moving it is unusually cheap: its 1262 lines import `re`, `shlex`,
`contextvars`, `dataclasses`, `enum` and `pathlib` and nothing from raven, so
the module arrives in `permissions` carrying no dependency of its own. Nothing
new enters that package's dependency set.

Its three consumers are repointed rather than reading through a shim at the old
path: the shell tool, the ACP server's approval-family wiring, and the
permissions rules that started this. `agent -> permissions` and
`acp -> permissions` are both directions that already existed.

This is the third instance of one shape in this tree: a capability with no
dependencies of its own, seated inside one of its consumers, which a lower layer
then has to reach up for. The vocabulary split in MR 610 was the second.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [x] Refactor
- [ ] Other

## Verification

```
$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ uv run --frozen --python 3.12 pytest tests/test_shell_approval.py \
    tests/test_shell_comments.py tests/test_shell_policy_reasons.py \
    tests/test_permissions_gate.py tests/test_acp_server.py \
    tests/test_agents_ppt_launcher.py -q
407 passed in 4.65s

$ uv run --frozen --python 3.12 pytest tests/ -q -k "shell or permission or policy"
746 passed, 8 skipped, 20 warnings in 23.73s

$ uv run --frozen --python 3.12 --extra dev ruff check raven/permissions/ \
    raven/acp/server.py raven/agent/tools/shell.py
All checks passed!

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

The eight skips in the wider sweep are pre-existing and environmental: optional
extras that are not installed in this checkout (`wecom_aibot_sdk`, the render
extra). None of them exercise shell policy.

Every consumer of the module was enumerated before the move -- three in `raven/`
and six test files -- and all nine are repointed in this commit, so no import of
the old path remains anywhere in the tree.

Effect on the dependency graph:

```
permissions -> agent edges     1  ->  0
mutually importing pairs      14  ->  13
packages in an import cycle   22  ->  22   (unchanged)
```

The package count does not move. Unlike the config vocabulary split, this pair
was not the only thing holding any other package in the component -- worth
recording, because it is the case where a mutual pair disappears and the
component does not shrink.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

This module decides whether a shell command runs, so the security-relevant
question is whether the decision changed: it did not. The file moves unedited --
git records it as a rename -- and the matchers, the approval families and the
policy class are byte-identical. `tests/test_shell_approval.py`,
`tests/test_shell_comments.py` and `tests/test_permissions_gate.py` cover the
deny and approval paths and pass unchanged apart from the import line.

No public surface is affected: `shell_policy` is internal to raven and its old
path had no consumers outside this repository. Rollback is reverting the one
commit, which git will apply as the reverse rename.

## Related Issues

N/A
2026-09-11 02:35:05 +00:00
gloryfromca
c01af5faa3 refactor(permissions): the shell command policy seats where it is enforced
## Summary

`raven.permissions` imported `raven.agent.tools.shell_policy` for
`CommandDecision` and `ShellCommandPolicy`, while the agent side imports
`raven.permissions` from the loop, the turn path and the `raven_loop` backend.
Four edges down, one edge back up, and a cycle between two top-level packages.

The one edge back was the misplaced one. `shell_policy` answers whether a
command may run and whether it needs approval -- which is what the permissions
package is for. It sat under `agent/tools` because that is where the shell tool
that consumes it lives, not because the policy belongs to the tool.

Moving it is unusually cheap: its 1262 lines import `re`, `shlex`,
`contextvars`, `dataclasses`, `enum` and `pathlib` and nothing from raven, so
the module arrives in `permissions` carrying no dependency of its own. Nothing
new enters that package's dependency set.

Its three consumers are repointed rather than reading through a shim at the old
path: the shell tool, the ACP server's approval-family wiring, and the
permissions rules that started this. `agent -> permissions` and
`acp -> permissions` are both directions that already existed.

This is the third instance of one shape in this tree: a capability with no
dependencies of its own, seated inside one of its consumers, which a lower layer
then has to reach up for. The vocabulary split in MR 610 was the second.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [x] Refactor
- [ ] Other

## Verification

```
$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ uv run --frozen --python 3.12 pytest tests/test_shell_approval.py \
    tests/test_shell_comments.py tests/test_shell_policy_reasons.py \
    tests/test_permissions_gate.py tests/test_acp_server.py \
    tests/test_agents_ppt_launcher.py -q
407 passed in 4.65s

$ uv run --frozen --python 3.12 pytest tests/ -q -k "shell or permission or policy"
746 passed, 8 skipped, 20 warnings in 23.73s

$ uv run --frozen --python 3.12 --extra dev ruff check raven/permissions/ \
    raven/acp/server.py raven/agent/tools/shell.py
All checks passed!

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

The eight skips in the wider sweep are pre-existing and environmental: optional
extras that are not installed in this checkout (`wecom_aibot_sdk`, the render
extra). None of them exercise shell policy.

Every consumer of the module was enumerated before the move -- three in `raven/`
and six test files -- and all nine are repointed in this commit, so no import of
the old path remains anywhere in the tree.

Effect on the dependency graph:

```
permissions -> agent edges     1  ->  0
mutually importing pairs      14  ->  13
packages in an import cycle   22  ->  22   (unchanged)
```

The package count does not move. Unlike the config vocabulary split, this pair
was not the only thing holding any other package in the component -- worth
recording, because it is the case where a mutual pair disappears and the
component does not shrink.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

This module decides whether a shell command runs, so the security-relevant
question is whether the decision changed: it did not. The file moves unedited --
git records it as a rename -- and the matchers, the approval families and the
policy class are byte-identical. `tests/test_shell_approval.py`,
`tests/test_shell_comments.py` and `tests/test_permissions_gate.py` cover the
deny and approval paths and pass unchanged apart from the import line.

No public surface is affected: `shell_policy` is internal to raven and its old
path had no consumers outside this repository. Rollback is reverting the one
commit, which git will apply as the reverse rename.

## Related Issues

N/A
2026-09-11 02:35:05 +00:00
0xKT
3262294989 fix(rpc): a watched sub-agent relay turn can approve an ask-tier tool
## Summary

When a DAG node fails, the sub-agent's report opens a turn in the user's own conversation (origin `SUBAGENT`). The asker already bound in that turn whenever a surface was watching the conversation, so the person could answer `ask_user` there and pick "continue". The approval responder, however, bound only for `USER` turns, so the `resolve_dag_node` call that acts on that answer was refused in the same turn as "this turn is not interactive". The run ended on the person's own decision: the node could be neither continued nor abandoned from the TUI or the WebUI.

The fix binds the approval responder on the gate the asker already used: a `USER` turn always, a `SUBAGENT` relay when its conversation has a live watcher, every other origin never. One expression, shared by both bindings, in `RpcTurnRunner.run`.

The gateway's channel runner (`GatewayTurnRunner`) is deliberately left as it is: a channel session has no watched-signal to gate on, and widening there would turn an abandoned-channel question from an instant decline into a stall, as its own comment says.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- `uv run pytest tests/test_rpc_spine.py tests/test_agent_loop_approval.py tests/test_shell_approval.py tests/test_permissions*.py -q`: 361 passed. Two new cases: a `SUBAGENT` turn in a watched conversation reaches the responder and the gated tool runs; the same turn with nobody watching is still refused as not interactive.
- Reverse check: with the spine change reverted, the watched-relay case fails on the gated tool not running.
- `make lint-python`: clean.
- `uv run --all-extras pytest -q` (before rebase): 20150 passed, 4 failed, 165 skipped. The 4 failures (`test_agent_loop_token_budget`, `test_agents_code_launcher`, `test_agents_oncall_launcher`, `test_ppt_engine_image_search`) fail identically with this change reverted and again on the rebased head; none of them imports `raven.rpc.spine`. Pre-existing on `main`.

End to end, no permission override in the config, host started from this branch, port owner start time checked against the last code change:

| Frontend | Flow | Result |
|---|---|---|
| TUI (`raven tui --dev`) | run a playbook whose carried server is down -> node fails -> host calls `resolve_dag_node continue` -> approval overlay "Approve this action: resolve_dag_node {...}" -> key 1 -> tool runs -> attempt-2 dispatched | pass (before the fix the same step ended in "This call requires user approval (ask tier), but this turn is not interactive") |
| WebUI (`raven serve`) | same flow -> approval sheet "Approve this action: resolve_dag_node {...}" -> "Allow once" -> tool runs (the model chose abandon this time, so no second attempt; the point under test is that the approval reaches the person and the gated tool executes) | pass |

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed (no user-facing docs exist for the approval gate)

## Risk

- Permission semantics: an ask-tier tool called in a sub-agent relay turn now reaches the person watching the conversation instead of being refused. It still fails closed with nobody watching (`has_subscribers` false), on timeout, and on every other origin. This is the same reachability rule the asker has had since the relay widening; approval was the one binding that had not followed it.
- Backward compatibility: `USER` and `CRON` turns are unchanged. The channel gateway runner is unchanged.
- Rollback: revert the squash commit; no data or config involved.

## Related Issues

N/A
2026-09-10 18:07:37 +00:00
gloryfromca
86651393ca fix(rpc): a watched sub-agent relay turn can approve an ask-tier tool
## Summary

When a DAG node fails, the sub-agent's report opens a turn in the user's own conversation (origin `SUBAGENT`). The asker already bound in that turn whenever a surface was watching the conversation, so the person could answer `ask_user` there and pick "continue". The approval responder, however, bound only for `USER` turns, so the `resolve_dag_node` call that acts on that answer was refused in the same turn as "this turn is not interactive". The run ended on the person's own decision: the node could be neither continued nor abandoned from the TUI or the WebUI.

The fix binds the approval responder on the gate the asker already used: a `USER` turn always, a `SUBAGENT` relay when its conversation has a live watcher, every other origin never. One expression, shared by both bindings, in `RpcTurnRunner.run`.

The gateway's channel runner (`GatewayTurnRunner`) is deliberately left as it is: a channel session has no watched-signal to gate on, and widening there would turn an abandoned-channel question from an instant decline into a stall, as its own comment says.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- `uv run pytest tests/test_rpc_spine.py tests/test_agent_loop_approval.py tests/test_shell_approval.py tests/test_permissions*.py -q`: 361 passed. Two new cases: a `SUBAGENT` turn in a watched conversation reaches the responder and the gated tool runs; the same turn with nobody watching is still refused as not interactive.
- Reverse check: with the spine change reverted, the watched-relay case fails on the gated tool not running.
- `make lint-python`: clean.
- `uv run --all-extras pytest -q` (before rebase): 20150 passed, 4 failed, 165 skipped. The 4 failures (`test_agent_loop_token_budget`, `test_agents_code_launcher`, `test_agents_oncall_launcher`, `test_ppt_engine_image_search`) fail identically with this change reverted and again on the rebased head; none of them imports `raven.rpc.spine`. Pre-existing on `main`.

End to end, no permission override in the config, host started from this branch, port owner start time checked against the last code change:

| Frontend | Flow | Result |
|---|---|---|
| TUI (`raven tui --dev`) | run a playbook whose carried server is down -> node fails -> host calls `resolve_dag_node continue` -> approval overlay "Approve this action: resolve_dag_node {...}" -> key 1 -> tool runs -> attempt-2 dispatched | pass (before the fix the same step ended in "This call requires user approval (ask tier), but this turn is not interactive") |
| WebUI (`raven serve`) | same flow -> approval sheet "Approve this action: resolve_dag_node {...}" -> "Allow once" -> tool runs (the model chose abandon this time, so no second attempt; the point under test is that the approval reaches the person and the gated tool executes) | pass |

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed (no user-facing docs exist for the approval gate)

## Risk

- Permission semantics: an ask-tier tool called in a sub-agent relay turn now reaches the person watching the conversation instead of being refused. It still fails closed with nobody watching (`has_subscribers` false), on timeout, and on every other origin. This is the same reachability rule the asker has had since the relay widening; approval was the one binding that had not followed it.
- Backward compatibility: `USER` and `CRON` turns are unchanged. The channel gateway runner is unchanged.
- Rollback: revert the squash commit; no data or config involved.

## Related Issues

N/A
2026-09-10 18:07:36 +00:00
0xKT
81c823519c test(*): the import cycles among subpackages may not reach further
## Summary

These are aggregate ceilings on how far import cycles reach, not a proof that no
cycle was deepened: an edge added between two members of the existing component
leaves every total unmoved, and that case is left to the contracts and to review.
The module docstring says so too.

`acyclic_siblings` is the import-linter contract that would forbid import cycles
among raven's top-level subpackages outright. It is not in `pyproject.toml`
because it is BROKEN: **18 of the 40 top-level subpackages sit in a single
strongly connected component**. Added as a gate it would paint CI red on arrival
and be switched off within the week.

This states the same rule as a budget instead of an absolute. Three ceilings, set
to what the tree measures today, and they may only go down:

```
PACKAGES_IN_CYCLES_CEILING = 18
MUTUAL_PAIRS_CEILING = 13
MODULES_IN_CYCLES_CEILING = 42
```

This branch carries the vocabulary refactor (MR 610) underneath it, because the
ceilings are the numbers that hold once that lands. If 610 merges first this
becomes a single-commit change; either way the ceilings match the tree the guard
runs against.

A change that draws a package or a module into a cycle for the first time, or
makes a new pair import each other, fails here. An edge added between two
members of the existing component does not: every total stays put, and that
case is left to the contracts and to review. Unpicking one lowers a ceiling,
which is a reviewed edit to the test file rather than a drive-by -- the same
shape `tests/test_kernel_budget.py` already uses, and for the same reason its
docstring gives.

Three numbers, because each is blind where another sees. Mutual pairs (a imports
b and b imports a) are the edges people actually add, and the failure message
names them. A cycle three packages long shows up in no pair at all, so a
component measure carries the general case.

The third exists because the package measure is an artifact of granularity as
much as of design. Collapsing a package to one node turns "config's writer
reaches agent, which reaches config's loader" into a cycle even where no module
imports itself back; measured per module, 42 of 635 modules sit in a cycle
rather than 18 of 40 packages. The two answer different questions -- whether a
package can be lifted out on its own, and whether a reader has a real knot to
walk around -- and they move independently: the refactor underneath took the
package count from 22 to 18 while moving the module count by three.

The numbers were still moving while this was written. `agent <-> permissions`
became the fourteenth mutual pair during the drafting, on a `permissions`
package that had just arrived. Nothing reported it, because nothing was
watching -- which is the case for pinning them.

`grimp` becomes an explicit dev dependency rather than staying a transitive one
through import-linter, since a test now imports it directly.

This changes no production code and unpicks no cycle. It fixes the number in
place so that the unpicking, when it happens, is not undone by the next branch.

### Both graph options are chosen, not defaulted

`exclude_type_checking_imports` is read out of `[tool.importlinter]` rather than
hardcoded, so the guard measures the same graph the contracts are checked
against. Without it, `gateway` counts as cyclic on a type-checking-only import
and the module count moves by three -- the guard would have been ratcheting a
graph no contract enforces.

`cache_dir=None` because grimp's default is a shared `.grimp_cache` that
outlives a branch switch. A guard whose job is to report the graph of the
checked-out tree must not serve one an earlier revision left behind: a stale hit
turns it red or green for reasons absent from the diff. Building fresh costs
about a second.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

Other: an architecture guard, in the shape of a budget. Closest to `test`, which
is the commit type used.

## Verification

```
$ uv run --frozen --python 3.12 pytest tests/test_import_cycle_budget.py -q
4 passed in 1.06s

$ uv run --frozen --python 3.12 pytest tests/test_import_cycle_budget.py \
    tests/test_kernel_closure.py tests/test_kernel_budget.py -q
10 passed in 1.51s

$ uv run --frozen --python 3.12 lint-imports
Contracts: 8 kept, 0 broken.

$ uv run --frozen --python 3.12 --extra dev ruff check tests/test_import_cycle_budget.py
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff format --check tests/test_import_cycle_budget.py
1 file already formatted

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

Checked in the failing direction once per ceiling, since a gate that has never
been seen red is not known to work.

Making `utils` import the subagent presets trips the two package ceilings and
leaves the module count untouched -- which is the granularity point above, seen
from the failing side:

```
AssertionError: 23 subpackages are inside an import cycle, over the ceiling of 18
AssertionError: 15 pairs of subpackages import each other, over the ceiling of 13
```

Making `utils.text` and `importer.skills.hermes` import each other is a real
module-level cycle, and trips the third:

```
AssertionError: 45 modules are inside an import cycle, over the ceiling of 42
```

Both probes were reverted; the diff carries only the guard, the ceilings and the
dependency line.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No runtime behaviour change. The guard reads the import graph and asserts three
counts; it adds about a second to the suite. All three ceilings are met on
arrival,
so nothing that exists today is blocked. Rollback is reverting the one commit.

The known limit of a count-based ratchet is the one the coverage ratchet already
carries: a change that closes one cycle and opens another leaves the totals
unmoved and passes. Naming the pairs in the failure message is what makes that
visible in review when it matters.

## Related Issues

N/A
2026-09-10 17:23:40 +00:00
gloryfromca
231a31c641 test(*): the import cycles among subpackages may not reach further
## Summary

These are aggregate ceilings on how far import cycles reach, not a proof that no
cycle was deepened: an edge added between two members of the existing component
leaves every total unmoved, and that case is left to the contracts and to review.
The module docstring says so too.

`acyclic_siblings` is the import-linter contract that would forbid import cycles
among raven's top-level subpackages outright. It is not in `pyproject.toml`
because it is BROKEN: **18 of the 40 top-level subpackages sit in a single
strongly connected component**. Added as a gate it would paint CI red on arrival
and be switched off within the week.

This states the same rule as a budget instead of an absolute. Three ceilings, set
to what the tree measures today, and they may only go down:

```
PACKAGES_IN_CYCLES_CEILING = 18
MUTUAL_PAIRS_CEILING = 13
MODULES_IN_CYCLES_CEILING = 42
```

This branch carries the vocabulary refactor (MR 610) underneath it, because the
ceilings are the numbers that hold once that lands. If 610 merges first this
becomes a single-commit change; either way the ceilings match the tree the guard
runs against.

A change that draws a package or a module into a cycle for the first time, or
makes a new pair import each other, fails here. An edge added between two
members of the existing component does not: every total stays put, and that
case is left to the contracts and to review. Unpicking one lowers a ceiling,
which is a reviewed edit to the test file rather than a drive-by -- the same
shape `tests/test_kernel_budget.py` already uses, and for the same reason its
docstring gives.

Three numbers, because each is blind where another sees. Mutual pairs (a imports
b and b imports a) are the edges people actually add, and the failure message
names them. A cycle three packages long shows up in no pair at all, so a
component measure carries the general case.

The third exists because the package measure is an artifact of granularity as
much as of design. Collapsing a package to one node turns "config's writer
reaches agent, which reaches config's loader" into a cycle even where no module
imports itself back; measured per module, 42 of 635 modules sit in a cycle
rather than 18 of 40 packages. The two answer different questions -- whether a
package can be lifted out on its own, and whether a reader has a real knot to
walk around -- and they move independently: the refactor underneath took the
package count from 22 to 18 while moving the module count by three.

The numbers were still moving while this was written. `agent <-> permissions`
became the fourteenth mutual pair during the drafting, on a `permissions`
package that had just arrived. Nothing reported it, because nothing was
watching -- which is the case for pinning them.

`grimp` becomes an explicit dev dependency rather than staying a transitive one
through import-linter, since a test now imports it directly.

This changes no production code and unpicks no cycle. It fixes the number in
place so that the unpicking, when it happens, is not undone by the next branch.

### Both graph options are chosen, not defaulted

`exclude_type_checking_imports` is read out of `[tool.importlinter]` rather than
hardcoded, so the guard measures the same graph the contracts are checked
against. Without it, `gateway` counts as cyclic on a type-checking-only import
and the module count moves by three -- the guard would have been ratcheting a
graph no contract enforces.

`cache_dir=None` because grimp's default is a shared `.grimp_cache` that
outlives a branch switch. A guard whose job is to report the graph of the
checked-out tree must not serve one an earlier revision left behind: a stale hit
turns it red or green for reasons absent from the diff. Building fresh costs
about a second.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [x] Other

Other: an architecture guard, in the shape of a budget. Closest to `test`, which
is the commit type used.

## Verification

```
$ uv run --frozen --python 3.12 pytest tests/test_import_cycle_budget.py -q
4 passed in 1.06s

$ uv run --frozen --python 3.12 pytest tests/test_import_cycle_budget.py \
    tests/test_kernel_closure.py tests/test_kernel_budget.py -q
10 passed in 1.51s

$ uv run --frozen --python 3.12 lint-imports
Contracts: 8 kept, 0 broken.

$ uv run --frozen --python 3.12 --extra dev ruff check tests/test_import_cycle_budget.py
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff format --check tests/test_import_cycle_budget.py
1 file already formatted

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

Checked in the failing direction once per ceiling, since a gate that has never
been seen red is not known to work.

Making `utils` import the subagent presets trips the two package ceilings and
leaves the module count untouched -- which is the granularity point above, seen
from the failing side:

```
AssertionError: 23 subpackages are inside an import cycle, over the ceiling of 18
AssertionError: 15 pairs of subpackages import each other, over the ceiling of 13
```

Making `utils.text` and `importer.skills.hermes` import each other is a real
module-level cycle, and trips the third:

```
AssertionError: 45 modules are inside an import cycle, over the ceiling of 42
```

Both probes were reverted; the diff carries only the guard, the ceilings and the
dependency line.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No runtime behaviour change. The guard reads the import graph and asserts three
counts; it adds about a second to the suite. All three ceilings are met on
arrival,
so nothing that exists today is blocked. Rollback is reverting the one commit.

The known limit of a count-based ratchet is the one the coverage ratchet already
carries: a change that closes one cycle and opens another leaves the totals
unmoved and passes. Naming the pairs in the failure message is what makes that
visible in review when it matters.

## Related Issues

N/A
2026-09-10 17:23:40 +00:00
0xKT
139110d9e0 refactor(config): the sub-agent name vocabulary seats below both sides
## Summary

`raven.config` and `raven.agent` imported each other. config validated sub-agent
declarations against tables living in `raven.agent.subagent`; the agent package
reads config for its shapes and paths. Both sides deferred their import into a
function body to keep module init off the cycle, which is what kept it invisible
to everything except a graph walk.

The validation needs the **vocabulary**, not the behaviour: which names are
legal, never what those names run. Only membership was ever read at the two call
sites -- `command`, `description`, `kind` and `readyTimeoutMs` were not. So the
names move down to `raven/config/agent_names.py` and the tables stay where they
are:

- **config owns what is legal** -- `BUILTIN_AGENT_NAMES`, `LEGACY_AGENT_ALIASES`,
  `THIRD_PARTY_PRESET_NAMES`, `canonical_agent_name`, `is_builtin_agent_name`.
  Pure data and pure string functions, no IO.
- **`raven.agent.subagent` owns what it does** -- the preset table with its
  commands, transports and timeouts is untouched.

`builtin_agents` re-exports the moved names, so its eight consumers (`registry`,
`rpc.methods.subagents`, `manager`, `spawn_tool`,
`context_engine.segments.identity`) are not touched at all.

### Why the check did not move up instead

Moving the validation later, rather than moving the data down, would also break
the cycle and would cost nothing in cohesion. It was rejected because the check
is deliberately at parse time. It runs as a `@model_validator(mode="after")` on
all three sub-agent transports, on both paths that build a model from a dict
(`load_config` reading the file, and `update_subagents` validating before an
atomic write). Its own docstring names what it catches: a hand-edited
`preset: "hermes"` on an unrelated entry, which would otherwise both dodge the
reserved-name guard and hide the real Hermes preset from the Presets group.
An invalid row would become constructible, and every later reader would treat it
as valid.

### The cost, and the pin

The split spells one name set in two places. A preset added to
`THIRD_PARTY_SUBAGENT_PRESETS` without its key added to the vocabulary would ship
and then be refused by the schema meant to accept it, with nothing reporting the
mismatch. `tests/test_subagent_name_vocabulary.py` pins both sets equal in both
directions, and does the same for the seed table against the reserved names.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [x] Refactor
- [ ] Other

## Verification

```
$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ uv run --frozen --python 3.12 pytest \
    tests/test_subagent_name_vocabulary.py tests/test_subagent_builtin_agents.py \
    tests/test_update_subagents.py tests/test_subagent_registry.py \
    tests/test_subagent_acp.py tests/test_rpc_subagents.py tests/test_kernel_closure.py -q
350 passed in 13.91s

$ uv run --frozen --python 3.12 --extra dev ruff check <the five changed files>
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff format --check <the five changed files>
5 files already formatted

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

Both the contract run and the test run above were repeated after rebasing onto
the current main, since this one touches production code.

Every call site of every moved symbol was enumerated before the edit
(`BUILTIN_AGENT_NAMES`, `canonical_agent_name`, `is_builtin_agent_name`,
`GENERIC_AGENT`, `LEGACY_AGENT_ALIASES`, `THIRD_PARTY_SUBAGENT_PRESETS`) and the
re-export is what keeps them all valid.

Effect on the dependency graph, measured before and after:

```
config -> agent edges          2  ->  0
packages in an import cycle   22  ->  19   (out of 40)
mutually importing pairs      14  ->  13
```

The three packages that leave the cycle were only ever pulled in through this
one pair.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No behaviour change: the same names, the same validation, the same failure
messages. The reserved-name guard and the preset provenance check both still run
at parse time on all three transports. Backward compatibility is why
`builtin_agents` re-exports rather than relocating its public surface, and why
`LEGACY_AGENT_ALIASES` moves intact -- stored records under the old lowercase
name still resolve.

Rollback is reverting the one commit. The risk this leaves behind is the
two-spellings drift, which is why the equality pin ships in the same commit
rather than as a follow-up.

## Related Issues

N/A
2026-09-10 16:19:11 +00:00
gloryfromca
aa026fd566 refactor(config): the sub-agent name vocabulary seats below both sides
## Summary

`raven.config` and `raven.agent` imported each other. config validated sub-agent
declarations against tables living in `raven.agent.subagent`; the agent package
reads config for its shapes and paths. Both sides deferred their import into a
function body to keep module init off the cycle, which is what kept it invisible
to everything except a graph walk.

The validation needs the **vocabulary**, not the behaviour: which names are
legal, never what those names run. Only membership was ever read at the two call
sites -- `command`, `description`, `kind` and `readyTimeoutMs` were not. So the
names move down to `raven/config/agent_names.py` and the tables stay where they
are:

- **config owns what is legal** -- `BUILTIN_AGENT_NAMES`, `LEGACY_AGENT_ALIASES`,
  `THIRD_PARTY_PRESET_NAMES`, `canonical_agent_name`, `is_builtin_agent_name`.
  Pure data and pure string functions, no IO.
- **`raven.agent.subagent` owns what it does** -- the preset table with its
  commands, transports and timeouts is untouched.

`builtin_agents` re-exports the moved names, so its eight consumers (`registry`,
`rpc.methods.subagents`, `manager`, `spawn_tool`,
`context_engine.segments.identity`) are not touched at all.

### Why the check did not move up instead

Moving the validation later, rather than moving the data down, would also break
the cycle and would cost nothing in cohesion. It was rejected because the check
is deliberately at parse time. It runs as a `@model_validator(mode="after")` on
all three sub-agent transports, on both paths that build a model from a dict
(`load_config` reading the file, and `update_subagents` validating before an
atomic write). Its own docstring names what it catches: a hand-edited
`preset: "hermes"` on an unrelated entry, which would otherwise both dodge the
reserved-name guard and hide the real Hermes preset from the Presets group.
An invalid row would become constructible, and every later reader would treat it
as valid.

### The cost, and the pin

The split spells one name set in two places. A preset added to
`THIRD_PARTY_SUBAGENT_PRESETS` without its key added to the vocabulary would ship
and then be refused by the schema meant to accept it, with nothing reporting the
mismatch. `tests/test_subagent_name_vocabulary.py` pins both sets equal in both
directions, and does the same for the seed table against the reserved names.

## Type

- [ ] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [x] Refactor
- [ ] Other

## Verification

```
$ uv run --frozen --python 3.12 lint-imports
Contracts: 9 kept, 0 broken.

$ uv run --frozen --python 3.12 pytest \
    tests/test_subagent_name_vocabulary.py tests/test_subagent_builtin_agents.py \
    tests/test_update_subagents.py tests/test_subagent_registry.py \
    tests/test_subagent_acp.py tests/test_rpc_subagents.py tests/test_kernel_closure.py -q
350 passed in 13.91s

$ uv run --frozen --python 3.12 --extra dev ruff check <the five changed files>
All checks passed!

$ uv run --frozen --python 3.12 --extra dev ruff format --check <the five changed files>
5 files already formatted

$ make check-commits COMMIT_RANGE=origin/main..HEAD
exit 0
```

Both the contract run and the test run above were repeated after rebasing onto
the current main, since this one touches production code.

Every call site of every moved symbol was enumerated before the edit
(`BUILTIN_AGENT_NAMES`, `canonical_agent_name`, `is_builtin_agent_name`,
`GENERIC_AGENT`, `LEGACY_AGENT_ALIASES`, `THIRD_PARTY_SUBAGENT_PRESETS`) and the
re-export is what keeps them all valid.

Effect on the dependency graph, measured before and after:

```
config -> agent edges          2  ->  0
packages in an import cycle   22  ->  19   (out of 40)
mutually importing pairs      14  ->  13
```

The three packages that leave the cycle were only ever pulled in through this
one pair.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

No user-facing surface changes.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

No behaviour change: the same names, the same validation, the same failure
messages. The reserved-name guard and the preset provenance check both still run
at parse time on all three transports. Backward compatibility is why
`builtin_agents` re-exports rather than relocating its public surface, and why
`LEGACY_AGENT_ALIASES` moves intact -- stored records under the old lowercase
name still resolve.

Rollback is reverting the one commit. The risk this leaves behind is the
two-spellings drift, which is why the equality pin ships in the same commit
rather than as a follow-up.

## Related Issues

N/A
2026-09-10 16:19:10 +00:00
TongLi31
2eb13a22a2 feat(agents): migrate raven-code tools and coding guidance
## Summary

Raven-Code gains a product-owned coding tool set and engineering guidance. The code-flow plugin supplies read_file, write_file, edit_file, list_dir, glob, todo, and exec through the host's existing plugin interfaces. It adds long-line read limits, explicit non-overlapping occurrence edits, Python syntax feedback, brace globbing with visible partial/error results, persistent checklists, and execution timeout/output reporting. All implementation changes are under agents/raven-code; raven/, other agent implementations, and both UIs have no diff.

Read-before-edit checks use records isolated by Raven-Code runtime and conversation. A successful read or full write establishes a record; appending to unseen or stale existing content does not grant editing permission. Fresh ACP sessions have distinct keys and separate records/checklists. Resuming an existing session restores its plan, and session deletion clears its product state. Tool binding covers user and subagent turns, including runs with flow guidance disabled.

Repository AGENTS.md, CLAUDE.md, and CONTEXT.md enter system context through Raven-Code's existing before_iteration hook. User queries, persisted transcripts, and /new and /help command handling stay intact. Each candidate is resolved and read only if it remains inside the resolved working directory, including absolute names, parent traversal, and symlink targets. Contained aliases are read once. The hook preserves the host system prefix, replaces its own addition on repeated iterations, and sizes it against the remaining prompt allowance with tools, pending checklist restoration, and the active model's reply ceiling counted. Truncation is explicit. The product uses existing hook and observer interfaces; no shared runtime extension or new command interception is added. The launcher seeds model-specific coding conduct, independently switchable engineering discipline, the product identity, and tool guidance. Untouched managed prompt copies refresh across upgrades while operator edits are preserved. Workspace and execution settings follow host configuration, including when rendering an already rendered configuration. One-shot CLI hosting defaults permissions to full because it cannot answer approval prompts; explicit permission configuration wins, and ACP hosting keeps the host default.

Completion verification gates and the code-verifier plugin are outside this change.

## Type

- [ ] Fix
- [x] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [x] User-facing docs or screenshots are updated when needed

- `uv run --frozen --python 3.12 --extra dev pytest tests/test_agents_code*.py tests/test_agent_hook*.py tests/test_context_engine_factory.py tests/test_kernel_budget.py tests/test_agents_research_tools.py tests/test_contracts_two_tier_ledger.py tests/test_l4_entrances.py tests/test_core_runtime_swap.py tests/test_acp_methods.py tests/test_context_scent.py tests/test_skill_hub_policy.py -q --tb=short`: 723 passed after rebasing onto current main. Coverage includes real ACP session creation and product-state isolation, real AgentLoop command dispatch and model-visible message roles, repository containment, user/subagent and concurrent-session binding, append behavior, permission propagation, tool schemas, prompt migration, and runtime contracts. Ordinary text mentioning /new reaches the provider; only the host's exact command form takes its existing command branch. Hook tests cover repeated/deep-copied contexts, token limits, host-prefix preservation, and checklist failure isolation.
- `make lint-python`: passed, including Ruff formatting across 1,899 Python files.
- `uv run --frozen --python 3.12 lint-imports`: 9 contracts kept, 0 broken.
- `make check-large-files check-source-language`, `git diff --check origin/main...HEAD`, and `uv run --frozen --python 3.12 python scripts/check_commit_messages.py origin/main..HEAD`: passed.
- The title and description pass the repository's canonical PR checkers. No frontend sources, generated RPC artifacts, or dependency lockfiles changed. Rebase comparison preserves all eight commits; the only file touched by both the feature and intervening main changes is CONTEXT.md, in separate domain entries. Tests for main's updated skill policy are included above.

Earlier full-suite validation, before the final read-state, repository-instruction, and hook changes, used `uv run --frozen --python 3.12 --extra dev pytest -q --tb=short`. Clean main reported 20,241 passed, 6 failed, 20 errors, and 212 skipped. The candidate reported 20,392 passed, 7 failed, 20 errors, and 212 skipped on each of two runs. Both checkouts used Python 3.12.13 and identical versions of all 212 installed distributions. The 6 cron failures and 20 cron errors had identical test IDs. The additional failure differed between candidate runs:

- `test_a_thin_dataset_card_falls_back_to_the_metadata_the_table_needs`: an intermittent `KeyError: served_url` in unchanged research tooling. The module passed all 82 tests separately on both checkouts and in the final targeted run. A controlled main-only DNS response reproduces the symptom; the original failure's cause remains unconfirmed.
- `test_doctor_answers_where_the_memories_are`: the temporary-directory path caused terminal wrapping inside `mem-root`, breaking the unchanged assertion. The original test reproduces on main with a 30-character `--basetemp`; shorter paths pass on both checkouts.

The full suite was not rerun after the final read-state, repository-instruction, and hook changes, and is not claimed green. Validation ran on Linux; no macOS/Windows execution, live-model run, or prompt-cache cost measurement was performed.

## Risk

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

The workspace fence remains opt-in and uses the host's path enforcement. Read-before-edit is session-local editing discipline, not a file lock or an atomic concurrency guarantee. Runtime restart requires a fresh read. Full overwrite retains its existing behavior; reading before overwrite remains model guidance rather than a new hard restriction. The exec replacement is offered only when the configured sandbox backend is none; otherwise the host's exec remains active.

Automatic repository-instruction loading always enforces containment, independently of the optional file-tool workspace fence. Injection runs after host history selection and does not evict transcript messages to make room. If even the truncation/concurrency notice cannot fit beside the reply allowance, the turn reports insufficient context instead of making a model call. The added repository text is not promoted into the host's stable cache prefix. New tasks use new session IDs. The host's in-place /new command retains its session key and clears the transcript without clearing separate Raven-Code todo/read state. This existing command behavior is preserved; the product does not add refusal messages or a reset callback. Resuming a session intentionally retains its plan, and deleting it removes its saved plan. Large exec output is retained under the agent home's exec-output directory without a new TTL or count cap; files can be removed manually. Operator-edited prompt copies may require manual updates.

Set plugins.config.code-flow.tools.enabled to false to restore the host tool set. CODE_PROJECT_FILES=off disables repository instruction loading; CODE_CONDUCT=off and CODE_CONDUCT_DISCIPLINE=off control guidance independently. Reverting the change restores the previous product behavior.

## Related Issues

N/A
2026-09-10 12:42:53 +00:00