Skip to content

Refactor plugins to use ctx.util helpers#54

Merged
robinebers merged 3 commits intomainfrom
refactor/more-native-api
Feb 3, 2026
Merged

Refactor plugins to use ctx.util helpers#54
robinebers merged 3 commits intomainfrom
refactor/more-native-api

Conversation

@robinebers
Copy link
Owner

@robinebers robinebers commented Feb 3, 2026

Summary

  • Hi there! Keep shipping great code.
  • Promote shared plugin helpers into the injected ctx.util API, update the claude/codex/cursor plugins and their tests to rely on the helpers, and deduplicate frontend plugin state/timer/settings logic.

Testing

  • Not run (not requested)

Note

Medium Risk
Medium risk because it changes the plugin runtime API surface (ctx.util) and refactors auth refresh/retry + JSON parsing paths in multiple plugins; regressions would primarily affect plugin data fetching and token refresh behavior.

Overview
Plugins now get a shared ctx.util API injected by the host (tryParseJson, request helpers, auth-status detection, retry-on-auth, date/expiry utilities), and the Claude/Codex/Cursor plugins are refactored to route JSON parsing, HTTP calls, token-expiry checks, and 401/403 refresh+retry logic through these helpers.

Tests and frontend logic are deduped by introducing plugins/test-helpers.js for shared plugin ctx mocks, adding a reusable useNowTicker hook (now used by PanelFooter with resetKey: autoUpdateNextAt and by ProviderCard with stopAfterMs), centralizing PluginDisplayState in src/lib/plugin-types.ts, and moving settings option constants (AUTO_UPDATE_OPTIONS, THEME_OPTIONS) into src/lib/settings.ts. Two short spec docs capture the intent and API surface.

Written by Cursor Bugbot for commit 380ca70. This will update automatically on new commits. Configure here.


Summary by cubic

Introduced a shared ctx.util helper API for plugins and refactored the Claude, Codex, and Cursor plugins (and tests) to use it. Also deduped frontend state, timer, and settings logic with no behavior changes expected.

  • Refactors
    • Host now injects ctx.util (JSON parsing, HTTP/requestJson, auth status checks, retryOnceOnAuth, parseDateMs, needsRefreshByExpiry).
    • Claude/Codex/Cursor plugins use ctx.util for JSON/HTTP/date/expiry and unified auth retry; error handling simplified.
    • Tests use plugins/test-helpers.js to share ctx mocks and utilities.
    • Frontend: added useNowTicker hook and used in panel-footer and provider-card; centralized PluginDisplayState type; consolidated AUTO_UPDATE_OPTIONS and THEME_OPTIONS in settings.
    • Added spec doc outlining goals and API surface.

Written for commit 380ca70. Summary will update on new commits.

@macroscopeapp
Copy link

macroscopeapp bot commented Feb 3, 2026

Refactor plugin HTTP, JSON, auth-refresh, and date parsing to use ctx.util helpers and add useNowTicker to reset PanelFooter countdown on autoUpdateNextAt changes

Plugins switch to ctx.util.request, ctx.util.tryParseJson, ctx.util.retryOnceOnAuth, and ctx.util.parseDateMs with needsRefreshByExpiry; UI introduces useNowTicker and updates PanelFooter and ProviderCard to use it; shared types and settings options move to common modules; test helpers provide a unified makeCtx; host injects updated JS util handling finite numbers and strings; specs document the refactor and ticker reset.

📍Where to Start

Start with the ctx.util contract used by plugins in tests via makeCtx in plugins/test-helpers.js, then review a representative plugin refactor such as probe in plugins/claude/plugin.js.


Macroscope summarized 380ca70.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 17 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="plugins/cursor/plugin.js">

<violation number="1" location="plugins/cursor/plugin.js:200">
P2: Missing null check after `tryParseJson`. Unlike `JSON.parse`, `tryParseJson` returns `null` on failure. The next line accesses `plan.planInfo` without checking if `plan` is null, which would throw a TypeError on malformed JSON. Add a null guard to be consistent with other usages in this file.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@robinebers robinebers merged commit 1cf9c68 into main Feb 3, 2026
3 checks passed
@robinebers robinebers deleted the refactor/more-native-api branch February 3, 2026 08:59
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.

1 participant