wolfhece._plugin_trust
Plugin trust store — persists per-plugin approval decisions.
Trust levels
BUILTINThe plugin ships inside
wolfhece/_builtin_plugins/. Always trusted, no user action required.APPROVEDThe user has explicitly approved the plugin in its current state: the SHA-256 digest of
companion.py+plugin.tomlmatches the stored value.CHANGEDThe user previously approved the plugin, but at least one of the two tracked files has changed since then. Re-approval is required.
UNKNOWNThe plugin has never been seen; the user has not yet been asked.
Usage example
from wolfhece._plugin_trust import get_default_store, TrustStatus
store = get_default_store()
status = store.get_status(plugin_info)
if status in (TrustStatus.UNKNOWN, TrustStatus.CHANGED):
# --- show approval dialog to the user ---
store.approve(plugin_info)
The trust file is a human-readable JSON document stored in the OS user-config directory (no extra dependencies required):
Windows —
%APPDATA%\wolfhece\trusted_plugins.jsonLinux / macOS —
$XDG_CONFIG_HOME/wolfhece/trusted_plugins.json(defaults to~/.config/wolfhece/)
Module Contents
- class wolfhece._plugin_trust.TrustStatus(*args, **kwds)[source]
Bases:
enum.Enum
Approval status of a discovered plugin.
- wolfhece._plugin_trust.compute_plugin_hash(plugin_dir: pathlib.Path) str[source]
Return a SHA-256 hex digest that covers
companion.py+plugin.toml.Both file names are included in the digest so that renaming a file without changing its content still invalidates the hash. The files are processed in a deterministic order so the result is stable across platforms.
- Parameters:
plugin_dir – Root directory of the plugin (must contain both files).
- Returns:
64-character lowercase hex string.
- wolfhece._plugin_trust._user_config_dir() pathlib.Path[source]
Return the wolfhece user-config directory without importing extras.
- class wolfhece._plugin_trust.TrustStore(trust_file: pathlib.Path | None = None)[source]
Persist per-plugin approval decisions in a local JSON file.
Each entry maps a plugin slug (
PluginInfo.name) to a record with:hash— SHA-256 digest at the time of approvalapproved_at— ISO-8601 UTC timestampdisplay_name— for human readability onlyversion— version string at the time of approval
- Parameters:
trust_file – Path to the JSON trust file. Defaults to
<user-config-dir>/wolfhece/trusted_plugins.json.
- get_status(info: wolfhece._plugin_loader.PluginInfo) TrustStatus[source]
Return the
TrustStatusfor info.The check is performed in this order:
If the plugin path is inside
BUILTIN_PLUGINS_DIR→BUILTIN.If no record exists for
info.name→UNKNOWN.If the stored hash matches the current digest →
APPROVED.Otherwise →
CHANGED.
- approve(info: wolfhece._plugin_loader.PluginInfo) None[source]
Record user approval for the current state of info.
Computes the hash of
companion.py+plugin.tomland stores it alongside a timestamp and human-readable metadata.
- revoke(name: str) None[source]
Remove any stored approval for the plugin name.
After revocation
get_status()returnsUNKNOWNfor that slug.
- wolfhece._plugin_trust._default_store: TrustStore | None = None[source]
- wolfhece._plugin_trust.get_default_store() TrustStore[source]
Return the process-wide
TrustStore(created on first call).
- wolfhece._plugin_trust.reset_default_store(trust_file: pathlib.Path | None = None) TrustStore[source]
Replace the default store — useful for testing.
- Parameters:
trust_file – Custom path;
Noneresets to the system default.- Returns:
The new
TrustStoreinstance.