Skip to content

Add isToolUpdatingRepl state to show overlay and block edits during updateRepl tool calls #36

@michaelmagan

Description

@michaelmagan

Summary

Add a new isToolUpdatingRepl state (separate from isAiUpdating) that tracks specifically when the updateRepl tool is executing. This state should:

  1. Show the "AI updating" overlay on the REPL
  2. Block user edits to the editor during the update

Background

Currently the "AI updating" overlay shows based on isAiUpdating, which is set whenever the AI is generating any response (thinking, text, any tool call). The overlay should only appear when the updateRepl tool is actively running.

Note: We're creating a new state rather than modifying isAiUpdating because other parts of the code may depend on isAiUpdating for different purposes.

Current Behavior

  • isAiUpdating is set based on Tambo's generationStage in src/app/chat/page.tsx (lines 186-191)
  • The overlay shows whenever AI is doing anything

Desired Behavior

  • New isToolUpdatingRepl state that is only true when the updateRepl tool is executing
  • Overlay uses isToolUpdatingRepl instead of isAiUpdating
  • Editor edits are blocked while isToolUpdatingRepl is true
  • isAiUpdating continues to work as before (other features may depend on it)

Technical Implementation

1. Add isToolUpdatingRepl to StrudelService (src/strudel/lib/service.ts)

// Add private state
private _isToolUpdatingRepl = false;
private toolUpdatingReplCallbacks: ((isUpdating: boolean) => void)[] = [];

// Add getter
get isToolUpdatingRepl(): boolean {
  return this._isToolUpdatingRepl;
}

// Add setter with notifications
setToolUpdatingRepl(value: boolean): void {
  this._isToolUpdatingRepl = value;
  this.toolUpdatingReplCallbacks.forEach(cb => cb(value));
}

// Add subscription method
onToolUpdatingReplChange(callback: (isUpdating: boolean) => void): () => void {
  this.toolUpdatingReplCallbacks.push(callback);
  return () => {
    this.toolUpdatingReplCallbacks = this.toolUpdatingReplCallbacks.filter(cb => cb !== callback);
  };
}

2. Update validateAndUpdateRepl tool (src/strudel/tools/validateAndUpdateRepl.ts)

export const validateAndUpdateRepl: TamboTool = {
  // ... existing config
  tool: async (code: string) => {
    const service = StrudelService.instance();
    service.setToolUpdatingRepl(true);
    
    try {
      await service.init();
      // ... existing validation logic
      const result = await service.updateAndPlay(code, { source: "ai" });
      return result;
    } finally {
      service.setToolUpdatingRepl(false);
    }
  },
  // ...
};

3. Update StrudelProvider (src/strudel/context/strudel-provider.tsx)

  • Add isToolUpdatingRepl to context type
  • Add useState for isToolUpdatingRepl
  • Subscribe to service's onToolUpdatingReplChange in useEffect
  • Expose in provider value

4. Update overlay component to use new state

  • The component that renders the overlay should use isToolUpdatingRepl instead of isAiUpdating

5. Block editor edits when updating

  • When isToolUpdatingRepl is true, the editor should be read-only or have edits blocked
  • This prevents race conditions where user edits conflict with AI updates

Relevant Files

  • src/strudel/lib/service.ts - Add new state and methods
  • src/strudel/tools/validateAndUpdateRepl.ts - Set/clear state around tool execution
  • src/strudel/context/strudel-provider.tsx - Expose new state via context
  • Component that renders the overlay (needs to be identified and updated)
  • Editor component - needs to respect isToolUpdatingRepl to block edits

Acceptance Criteria

  • New isToolUpdatingRepl state added to StrudelService
  • validateAndUpdateRepl tool sets state to true at start, false when complete
  • State is exposed through StrudelContext
  • Overlay uses isToolUpdatingRepl instead of isAiUpdating
  • Editor edits are blocked while isToolUpdatingRepl is true
  • isAiUpdating continues to work unchanged for other features
  • Overlay only appears when updateRepl tool is running (not during AI thinking/text responses)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions