Rust device-side agent for managed workstations, edge devices, and IoT stations.
CC-rDeviceAgent adopts a dual-sided, three-layer architecture β facing the management backend northbound and payload applications southbound. The three layers are: Protocol Layer, Core Services Layer, and Platform Abstraction Layer (PAL). The goal is a lightweight, secure, cross-platform device agent that provides both device management capabilities (L1) and application platform capabilities (L2).
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CC-rDeviceAgent (Process) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Protocol Layer β β
β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β β
β β β gRPC β β MQTT β β OTLP β β gRPC β β β
β β β North β β Client β β Receiver β β South β β β
β β β (mTLS) β β β β β β (UDS) β β β
β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Core Services β β
β β β β
β β Device Management: β β
β β Control Service Β· File Transfer Β· Upgrade Engine Β· β β
β β Config Manager Β· Telemetry Pipeline β β
β β β β
β β Application Platform: β β
β β App Registry Β· App Lifecycle Β· Data Router Β· β β
β β Config Watcher Β· Update Notifier β β
β β β β
β β Cross-cutting: β β
β β Security Center Β· Audit Chain Β· Observability Hub Β· β β
β β Scheduler/Quota Β· State Store (SQLite) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Platform Abstraction Layer (PAL) β β
β β β β
β β ProcessMgr Β· FileSystem Β· Network Β· KeyStore Β· Bootloader Β· β β
β β Sandbox Β· SensorReader Β· PowerMgr Β· ServiceMgr Β· TimeSource β β
β β β β
β β Implementations: Linux Β· Windows Β· macOS Β· Embedded Β· Mock β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
OS / Hardware / External Systems
See doc/architecture-zh.md for detailed architecture design.
The main service exposes two protobuf services:
StationControl- start, stop, and restart processes
- reboot or shut down the host
- return system state, process lists, network interfaces, TCP/UDP listeners, and version info
- execute shell commands with a timeout
- update watched process names and the in-memory state gathering interval
- return the telemetry schema and replace MQTT telemetry profiles at runtime
- proxy
CaptureScreenrequests to the desktop agent
FileTransfer- upload files as streamed chunks
- download files as streamed chunks
The service listens on control.listen_addr, which is 0.0.0.0:50051 in the sample config.
The desktop capture path is implemented in the desktop agent gRPC service:
- binds only to loopback using
agent.listen_addr - requires the
x-cc-agent-tokenheader to matchagent.auth_token - captures the configured display index and streams PNG chunks back to the service
- caches the latest capture so interrupted downloads can resume by byte offset
- on Linux, retries via
grimwhen the primary screenshot path fails
CaptureScreen on the main service is only a proxy. The privileged service does not
capture the desktop directly.
When mqtt.enabled = true, the service can:
- publish station status to
cc/<station_id>/status - publish telemetry bundles to
cc/<station_id>/telemetry - subscribe to
cc/<station_id>/command - publish command acknowledgements to
cc/<station_id>/command/ack
The currently implemented MQTT command handler supports restart_process with a
process_name parameter.
Telemetry profiles are validated and normalized from configuration or replaced at runtime through gRPC. The supported telemetry include keys are:
runtime_basicruntime_systemruntime_appsruntime_networkruntime_storage
If no telemetry profiles are configured, the service synthesizes a default profile that includes all of the sections above and uses the service state interval.
| Gap | Severity | Target |
|---|---|---|
| No platform abstraction layer (PAL) | π΄ High | Phase 0 |
| No Upgrade Engine (OTA) | π΄ High | Phase 2-3 |
| No Security Center / mTLS | π΄ High | Phase 1 |
| No Audit Chain | π΄ High | Phase 1 |
| No App Registry / Lifecycle | π΄ High | Phase 2 |
| No Config Manager | π‘ Medium | Phase 2 |
| No unit tests or CI | π‘ Medium | Phase 0 |
See doc/action_plan-v2.0-zh.md for the full action plan.
Phase -1 (v0.4) Architecture gap analysis & fixes 2 weeks β Current
Phase 0 (v0.5) Foundation + PAL complete contracts 5 weeks
Phase 1 (v0.8) Security hardening 6 weeks
Phase 2 (v1.0) Application platform + OTA design 8 weeks
Phase 3 (v1.5) Full OTA upgrade 10 weeks
Phase 4 (v2.0) Platformization 10 weeks
Phase 5 (v2.1) Production readiness 6 weeks
| Phase | Version | Focus | Key deliverables |
|---|---|---|---|
| -1 | v0.4 | Architecture gap analysis | Migration design, CI pipeline, clean baseline |
| 0 | v0.5 | Foundation + PAL | Full PAL traits, Linux adapter, State Store, CapabilityProfile |
| 1 | v0.8 | Security | mTLS, KeyStore, RBAC, Audit Chain, Sandbox, command whitelist |
| 2 | v1.0 | Application platform | IPC, App Registry, Lifecycle, Config Manager, OTA design |
| 3 | v1.5 | OTA upgrade | A/B slot, Agent self-update, fault injection tests |
| 4 | v2.0 | Platformization | Multi-tenant, canary release, extension points |
| 5 | v2.1 | Production readiness | SLA validation, security audit, documentation |
The PAL is the architectural foundation for cross-platform support. It abstracts all
platform-specific operations behind Rust traits, ensuring business code is completely
platform-independent (no #[cfg(target_os)] in business logic).
| Trait | Linux | Windows | macOS |
|---|---|---|---|
| ProcessManager | fork/exec + cgroup v2 | CreateProcess + Job Object | posix_spawn + rlimit |
| ServiceManager | systemd D-Bus | SCM API | launchd |
| KeyStore | TPM 2.0 / pkcs11 | DPAPI / CNG | Keychain / SEP |
| BootloaderAdapter | RAUC / U-Boot | UEFI BCD | N/A (limited) |
| SandboxRunner | seccomp + namespace | Job Object + AppContainer | sandbox-exec |
| FileSystem | libc + statvfs | Win32 File API | libc + APFS |
| NetworkProbe | netlink | IP Helper API | SystemConfig |
| IpcServer | Unix Socket | Named Pipe | Unix Socket |
| SystemLogger | journald | EventLog | unified log |
On startup, agent probes platform capabilities and generates a CapabilityProfile:
CapabilityProfile {
has_tpm: bool,
has_ab_partition: bool,
has_cgroup_v2: bool,
has_secure_boot: bool,
storage_writable_mb: u64,
// ...
}Business logic uses this profile to decide which implementation to use at runtime, with automatic fallback to degraded modes when advanced capabilities are unavailable.
See doc/PAL-arch-dd-zh.md for the full PAL design.
The OTA upgrade engine implements a 14-state state machine with A/B slot switching, designed for zero-brick reliability.
Idle β Received β Validated β Downloading β Verifying β PreCheck β
Staging β ReadyToActivate β Activating β PostCheck β Committed
β
RollingBack β RolledBack β Failed
- Atomicity: Upgrade either fully succeeds or fully rolls back
- Crash recovery: State persisted to SQLite with WAL mode; resume from breakpoint on restart
- Health gates: Each critical state has health checks as gates; auto rollback on failure
- Trial mode: Bootloader
boot_countmechanism; auto-fallback after N failed boots - A/B slots: New version written to inactive slot; bootloader switches on activation
- Signature verification: Ed25519 signatures with anti-rollback version protection
| Type | Scope | Reboot required | Rollback mechanism |
|---|---|---|---|
| System | OS image / kernel / rootfs | Yes (slot switch) | Bootloader fallback |
| Agent | Agent binary self-update | Yes (process replace) | Updater binary fallback |
| Application | Business app binaries | Usually no | Backup directory restore |
| Config | Configuration files | No (hot reload) | Version history rollback |
See doc/OTA-statemachine-detail-design-zh.md for the complete state machine design.
By default, the service loads CC-rDeviceAgent.toml from the executable directory.
If service.station_id is blank, the service resolves it to <hostname>-<uuid>.
[service]
service_name = "CC-rDeviceAgent"
station_id = "station-01"
state_interval_seconds = 5
watched_processes = []
udp_display_target = "127.0.0.1:9008"
launcher_proxy_path = ""
[control]
listen_addr = "0.0.0.0:50051"
[agent]
listen_addr = "127.0.0.1:50052"
auth_token = "local-change-me"
preferred_display_index = 0
[mqtt]
enabled = true
broker_host = "localhost"
broker_port = 1883
telemetry_enabled = true
status_enabled = trueThe sample config continues with mqtt.telemetry_profiles, which define
profile IDs, names, collection intervals, and include sets.
Three-layer configuration model (planned):
Device-level (not app-modifiable) β Agent-level β App-level (per app)
The main binary is cc-rdeviceagent.
Supported CLI arguments:
foregroundor--foregrounddaemonor--daemon--config <path>--console-telemetryor--telemetry-console
Platform behavior:
- Windows auto mode first attempts to run as an SCM service
- Unix auto mode daemonizes unless
foregroundis requested - shutdown is handled through Ctrl+C and OS service signals
Build the workspace:
cargo build --releaseRun the service in the foreground:
./target/release/cc-rdeviceagent foreground --config ./CC-rDeviceAgent.tomlThe repository also contains a desktop agent implementation used by the Linux and
Windows packaging scripts and by the smoke test. Those scripts expect a companion
binary named cc-rdeviceagent-agent built alongside the service.
For local debugging, you can mirror runtime telemetry to stdout:
./target/release/cc-rdeviceagent foreground --config ./CC-rDeviceAgent.toml --console-telemetryThe crate also contains library modules for scripts, tags, groups, batch execution, alerts, and plugin abstractions. Those modules are present in the source tree, but the current service entry point is centered on gRPC station control, file transfer, telemetry collection, MQTT publishing, and desktop capture proxying.
agent-core/ Business core (Control, FileXfer, Upgrade, Config, Telemetry)
agent-protocols/ North/South protocol definitions (Protobuf, OTLP)
pal-core/ PAL trait contracts + assembly framework
pal-linux/ Linux adapter implementation
pal-windows/ Windows adapter implementation
pal-macos/ macOS adapter implementation
pal-fallback/ Cross-platform fallback implementations
pal-mock/ Testing mock implementations
agent-telemetry/ Telemetry pipeline (Collector β Processor β Exporter)
agent-store/ State Store (SQLite + WAL)
agent-cli/ CLI entry point
- Linux install artifacts:
packaging/linux - Windows install artifacts:
packaging/windows - Docker IoT simulation image:
packaging/docker/Dockerfile.iot-sim
The install scripts:
- copy the service and desktop-agent binaries
- install
CC-rDeviceAgent.toml - generate and stamp a shared
agent.auth_token - register the service with
systemdor SCM - register the desktop agent as a user service or scheduled task
The simulator launcher is kept in the management-side CC repository because it also
manages broker and log paths. With sibling checkouts, run it from CC:
cd ../CC
./scripts/start-iot-sim.sh 10The launcher builds a minimal runtime image for cc-rdeviceagent, starts a Mosquitto
broker, and launches headless stations such as iot-001, iot-002, and iot-003.
Useful commands:
./scripts/start-iot-sim.sh --status
./scripts/start-iot-sim.sh --stop
./scripts/start-iot-sim.sh 10 --dry-run./scripts/test-smoke.shOptional strict desktop-capture validation:
REQUIRE_CAPTURE=1 ./scripts/test-smoke.sh| Document | Description |
|---|---|
doc/architecture-zh.md |
System architecture design (dual-sided, three-layer) |
doc/PAL-arch-dd-zh.md |
Platform Abstraction Layer detailed design |
doc/OTA-statemachine-detail-design-zh.md |
OTA upgrade state machine detailed design |
doc/action_plan-v2.0-zh.md |
Action plan v2.0 (revised, with Phase -1) |
doc/action_plan-zh.md |
Action plan v1.0 (original) |
doc/requirements_v1.0-zh.md |
Requirements specification v1.0 |
doc/arch-migrate-zh.md |
Current-vs-target architecture migration analysis |
doc/review-v0.5-zh.md |
Code review of v0.5 |
doc/review-v1.0-dev-plan-zh.md |
Requirements assessment & dev plan review |
See LICENSE for details.