Skip to content

Conversation

@Paribesh01
Copy link
Contributor

@Paribesh01 Paribesh01 commented Sep 1, 2025

close #2759


Important

Adds a new typecheck tool to ensure type safety, integrating it into the toolset and handlers.

  • New Tool Addition:
    • Adds TYPECHECK_TOOL_NAME and TYPECHECK_TOOL_PARAMETERS in cli.ts.
    • Implements typecheckTool in cli.ts with a description and empty input schema.
  • Tool Integration:
    • Adds typecheckTool to BUILD_TOOL_SET in toolset.ts.
    • Updates TOOL_HANDLERS in tools.ts to include TYPECHECK_TOOL_NAME with a handler that runs bun run typecheck.
  • Behavior:
    • The typecheck tool is intended to be run after file edits or when type changes are suspected to ensure type safety.

This description was created by Ellipsis for 2a0a474. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features
    • Added a Type Check tool that runs project type checks, shows pass/fail output, and displays sanitized error details; appears in tool lists and chat with a “Checking types” label and icon.
  • UI
    • Tool invocation messages render more consistently (including empty parts) and now surface tool output states instead of hiding them; per-tool displays are more explicit (terminal, search, file edits, todos).

@vercel
Copy link

vercel bot commented Sep 1, 2025

@Paribesh01 is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds an end-to-end "typecheck" tool: CLI tool definition and toolset registration, client handler to run a sandboxed bunx tsc --noEmit, UI rendering for typecheck results, a SYSTEM_PROMPT directive to always run typecheck, and minor UI guard/refactor changes and a removed debug log.

Changes

Cohort / File(s) Summary
AI CLI Tool Definition
packages/ai/src/tools/cli.ts
Adds TYPECHECK_TOOL_NAME, TYPECHECK_TOOL_PARAMETERS (empty z.object), and exported typecheckTool.
AI Toolset Registration
packages/ai/src/tools/toolset.ts
Imports and registers typecheckTool in BUILD_TOOL_SET under TYPECHECK_TOOL_NAME.
Client Tool Handlers
apps/web/client/src/components/tools/handlers/cli.ts
Adds handleTypecheckTool(args, editorEngine) which runs bunx tsc --noEmit via editorEngine.sandbox.session.runCommand and returns { success, error? }.
Client Tool Mapping / Tools
apps/web/client/src/components/tools/tools.ts
Registers TYPECHECK_TOOL_NAME and TYPECHECK_TOOL_PARAMETERS in the client TOOL_HANDLERS mapping to call handleTypecheckTool.
UI: Tool Display - Detailed
apps/web/client/src/app/project/[id]/_components/.../tool-call-display.tsx
Adds branch for TYPECHECK_TOOL_NAME, sanitizes stderr with strip-ansi, flattens per-tool gating into explicit branches, and standardizes rendering for terminal/file-edit/search tools.
UI: Tool Display - Simple
apps/web/client/src/app/project/[id]/_components/.../tool-call-simple.tsx
Adds TYPECHECK_TOOL_NAME icon/label ("Checking types"); removes early return for output-available so output/error can be shown.
UI: Message Content
apps/web/client/src/app/project/[id]/_components/.../message-content/index.tsx
Removes early exit when parts is empty so component renders an empty fragment instead of returning null.
Prompt / Guidance
packages/ai/src/prompt/system.ts
Adds system prompt directive instructing agents to always run typecheck after code changes.
Misc
apps/web/client/src/components/store/editor/chat/conversation.ts
Removes a debug console.log from upsertMessageInStorage.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Agent
  participant AI_Toolset as AI Toolset
  participant Client as Web Client
  participant Sandbox as EditorEngine.sandbox

  Agent->>AI_Toolset: request "typecheck"
  AI_Toolset->>Agent: emit tool invocation (TYPECHECK_TOOL_NAME)
  Agent->>Client: invoke client handler (TYPECHECK_TOOL_NAME)
  Client->>Sandbox: runCommand("bunx tsc --noEmit")
  Sandbox-->>Client: { exitCode, output, error }
  Client-->>Agent: { success: bool, error?: string }
  Note right of Client: UI renders result — stdout on success\nor sanitized stderr on failure
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Expose a tool for the agent to run typecheck [#2759]

Out-of-scope changes

Code Change Explanation
Removed early return when parts is empty (apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/index.tsx) UI rendering guard change not required by the typecheck-tool objective; alters render behavior for empty message parts.
Flattened per-tool gating and broader refactor in tool-call-display.tsx (apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-display.tsx) Refactors multiple per-tool branching and gating beyond just adding a typecheck display; changes rendering semantics for several tools.

Possibly related PRs

Poem

I hop where code and carrots meet,
I sniff the types from head to feet.
Bunx runs tsc with gentle thump,
If errors hide, I give a jump.
A rabbit's cheer — types clean and neat. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cdc3679 and e208001.

📒 Files selected for processing (1)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-display.tsx (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Paribesh01
Copy link
Contributor Author

hey @Kitenite i have added a typecheck tool, can you plz review this pr

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/web/client/src/components/tools/tools.ts (1)

172-179: Rename unused handler parameter and optionally add a preflight check for the typecheck script

File: apps/web/client/src/components/tools/tools.ts (lines 172–179)

- handler: async (args: z.infer<typeof TYPECHECK_TOOL_PARAMETERS>, editorEngine: EditorEngine) => {
+ handler: async (_args: z.infer<typeof TYPECHECK_TOOL_PARAMETERS>, editorEngine: EditorEngine) => {
  • Rename args to _args in the handler signature to satisfy no-unused-parameters.
  • Optional: before running bun run typecheck, verify the workspace’s package.json defines a "typecheck" script (most packages lack it: apps/backend, apps/web, tooling/typescript) and throw a clear error if missing.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 106ec88 and 2a0a474.

📒 Files selected for processing (3)
  • apps/web/client/src/components/tools/tools.ts (2 hunks)
  • packages/ai/src/tools/cli.ts (1 hunks)
  • packages/ai/src/tools/toolset.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: onlook-dev/onlook#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T03:33:58.606Z
Learning: Run type checking with `bun run typecheck`
🧬 Code graph analysis (2)
apps/web/client/src/components/tools/tools.ts (3)
packages/ai/src/tools/cli.ts (2)
  • TYPECHECK_TOOL_NAME (104-104)
  • TYPECHECK_TOOL_PARAMETERS (105-105)
apps/web/client/src/components/store/editor/engine.ts (1)
  • EditorEngine (31-111)
apps/web/client/src/components/tools/handlers/cli.ts (1)
  • handleTerminalCommandTool (13-22)
packages/ai/src/tools/toolset.ts (1)
packages/ai/src/tools/cli.ts (2)
  • TYPECHECK_TOOL_NAME (104-104)
  • typecheckTool (106-110)
🔇 Additional comments (4)
packages/ai/src/tools/cli.ts (1)

104-110: Typecheck tool definition — LGTM

Well-scoped addition with empty input schema and a clear description. No issues.

packages/ai/src/tools/toolset.ts (2)

13-15: Wiring imports — LGTM

Imports for TYPECHECK tool are correct and consistent with local conventions.


65-65: Build-only registration — LGTM

Added only to BUILD_TOOL_SET (not ASK), which matches the intended usage.

apps/web/client/src/components/tools/tools.ts (1)

34-35: Client-side tool import — LGTM

Imports align with the AI package exports. No concerns.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/web/client/src/components/tools/handlers/cli.ts (2)

151-156: Type the args with the zod schema and mark as intentionally unused

Use the exported TYPECHECK_TOOL_PARAMETERS for consistency with other handlers and prefix the unused param to satisfy linters.

-import type { EditorEngine } from '@/components/store/editor/engine';
+import type { EditorEngine } from '@/components/store/editor/engine';
 import {
   ALLOWED_BASH_EDIT_COMMANDS,
   ALLOWED_BASH_READ_COMMANDS,
   BASH_EDIT_TOOL_PARAMETERS,
   BASH_READ_TOOL_PARAMETERS,
   GLOB_TOOL_PARAMETERS,
   GREP_TOOL_PARAMETERS,
-  TERMINAL_COMMAND_TOOL_PARAMETERS
+  TERMINAL_COMMAND_TOOL_PARAMETERS,
+  TYPECHECK_TOOL_PARAMETERS
 } from '@onlook/ai';
@@
-export async function handleTypecheckTool(
-    args: Record<string, never>,
+export async function handleTypecheckTool(
+    _args: z.infer<typeof TYPECHECK_TOOL_PARAMETERS>,
     editorEngine: EditorEngine,
 ): Promise<{
     success: boolean;
     error?: string;
 }> {

158-171: Avoid “false green” UI by exposing stdout and keep command configurable

Return result.output on success (useful warnings), and surface both error and output on failure. Also, consider centralizing the command string to avoid drift with the UI.

-    try {
-        // Run Next.js typecheck command
-        const result = await editorEngine.sandbox.session.runCommand('bunx tsc --noEmit');
+    try {
+        const cmd = 'bunx tsc --noEmit';
+        const result = await editorEngine.sandbox.session.runCommand(cmd);
 
-        if (result.success) {
-            return {
-                success: true
-            };
-        } else {
-            return {
-                success: false,
-                error: result.error || result.output || 'Typecheck failed with unknown error'
-            };
-        }
+        if (result.success) {
+            return { success: true /* optionally: , output: result.output */ };
+        }
+        return { success: false, error: result.error || result.output || 'Typecheck failed with unknown error' };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0a474 and 6efea7b.

📒 Files selected for processing (6)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/index.tsx (0 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-display.tsx (3 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-simple.tsx (3 hunks)
  • apps/web/client/src/components/tools/handlers/cli.ts (1 hunks)
  • apps/web/client/src/components/tools/tools.ts (3 hunks)
  • packages/ai/src/tools/cli.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/index.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/client/src/components/tools/tools.ts
  • packages/ai/src/tools/cli.ts
🧰 Additional context used
🧬 Code graph analysis (3)
apps/web/client/src/components/tools/handlers/cli.ts (1)
apps/web/client/src/components/store/editor/engine.ts (1)
  • EditorEngine (32-115)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-simple.tsx (2)
packages/ai/src/tools/cli.ts (1)
  • TYPECHECK_TOOL_NAME (104-104)
packages/ui/src/components/icons/index.tsx (1)
  • Icons (137-3592)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-display.tsx (5)
packages/ai/src/tools/cli.ts (2)
  • TERMINAL_COMMAND_TOOL_NAME (4-4)
  • TYPECHECK_TOOL_NAME (104-104)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-simple.tsx (1)
  • ToolCallSimple (60-207)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/code-display/bash-code-display.tsx (1)
  • BashCodeDisplay (60-151)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/code-display/search-sources-display.tsx (1)
  • SearchSourcesDisplay (18-86)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/code-display/collapsible-code-block.tsx (1)
  • CollapsibleCodeBlock (21-125)
🔇 Additional comments (3)
apps/web/client/src/components/tools/handlers/cli.ts (1)

160-161: Use tsc --noEmit directly for Next.js type checks
Next.js does not provide a built-in next typecheck command—its docs explicitly recommend running tsc --noEmit for CI/type checking. You may optionally define a "typecheck": "tsc --noEmit" script in package.json and invoke that, but retaining bunx tsc --noEmit is correct if no custom script exists.

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-simple.tsx (1)

27-32: LGTM: tool name import, icon mapping, and label

The TYPECHECK tool import, icon mapping, and “Checking types” label look consistent with the rest of the component.

Also applies to: 57-58, 175-176

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/message-content/tool-call-display.tsx (1)

19-20: strip-ansi dependency verified: Found in apps/web/client/package.json; no action required.

Copy link
Contributor

@Kitenite Kitenite left a comment

Choose a reason for hiding this comment

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

@Paribesh01 i don't believe your original implementation works because bun run typecheck does not actually exist as a command outside of the app. I fixed it up and added display.

@Kitenite Kitenite merged commit 7b34c0f into onlook-dev:main Sep 1, 2025
1 of 3 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/ai/src/prompt/system.ts (1)

10-10: Reword the directive to scope typecheck tool calls

  • In packages/ai/src/prompt/system.ts, replace the line:
- - ALWAYS run typecheck after making code changes to ensure type safety. Use the typecheck tool to verify your changes don't introduce type errors.

with:

+ - After making changes that may affect types, run the typecheck tool (preferred over terminal) at least once before finishing an edit. If it fails, summarize and fix or ask for input; if it passes, note "✅ Typecheck passed!"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6efea7b and cdc3679.

📒 Files selected for processing (3)
  • apps/web/client/src/components/store/editor/chat/conversation.ts (0 hunks)
  • packages/ai/src/prompt/system.ts (1 hunks)
  • packages/ai/src/tools/cli.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/client/src/components/store/editor/chat/conversation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ai/src/tools/cli.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: onlook-dev/onlook#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-31T03:33:58.606Z
Learning: Run type checking with `bun run typecheck`

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.

[feat] Give the agent the tool to run typecheck

2 participants