Command Palette
Search for a command to run...

power-manage-sdk

Overview

The SDK defines the contract between all power-manage components. Three layers:

  1. Protobuf definitions (proto/pm/v1/) — 6 proto files, 178 RPCs total.
  2. Generated code (gen/go/, gen/ts/) — Go + TypeScript stubs from buf generate.
  3. Capability library (27 Go packages) — dependency-injected system management.

Module path: github.com/manchtools/power-manage-sdk (Go 1.25).

Proto surface

File catalog

FileLinesContents
common.proto~120ActionId, DeviceId, ExecutionStatus (8 states), AssignmentMode (4 modes), shared enums
actions.proto~60023 action type messages + param oneofs: Shell, ScriptRun, Package, Update, Repository, Deb, RPM, AppImage, Flatpak, Service, File, Directory, Reboot, Sync, User, Group, SSH, SSHD, AdminPolicy, Encryption, WiFi, AgentUpdate, LPS
agent.proto~30AgentService with 3 RPCs: Stream (bidi), SyncActions, ValidateLuksToken
control.proto~2800ControlService with 164 RPCs across 20 domains
device_auth.proto~25DeviceAuthService with 2 RPCs: Enroll, GetEnrollmentStatus
internal.proto~250InternalService with 9 RPCs: VerifyDevice, ProxySyncActions, ProxyValidateLuksToken, ProxyGetLuksKey, ProxyStoreLuksKey, ProxyStoreLpsPasswords, ProxyValidateTerminalToken, ListGatewayTerminalSessions, TerminateGatewayTerminalSession

RPC distribution

ServiceRPCsAuth
ControlService164JWT (access + refresh, optional TOTP)
InternalService9mTLS (gateway client cert)
AgentService3mTLS (agent client cert)
DeviceAuthService2Registration token (Unix socket)
Total178

Proto conventions

  • Every field crossing a trust boundary carries @gotags validate:"..." tag. Required, ulid, min_len, max_len, gt, pattern, required_if constraints.
  • IDs are ULIDsstring value = 1 with validate:"required,ulid".
  • Enums start at 1 — proto3 requires 0 for unspecified default.
  • oneof for action parameters — 23 action types, each with its own params message inside a oneof field.
  • Backward compatibility enforced by buf breaking against main branch. Field numbers are frozen once released.

Generated code

Go (gen/go/pm/v1/)

Produces message structs with @gotags validate tags, Connect-RPC clients and handlers, and JSON/proto marshaling. Package pmv1.

TypeScript (gen/ts/pm/)

Produces ES module classes, Connect-RPC transport-agnostic clients (createPromiseClient), and TypeScript types. Uses @bufbuild/protoc-gen-es and @connectrpc/protoc-gen-connect-es.

Regeneration

cd sdk && make generate   # both Go and TypeScript

CI verifies regeneration produces no diff.

Capability library

27 Go packages organized by system domain. Every capability follows the injected shape: Runner + Backend → Manager.

Design principles

  1. Explicit over clever — the caller names the privilege tool (exec.Sudo, exec.Direct, exec.Doas) and backend (pkg.Apt, service.Systemd).
  2. No global state — backend selection lives on the instance.
  3. Testable without a hostFakeRunner asserts exact argv shapes.
  4. Mutations return exec.Result — stdout, stderr, exit code.

Package catalog

PackageFilesCapabilityBackends
pkg10Package managementApt, Dnf, Pacman, Zypper, Flatpak, AppImage, Deb, RPM
sys/exec9Command execution, privilege escalationSudo, Doas, Direct
sys/exec/exectest1Fake runner for tests
sys/service*Systemd service managementSystemd
sys/user*User/group managementShadowUtils (useradd, usermod, groupadd, etc.)
sys/encryption7LUKS disk encryptionCryptsetup, TPM
sys/network*Network configurationNetworkManager, Netplan, SystemdNetworkd, WPA Supplicant, IWD, ConnMan
sys/firewall6Firewall managementIptables, Nftables, Firewalld, UFW
sys/dns4DNS configurationSystemdResolved, Resolvconf, NetworkManager
sys/catrust3CA trust storeupdate-ca-trust, update-ca-certificates
sys/smart*Disk health (SMART)Smartctl
sys/antivirus3Antivirus scanningClamAV
sys/osquery*System introspectionOsqueryi
sys/inventory*Hardware/software inventoryDmidecode, Lscpu, Lspci, Lsblk, Lsscsi, etc.
sys/log*Log collectionJournalCtl
sys/notify*Desktop notificationsNotifySend
sys/desktop5Desktop environmentGnome, KDE (session listing, user run-as)
sys/timesync*Time synchronizationTimedatectl, Chronyc
sys/terminal*Remote terminal (PTY)Script
sys/remote*Remote desktopRDP, VNC
sys/reboot*System rebootSystemctl reboot, Shutdown
sys/fs*Filesystem operationsMkdir, Chown, Chmod, Copy, Remove
sys/repo*Repository managementApt sources, Dnf repos, Zypper repos, Pacman mirrors
sys/netconfig*Network interface configIp, Ethtool

Testing infrastructure

PackageFilesPurpose
sys/exec/exectest1FakeRunner — asserts argv shape, scripts stdout/stderr, injects errors
cryptotest1Crypto test helpers
archtest2Architecture fitness functions — circular imports, package layering, proto validation coverage
validate1Proto validation test helpers

Shared infrastructure

PackageFilesPurpose
crypto2Certificate generation (CSR), cert parsing, ULID generation
logging1Structured logging adapter (slog shim)
maintenance1Maintenance window data types + validation
verify3Signature verification utilities
client.go1Shared Connect-RPC client construction
url.go1URL parsing + validation

Adversarial testing

adversary/ package: attack simulations verifying protocol invariants — forged task HMAC, key substitution, cross-actor binding, replay, downgrade.

Container test strategy (proposed)

Multi-distro Docker stages in test/Dockerfile.{debian,fedora,opensuse,archlinux}. Each stage is a known system state (stale lock, degraded service, missing tools). Tests run real binaries against known states. See docs/02-concepts/02-backends.md.

Invariants

  1. Proto files are the source of truth. Generated code never hand-edited.
  2. Every proto field crossing a trust boundary has a validate tag.
  3. buf breaking must pass against main. Backward compatible.
  4. No global state in the capability library. All injected.
  5. Backend selection is explicit. Never auto-detect.
  6. All crypto calls carry domain-separation info tags.
  7. ULIDs for all identifiers. Never crypto.randomUUID().
  8. docref anchors for all exported symbols in SDK docs.
  9. Roundtrip tests for event payloads — byte-identical marshal/unmarshal.