Skip to content

refactor(codemode): name the data boundary and prepare tools once - #48021

Open
rekram1-node wants to merge 1 commit into
v2from
codemode-boundary
Open

refactor(codemode): name the data boundary and prepare tools once#48021
rekram1-node wants to merge 1 commit into
v2from
codemode-boundary

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

Second cleanup pass, following #48009. Behavior-preserving; the existing copyOut parity tests (toStrictEqual) now pin the new functions.

One data boundary module

copyIn(value, label, preserveCodeModeValues) + copyOut(value, mode) did three different jobs behind a boolean and a two-pass pipeline. They're replaced by a new dependency-free data.ts with one walker and three named directions:

Function Direction Replaces
toProgram(value, label) host runtime result → program (keeps Values.*, wraps host Date/Map/…) boundedData / copyIn(…, true)
fromData(value, label) host data → program (Date/URL → strings, null-prototype copies) copyIn(…, false) on tool output and JSON.parse
toData(value, label, undefinedAs?) program → host JSON in one walk copyOut(copyIn(…), "json" | "nullify")

Tool arguments and the execution result now traverse once instead of twice. SafeObject, isBlockedMember, and ToolRuntimeError move to data.ts too, so the stdlib and openapi/spec.ts no longer import the tool runtime (Effect Schema, search, hooks) for a three-line blocked-name check.

JSON.stringify is restructured so each branch does exactly one copy instead of a discarded validation pass plus a real one.

Tools prepared once

ToolRuntime.prepare(tools) now returns { root, catalog, searchIndex } and ToolRuntime.make consumes it. Previously the trie was rebuilt on every execution (and twice per one-shot CodeMode.execute). Removed: searchIndex(), DiscoveryPlan, the dead ToolRuntime.root field.

codemode.ts

  • Options is the base type; ExecuteOptions = Options & { code } (was inverted via Omit).
  • Options extends ToolCallHooks instead of redeclaring both hooks.
  • execute = make(options).execute(options.code).
  • executeProgram(code, prepared, limits, hooks) is generic in R and no longer takes the public options bag, removing the reverse codemode.ts → execute.ts type coupling.

Net −44 lines.

Test plan

  • bun typecheck (with noUnusedLocals)
  • bun test — 1141 pass
  • packages/core has no references to removed exports

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