#65

fix(providers): resolve auth cache relative to its package (#62)

Draftwizardengineerwants to merge intofrom

With the anthropic provider and the keychain checkbox enabled, Rikugan reports "No Anthropic credential found" on Binary Ninja even when the token is valid and oauth_consent_accepted is true. The log says why:

Unable to import auth cache: No module named 'rikugan.providers'

Binary Ninja loads the plugin directory itself as top-level rikugan, so the real package is rikugan.rikugan.providers. auth_compat._load_auth_cache() imported by the absolute name rikugan.providers.auth_cache, which cannot exist there. It failed on every call, apply_keychain_consent() returned False, _keychain_consent stayed False, and the keychain lookup was skipped. Closes #62.

What changed:

  • Import relative to the package so both layouts resolve. IDA is unaffected, since install_ida.sh puts rikugan/ in as a real top-level package and the resolved name stays rikugan.providers.auth_cache.
  • Catch TypeError as well as ImportError. That is what import_module raises for a relative import with an empty __package__, and it would previously escape the handler.
  • Report the module's real name in the stale-install warning, instead of a hardcoded one that does not exist on Binary Ninja.

The new test builds the nested layout in a subprocess and asserts consent reaches the same auth_cache module object the providers read. It fails against the old code with APPLIED False / CONSENT False, so it pins the regression rather than just covering the line.

rikugan_plugin.py keeps its absolute imports on purpose. IDA loads it as a top-level script with no package, so relative imports are not available there.

One thing worth your call: auth_compat exists to tolerate a stale auth cache, but settings_dialog.py and panel_core.py already import auth_cache directly at module scope, so a partially-updated install would fail at import time before the shim could help. Collapsing it to a plain relative import would remove this class of bug entirely. I kept the change minimal here rather than deleting a module you added deliberately.

Activity

1

This pull request is a draft

Merging is unavailable until it is marked ready for review.