Skip to content

feat(agent): add addTrims and addZooms, so a cut stops costing a round trip - #258

Merged
EtienneLescot merged 2 commits into
mainfrom
feat/agent-batch-edit-tools
Aug 5, 2026
Merged

feat(agent): add addTrims and addZooms, so a cut stops costing a round trip#258
EtienneLescot merged 2 commits into
mainfrom
feat/agent-batch-edit-tools

Conversation

@EtienneLescot

@EtienneLescot EtienneLescot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the main recommendation of #217. The measured cost of an auto-enhance turn is not its context, it is its shape: 19 tool calls in series — six addTrim and nine addZoom one at a time — each a full round trip. deep-agent/service.ts says so where it raises recursionLimit: one step per silence. On a half-hour recording that is hundreds of round trips for a decision the model made in one breath.

Two batch tools, addTrims(ranges[]) and addZooms(regions[]). The unitary tools stay.

A batch is N unitary calls, minus N−1 round trips. The element schema is the unitary schema (z.array(addTrimArgs)), and the executor replays the unitary tool per item, folding the document forward. Clip resolution, anchoring, clamping, the wording of every refusal — identical by construction, not by a second implementation staying in step. A test builds the same document both ways and compares.

Partial application, deliberately. replaceTimeline is the repo's other array-taking tool and refuses in one block — right for rebuilding a timeline, ruinous for adding ten independent cuts. Here each item stands alone: the result leads with requested / appliedCount / refusedCount, and refused names the index and the unitary reason, so a partial outcome is readable without re-reading the document. ok:false is reserved for the case where nothing landed — the only one where the document did not move, and the only one where chat-service's applied-calls list may legitimately stay empty.

No cap on the array, for the reason getTranscript just taught us in #256: a number guessed here would be the next thing to cut a recording in half in silence.

Two invariants that had to be found rather than assumed

diffMatches (workbench/lib/oracles.ts) reads an id at the top level of a tool result. A batch puts its ids inside applied[], so the only check that catches a tool lying about its own writes would have returned vacuously true — silently, on the calls that write the most. #217 named this risk; it is real. It now verifies every entry, and removing that branch turns the new oracle test red.

Overlapping zooms in one batch stay overlapping, because two sequential addZoom calls already do: no add* path clamps against neighbours, in the agent or in the UI (useTimeline appends too). Deconflicting inside the batch would make the outcome depend on how the model chose to group its calls, and would give addZooms rules its unitary sibling does not have. Pinned by a test so it stays a decision rather than an accident. The bench still flags the overlap through editorial.ts zoomIssues, which is where that argument belongs.

Related issue

Refs #217 — §1 bis, "RECOMMANDATION PRINCIPALE".

Type of change

  • Feature

Release impact

  • Minor

Desktop impact

  • Not platform-specific

Testing

  • npm test: 137 files, 1632 passed.
  • npm run wb:l0: 214 passed, 44 pre-existing failures (the unversioned real fixture, unrelated).
  • tsc --noEmit, tsc -p tsconfig.test.json, wb:typecheck, biome, docs:check all clean.

New cases: batch/unitary equivalence for trims; partial application naming the refused index and reason; a whole-batch refusal reported as an error with Nothing was modified; addZooms refusing only the region that covers no clip while the others land with their renderedScale; the overlap decision; and the diffMatches batch branch, verified to fail without the fix.

Three inventories that pin the tool surface failed loudly and were updated — MUTATING_TOOL_NAMES, OPENSCREEN_TOOLS, and the two tool-count assertions (19 → 21). MUTATING_TOOL_NAMES carrying both names is what puts them behind the "project edits disabled" wall; the existing loop over that table, named "no write escapes by being added later", covers them without a new test.

Not done here

#217 also asks for a bench scenario that decides whether the model can use a batch tool correctly before generalizing — a batch is harder to call than a unitary tool, it needs a well-formed array first time. That needs a live paid run against the unversioned real take, so it is not in this PR. Nothing is generalized in the meantime: both unitary tools remain, and the system prompt points at the batch without forbidding the single call.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added batch trim and zoom actions for creating multiple edits in one request.
    • Batch operations report applied and refused entries, allowing partial success.
    • Requests are rejected when no entries can be applied.
    • Improved handling of overlapping zoom regions and rendered zoom scales.
    • Enhanced validation of results from multi-item editing requests.
  • Documentation

    • Updated AI agent documentation and guidance with the new batch editing tools and result reporting.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The agent now supports batch trim and zoom tools. Each entry executes independently, valid entries apply, refused entries report indexed errors, and fully refused batches fail without a document. Agent prompts, documentation, tool counts, and workbench validation were updated.

Changes

Batch editing tools

Layer / File(s) Summary
Batch execution and result reporting
electron/ai-edition/agent-tools.ts, electron/ai-edition/agent-tools.test.ts
Added batch schemas, tool registration, sequential execution, partial-success reporting, all-refused failure handling, and coverage for trims and zooms.
Agent tool surface and guidance
electron/ai-edition/deep-agent/service.ts, electron/ai-edition/deep-agent/service.test.ts, technical-documentation/architecture/ai-agent.md
Registered the two tools, updated prompts and tool descriptions, and changed the documented and tested tool counts.
Batch response validation
workbench/lib/oracles.ts, workbench/l0/oracles.wb.ts
Updated diffMatches to validate each object in batch applied results and added matching oracle coverage.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant BatchExecutor
  participant UnitaryExecutor
  participant Document
  Agent->>BatchExecutor: submit batch trim or zoom items
  BatchExecutor->>UnitaryExecutor: execute items sequentially
  UnitaryExecutor->>Document: apply valid item
  BatchExecutor-->>Agent: return applied and refused results
Loading

Possibly related PRs

  • getopenscreen/openscreen#217: Both changes modify batch zoom behavior and validation, including overlapping zoom handling in zoomPlacement.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of the addTrims and addZooms batch tools and their round-trip reduction benefit.
Description check ✅ Passed The description completes the required sections with scope, issue reference, change type, release impact, platform impact, and detailed testing information.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/agent-batch-edit-tools

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@electron/ai-edition/agent-tools.ts`:
- Around line 364-366: The batch schemas addTrimsArgs and addZoomsArgs must
validate only their container shape, not individual elements; update
electron/ai-edition/agent-tools.ts:364-366 and 431-433 accordingly. In
ExecuteAgentTool at electron/ai-edition/agent-tools.ts:1032-1036 and 1273-1277,
validate only the batch container and let applyBatch pass raw items to the
unitary executor so each invalid sibling is reported at its refused[index].
Preserve and update the related expectations in
electron/ai-edition/agent-tools.test.ts:263-336.

In `@electron/ai-edition/deep-agent/service.test.ts`:
- Line 405: Update the test around the buildTools expectation so it reflects
that edits-disabled mode returns 21 tools, not 20. Change the test title and its
assertion consistently, while preserving the existing tool-building behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: baa3a0a3-839e-47ca-86ef-b931f98644f1

📥 Commits

Reviewing files that changed from the base of the PR and between 1749d84 and b4e4149.

📒 Files selected for processing (7)
  • electron/ai-edition/agent-tools.test.ts
  • electron/ai-edition/agent-tools.ts
  • electron/ai-edition/deep-agent/service.test.ts
  • electron/ai-edition/deep-agent/service.ts
  • technical-documentation/architecture/ai-agent.md
  • workbench/l0/oracles.wb.ts
  • workbench/lib/oracles.ts

Comment thread electron/ai-edition/agent-tools.ts
Comment thread electron/ai-edition/deep-agent/service.test.ts Outdated
…d trip

The measured cost of an auto-enhance turn is not its context, it is its shape:
19 tool calls in series, six addTrim and nine addZoom one at a time, each a full
round trip to the provider. `deep-agent/service.ts` says as much where it raises
`recursionLimit` — "one step per silence". On a half-hour recording that is
hundreds of round trips for a decision the model made in one breath.

Two batch tools, and nothing else changes:

- The element schema IS the unitary schema (`z.array(addTrimArgs)`), and the
  executor REPLAYS the unitary tool per item, folding the document forward. Clip
  resolution, anchoring, clamping, the wording of every refusal — identical by
  construction rather than by a second implementation staying in step. A batch of
  N is exactly N unitary calls minus N-1 round trips, and a test asserts that
  against a document built the long way.
- Partial application, deliberately. `replaceTimeline` is the repo's other
  array-taking tool and refuses in one block; that is right for rebuilding a
  timeline and ruinous for adding ten independent cuts. Each item stands alone,
  the result leads with requested / appliedCount / refusedCount, and `refused`
  names the index and the unitary reason. `ok:false` is kept for the one case
  where nothing landed — the only one where the document did not move, and the
  only one where chat-service's applied-calls list may legitimately stay empty.
- No cap on the array, for the reason `getTranscript` just taught us: a number
  guessed here would be the next thing to cut a recording in half in silence.

The unitary tools stay. A one-off correction should not need a one-element array,
and `setTrim` — the tool for "move that trim" — was never in scope for a batch.

Two invariants that had to be found rather than assumed:

- `diffMatches` reads an id at the TOP level of the tool result, so a batch would
  have made the only check that catches a tool lying about its own writes return
  vacuously true — silently, on the calls that write the most. It now verifies
  every entry of `applied`. Removing that branch turns the new oracle test red.
- Overlapping zooms in one batch stay overlapping, because two `addZoom` calls
  already do: no `add*` path clamps against neighbours, in the agent or the UI.
  Deconflicting inside the batch would make the result depend on how the model
  chose to group its calls. Pinned by a test so it stays a decision.

`MUTATING_TOOL_NAMES` carries both names, which is what puts them behind the
"project edits disabled" wall — the existing loop over that table ("no write
escapes by being added later") covers them without a new test.
`addTrims`/`addZooms` promise the model that each entry stands or falls by
itself, and `applyBatch` is written for exactly that. The batch schemas were
not: `z.array(addTrimArgs)` rejected the whole call the moment one entry was
malformed, so nine good cuts died with the tenth and `refused[index]` could
never name the culprit. Worse, LangChain parses the tool schema BEFORE calling
us, so on the product path the call never reached `applyBatch` at all — it
threw "Received tool input did not match expected schema".

The element schema is now advertised rather than enforced, as a union with
`unknown`. The model still reads the full shape in the tool's JSON schema
(`anyOf: [addTrim, {}]`), a bad entry reaches the unitary executor, and that
executor refuses it with the wording it always uses. The container is still
validated: a missing, empty or non-array `ranges` is refused as a whole.

Also corrects two stale tool counts left at 20/19 by the previous commit.

Both CodeRabbit findings on #258.
@EtienneLescot
EtienneLescot force-pushed the feat/agent-batch-edit-tools branch from 7436cff to ad8a43d Compare August 5, 2026 09:50
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
electron/ai-edition/deep-agent/service.test.ts (1)

295-311: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add service-boundary coverage for malformed addZooms regions.

services.test.ts only covers malformed addTrims through tool.invoke; agent-tools.test.ts has direct executor coverage for malformed addZooms regions. Add an equivalent addZooms service-boundary test so the schema forwarding behavior is covered for both batch tools.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@electron/ai-edition/deep-agent/service.test.ts` around lines 295 - 311, Add a
service-boundary test in the same suite as the existing malformed addTrims
tool.invoke test, targeting the addZooms tool with one valid region and one
malformed region. Assert the malformed entry reaches the executor, producing one
applied result and a refused entry at index 1, while preserving the document’s
expected zoom state.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@electron/ai-edition/deep-agent/service.test.ts`:
- Around line 295-311: Add a service-boundary test in the same suite as the
existing malformed addTrims tool.invoke test, targeting the addZooms tool with
one valid region and one malformed region. Assert the malformed entry reaches
the executor, producing one applied result and a refused entry at index 1, while
preserving the document’s expected zoom state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ca0bba4-5a3b-4085-9200-4d78fb64c878

📥 Commits

Reviewing files that changed from the base of the PR and between 20bd56e and ad8a43d.

📒 Files selected for processing (7)
  • electron/ai-edition/agent-tools.test.ts
  • electron/ai-edition/agent-tools.ts
  • electron/ai-edition/deep-agent/service.test.ts
  • electron/ai-edition/deep-agent/service.ts
  • technical-documentation/architecture/ai-agent.md
  • workbench/l0/oracles.wb.ts
  • workbench/lib/oracles.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • technical-documentation/architecture/ai-agent.md
  • workbench/l0/oracles.wb.ts
  • workbench/lib/oracles.ts
  • electron/ai-edition/deep-agent/service.ts
  • electron/ai-edition/agent-tools.test.ts
  • electron/ai-edition/agent-tools.ts

@EtienneLescot
EtienneLescot merged commit 9bcfeee into main Aug 5, 2026
17 checks passed
EtienneLescot added a commit that referenced this pull request Aug 5, 2026
`addTrims`/`addZooms` promise the model that each entry stands or falls by
itself, and `applyBatch` is written for exactly that. The batch schemas were
not: `z.array(addTrimArgs)` rejected the whole call the moment one entry was
malformed, so nine good cuts died with the tenth and `refused[index]` could
never name the culprit. Worse, LangChain parses the tool schema BEFORE calling
us, so on the product path the call never reached `applyBatch` at all — it
threw "Received tool input did not match expected schema".

The element schema is now advertised rather than enforced, as a union with
`unknown`. The model still reads the full shape in the tool's JSON schema
(`anyOf: [addTrim, {}]`), a bad entry reaches the unitary executor, and that
executor refuses it with the wording it always uses. The container is still
validated: a missing, empty or non-array `ranges` is refused as a whole.

Also corrects two stale tool counts left at 20/19 by the previous commit.

Both CodeRabbit findings on #258.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant