Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Mar 27, 2025

Context

I realized that automatically generating the types we need for our external declaration file cleans up a bunch of stuff, including:

  • ~750 lines of duplicative TypeScript boilerplate
  • A bunch of type-fu assertions to ensure that zod schemas perfectly match existing types (as opposed to inferring the types from the schema)

Given that, I decided to derive and generate the roo-code.d.ts types from our extension code instead of the other way around. This lets us actually infer types from zod schemas (when it's appropriate).

Here's how it works:

  • If you need to expose a type in roo-code.d.ts then you simply add a TypeDefinition entry to schemas/index.ts.
  • When you commit your changes a script will run to generate clean types in exports/types.ts.
  • Types from exports/types.ts can be safely imported by roo-code.ts.
  • After the types are generated the .d.ts file is automatically transpiled by tsup (this always should have been automatically generated with tsc or some other build tool).

There are no logic changes in this PR; it's all typing and build tooling.

Implementation

Screenshots

before after

How to Test

Get in Touch


Important

Automates generation of roo-code.d.ts from Zod schemas, streamlining type management and reducing boilerplate.

  • Type Generation:
    • Introduces automated generation of roo-code.d.ts using zod-to-ts.
    • Adds generate-types.mts script to generate types from Zod schemas in schemas/index.ts.
    • Updates package.json with generate-types script.
  • Schema and Type Management:
    • Moves type definitions to schemas/index.ts and updates imports across multiple files.
    • Removes redundant type definitions from globalState.ts and other files.
    • Updates schemas/__tests__/index.test.ts to test GLOBAL_STATE_KEYS.
  • Pre-commit Hook:
    • Adds pre-commit hook in .husky/pre-commit to ensure roo-code.d.ts is up-to-date.
  • Miscellaneous:
    • Increases timeout in waitFor function in utils.ts from 30,000 to 60,000.

This description was created by Ellipsis for 47f1e60. It will automatically update as commits are pushed.

@changeset-bot
Copy link

changeset-bot bot commented Mar 27, 2025

🦋 Changeset detected

Latest commit: 47f1e60

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
roo-cline Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Mar 27, 2025
@ellipsis-dev
Copy link
Contributor

ellipsis-dev bot commented Mar 27, 2025

The pull request is quite large, with 30 files changed, 2173 lines added, and 1231 lines removed. It includes various changes such as adding new scripts for type generation, updating pre-commit hooks, refactoring import paths, and adding new type definitions using zod.

To improve the review process, it might be beneficial to split this pull request into smaller, more focused ones. Here are some suggestions on how to split the changes:

  1. Type Generation and Scripts: Separate the changes related to the new type generation script (scripts/generate-types.mts) and the associated updates in package.json and .husky/pre-commit.

  2. Refactoring Imports: Group all the changes related to refactoring import paths across different files. This includes updates in files like src/core/config/ContextProxy.ts, src/core/config/ProviderSettingsManager.ts, and others.

  3. Schema and Type Definitions: Isolate the changes related to the new type definitions and schema updates using zod, such as those in src/schemas/index.ts and src/exports/types.ts.

By splitting the pull request into these categories, it will be easier to review and ensure that each set of changes is thoroughly examined. Please consider this suggestion if the changes are not tightly interdependent.

@cte cte changed the base branch from main to cte/generate-types-tooling March 27, 2025 08:25
@cte cte changed the base branch from cte/generate-types-tooling to main March 27, 2025 08:25
cte and others added 4 commits March 27, 2025 01:28
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@cte cte changed the title Automatically generate types for roo-code.d.ts using zod-to-ts Automatically generate roo-code.d.ts (including type generation via zod-to-ts) Mar 27, 2025
@cte cte changed the title Automatically generate roo-code.d.ts (including type generation via zod-to-ts) Automatically generate roo-code.d.ts (including type generation via zod-to-ts) Mar 27, 2025
cte and others added 2 commits March 27, 2025 02:42
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@samhvw8
Copy link
Contributor

samhvw8 commented Mar 27, 2025

cool

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 27, 2025
@cte cte merged commit 0fd399d into main Mar 27, 2025
12 checks passed
@cte cte deleted the cte/generate-types branch March 27, 2025 16:38
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants