- Build single-source-of-truth 7-domain locale catalog (`locales/{zh-CN,en-US}/*.json`, 1,100+ keys) and `cmd/i18ngen` generator emitting Go catalogs and eager/lazy-split TypeScript domain modules (`core`/`vm` eager; `wizard`/`settings`/`plugins` lazy)
- Add zero-dependency ICU MessageFormat subset (`{var}`, `{n, number}`, CLDR `plural`, `select`), 8-hop cycle-free regional fallback (`zh-HK/zh-MO -> zh-Hant -> zh-TW -> zh-CN`), `auto` OS display-language preference, and `en-XA` pseudo-localization across Go and TypeScript
- Introduce `CodedError` supportability with `[E_CODE]` badges, collapsible `[detail]` diagnostics, and automatic SMC OSK / SMBIOS serial / MAC / token redaction
- Add Host × Guest macOS dual-terminology annotation (`FormatGuestTerm`) across 6 official Apple guest UI locales and localize Win32 system tray, file pickers, and DPI-adaptive `installguide` overlays with CJK font fallback probing
- Upgrade L1–L4 plugin localization to dual-track v2: Track A full language packs (`files`, WOFF2 `fonts`, cross-plugin `pluginOverrides`), Track B plugin-scoped `l10n` bundles (`HasUIMessages` isolation), live `plugin/localeChanged` notifications, `< 2ms` static CLI pack loading, and `reims-go plugin locale init|check` translator toolchain with `zh-TW` and `ja-JP` reference packs
- Harden security, WCAG 2.1 AA token contrast, `< 768px` responsive drawer & form layouts, and RTL logical properties; add backend security/locale regression tests and frontend `node --test` static/runtime guard suite in CI
# Conflicts:
# frontend/src/i18n.ts
# internal/cli/cli.go
# internal/i18n/i18n.go
254 lines
7.7 KiB
Go
254 lines
7.7 KiB
Go
package runtime
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
"sort"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
var reRuntimeKind = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]*$`)
|
|
|
|
const (
|
|
// DefaultKind is the built-in macOS vGPU runtime kind.
|
|
DefaultKind = "reims-vgpu"
|
|
// DefaultRuntimeAPI is the baseline CLI/output contract version for reims-vgpu.
|
|
DefaultRuntimeAPI = "1.0.0"
|
|
)
|
|
|
|
// KindSpec describes a registered runtime kind (e.g. "reims-vgpu", "qemu-ovmf").
|
|
type KindSpec struct {
|
|
Kind string `json:"kind"`
|
|
Name plugin.LocalizedText `json:"name,omitempty"`
|
|
NameZh string `json:"name_zh"`
|
|
NameEn string `json:"name_en"`
|
|
RequiredFiles []string `json:"required_files,omitempty"`
|
|
DefaultAPIVersion string `json:"default_api_version,omitempty"`
|
|
Builtin bool `json:"builtin,omitempty"`
|
|
PluginID string `json:"plugin_id,omitempty"`
|
|
}
|
|
|
|
// KindRegistry holds all registered runtime kinds (§5.2).
|
|
type KindRegistry struct {
|
|
mu sync.RWMutex
|
|
kinds map[string]KindSpec
|
|
}
|
|
|
|
// NewKindRegistry creates a registry pre-populated with the built-in reims-vgpu kind.
|
|
func NewKindRegistry() *KindRegistry {
|
|
kr := &KindRegistry{
|
|
kinds: make(map[string]KindSpec),
|
|
}
|
|
kr.kinds[DefaultKind] = KindSpec{
|
|
Kind: DefaultKind,
|
|
Name: plugin.LocalizedText{ZhCN: "Reims vGPU 运行时", EnUS: "Reims vGPU Runtime"},
|
|
NameZh: "Reims vGPU 运行时",
|
|
NameEn: "Reims vGPU Runtime",
|
|
RequiredFiles: []string{"bin/reims-ctl.exe", "qemu/bin/qemu-system-x86_64.exe"},
|
|
DefaultAPIVersion: DefaultRuntimeAPI,
|
|
Builtin: true,
|
|
PluginID: "builtin.runtime.reims-vgpu",
|
|
}
|
|
return kr
|
|
}
|
|
|
|
// Register adds or updates a runtime kind.
|
|
func (kr *KindRegistry) Register(spec KindSpec) error {
|
|
spec.Kind = strings.TrimSpace(spec.Kind)
|
|
if spec.Kind == "" {
|
|
return errors.New("runtime kind cannot be empty")
|
|
}
|
|
if !reRuntimeKind.MatchString(spec.Kind) || strings.Contains(spec.Kind, "..") {
|
|
return fmt.Errorf("invalid runtime kind %q", spec.Kind)
|
|
}
|
|
kr.mu.Lock()
|
|
defer kr.mu.Unlock()
|
|
if cur, exists := kr.kinds[spec.Kind]; exists {
|
|
if cur.Builtin {
|
|
return fmt.Errorf("cannot overwrite built-in runtime kind %q", spec.Kind)
|
|
}
|
|
if cur.PluginID != "" && spec.PluginID != "" && cur.PluginID != spec.PluginID {
|
|
return fmt.Errorf("runtime kind %q is already owned by plugin %q", spec.Kind, cur.PluginID)
|
|
}
|
|
}
|
|
kr.kinds[spec.Kind] = spec
|
|
return nil
|
|
}
|
|
|
|
// Unregister removes a non-builtin runtime kind registered by pluginID.
|
|
func (kr *KindRegistry) Unregister(kind, pluginID string) {
|
|
kr.mu.Lock()
|
|
if cur, ok := kr.kinds[kind]; ok && !cur.Builtin && (pluginID == "" || cur.PluginID == pluginID) {
|
|
delete(kr.kinds, kind)
|
|
}
|
|
kr.mu.Unlock()
|
|
}
|
|
|
|
// Get returns a registered runtime kind.
|
|
func (kr *KindRegistry) Get(kind string) (KindSpec, bool) {
|
|
kr.mu.RLock()
|
|
spec, ok := kr.kinds[kind]
|
|
kr.mu.RUnlock()
|
|
return spec, ok
|
|
}
|
|
|
|
// List returns all registered runtime kinds sorted deterministically.
|
|
func (kr *KindRegistry) List() []KindSpec {
|
|
kr.mu.RLock()
|
|
defer kr.mu.RUnlock()
|
|
out := make([]KindSpec, 0, len(kr.kinds))
|
|
for _, s := range kr.kinds {
|
|
out = append(out, s)
|
|
}
|
|
sort.Slice(out, func(i, j int) bool {
|
|
if out[i].Builtin != out[j].Builtin {
|
|
return out[i].Builtin
|
|
}
|
|
return out[i].Kind < out[j].Kind
|
|
})
|
|
return out
|
|
}
|
|
|
|
// EffectiveKind returns Manifest.Kind, defaulting to "reims-vgpu" for legacy packages.
|
|
func (m Manifest) EffectiveKind() string {
|
|
if strings.TrimSpace(m.Kind) != "" {
|
|
return strings.TrimSpace(m.Kind)
|
|
}
|
|
return DefaultKind
|
|
}
|
|
|
|
// EffectiveRuntimeAPI returns Manifest.RuntimeAPI, defaulting to "1.0.0".
|
|
func (m Manifest) EffectiveRuntimeAPI() string {
|
|
if strings.TrimSpace(m.RuntimeAPI) != "" {
|
|
return strings.TrimSpace(m.RuntimeAPI)
|
|
}
|
|
return DefaultRuntimeAPI
|
|
}
|
|
|
|
// EffectiveCapabilities returns declared capabilities plus inferred legacy
|
|
// capabilities derived from Patches so callers no longer match raw patch filenames (§5.2).
|
|
func (m Manifest) EffectiveCapabilities() []string {
|
|
seen := make(map[string]bool, len(m.Capabilities)+len(m.Patches))
|
|
var out []string
|
|
add := func(c string) {
|
|
c = strings.TrimSpace(c)
|
|
if c != "" && !seen[c] {
|
|
seen[c] = true
|
|
out = append(out, c)
|
|
}
|
|
}
|
|
for _, c := range m.Capabilities {
|
|
add(c)
|
|
}
|
|
for _, p := range m.Patches {
|
|
low := strings.ToLower(p.Name)
|
|
switch {
|
|
case strings.Contains(low, "nested-virt-nonfatal"):
|
|
add("nested-virt-nonfatal")
|
|
case strings.Contains(low, "startup-ipis"):
|
|
add("win10-startup-ipis")
|
|
case strings.Contains(low, "win10-compat"):
|
|
add("win10-compat")
|
|
case strings.Contains(low, "coroutine-fiber"):
|
|
add("win32-coroutine-fiber")
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// HasCapability reports whether the runtime declares or infers capability capName.
|
|
func (m Manifest) HasCapability(capName string) bool {
|
|
for _, c := range m.EffectiveCapabilities() {
|
|
if strings.EqualFold(c, capName) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// CheckCompatibility verifies that an installed runtime matches a driver's
|
|
// required runtime kind and runtime_api SemVer range (§5.2).
|
|
func CheckCompatibility(requiredKind, requiredAPIRange string, inst Installed) error {
|
|
if requiredKind == "" {
|
|
requiredKind = DefaultKind
|
|
}
|
|
gotKind := inst.Manifest.EffectiveKind()
|
|
if inst.Kind != "" {
|
|
gotKind = inst.Kind
|
|
}
|
|
if !strings.EqualFold(gotKind, requiredKind) {
|
|
return fmt.Errorf("runtime kind mismatch: driver requires %q, installed runtime %s is %q", requiredKind, inst.Commit, gotKind)
|
|
}
|
|
if strings.TrimSpace(requiredAPIRange) != "" {
|
|
gotAPI := inst.Manifest.EffectiveRuntimeAPI()
|
|
if !plugin.MatchesRange(gotAPI, requiredAPIRange) {
|
|
return fmt.Errorf("incompatible runtime_api: driver requires %s, runtime %s (%s) provides %s", requiredAPIRange, inst.Commit, gotKind, gotAPI)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateThirdPartyProvenance enforces GPL/compliance provenance rules for
|
|
// third-party runtime packages (§5.2): must declare license and source archive,
|
|
// and cannot enter the official "stable" channel.
|
|
func ValidateThirdPartyProvenance(m Manifest) error {
|
|
if strings.EqualFold(m.Channel, "stable") {
|
|
return errors.New("third-party runtime packages cannot claim the official stable channel")
|
|
}
|
|
if strings.TrimSpace(m.License) == "" {
|
|
return errors.New("third-party runtime manifest missing license declaration")
|
|
}
|
|
if strings.TrimSpace(m.SourcePackage) == "" {
|
|
return errors.New("third-party runtime manifest missing source_package (required for GPL compliance)")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ListByKind returns installed runtimes matching kind.
|
|
func ListByKind(cfg *config.Config, kind string) ([]Installed, error) {
|
|
all, err := List(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if kind == "" {
|
|
return all, nil
|
|
}
|
|
var out []Installed
|
|
for _, item := range all {
|
|
k := item.Kind
|
|
if k == "" {
|
|
k = item.Manifest.EffectiveKind()
|
|
}
|
|
if strings.EqualFold(k, kind) {
|
|
out = append(out, item)
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// ResolveForKind returns the active runtime for kind, falling back to the
|
|
// newest installed runtime of that kind when only one exists (or for non-default kinds).
|
|
func ResolveForKind(cfg *config.Config, kind string) (*Installed, error) {
|
|
if kind == "" {
|
|
kind = DefaultKind
|
|
}
|
|
list, err := ListByKind(cfg, kind)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for i := range list {
|
|
if list[i].Commit == cfg.ActiveRuntime || (kind+"/"+list[i].Commit) == cfg.ActiveRuntime {
|
|
return &list[i], nil
|
|
}
|
|
}
|
|
if len(list) == 1 || (kind != DefaultKind && len(list) > 0) {
|
|
return &list[0], nil
|
|
}
|
|
return nil, fmt.Errorf("no active %s runtime installed", kind)
|
|
}
|