Skip to content

refactor(runtime): extract computer-use wire codec and contract types… - #1507

Merged
Astro-Han merged 1 commit into
apache:mainfrom
chinawch007:refactor/computer-use-codec-extract
Jul 28, 2026
Merged

Astro-Han merged 1 commit into
apache:mainfrom
chinawch007:refactor/computer-use-codec-extract

Conversation

@chinawch007

Copy link
Copy Markdown
Contributor

Summary

Splits packages/runtime/src/computer-use-tools.ts (1836 lines) into three focused files per #1405, keeping the @maka/runtime public surface stable via re-exports. Behavior-neutral — the moved code is byte-identical, only its location changes.

computer-use-types.ts (new, ~180 lines) — pure contract types (zero runtime deps), consumed by adapters without dragging in the tool assembly:

  • CuScreenshot, CuDispatchEvidence, CuDispatchOutcome, CuRunResult, CuAppSummary, CuObservedElement, CuObservation, CuSemanticAction, CuRunContext, CuDispatchBackend
  • CuPresentationFence, CuOverlayHookContext, CuOverlayHook (overlay hooks)

computer-use-codec.ts (new, ~320 lines) — wire-protocol codec (mirrors the established openai-computer-codec.ts pattern):

  • computerParams zod discriminated union (+ shared coordinate/text helpers)
  • snapshotComputerParams, adaptToCuAction
  • summarize + summarizeEvidence (moved together since they're tightly coupled)

computer-use-tools.ts (retained, 1836 → ~1300 lines) — buildComputerUseTools and its assembly logic stay here.

Implementation notes

  • computerParams, summarize, and summarizeEvidence were previously module-private; they become exports on the codec so buildComputerUseTools can import them back. summarizeEvidence is also called directly inside buildComputerUseTools (not just via summarize), so it must be exported.
  • The shared coordinate/text zod helpers move with computerParams to the codec; computerWireParams (stays in tools, used at the tool schema level) imports them back — one-way, no cycle.
  • A local variable in summarize was renamed (point → pointStr) to avoid a shadowing clash with the point helper that moved into the same file.
  • computer-use-tools.ts re-exports the moved types and codec functions, so index.ts, openai-computer-loop.ts, and test files keep their import paths unchanged.
  • Cleaned up dead imports left over from the move (4 unused @maka/core types + 3 re-exported-only types + CU_ACTION_TYPES in the codec).

Dependency direction is acyclic: computer-use-types.ts (leaf) ← computer-use-codec.ts ← computer-use-tools.ts.

Verification

  • npm --workspace @maka/runtime run typecheck — clean
  • npm --workspace @maka/runtime run build — clean
  • npm --workspace @maka/runtime run test — 2554 tests, 2547 pass, 0 fail, 7 skipped
  • npm run lint — clean (biome, 2087 files)
  • npm run format:check — clean (biome, 1049 files)
  • git diff origin/main...HEAD --check — no whitespace errors

Review focus

  • The move is mechanical (byte-identical code, no logic changes) — the only non-trivial decisions are the visibility/export adjustments noted above.
  • Confirm the re-export block in computer-use-tools.ts covers all symbols that downstream consumers (index.ts, openai-computer-loop.ts, tests) previously imported from it.
  • The point → pointStr rename in summarize is purely cosmetic (avoids shadowing); the function's input/output is unchanged.

@Astro-Han

Copy link
Copy Markdown
Contributor

Reviewed at 5d2030ddcab6cbc04500a892f1901bc9c01def45.

This branch now conflicts with main after #1555. Please rebase it; maintainers will not resolve the contributor branch conflict. While resolving CuObservedElement, keep #1555 fields enabled, selected, and parentElementId in computer-use-types.ts, and keep their model-text output in computer-use-tools.ts.

P3: The new type owner is not used at the adapter and public export seams.

openai-computer-loop.ts still imports CuDispatchOutcome and CuRunResult from computer-use-tools.ts, and index.ts still re-exports the contract types through that implementation module. This leaves the stated adapter-decoupling goal unfinished. Please route those type-only imports and exports directly through computer-use-types.ts, while retaining the compatibility re-export from computer-use-tools.ts.

The codec and type move itself is behavior-equivalent; differential probes found no parsing, adaptation, summary, export, or dependency-cycle regression.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved at 5d2030dd. The remaining P3 does not block the behavior-equivalent extraction. The branch still needs an author rebase after #1555.

@chinawch007
chinawch007 force-pushed the refactor/computer-use-codec-extract branch from 5d2030d to 0cd84fc Compare July 28, 2026 15:36
@chinawch007

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I learned a lot from your feedback.

Rebased onto latest main and resolved the CuObservedElement conflict — the #1555 fields (enabled, selected, parentElementId) are in computer-use-types.ts, and their model-text output in observationText is preserved.

Also addressed P3: openai-computer-loop.ts now imports CuDispatchOutcome/CuRunResult directly from computer-use-types.ts, and index.ts re-exports the Cu* contract types from computer-use-types.ts (keeping ComputerUseToolSet from computer-use-tools.ts since it's not a pure contract type). The compatibility re-export from computer-use-tools.ts is retained.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked 0cd84fcd. The range-diff from 5d2030dd contains the requested direct type imports and exports, plus the three fields added by #1555. No findings.

@Astro-Han
Astro-Han merged commit 8d5cd40 into apache:main Jul 28, 2026
3 checks passed
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.

2 participants