Files
Reims-Go/internal/plugin/risks.go
T
NwflowerandClaude Opus 5.5 e259833b5f feat(plugins): rework the plugin market and first-run language packs
Market page
- Card grid that fills the width; cards show only icon, name,
  publisher (trust mark by color and icon), version and the action.
- Paints from cache via the new PeekPluginMarket binding, then revalidates;
  cards reveal 24 at a time as the feed scrolls.
- Category chips come from the index (MarketBrowseResult.kinds) instead of
  a fixed list; the alpha toggle and source badge are gone.
- Installed/Market is a segmented control; refresh now shows feedback.
- WordmarkLoader writes the Reims-Go wordmark stroke by stroke while the
  market loads (static pulse under reduced motion).

Install and enable
- reims:plugin-install events drive a progress bar on the card.
- After install, a dialog offers to enable the plugin and lists what it can
  do in plain words (PluginInfo.risks / MarketCatalogItem.risks, derived
  from tier, permissions and contributions in risks.go).
- Enabling a plugin that provides UI languages switches to the first one
  unless the current language is among them (PluginInfo.locales).

Trust
- A package installed from the project's own index, fetched over HTTPS in
  this session, inherits the index's trust level when its SHA-256 matches.
  Third-party indexes (REIMS_GO_PLUGIN_MARKET_URL) cannot vouch and show
  every entry as community.
- Trust no longer waives review: official packages get the same scan,
  high-risk approval and L3 hash check as any other; only builtin and
  bundled plugins are pre-approved.

First launch
- When the OS language is not covered by zh-CN/en-US, the folder screen
  looks up a matching pack once (SuggestLanguagePack) and offers to install
  it; Continue installs and enables it so the UI follows the OS language.
  Before setup the market keeps its index in memory only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 05:17:45 -07:00

123 lines
3.5 KiB
Go

package plugin
import "strings"
// Risk categories summarize what a plugin can do in words a user can weigh
// before enabling it. IDs are stable; the GUI and CLI translate them.
const (
RiskNative = "native" // ships a native executable with the user's full account rights
RiskBackground = "background" // keeps code running in the background
RiskNetwork = "network" // talks to the network
RiskFiles = "files" // reads or writes files outside its own data folder
RiskVM = "vm" // starts, stops or drives virtual machines
RiskClipboard = "clipboard" // reads or writes the system clipboard
RiskInput = "input" // intercepts or rewrites keyboard and mouse input
RiskUI = "ui" // changes the interface the user sees
)
// riskOrder lists categories from most to least consequential.
var riskOrder = []string{
RiskNative, RiskBackground, RiskNetwork, RiskFiles,
RiskVM, RiskClipboard, RiskInput, RiskUI,
}
// ManifestRisks derives risk categories from a manifest's execution tier,
// permissions and contributions. Built-in plugins ship with the app and
// report none.
func ManifestRisks(m Manifest, tier Tier) []string {
if tier == TierBuiltin {
return nil
}
set := map[string]bool{}
addTierRisks(set, tier)
for _, p := range m.Permissions {
addPermissionRisks(set, p)
}
c := m.Contributes
if len(c.Themes) > 0 || len(c.UIScripts) > 0 || len(c.Locales) > 0 || len(c.Panels) > 0 ||
len(c.Menus) > 0 || len(c.VMCards) > 0 || len(c.StatusItems) > 0 || len(c.SettingsPages) > 0 ||
strings.TrimSpace(m.L10n) != "" {
set[RiskUI] = true
}
if len(c.Hooks) > 0 {
set[RiskBackground] = true
}
if len(c.InputFilters) > 0 {
set[RiskInput] = true
}
if len(c.GuestDrivers) > 0 || len(c.RuntimeKinds) > 0 {
set[RiskVM] = true
}
if len(c.RuntimeSources) > 0 {
set[RiskNetwork] = true
}
return orderedRisks(set)
}
// MarketEntryRisks estimates risk categories for a market listing from its
// declared kind, tier and permissions, before anything is downloaded. The
// installed manifest is authoritative once the package is on disk.
func MarketEntryRisks(e MarketEntry) []string {
set := map[string]bool{}
addTierRisks(set, e.Tier)
for _, p := range e.Permissions {
addPermissionRisks(set, p)
}
switch strings.ToLower(strings.TrimSpace(e.Kind)) {
case "theme", "locale":
set[RiskUI] = true
case "driver", "runtime":
set[RiskVM] = true
}
return orderedRisks(set)
}
func addTierRisks(set map[string]bool, tier Tier) {
switch tier {
case TierL3:
set[RiskNative] = true
set[RiskBackground] = true
set[RiskNetwork] = true
set[RiskFiles] = true
case TierL2:
set[RiskBackground] = true
case TierL4:
set[RiskUI] = true
}
}
func addPermissionRisks(set map[string]bool, perm string) {
p := strings.TrimSpace(perm)
if strings.HasPrefix(p, "net:") && len(p) > len("net:") {
set[RiskNetwork] = true
return
}
switch p {
case "runtime:source":
set[RiskNetwork] = true
case "fs:vm_dir", "fs:shared":
set[RiskFiles] = true
case "vm:control", "qmp:write", "driver:vm", "runtime:provider", "process:spawn", "vm:intent":
set[RiskVM] = true
case "host:clipboard":
set[RiskClipboard] = true
case "input:filter":
set[RiskInput] = true
case "ui:script":
set[RiskUI] = true
set[RiskBackground] = true
case "ui:slot":
set[RiskUI] = true
}
}
func orderedRisks(set map[string]bool) []string {
var out []string
for _, id := range riskOrder {
if set[id] {
out = append(out, id)
}
}
return out
}