Skip to content

Fix explicit active file drift in multi-file bridge - #90

Open
StealthEyeLLC wants to merge 1 commit into
southleft:mainfrom
StealthEyeLLC:fix-explicit-active-file-lock
Open

Fix explicit active file drift in multi-file bridge#90
StealthEyeLLC wants to merge 1 commit into
southleft:mainfrom
StealthEyeLLC:fix-explicit-active-file-lock

Conversation

@StealthEyeLLC

Copy link
Copy Markdown

Summary

Fixes #72.

This makes explicit multi-file targeting sticky in the local WebSocket Desktop Bridge. Before an MCP client explicitly targets a file, the legacy behavior is preserved: the active file follows the latest connected/user-touched file. After setActiveFile() is called (normally through figma_navigate), passive peer FILE_INFO, SELECTION_CHANGE, and PAGE_CHANGE events continue updating per-file state, but no longer silently retarget subsequent tool calls.

Why

In multi-file sessions, background events from another Figma file can currently override an explicit figma_navigate() target. That makes long-running agent workflows unsafe: an operation can begin in file A and silently continue in file B after a tab focus, selection event, page event, or plugin reconnect.

Changes

  • Add an explicit active-file mode to FigmaWebSocketServer.
  • Preserve implicit auto-switching until a caller explicitly chooses a target.
  • Prevent peer selection/page events from stealing an explicit active target.
  • Prevent peer FILE_INFO reconnects/new file connections from stealing an explicit active target.
  • Keep same-file reconnects working without clearing the explicit target.
  • Reset explicit mode only when the active file is removed/disconnected and the server falls back to another connected file.
  • Make the figma_navigate already-connected path call setActiveFile() so it pins the target explicitly even when the requested file is already active.
  • Add regression coverage for peer SELECTION_CHANGE, PAGE_CHANGE, and FILE_INFO reconnect/new-file drift.

Validation

Run on OVH using the upstream repo checkout on branch fix-explicit-active-file-lock.

  • npm ci --include=dev
  • npx -y node@22 node_modules/jest/bin/jest.js tests/websocket-bridge.test.ts --runInBand
  • npx -y node@22 node_modules/typescript/bin/tsc -p tsconfig.local.json --noEmit
  • npx -y node@22 node_modules/typescript/bin/tsc --project tsconfig.local.json
  • npx -y node@22 node_modules/jest/bin/jest.js --runInBand ✅ — 45 suites / 1339 tests passed
  • git diff --check

Note: full tsc --noEmit still reports existing app UI type errors in src/apps/*/ui/mcp-app.ts unrelated to this change. The touched local-server path passes tsconfig.local.json type-check and build, and the full Jest suite passes under Node 22.

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.

Multi-file: active file silently switches on peer SELECTION_CHANGE/PAGE_CHANGE/FILE_INFO, overriding figma_navigate

1 participant