Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Nov 21, 2025

Summary

New copilot version: improves existing tools, adds new copilot tools, improves diff store interactions

Type of Change

  • Bug fix
  • New feature

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Sg312 and others added 30 commits November 12, 2025 12:26
* Fix template details

* Fix deps
… consistent, smoothen out creation of profile (#1943)

* fix(templates): view current ui

* update UI to be less cluttered

* make state management for creating user profile smoother

* fix autoselect logic

* fix lint
…ng (#1945)

* fix(settings): fix broken api keys, help modal, logs, workflow renaming

* fix build

* cleanup

* use emcn
* new gifs

* changed wording

* changed wording

* lowercase

* changed wording

* remove blog stuff

---------

Co-authored-by: aadamgough <[email protected]>
Co-authored-by: waleed <[email protected]>
* feat(drizzle): added ods for analytics from drizzle

* clean
* feat(docs): added docs analytics drizzle ods

* fix build
@vercel
Copy link

vercel bot commented Nov 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 21, 2025 6:17pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 21, 2025

Greptile Overview

Greptile Summary

This PR introduces copilot v0.2 with significant architectural improvements to workflow editing and new capabilities for deployment and navigation. The changes center around a refactored diff system that now tracks baseline workflows separately from proposed changes, enabling better undo/redo integration.

Key Changes

  • New Copilot Tools: Added 6 new tools including navigate_ui (UI navigation), deploy_workflow (workflow deployment), search_patterns, search_errors, remember_debug, and renamed get_oauth_credentials to unified get_credentials
  • Diff System Refactor: Replaced diffWorkflow with baselineWorkflow tracking in workflow-diff store, improved state management with proper cleanup and baseline snapshots
  • Undo/Redo Improvements: Converted to async operations with recording suspension mechanism to prevent interference during copilot edits, added duplicate diff operation prevention
  • Plan Mode Support: Added plan mode UI with plan artifacts, context usage indicator, and "build workflow" button to execute planned workflows
  • Editable Tool Parameters: Users can now edit parameters for pending tool calls (e.g., API request URLs) before execution
  • Database Schema: Added plan_artifact and config JSONB columns to copilot_chats table

Architecture Improvements

The workflow diff engine now properly isolates baseline state from proposed changes, allowing copilot edits to be applied, previewed, accepted, or rejected without corrupting the undo/redo stack. The new runWithUndoRedoRecordingSuspended function ensures that programmatic workflow state replacements don't create spurious undo history entries.

Issues Found

  • Navigation tool uses full page reload instead of client-side routing
  • Async function signature missing Promise return type
  • structuredClone may fail on complex objects with functions or callbacks
  • Silent failures in workflow sanitization aren't surfaced to copilot

Confidence Score: 3/5

  • This PR introduces significant architectural changes with some logical issues that should be addressed before merging
  • Score reflects the large scope (84 files, 13k+ additions) with critical changes to undo/redo and diff systems. Found 2 logic issues (page reload causing state loss, structuredClone failures) and 1 syntax issue (missing async return type) that need fixing. The refactoring is well-structured but the navigation and cloning implementations have correctness issues.
  • Pay close attention to apps/sim/lib/copilot/tools/client/navigation/navigate-ui.ts (page reload issue), apps/sim/stores/workflow-diff/store.ts (structuredClone failures), and apps/sim/hooks/use-undo-redo.ts (async signature mismatch)

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/stores/workflow-diff/store.ts 3/5 Major refactoring of diff store from diffWorkflow to baseline tracking, improved state management and cleanup logic
apps/sim/stores/panel-new/copilot/store.ts 4/5 Added 6 new copilot tools (navigate_ui, deploy_workflow, search_patterns, etc), improved display text formatting with dynamic getDynamicText
apps/sim/lib/copilot/tools/client/navigation/navigate-ui.ts 3/5 New navigation tool using window.location.href for navigation, case-insensitive workflow name matching
apps/sim/lib/copilot/tools/client/workflow/deploy-workflow.ts 4/5 New deployment tool with API key checking, dynamic button text, curl command generation for deployed workflows
apps/sim/lib/copilot/tools/client/workflow/edit-workflow.ts 4/5 Improved workflow editing with better subblock merging, sanitization, and diff application logic
apps/sim/hooks/use-undo-redo.ts 3/5 Major refactor to async undo/redo with suspended recording support, replaceWorkflowState operations instead of individual block operations

Sequence Diagram

sequenceDiagram
    participant User
    participant CopilotUI as Copilot UI
    participant CopilotStore as Copilot Store
    participant Tool as Client Tool
    participant DiffStore as Workflow Diff Store
    participant WorkflowStore as Workflow Store
    participant UndoRedo as Undo/Redo Store
    participant API as Backend API

    User->>CopilotUI: Send message with mode (ask/build/plan)
    CopilotUI->>API: POST /api/copilot/chat
    API-->>CopilotStore: SSE stream (tool_call events)
    
    alt Tool Call: edit_workflow
        CopilotStore->>Tool: Instantiate EditWorkflowClientTool
        Tool->>API: Execute edit_workflow with operations
        API-->>Tool: Return proposed WorkflowState
        Tool->>DiffStore: setProposedChanges(proposedState)
        DiffStore->>DiffStore: Capture baseline snapshot
        DiffStore->>WorkflowStore: Apply diff markers to blocks
        DiffStore-->>CopilotUI: Show diff preview
        
        alt User accepts changes
            User->>Tool: Click Accept
            Tool->>DiffStore: acceptChanges()
            DiffStore->>UndoRedo: runWithUndoRedoRecordingSuspended
            DiffStore->>WorkflowStore: replaceWorkflowState(cleanState)
            DiffStore->>API: PUT /api/workflows/{id}/state
            DiffStore->>DiffStore: clearDiff()
            DiffStore-->>CopilotUI: Hide diff preview
        else User rejects changes
            User->>Tool: Click Reject
            Tool->>DiffStore: rejectChanges()
            DiffStore->>UndoRedo: runWithUndoRedoRecordingSuspended
            DiffStore->>WorkflowStore: replaceWorkflowState(baseline)
            DiffStore->>DiffStore: clearDiff()
            DiffStore-->>CopilotUI: Hide diff preview
        end
    end
    
    alt Tool Call: deploy_workflow
        CopilotStore->>Tool: Instantiate DeployWorkflowClientTool
        Tool->>API: Check API keys
        alt Has API keys
            Tool->>API: POST /api/workflows/{id}/deploy
            API-->>Tool: Deployment success + endpoint
            Tool->>WorkflowStore: Update deployment status
            Tool-->>CopilotUI: Show curl command
        else No API keys
            Tool->>CopilotUI: Open API keys modal
            Tool-->>CopilotUI: Show "needs API key" message
        end
    end
    
    alt Tool Call: navigate_ui
        CopilotStore->>Tool: Instantiate NavigateUIClientTool
        User->>Tool: Click Accept (Open)
        Tool->>Tool: Resolve destination URL
        Tool->>User: window.location.href = url
    end
    
    alt Undo/Redo Operations
        User->>UndoRedo: Trigger undo
        UndoRedo->>UndoRedo: Check if recording suspended
        UndoRedo->>WorkflowStore: replaceWorkflowState(previousState)
        UndoRedo->>API: Queue replaceWorkflowState operation
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

84 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile


// Navigate if URL was set
if (navigationUrl) {
window.location.href = navigationUrl
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: using window.location.href causes full page reload, losing client-side state and causing jarring UX

Suggested change
window.location.href = navigationUrl
window.history.pushState({}, '', navigationUrl)
window.dispatchEvent(new PopStateEvent('popstate'))
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/client/navigation/navigate-ui.ts
Line: 207:207

Comment:
**logic:** using `window.location.href` causes full page reload, losing client-side state and causing jarring UX

```suggestion
        window.history.pushState({}, '', navigationUrl)
        window.dispatchEvent(new PopStateEvent('popstate'))
```

How can I resolve this? If you propose a fix, please make it concise.

edgeCount: affectedEdges?.length || 0,
})
},
[activeWorkflowId, userId, undoRedoStore]
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: changed from sync to async without updating return type in signature, could cause issues for callers expecting synchronous behavior

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/hooks/use-undo-redo.ts
Line: 328:328

Comment:
**syntax:** changed from sync to async without updating return type in signature, could cause issues for callers expecting synchronous behavior

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +26 to +33
function cloneWorkflowState(state: WorkflowState): WorkflowState {
return {
...state,
blocks: structuredClone(state.blocks || {}),
edges: structuredClone(state.edges || []),
loops: structuredClone(state.loops || {}),
parallels: structuredClone(state.parallels || {}),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: using structuredClone can fail on complex objects with functions, symbols, or DOM nodes (common in workflow blocks with callbacks)

Suggested change
function cloneWorkflowState(state: WorkflowState): WorkflowState {
return {
...state,
blocks: structuredClone(state.blocks || {}),
edges: structuredClone(state.edges || []),
loops: structuredClone(state.loops || {}),
parallels: structuredClone(state.parallels || {}),
}
function cloneWorkflowState(state: WorkflowState): WorkflowState {
return JSON.parse(JSON.stringify({
...state,
blocks: state.blocks || {},
edges: state.edges || [],
loops: state.loops || {},
parallels: state.parallels || {},
}))
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/stores/workflow-diff/store.ts
Line: 26:33

Comment:
**logic:** using `structuredClone` can fail on complex objects with functions, symbols, or DOM nodes (common in workflow blocks with callbacks)

```suggestion
function cloneWorkflowState(state: WorkflowState): WorkflowState {
  return JSON.parse(JSON.stringify({
    ...state,
    blocks: state.blocks || {},
    edges: state.edges || [],
    loops: state.loops || {},
    parallels: state.parallels || {},
  }))
}
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +44 to +50
private getSanitizedWorkflowJson(workflowState: any): string | undefined {
const logger = createLogger('EditWorkflowClientTool')

if (!this.workflowId) {
logger.warn('No workflowId available for getting sanitized workflow JSON')
return undefined
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: returning undefined without error handling means silent failures won't be surfaced to copilot, making debugging difficult

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/client/workflow/edit-workflow.ts
Line: 44:50

Comment:
**style:** returning `undefined` without error handling means silent failures won't be surfaced to copilot, making debugging difficult

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 481 to +549
<div className='px-[10px] py-[8px]'>
<span className='font-mono text-muted-foreground text-xs'>
{method || 'GET'}
</span>
<input
type='text'
value={method || 'GET'}
onChange={(e) => setEditedParams({ ...editedParams, method: e.target.value })}
className='w-full bg-transparent font-mono text-muted-foreground text-xs outline-none focus:text-foreground'
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: editing method directly without validation allows invalid HTTP methods like "GETT" or "post" (lowercase)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/copilot/components/inline-tool-call/inline-tool-call.tsx
Line: 543:549

Comment:
**style:** editing method directly without validation allows invalid HTTP methods like "GETT" or "post" (lowercase)

How can I resolve this? If you propose a fix, please make it concise.

@Sg312 Sg312 merged commit ddd3219 into staging Nov 21, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/copilot-3 branch November 22, 2025 03:52
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.

6 participants