Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Prepare v6.0.0 release candidate
rcourtmanbd6f77e093c6
diff --git a/.github/workflows/backfill-release-assets.yml b/.github/workflows/backfill-release-assets.ymlindex 5af93250cf..956c3ea8fc 100644--- a/.github/workflows/backfill-release-assets.yml+++ b/.github/workflows/backfill-release-assets.yml@@ -28,7 +28,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Install Syftdiff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.ymlindex aea82c65fc..1016a60a2e 100644--- a/.github/workflows/create-release.yml+++ b/.github/workflows/create-release.yml@@ -253,7 +253,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Run backend tests@@ -484,7 +484,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Build Pulse Docker image for integration tests@@ -583,7 +583,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Set up Node.js@@ -1008,7 +1008,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Install Syftdiff --git a/.github/workflows/deploy-demo-server.yml b/.github/workflows/deploy-demo-server.ymlindex 1018903291..c12bec632a 100644--- a/.github/workflows/deploy-demo-server.yml+++ b/.github/workflows/deploy-demo-server.yml@@ -82,7 +82,7 @@ jobs:- name: Set up Gouses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5with:- go-version: '1.25.9'+ go-version-file: go.modcache: true- name: Set up Node.jsdiff --git a/Dockerfile b/Dockerfileindex f01fb6ec3f..01a1bf2da2 100644--- a/Dockerfile+++ b/Dockerfile@@ -213,7 +213,8 @@ FROM alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6ARG TARGETARCHARG TARGETVARIANT-RUN apk --no-cache add ca-certificates tzdata+RUN apk --no-cache add ca-certificates tzdata && \+ mkdir -p /var/lib/pulse-agentWORKDIR /app@@ -234,9 +235,16 @@ RUN if [ "$TARGETARCH" = "arm64" ]; then \COPY --from=release-assets-builder /app/VERSION /VERSION-ENV PULSE_NO_AUTO_UPDATE=true+ENV PULSE_NO_AUTO_UPDATE=true \+ PULSE_DISABLE_AUTO_UPDATE=true \+ PULSE_ENABLE_HOST=false \+ PULSE_ENABLE_DOCKER=true \+ PULSE_AGENT_ID_FILE=/var/lib/pulse-agent/agent-id \+ PULSE_STATE_DIR=/var/lib/pulse-agent-ENTRYPOINT ["/usr/local/bin/pulse-agent", "--enable-docker", "--enable-host=false"]+VOLUME ["/var/lib/pulse-agent"]++ENTRYPOINT ["/usr/local/bin/pulse-agent"]# Base Pulse server runtime shared by self-hosted and hosted tenant images.FROM alpine:3.20@sha256:d9e853e87e55526f6b2917df91a2115c36dd7c696a35be12163d44e6e2a4b6bc AS pulse-runtime-basediff --git a/cmd/pulse-control-plane/provider_msp_preflight.go b/cmd/pulse-control-plane/provider_msp_preflight.goindex 756572fd2f..507b68bac0 100644--- a/cmd/pulse-control-plane/provider_msp_preflight.go+++ b/cmd/pulse-control-plane/provider_msp_preflight.go@@ -94,8 +94,8 @@ func runProviderMSPPreflightWithDependencies(ctx context.Context, cfg *cloudcp.Creport.Failures = append(report.Failures, fmt.Sprintf(format, args...))}- if !cfg.IsProviderHostedMSP() {- addFailure("CP_CONTROL_PLANE_MODE must be %s", cloudcp.ControlPlaneModeProviderHostedMSP)+ if !cfg.IsMSPControlPlane() {+ addFailure("CP_CONTROL_PLANE_MODE must be %s or %s", cloudcp.ControlPlaneModeProviderHostedMSP, cloudcp.ControlPlaneModePulseHostedMSP)}if cfg.UsesStripeBilling() {addFailure("provider-hosted MSP preflight must be Stripe-free")diff --git a/cmd/pulse-control-plane/provider_msp_preflight_test.go b/cmd/pulse-control-plane/provider_msp_preflight_test.goindex 34c93ca125..b4848c1899 100644--- a/cmd/pulse-control-plane/provider_msp_preflight_test.go+++ b/cmd/pulse-control-plane/provider_msp_preflight_test.go@@ -112,6 +112,40 @@ func TestProviderMSPPreflightPassesWithLicenseDockerAndStorage(t *testing.T) {}}+func TestProviderMSPPreflightAcceptsPulseHostedMSPMode(t *testing.T) {+ docker := &fakeProviderMSPPreflightDocker{+ report: &cpDocker.RuntimePrerequisiteReport{+ OK: true,+ DockerReachable: true,+ NetworkName: "pulse-provider-msp",+ NetworkOK: true,+ NetworkID: "network-test",+ ImageRef: "pulse:test",+ ImageID: "sha256:test",+ ImageAvailable: true,+ },+ }+ cfg := testProviderMSPPreflightConfig(t, cloudcp.ProviderMSPPlanSourceLicenseFile)+ cfg.ControlPlaneMode = cloudcp.ControlPlaneModePulseHostedMSP++ report, err := runProviderMSPPreflightWithDependencies(+ context.Background(),+ cfg,+ providerMSPPreflightOptions{},+ fakeProviderMSPPreflightDependencies(docker, &cloudcp.StorageGuardrailReport{Enabled: false, OK: true}),+ )++ if err != nil {+ t.Fatalf("runProviderMSPPreflightWithDependencies: %v", err)+ }+ if !report.OK {+ t.Fatalf("report.OK = false, failures = %v", report.Failures)+ }+ if report.ControlMode != string(cloudcp.ControlPlaneModePulseHostedMSP) {+ t.Fatalf("ControlMode = %q, want %q", report.ControlMode, cloudcp.ControlPlaneModePulseHostedMSP)+ }+}+func TestProviderMSPPreflightSkipImagePullUsesInspectOnly(t *testing.T) {docker := &fakeProviderMSPPreflightDocker{report: &cpDocker.RuntimePrerequisiteReport{diff --git a/cmd/pulse-control-plane/provider_msp_proof.go b/cmd/pulse-control-plane/provider_msp_proof.goindex f39d760146..6ad0fa0855 100644--- a/cmd/pulse-control-plane/provider_msp_proof.go+++ b/cmd/pulse-control-plane/provider_msp_proof.go@@ -153,8 +153,8 @@ func newProviderMSPProofRuntimeFromConfig(cfg *cloudcp.CPConfig) (*providerMSPPrif cfg == nil {return nil, fmt.Errorf("control plane config is required")}- if !cfg.IsProviderHostedMSP() {- return nil, fmt.Errorf("provider MSP proof requires CP_CONTROL_PLANE_MODE=%s", cloudcp.ControlPlaneModeProviderHostedMSP)+ if !cfg.IsMSPControlPlane() {+ return nil, fmt.Errorf("provider MSP proof requires CP_CONTROL_PLANE_MODE=%s or %s", cloudcp.ControlPlaneModeProviderHostedMSP, cloudcp.ControlPlaneModePulseHostedMSP)}if err := os.MkdirAll(cfg.TenantsDir(), 0o755); err != nil {return nil, fmt.Errorf("create tenants dir: %w", err)diff --git a/cmd/pulse-control-plane/provider_msp_proof_test.go b/cmd/pulse-control-plane/provider_msp_proof_test.goindex c47adc3bf7..3c2df80edb 100644--- a/cmd/pulse-control-plane/provider_msp_proof_test.go+++ b/cmd/pulse-control-plane/provider_msp_proof_test.go@@ -65,6 +65,22 @@ func TestProviderMSPProofRequiresLicenseBackedPlanSourceByDefault(t *testing.T)}}+func TestProviderMSPProofRuntimeAcceptsPulseHostedMSPMode(t *testing.T) {+ t.Setenv("DOCKER_HOST", "unix:///tmp/pulse-provider-msp-proof-missing-docker.sock")+ t.Setenv("DOCKER_TLS_VERIFY", "")+ t.Setenv("DOCKER_CERT_PATH", "")++ cfg := testProviderMSPProofConfig(t)+ cfg.ControlPlaneMode = cloudcp.ControlPlaneModePulseHostedMSP+ cfg.BaseURL = "https://acme.msp.pulserelay.pro"++ rt, err := newProviderMSPProofRuntimeFromConfig(cfg)+ if err != nil {+ t.Fatalf("newProviderMSPProofRuntimeFromConfig: %v", err)+ }+ defer rt.close()+}+func TestProviderMSPProofExercisesWorkspaceInstallHandoffAndIsolation(t *testing.T) {t.Setenv("DOCKER_HOST", "unix:///tmp/pulse-provider-msp-proof-missing-docker.sock")t.Setenv("DOCKER_TLS_VERIFY", "")diff --git a/deploy/provider-msp/.env.example b/deploy/provider-msp/.env.exampleindex 1fb654eb04..34dc41bfe7 100644--- a/deploy/provider-msp/.env.example+++ b/deploy/provider-msp/.env.example@@ -1,4 +1,7 @@# Domain+# Client runtimes are routed as https://<client-id>.${DOMAIN}/.+# Provider-hosted MSP: use the MSP's own domain, for example pulse.example-msp.com.+# Pulse-hosted MSP: use a Pulse-operated provider namespace, for example example-msp.msp.pulserelay.pro, and set CP_CONTROL_PLANE_MODE=pulse_hosted_msp.DOMAIN=msp.example.com@@ -13,6 +16,7 @@ CP_PULSE_IMAGE=ghcr.io/rcourtman/pulse@sha256:<pin># Control planeCP_ENV=production+CP_CONTROL_PLANE_MODE=provider_hosted_mspCP_ADMIN_KEY=PULSE_PROVIDER_MSP_DATA_DIR=/dataPULSE_PROVIDER_MSP_DOCKER_NETWORK=pulse-provider-mspdiff --git a/deploy/provider-msp/docker-compose.yml b/deploy/provider-msp/docker-compose.ymlindex 19679b9426..eaa6714295 100644--- a/deploy/provider-msp/docker-compose.yml+++ b/deploy/provider-msp/docker-compose.yml@@ -53,7 +53,7 @@ services:environment:- CP_DATA_DIR=${PULSE_PROVIDER_MSP_DATA_DIR:-/data}- CP_ENV=${CP_ENV}- - CP_CONTROL_PLANE_MODE=provider_hosted_msp+ - CP_CONTROL_PLANE_MODE=${CP_CONTROL_PLANE_MODE:-provider_hosted_msp}- CP_BIND_ADDRESS=0.0.0.0- CP_PORT=8443- CP_ADMIN_KEY=${CP_ADMIN_KEY}diff --git a/docs/TEMPERATURE_MONITORING.md b/docs/TEMPERATURE_MONITORING.mdindex 33763b14e5..68b45e1911 100644--- a/docs/TEMPERATURE_MONITORING.md+++ b/docs/TEMPERATURE_MONITORING.md@@ -77,29 +77,18 @@ ssh -i /path/to/key root@node "cat /sys/class/thermal/thermal_zone0/temp"## Legacy Cleanup (If Upgrading)-If you still have the old sensor proxy installed from prior releases, remove it from each **Proxmox host** (not the Pulse container):+If you still have the old sensor proxy installed from prior releases, remove it from each **Proxmox host** (not the Pulse container) with the supported cleanup helper:```bash-# Stop and disable all sensor-proxy systemd units-sudo systemctl disable --now pulse-sensor-proxy pulse-sensor-proxy-selfheal.timer pulse-sensor-proxy-selfheal.service pulse-sensor-cleanup.path pulse-sensor-cleanup.service 2>/dev/null--# Remove systemd unit files-sudo rm -f /etc/systemd/system/pulse-sensor-proxy.service-sudo rm -f /etc/systemd/system/pulse-sensor-proxy-selfheal.timer-sudo rm -f /etc/systemd/system/pulse-sensor-proxy-selfheal.service-sudo rm -f /etc/systemd/system/pulse-sensor-cleanup.service-sudo rm -f /etc/systemd/system/pulse-sensor-cleanup.path-sudo systemctl daemon-reload--# Remove sensor-proxy files-sudo rm -rf /opt/pulse/sensor-proxy-sudo rm -rf /etc/pulse-sensor-proxy-sudo rm -rf /var/lib/pulse-sensor-proxy-sudo rm -rf /var/log/pulse/sensor-proxy-sudo rm -rf /run/pulse-sensor-proxy--# Optional: remove sensor-proxy SSH keys from authorized_keys-sudo sed -i '/# pulse-managed-key$/d;/# pulse-proxy-key$/d' /root/.ssh/authorized_keys+curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/uninstall-sensor-proxy.sh | \+ sudo bash -s -- --uninstall --purge+```++If you also want to remove the old `pulse-monitor@pam` API user and tokens before re-adding the node, include `--remove-proxmox-access`:++```bash+curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/uninstall-sensor-proxy.sh | \+ sudo bash -s -- --uninstall --purge --remove-proxmox-access```Reinstalling or upgrading the Pulse container does **not** remove the sensor proxy from the host — they are separate installations. If you skip this cleanup, the selfheal timer will keep running and may generate recurring `TASK ERROR` entries in the Proxmox task log.diff --git a/docs/UPGRADE_v5.md b/docs/UPGRADE_v5.mdindex 2a9273cc99..f133a3d8da 100644--- a/docs/UPGRADE_v5.md+++ b/docs/UPGRADE_v5.md@@ -57,7 +57,16 @@ If you reset auth (for example by deleting `.env`), Pulse may require a bootstra### Sensor proxy removal-The `pulse-sensor-proxy` from v4 is no longer needed — temperature monitoring is now handled by the unified agent. If you had the sensor proxy installed on your Proxmox hosts, remove it **on each host** after upgrading. See the [Legacy Cleanup](TEMPERATURE_MONITORING.md#legacy-cleanup-if-upgrading) section in the temperature monitoring docs for the full cleanup commands.+The `pulse-sensor-proxy` from v4 is no longer needed — temperature monitoring is now handled by the unified agent. If you had the sensor proxy installed on your Proxmox hosts, remove it **on each host** after upgrading:++```bash+curl -fsSL https://raw.githubusercontent.com/rcourtman/Pulse/main/scripts/uninstall-sensor-proxy.sh | \+ sudo bash -s -- --uninstall --purge+```++If you deleted the old node from Pulse and want the cleanup to also remove the old `pulse-monitor@pam` API user and tokens before reinstalling, add `--remove-proxmox-access`.++See the [Legacy Cleanup](TEMPERATURE_MONITORING.md#legacy-cleanup-if-upgrading) section in the temperature monitoring docs for the full cleanup details.Skipping this step will leave a selfheal timer running on the host that generates recurring `TASK ERROR` entries in the Proxmox task log.diff --git a/docs/UPGRADE_v6.md b/docs/UPGRADE_v6.mdindex 39daa5ee62..5f4f0a0add 100644--- a/docs/UPGRADE_v6.md+++ b/docs/UPGRADE_v6.md@@ -96,8 +96,8 @@ servers.### Can I keep Pulse v5 stable while I test Pulse v6?-Pulse v5 entered maintenance-only support on `2026-06-03` and remains eligible-only for critical maintenance fixes until `2026-09-01`.+Pulse v5 entered maintenance-only support on `2026-06-04` and remains eligible+only for critical maintenance fixes until `2026-09-02`.If you want extra caution, use a staging or otherwise controlled upgrade firstand keep a rollback path available, but v6 is now the supported stable line.diff --git a/docs/architecture/v6-pricing-and-tiering.md b/docs/architecture/v6-pricing-and-tiering.mdindex 74945d0a0e..4fe48f920c 100644--- a/docs/architecture/v6-pricing-and-tiering.md+++ b/docs/architecture/v6-pricing-and-tiering.md@@ -529,7 +529,7 @@ explain monitored-system identity:| Date | Change | Author ||---|---|---|-| 2026-06-02 | Reconciled MSP pricing evidence with the provider-hosted model: signed MSP license, Stripe-free provider control plane, isolated Pulse runtime per client, 5/15/40 client workspace caps, and request-assisted access until launch approval. | Richard |+| 2026-06-02 | Reconciled MSP pricing evidence with the provider-operated architecture: signed MSP license, Stripe-free provider control plane, isolated Pulse runtime per client, 5/15/40 client workspace caps, and request-assisted access until launch approval. | Richard || 2026-04-29 | Replaced stale capacity-style monitoring phrasing with core-monitoring-included language across active v6 docs and upgrade-return copy so Community does not read like a former capacity upsell. | Codex || 2026-04-23 | Removed stale self-hosted monitored-system capacity and Pro+ public-checkout language. Reaffirmed Community / Relay / Pro as current public self-hosted tiers, with Pro+ as continuity only and Pro value centered on operations, history, and admin controls. | Codex || 2026-03-17 | Re-locked the self-hosted commercial model around monitored systems rather than installed agents. New self-hosted public pricing: Relay $4.99/$39, Pro $8.99/$79, Pro+ $14.99/$129. Added free-tier grace policy and marked the monitored-system counting migration as still required in code. | Codex + Richard |diff --git a/docs/release-control/v6/internal/V5_MAINTENANCE_SUPPORT_POLICY.md b/docs/release-control/v6/internal/V5_MAINTENANCE_SUPPORT_POLICY.mdindex e533ec66cb..139763e08a 100644--- a/docs/release-control/v6/internal/V5_MAINTENANCE_SUPPORT_POLICY.md+++ b/docs/release-control/v6/internal/V5_MAINTENANCE_SUPPORT_POLICY.md@@ -64,8 +64,8 @@ These do not qualify as v5 maintenance work:The first stable `v6.0.0` release must publish this exact notice:-> Pulse v5 entered maintenance-only support on 2026-06-03. I will ship only+> Pulse v5 entered maintenance-only support on 2026-06-04. I will ship only> critical security, data-loss, licensing or billing blocker, installer or> updater failure, and safe migration blocker fixes for existing v5 users until-> 2026-09-01. After 2026-09-01, Pulse v5 is end-of-support and new fixes land+> 2026-09-02. After 2026-09-02, Pulse v5 is end-of-support and new fixes land> on v6 unless I publish an explicit exception.diff --git a/docs/release-control/v6/internal/records/rc-to-ga-promotion-readiness-blocked-2026-04-04.md b/docs/release-control/v6/internal/records/rc-to-ga-promotion-readiness-blocked-2026-04-04.mdindex 057c56719d..a087baa414 100644--- a/docs/release-control/v6/internal/records/rc-to-ga-promotion-readiness-blocked-2026-04-04.md+++ b/docs/release-control/v6/internal/records/rc-to-ga-promotion-readiness-blocked-2026-04-04.md@@ -20,8 +20,8 @@7. `docs/releases/RELEASE_NOTES_v6.md` and`docs/release-control/v6/internal/V5_MAINTENANCE_SUPPORT_POLICY.md` now carry thecurrently proposed exact dates for the eventual GA notice:- - `v6` GA date: `2026-06-03`- - `v5` end-of-support date: `2026-09-01`+ - `v6` GA date: `2026-06-04`+ - `v5` end-of-support date: `2026-09-02`8. There is still no governed `Release Dry Run` artifact or rehearsal recordexercising stable inputs for:- `version=6.0.0`@@ -30,10 +30,10 @@- the artifact-owned promotion channel for that rehearsal- the artifact-owned promoted prerelease tag for that rehearsal- the artifact-owned rollback target for that stable candidate- - `ga_date=2026-06-03`+ - `ga_date=2026-06-04`- an explicit `rollback_version`- the exact derived rollback command that artifact will publish- - `v5_eos_date=2026-09-01`+ - `v5_eos_date=2026-09-02`## Why The Gate Cannot Be Cleared Yet@@ -57,10 +57,10 @@ users would still be the first real cohort for the final promotion path.- an artifact-owned promoted prerelease tag matching that rehearsal- an artifact-owned rollback target for the stable candidate- the exact planned GA and v5 end-of-support dates for the publish notice- - `ga_date=2026-06-03`+ - `ga_date=2026-06-04`- an explicit stable `rollback_version`- the exact derived rollback command that artifact will publish- - `v5_eos_date=2026-09-01`+ - `v5_eos_date=2026-09-02`4. Capture the `rc-to-ga-rehearsal-summary` artifact and run URL.5. Materialize the final rehearsal record from that artifact withouthand-repairing any missing candidate tag, promoted prerelease tag, rollbackdiff --git a/docs/release-control/v6/internal/status.json b/docs/release-control/v6/internal/status.jsonindex c1ec4d204f..cf0f100aad 100644--- a/docs/release-control/v6/internal/status.json+++ b/docs/release-control/v6/internal/status.json@@ -6763,7 +6763,21 @@],"coverage_gaps": [],"candidate_lanes": [],- "work_claims": [],+ "work_claims": [+ {+ "id": "codex-v6-release-release-gate-known-rc-issue-closure-for-ga",+ "agent_id": "codex-v6-release",+ "summary": "Resolve current v5-to-v6 parity audit gaps that would regress known user-visible fixes before GA publication.",+ "target_id": "v6-product-lane-expansion",+ "claimed_at": "2026-06-04T11:23:28Z",+ "heartbeat_at": "2026-06-04T13:02:12Z",+ "expires_at": "2026-06-04T17:02:12Z",+ "work_item": {+ "kind": "release-gate",+ "id": "known-rc-issue-closure-for-ga"+ }+ }+ ],"open_decisions": [],"source_of_truth_file": "docs/release-control/v6/internal/SOURCE_OF_TRUTH.md","resolved_decisions": [diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.mdindex a6eff7a737..515173c985 100644--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md@@ -243,6 +243,13 @@ Stripe-free and avoids a cloud-control-plane report data path across clients.into each tenant container, but it must not collect report data or renderPDFs in the control plane. Tenant-local reporting and tenant-local licensingdecide whether that configured brand appears.+ `pulse_hosted_msp` is the Pulse-operated form of the same Stripe-free MSP+ control-plane family, not the public Pulse-hosted SaaS checkout path. It+ must share the license-backed MSP plan source, workspace limit policy,+ disabled public signup and Stripe billing routes, isolated tenant runtime+ networks, tenant-local report branding, and provider MSP operator commands+ with `provider_hosted_msp` while preserving its own control-plane mode value+ for status, backup manifests, and operational audit.10. `internal/cloudcp/provider_msp_backup.go` shared with `deployment-installability`: provider-hosted MSP backup is both a cloud-paid license/account/runtime continuity boundary and a deployment-installability recovery artifact boundary.License-backed provider MSP backups must include the signed MSP licensefile as a recovery artifact while exposing only license metadata in commanddiff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex 1a33213f23..f8bf55a8d1 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -175,6 +175,12 @@ TLS floor in the dynamic config.dry-run restore into a separate target data dir, dry-run failed-workspacerecovery, remove proof workspaces when requested, and report finaloperational status.+ The packaged provider MSP compose bundle defaults to+ `CP_CONTROL_PLANE_MODE=provider_hosted_msp`, but must allow+ `pulse_hosted_msp` as an operator override for Pulse-operated MSP stacks+ without forking the deployment artifact. Both modes use the same+ `provider-msp` command group, license-backed proof path, isolated client+ runtime containers, and runtime URL shape `https://<client-id>.${DOMAIN}/`.`deploy/provider-msp/run-install-proof.sh` is the compose-level operatorwrapper for that rehearsal. It must validate the provider `.env` and composeconfig, require a reachable Docker daemon, optionally pull the pinned@@ -514,9 +520,9 @@ TLS floor in the dynamic config.rollback target, exact GA date, and exact v5 end-of-support date alignedacross release notes, upgrade guidance, support policy, promotion records,and release-promotion resolver proof before workflow dispatch. For the- 2026-06-03 cutover candidate, that packet is+ 2026-06-04 cutover candidate, that packet is`promoted_from_tag=v6.0.0-rc.6`, `rollback_version=v5.1.34`,- `ga_date=2026-06-03`, and `v5_eos_date=2026-09-01`.+ `ga_date=2026-06-04`, and `v5_eos_date=2026-09-02`.That stable cut must also move the repo-root Docker compose default and`scripts/install-docker.sh` fallback from the final RC image tag to thestable `6.0.0` image tag in the same commit as `VERSION=6.0.0`.diff --git a/docs/releases/RELEASE_NOTES_v6.md b/docs/releases/RELEASE_NOTES_v6.mdindex f8249f34a9..4a107404bc 100644--- a/docs/releases/RELEASE_NOTES_v6.md+++ b/docs/releases/RELEASE_NOTES_v6.md@@ -21,10 +21,10 @@ backend, the navigation shape you already know.## Pulse v5 Support Transition-Pulse v5 entered maintenance-only support on `2026-06-03`.+Pulse v5 entered maintenance-only support on `2026-06-04`.I will ship only critical security, data-loss, licensing or billing blocker,-installer or updater failure, and safe migration blocker fixes for existing v5 users until `2026-09-01`.-After `2026-09-01`, Pulse v5 is end-of-support and new fixes land on v6 unless+installer or updater failure, and safe migration blocker fixes for existing v5 users until `2026-09-02`.+After `2026-09-02`, Pulse v5 is end-of-support and new fixes land on v6 unlessI publish an explicit exception.## What Is In v6.0.0diff --git a/frontend-modern/public/docs/MIGRATION_UNIFIED_NAV.md b/frontend-modern/public/docs/MIGRATION_UNIFIED_NAV.mdindex 84cc2578a2..e8cb6f0555 100644--- a/frontend-modern/public/docs/MIGRATION_UNIFIED_NAV.md+++ b/frontend-modern/public/docs/MIGRATION_UNIFIED_NAV.md@@ -2,7 +2,7 @@> **This migration has been reverted as of `v6.0.0-rc.6`.** Pulse v6 ships> with the platform-shaped top-level navigation existing v5 operators-> already know (Proxmox, Docker, Kubernetes, TrueNAS, vSphere, Standalone,+> already know (Proxmox, Docker, Kubernetes, TrueNAS, vSphere, Machines,> plus Alerts, Patrol, and Settings). The unified> `/infrastructure` / `/workloads` / `/storage` / `/recovery` layout that> briefly shipped across `rc.1` through `rc.5` is retired. The unified@@ -21,7 +21,7 @@> The keyboard shortcuts follow the platform-shaped shape:>> - `g p` Proxmox, `g d` Docker, `g k` Kubernetes, `g n` TrueNAS,-> `g v` vSphere, `g s` Standalone+> `g v` vSphere, `g s` Machines> - `g a` Alerts, `g r` Patrol, `g t` Settings, `?` shortcuts help>> The "Classic shortcuts" bar referenced in the historical content belowdiff --git a/frontend-modern/src/api/dockerMetadata.ts b/frontend-modern/src/api/dockerMetadata.tsnew file mode 100644index 0000000000..9acf46ee48--- /dev/null+++ b/frontend-modern/src/api/dockerMetadata.ts@@ -0,0 +1,26 @@+import { buildMetadataAPI, type ResourceMetadataRecord } from './metadataClient';++export interface DockerMetadata extends ResourceMetadataRecord {}++const dockerMetadataAPI = buildMetadataAPI<DockerMetadata>('/api/docker/metadata');++export class DockerMetadataAPI {+ static async getMetadata(resourceId: string): Promise<DockerMetadata> {+ return dockerMetadataAPI.getMetadata(resourceId);+ }++ static async getAllMetadata(): Promise<Record<string, DockerMetadata>> {+ return dockerMetadataAPI.getAllMetadata();+ }++ static async updateMetadata(+ resourceId: string,+ metadata: Partial<DockerMetadata>,+ ): Promise<DockerMetadata> {+ return dockerMetadataAPI.updateMetadata(resourceId, metadata);+ }++ static async deleteMetadata(resourceId: string): Promise<void> {+ await dockerMetadataAPI.deleteMetadata(resourceId);+ }+}diff --git a/frontend-modern/src/components/Discovery/DiscoveryTab.tsx b/frontend-modern/src/components/Discovery/DiscoveryTab.tsxindex 5e4220a691..d0cdace8d0 100644--- a/frontend-modern/src/components/Discovery/DiscoveryTab.tsx+++ b/frontend-modern/src/components/Discovery/DiscoveryTab.tsx@@ -2,6 +2,7 @@ import { Component, For, Show, createMemo } from 'solid-js';import CheckIcon from 'lucide-solid/icons/check';import CopyIcon from 'lucide-solid/icons/copy';import ExternalLinkIcon from 'lucide-solid/icons/external-link';+import TriangleAlertIcon from 'lucide-solid/icons/triangle-alert';import type { ResourceType } from '../../types/discovery';import {formatDiscoveryAge,@@ -97,6 +98,7 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {connectedAgents,copiedDiscoveryValue,discovery,+ discoveryFeatureKnownDisabled,discoveryInfo,editingNotes,handleCopyDiscoveryValue,@@ -162,86 +164,164 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {// via CSS inheritance, so explanatory copy and command descriptions wrap.return (<div class="space-y-4 whitespace-normal">- {/* Analysis provider badge - shown when a provider is configured */}- <Show when={!discoveryInfo.loading && discoveryInfo()?.ai_provider}>- <div class="flex items-center gap-2">- <Show- when={discoveryInfo()?.ai_provider?.is_local}- fallback={- <span class={getDiscoveryAnalysisProviderBadgeClass(false)}>- {/* Cloud icon */}+ <Show when={discoveryFeatureKnownDisabled()}>+ <div class="rounded border border-amber-200 bg-amber-50/80 p-3 shadow-sm dark:border-amber-800/50 dark:bg-amber-900/20">+ <div class="flex items-start gap-2.5">+ <TriangleAlertIcon class="mt-0.5 h-4 w-4 flex-shrink-0 text-amber-600 dark:text-amber-400" />+ <div class="text-xs text-amber-800 dark:text-amber-200">+ <p class="mb-1 font-medium">AI Discovery Disabled</p>+ <p class="text-amber-700 dark:text-amber-300">+ Enable infrastructure discovery in Settings -> AI before using this tab.+ </p>+ </div>+ </div>+ </div>+ </Show>++ <Show when={!discoveryFeatureKnownDisabled()}>+ {/* Analysis provider badge - shown when a provider is configured */}+ <Show when={!discoveryInfo.loading && discoveryInfo()?.ai_provider}>+ <div class="flex items-center gap-2">+ <Show+ when={discoveryInfo()?.ai_provider?.is_local}+ fallback={+ <span class={getDiscoveryAnalysisProviderBadgeClass(false)}>+ {/* Cloud icon */}+ <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"+ />+ </svg>+ Analysis: {discoveryInfo()?.ai_provider?.label}+ </span>+ }+ >+ <span class={getDiscoveryAnalysisProviderBadgeClass(true)}>+ {/* Server/local icon */}<svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><pathstroke-linecap="round"stroke-linejoin="round"stroke-width="2"- d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"+ d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"/></svg>Analysis: {discoveryInfo()?.ai_provider?.label}</span>- }- >- <span class={getDiscoveryAnalysisProviderBadgeClass(true)}>- {/* Server/local icon */}- <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"- />- </svg>- Analysis: {discoveryInfo()?.ai_provider?.label}- </span>- </Show>- </div>- </Show>+ </Show>+ </div>+ </Show>- <Show when={showManualRunAction()}>- <div class="rounded border border-border bg-surface p-3 shadow-sm">- <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">- <div>- <div class="text-xs font-medium text-base-content">Discovery run</div>- <p class="mt-0.5 text-xs text-muted">{manualRunSummary()}</p>+ <Show when={showManualRunAction()}>+ <div class="rounded border border-border bg-surface p-3 shadow-sm">+ <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">+ <div>+ <div class="text-xs font-medium text-base-content">Discovery run</div>+ <p class="mt-0.5 text-xs text-muted">{manualRunSummary()}</p>+ </div>+ <button+ type="button"+ onClick={() => handleTriggerDiscovery(true)}+ disabled={isScanning() || !canTriggerDiscovery()}+ class="inline-flex min-h-9 items-center justify-center gap-1.5 rounded border border-border bg-surface px-3 py-1.5 text-xs font-medium text-base-content transition-colors hover:bg-surface-hover disabled:cursor-not-allowed disabled:opacity-50"+ >+ <Show+ when={isScanning()}+ fallback={+ <>+ <svg+ class="h-3.5 w-3.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"+ />+ </svg>+ Run Discovery+ </>+ }+ >+ <span class="h-3.5 w-3.5 animate-spin rounded-full border-2 border-slate-500 border-t-transparent" />+ Scanning...+ </Show>+ </button></div>- <button- type="button"- onClick={() => handleTriggerDiscovery(true)}- disabled={isScanning() || !canTriggerDiscovery()}- class="inline-flex min-h-9 items-center justify-center gap-1.5 rounded border border-border bg-surface px-3 py-1.5 text-xs font-medium text-base-content transition-colors hover:bg-surface-hover disabled:cursor-not-allowed disabled:opacity-50"- >- <Show- when={isScanning()}- fallback={- <>- <svg class="h-3.5 w-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"- />- </svg>- Run Discovery- </>- }+ </div>+ </Show>++ {/* "What Discovery Does" explanation - shown when no discovery exists yet */}+ <Show when={!discovery() && !isScanning() && !showLoadingSpinner() && showExplanation()}>+ <div class="rounded border border-amber-200 bg-amber-50 p-3 shadow-sm dark:border-amber-800 dark:bg-amber-900">+ <div class="flex items-start justify-between gap-3">+ <div class="flex items-start gap-2.5">+ <svg+ class="w-4 h-4 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"+ />+ </svg>+ <div class="text-xs text-amber-800 dark:text-amber-200">+ <p class="font-medium mb-1">What Discovery Does</p>+ <p class="text-amber-700 dark:text-amber-300">{DISCOVERY_ANALYSIS_EXPLANATION}</p>+ </div>+ </div>+ <button+ onClick={() => setShowExplanation(false)}+ class="text-amber-500 hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300 flex-shrink-0"+ title="Dismiss">- <span class="h-3.5 w-3.5 animate-spin rounded-full border-2 border-slate-500 border-t-transparent" />- Scanning...- </Show>- </button>+ <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M6 18L18 6M6 6l12 12"+ />+ </svg>+ </button>+ </div></div>- </div>- </Show>+ </Show>- {/* "What Discovery Does" explanation - shown when no discovery exists yet */}- <Show when={!discovery() && !isScanning() && !showLoadingSpinner() && showExplanation()}>- <div class="rounded border border-amber-200 bg-amber-50 p-3 shadow-sm dark:border-amber-800 dark:bg-amber-900">- <div class="flex items-start justify-between gap-3">- <div class="flex items-start gap-2.5">+ {/* Commands Preview - Expandable before first scan */}+ <Show+ when={+ !discovery() &&+ !isScanning() &&+ !discovery.loading &&+ !discoveryInfo.loading &&+ discoveryInfo()?.commands &&+ discoveryInfo()!.commands!.length > 0+ }+ >+ <details+ class="rounded border border-border bg-surface shadow-sm"+ open={showCommandsPreview()}+ >+ <summary+ class="p-2.5 text-xs font-medium text-base-content cursor-pointer hover:bg-surface-hover flex items-center gap-2"+ onClick={(e) => {+ e.preventDefault();+ setShowCommandsPreview(!showCommandsPreview());+ }}+ ><svg- class="w-4 h-4 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"+ class={`w-3.5 h-3.5 transition-transform ${showCommandsPreview() ? 'rotate-90' : ''}`}fill="none"viewBox="0 0 24 24"stroke="currentColor"@@ -250,823 +330,775 @@ export const DiscoveryTab: Component<DiscoveryTabProps> = (props) => {stroke-linecap="round"stroke-linejoin="round"stroke-width="2"- d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"+ d="M9 5l7 7-7 7"/></svg>- <div class="text-xs text-amber-800 dark:text-amber-200">- <p class="font-medium mb-1">What Discovery Does</p>- <p class="text-amber-700 dark:text-amber-300">{DISCOVERY_ANALYSIS_EXPLANATION}</p>+ Commands that will run ({discoveryInfo()?.commands?.length || 0})+ </summary>+ <Show when={showCommandsPreview()}>+ <div class="px-3 pb-3 space-y-2">+ <For each={discoveryInfo()?.commands}>+ {(cmd) => (+ <div class="text-xs">+ <div class="flex items-start gap-2">+ <code class="text-[10px] px-1.5 py-0.5 rounded bg-surface-hover text-base-content font-mono break-all">+ {cmd.command}+ </code>+ </div>+ <p class="text-muted mt-0.5 pl-0.5">{cmd.description}</p>+ </div>+ )}+ </For></div>- </div>- <button- onClick={() => setShowExplanation(false)}- class="text-amber-500 hover:text-amber-700 dark:text-amber-400 dark:hover:text-amber-300 flex-shrink-0"- title="Dismiss"- >- <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M6 18L18 6M6 6l12 12"- />- </svg>- </button>+ </Show>+ </details>+ </Show>++ {/* Loading state - delayed to prevent flash for fast loads */}+ <Show when={showLoadingSpinner()}>+ <div class="flex items-center justify-center py-8">+ <div class="animate-spin h-6 w-6 border-2 border-blue-500 border-t-transparent rounded-full"></div>+ <span class="ml-2 text-sm text-muted">{getDiscoveryLoadingState().text}</span></div>- </div>- </Show>+ </Show>- {/* Commands Preview - Expandable before first scan */}- <Show- when={- !discovery() &&- !isScanning() &&- !discovery.loading &&- !discoveryInfo.loading &&- discoveryInfo()?.commands &&- discoveryInfo()!.commands!.length > 0- }- >- <details- class="rounded border border-border bg-surface shadow-sm"- open={showCommandsPreview()}- >- <summary- class="p-2.5 text-xs font-medium text-base-content cursor-pointer hover:bg-surface-hover flex items-center gap-2"- onClick={(e) => {- e.preventDefault();- setShowCommandsPreview(!showCommandsPreview());- }}- >- <svg- class={`w-3.5 h-3.5 transition-transform ${showCommandsPreview() ? 'rotate-90' : ''}`}- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M9 5l7 7-7 7"- />- </svg>- Commands that will run ({discoveryInfo()?.commands?.length || 0})- </summary>- <Show when={showCommandsPreview()}>- <div class="px-3 pb-3 space-y-2">- <For each={discoveryInfo()?.commands}>- {(cmd) => (- <div class="text-xs">- <div class="flex items-start gap-2">- <code class="text-[10px] px-1.5 py-0.5 rounded bg-surface-hover text-base-content font-mono break-all">- {cmd.command}- </code>- </div>- <p class="text-muted mt-0.5 pl-0.5">{cmd.description}</p>- </div>- )}- </For>+ {/* Scan Progress Bar */}+ <Show when={scanProgress() && isScanning()}>+ <div class="rounded border border-blue-200 bg-blue-50 p-3 shadow-sm dark:border-blue-800 dark:bg-blue-900">+ <div class="flex items-center justify-between mb-2">+ <div class="flex items-center gap-2">+ <div class="animate-spin h-4 w-4 border-2 border-blue-500 border-t-transparent rounded-full"></div>+ <span class="text-sm font-medium text-blue-700 dark:text-blue-300">+ {scanProgress()?.current_step || 'Scanning...'}+ </span>+ </div>+ <span class="text-xs text-blue-600 dark:text-blue-400">+ {Math.round(scanProgress()?.percent_complete || 0)}%+ </span></div>- </Show>- </details>- </Show>-- {/* Loading state - delayed to prevent flash for fast loads */}- <Show when={showLoadingSpinner()}>- <div class="flex items-center justify-center py-8">- <div class="animate-spin h-6 w-6 border-2 border-blue-500 border-t-transparent rounded-full"></div>- <span class="ml-2 text-sm text-muted">{getDiscoveryLoadingState().text}</span>- </div>- </Show>+ <div class="w-full bg-blue-200 dark:bg-blue-800 rounded-full h-2 overflow-hidden">+ <div+ class="bg-blue-500 h-2 rounded-full transition-all duration-300"+ style={{ width: `${scanProgress()?.percent_complete || 0}%` }}+ ></div>+ </div>+ <Show when={scanProgress()?.current_command}>+ <div class="mt-2 text-xs text-blue-600 dark:text-blue-400">+ Running: <code class="font-mono">{scanProgress()?.current_command}</code>+ </div>+ </Show>+ {/* Live elapsed time and hint */}+ <div class="mt-2 flex items-center justify-between text-xs text-blue-500 dark:text-blue-400">+ <span>Elapsed: {liveElapsedSeconds()}s</span>+ <span class="text-blue-400 dark:text-blue-500">+ Analysis time varies by model. You can navigate away — results save automatically.+ </span>+ </div>+ </div>+ </Show>- {/* Scan Progress Bar */}- <Show when={scanProgress() && isScanning()}>- <div class="rounded border border-blue-200 bg-blue-50 p-3 shadow-sm dark:border-blue-800 dark:bg-blue-900">- <div class="flex items-center justify-between mb-2">- <div class="flex items-center gap-2">+ {/* Scanning state without WebSocket progress - show live timer */}+ <Show when={isScanning() && !scanProgress()}>+ <div class="rounded border border-blue-200 bg-blue-50 p-3 shadow-sm dark:border-blue-800 dark:bg-blue-900">+ <div class="flex items-center gap-2 mb-2"><div class="animate-spin h-4 w-4 border-2 border-blue-500 border-t-transparent rounded-full"></div><span class="text-sm font-medium text-blue-700 dark:text-blue-300">- {scanProgress()?.current_step || 'Scanning...'}+ Running discovery...</span></div>- <span class="text-xs text-blue-600 dark:text-blue-400">- {Math.round(scanProgress()?.percent_complete || 0)}%- </span>- </div>- <div class="w-full bg-blue-200 dark:bg-blue-800 rounded-full h-2 overflow-hidden">- <div- class="bg-blue-500 h-2 rounded-full transition-all duration-300"- style={{ width: `${scanProgress()?.percent_complete || 0}%` }}- ></div>- </div>- <Show when={scanProgress()?.current_command}>- <div class="mt-2 text-xs text-blue-600 dark:text-blue-400">- Running: <code class="font-mono">{scanProgress()?.current_command}</code>+ <div class="flex items-center justify-between text-xs text-blue-500 dark:text-blue-400">+ <span>Elapsed: {liveElapsedSeconds()}s</span>+ <span class="text-blue-400 dark:text-blue-500">+ Analysis time varies by model. You can navigate away — results save automatically.+ </span></div>- </Show>- {/* Live elapsed time and hint */}- <div class="mt-2 flex items-center justify-between text-xs text-blue-500 dark:text-blue-400">- <span>Elapsed: {liveElapsedSeconds()}s</span>- <span class="text-blue-400 dark:text-blue-500">- Analysis time varies by model. You can navigate away — results save automatically.- </span></div>- </div>- </Show>+ </Show>- {/* Scanning state without WebSocket progress - show live timer */}- <Show when={isScanning() && !scanProgress()}>- <div class="rounded border border-blue-200 bg-blue-50 p-3 shadow-sm dark:border-blue-800 dark:bg-blue-900">- <div class="flex items-center gap-2 mb-2">- <div class="animate-spin h-4 w-4 border-2 border-blue-500 border-t-transparent rounded-full"></div>- <span class="text-sm font-medium text-blue-700 dark:text-blue-300">- Running discovery...- </span>- </div>- <div class="flex items-center justify-between text-xs text-blue-500 dark:text-blue-400">- <span>Elapsed: {liveElapsedSeconds()}s</span>- <span class="text-blue-400 dark:text-blue-500">- Analysis time varies by model. You can navigate away — results save automatically.- </span>- </div>- </div>- </Show>-- {/* Scan Success */}- <Show when={scanSuccess()}>- <div- role="status"- aria-live="polite"- class="mb-4 rounded-md border border-green-200 bg-green-50 p-4 dark:border-green-800 dark:bg-green-900"- >- <div class="flex items-center gap-2">- <svg- class="w-5 h-5 text-green-500 dark:text-green-400"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M5 13l4 4L19 7"- />- </svg>- <p class="text-sm font-medium text-green-800 dark:text-green-200">- Discovery complete!- </p>- </div>- </div>- </Show>-- {/* Scan Error */}- <Show when={scanError()}>- <div class="mb-4 rounded-md border border-red-200 bg-red-50 p-4 dark:border-red-800 dark:bg-red-900">- <div class="flex items-start gap-3">- <svg- class="w-5 h-5 text-red-500 dark:text-red-400 flex-shrink-0 mt-0.5"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"- />- </svg>- <div>- <p class="text-sm font-medium text-red-800 dark:text-red-200">Discovery Failed</p>- <p class="text-sm text-red-700 dark:text-red-300 mt-1">{scanError()}</p>- </div>- <button- onClick={() => setScanError(null)}- class="ml-auto text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"- >- <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ {/* Scan Success */}+ <Show when={scanSuccess()}>+ <div+ role="status"+ aria-live="polite"+ class="mb-4 rounded-md border border-green-200 bg-green-50 p-4 dark:border-green-800 dark:bg-green-900"+ >+ <div class="flex items-center gap-2">+ <svg+ class="w-5 h-5 text-green-500 dark:text-green-400"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ ><pathstroke-linecap="round"stroke-linejoin="round"stroke-width="2"- d="M6 18L18 6M6 6l12 12"+ d="M5 13l4 4L19 7"/></svg>- </button>+ <p class="text-sm font-medium text-green-800 dark:text-green-200">+ Discovery complete!+ </p>+ </div></div>- </div>- </Show>+ </Show>- {/* No discovery yet - only show after initial fetch completes to prevent flash */}- <Show when={!discovery() && !isScanning()}>- <div class="text-center py-8">- <div class="text-muted mb-4">- <svg- class="w-12 h-12 mx-auto mb-2 opacity-50"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="1.5"- d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"- />- </svg>- <Show- when={discovery.loading}- fallback={- <>- <p class="text-sm">{getDiscoveryInitialEmptyState(false).title}</p>- <p class="text-xs text-muted mt-1">- {getDiscoveryInitialEmptyState(false).description}- </p>- </>- }- >- <p class="text-sm">{getDiscoveryInitialEmptyState(true).title}</p>- <p class="text-xs text-muted mt-1">- {getDiscoveryInitialEmptyState(true).description}- </p>- </Show>+ {/* Scan Error */}+ <Show when={scanError()}>+ <div class="mb-4 rounded-md border border-red-200 bg-red-50 p-4 dark:border-red-800 dark:bg-red-900">+ <div class="flex items-start gap-3">+ <svg+ class="w-5 h-5 text-red-500 dark:text-red-400 flex-shrink-0 mt-0.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"+ />+ </svg>+ <div>+ <p class="text-sm font-medium text-red-800 dark:text-red-200">Discovery Failed</p>+ <p class="text-sm text-red-700 dark:text-red-300 mt-1">{scanError()}</p>+ </div>+ <button+ onClick={() => setScanError(null)}+ class="ml-auto text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"+ >+ <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M6 18L18 6M6 6l12 12"+ />+ </svg>+ </button>+ </div></div>+ </Show>- {/* Connection Status Warning - Show when commands are needed but not available */}- <Show when={props.resourceType === 'agent' && !connectedAgents.loading}>- <Show when={props.commandsEnabled === false}>- <div class="mb-4 mx-auto max-w-md rounded-md border border-amber-200 bg-amber-50 p-3 text-left dark:border-amber-800 dark:bg-amber-900">- <div class="flex items-start gap-2">- <svg- class="w-4 h-4 text-amber-500 dark:text-amber-400 flex-shrink-0 mt-0.5"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"- />- </svg>- <div class="text-xs">- <p class="font-medium text-amber-800 dark:text-amber-200">- Commands not enabled- </p>- <p class="text-amber-700 dark:text-amber-300 mt-0.5">- Discovery requires command execution. Enable Pulse commands from{' '}- <a href={commandSettingsTarget.href} class="underline hover:no-underline">- {commandSettingsTarget.label}- </a>- .+ {/* No discovery yet - only show after initial fetch completes to prevent flash */}+ <Show when={!discovery() && !isScanning()}>+ <div class="text-center py-8">+ <div class="text-muted mb-4">+ <svg+ class="w-12 h-12 mx-auto mb-2 opacity-50"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"+ />+ </svg>+ <Show+ when={discovery.loading}+ fallback={+ <>+ <p class="text-sm">{getDiscoveryInitialEmptyState(false).title}</p>+ <p class="text-xs text-muted mt-1">+ {getDiscoveryInitialEmptyState(false).description}</p>+ </>+ }+ >+ <p class="text-sm">{getDiscoveryInitialEmptyState(true).title}</p>+ <p class="text-xs text-muted mt-1">+ {getDiscoveryInitialEmptyState(true).description}+ </p>+ </Show>+ </div>++ {/* Connection Status Warning - Show when commands are needed but not available */}+ <Show when={props.resourceType === 'agent' && !connectedAgents.loading}>+ <Show when={props.commandsEnabled === false}>+ <div class="mb-4 mx-auto max-w-md rounded-md border border-amber-200 bg-amber-50 p-3 text-left dark:border-amber-800 dark:bg-amber-900">+ <div class="flex items-start gap-2">+ <svg+ class="w-4 h-4 text-amber-500 dark:text-amber-400 flex-shrink-0 mt-0.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"+ />+ </svg>+ <div class="text-xs">+ <p class="font-medium text-amber-800 dark:text-amber-200">+ Commands not enabled+ </p>+ <p class="text-amber-700 dark:text-amber-300 mt-0.5">+ Discovery requires command execution. Enable Pulse commands from{' '}+ <a href={commandSettingsTarget.href} class="underline hover:no-underline">+ {commandSettingsTarget.label}+ </a>+ .+ </p>+ </div></div></div>- </div>- </Show>- <Show when={props.commandsEnabled === true && !hasConnectedAgent()}>- <div class="mb-4 mx-auto max-w-md rounded-md border border-amber-200 bg-amber-50 p-3 text-left dark:border-amber-800 dark:bg-amber-900">- <div class="flex items-start gap-2">- <svg- class="w-4 h-4 text-amber-500 dark:text-amber-400 flex-shrink-0 mt-0.5"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"- />- </svg>- <div class="text-xs">- <p class="font-medium text-amber-800 dark:text-amber-200">- Agent not connected for commands- </p>- <p class="text-amber-700 dark:text-amber-300 mt-0.5">- Commands are enabled, but the agent isn't connected via WebSocket. Check that- the API token has the{' '}- <code class="px-1 py-0.5 bg-amber-100 dark:bg-amber-800 rounded">- agent:exec- </code>{' '}- scope in{' '}- <a href={apiAccessSettingsTarget.href} class="underline hover:no-underline">- {apiAccessSettingsTarget.label}- </a>- .- </p>+ </Show>+ <Show when={props.commandsEnabled === true && !hasConnectedAgent()}>+ <div class="mb-4 mx-auto max-w-md rounded-md border border-amber-200 bg-amber-50 p-3 text-left dark:border-amber-800 dark:bg-amber-900">+ <div class="flex items-start gap-2">+ <svg+ class="w-4 h-4 text-amber-500 dark:text-amber-400 flex-shrink-0 mt-0.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"+ />+ </svg>+ <div class="text-xs">+ <p class="font-medium text-amber-800 dark:text-amber-200">+ Agent not connected for commands+ </p>+ <p class="text-amber-700 dark:text-amber-300 mt-0.5">+ Commands are enabled, but the agent isn't connected via WebSocket. Check+ that the API token has the{' '}+ <code class="px-1 py-0.5 bg-amber-100 dark:bg-amber-800 rounded">+ agent:exec+ </code>{' '}+ scope in{' '}+ <a href={apiAccessSettingsTarget.href} class="underline hover:no-underline">+ {apiAccessSettingsTarget.label}+ </a>+ .+ </p>+ </div></div></div>- </div>- </Show>- <Show when={props.commandsEnabled === true && hasConnectedAgent()}>- <div class="mb-4 mx-auto max-w-md rounded-md border border-green-200 bg-green-50 p-3 text-left dark:border-green-800 dark:bg-green-900">- <div class="flex items-center gap-2">- <svg- class="w-4 h-4 text-green-500 dark:text-green-400 flex-shrink-0"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M5 13l4 4L19 7"- />- </svg>- <p class="text-xs font-medium text-green-800 dark:text-green-200">- Agent connected and ready for command execution- </p>+ </Show>+ <Show when={props.commandsEnabled === true && hasConnectedAgent()}>+ <div class="mb-4 mx-auto max-w-md rounded-md border border-green-200 bg-green-50 p-3 text-left dark:border-green-800 dark:bg-green-900">+ <div class="flex items-center gap-2">+ <svg+ class="w-4 h-4 text-green-500 dark:text-green-400 flex-shrink-0"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M5 13l4 4L19 7"+ />+ </svg>+ <p class="text-xs font-medium text-green-800 dark:text-green-200">+ Agent connected and ready for command execution+ </p>+ </div></div>- </div>+ </Show></Show>- </Show>- <Show when={!showManualRunAction()}>- <button- onClick={() => handleTriggerDiscovery(true)}- disabled={isScanning()}- class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"- >- {isScanning() ? (- <span class="flex items-center">- <span class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full mr-2"></span>- Scanning...- </span>- ) : discovery.loading ? (- 'Run Discovery Now'- ) : (- 'Run Discovery'- )}- </button>- </Show>- </div>- </Show>+ <Show when={!showManualRunAction()}>+ <button+ onClick={() => handleTriggerDiscovery(true)}+ disabled={isScanning()}+ class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"+ >+ {isScanning() ? (+ <span class="flex items-center">+ <span class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full mr-2"></span>+ Scanning...+ </span>+ ) : discovery.loading ? (+ 'Run Discovery Now'+ ) : (+ 'Run Discovery'+ )}+ </button>+ </Show>+ </div>+ </Show>- {/* Discovery exists but has no meaningful data - show re-scan option */}- <Show when={!discovery.loading && discovery() && !hasValidDiscovery() && !isScanning()}>- <div class="text-center py-8">- <div class="text-muted mb-4">- <svg- class="w-12 h-12 mx-auto mb-2 opacity-50"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="1.5"- d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"- />- </svg>- <p class="text-sm">Unknown Service</p>- <p class="text-xs text-muted mt-1">- Discovery completed but couldn't identify a known service.- </p>- <Show when={discovery()?.updated_at}>- <p class="text-xs text-muted mt-2">- Last scanned: {formatDiscoveryAge(discovery()!.updated_at)}+ {/* Discovery exists but has no meaningful data - show re-scan option */}+ <Show when={!discovery.loading && discovery() && !hasValidDiscovery() && !isScanning()}>+ <div class="text-center py-8">+ <div class="text-muted mb-4">+ <svg+ class="w-12 h-12 mx-auto mb-2 opacity-50"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="1.5"+ d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"+ />+ </svg>+ <p class="text-sm">Unknown Service</p>+ <p class="text-xs text-muted mt-1">+ Discovery completed but couldn't identify a known service.</p>+ <Show when={discovery()?.updated_at}>+ <p class="text-xs text-muted mt-2">+ Last scanned: {formatDiscoveryAge(discovery()!.updated_at)}+ </p>+ </Show>+ </div>+ <Show when={!showManualRunAction()}>+ <button+ onClick={() => handleTriggerDiscovery(true)}+ disabled={isScanning()}+ class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"+ >+ {isScanning() ? (+ <span class="flex items-center justify-center">+ <span class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full mr-2"></span>+ Scanning...+ </span>+ ) : (+ 'Re-scan Discovery'+ )}+ </button></Show></div>- <Show when={!showManualRunAction()}>- <button- onClick={() => handleTriggerDiscovery(true)}- disabled={isScanning()}- class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"- >- {isScanning() ? (- <span class="flex items-center justify-center">- <span class="animate-spin h-4 w-4 border-2 border-white border-t-transparent rounded-full mr-2"></span>- Scanning...- </span>- ) : (- 'Re-scan Discovery'- )}- </button>- </Show>- </div>- </Show>+ </Show>- {/* Discovery data with valid results */}- <Show when={validDiscovery()}>- {(d) => (- <div class="space-y-4">- {/* Service Header */}- <div class="rounded border border-border bg-surface p-3 shadow-sm">- <div class="flex items-start justify-between">- <div>- <div class="flex flex-wrap items-center gap-1.5">- <h3 class="text-sm font-semibold text-base-content">- {d().service_name || 'Unknown Service'}- </h3>- <DiscoveryProvenanceMarker />- </div>- <Show when={d().service_version}>- <div class="mt-1 flex items-center gap-2">- <DiscoveryProvenanceMarker showLabel={false} />- <span class="text-xs text-muted">Version {d().service_version}</span>- <CopyValueButton- value={d().service_version}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy service version"- class="inline-flex min-h-5 min-w-5 shrink-0 items-center justify-center rounded text-muted transition-colors hover:bg-surface-hover hover:text-base-content"- />+ {/* Discovery data with valid results */}+ <Show when={validDiscovery()}>+ {(d) => (+ <div class="space-y-4">+ {/* Service Header */}+ <div class="rounded border border-border bg-surface p-3 shadow-sm">+ <div class="flex items-start justify-between">+ <div>+ <div class="flex flex-wrap items-center gap-1.5">+ <h3 class="text-sm font-semibold text-base-content">+ {d().service_name || 'Unknown Service'}+ </h3>+ <DiscoveryProvenanceMarker /></div>+ <Show when={d().service_version}>+ <div class="mt-1 flex items-center gap-2">+ <DiscoveryProvenanceMarker showLabel={false} />+ <span class="text-xs text-muted">Version {d().service_version}</span>+ <CopyValueButton+ value={d().service_version}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy service version"+ class="inline-flex min-h-5 min-w-5 shrink-0 items-center justify-center rounded text-muted transition-colors hover:bg-surface-hover hover:text-base-content"+ />+ </div>+ </Show>+ </div>+ <Show when={d().category && d().category !== 'unknown'}>+ <span class={getDiscoveryCategoryBadgeClass()}>+ {getCategoryDisplayName(d().category)}+ </span></Show></div>- <Show when={d().category && d().category !== 'unknown'}>- <span class={getDiscoveryCategoryBadgeClass()}>- {getCategoryDisplayName(d().category)}- </span>- </Show>- </div>- <Show when={confidenceInfo()}>- <p class={`text-xs mt-2 ${confidenceInfo()!.color}`}>- {confidenceInfo()!.label} ({Math.round((d().confidence || 0) * 100)}%)- </p>- </Show>- <div class="mt-3 flex flex-wrap gap-2 text-[10px] text-muted">- <DiscoveryProvenanceMarker label={getDiscoveryObservedSourceLabel()} />- <Show when={d().updated_at}>+ <Show when={confidenceInfo()}>+ <p class={`text-xs mt-2 ${confidenceInfo()!.color}`}>+ {confidenceInfo()!.label} ({Math.round((d().confidence || 0) * 100)}%)+ </p>+ </Show>+ <div class="mt-3 flex flex-wrap gap-2 text-[10px] text-muted">+ <DiscoveryProvenanceMarker label={getDiscoveryObservedSourceLabel()} />+ <Show when={d().updated_at}>+ <span class="rounded border border-border bg-surface-alt px-2 py-0.5">+ Last observed {formatDiscoveryAge(d().updated_at)}+ </span>+ </Show><span class="rounded border border-border bg-surface-alt px-2 py-0.5">- Last observed {formatDiscoveryAge(d().updated_at)}+ Available to Pulse Assistant</span>- </Show>- <span class="rounded border border-border bg-surface-alt px-2 py-0.5">- Available to Pulse Assistant- </span>+ </div></div>- </div>- <Show when={d().suggested_url || d().suggested_url_diagnostic}>- <div class={getDiscoverySuggestedURLCardClass()}>- <div class={`${getDiscoverySuggestedURLHeadingClass()} flex items-center gap-1.5`}>- <span>Web Interface Suggestion</span>- <DiscoveryProvenanceMarker />- </div>- <Show- when={d().suggested_url}- fallback={- <div class="text-xs text-blue-800 dark:text-blue-200">- <p class="font-medium">{getDiscoverySuggestedURLFallback().title}</p>- <p class="mt-1 text-blue-700 dark:text-blue-300">- {getDiscoverySuggestedURLFallback(d().suggested_url_diagnostic).description}+ <Show when={d().suggested_url || d().suggested_url_diagnostic}>+ <div class={getDiscoverySuggestedURLCardClass()}>+ <div+ class={`${getDiscoverySuggestedURLHeadingClass()} flex items-center gap-1.5`}+ >+ <span>Web Interface Suggestion</span>+ <DiscoveryProvenanceMarker />+ </div>+ <Show+ when={d().suggested_url}+ fallback={+ <div class="text-xs text-blue-800 dark:text-blue-200">+ <p class="font-medium">{getDiscoverySuggestedURLFallback().title}</p>+ <p class="mt-1 text-blue-700 dark:text-blue-300">+ {+ getDiscoverySuggestedURLFallback(d().suggested_url_diagnostic)+ .description+ }+ </p>+ </div>+ }+ >+ <Show when={suggestedURLReasonText()}>+ <p+ class={`mb-1 text-[10px] ${getDiscoverySuggestedURLTextClass()}`}+ title={suggestedURLReasonTitle()}+ >+ Why this URL: {suggestedURLReasonText()}</p>+ </Show>+ <div class="flex items-start gap-2">+ <code class={getDiscoverySuggestedURLCodeClass()}>{d().suggested_url}</code>+ <a+ href={d().suggested_url}+ target="_blank"+ rel="noopener noreferrer"+ class={getDiscoverySuggestedURLActionClass()}+ title="Open suggested URL"+ aria-label="Open suggested URL"+ >+ <ExternalLinkIcon class="h-3.5 w-3.5" />+ </a>+ <CopyValueButton+ value={d().suggested_url}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy suggested URL"+ class={getDiscoverySuggestedURLActionClass()}+ /></div>- }- >- <Show when={suggestedURLReasonText()}>- <p- class={`mb-1 text-[10px] ${getDiscoverySuggestedURLTextClass()}`}- title={suggestedURLReasonTitle()}- >- Why this URL: {suggestedURLReasonText()}+ <p class={`mt-1.5 text-[11px] ${getDiscoverySuggestedURLTextClass()}`}>+ Save it in the Web Interface URL field before Pulse uses it as a link.</p></Show>- <div class="flex items-start gap-2">- <code class={getDiscoverySuggestedURLCodeClass()}>{d().suggested_url}</code>- <a- href={d().suggested_url}- target="_blank"- rel="noopener noreferrer"- class={getDiscoverySuggestedURLActionClass()}- title="Open suggested URL"- aria-label="Open suggested URL"- >- <ExternalLinkIcon class="h-3.5 w-3.5" />- </a>- <CopyValueButton- value={d().suggested_url}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy suggested URL"- class={getDiscoverySuggestedURLActionClass()}- />- </div>- <p class={`mt-1.5 text-[11px] ${getDiscoverySuggestedURLTextClass()}`}>- Save it in the Web Interface URL field before Pulse uses it as a link.- </p>- </Show>- </div>- </Show>-- {/* CLI Access */}- <Show when={d().cli_access}>- <div class="rounded border border-border p-3 shadow-sm">- <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>CLI Access</span>- <DiscoveryProvenanceMarker showLabel={false} /></div>- <CopyableCodeRow- value={d().cli_access}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy CLI access"- />- </div>- </Show>+ </Show>- {/* Configuration, Data & Log Paths */}- <Show- when={- d().config_paths?.length > 0 ||- d().data_paths?.length > 0 ||- d().log_paths?.length > 0- }- >- <div class="rounded border border-border p-3 shadow-sm">- <Show when={d().config_paths?.length > 0}>- <div class="mb-3">- <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>Config Paths</span>- <DiscoveryProvenanceMarker showLabel={false} />- </div>- <div class="space-y-1">- <For each={d().config_paths}>- {(path) => (- <CopyableCodeRow- value={path}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy config path"- />- )}- </For>- </div>+ {/* CLI Access */}+ <Show when={d().cli_access}>+ <div class="rounded border border-border p-3 shadow-sm">+ <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>CLI Access</span>+ <DiscoveryProvenanceMarker showLabel={false} /></div>- </Show>- <Show when={d().data_paths?.length > 0}>- <div class="mb-3">- <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>Data Paths</span>- <DiscoveryProvenanceMarker showLabel={false} />- </div>- <div class="space-y-1">- <For each={d().data_paths}>- {(path) => (- <CopyableCodeRow- value={path}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy data path"- />- )}- </For>+ <CopyableCodeRow+ value={d().cli_access}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy CLI access"+ />+ </div>+ </Show>++ {/* Configuration, Data & Log Paths */}+ <Show+ when={+ d().config_paths?.length > 0 ||+ d().data_paths?.length > 0 ||+ d().log_paths?.length > 0+ }+ >+ <div class="rounded border border-border p-3 shadow-sm">+ <Show when={d().config_paths?.length > 0}>+ <div class="mb-3">+ <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>Config Paths</span>+ <DiscoveryProvenanceMarker showLabel={false} />+ </div>+ <div class="space-y-1">+ <For each={d().config_paths}>+ {(path) => (+ <CopyableCodeRow+ value={path}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy config path"+ />+ )}+ </For>+ </div></div>- </div>- </Show>- <Show when={d().log_paths?.length > 0}>- <div>- <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>Log Paths</span>- <DiscoveryProvenanceMarker showLabel={false} />+ </Show>+ <Show when={d().data_paths?.length > 0}>+ <div class="mb-3">+ <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>Data Paths</span>+ <DiscoveryProvenanceMarker showLabel={false} />+ </div>+ <div class="space-y-1">+ <For each={d().data_paths}>+ {(path) => (+ <CopyableCodeRow+ value={path}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy data path"+ />+ )}+ </For>+ </div></div>- <div class="space-y-1">- <For each={d().log_paths}>- {(path) => (- <CopyableCodeRow- value={path}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label="Copy log path"- />- )}- </For>+ </Show>+ <Show when={d().log_paths?.length > 0}>+ <div>+ <div class="mb-1 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>Log Paths</span>+ <DiscoveryProvenanceMarker showLabel={false} />+ </div>+ <div class="space-y-1">+ <For each={d().log_paths}>+ {(path) => (+ <CopyableCodeRow+ value={path}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label="Copy log path"+ />+ )}+ </For>+ </div></div>- </div>- </Show>- </div>- </Show>-- {/* Ports */}- <Show when={d().ports?.length > 0}>- <div class="rounded border border-border p-3 shadow-sm">- <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>Listening Ports</span>- <DiscoveryProvenanceMarker showLabel={false} />+ </Show></div>- <div class="flex flex-wrap gap-1">- <For each={d().ports}>- {(port) => (- <button- type="button"- class="inline-flex items-center gap-1 rounded bg-surface-alt px-1.5 py-0.5 text-[10px] text-base-content transition-colors hover:bg-surface-hover"- onClick={() =>- void handleCopyDiscoveryValue(`${port.port}/${port.protocol}`)- }- title="Copy port"- aria-label={`Copy ${port.port}/${port.protocol}`}- >- <span>- {port.port}/{port.protocol}- </span>- <Show when={port.process}>- <span class="text-muted">({port.process})</span>- </Show>- <Show- when={copiedDiscoveryValue() === `${port.port}/${port.protocol}`}- fallback={<CopyIcon class="h-3 w-3 text-muted" />}+ </Show>++ {/* Ports */}+ <Show when={d().ports?.length > 0}>+ <div class="rounded border border-border p-3 shadow-sm">+ <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>Listening Ports</span>+ <DiscoveryProvenanceMarker showLabel={false} />+ </div>+ <div class="flex flex-wrap gap-1">+ <For each={d().ports}>+ {(port) => (+ <button+ type="button"+ class="inline-flex items-center gap-1 rounded bg-surface-alt px-1.5 py-0.5 text-[10px] text-base-content transition-colors hover:bg-surface-hover"+ onClick={() =>+ void handleCopyDiscoveryValue(`${port.port}/${port.protocol}`)+ }+ title="Copy port"+ aria-label={`Copy ${port.port}/${port.protocol}`}>- <CheckIcon class="h-3 w-3 text-emerald-600 dark:text-emerald-400" />- </Show>- </button>- )}- </For>+ <span>+ {port.port}/{port.protocol}+ </span>+ <Show when={port.process}>+ <span class="text-muted">({port.process})</span>+ </Show>+ <Show+ when={copiedDiscoveryValue() === `${port.port}/${port.protocol}`}+ fallback={<CopyIcon class="h-3 w-3 text-muted" />}+ >+ <CheckIcon class="h-3 w-3 text-emerald-600 dark:text-emerald-400" />+ </Show>+ </button>+ )}+ </For>+ </div></div>- </div>- </Show>+ </Show>- {/* Key Facts */}- <Show when={d().facts?.length > 0}>- <div class="rounded border border-border p-3 shadow-sm">- <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">- <span>Discovered Facts</span>- <DiscoveryProvenanceMarker showLabel={false} />- </div>- <div class="space-y-1.5">- <For each={d().facts.slice(0, 8)}>- {(fact) => (- <div class="flex items-center justify-between gap-2 text-xs">- <span class="min-w-0 text-muted truncate">{fact.key}</span>- <div class="flex min-w-0 items-center gap-1.5">- <span class="truncate font-medium text-base-content" title={fact.value}>- {fact.value}- </span>- <CopyValueButton- value={fact.value}- copiedValue={copiedDiscoveryValue}- onCopy={handleCopyDiscoveryValue}- label={`Copy ${fact.key}`}- class="inline-flex min-h-5 min-w-5 shrink-0 items-center justify-center rounded text-muted transition-colors hover:bg-surface-hover hover:text-base-content"- />+ {/* Key Facts */}+ <Show when={d().facts?.length > 0}>+ <div class="rounded border border-border p-3 shadow-sm">+ <div class="mb-2 flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-base-content">+ <span>Discovered Facts</span>+ <DiscoveryProvenanceMarker showLabel={false} />+ </div>+ <div class="space-y-1.5">+ <For each={d().facts.slice(0, 8)}>+ {(fact) => (+ <div class="flex items-center justify-between gap-2 text-xs">+ <span class="min-w-0 text-muted truncate">{fact.key}</span>+ <div class="flex min-w-0 items-center gap-1.5">+ <span class="truncate font-medium text-base-content" title={fact.value}>+ {fact.value}+ </span>+ <CopyValueButton+ value={fact.value}+ copiedValue={copiedDiscoveryValue}+ onCopy={handleCopyDiscoveryValue}+ label={`Copy ${fact.key}`}+ class="inline-flex min-h-5 min-w-5 shrink-0 items-center justify-center rounded text-muted transition-colors hover:bg-surface-hover hover:text-base-content"+ />+ </div></div>- </div>- )}- </For>+ )}+ </For>+ </div></div>- </div>- </Show>+ </Show>- {/* User Notes */}- <div class="rounded border border-border p-3 shadow-sm">- <div class="flex items-center justify-between mb-2">- <div class="text-[11px] font-medium uppercase tracking-wide text-base-content">- Your Notes+ {/* User Notes */}+ <div class="rounded border border-border p-3 shadow-sm">+ <div class="flex items-center justify-between mb-2">+ <div class="text-[11px] font-medium uppercase tracking-wide text-base-content">+ Your Notes+ </div>+ <Show when={!editingNotes()}>+ <button+ onClick={startEditingNotes}+ class="text-xs text-blue-600 dark:text-blue-400 hover:underline"+ >+ {d().user_notes ? 'Edit' : 'Add notes'}+ </button>+ </Show></div>- <Show when={!editingNotes()}>- <button- onClick={startEditingNotes}- class="text-xs text-blue-600 dark:text-blue-400 hover:underline"- >- {d().user_notes ? 'Edit' : 'Add notes'}- </button>++ <Show+ when={editingNotes()}+ fallback={+ <Show+ when={d().user_notes}+ fallback={+ <p class="text-xs text-muted italic">+ {getDiscoveryNotesEmptyState().text}+ </p>+ }+ >+ <p class="text-xs text-muted whitespace-pre-wrap">{d().user_notes}</p>+ </Show>+ }+ >+ <div class="space-y-2">+ <textarea+ value={notesText()}+ onInput={(e) => setNotesText(e.currentTarget.value)}+ placeholder="Add notes about this resource (API tokens, passwords, important info)..."+ class="w-full h-24 px-2 py-1.5 text-xs border border-border rounded bg-surface text-base-content focus:outline-none focus:ring-1 focus:ring-blue-500"+ />+ <Show when={saveError()}>+ <p+ role="alert"+ aria-live="assertive"+ class="text-xs text-red-600 dark:text-red-400"+ >+ {saveError()}+ </p>+ </Show>+ <div class="flex gap-2">+ <button+ onClick={handleSaveNotes}+ class="px-3 py-1 bg-blue-600 text-white text-xs rounded hover:bg-blue-700 transition-colors"+ >+ Save+ </button>+ <button+ onClick={() => setEditingNotes(false)}+ class="px-3 py-1 bg-surface-hover text-base-content text-xs rounded hover:bg-slate-300 transition-colors"+ >+ Cancel+ </button>+ </div>+ </div></Show></div>+ {/* Analysis reasoning (collapsible) */}+ <Show when={d().ai_reasoning}>+ <details class="rounded border shadow-sm">+ <summary class="p-3 text-[11px] font-medium uppercase tracking-wide text-base-content cursor-pointer hover:bg-surface-hover">+ {DISCOVERY_ANALYSIS_REASONING_LABEL}+ </summary>+ <div class="px-3 pb-3">+ <p class="text-xs text-muted">{d().ai_reasoning}</p>+ </div>+ </details>+ </Show>++ {/* Scan Details / Raw Command Outputs (collapsible) */}<Show- when={editingNotes()}- fallback={- <Show- when={d().user_notes}- fallback={- <p class="text-xs text-muted italic">{getDiscoveryNotesEmptyState().text}</p>- }- >- <p class="text-xs text-muted whitespace-pre-wrap">{d().user_notes}</p>- </Show>- }+ when={d().raw_command_output && Object.keys(d().raw_command_output!).length > 0}>- <div class="space-y-2">- <textarea- value={notesText()}- onInput={(e) => setNotesText(e.currentTarget.value)}- placeholder="Add notes about this resource (API tokens, passwords, important info)..."- class="w-full h-24 px-2 py-1.5 text-xs border border-border rounded bg-surface text-base-content focus:outline-none focus:ring-1 focus:ring-blue-500"- />- <Show when={saveError()}>- <p- role="alert"- aria-live="assertive"- class="text-xs text-red-600 dark:text-red-400"- >- {saveError()}- </p>- </Show>- <div class="flex gap-2">- <button- onClick={handleSaveNotes}- class="px-3 py-1 bg-blue-600 text-white text-xs rounded hover:bg-blue-700 transition-colors"- >- Save- </button>- <button- onClick={() => setEditingNotes(false)}- class="px-3 py-1 bg-surface-hover text-base-content text-xs rounded hover:bg-slate-300 transition-colors"- >- Cancel- </button>+ <details class="rounded border shadow-sm">+ <summary class="p-3 text-[11px] font-medium uppercase tracking-wide text-base-content cursor-pointer hover:bg-surface-hover">+ Scan Details ({Object.keys(d().raw_command_output!).length} commands)+ </summary>+ <div class="px-3 pb-3 space-y-3">+ <For each={Object.entries(d().raw_command_output!)}>+ {([cmdName, output]) => (+ <div>+ <div class="text-xs font-medium text-base-content mb-1">{cmdName}</div>+ <pre class="text-[10px] bg-surface-alt rounded p-2 overflow-x-auto text-muted max-h-32 overflow-y-auto">+ {output || '(no output)'}+ </pre>+ </div>+ )}+ </For></div>- </div>+ </details></Show>- </div>-- {/* Analysis reasoning (collapsible) */}- <Show when={d().ai_reasoning}>- <details class="rounded border shadow-sm">- <summary class="p-3 text-[11px] font-medium uppercase tracking-wide text-base-content cursor-pointer hover:bg-surface-hover">- {DISCOVERY_ANALYSIS_REASONING_LABEL}- </summary>- <div class="px-3 pb-3">- <p class="text-xs text-muted">{d().ai_reasoning}</p>- </div>- </details>- </Show>-- {/* Scan Details / Raw Command Outputs (collapsible) */}- <Show when={d().raw_command_output && Object.keys(d().raw_command_output!).length > 0}>- <details class="rounded border shadow-sm">- <summary class="p-3 text-[11px] font-medium uppercase tracking-wide text-base-content cursor-pointer hover:bg-surface-hover">- Scan Details ({Object.keys(d().raw_command_output!).length} commands)- </summary>- <div class="px-3 pb-3 space-y-3">- <For each={Object.entries(d().raw_command_output!)}>- {([cmdName, output]) => (- <div>- <div class="text-xs font-medium text-base-content mb-1">{cmdName}</div>- <pre class="text-[10px] bg-surface-alt rounded p-2 overflow-x-auto text-muted max-h-32 overflow-y-auto">- {output || '(no output)'}- </pre>- </div>- )}- </For>- </div>- </details>- </Show>- {/* Commands Run (for non-admin users who can't see full output) */}- <Show when={!d().raw_command_output && d().scan_duration && d().scan_duration > 0}>- <div class="rounded border border-border bg-surface p-3 shadow-sm">- <div class="text-[11px] font-medium uppercase tracking-wide text-base-content mb-1">- Scan Info+ {/* Commands Run (for non-admin users who can't see full output) */}+ <Show when={!d().raw_command_output && d().scan_duration && d().scan_duration > 0}>+ <div class="rounded border border-border bg-surface p-3 shadow-sm">+ <div class="text-[11px] font-medium uppercase tracking-wide text-base-content mb-1">+ Scan Info+ </div>+ <p class="text-xs text-muted">+ Scan completed in {(d().scan_duration! / 1000).toFixed(1)}s. Full scan details+ are available to administrators.+ </p></div>- <p class="text-xs text-muted">- Scan completed in {(d().scan_duration! / 1000).toFixed(1)}s. Full scan details are- available to administrators.- </p>- </div>- </Show>+ </Show>- {/* Footer with Update button */}- <div- class={`flex items-center pt-2 border-t border-border ${showManualRunAction() ? 'justify-start' : 'justify-between'}`}- >- <span class="text-xs text-muted">- Last updated: {formatDiscoveryAge(d().updated_at)}- </span>- <Show when={!showManualRunAction()}>- <button- onClick={() => handleTriggerDiscovery(true)}- disabled={isScanning()}- class="px-3 py-1.5 bg-surface-hover text-base-content text-xs rounded hover:bg-surface-hover disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5"- >- <Show- when={isScanning()}- fallback={- <>- <svg- class="w-3.5 h-3.5"- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- >- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"- />- </svg>- Update Discovery- </>- }+ {/* Footer with Update button */}+ <div+ class={`flex items-center pt-2 border-t border-border ${showManualRunAction() ? 'justify-start' : 'justify-between'}`}+ >+ <span class="text-xs text-muted">+ Last updated: {formatDiscoveryAge(d().updated_at)}+ </span>+ <Show when={!showManualRunAction()}>+ <button+ onClick={() => handleTriggerDiscovery(true)}+ disabled={isScanning()}+ class="px-3 py-1.5 bg-surface-hover text-base-content text-xs rounded hover:bg-surface-hover disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-1.5">- <span class="animate-spin h-3.5 w-3.5 border-2 border-slate-500 border-t-transparent rounded-full"></span>- Scanning...- </Show>- </button>- </Show>+ <Show+ when={isScanning()}+ fallback={+ <>+ <svg+ class="w-3.5 h-3.5"+ fill="none"+ viewBox="0 0 24 24"+ stroke="currentColor"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"+ />+ </svg>+ Update Discovery+ </>+ }+ >+ <span class="animate-spin h-3.5 w-3.5 border-2 border-slate-500 border-t-transparent rounded-full"></span>+ Scanning...+ </Show>+ </button>+ </Show>+ </div></div>- </div>- )}+ )}+ </Show></Show></div>);diff --git a/frontend-modern/src/components/Discovery/__tests__/DiscoveryTab.test.tsx b/frontend-modern/src/components/Discovery/__tests__/DiscoveryTab.test.tsxindex bc6e07fcbf..da5c70f046 100644--- a/frontend-modern/src/components/Discovery/__tests__/DiscoveryTab.test.tsx+++ b/frontend-modern/src/components/Discovery/__tests__/DiscoveryTab.test.tsx@@ -20,15 +20,26 @@ vi.mock('@/utils/clipboard', () => ({copyToClipboard: vi.fn(async () => true),}));+vi.mock('@/api/ai', () => ({+ AIAPI: {+ getSettings: vi.fn(async () => ({ discovery_enabled: true })),+ },+}));++import { AIAPI } from '@/api/ai';import * as discoveryApi from '@/api/discovery';import { DiscoveryTab } from '@/components/Discovery/DiscoveryTab';import { copyToClipboard } from '@/utils/clipboard';import { getDiscoveryProvenanceTitle } from '@/utils/discoveryPresentation';+const aiSettingsWithDiscovery = (discovery_enabled: boolean) =>+ ({ discovery_enabled }) as Awaited<ReturnType<typeof AIAPI.getSettings>>;+describe('DiscoveryTab', () => {afterEach(() => {cleanup();vi.clearAllMocks();+ vi.mocked(AIAPI.getSettings).mockResolvedValue(aiSettingsWithDiscovery(true));});it('keeps run action visible while discovery lookup is still loading', async () => {@@ -39,6 +50,19 @@ describe('DiscoveryTab', () => {expect(await screen.findByRole('button', { name: 'Run Discovery Now' })).toBeInTheDocument();});+ it('does not fetch discovery data when AI discovery is disabled', async () => {+ vi.mocked(AIAPI.getSettings).mockResolvedValue(aiSettingsWithDiscovery(false));++ render(() => (+ <DiscoveryTab resourceType="agent" agentId="agent-1" resourceId="agent-1" hostname="pve1" />+ ));++ expect(await screen.findByText('AI Discovery Disabled')).toBeInTheDocument();+ expect(discoveryApi.getDiscovery).not.toHaveBeenCalled();+ expect(discoveryApi.getDiscoveryInfo).not.toHaveBeenCalled();+ expect(discoveryApi.getConnectedAgents).not.toHaveBeenCalled();+ });+it('treats placeholder-only discovery records as unidentified instead of valid results', async () => {vi.mocked(discoveryApi.getDiscovery).mockResolvedValue({id: 'system-container:pve4:152',@@ -135,7 +159,9 @@ describe('DiscoveryTab', () => {/>));- fireEvent.click(await screen.findByRole('button', { name: 'Run Discovery' }));+ const runButton = await screen.findByRole('button', { name: 'Run Discovery' });+ await waitFor(() => expect(runButton).not.toBeDisabled());+ fireEvent.click(runButton);await waitFor(() => {expect(discoveryApi.triggerDiscovery).toHaveBeenCalledWith('agent', 'agent-1', 'agent-1', {diff --git a/frontend-modern/src/components/Discovery/useDiscoveryTabState.ts b/frontend-modern/src/components/Discovery/useDiscoveryTabState.tsindex d988b67d12..1e46a5c775 100644--- a/frontend-modern/src/components/Discovery/useDiscoveryTabState.ts+++ b/frontend-modern/src/components/Discovery/useDiscoveryTabState.ts@@ -7,6 +7,7 @@ import {triggerDiscovery,updateDiscoveryNotes,} from '@/api/discovery';+import { AIAPI } from '@/api/ai';import { eventBus } from '@/stores/events';import type { DiscoveryProgress, ResourceType } from '@/types/discovery';import {@@ -52,9 +53,25 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {makeResourceId(props.resourceType, targetAgentId(), props.resourceId),);+ const [aiSettings] = createResource(async () => {+ try {+ return await AIAPI.getSettings();+ } catch {+ return null;+ }+ });+ const discoveryFeatureResolved = createMemo(() => !aiSettings.loading);+ const discoveryFeatureEnabled = createMemo(+ () => discoveryFeatureResolved() && aiSettings()?.discovery_enabled !== false,+ );+ const discoveryFeatureKnownDisabled = createMemo(+ () => discoveryFeatureResolved() && aiSettings()?.discovery_enabled === false,+ );+const [discoveryInfo] = createResource(- () => props.resourceType,+ () => (discoveryFeatureEnabled() ? props.resourceType : null),async (type) => {+ if (!type) return null;try {return await getDiscoveryInfo(type);} catch {@@ -63,13 +80,19 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {},);- const [connectedAgents] = createResource(async () => {- try {- return await getConnectedAgents();- } catch {- return { count: 0, agents: [] };- }- });+ const [connectedAgents] = createResource(+ () => discoveryFeatureEnabled(),+ async (enabled) => {+ if (!enabled) {+ return { count: 0, agents: [] };+ }+ try {+ return await getConnectedAgents();+ } catch {+ return { count: 0, agents: [] };+ }+ },+ );const hasConnectedAgent = createMemo(() => {const agentId = targetAgentId();@@ -83,20 +106,28 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {return agents.length === 1;});- const canTriggerDiscovery = createMemo(() => Boolean(targetAgentId()));+ const canTriggerDiscovery = createMemo(+ () => discoveryFeatureEnabled() && Boolean(targetAgentId()),+ );- const [discovery, { refetch, mutate }] = createResource(discoverySourceKey, async () => {- const agentId = targetAgentId();- if (!agentId) return null;+ const [discovery, { refetch, mutate }] = createResource(+ () => (discoveryFeatureEnabled() ? discoverySourceKey() : null),+ async (sourceKey) => {+ if (!sourceKey) return null;- try {- return await getDiscovery(props.resourceType, agentId, props.resourceId);- } catch {- return null;- }- });+ const agentId = targetAgentId();+ if (!agentId) return null;++ try {+ return await getDiscovery(props.resourceType, agentId, props.resourceId);+ } catch {+ return null;+ }+ },+ );createEffect(() => {+ void discoveryFeatureEnabled();void discoverySourceKey();setIsScanning(false);setHttpScanInProgress(false);@@ -111,9 +142,13 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {});createEffect(() => {+ if (discoveryFeatureKnownDisabled()) {+ setShowLoadingSpinner(false);+ return;+ }if (discovery.loading) {const timer = setTimeout(() => {- if (discovery.loading) {+ if (discovery.loading && !discoveryFeatureKnownDisabled()) {setShowLoadingSpinner(true);}}, 150);@@ -136,6 +171,11 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {});const handleTriggerDiscovery = async (force = false) => {+ if (!discoveryFeatureEnabled()) {+ setScanError('AI discovery is disabled in Settings -> AI.');+ return;+ }+setIsScanning(true);setHttpScanInProgress(true);setScanProgress(null);@@ -231,6 +271,8 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {};createEffect(() => {+ if (!discoveryFeatureEnabled()) return;+const unsubscribe = eventBus.on('ai_discovery_progress', (progress) => {if (!progress || progress.resource_id !== resourceId()) return;@@ -277,6 +319,7 @@ export function useDiscoveryTabState(props: DiscoveryTabStateProps) {canTriggerDiscovery,copiedDiscoveryValue,discovery,+ discoveryFeatureKnownDisabled,discoveryInfo,editingNotes,handleSaveNotes,diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.discovery.test.ts b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.discovery.test.tsindex ae38748af2..4a3ede9136 100644--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.discovery.test.ts+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.discovery.test.ts@@ -245,8 +245,8 @@ describe('toDiscoveryConfig', () => {agentId: 'docker-host-1',resourceId: 'container-abc123',hostname: 'stale-hostname',- metadataKind: 'guest',- metadataId: 'resource:app-container:hash-1',+ metadataKind: 'docker',+ metadataId: 'docker-host-1:container:container-abc123',targetLabel: 'container',});});@@ -280,8 +280,8 @@ describe('toDiscoveryConfig', () => {agentId: 'agent-edge-01',resourceId: 'customer-portal',hostname: 'edge-apps-01',- metadataKind: 'guest',- metadataId: 'customer-portal',+ metadataKind: 'docker',+ metadataId: 'agent-edge-01:container:abc123def456',targetLabel: 'container',});});diff --git a/frontend-modern/src/components/Infrastructure/resourceDetailDiscoveryModel.ts b/frontend-modern/src/components/Infrastructure/resourceDetailDiscoveryModel.tsindex de7334071e..fefd96dfa6 100644--- a/frontend-modern/src/components/Infrastructure/resourceDetailDiscoveryModel.ts+++ b/frontend-modern/src/components/Infrastructure/resourceDetailDiscoveryModel.ts@@ -20,7 +20,7 @@ export type DiscoveryConfig = {agentId: string;resourceId: string;hostname: string;- metadataKind: 'guest' | 'agent';+ metadataKind: 'guest' | 'agent' | 'docker';metadataId: string;targetLabel: string;};@@ -31,6 +31,7 @@ type ProxmoxPlatformData = {};type DockerPlatformData = {+ hostSourceId?: string;containerId?: string;hostname?: string;};@@ -84,7 +85,44 @@ const getPreferredHostLabel = (resource: Resource): string =>getPreferredInfrastructureDisplayName(resource) ||resource.id;+const getDockerContainerMetadataId = (+ resource: Resource,+ platformData: PlatformData | undefined,+): string | undefined => {+ const dockerPlatformData = platformData?.docker;+ const hostSourceId =+ asString(resource.docker?.hostSourceId) || asString(dockerPlatformData?.hostSourceId);+ const containerId =+ asString(resource.docker?.containerId) || asString(dockerPlatformData?.containerId);++ if (!hostSourceId || !containerId) return undefined;+ return `${hostSourceId}:container:${containerId}`;+};++const getMetadataTarget = (+ resource: Resource,+ resourceType: DiscoveryResourceType,+ fallbackMetadataId: string,+ platformData: PlatformData | undefined,+): Pick<DiscoveryConfig, 'metadataKind' | 'metadataId'> => {+ if (resourceType === 'app-container') {+ const dockerMetadataId = getDockerContainerMetadataId(resource, platformData);+ if (dockerMetadataId) {+ return {+ metadataKind: 'docker',+ metadataId: dockerMetadataId,+ };+ }+ }++ return {+ metadataKind: 'guest',+ metadataId: fallbackMetadataId,+ };+};+export const toDiscoveryConfig = (resource: Resource): DiscoveryConfig | null => {+ const platformData = resource.platformData as PlatformData | undefined;const explicitDiscoveryTarget = resource.discoveryTarget;const explicitDiscoveryAgentId = asString((explicitDiscoveryTarget as { agentId?: unknown } | undefined)?.agentId,@@ -119,6 +157,9 @@ export const toDiscoveryConfig = (resource: Resource): DiscoveryConfig | null =>if (resourceType) {const hostname = explicitDiscoveryTarget.hostname || getPreferredHostLabel(resource);const isHostDiscovery = isAgentDiscoveryResourceType(resourceType);+ const metadataTarget = isHostDiscovery+ ? { metadataKind: 'agent' as const, metadataId: explicitDiscoveryAgentId }+ : getMetadataTarget(resource, resourceType, explicitDiscoveryResourceId, platformData);const targetLabel = isHostDiscovery? 'agent': resourceType === 'app-container'@@ -131,14 +172,13 @@ export const toDiscoveryConfig = (resource: Resource): DiscoveryConfig | null =>agentId: explicitDiscoveryAgentId,resourceId: explicitDiscoveryResourceId,hostname,- metadataKind: isHostDiscovery ? 'agent' : 'guest',- metadataId: explicitDiscoveryResourceId,+ metadataKind: metadataTarget.metadataKind,+ metadataId: metadataTarget.metadataId,targetLabel,};}}- const platformData = resource.platformData as PlatformData | undefined;const dockerPlatformData = platformData?.docker;const kubernetesPlatformData = platformData?.kubernetes;const proxmoxVmid =@@ -253,8 +293,7 @@ export const toDiscoveryConfig = (resource: Resource): DiscoveryConfig | null =>agentId: workloadAgentId,resourceId: asString(dockerPlatformData?.containerId) || resource.id,hostname,- metadataKind: 'guest',- metadataId: resource.id,+ ...getMetadataTarget(resource, 'app-container', resource.id, platformData),targetLabel: 'container',};case 'pod':diff --git a/frontend-modern/src/components/Settings/reportingResourceTypes.ts b/frontend-modern/src/components/Settings/reportingResourceTypes.tsindex 8b13789179..d2150f6374 100644--- a/frontend-modern/src/components/Settings/reportingResourceTypes.ts+++ b/frontend-modern/src/components/Settings/reportingResourceTypes.ts@@ -1 +1 @@-+export { toReportingResourceType, type ReportingResourceType } from '@/utils/reportingResourceTypes';diff --git a/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.k8s.test.tsx b/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.k8s.test.tsxindex 93edcbd809..6926fbe669 100644--- a/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.k8s.test.tsx+++ b/frontend-modern/src/components/Workloads/__tests__/WorkloadsSurface.k8s.test.tsx@@ -26,6 +26,7 @@ const mockWebSocketState: State = {},activeAlerts: [],recentlyResolved: [],+ pveTagColors: {},lastUpdate: 0,resources: [],temperatureMonitoringEnabled: false,diff --git a/frontend-modern/src/components/shared/TagBadges.tsx b/frontend-modern/src/components/shared/TagBadges.tsxindex 5b79f85275..60e2948845 100644--- a/frontend-modern/src/components/shared/TagBadges.tsx+++ b/frontend-modern/src/components/shared/TagBadges.tsx@@ -2,6 +2,7 @@ import { Component, For, Show } from 'solid-js';import { getTagColorWithSpecial } from '@/utils/tagColors';import { useDarkMode } from '@/contexts/appRuntime';import { showTooltip, hideTooltip } from '@/components/shared/Tooltip';+import { getGlobalWebSocketStore } from '@/stores/websocket-global';interface TagBadgesProps {tags?: string[];@@ -16,12 +17,14 @@ export const TagBadges: Component<TagBadgesProps> = (props) => {const maxVisible = () => (props.maxVisible === 0 ? Infinity : (props.maxVisible ?? 3));const darkModeSignal = useDarkMode();const isDark = () => props.isDarkMode ?? darkModeSignal();+ const ws = getGlobalWebSocketStore();+ const pveTagColors = () => ws.state.pveTagColors;const visibleTags = () => props.tags?.slice(0, maxVisible()) || [];const hiddenTags = () => props.tags?.slice(maxVisible()) || [];const TagDot: Component<{ tag: string }> = (dotProps) => {- const colors = () => getTagColorWithSpecial(dotProps.tag, isDark());+ const colors = () => getTagColorWithSpecial(dotProps.tag, isDark(), pveTagColors());const isActive = () => props.activeSearch?.includes(`tags:${dotProps.tag}`) || false;const ringClass = () =>isActive() ? (isDark() ? 'text-white/90' : 'text-black/80') : 'text-transparent';diff --git a/frontend-modern/src/components/shared/__tests__/TagBadges.test.tsx b/frontend-modern/src/components/shared/__tests__/TagBadges.test.tsxindex 8405ee7807..b070b6b281 100644--- a/frontend-modern/src/components/shared/__tests__/TagBadges.test.tsx+++ b/frontend-modern/src/components/shared/__tests__/TagBadges.test.tsx@@ -3,11 +3,12 @@ import { render, screen, cleanup, fireEvent } from '@solidjs/testing-library';// ── Hoisted mocks ──────────────────────────────────────────────────────-const { darkModeMock, showTooltipMock, hideTooltipMock } = vi.hoisted(() => {+const { darkModeMock, showTooltipMock, hideTooltipMock, pveTagColors } = vi.hoisted(() => {const darkModeMock = vi.fn(() => false);const showTooltipMock = vi.fn();const hideTooltipMock = vi.fn();- return { darkModeMock, showTooltipMock, hideTooltipMock };+ const pveTagColors = { web: '#112233' };+ return { darkModeMock, showTooltipMock, hideTooltipMock, pveTagColors };});// ── Module mocks ───────────────────────────────────────────────────────@@ -21,15 +22,25 @@ vi.mock('@/components/shared/Tooltip', () => ({hideTooltip: hideTooltipMock,}));-const getTagColorWithSpecialMock = vi.fn((_tag: string, isDark: boolean) => ({- bg: isDark ? 'rgb(30, 30, 30)' : 'rgb(200, 200, 200)',- text: isDark ? 'rgb(240, 240, 240)' : 'rgb(20, 20, 20)',- border: isDark ? 'rgb(80, 80, 80)' : 'rgb(150, 150, 150)',+vi.mock('@/stores/websocket-global', () => ({+ getGlobalWebSocketStore: () => ({+ state: {+ pveTagColors,+ },+ }),}));+const getTagColorWithSpecialMock = vi.fn(+ (_tag: string, isDark: boolean, _colorMap?: Record<string, string>) => ({+ bg: isDark ? 'rgb(30, 30, 30)' : 'rgb(200, 200, 200)',+ text: isDark ? 'rgb(240, 240, 240)' : 'rgb(20, 20, 20)',+ border: isDark ? 'rgb(80, 80, 80)' : 'rgb(150, 150, 150)',+ }),+);+vi.mock('@/utils/tagColors', () => ({getTagColorWithSpecial: (...args: unknown[]) =>- getTagColorWithSpecialMock(...(args as [string, boolean])),+ getTagColorWithSpecialMock(...(args as [string, boolean, Record<string, string> | undefined])),}));import { TagBadges } from '../TagBadges';@@ -141,14 +152,14 @@ describe('TagBadges', () => {it('calls getTagColorWithSpecial with isDark=false in light mode', () => {darkModeMock.mockReturnValue(false);render(() => <TagBadges tags={['web']} />);- expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', false);+ expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', false, pveTagColors);const dot = getTagDots()[0];expect(getTagDotFill(dot)).toBe('rgb(200, 200, 200)');});it('calls getTagColorWithSpecial with isDark=true when isDarkMode prop is true', () => {render(() => <TagBadges tags={['web']} isDarkMode={true} />);- expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', true);+ expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', true, pveTagColors);const dot = getTagDots()[0];expect(getTagDotFill(dot)).toBe('rgb(30, 30, 30)');});@@ -156,7 +167,7 @@ describe('TagBadges', () => {it('uses dark mode signal when isDarkMode prop is not set', () => {darkModeMock.mockReturnValue(true);render(() => <TagBadges tags={['db']} />);- expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('db', true);+ expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('db', true, pveTagColors);const dot = getTagDots()[0];expect(getTagDotFill(dot)).toBe('rgb(30, 30, 30)');});@@ -164,7 +175,7 @@ describe('TagBadges', () => {it('isDarkMode=false overrides dark mode signal', () => {darkModeMock.mockReturnValue(true);render(() => <TagBadges tags={['web']} isDarkMode={false} />);- expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', false);+ expect(getTagColorWithSpecialMock).toHaveBeenCalledWith('web', false, pveTagColors);const dot = getTagDots()[0];expect(getTagDotFill(dot)).toBe('rgb(200, 200, 200)');});diff --git a/frontend-modern/src/components/shared/__tests__/WebInterfaceUrlField.test.tsx b/frontend-modern/src/components/shared/__tests__/WebInterfaceUrlField.test.tsxindex dae6525344..dedf1ca078 100644--- a/frontend-modern/src/components/shared/__tests__/WebInterfaceUrlField.test.tsx+++ b/frontend-modern/src/components/shared/__tests__/WebInterfaceUrlField.test.tsx@@ -18,11 +18,22 @@ vi.mock('@/api/agentMetadata', () => ({},}));+vi.mock('@/api/dockerMetadata', () => ({+ DockerMetadataAPI: {+ getMetadata: vi.fn(async () => ({ id: 'docker-host-1:container:container-1', customUrl: '' })),+ updateMetadata: vi.fn(async () => ({+ id: 'docker-host-1:container:container-1',+ customUrl: '',+ })),+ },+}));+vi.mock('@/utils/clipboard', () => ({copyToClipboard: vi.fn(async () => true),}));import { AgentMetadataAPI } from '@/api/agentMetadata';+import { DockerMetadataAPI } from '@/api/dockerMetadata';import { WebInterfaceUrlField } from '@/components/shared/WebInterfaceUrlField';import { copyToClipboard } from '@/utils/clipboard';import { getDiscoveryProvenanceTitle } from '@/utils/discoveryPresentation';@@ -43,6 +54,7 @@ describe('WebInterfaceUrlField', () => {expect(webInterfaceUrlFieldStateSource).toContain('GuestMetadataAPI.getMetadata');expect(webInterfaceUrlFieldStateSource).toContain('AgentMetadataAPI.updateMetadata');+ expect(webInterfaceUrlFieldStateSource).toContain('DockerMetadataAPI.updateMetadata');expect(webInterfaceUrlFieldStateSource).toContain('createSignal');expect(webInterfaceUrlFieldStateSource).toContain('copyToClipboard');expect(webInterfaceUrlFieldStateSource).toContain(@@ -99,6 +111,30 @@ describe('WebInterfaceUrlField', () => {});});+ it('saves a Docker container URL through Docker metadata API', async () => {+ render(() => (+ <WebInterfaceUrlField+ metadataKind="docker"+ metadataId="docker-host-1:container:container-1"+ targetLabel="container"+ customUrl=""+ />+ ));++ const input = await screen.findByPlaceholderText('https://198.51.100.100:8080');+ fireEvent.input(input, { target: { value: 'https://app.internal:9443' } });+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));++ await waitFor(() => {+ expect(DockerMetadataAPI.updateMetadata).toHaveBeenCalledWith(+ 'docker-host-1:container:container-1',+ {+ customUrl: 'https://app.internal:9443',+ },+ );+ });+ });+it('broadcasts saved URL changes for same-tab metadata consumers', async () => {const handler = vi.fn();window.addEventListener(RESOURCE_METADATA_CHANGED_EVENT, handler);diff --git a/frontend-modern/src/components/shared/summaryChartLayout.ts b/frontend-modern/src/components/shared/summaryChartLayout.tsindex 45fd9be168..20b7da0eb8 100644--- a/frontend-modern/src/components/shared/summaryChartLayout.ts+++ b/frontend-modern/src/components/shared/summaryChartLayout.ts@@ -1,3 +1,4 @@+export const SUMMARY_CHART_SLOT_CLASS = 'h-[136px] sm:h-[150px]';export const SUMMARY_CHART_SLOT_COMPACT_CLASS = 'h-[108px] sm:h-[120px]';export const SUMMARY_CHART_PLOT_AREA_CLASS = 'h-[120px] sm:h-[134px]';diff --git a/frontend-modern/src/components/shared/useWebInterfaceUrlFieldState.ts b/frontend-modern/src/components/shared/useWebInterfaceUrlFieldState.tsindex 963f6fa748..450595019a 100644--- a/frontend-modern/src/components/shared/useWebInterfaceUrlFieldState.ts+++ b/frontend-modern/src/components/shared/useWebInterfaceUrlFieldState.ts@@ -1,6 +1,7 @@import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js';import { GuestMetadataAPI } from '@/api/guestMetadata';import { AgentMetadataAPI } from '@/api/agentMetadata';+import { DockerMetadataAPI } from '@/api/dockerMetadata';import { copyToClipboard } from '@/utils/clipboard';import { dispatchResourceMetadataChanged } from '@/utils/resourceMetadataEvents';import {@@ -79,6 +80,10 @@ export function useWebInterfaceUrlFieldState(props: WebInterfaceUrlFieldProps) {const metadata = await AgentMetadataAPI.getMetadata(id);return metadata?.customUrl ?? '';}+ if (props.metadataKind === 'docker') {+ const metadata = await DockerMetadataAPI.getMetadata(id);+ return metadata?.customUrl ?? '';+ }const metadata = await GuestMetadataAPI.getMetadata(id);return metadata?.customUrl ?? '';};@@ -88,6 +93,10 @@ export function useWebInterfaceUrlFieldState(props: WebInterfaceUrlFieldProps) {await AgentMetadataAPI.updateMetadata(id, { customUrl: value });return;}+ if (props.metadataKind === 'docker') {+ await DockerMetadataAPI.updateMetadata(id, { customUrl: value });+ return;+ }await GuestMetadataAPI.updateMetadata(id, { customUrl: value });};diff --git a/frontend-modern/src/components/shared/webInterfaceUrlFieldModel.ts b/frontend-modern/src/components/shared/webInterfaceUrlFieldModel.tsindex bb54c2ee66..c71d20519e 100644--- a/frontend-modern/src/components/shared/webInterfaceUrlFieldModel.ts+++ b/frontend-modern/src/components/shared/webInterfaceUrlFieldModel.ts@@ -1,7 +1,7 @@import { getDiscoverySuggestedURLFallback } from '@/utils/discoveryPresentation';export interface WebInterfaceUrlFieldProps {- metadataKind: 'guest' | 'agent';+ metadataKind: 'guest' | 'agent' | 'docker';metadataId?: string;targetLabel?: string;title?: string;diff --git a/frontend-modern/src/features/docker/DockerNetworksTable.tsx b/frontend-modern/src/features/docker/DockerNetworksTable.tsxindex 2688dcc2ce..31f23bbf93 100644--- a/frontend-modern/src/features/docker/DockerNetworksTable.tsx+++ b/frontend-modern/src/features/docker/DockerNetworksTable.tsx@@ -1,6 +1,4 @@-import { For, Show, createMemo, createSignal, type Component, type JSX } from 'solid-js';-import { FilterSegmentedControl } from '@/components/shared/FilterToolbar';-import { SearchInput } from '@/components/shared/SearchInput';+import { For, Show, createMemo, createSignal, type Component } from 'solid-js';import { StatusDot } from '@/components/shared/StatusDot';import { TableCard } from '@/components/shared/TableCard';import { TableCardHeader } from '@/components/shared/TableCardHeader';@@ -17,6 +15,7 @@ import {PLATFORM_TABLE_BODY_CLASS,PLATFORM_TABLE_CARD_CLASS,PLATFORM_TABLE_HEADER_ROW_CLASS,+ type PlatformTableFilterOption,PlatformTableEmptyState,PlatformTableToolbar,createPlatformTableFilterState,@@ -48,9 +47,9 @@ type DockerNetworksTableProps = DockerNativeTableProps & {relatedResources?: Resource[];};-type AttachmentStatusFilter = 'all' | 'attention' | 'running' | 'other';+type AttachmentGroupKey = 'attention' | 'running' | 'other';-type AttachmentGroupKey = Exclude<AttachmentStatusFilter, 'all'>;+type AttachmentStatusFilter = 'all' | AttachmentGroupKey;type AttachmentGroup = {key: AttachmentGroupKey;@@ -66,6 +65,28 @@ const ATTACHMENT_GROUPS: readonly AttachmentGroup[] = [{ key: 'running', label: 'Running', description: 'No active issue reported' },] as const;+const ATTACHMENT_STATUS_FILTER_OPTIONS: PlatformTableFilterOption<AttachmentStatusFilter>[] = [+ { value: 'all', label: 'All', ariaLabel: 'All', title: 'All attached containers' },+ {+ value: 'attention',+ label: 'Attention',+ ariaLabel: 'Attention',+ title: 'Containers that need review',+ },+ {+ value: 'running',+ label: 'Running',+ ariaLabel: 'Running',+ title: 'Running containers',+ },+ {+ value: 'other',+ label: 'Other',+ ariaLabel: 'Other',+ title: 'Stopped, paused, or unknown containers',+ },+];+const networkFlags = (resource: Resource): string =>dockerJoinValues([@@ -141,33 +162,19 @@ const attachmentGroupKey = (row: DockerNetworkAttachmentRow): AttachmentGroupKeyreturn 'other';};-const attachmentFilterMatches = (- row: DockerNetworkAttachmentRow,- filter: AttachmentStatusFilter,-): boolean => filter === 'all' || attachmentGroupKey(row) === filter;--const attachmentStatusCounts = (rows: readonly DockerNetworkAttachmentRow[]) => {- const counts: Record<AttachmentStatusFilter, number> = {- all: rows.length,- attention: 0,- running: 0,- other: 0,- };- for (const row of rows) {- counts[attachmentGroupKey(row)] += 1;- }- return counts;+const filterAttachmentRows = (+ rows: DockerNetworkAttachmentRow[],+ search: string,+ status: AttachmentStatusFilter,+): DockerNetworkAttachmentRow[] => {+ const needle = search.trim().toLowerCase();+ return rows.filter((row) => {+ if (status !== 'all' && attachmentGroupKey(row) !== status) return false;+ if (!needle) return true;+ return row.searchText.includes(needle);+ });};-const filterOptionLabel = (label: string, count: number): JSX.Element => (- <>- <span>{label}</span>- <span class="rounded bg-surface-alt px-1.5 py-px text-[10px] font-semibold text-muted">- {count}- </span>- </>-);-const AttachmentRowCard: Component<{ row: DockerNetworkAttachmentRow }> = (props) => (<div class="rounded border border-border bg-surface px-3 py-2"><div class="grid gap-2 text-[11px] md:grid-cols-[minmax(0,1.2fr)_7rem_9rem_minmax(0,1fr)] md:items-center">@@ -192,46 +199,14 @@ const AttachmentRowCard: Component<{ row: DockerNetworkAttachmentRow }> = (props);const AttachmentDetail: Component<{ rows: readonly DockerNetworkAttachmentRow[] }> = (props) => {- const [attachmentSearch, setAttachmentSearch] = createSignal('');- const [attachmentFilter, setAttachmentFilter] = createSignal<AttachmentStatusFilter>('all');const [showAll, setShowAll] = createSignal(false);- const counts = createMemo(() => attachmentStatusCounts(props.rows));- const filterOptions = createMemo(() => [- {- value: 'all',- label: filterOptionLabel('All', counts().all),- ariaLabel: 'All',- title: 'All attached containers',- },- {- value: 'attention',- label: filterOptionLabel('Attention', counts().attention),- ariaLabel: 'Attention',- title: 'Containers that need review',- },- {- value: 'running',- label: filterOptionLabel('Running', counts().running),- ariaLabel: 'Running',- title: 'Running containers',- },- {- value: 'other',- label: filterOptionLabel('Other', counts().other),- ariaLabel: 'Other',- title: 'Stopped, paused, or unknown containers',- },- ]);- const filteredRows = createMemo(() => {- const needle = attachmentSearch().trim().toLowerCase();- return props.rows.filter((row) => {- if (!attachmentFilterMatches(row, attachmentFilter())) return false;- if (!needle) return true;- return row.searchText.includes(needle);- });+ const tableState = createPlatformTableFilterState<DockerNetworkAttachmentRow, AttachmentStatusFilter>({+ resources: () => [...props.rows],+ initialStatus: 'all',+ filter: filterAttachmentRows,});const visibleRows = createMemo(() =>- showAll() ? filteredRows() : filteredRows().slice(0, ATTACHMENT_DETAIL_ROW_LIMIT),+ showAll() ? tableState.filtered() : tableState.filtered().slice(0, ATTACHMENT_DETAIL_ROW_LIMIT),);const groupedRows = createMemo(() =>ATTACHMENT_GROUPS.map((group) => ({@@ -240,26 +215,20 @@ const AttachmentDetail: Component<{ rows: readonly DockerNetworkAttachmentRow[]})).filter((group) => group.rows.length > 0),);const hiddenRowCount = createMemo(() =>- Math.max(filteredRows().length - visibleRows().length, 0),+ Math.max(tableState.filtered().length - visibleRows().length, 0),);- const activeFilterCount = createMemo(() => {- let count = 0;- if (attachmentSearch().trim()) count += 1;- if (attachmentFilter() !== 'all') count += 1;- return count;- });const filteredSummary = createMemo(() => {- if (activeFilterCount() === 0) return attachmentCountLabel(props.rows.length);- return `${attachmentPlainCountLabel(filteredRows().length)} of ${attachmentPlainCountLabel(- props.rows.length,+ if (!tableState.hasActiveFilters()) return attachmentCountLabel(tableState.total());+ return `${attachmentPlainCountLabel(tableState.visible())} of ${attachmentPlainCountLabel(+ tableState.total(),)}`;});const setSearch = (value: string) => {- setAttachmentSearch(value);+ tableState.setSearch(value);setShowAll(false);};- const setFilter = (value: string) => {- setAttachmentFilter(value as AttachmentStatusFilter);+ const setStatus = (value: AttachmentStatusFilter) => {+ tableState.setStatus(value);setShowAll(false);};@@ -277,26 +246,27 @@ const AttachmentDetail: Component<{ rows: readonly DockerNetworkAttachmentRow[]</div>}>- <div class="mb-3 grid gap-2 xl:grid-cols-[minmax(0,1fr)_auto] xl:items-center">- <SearchInput- value={attachmentSearch}- onChange={setSearch}- placeholder="Search attached containers"- title="Search attached containers"- inputClass="py-1.5 text-xs"- clearOnFocusedEscape- />- <FilterSegmentedControl- value={attachmentFilter()}- onChange={setFilter}- options={filterOptions()}- aria-label="Attached container status"- class="justify-start xl:justify-end"+ <div class="mb-3">+ <PlatformTableToolbar+ search={tableState.search}+ onSearchChange={setSearch}+ searchPlaceholder="Search attached containers"+ status={tableState.status()}+ onStatusChange={setStatus}+ statusOptions={ATTACHMENT_STATUS_FILTER_OPTIONS}+ visible={tableState.visible()}+ total={tableState.total()}+ rowNoun="containers"+ hasActiveFilters={tableState.hasActiveFilters()}+ onResetFilters={() => {+ tableState.resetFilters();+ setShowAll(false);+ }}/></div><Show- when={filteredRows().length > 0}+ when={tableState.filtered().length > 0}fallback={<div class="rounded border border-border bg-surface px-3 py-2 text-[11px] text-muted">No attached containers match current filters.@@ -326,10 +296,10 @@ const AttachmentDetail: Component<{ rows: readonly DockerNetworkAttachmentRow[]class="w-full rounded border border-border bg-surface px-3 py-2 text-xs font-medium text-base-content hover:bg-surface-hover"onClick={() => setShowAll(true)}>- Show all {attachmentPlainCountLabel(filteredRows().length)}+ Show all {attachmentPlainCountLabel(tableState.filtered().length)}</button></Show>- <Show when={showAll() && filteredRows().length > ATTACHMENT_DETAIL_ROW_LIMIT}>+ <Show when={showAll() && tableState.filtered().length > ATTACHMENT_DETAIL_ROW_LIMIT}><buttontype="button"class="w-full rounded border border-border bg-surface px-3 py-2 text-xs font-medium text-base-content hover:bg-surface-hover"diff --git a/frontend-modern/src/features/storageBackups/__tests__/storageAdapters.test.ts b/frontend-modern/src/features/storageBackups/__tests__/storageAdapters.test.tsindex 9557e27916..749bf13251 100644--- a/frontend-modern/src/features/storageBackups/__tests__/storageAdapters.test.ts+++ b/frontend-modern/src/features/storageBackups/__tests__/storageAdapters.test.ts@@ -23,6 +23,7 @@ const baseState = (overrides: Partial<State> = {}): State => ({lastUpdate: 0,resources: [],...overrides,+ pveTagColors: overrides.pveTagColors ?? {},});const makeResourceStorage = (overrides: Partial<Resource> = {}): Resource =>diff --git a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.tsindex 1459186bf0..08ea5a7e55 100644--- a/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts+++ b/frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts@@ -180,6 +180,7 @@ describe('useUnifiedResources', () => {},activeAlerts: [],recentlyResolved: [],+ pveTagColors: {},resources: [wsResource],lastUpdate: 0,});diff --git a/frontend-modern/src/stores/websocket-global.ts b/frontend-modern/src/stores/websocket-global.tsindex 86af76bb61..c10713bd3d 100644--- a/frontend-modern/src/stores/websocket-global.ts+++ b/frontend-modern/src/stores/websocket-global.ts@@ -1,5 +1,8 @@import { createWebSocketStore } from './websocket';+import { createSignal } from 'solid-js';+import { createStore } from 'solid-js/store';import { getPulseWebSocketUrl } from '@/utils/url';+import type { Alert, ResolvedAlert, State } from '@/types/api';// Store the instance on window to survive hot reloadsdeclare global {@@ -9,6 +12,61 @@ declare global {}}+const isJSDOMTestRuntime = () =>+ import.meta.env.MODE === 'test' &&+ typeof window !== 'undefined' &&+ /jsdom/i.test(window.navigator.userAgent);++const createNoopWebSocketStore = (): ReturnType<typeof createWebSocketStore> => {+ const [connected] = createSignal(false);+ const [reconnecting] = createSignal(false);+ const [initialDataReceived] = createSignal(true);+ const [updateProgress] = createSignal<unknown>(null);+ const [state] = createStore<State>({+ connectedInfrastructure: [],+ metrics: [],+ performance: {+ apiCallDuration: {},+ lastPollDuration: 0,+ pollingStartTime: '',+ totalApiCalls: 0,+ failedApiCalls: 0,+ cacheHits: 0,+ cacheMisses: 0,+ },+ connectionHealth: {},+ stats: {+ startTime: new Date().toISOString(),+ uptime: 0,+ pollingCycles: 0,+ webSocketClients: 0,+ version: '2.0.0',+ },+ activeAlerts: [],+ recentlyResolved: [],+ lastUpdate: 0,+ pveTagColors: {},+ resources: [],+ });++ return {+ state,+ activeAlerts: {} as Record<string, Alert>,+ recentlyResolved: {} as Record<string, ResolvedAlert>,+ connected,+ reconnecting,+ initialDataReceived,+ updateProgress,+ shutdown: () => {},+ reconnect: () => {},+ switchUrl: () => {},+ markDockerRuntimesTokenRevoked: () => {},+ markAgentsTokenRevoked: () => {},+ removeAlerts: () => {},+ updateAlert: () => {},+ };+};+const bindGlobalShutdownHandler = () => {if (window.__pulseWsShutdownBound) return;@@ -25,6 +83,11 @@ const bindGlobalShutdownHandler = () => {export function getGlobalWebSocketStore() {if (!window.__pulseWsStore) {+ if (isJSDOMTestRuntime()) {+ window.__pulseWsStore = createNoopWebSocketStore();+ return window.__pulseWsStore;+ }+const wsUrl = getPulseWebSocketUrl();window.__pulseWsStore = createWebSocketStore(wsUrl);diff --git a/frontend-modern/src/stores/websocket.ts b/frontend-modern/src/stores/websocket.tsindex 254620bee1..b83a1110a6 100644--- a/frontend-modern/src/stores/websocket.ts+++ b/frontend-modern/src/stores/websocket.ts@@ -148,6 +148,7 @@ export function createWebSocketStore(url: string) {activeAlerts: [],recentlyResolved: [],lastUpdate: 0,+ pveTagColors: {},// Unified resources for cross-platform monitoringresources: [],});@@ -463,6 +464,9 @@ export function createWebSocketStore(url: string) {if (message.data.connectionHealth !== undefined)setState('connectionHealth', message.data.connectionHealth);if (message.data.stats !== undefined) setState('stats', message.data.stats);+ if (message.data.pveTagColors !== undefined) {+ setState('pveTagColors', message.data.pveTagColors ?? {});+ }// Handle unified resourcesif (message.data.resources !== undefined) {const nextResources = Array.isArray(message.data.resources)diff --git a/frontend-modern/src/types/api.ts b/frontend-modern/src/types/api.tsindex a79bf70a01..d18b8578cc 100644--- a/frontend-modern/src/types/api.ts+++ b/frontend-modern/src/types/api.ts@@ -26,6 +26,7 @@ export interface State {recentlyResolved: ResolvedAlert[];lastUpdate: number;temperatureMonitoringEnabled?: boolean;+ pveTagColors: Record<string, string>;// Unified resources (canonical resource model)resources: Resource[];}diff --git a/frontend-modern/src/types/resource.ts b/frontend-modern/src/types/resource.tsindex d60631f709..cf47e92b5d 100644--- a/frontend-modern/src/types/resource.ts+++ b/frontend-modern/src/types/resource.ts@@ -1316,6 +1316,7 @@ export interface Resource {// Metadatatags?: string[];labels?: Record<string, string>;+ customUrl?: string;lastSeen: number; // Unix millisecondsalerts?: ResourceAlert[];incidents?: ResourceIncident[];diff --git a/frontend-modern/src/useAppRuntimeState.ts b/frontend-modern/src/useAppRuntimeState.tsindex e9589102df..c3403f3489 100644--- a/frontend-modern/src/useAppRuntimeState.ts+++ b/frontend-modern/src/useAppRuntimeState.ts@@ -124,6 +124,7 @@ export const useAppRuntimeState = () => {},activeAlerts: [],recentlyResolved: [],+ pveTagColors: {},lastUpdate: 0,resources: [],};diff --git a/frontend-modern/src/utils/__tests__/tagColors.test.ts b/frontend-modern/src/utils/__tests__/tagColors.test.tsindex 65d0910116..2626db2863 100644--- a/frontend-modern/src/utils/__tests__/tagColors.test.ts+++ b/frontend-modern/src/utils/__tests__/tagColors.test.ts@@ -1,44 +1,32 @@-import { describe, it, expect } from 'vitest';+import { describe, expect, it } from 'vitest';import { getTagColorWithSpecial } from '../tagColors';describe('tagColors', () => {describe('getTagColorWithSpecial', () => {- it('returns consistent colors for special tags in light mode', () => {- const production = getTagColorWithSpecial('production', false);- expect(production).toEqual({- bg: 'rgb(254, 226, 226)',- text: 'rgb(153, 27, 27)',- border: 'rgb(239, 68, 68)',+ it('matches Proxmox fallback colors for tags', () => {+ expect(getTagColorWithSpecial('production', false)).toEqual({+ bg: 'rgb(191.3, 176.60000000000002, 238.89999999999998)',+ text: '#000000',+ border: 'rgb(191.3, 176.60000000000002, 238.89999999999998)',});- const staging = getTagColorWithSpecial('STAGING', false); // case insensitive- expect(staging).toEqual({- bg: 'rgb(254, 243, 199)',- text: 'rgb(146, 64, 14)',- border: 'rgb(245, 158, 11)',+ expect(getTagColorWithSpecial('STAGING', false)).toEqual({+ bg: 'rgb(103.10000000000001, 103.10000000000001, 175.9)',+ text: '#ffffff',+ border: 'rgb(103.10000000000001, 103.10000000000001, 175.9)',});});- it('returns consistent colors for special tags in dark mode', () => {- const backup = getTagColorWithSpecial('backup', true);- expect(backup).toEqual({- bg: 'rgb(30, 58, 138)',- text: 'rgb(191, 219, 254)',- border: 'rgb(59, 130, 246)',- });- });-- it('generates hash-based colors for non-special tags', () => {+ it('is deterministic for the same tag', () => {const color1 = getTagColorWithSpecial('mytag', false);- const color2 = getTagColorWithSpecial('mytag', false);+ const color2 = getTagColorWithSpecial('mytag', true);- // Consistencyexpect(color1).toEqual(color2);-- // Values (H, S, L format)- expect(color1.bg).toMatch(/hsl\(\d+, 65%, 60%\)/);- expect(color1.text).toMatch(/hsl\(\d+, 65%, 25%\)/);- expect(color1.border).toMatch(/hsl\(\d+, 65%, 50%\)/);+ expect(color1).toEqual({+ bg: 'rgb(228.39999999999998, 164.7, 128.3)',+ text: '#000000',+ border: 'rgb(228.39999999999998, 164.7, 128.3)',+ });});it('generates different colors for different tags', () => {@@ -48,12 +36,28 @@ describe('tagColors', () => {expect(colorA.bg).not.toBe(colorB.bg);});- it('generates dark mode hash-based colors', () => {- const color = getTagColorWithSpecial('custom', true);+ it('prefers proxmox-supplied colors over generated fallback colors', () => {+ expect(+ getTagColorWithSpecial('Production', false, {+ production: '#112233',+ }),+ ).toEqual({+ bg: 'rgb(17, 34, 51)',+ text: '#ffffff',+ border: 'rgb(17, 34, 51)',+ });+ });- expect(color.bg).toMatch(/hsl\(\d+, 55%, 35%\)/);- expect(color.text).toMatch(/hsl\(\d+, 55%, 85%\)/);- expect(color.border).toMatch(/hsl\(\d+, 55%, 45%\)/);+ it('falls back to generated colors when proxmox color is invalid', () => {+ expect(+ getTagColorWithSpecial('backup', false, {+ backup: 'not-a-color',+ }),+ ).toEqual({+ bg: 'rgb(108.00000000000001, 149.3, 143.7)',+ text: '#ffffff',+ border: 'rgb(108.00000000000001, 149.3, 143.7)',+ });});});});diff --git a/frontend-modern/src/utils/resourceMetadataEvents.ts b/frontend-modern/src/utils/resourceMetadataEvents.tsindex 93df895023..18d9841db1 100644--- a/frontend-modern/src/utils/resourceMetadataEvents.ts+++ b/frontend-modern/src/utils/resourceMetadataEvents.ts@@ -1,7 +1,7 @@export const RESOURCE_METADATA_CHANGED_EVENT = 'pulse:resource-metadata-changed';export type ResourceMetadataChangedDetail = {- metadataKind: 'agent' | 'guest';+ metadataKind: 'agent' | 'guest' | 'docker';metadataId: string;customUrl?: string;};diff --git a/frontend-modern/src/utils/tagColors.ts b/frontend-modern/src/utils/tagColors.tsindex 0f9dd89421..9a7a48c852 100644--- a/frontend-modern/src/utils/tagColors.ts+++ b/frontend-modern/src/utils/tagColors.ts@@ -1,111 +1,93 @@-// Generate consistent colors for tags based on their text-// This replicates Proxmox's tag color generation logic+interface TagColorStyle {+ bg: string;+ text: string;+ border: string;+}-/**- * Simple hash function to generate a number from a string- * This ensures the same tag always gets the same color- */-function hashString(str: string): number {+function stringToRGB(tag: string): [number, number, number] {let hash = 0;- for (let i = 0; i < str.length; i++) {- const char = str.charCodeAt(i);- hash = (hash << 5) - hash + char;- hash = hash & hash; // Convert to 32bit integer+ if (!tag) {+ return [255, 255, 255];}- return Math.abs(hash);-}-/**- * Generate a color for a tag based on its text- * Uses HSL to ensure good visibility and consistent saturation/lightness- * (Internal helper - use getTagColorWithSpecial instead)- */-function getTagColor(tag: string): { bg: string; text: string; border: string } {- // Get a hash of the tag- const hash = hashString(tag.toLowerCase());+ const value = `${tag.toLowerCase()}prox`;+ for (let i = 0; i < value.length; i++) {+ hash = value.charCodeAt(i) + ((hash << 5) - hash);+ hash &= hash;+ }- // Generate hue from hash (0-360 degrees)- const hue = hash % 360;+ const alpha = 0.7;+ const bg = 255;- // Use moderate saturation for subtle but visible colors- // These values are tuned to be noticeable without being distracting- const saturation = 65; // Moderate saturation- const lightnessBg = 60; // Slightly muted background- const lightnessText = 25; // Dark text for contrast- const lightnessBorder = 50; // Medium border+ return [+ (hash & 255) * alpha + bg * (1 - alpha),+ ((hash >> 8) & 255) * alpha + bg * (1 - alpha),+ ((hash >> 16) & 255) * alpha + bg * (1 - alpha),+ ];+}- // For dark mode, we'll adjust these in the component- return {- bg: `hsl(${hue}, ${saturation}%, ${lightnessBg}%)`,- text: `hsl(${hue}, ${saturation}%, ${lightnessText}%)`,- border: `hsl(${hue}, ${saturation}%, ${lightnessBorder}%)`,- };+function rgbToCss(rgb: [number, number, number]): string {+ return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`;}-/**- * Get tag colors adjusted for dark mode- * (Internal helper - use getTagColorWithSpecial instead)- */-function getTagColorDark(tag: string): { bg: string; text: string; border: string } {- const hash = hashString(tag.toLowerCase());- const hue = hash % 360;- const saturation = 55; // Moderate saturation in dark mode+function getTextContrastClass(rgb: [number, number, number]): 'light' | 'dark' {+ const blkThrs = 0.022;+ const blkClmp = 1.414;- return {- bg: `hsl(${hue}, ${saturation}%, 35%)`, // Subtler background- text: `hsl(${hue}, ${saturation}%, 85%)`, // Light text- border: `hsl(${hue}, ${saturation}%, 45%)`, // Subtle border- };-}+ const r = (rgb[0] / 255) ** 2.4;+ const g = (rgb[1] / 255) ** 2.4;+ const b = (rgb[2] / 255) ** 2.4;-interface TagColorStyle {- bg: string;- text: string;- border: string;+ let bg = r * 0.2126729 + g * 0.7151522 + b * 0.072175;+ bg = bg > blkThrs ? bg : bg + (blkThrs - bg) ** blkClmp;++ const contrastLight = bg ** 0.65 - 1;+ const contrastDark = bg ** 0.56 - 0.046134502;++ return Math.abs(contrastLight) >= Math.abs(contrastDark) ? 'light' : 'dark';}-interface TagColorTheme {- light: TagColorStyle;- dark: TagColorStyle;+function parseHexColor(hex: string): [number, number, number] | null {+ const normalized = hex.trim().replace(/^#/, '');+ if (!/^[0-9a-fA-F]{6}$/.test(normalized)) {+ return null;+ }++ return [+ parseInt(normalized.slice(0, 2), 16),+ parseInt(normalized.slice(2, 4), 16),+ parseInt(normalized.slice(4, 6), 16),+ ];}-/**- * Proxmox's default tag colors for special tags- * These override the hash-based colors for specific tags- */-const specialTagColors: Record<string, TagColorTheme> = {- production: {- light: { bg: 'rgb(254, 226, 226)', text: 'rgb(153, 27, 27)', border: 'rgb(239, 68, 68)' },- dark: { bg: 'rgb(127, 29, 29)', text: 'rgb(254, 202, 202)', border: 'rgb(185, 28, 28)' },- },- staging: {- light: { bg: 'rgb(254, 243, 199)', text: 'rgb(146, 64, 14)', border: 'rgb(245, 158, 11)' },- dark: { bg: 'rgb(120, 53, 15)', text: 'rgb(253, 230, 138)', border: 'rgb(217, 119, 6)' },- },- development: {- light: { bg: 'rgb(220, 252, 231)', text: 'rgb(22, 101, 52)', border: 'rgb(34, 197, 94)' },- dark: { bg: 'rgb(20, 83, 45)', text: 'rgb(187, 247, 208)', border: 'rgb(34, 197, 94)' },- },- backup: {- light: { bg: 'rgb(219, 234, 254)', text: 'rgb(30, 58, 138)', border: 'rgb(59, 130, 246)' },- dark: { bg: 'rgb(30, 58, 138)', text: 'rgb(191, 219, 254)', border: 'rgb(59, 130, 246)' },- },-};+function buildStyleFromRGB(rgb: [number, number, number]): TagColorStyle {+ const bg = rgbToCss(rgb);+ const text = getTextContrastClass(rgb) === 'light' ? '#ffffff' : '#000000';++ return {+ bg,+ text,+ border: bg,+ };+}/**- * Get color for a tag, checking special colors first+ * Get color for a tag.+ * Priority: Proxmox-supplied hex color -> Proxmox fallback hash algorithm.*/export function getTagColorWithSpecial(tag: string,- isDarkMode: boolean,-): { bg: string; text: string; border: string } {+ _isDarkMode: boolean,+ colorMap?: Record<string, string>,+): TagColorStyle {const lowerTag = tag.toLowerCase();-- // Check if it's a special tag- if (specialTagColors[lowerTag]) {- return isDarkMode ? specialTagColors[lowerTag].dark : specialTagColors[lowerTag].light;+ const proxmoxHex = colorMap?.[lowerTag];+ if (proxmoxHex) {+ const rgb = parseHexColor(proxmoxHex);+ if (rgb) {+ return buildStyleFromRGB(rgb);+ }}- // Otherwise use hash-based color- return isDarkMode ? getTagColorDark(tag) : getTagColor(tag);+ return buildStyleFromRGB(stringToRGB(tag));}diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.goindex 79cab17bb8..a9aceac04f 100644--- a/internal/ai/chat/service.go+++ b/internal/ai/chat/service.go@@ -1980,7 +1980,10 @@ func (s *Service) ExecutePatrolStream(ctx context.Context, req PatrolRequest, calog.Warn().Err(saveErr).Msg("failed to save patrol message after error")}}- return nil, err+ return &PatrolResponse{+ InputTokens: tempLoop.GetTotalInputTokens(),+ OutputTokens: tempLoop.GetTotalOutputTokens(),+ }, err}// Save result messagesdiff --git a/internal/ai/chat/service_patrol_additional_test.go b/internal/ai/chat/service_patrol_additional_test.goindex faa4688b50..df4893a98f 100644--- a/internal/ai/chat/service_patrol_additional_test.go+++ b/internal/ai/chat/service_patrol_additional_test.go@@ -3,6 +3,7 @@ package chatimport ("context""encoding/json"+ "errors""net/http""net/http/httptest""strings"@@ -198,6 +199,70 @@ func TestService_ExecutePatrolStream_Success(t *testing.T) {}}+func TestServiceExecutePatrolStreamReturnsPartialTokenCountsOnError(t *testing.T) {+ store, err := NewSessionStore(t.TempDir())+ if err != nil {+ t.Fatalf("failed to create session store: %v", err)+ }+ executor := tools.NewPulseToolExecutor(tools.ExecutorConfig{})++ service := &Service{+ started: true,+ sessions: store,+ executor: executor,+ cfg: &config.AIConfig{PatrolModel: "mock:model"},+ }+ executor.RegisterTool(tools.RegisteredTool{+ Definition: tools.Tool{+ Name: "test_tool",+ Description: "test tool",+ InputSchema: tools.InputSchema{+ Type: "object",+ Properties: map[string]tools.PropertySchema{},+ },+ },+ Handler: func(ctx context.Context, exec *tools.PulseToolExecutor, args map[string]interface{}) (tools.CallToolResult, error) {+ return tools.NewTextResult("tool ok"), nil+ },+ })+ callCount := 0+ service.providerFactory = func(modelStr string) (providers.StreamingProvider, error) {+ return &mockStreamingProvider{+ chatStreamFunc: func(ctx context.Context, req providers.ChatRequest, callback providers.StreamCallback) error {+ callCount+++ if callCount == 1 {+ callback(providers.StreamEvent{Type: "done", Data: providers.DoneEvent{+ InputTokens: 13,+ OutputTokens: 8,+ ToolCalls: []providers.ToolCall{{+ ID: "call-1",+ Name: "test_tool",+ Input: map[string]interface{}{},+ }},+ }})+ return nil+ }+ return errors.New("provider interrupted")+ },+ }, nil+ }++ resp, err := service.ExecutePatrolStream(context.Background(), PatrolRequest{+ Prompt: "check status",+ MaxTurns: 2,+ SessionID: "patrol-main",+ }, func(event StreamEvent) {})+ if err == nil {+ t.Fatal("expected patrol stream error")+ }+ if resp == nil {+ t.Fatal("expected partial patrol response")+ }+ if resp.InputTokens != 13 || resp.OutputTokens != 8 {+ t.Fatalf("unexpected partial token counts: %+v", resp)+ }+}+func TestService_ExecutePatrolStream_PulseStorageSnapshotsToleratesMalformedRecoveryMetadata(t *testing.T) {store, err := NewSessionStore(t.TempDir())if err != nil {diff --git a/internal/ai/cost/coverage_test.go b/internal/ai/cost/coverage_test.goindex 2e2cf728a4..948859a407 100644--- a/internal/ai/cost/coverage_test.go+++ b/internal/ai/cost/coverage_test.go@@ -49,17 +49,17 @@ func TestNormalizeModelForProvider(t *testing.T) {}func TestLookupPriceAndPatterns(t *testing.T) {- if _, ok := lookupPrice("", "gpt-4o"); ok {+ if _, ok := lookupPrice("", "gpt-4o", 0); ok {t.Fatal("expected empty provider to be unknown")}- if _, ok := lookupPrice("openai", ""); ok {+ if _, ok := lookupPrice("openai", "", 0); ok {t.Fatal("expected empty model to be unknown")}- if _, ok := lookupPrice("unknown", "model"); ok {+ if _, ok := lookupPrice("unknown", "model", 0); ok {t.Fatal("expected unknown provider to be unknown")}- price, ok := lookupPrice("openai", "gpt-4o-mini")+ price, ok := lookupPrice("openai", "gpt-4o-mini", 0)if !ok || price.InputUSDPerMTok == 0 {t.Fatalf("expected openai pricing match, got ok=%v price=%+v", ok, price)}@@ -78,6 +78,56 @@ func TestLookupPriceAndPatterns(t *testing.T) {}}+func TestLookupPriceUsesTieredGeminiPricing(t *testing.T) {+ under200k, ok := lookupPrice("gemini", "gemini-2.5-pro", 150_000)+ if !ok {+ t.Fatal("expected Gemini 2.5 Pro pricing to resolve")+ }+ if under200k.InputUSDPerMTok != 1.25 || under200k.OutputUSDPerMTok != 10.00 {+ t.Fatalf("unexpected <=200k tier: %+v", under200k)+ }++ over200k, ok := lookupPrice("gemini", "gemini-2.5-pro", 250_000)+ if !ok {+ t.Fatal("expected Gemini 2.5 Pro high-tier pricing to resolve")+ }+ if over200k.InputUSDPerMTok != 2.50 || over200k.OutputUSDPerMTok != 15.00 {+ t.Fatalf("unexpected >200k tier: %+v", over200k)+ }++ pro31, ok := lookupPrice("gemini", "gemini-3.1-pro-preview", 150_000)+ if !ok {+ t.Fatal("expected Gemini 3.1 Pro Preview pricing to resolve")+ }+ if pro31.InputUSDPerMTok != 2.00 || pro31.OutputUSDPerMTok != 12.00 {+ t.Fatalf("unexpected Gemini 3.1 Pro Preview pricing: %+v", pro31)+ }++ flash35, ok := lookupPrice("gemini", "gemini-3.5-flash", 50_000)+ if !ok {+ t.Fatal("expected Gemini 3.5 Flash pricing to resolve")+ }+ if flash35.InputUSDPerMTok != 1.50 || flash35.OutputUSDPerMTok != 9.00 {+ t.Fatalf("unexpected Gemini 3.5 Flash pricing: %+v", flash35)+ }++ flash25, ok := lookupPrice("gemini", "gemini-2.5-flash", 50_000)+ if !ok {+ t.Fatal("expected Gemini 2.5 Flash pricing to resolve")+ }+ if flash25.InputUSDPerMTok != 0.30 || flash25.OutputUSDPerMTok != 2.50 {+ t.Fatalf("unexpected Gemini 2.5 Flash pricing: %+v", flash25)+ }++ flashLite25, ok := lookupPrice("gemini", "gemini-2.5-flash-lite", 50_000)+ if !ok {+ t.Fatal("expected Gemini 2.5 Flash-Lite pricing to resolve")+ }+ if flashLite25.InputUSDPerMTok != 0.10 || flashLite25.OutputUSDPerMTok != 0.40 {+ t.Fatalf("unexpected Gemini 2.5 Flash-Lite pricing: %+v", flashLite25)+ }+}+func TestSetPersistence_LoadError(t *testing.T) {store := NewStore(30)mock := &savePersistence{loadErr: errors.New("load failed")}diff --git a/internal/ai/cost/pricing.go b/internal/ai/cost/pricing.goindex f2536890bd..3b6826973c 100644--- a/internal/ai/cost/pricing.go+++ b/internal/ai/cost/pricing.go@@ -13,7 +13,7 @@ type TokenPrice struct {// EstimateUSD returns an estimated USD cost for the given provider/model and token counts.// If the model pricing is unknown, ok is false and usd is 0.func EstimateUSD(provider, model string, inputTokens, outputTokens int64) (usd float64, ok bool, price TokenPrice) {- price, ok = lookupPrice(provider, model)+ price, ok = lookupPrice(provider, model, inputTokens)if !ok {return 0, false, TokenPrice{}}@@ -24,12 +24,18 @@ func EstimateUSD(provider, model string, inputTokens, outputTokens int64) (usd f}type modelPrice struct {- Pattern string+ Pattern string+ Tiers []priceTier+}++type priceTier struct {+ // MaxInputTokens is inclusive. Zero means no upper bound.+ MaxInputTokens int64InputUSDPerMTok float64OutputUSDPerMTok float64}-const pricingAsOf = "2026-04"+const pricingAsOf = "2026-06-04"// PricingAsOf indicates the effective date of the pricing table used for estimation.func PricingAsOf() string {@@ -40,37 +46,67 @@ func PricingAsOf() string {// The goal is quick estimation and relative comparisons, not exact billing.var providerPrices = map[string][]modelPrice{"openai": {- {Pattern: "gpt-4o*", InputUSDPerMTok: 5.00, OutputUSDPerMTok: 15.00},- {Pattern: "gpt-4o-mini*", InputUSDPerMTok: 0.15, OutputUSDPerMTok: 0.60},+ flatPrice("gpt-4o-mini*", 0.15, 0.60),+ flatPrice("gpt-4o*", 5.00, 15.00),},"anthropic": {- {Pattern: "claude-opus*", InputUSDPerMTok: 15.00, OutputUSDPerMTok: 75.00},- {Pattern: "claude-sonnet*", InputUSDPerMTok: 3.00, OutputUSDPerMTok: 15.00},- {Pattern: "claude-haiku*", InputUSDPerMTok: 0.25, OutputUSDPerMTok: 1.25},+ flatPrice("claude-opus*", 15.00, 75.00),+ flatPrice("claude-sonnet*", 3.00, 15.00),+ flatPrice("claude-haiku*", 0.25, 1.25),},"deepseek": {// DeepSeek docs include an input cache-hit discount; this uses cache-miss rates for conservative estimates.- {Pattern: "deepseek-v4-flash*", InputUSDPerMTok: 0.14, OutputUSDPerMTok: 0.28},- {Pattern: "deepseek-v4-pro*", InputUSDPerMTok: 0.435, OutputUSDPerMTok: 0.87},- {Pattern: "deepseek-*", InputUSDPerMTok: 0.14, OutputUSDPerMTok: 0.28},+ flatPrice("deepseek-v4-flash*", 0.14, 0.28),+ flatPrice("deepseek-v4-pro*", 0.435, 0.87),+ flatPrice("deepseek-*", 0.14, 0.28),},"gemini": {- // Gemini pricing (as of December 2025)- // Gemini 3 models are in preview, pricing may change- {Pattern: "gemini-3-pro*", InputUSDPerMTok: 1.25, OutputUSDPerMTok: 5.00},- {Pattern: "gemini-3-flash*", InputUSDPerMTok: 0.075, OutputUSDPerMTok: 0.30},- {Pattern: "gemini-2.5-pro*", InputUSDPerMTok: 1.25, OutputUSDPerMTok: 5.00},- {Pattern: "gemini-2.5-flash*", InputUSDPerMTok: 0.075, OutputUSDPerMTok: 0.30},- {Pattern: "gemini-1.5-pro*", InputUSDPerMTok: 1.25, OutputUSDPerMTok: 5.00},- {Pattern: "gemini-1.5-flash*", InputUSDPerMTok: 0.075, OutputUSDPerMTok: 0.30},- {Pattern: "gemini-*", InputUSDPerMTok: 0.075, OutputUSDPerMTok: 0.30}, // Default to flash pricing+ // Gemini Developer API standard paid-tier pricing, checked from+ // https://ai.google.dev/gemini-api/docs/pricing on 2026-06-04.+ flatPrice("gemini-3.5-flash*", 1.50, 9.00),+ tieredPrice("gemini-3.1-pro-preview*", priceTier{MaxInputTokens: 200_000, InputUSDPerMTok: 2.00, OutputUSDPerMTok: 12.00}, priceTier{InputUSDPerMTok: 4.00, OutputUSDPerMTok: 18.00}),+ tieredPrice("gemini-3.1-pro*", priceTier{MaxInputTokens: 200_000, InputUSDPerMTok: 2.00, OutputUSDPerMTok: 12.00}, priceTier{InputUSDPerMTok: 4.00, OutputUSDPerMTok: 18.00}),+ flatPrice("gemini-3.1-flash-live-preview*", 0.75, 4.50),+ flatPrice("gemini-3.1-flash-image*", 0.50, 3.00),+ flatPrice("gemini-3.1-flash-lite*", 0.25, 1.50),+ flatPrice("gemini-3-pro-image*", 2.00, 12.00),+ tieredPrice("gemini-3-pro-preview*", priceTier{MaxInputTokens: 200_000, InputUSDPerMTok: 2.00, OutputUSDPerMTok: 12.00}, priceTier{InputUSDPerMTok: 4.00, OutputUSDPerMTok: 18.00}),+ tieredPrice("gemini-3-pro*", priceTier{MaxInputTokens: 200_000, InputUSDPerMTok: 2.00, OutputUSDPerMTok: 12.00}, priceTier{InputUSDPerMTok: 4.00, OutputUSDPerMTok: 18.00}),+ flatPrice("gemini-3-flash-preview*", 0.50, 3.00),+ flatPrice("gemini-3-flash*", 0.50, 3.00),+ tieredPrice("gemini-2.5-pro*", priceTier{MaxInputTokens: 200_000, InputUSDPerMTok: 1.25, OutputUSDPerMTok: 10.00}, priceTier{InputUSDPerMTok: 2.50, OutputUSDPerMTok: 15.00}),+ flatPrice("gemini-2.5-flash-lite-preview*", 0.10, 0.40),+ flatPrice("gemini-2.5-flash-lite*", 0.10, 0.40),+ flatPrice("gemini-2.5-flash*", 0.30, 2.50),+ flatPrice("gemini-2.0-flash-lite*", 0.075, 0.30),+ flatPrice("gemini-2.0-flash*", 0.10, 0.40),+ flatPrice("gemini-1.5-pro*", 1.25, 5.00),+ flatPrice("gemini-1.5-flash*", 0.075, 0.30),+ flatPrice("gemini-*", 0.30, 2.50), // Default to current Flash pricing.},"ollama": {- {Pattern: "*", InputUSDPerMTok: 0, OutputUSDPerMTok: 0},+ flatPrice("*", 0, 0),},}-func lookupPrice(provider, model string) (TokenPrice, bool) {+func flatPrice(pattern string, inputUSDPerMTok, outputUSDPerMTok float64) modelPrice {+ return modelPrice{+ Pattern: pattern,+ Tiers: []priceTier{{+ InputUSDPerMTok: inputUSDPerMTok,+ OutputUSDPerMTok: outputUSDPerMTok,+ }},+ }+}++func tieredPrice(pattern string, tiers ...priceTier) modelPrice {+ return modelPrice{+ Pattern: pattern,+ Tiers: tiers,+ }+}++func lookupPrice(provider, model string, inputTokens int64) (TokenPrice, bool) {provider = strings.ToLower(strings.TrimSpace(provider))model = strings.ToLower(strings.TrimSpace(model))if provider == "" || model == "" {@@ -84,9 +120,13 @@ func lookupPrice(provider, model string) (TokenPrice, bool) {for _, p := range prices {if matchPattern(model, strings.ToLower(p.Pattern)) {+ tier, ok := selectPriceTier(p.Tiers, inputTokens)+ if !ok {+ return TokenPrice{}, false+ }return TokenPrice{- InputUSDPerMTok: p.InputUSDPerMTok,- OutputUSDPerMTok: p.OutputUSDPerMTok,+ InputUSDPerMTok: tier.InputUSDPerMTok,+ OutputUSDPerMTok: tier.OutputUSDPerMTok,AsOf: pricingAsOf,}, true}@@ -94,6 +134,21 @@ func lookupPrice(provider, model string) (TokenPrice, bool) {return TokenPrice{}, false}+func selectPriceTier(tiers []priceTier, inputTokens int64) (priceTier, bool) {+ if len(tiers) == 0 {+ return priceTier{}, false+ }+ if inputTokens < 0 {+ inputTokens = 0+ }+ for _, tier := range tiers {+ if tier.MaxInputTokens == 0 || inputTokens <= tier.MaxInputTokens {+ return tier, true+ }+ }+ return tiers[len(tiers)-1], true+}+func matchPattern(model, pattern string) bool {if pattern == "*" {return truediff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex 52ec99937e..35c8d1087b 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -531,6 +531,9 @@ func (p *PatrolService) runAIAnalysisState(ctx context.Context, snap patrolRunti}if chatErr != nil {+ if attempt != nil && attempt.response != nil {+ p.recordPatrolUsage(attempt.response.InputTokens, attempt.response.OutputTokens)+ }if !noStream {p.setStreamPhase("idle")p.broadcast(PatrolStreamEvent{Type: "error", Content: chatErr.Error()})@@ -734,6 +737,9 @@ func (p *PatrolService) runEvaluationPass(ctx context.Context, adapter *patrolFi})if err != nil {+ if resp != nil {+ p.recordPatrolUsage(resp.InputTokens, resp.OutputTokens)+ }log.Warn().Err(err).Msg("AI Patrol: Evaluation pass failed")return nil, err}diff --git a/internal/ai/patrol_ai_eval_additional_test.go b/internal/ai/patrol_ai_eval_additional_test.goindex 27b129dda6..509ee772ee 100644--- a/internal/ai/patrol_ai_eval_additional_test.go+++ b/internal/ai/patrol_ai_eval_additional_test.go@@ -2,6 +2,7 @@ package aiimport ("context"+ "errors""strings""testing"@@ -75,3 +76,31 @@ func TestRunEvaluationPass(t *testing.T) {t.Fatalf("unexpected evaluation response: %+v", resp)}}++func TestRunEvaluationPassRecordsPartialUsageOnStreamError(t *testing.T) {+ persistence := config.NewConfigPersistence(t.TempDir())+ svc := NewService(persistence, nil)+ svc.cfg = &config.AIConfig{Enabled: true, PatrolModel: "mock:patrol"}+ svc.provider = &mockProvider{nameFunc: func() string { return "mock" }}+ svc.SetChatService(&patrolMockChatService{+ executePatrolStreamFunc: func(ctx context.Context, req PatrolExecuteRequest, callback ChatStreamCallback) (*PatrolStreamResponse, error) {+ return &PatrolStreamResponse{InputTokens: 11, OutputTokens: 7}, errors.New("stream interrupted")+ },+ })++ ps := NewPatrolService(svc, nil)+ resp, err := ps.runEvaluationPass(context.Background(), nil, []DetectedSignal{{SignalType: SignalHighCPU}}, "patrol-run-eval")+ if err == nil {+ t.Fatal("expected evaluation error")+ }+ if resp != nil {+ t.Fatalf("expected no response on evaluation error, got %+v", resp)+ }+ events := svc.ListCostEvents(1)+ if len(events) != 1 {+ t.Fatalf("expected one partial usage event, got %d", len(events))+ }+ if events[0].Provider != "mock" || events[0].RequestModel != "mock:patrol" || events[0].UseCase != "patrol" || events[0].InputTokens != 11 || events[0].OutputTokens != 7 {+ t.Fatalf("unexpected partial usage event: %+v", events[0])+ }+}diff --git a/internal/ai/service_coverage_imp_test.go b/internal/ai/service_coverage_imp_test.goindex 2e6de25d4c..a9a5f53b1f 100644--- a/internal/ai/service_coverage_imp_test.go+++ b/internal/ai/service_coverage_imp_test.go@@ -33,9 +33,13 @@ func TestService_QuickAnalysis(t *testing.T) {t.Fatalf("execution_id=%q want patrol-run-123", req.ExecutionID)}return &providers.ChatResponse{- Content: "Analysis Result",+ Content: "Analysis Result",+ Model: "fast-model-response",+ InputTokens: 12,+ OutputTokens: 5,}, nil},+ nameFunc: func() string { return "mock-provider" },}svc.provider = mockProvsvc.cfg = &config.AIConfig{@@ -54,6 +58,13 @@ func TestService_QuickAnalysis(t *testing.T) {if res != "Analysis Result" {t.Errorf("Unexpected result: %s", res)}+ events := svc.ListCostEvents(1)+ if len(events) != 1 {+ t.Fatalf("expected QuickAnalysis usage event, got %d", len(events))+ }+ if events[0].Provider == "" || events[0].UseCase != "patrol" || events[0].InputTokens != 12 || events[0].OutputTokens != 5 {+ t.Fatalf("unexpected QuickAnalysis usage event: %+v", events[0])+ }// Case 3: Empty responsemockProv.chatFunc = func(ctx context.Context, req providers.ChatRequest) (*providers.ChatResponse, error) {diff --git a/internal/api/chat_service_adapter.go b/internal/api/chat_service_adapter.goindex d432767f44..13a3a6b651 100644--- a/internal/api/chat_service_adapter.go+++ b/internal/api/chat_service_adapter.go@@ -43,6 +43,13 @@ func (a *chatServiceAdapter) ExecutePatrolStream(ctx context.Context, req ai.PatMaxTurns: req.MaxTurns,}, adaptCallback(callback))if err != nil {+ if resp != nil {+ return &ai.PatrolStreamResponse{+ Content: resp.Content,+ InputTokens: resp.InputTokens,+ OutputTokens: resp.OutputTokens,+ }, err+ }return nil, err}return &ai.PatrolStreamResponse{diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.goindex 434df2cc44..9ccf05bfef 100644--- a/internal/api/config_handlers.go+++ b/internal/api/config_handlers.go@@ -669,6 +669,8 @@ type NodeConfigRequest struct {Password string `json:"password,omitempty"`TokenName string `json:"tokenName,omitempty"`TokenValue string `json:"tokenValue,omitempty"`+ TokenID string `json:"tokenId,omitempty"`+ TokenSecret string `json:"tokenSecret,omitempty"`Fingerprint string `json:"fingerprint,omitempty"`VerifySSL *bool `json:"verifySSL,omitempty"`MonitorVMs *bool `json:"monitorVMs,omitempty"` // PVE only@@ -691,6 +693,18 @@ type NodeConfigRequest struct {Enabled *bool `json:"enabled,omitempty"` // Lifecycle toggle; nil on update preserves current}+func (r *NodeConfigRequest) normalizeTokenAliases() {+ r.TokenName = strings.TrimSpace(r.TokenName)+ r.TokenValue = strings.TrimSpace(r.TokenValue)++ if r.TokenName == "" {+ r.TokenName = strings.TrimSpace(r.TokenID)+ }+ if r.TokenValue == "" {+ r.TokenValue = strings.TrimSpace(r.TokenSecret)+ }+}+// NodeResponse represents a node in API responsestype NodeResponse struct {ID string `json:"id"`diff --git a/internal/api/config_handlers_add_test.go b/internal/api/config_handlers_add_test.goindex 50988a265d..3d29aabebf 100644--- a/internal/api/config_handlers_add_test.go+++ b/internal/api/config_handlers_add_test.go@@ -156,6 +156,31 @@ func TestHandleAddNode(t *testing.T) {}},},+ {+ name: "success_add_pve_token_aliases",+ requestBody: map[string]interface{}{+ "name": "test-token-alias-pve",+ "type": "pve",+ "host": "10.0.0.4",+ "tokenId": "root@pam!alias",+ "tokenSecret": "alias-secret",+ },+ expectedStatus: http.StatusCreated,+ verifyConfig: func(t *testing.T, c *config.Config) {+ for _, node := range c.PVEInstances {+ if node.Name == "test-token-alias-pve" {+ if node.TokenName != "root@pam!alias" {+ t.Errorf("expected token name alias to persist, got %q", node.TokenName)+ }+ if node.TokenValue != "alias-secret" {+ t.Errorf("expected token secret alias to persist, got %q", node.TokenValue)+ }+ return+ }+ }+ t.Error("new PVE node (token aliases) not found in config")+ },+ },}for _, tt := range tests {@@ -177,6 +202,33 @@ func TestHandleAddNode(t *testing.T) {}}+func TestNodeConfigRequestNormalizeTokenAliases(t *testing.T) {+ req := NodeConfigRequest{+ TokenID: " root@pam!token ",+ TokenSecret: " secret ",+ }+ req.normalizeTokenAliases()++ if req.TokenName != "root@pam!token" {+ t.Fatalf("TokenName = %q, want tokenId alias", req.TokenName)+ }+ if req.TokenValue != "secret" {+ t.Fatalf("TokenValue = %q, want tokenSecret alias", req.TokenValue)+ }++ req = NodeConfigRequest{+ TokenName: " root@pam!canonical ",+ TokenValue: " canonical-secret ",+ TokenID: "root@pam!alias",+ TokenSecret: "alias-secret",+ }+ req.normalizeTokenAliases()++ if req.TokenName != "root@pam!canonical" || req.TokenValue != "canonical-secret" {+ t.Fatalf("canonical token fields must win over aliases, got name=%q value=%q", req.TokenName, req.TokenValue)+ }+}+func TestHandleAddNode_PBSTurnkeyTokenCreationUsesCanonicalPulseURL(t *testing.T) {tempDir := t.TempDir()diff --git a/internal/api/config_handlers_setup_script_test.go b/internal/api/config_handlers_setup_script_test.goindex 641aafe32e..4c570d6c1a 100644--- a/internal/api/config_handlers_setup_script_test.go+++ b/internal/api/config_handlers_setup_script_test.go@@ -300,7 +300,11 @@ func TestPVESetupScript_ConfiguresPulseMonitorRoleSafely(t *testing.T) {// Privileges must be comma-separated for pveum, and generated tokens must stay privilege-separated.wantSnippets := []string{- `TOKEN_OUTPUT=$(pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 2>&1)`,+ `extract_pve_token_value()`,+ `create_pve_token()`,+ `pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 --output-format json`,+ `pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 2>&1`,+ `TOKEN_VALUE=$(extract_pve_token_value "$TOKEN_OUTPUT")`,`pveum aclmod / -user pulse-monitor@pve -role PVEAuditor`,`pveum aclmod / -token "$PULSE_TOKEN_ID" -role PVEAuditor`,`PRIV_STRING="$(IFS=,; echo "${EXTRA_PRIVS[*]}")"`,@@ -318,6 +322,91 @@ func TestPVESetupScript_ConfiguresPulseMonitorRoleSafely(t *testing.T) {}}+func TestPVESetupScript_HardensTokenValueExtraction(t *testing.T) {+ tempDir := t.TempDir()+ cfg := &config.Config{+ DataPath: tempDir,+ ConfigPath: tempDir,+ }++ handlers := newTestConfigHandlers(t, cfg)++ req := httptest.NewRequest(http.MethodGet,+ "/api/setup-script?type=pve&host=http://sentinel-host:8006&pulse_url=http://sentinel-url:7656&setup_token=deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", nil)+ rr := httptest.NewRecorder()++ handlers.HandleSetupScript(rr, req)++ if rr.Code != http.StatusOK {+ t.Fatalf("expected 200 OK, got %d (%s)", rr.Code, rr.Body.String())+ }++ script := rr.Body.String()+ wantSnippets := []string{+ `extract_json_string_field()`,+ `sed -n 's/.*"'"$field_name"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p'`,+ `awk -F'[|│]'`,+ `unknown option|unknown command|no such option|unable to parse option|output-format`,+ }+ for _, snippet := range wantSnippets {+ if !containsString(script, snippet) {+ t.Fatalf("expected generated script to contain:\n%s\n\nGot (first 1200 chars):\n%s", snippet, truncate(script, 1200))+ }+ }++ jsonCreate := strings.Index(script, `pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 --output-format json`)+ legacyCreate := strings.Index(script, `pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 2>&1`)+ if jsonCreate < 0 || legacyCreate < 0 || jsonCreate > legacyCreate {+ t.Fatalf("generated script must try JSON token output before legacy output fallback")+ }+ if containsString(script, `grep "│ value" | awk -F'│'`) {+ t.Fatalf("expected hardened token parser to replace the old grep/awk single-shape extraction")+ }+}++func TestPVESetupScript_PrefersGuestAgentPrivileges(t *testing.T) {+ tempDir := t.TempDir()+ cfg := &config.Config{+ DataPath: tempDir,+ ConfigPath: tempDir,+ }++ handlers := newTestConfigHandlers(t, cfg)++ req := httptest.NewRequest(http.MethodGet,+ "/api/setup-script?type=pve&host=http://sentinel-host:8006&pulse_url=http://sentinel-url:7656&setup_token=deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", nil)+ rr := httptest.NewRecorder()++ handlers.HandleSetupScript(rr, req)++ if rr.Code != http.StatusOK {+ t.Fatalf("expected 200 OK, got %d (%s)", rr.Code, rr.Body.String())+ }++ script := rr.Body.String()+ wantSnippets := []string{+ `local HAS_VM_GUEST_AGENT_FILE_READ=false`,+ `pveum role add TestGuestAgentFileRead -privs VM.GuestAgent.FileRead 2>/dev/null`,+ `if [ "$HAS_VM_GUEST_AGENT_AUDIT" = true ]; then`,+ `EXTRA_PRIVS+=("VM.GuestAgent.Audit")`,+ `if [ "$HAS_VM_GUEST_AGENT_FILE_READ" = true ]; then`,+ `EXTRA_PRIVS+=("VM.GuestAgent.FileRead")`,+ `elif [ "$HAS_VM_MONITOR" = true ]; then`,+ `EXTRA_PRIVS+=("VM.Monitor")`,+ }+ for _, snippet := range wantSnippets {+ if !containsString(script, snippet) {+ t.Fatalf("expected generated script to contain:\n%s\n\nGot (first 900 chars):\n%s", snippet, truncate(script, 900))+ }+ }++ guestBranch := strings.Index(script, `if [ "$HAS_VM_GUEST_AGENT_AUDIT" = true ]; then`)+ monitorBranch := strings.Index(script, `elif [ "$HAS_VM_MONITOR" = true ]; then`)+ if guestBranch < 0 || monitorBranch < 0 || guestBranch > monitorBranch {+ t.Fatalf("generated script must prefer VM.GuestAgent.* privileges before VM.Monitor")+ }+}+func TestPVESetupScript_UsesFailFastRetryGuidance(t *testing.T) {tempDir := t.TempDir()cfg := &config.Config{diff --git a/internal/api/config_node_handlers.go b/internal/api/config_node_handlers.goindex c532dedc59..63309d244c 100644--- a/internal/api/config_node_handlers.go+++ b/internal/api/config_node_handlers.go@@ -266,6 +266,7 @@ func (h *ConfigHandlers) handleAddNode(w http.ResponseWriter, r *http.Request) {http.Error(w, "Invalid request body", http.StatusBadRequest)return}+ req.normalizeTokenAliases()log.Info().Str("type", req.Type).@@ -764,6 +765,7 @@ func (h *ConfigHandlers) handleTestConnection(w http.ResponseWriter, r *http.Reqhttp.Error(w, "Invalid request body", http.StatusBadRequest)return}+ req.normalizeTokenAliases()log.Info().Str("type", req.Type).@@ -1075,6 +1077,7 @@ func (h *ConfigHandlers) handleUpdateNode(w http.ResponseWriter, r *http.Requesthttp.Error(w, "Invalid request body", http.StatusBadRequest)return}+ req.normalizeTokenAliases()// Debug: Log the received temperatureMonitoringEnabled valuelog.Info().@@ -1699,6 +1702,7 @@ func (h *ConfigHandlers) handleTestNodeConfig(w http.ResponseWriter, r *http.Reqhttp.Error(w, "Invalid request body", http.StatusBadRequest)return}+ req.normalizeTokenAliases()var testResult map[string]interface{}diff --git a/internal/api/route_inventory_test.go b/internal/api/route_inventory_test.goindex 902e441b16..e72191e33f 100644--- a/internal/api/route_inventory_test.go+++ b/internal/api/route_inventory_test.go@@ -337,6 +337,7 @@ var bareRouteAllowlist = []string{"/api/server/info","/api/setup-script","/api/state",+ "/api/state/summary","/api/system/mock-mode","/api/system/ssh-config","/api/system/verify-temperature-ssh",@@ -365,6 +366,7 @@ var allRouteAllowlist = []string{"/api/health","/api/monitoring/scheduler/health","/api/state",+ "/api/state/summary","/api/logs/stream","/api/logs/download","/api/logs/level",diff --git a/internal/api/router_routes_auth_security.go b/internal/api/router_routes_auth_security.goindex ebb562b945..2467a98800 100644--- a/internal/api/router_routes_auth_security.go+++ b/internal/api/router_routes_auth_security.go@@ -25,6 +25,7 @@ func (r *Router) registerAuthSecurityInstallRoutes() {// API routesr.mux.HandleFunc("/api/health", r.handleHealth)r.mux.HandleFunc("/api/state", r.handleState)+ r.mux.HandleFunc("/api/state/summary", r.handleStateSummary)r.mux.HandleFunc("/api/version", r.handleVersion)r.mux.HandleFunc("/api/security/validate-bootstrap-token", r.handleValidateBootstrapToken)// Security routesdiff --git a/internal/api/router_state_test.go b/internal/api/router_state_test.goindex 82f94080c5..d6653a3c13 100644--- a/internal/api/router_state_test.go+++ b/internal/api/router_state_test.go@@ -5,10 +5,12 @@ import ("net/http""net/http/httptest""testing"+ "time""github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/monitoring"+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources""github.com/rcourtman/pulse-go-rewrite/pkg/auth""github.com/stretchr/testify/assert")@@ -104,3 +106,96 @@ func TestRouter_HandleState_MockIsolation(t *testing.T) {assert.Equal(t, http.StatusUnauthorized, w.Code)})}++func TestRouter_HandleStateSummary(t *testing.T) {+ dataPath := t.TempDir()+ hp, _ := auth.HashPassword("password")+ cfg := &config.Config{+ DataPath: dataPath,+ AuthUser: "admin",+ AuthPass: hp,+ }+ InitSessionStore(dataPath)+ InitCSRFStore(dataPath)+ monitor, state, _ := newTestMonitor(t)+ lastUpdate := time.Date(2026, 5, 24, 10, 11, 12, 0, time.UTC)+ state.Nodes = []models.Node{{ID: "node-1"}, {ID: "node-2"}}+ state.VMs = []models.VM{{ID: "vm-1"}}+ state.Containers = []models.Container{{ID: "ct-1"}, {ID: "ct-2"}, {ID: "ct-3"}}+ state.ActiveAlerts = []models.Alert{{ID: "alert-1"}}+ state.DockerHosts = []models.DockerHost{+ {+ ID: "docker-1",+ Hostname: "docker.local",+ DisplayName: "Docker Host",+ UptimeSeconds: 3600,+ CPUUsage: 12.5,+ Containers: []models.DockerContainer{+ {ID: "container-1"},+ {ID: "container-2"},+ },+ },+ }+ state.LastUpdate = lastUpdate+ syncTestResourceStore(t, monitor, state)++ router := &Router{config: cfg, monitor: monitor}+ req := httptest.NewRequest(http.MethodGet, "/api/state/summary", nil)+ req.SetBasicAuth("admin", "password")+ rec := httptest.NewRecorder()++ router.handleStateSummary(rec, req)++ assert.Equal(t, http.StatusOK, rec.Code)++ var summary stateSummaryResponse+ err := json.Unmarshal(rec.Body.Bytes(), &summary)+ assert.NoError(t, err)+ assert.Equal(t, 1, summary.ActiveAlerts)+ assert.Equal(t, 2, summary.Nodes)+ assert.Equal(t, 1, summary.VMs)+ assert.Equal(t, 3, summary.Containers)+ assert.Equal(t, lastUpdate, summary.LastUpdate)+ if assert.Len(t, summary.DockerHosts, 1) {+ assert.Equal(t, "Docker Host", summary.DockerHosts[0].Name)+ assert.Equal(t, 2, summary.DockerHosts[0].Containers)+ assert.Equal(t, int64(3600), summary.DockerHosts[0].UptimeSeconds)+ assert.Equal(t, 12.5, summary.DockerHosts[0].CPUUsagePercent)+ }+}++func TestBuildStateSummaryCountsSnapshotResources(t *testing.T) {+ lastUpdate := time.Date(2026, 5, 24, 10, 11, 12, 0, time.UTC)+ snapshot := models.StateSnapshot{+ ActiveAlerts: []models.Alert{{ID: "alert-1"}},+ Nodes: []models.Node{{ID: "node-1"}, {ID: "node-2"}},+ VMs: []models.VM{{ID: "vm-1"}},+ Containers: []models.Container{{ID: "ct-1"}, {ID: "ct-2"}, {ID: "ct-3"}},+ DockerHosts: []models.DockerHost{{+ ID: "docker-1",+ Hostname: "docker.local",+ DisplayName: "Docker Host",+ CustomDisplayName: "Custom Docker Host",+ UptimeSeconds: 3600,+ CPUUsage: 12.5,+ Containers: []models.DockerContainer{{ID: "container-1"}, {ID: "container-2"}},+ }},+ LastUpdate: lastUpdate,+ }+ registry := unifiedresources.NewRegistry(nil)+ registry.IngestSnapshot(snapshot)++ summary := buildStateSummary(registry, len(snapshot.ActiveAlerts), snapshot.LastUpdate)++ assert.Equal(t, 1, summary.ActiveAlerts)+ assert.Equal(t, 2, summary.Nodes)+ assert.Equal(t, 1, summary.VMs)+ assert.Equal(t, 3, summary.Containers)+ assert.Equal(t, lastUpdate, summary.LastUpdate)+ if assert.Len(t, summary.DockerHosts, 1) {+ assert.Equal(t, "Custom Docker Host", summary.DockerHosts[0].Name)+ assert.Equal(t, 2, summary.DockerHosts[0].Containers)+ assert.Equal(t, int64(3600), summary.DockerHosts[0].UptimeSeconds)+ assert.Equal(t, 12.5, summary.DockerHosts[0].CPUUsagePercent)+ }+}diff --git a/internal/api/setup_script_render.go b/internal/api/setup_script_render.goindex 96d004cb13..e50db49422 100644--- a/internal/api/setup_script_render.go+++ b/internal/api/setup_script_render.go@@ -261,6 +261,7 @@ configure_pve_pulse_monitor_role() {local apply_token_acl="$1"local HAS_VM_MONITOR=falselocal HAS_VM_GUEST_AGENT_AUDIT=false+ local HAS_VM_GUEST_AGENT_FILE_READ=falselocal HAS_SYS_AUDIT=falselocal PVE_VERSION=""local EXTRA_PRIVS=()@@ -278,6 +279,13 @@ configure_pve_pulse_monitor_role() {pveum role delete TestGuestAgentAudit 2>/dev/null || truefi+ if pveum role list 2>/dev/null | grep -q "VM.GuestAgent.FileRead"; then+ HAS_VM_GUEST_AGENT_FILE_READ=true+ elif pveum role add TestGuestAgentFileRead -privs VM.GuestAgent.FileRead 2>/dev/null; then+ HAS_VM_GUEST_AGENT_FILE_READ=true+ pveum role delete TestGuestAgentFileRead 2>/dev/null || true+ fi+if pveum role list 2>/dev/null | grep -q "Sys.Audit"; thenHAS_SYS_AUDIT=trueelif pveum role add TestSysAudit -privs Sys.Audit 2>/dev/null; then@@ -293,10 +301,13 @@ configure_pve_pulse_monitor_role() {EXTRA_PRIVS+=("Sys.Audit")fi- if [ "$HAS_VM_MONITOR" = true ]; then- EXTRA_PRIVS+=("VM.Monitor")- elif [ "$HAS_VM_GUEST_AGENT_AUDIT" = true ]; then+ if [ "$HAS_VM_GUEST_AGENT_AUDIT" = true ]; thenEXTRA_PRIVS+=("VM.GuestAgent.Audit")+ if [ "$HAS_VM_GUEST_AGENT_FILE_READ" = true ]; then+ EXTRA_PRIVS+=("VM.GuestAgent.FileRead")+ fi+ elif [ "$HAS_VM_MONITOR" = true ]; then+ EXTRA_PRIVS+=("VM.Monitor")fiif [ ${#EXTRA_PRIVS[@]} -gt 0 ]; then@@ -612,6 +623,66 @@ pveum user add pulse-monitor@pve --comment "Pulse monitoring service" 2>/dev/nulAUTO_REG_SUCCESS=false+extract_json_string_field() {+ local json_input="$1"+ local field_name="$2"++ printf '%%s\n' "$json_input" | sed -n 's/.*"'"$field_name"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1+}++extract_pve_token_value() {+ local token_output="$1"+ local token_value=""++ token_value=$(extract_json_string_field "$token_output" "value")+ if [ -n "$token_value" ]; then+ printf '%%s\n' "$token_value"+ return 0+ fi++ printf '%%s\n' "$token_output" | awk -F'[|│]' '+ function trim(value) {+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)+ return value+ }++ {+ key = trim($2)+ value = trim($3)+ if (key == "value" && value != "") {+ print value+ exit+ }+ }+ '+}++create_pve_token() {+ if TOKEN_OUTPUT=$(pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 --output-format json 2>&1); then+ TOKEN_CREATE_RC=0+ else+ TOKEN_CREATE_RC=$?+ fi++ if [ "$TOKEN_CREATE_RC" -eq 0 ]; then+ TOKEN_VALUE=$(extract_pve_token_value "$TOKEN_OUTPUT")+ return 0+ fi++ if echo "$TOKEN_OUTPUT" | grep -Eqi 'unknown option|unknown command|no such option|unable to parse option|output-format'; then+ if TOKEN_OUTPUT=$(pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 2>&1); then+ TOKEN_CREATE_RC=0+ else+ TOKEN_CREATE_RC=$?+ fi+ if [ "$TOKEN_CREATE_RC" -eq 0 ]; then+ TOKEN_VALUE=$(extract_pve_token_value "$TOKEN_OUTPUT")+ fi+ fi++ return "$TOKEN_CREATE_RC"+}+attempt_auto_registration() {if [ -z "$PULSE_SETUP_TOKEN" ]; thenif [ -t 0 ]; then@@ -697,8 +768,7 @@ if pulse_pve_token_exists; thenfi# Create a privilege-separated token and capture value (shown once by Proxmox)-TOKEN_OUTPUT=$(pveum user token add pulse-monitor@pve "$TOKEN_NAME" --privsep 1 2>&1)-TOKEN_CREATE_RC=$?+create_pve_tokenif [ "$TOKEN_CREATE_RC" -ne 0 ]; thenecho "❌ Failed to create token '$TOKEN_NAME'"echo "$TOKEN_OUTPUT"@@ -707,7 +777,6 @@ if [ "$TOKEN_CREATE_RC" -ne 0 ]; thenecho ""elseTOKEN_CREATED=true- TOKEN_VALUE=$(echo "$TOKEN_OUTPUT" | grep "│ value" | awk -F'│' '{print $3}' | tr -d ' ' | tail -1)if [ -z "$TOKEN_VALUE" ]; thenecho ""diff --git a/internal/api/state_summary.go b/internal/api/state_summary.gonew file mode 100644index 0000000000..bcf5968168--- /dev/null+++ b/internal/api/state_summary.go@@ -0,0 +1,108 @@+package api++import (+ "net/http"+ "strings"+ "time"++ "github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"+ "github.com/rcourtman/pulse-go-rewrite/internal/utils"+ "github.com/rs/zerolog/log"+)++type stateSummaryResponse struct {+ ActiveAlerts int `json:"activeAlerts"`+ Nodes int `json:"nodes"`+ VMs int `json:"vms"`+ Containers int `json:"containers"`+ DockerHosts []stateSummaryDockerHost `json:"dockerHosts"`+ LastUpdate time.Time `json:"lastUpdate"`+}++type stateSummaryDockerHost struct {+ Name string `json:"name"`+ Containers int `json:"containers"`+ UptimeSeconds int64 `json:"uptimeSeconds"`+ CPUUsagePercent float64 `json:"cpuUsagePercent"`+}++func buildStateSummary(readState unifiedresources.ReadState, activeAlerts int, lastUpdate time.Time) stateSummaryResponse {+ if readState == nil {+ return stateSummaryResponse{+ ActiveAlerts: activeAlerts,+ LastUpdate: lastUpdate,+ }+ }++ dockerHosts := make([]stateSummaryDockerHost, 0, len(readState.DockerHosts()))+ for _, host := range readState.DockerHosts() {+ if host == nil {+ continue+ }++ name := strings.TrimSpace(host.CustomDisplayName())+ if name == "" {+ name = strings.TrimSpace(host.DisplayName())+ }+ if name == "" {+ name = strings.TrimSpace(host.Hostname())+ }+ if name == "" {+ name = host.ID()+ }++ dockerHosts = append(dockerHosts, stateSummaryDockerHost{+ Name: name,+ Containers: len(host.Containers()),+ UptimeSeconds: host.UptimeSeconds(),+ CPUUsagePercent: host.CPUPercent(),+ })+ }++ return stateSummaryResponse{+ ActiveAlerts: activeAlerts,+ Nodes: len(readState.Nodes()),+ VMs: len(readState.VMs()),+ Containers: len(readState.Containers()),+ DockerHosts: dockerHosts,+ LastUpdate: lastUpdate,+ }+}++func (r *Router) handleStateSummary(w http.ResponseWriter, req *http.Request) {+ if req.Method != http.MethodGet {+ writeErrorResponse(w, http.StatusMethodNotAllowed, "method_not_allowed",+ "Only GET method is allowed", nil)+ return+ }++ authWriter := &responseCapture{ResponseWriter: w}+ if !checkAuth(r.config, authWriter, req, false) {+ if !authWriter.wrote {+ writeErrorResponse(w, http.StatusUnauthorized, "unauthorized",+ "Authentication required", nil)+ }+ return+ }++ if record := getAPITokenRecordFromRequest(req); record != nil && !record.HasScope(config.ScopeMonitoringRead) {+ respondMissingScope(w, config.ScopeMonitoringRead)+ return+ }++ monitor := r.getTenantMonitor(req.Context())+ if monitor == nil {+ writeErrorResponse(w, http.StatusInternalServerError, "no_monitor",+ "Monitor not available", nil)+ return+ }++ readState := monitor.GetUnifiedReadStateOrSnapshot()+ snapshot := monitor.ReadSnapshot()+ if err := utils.WriteJSONResponse(w, buildStateSummary(readState, len(snapshot.ActiveAlerts), snapshot.LastUpdate)); err != nil {+ log.Error().Err(err).Msg("Failed to encode state summary response")+ writeErrorResponse(w, http.StatusInternalServerError, "encoding_error",+ "Failed to encode state summary", nil)+ }+}diff --git a/internal/api/unified_agent_download_test.go b/internal/api/unified_agent_download_test.goindex 44a4473a68..684cfef529 100644--- a/internal/api/unified_agent_download_test.go+++ b/internal/api/unified_agent_download_test.go@@ -63,3 +63,32 @@ func TestHandleDownloadUnifiedAgentSetsChecksumAndInvalidatesOnChange(t *testingt.Fatalf("unexpected response body after update")}}++func TestHandleDownloadUnifiedAgentAllowsVersionCacheKeyQuery(t *testing.T) {+ binDir := setupTempPulseBin(t)+ filePath := filepath.Join(binDir, "pulse-agent-linux-amd64")++ payload := validTestUnifiedAgentBinary("agent-binary-v1")+ if err := os.WriteFile(filePath, payload, 0o755); err != nil {+ t.Fatalf("failed to write test binary: %v", err)+ }++ req := httptest.NewRequest(http.MethodGet, "/download/pulse-agent?arch=linux-amd64&serverVersion=v6.0.0-rc.6", nil)+ rr := httptest.NewRecorder()++ router := &Router{checksumCache: make(map[string]checksumCacheEntry)}+ router.handleDownloadUnifiedAgent(rr, req)++ if rr.Code != http.StatusOK {+ t.Fatalf("expected 200 OK, got %d", rr.Code)+ }++ expected := fmt.Sprintf("%x", sha256.Sum256(payload))+ if got := rr.Header().Get("X-Checksum-Sha256"); got != expected {+ t.Fatalf("unexpected checksum header: got %q want %q", got, expected)+ }++ if strings.TrimSpace(rr.Body.String()) != string(payload) {+ t.Fatalf("unexpected response body")+ }+}diff --git a/internal/cloudcp/config.go b/internal/cloudcp/config.goindex c4db9ae29f..98e4dda95a 100644--- a/internal/cloudcp/config.go+++ b/internal/cloudcp/config.go@@ -22,6 +22,7 @@ type ControlPlaneMode stringconst (ControlPlaneModePulseHosted ControlPlaneMode = "pulse_hosted"+ ControlPlaneModePulseHostedMSP ControlPlaneMode = "pulse_hosted_msp"ControlPlaneModeProviderHostedMSP ControlPlaneMode = "provider_hosted_msp"defaultProviderHostedMSPPlanVersion = "msp_starter"ProviderMSPPlanSourceLicenseFile = "license_file"@@ -106,8 +107,12 @@ func (c *CPConfig) IsProviderHostedMSP() bool {return c != nil && c.ControlPlaneMode == ControlPlaneModeProviderHostedMSP}+func (c *CPConfig) IsMSPControlPlane() bool {+ return c != nil && isMSPControlPlaneMode(c.ControlPlaneMode)+}+func (c *CPConfig) UsesStripeBilling() bool {- return c != nil && !c.IsProviderHostedMSP()+ return c != nil && !c.IsMSPControlPlane()}// LoadConfig loads control plane configuration from environment variables.@@ -184,7 +189,7 @@ func LoadConfig() (*CPConfig, error) {providerMSPPlanSource := ProviderMSPPlanSourceEnvFallbackproviderMSPLicenseID := ""providerMSPLicenseEmail := ""- if controlPlaneMode == ControlPlaneModeProviderHostedMSP && providerMSPLicenseFile != "" {+ if isMSPControlPlaneMode(controlPlaneMode) && providerMSPLicenseFile != "" {resolvedPlan, licenseID, licenseEmail, err := resolveProviderMSPPlanFromLicenseFile(providerMSPLicenseFile)if err != nil {return nil, fmt.Errorf("resolve provider MSP license: %w", err)@@ -344,30 +349,30 @@ func (c *CPConfig) validate() error {if c.Environment != "development" && c.Environment != "staging" && c.Environment != "production" {return fmt.Errorf("CP_ENV must be one of development, staging, production (got %q)", c.Environment)}- if c.ControlPlaneMode != ControlPlaneModePulseHosted && c.ControlPlaneMode != ControlPlaneModeProviderHostedMSP {- return fmt.Errorf("CP_CONTROL_PLANE_MODE must be one of %s, %s (got %q)", ControlPlaneModePulseHosted, ControlPlaneModeProviderHostedMSP, c.ControlPlaneMode)+ if !isKnownControlPlaneMode(c.ControlPlaneMode) {+ return fmt.Errorf("CP_CONTROL_PLANE_MODE must be one of %s, %s, %s (got %q)", ControlPlaneModePulseHosted, ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP, c.ControlPlaneMode)}if c.Environment == "production" && c.AllowDockerlessProvisioning {return fmt.Errorf("CP_ALLOW_DOCKERLESS_PROVISIONING must be false in production")}- if c.IsProviderHostedMSP() {+ if c.IsMSPControlPlane() {if strings.TrimSpace(c.StripeWebhookSecret) != "" {- return fmt.Errorf("STRIPE_WEBHOOK_SECRET must not be configured when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("STRIPE_WEBHOOK_SECRET must not be configured when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if strings.TrimSpace(c.StripeAPIKey) != "" {- return fmt.Errorf("STRIPE_API_KEY must not be configured when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("STRIPE_API_KEY must not be configured when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if c.PublicCloudSignupEnabled {- return fmt.Errorf("CP_PUBLIC_CLOUD_SIGNUP_ENABLED must be false when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("CP_PUBLIC_CLOUD_SIGNUP_ENABLED must be false when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if strings.TrimSpace(c.CloudMSPStarterPriceID) != "" || strings.TrimSpace(c.CloudMSPGrowthPriceID) != "" || strings.TrimSpace(c.CloudMSPScalePriceID) != "" {- return fmt.Errorf("CP_MSP_*_PRICE_ID must not be configured when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("CP_MSP_*_PRICE_ID must not be configured when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if strings.TrimSpace(c.TrialActivationPrivateKey) == "" {- return fmt.Errorf("CP_TRIAL_ACTIVATION_PRIVATE_KEY is required when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("CP_TRIAL_ACTIVATION_PRIVATE_KEY is required when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if c.Environment == "production" && strings.TrimSpace(c.ProviderMSPLicenseFile) == "" {- return fmt.Errorf("CP_PROVIDER_MSP_LICENSE_FILE is required in production when CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ return fmt.Errorf("CP_PROVIDER_MSP_LICENSE_FILE is required in production when CP_CONTROL_PLANE_MODE=%s", c.ControlPlaneMode)}if !strings.HasPrefix(strings.ToLower(c.ProviderMSPPlanVersion), "msp_") {return fmt.Errorf("CP_PROVIDER_MSP_PLAN_VERSION must be a canonical MSP plan version, got %q", c.ProviderMSPPlanVersion)@@ -505,6 +510,8 @@ func normalizeControlPlaneMode(raw string) ControlPlaneMode {switch strings.ToLower(strings.TrimSpace(raw)) {case "", "pulse_hosted", "pulse-hosted", "pulse_cloud", "pulse-cloud", "cloud":return ControlPlaneModePulseHosted+ case "pulse_hosted_msp", "pulse-hosted-msp", "pulse_msp", "pulse-msp", "hosted_msp", "hosted-msp":+ return ControlPlaneModePulseHostedMSPcase "provider_hosted_msp", "provider-hosted-msp", "provider_msp", "provider-msp", "msp_provider", "msp-provider":return ControlPlaneModeProviderHostedMSPdefault:@@ -512,6 +519,24 @@ func normalizeControlPlaneMode(raw string) ControlPlaneMode {}}+func isKnownControlPlaneMode(mode ControlPlaneMode) bool {+ switch mode {+ case ControlPlaneModePulseHosted, ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP:+ return true+ default:+ return false+ }+}++func isMSPControlPlaneMode(mode ControlPlaneMode) bool {+ switch mode {+ case ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP:+ return true+ default:+ return false+ }+}+func resolveProviderMSPPlanFromLicenseFile(path string) (planVersion, licenseID, licenseEmail string, err error) {path = strings.TrimSpace(path)if path == "" {diff --git a/internal/cloudcp/config_test.go b/internal/cloudcp/config_test.goindex 761a7c9f45..9bad359b0c 100644--- a/internal/cloudcp/config_test.go+++ b/internal/cloudcp/config_test.go@@ -467,6 +467,12 @@ func setProviderHostedMSPEnv(t *testing.T) {setTrialSigningEnv(t)}+func setPulseHostedMSPEnv(t *testing.T) {+ t.Helper()+ setProviderHostedMSPEnv(t)+ t.Setenv("CP_CONTROL_PLANE_MODE", "pulse_hosted_msp")+}+func writeProviderMSPLicenseForTest(t *testing.T, tier pkglicensing.Tier, planVersion string) string {t.Helper()publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)@@ -523,6 +529,58 @@ func TestLoadConfig_ProviderHostedMSPDoesNotRequireStripe(t *testing.T) {}}+func TestLoadConfig_PulseHostedMSPUsesStripeFreeMSPStack(t *testing.T) {+ setPulseHostedMSPEnv(t)++ cfg, err := LoadConfig()+ if err != nil {+ t.Fatalf("LoadConfig: %v", err)+ }+ if cfg.ControlPlaneMode != ControlPlaneModePulseHostedMSP {+ t.Fatalf("ControlPlaneMode = %q, want %q", cfg.ControlPlaneMode, ControlPlaneModePulseHostedMSP)+ }+ if !cfg.IsMSPControlPlane() {+ t.Fatal("IsMSPControlPlane = false, want true")+ }+ if cfg.IsProviderHostedMSP() {+ t.Fatal("IsProviderHostedMSP = true, want false for Pulse-hosted MSP")+ }+ if cfg.UsesStripeBilling() {+ t.Fatal("UsesStripeBilling = true, want false")+ }+ if cfg.ProviderMSPPlanVersion != "msp_starter" {+ t.Fatalf("ProviderMSPPlanVersion = %q, want msp_starter", cfg.ProviderMSPPlanVersion)+ }+}++func TestLoadConfig_PulseHostedMSPUsesSignedLicenseFilePlan(t *testing.T) {+ setPulseHostedMSPEnv(t)+ t.Setenv("CP_ENV", "production")+ t.Setenv("CP_PROVIDER_MSP_PLAN_VERSION", "msp_starter")+ t.Setenv("CP_PROVIDER_MSP_LICENSE_FILE", writeProviderMSPLicenseForTest(t, pkglicensing.TierMSP, "msp_scale"))++ cfg, err := LoadConfig()+ if err != nil {+ t.Fatalf("LoadConfig: %v", err)+ }+ if cfg.ProviderMSPPlanVersion != "msp_scale" {+ t.Fatalf("ProviderMSPPlanVersion = %q, want msp_scale", cfg.ProviderMSPPlanVersion)+ }+ if cfg.ProviderMSPPlanSource != ProviderMSPPlanSourceLicenseFile {+ t.Fatalf("ProviderMSPPlanSource = %q, want %q", cfg.ProviderMSPPlanSource, ProviderMSPPlanSourceLicenseFile)+ }+}++func TestNormalizeControlPlaneMode_PulseHostedMSPAliases(t *testing.T) {+ for _, raw := range []string{"pulse_hosted_msp", "pulse-hosted-msp", "pulse_msp", "pulse-msp", "hosted_msp", "hosted-msp"} {+ t.Run(raw, func(t *testing.T) {+ if got := normalizeControlPlaneMode(raw); got != ControlPlaneModePulseHostedMSP {+ t.Fatalf("normalizeControlPlaneMode(%q) = %q, want %q", raw, got, ControlPlaneModePulseHostedMSP)+ }+ })+ }+}+func TestLoadConfig_ProviderHostedMSPReportBrandDefaults(t *testing.T) {setProviderHostedMSPEnv(t)t.Setenv("CP_REPORT_BRAND_DISPLAY_NAME", "Provider Default")@@ -586,6 +644,19 @@ func TestLoadConfig_ProviderHostedMSPRejectsStripeConfig(t *testing.T) {}}+func TestLoadConfig_PulseHostedMSPRejectsStripeConfig(t *testing.T) {+ setPulseHostedMSPEnv(t)+ t.Setenv("STRIPE_API_KEY", "sk_test_123")++ _, err := LoadConfig()+ if err == nil {+ t.Fatal("expected error when STRIPE_API_KEY is configured")+ }+ if !strings.Contains(err.Error(), "must not be configured") {+ t.Fatalf("unexpected error: %v", err)+ }+}+func TestLoadConfig_ProviderHostedMSPRejectsPublicSignup(t *testing.T) {setProviderHostedMSPEnv(t)t.Setenv("CP_PUBLIC_CLOUD_SIGNUP_ENABLED", "true")diff --git a/internal/cloudcp/docker/labels.go b/internal/cloudcp/docker/labels.goindex c354a92881..384aafd055 100644--- a/internal/cloudcp/docker/labels.go+++ b/internal/cloudcp/docker/labels.go@@ -29,7 +29,7 @@ func CanonicalTenantRuntimeRouting(tenantID, baseDomain string) TenantRuntimeRou}// TraefikLabels generates Docker labels for Traefik reverse-proxy routing.-// Each tenant gets a subdomain: <tenantID>.cloud.pulserelay.pro+// Each tenant gets a subdomain under the configured control-plane base domain.func TraefikLabels(tenantID, baseDomain string, containerPort int, dockerNetwork ...string) map[string]string {svc := "pulse-" + tenantIDrouting := CanonicalTenantRuntimeRouting(tenantID, baseDomain)diff --git a/internal/cloudcp/provider_msp_backup.go b/internal/cloudcp/provider_msp_backup.goindex d749abb3a2..07c8dfd0f9 100644--- a/internal/cloudcp/provider_msp_backup.go+++ b/internal/cloudcp/provider_msp_backup.go@@ -132,8 +132,8 @@ func CreateProviderMSPBackup(ctx context.Context, cfg *CPConfig, outputPath striif cfg == nil {return nil, fmt.Errorf("control plane config is required")}- if !cfg.IsProviderHostedMSP() {- return nil, fmt.Errorf("provider MSP backup requires CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ if !cfg.IsMSPControlPlane() {+ return nil, fmt.Errorf("provider MSP backup requires CP_CONTROL_PLANE_MODE=%s or %s", ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP)}if cfg.UsesStripeBilling() {return nil, fmt.Errorf("provider MSP backup is unavailable for Stripe-backed control planes")@@ -967,8 +967,8 @@ func validateProviderMSPBackupManifest(manifest ProviderMSPBackupManifest) errorif manifest.Version != ProviderMSPBackupManifestVersion {return fmt.Errorf("unsupported provider MSP backup manifest version %q", manifest.Version)}- if manifest.ControlPlaneMode != string(ControlPlaneModeProviderHostedMSP) {- return fmt.Errorf("backup control_plane_mode = %q, want %q", manifest.ControlPlaneMode, ControlPlaneModeProviderHostedMSP)+ if !isMSPControlPlaneMode(ControlPlaneMode(manifest.ControlPlaneMode)) {+ return fmt.Errorf("backup control_plane_mode = %q, want %q or %q", manifest.ControlPlaneMode, ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP)}if strings.TrimSpace(manifest.PlanVersion) == "" {return fmt.Errorf("backup manifest is missing plan_version")diff --git a/internal/cloudcp/provider_msp_backup_test.go b/internal/cloudcp/provider_msp_backup_test.goindex 8e7ba1a747..30cb2a00c8 100644--- a/internal/cloudcp/provider_msp_backup_test.go+++ b/internal/cloudcp/provider_msp_backup_test.go@@ -225,6 +225,26 @@ func TestProviderMSPBackupRestoreRequiresReplaceForExistingState(t *testing.T) {assertProviderMSPBackupRestoredTenantCount(t, filepath.Join(targetDataDir, "control-plane", "tenants.db"), 2)}+func TestProviderMSPBackupManifestAcceptsMSPControlPlaneModes(t *testing.T) {+ base := ProviderMSPBackupManifest{+ Version: ProviderMSPBackupManifestVersion,+ PlanVersion: "msp_growth",+ PlanSource: ProviderMSPPlanSourceLicenseFile,+ ControlPlaneDir: providerMSPBackupControlPlaneDir,+ TenantsDir: providerMSPBackupTenantsDir,+ }++ for _, mode := range []ControlPlaneMode{ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP} {+ t.Run(string(mode), func(t *testing.T) {+ manifest := base+ manifest.ControlPlaneMode = string(mode)+ if err := validateProviderMSPBackupManifest(manifest); err != nil {+ t.Fatalf("validateProviderMSPBackupManifest: %v", err)+ }+ })+ }+}+func testProviderMSPBackupConfig(t *testing.T) *CPConfig {t.Helper()root := t.TempDir()diff --git a/internal/cloudcp/provider_msp_bootstrap.go b/internal/cloudcp/provider_msp_bootstrap.goindex 1941fc14ad..0c46204794 100644--- a/internal/cloudcp/provider_msp_bootstrap.go+++ b/internal/cloudcp/provider_msp_bootstrap.go@@ -37,8 +37,8 @@ type ProviderMSPBootstrapResult struct {}// BootstrapProviderMSP creates or reuses the MSP account and owner identity for-// a provider-hosted MSP control plane. It is deliberately unavailable in normal-// Pulse-hosted mode so the MSP bootstrap path cannot leak into ordinary hosting.+// an MSP control plane. It is deliberately unavailable in normal Pulse-hosted+// mode so the MSP bootstrap path cannot leak into ordinary hosting.func BootstrapProviderMSP(ctx context.Context, cfg *CPConfig, opts ProviderMSPBootstrapOptions) (*ProviderMSPBootstrapResult, error) {if err := ctx.Err(); err != nil {return nil, err@@ -46,8 +46,8 @@ func BootstrapProviderMSP(ctx context.Context, cfg *CPConfig, opts ProviderMSPBoif cfg == nil {return nil, fmt.Errorf("control plane config is required")}- if !cfg.IsProviderHostedMSP() {- return nil, fmt.Errorf("provider MSP bootstrap requires CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ if !cfg.IsMSPControlPlane() {+ return nil, fmt.Errorf("provider MSP bootstrap requires CP_CONTROL_PLANE_MODE=%s or %s", ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP)}accountName := strings.TrimSpace(opts.AccountName)diff --git a/internal/cloudcp/provider_msp_bootstrap_test.go b/internal/cloudcp/provider_msp_bootstrap_test.goindex 6d62b8cb23..e0f7d64f71 100644--- a/internal/cloudcp/provider_msp_bootstrap_test.go+++ b/internal/cloudcp/provider_msp_bootstrap_test.go@@ -101,6 +101,23 @@ func TestBootstrapProviderMSPIsIdempotentForExistingMSPAccount(t *testing.T) {}}+func TestBootstrapProviderMSPAcceptsPulseHostedMSPMode(t *testing.T) {+ cfg := testProviderMSPBootstrapConfig(t)+ cfg.ControlPlaneMode = ControlPlaneModePulseHostedMSP+ cfg.BaseURL = "https://acme.msp.pulserelay.pro"++ result, err := BootstrapProviderMSP(context.Background(), cfg, ProviderMSPBootstrapOptions{+ AccountName: "Acme MSP",+ OwnerEmail: "[email protected]",+ })+ if err != nil {+ t.Fatalf("BootstrapProviderMSP: %v", err)+ }+ if result.WorkspaceLimit != 15 {+ t.Fatalf("WorkspaceLimit = %d, want 15", result.WorkspaceLimit)+ }+}+func TestBootstrapProviderMSPRejectsPulseHostedMode(t *testing.T) {cfg := testProviderMSPBootstrapConfig(t)cfg.ControlPlaneMode = ControlPlaneModePulseHosteddiff --git a/internal/cloudcp/provider_msp_recovery.go b/internal/cloudcp/provider_msp_recovery.goindex 86c8dd2b1e..eeffd2e793 100644--- a/internal/cloudcp/provider_msp_recovery.go+++ b/internal/cloudcp/provider_msp_recovery.go@@ -204,8 +204,8 @@ func validateProviderMSPRecoveryOptions(opts ProviderMSPRecoveryOptions) error {}func validateProviderMSPRecoveryConfig(cfg *CPConfig, opts ProviderMSPRecoveryOptions) error {- if !cfg.IsProviderHostedMSP() {- return fmt.Errorf("provider MSP recovery requires CP_CONTROL_PLANE_MODE=%s", ControlPlaneModeProviderHostedMSP)+ if !cfg.IsMSPControlPlane() {+ return fmt.Errorf("provider MSP recovery requires CP_CONTROL_PLANE_MODE=%s or %s", ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP)}if cfg.UsesStripeBilling() {return fmt.Errorf("provider-hosted MSP recovery must be Stripe-free")diff --git a/internal/cloudcp/routes.go b/internal/cloudcp/routes.goindex e1090fc20a..a4d3db1519 100644--- a/internal/cloudcp/routes.go+++ b/internal/cloudcp/routes.go@@ -33,7 +33,7 @@ type Deps struct {}func publicCloudSignupPath(cfg *CPConfig) string {- if cfg != nil && cfg.IsProviderHostedMSP() {+ if cfg != nil && cfg.IsMSPControlPlane() {return ""}if cfg != nil && cfg.PublicCloudSignupEnabled {@@ -56,7 +56,7 @@ func runtimeStatus(cfg *CPConfig) admin.RuntimeStatus {status := admin.RuntimeStatus{ControlPlaneMode: string(cfg.ControlPlaneMode),}- if cfg.IsProviderHostedMSP() {+ if cfg.IsMSPControlPlane() {status.ProviderMSPPlanVersion = providerMSPPlanVersion(cfg)status.ProviderMSPPlanSource = cfg.ProviderMSPPlanSourceif limit, known := pkglicensing.WorkspaceLimitForPlan(status.ProviderMSPPlanVersion); known {@@ -246,7 +246,7 @@ func RegisterRoutes(mux *http.ServeMux, deps *Deps) {// Workspace management (session + account-membership authenticated)listTenants := account.HandleListTenants(deps.Registry)workspaceLimitPolicy := account.WorkspaceLimitPolicy{}- if deps.Config.IsProviderHostedMSP() {+ if deps.Config.IsMSPControlPlane() {workspaceLimitPolicy.ProviderHostedMSP = trueworkspaceLimitPolicy.ProviderMSPPlanVersion = providerMSPPlanVersion(deps.Config)}diff --git a/internal/cloudcp/routes_test.go b/internal/cloudcp/routes_test.goindex 8dea171df7..312a75c4bb 100644--- a/internal/cloudcp/routes_test.go+++ b/internal/cloudcp/routes_test.go@@ -58,6 +58,51 @@ func TestRegisterRoutes_StatusIncludesProviderMSPRuntime(t *testing.T) {}}+func TestRegisterRoutes_StatusIncludesPulseHostedMSPRuntime(t *testing.T) {+ dir := t.TempDir()+ reg, err := registry.NewTenantRegistry(dir)+ if err != nil {+ t.Fatalf("NewTenantRegistry: %v", err)+ }+ t.Cleanup(func() { _ = reg.Close() })++ mux := http.NewServeMux()+ RegisterRoutes(mux, &Deps{+ Config: &CPConfig{+ DataDir: dir,+ AdminKey: "test-admin-key",+ BaseURL: "https://example-msp.msp.pulserelay.pro",+ ControlPlaneMode: ControlPlaneModePulseHostedMSP,+ ProviderMSPPlanVersion: "msp_scale",+ ProviderMSPPlanSource: ProviderMSPPlanSourceLicenseFile,+ },+ Registry: reg,+ Version: "test",+ })++ req := httptest.NewRequest(http.MethodGet, "/status", nil)+ req.Header.Set("X-Admin-Key", "test-admin-key")+ rec := httptest.NewRecorder()+ mux.ServeHTTP(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("GET /status status=%d, want %d (body=%q)", rec.Code, http.StatusOK, rec.Body.String())+ }+ var payload map[string]any+ if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {+ t.Fatalf("decode /status payload: %v", err)+ }+ if payload["control_plane_mode"] != string(ControlPlaneModePulseHostedMSP) {+ t.Fatalf("control_plane_mode = %#v", payload["control_plane_mode"])+ }+ if payload["provider_msp_plan_version"] != "msp_scale" {+ t.Fatalf("provider_msp_plan_version = %#v", payload["provider_msp_plan_version"])+ }+ if payload["provider_msp_workspace_limit"] != float64(40) {+ t.Fatalf("provider_msp_workspace_limit = %#v", payload["provider_msp_workspace_limit"])+ }+}+func TestRegisterRoutes_AccountAndTenantMethodDispatch(t *testing.T) {dir := t.TempDir()reg, err := registry.NewTenantRegistry(dir)@@ -383,45 +428,49 @@ func TestRegisterRoutes_PublicCloudSignupRoutesDisabledByDefault(t *testing.T) {}}-func TestRegisterRoutes_ProviderHostedMSPDisablesPulseHostedBillingRoutes(t *testing.T) {- dir := t.TempDir()- reg, err := registry.NewTenantRegistry(dir)- if err != nil {- t.Fatalf("NewTenantRegistry: %v", err)- }- t.Cleanup(func() { _ = reg.Close() })-- mux := http.NewServeMux()- RegisterRoutes(mux, &Deps{- Config: &CPConfig{- DataDir: dir,- AdminKey: "test-admin-key",- BaseURL: "https://msp.example.com",- ControlPlaneMode: ControlPlaneModeProviderHostedMSP,- PublicCloudSignupEnabled: true,- ProviderMSPPlanVersion: "msp_growth",- },- Registry: reg,- Version: "test",- })-- for _, tc := range []struct {- method string- path string- }{- {method: http.MethodPost, path: "/api/stripe/webhook"},- {method: http.MethodGet, path: "/api/portal/billing"},- {method: http.MethodGet, path: "/signup"},- {method: http.MethodGet, path: "/cloud/signup"},- {method: http.MethodPost, path: "/api/public/signup"},- {method: http.MethodGet, path: "/cloud/msp/signup"},- {method: http.MethodPost, path: "/api/public/msp/signup"},- } {- req := httptest.NewRequest(tc.method, tc.path, nil)- rec := httptest.NewRecorder()- mux.ServeHTTP(rec, req)- if rec.Code != http.StatusNotFound {- t.Fatalf("%s %s status=%d, want %d", tc.method, tc.path, rec.Code, http.StatusNotFound)- }+func TestRegisterRoutes_MSPControlPlaneDisablesPulseHostedBillingRoutes(t *testing.T) {+ for _, mode := range []ControlPlaneMode{ControlPlaneModeProviderHostedMSP, ControlPlaneModePulseHostedMSP} {+ t.Run(string(mode), func(t *testing.T) {+ dir := t.TempDir()+ reg, err := registry.NewTenantRegistry(dir)+ if err != nil {+ t.Fatalf("NewTenantRegistry: %v", err)+ }+ t.Cleanup(func() { _ = reg.Close() })++ mux := http.NewServeMux()+ RegisterRoutes(mux, &Deps{+ Config: &CPConfig{+ DataDir: dir,+ AdminKey: "test-admin-key",+ BaseURL: "https://msp.example.com",+ ControlPlaneMode: mode,+ PublicCloudSignupEnabled: true,+ ProviderMSPPlanVersion: "msp_growth",+ },+ Registry: reg,+ Version: "test",+ })++ for _, tc := range []struct {+ method string+ path string+ }{+ {method: http.MethodPost, path: "/api/stripe/webhook"},+ {method: http.MethodGet, path: "/api/portal/billing"},+ {method: http.MethodGet, path: "/signup"},+ {method: http.MethodGet, path: "/cloud/signup"},+ {method: http.MethodPost, path: "/api/public/signup"},+ {method: http.MethodGet, path: "/cloud/msp/signup"},+ {method: http.MethodPost, path: "/api/public/msp/signup"},+ } {+ req := httptest.NewRequest(tc.method, tc.path, nil)+ rec := httptest.NewRecorder()+ mux.ServeHTTP(rec, req)+ if rec.Code != http.StatusNotFound {+ t.Fatalf("%s %s status=%d, want %d", tc.method, tc.path, rec.Code, http.StatusNotFound)+ }+ }+ })}}diff --git a/internal/cloudcp/server.go b/internal/cloudcp/server.goindex 05096c300f..c826ac5732 100644--- a/internal/cloudcp/server.go+++ b/internal/cloudcp/server.go@@ -55,7 +55,7 @@ func Run(ctx context.Context, version string) error {dockerMgr, err = cpDocker.NewManager(cpDocker.ManagerConfig{Image: cfg.PulseImage,Network: cfg.DockerNetwork,- IsolateTenantNetworks: cfg.IsProviderHostedMSP(),+ IsolateTenantNetworks: cfg.IsMSPControlPlane(),BaseDomain: baseDomainFromURL(cfg.BaseURL),TrialActivationPublicKey: cfg.TrialActivationPublicKey,TrustedProxyCIDRs: cfg.TrustedProxyCIDRs,diff --git a/internal/cloudcp/tenant_runtime_rollout.go b/internal/cloudcp/tenant_runtime_rollout.goindex dd402d3876..6bb3a051b9 100644--- a/internal/cloudcp/tenant_runtime_rollout.go+++ b/internal/cloudcp/tenant_runtime_rollout.go@@ -218,7 +218,7 @@ func newTenantRuntimeRolloutServiceFromConfig(dockerMgr, err := cpDocker.NewManager(cpDocker.ManagerConfig{Image: image,Network: cfg.DockerNetwork,- IsolateTenantNetworks: cfg.IsProviderHostedMSP(),+ IsolateTenantNetworks: cfg.IsMSPControlPlane(),BaseDomain: baseDomainFromURL(cfg.BaseURL),TrialActivationPublicKey: cfg.TrialActivationPublicKey,TrustedProxyCIDRs: cfg.TrustedProxyCIDRs,diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.goindex dd5dfc5a46..8a32347e1f 100644--- a/internal/hostagent/proxmox_setup.go+++ b/internal/hostagent/proxmox_setup.go@@ -244,7 +244,7 @@ func (p *ProxmoxSetup) configurePVEPermissions(ctx context.Context, tokenID stri// Extra privileges are optional, but enable additional features:// - Sys.Audit: required for pending apt updates + some cluster/ceph visibility- // - VM.Monitor (PVE 8) or VM.GuestAgent.Audit (PVE 9+): guest agent data+ // - VM.GuestAgent.Audit/FileRead (PVE 9+) or VM.Monitor (PVE 8): guest agent data// - Datastore.Audit: improved storage visibilityvar extraPrivs []string@@ -252,10 +252,13 @@ func (p *ProxmoxSetup) configurePVEPermissions(ctx context.Context, tokenID striextraPrivs = append(extraPrivs, "Sys.Audit")}- if p.probePVEPrivilege(ctx, "VM.Monitor") {- extraPrivs = append(extraPrivs, "VM.Monitor")- } else if p.probePVEPrivilege(ctx, "VM.GuestAgent.Audit") {+ if p.probePVEPrivilege(ctx, "VM.GuestAgent.Audit") {extraPrivs = append(extraPrivs, "VM.GuestAgent.Audit")+ if p.probePVEPrivilege(ctx, "VM.GuestAgent.FileRead") {+ extraPrivs = append(extraPrivs, "VM.GuestAgent.FileRead")+ }+ } else if p.probePVEPrivilege(ctx, "VM.Monitor") {+ extraPrivs = append(extraPrivs, "VM.Monitor")}if p.probePVEPrivilege(ctx, "Datastore.Audit") {diff --git a/internal/hostagent/proxmox_setup_test.go b/internal/hostagent/proxmox_setup_test.goindex 0f86f38119..f7df89b9b3 100644--- a/internal/hostagent/proxmox_setup_test.go+++ b/internal/hostagent/proxmox_setup_test.go@@ -745,6 +745,51 @@ func TestProxmoxSetup_ProbePVEPrivilege_ReturnsFalseOnAddError(t *testing.T) {}}+func TestProxmoxSetup_ConfigurePVEPermissions_PrefersGuestAgentPrivileges(t *testing.T) {+ mc := &mockCollector{}+ var pulseMonitorPrivs string+ var calls []commandCall+ tokenID := fmt.Sprintf("%s!%s", proxmoxUserPVE, "pulse-node-1")++ mc.commandCombinedOutputFn = func(ctx context.Context, name string, arg ...string) (string, error) {+ calls = append(calls, newCommandCall(name, arg...))+ if name != "pveum" {+ return "", nil+ }++ if len(arg) >= 5 && arg[0] == "role" && (arg[1] == "modify" || arg[1] == "add") && arg[2] == proxmoxMonitorRole {+ for i := 0; i < len(arg)-1; i++ {+ if arg[i] == "-privs" {+ pulseMonitorPrivs = arg[i+1]+ }+ }+ return "", nil+ }++ return "", nil+ }++ p := &ProxmoxSetup{+ logger: zerolog.Nop(),+ collector: mc,+ }++ p.configurePVEPermissions(context.Background(), tokenID)++ if !strings.Contains(pulseMonitorPrivs, "VM.GuestAgent.Audit") {+ t.Fatalf("expected PulseMonitor privileges to include VM.GuestAgent.Audit, got %q", pulseMonitorPrivs)+ }+ if !strings.Contains(pulseMonitorPrivs, "VM.GuestAgent.FileRead") {+ t.Fatalf("expected PulseMonitor privileges to include VM.GuestAgent.FileRead, got %q", pulseMonitorPrivs)+ }+ if strings.Contains(pulseMonitorPrivs, "VM.Monitor") {+ t.Fatalf("did not expect PulseMonitor privileges to include VM.Monitor when guest-agent privileges are available, got %q", pulseMonitorPrivs)+ }+ if hasCommandCall(calls, "pveum", "role", "add", privProbeRoleName("VM.Monitor"), "-privs", "VM.Monitor") {+ t.Fatalf("expected guest-agent privilege support to avoid probing legacy VM.Monitor; calls=%#v", calls)+ }+}+func TestProxmoxSetup_ConfigurePVEPermissions_FallsBackToGuestAgentAudit(t *testing.T) {mc := &mockCollector{}var pulseMonitorPrivs stringdiff --git a/internal/models/converters.go b/internal/models/converters.goindex 5ed492bd67..0611f78a45 100644--- a/internal/models/converters.go+++ b/internal/models/converters.go@@ -1037,6 +1037,7 @@ type ResourceConvertInput struct {Uptime *int64Tags []stringLabels map[string]string+ CustomURL stringLastSeenUnix int64Alerts []ResourceAlertInputIncidentCount int@@ -1118,6 +1119,7 @@ func ConvertResourceToFrontend(input ResourceConvertInput) ResourceFrontend {Uptime: input.Uptime,Tags: append([]string(nil), input.Tags...),Labels: nil,+ CustomURL: input.CustomURL,LastSeen: input.LastSeenUnix,IncidentCount: input.IncidentCount,IncidentCode: input.IncidentCode,diff --git a/internal/models/converters_additional_test.go b/internal/models/converters_additional_test.goindex 4627650bd1..afe8a2cdbe 100644--- a/internal/models/converters_additional_test.go+++ b/internal/models/converters_additional_test.go@@ -160,6 +160,7 @@ func TestConvertResourceToFrontend(t *testing.T) {HasNetwork: true,Tags: []string{"prod"},Labels: map[string]string{"env": "prod"},+ CustomURL: "https://resource.internal",LastSeenUnix: 12345,Alerts: []ResourceAlertInput{{ID: "a1", Type: "cpu", Level: "warn", Message: "high", Value: 90, Threshold: 80, StartTimeUnix: 111},@@ -181,6 +182,9 @@ func TestConvertResourceToFrontend(t *testing.T) {if len(frontend.Alerts) != 1 || frontend.Alerts[0].ID != "a1" {t.Fatalf("Alerts = %#v, want 1 alert", frontend.Alerts)}+ if frontend.CustomURL != input.CustomURL {+ t.Fatalf("CustomURL = %q, want %q", frontend.CustomURL, input.CustomURL)+ }if frontend.Identity == nil || frontend.Identity.Hostname != identity.Hostname {t.Fatalf("Identity = %#v, want hostname %q", frontend.Identity, identity.Hostname)}diff --git a/internal/models/models.go b/internal/models/models.goindex 245c558e57..723828d7e4 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -44,6 +44,7 @@ type State struct {RecentlyResolved []ResolvedAlert `json:"recentlyResolved"`LastUpdate time.Time `json:"lastUpdate"`TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"`+ PVETagColors map[string]string `json:"pveTagColors,omitempty"`}var (@@ -2939,6 +2940,7 @@ func NewState() *State {ConnectionHealth: make(map[string]bool),ActiveAlerts: make([]Alert, 0),RecentlyResolved: make([]ResolvedAlert, 0),+ PVETagColors: make(map[string]string),Performance: Performance{}.NormalizeCollections(),LastUpdate: time.Now(),}@@ -2947,6 +2949,22 @@ func NewState() *State {return state}+// MergeTagColors merges Proxmox tag color entries into the shared state.+func (s *State) MergeTagColors(colors map[string]string) {+ if len(colors) == 0 {+ return+ }+ s.mu.Lock()+ defer s.mu.Unlock()+ if s.PVETagColors == nil {+ s.PVETagColors = make(map[string]string, len(colors))+ }+ for tag, color := range colors {+ s.PVETagColors[strings.ToLower(strings.TrimSpace(tag))] = strings.TrimSpace(color)+ }+ s.LastUpdate = time.Now()+}+// syncBackupsLocked updates the aggregated backups structure.func (s *State) syncBackupsLocked() {s.Backups = Backups{diff --git a/internal/models/models_frontend.go b/internal/models/models_frontend.goindex f104915398..175127a246 100644--- a/internal/models/models_frontend.go+++ b/internal/models/models_frontend.go@@ -893,14 +893,15 @@ type ReplicationJobFrontend struct {// StateFrontend represents the state with frontend-friendly field namestype StateFrontend struct {- ActiveAlerts []Alert `json:"activeAlerts"` // Active alerts- RecentlyResolved []ResolvedAlert `json:"recentlyResolved"` // Recently resolved alerts- Metrics []Metric `json:"metrics"` // Time-series metrics- Performance Performance `json:"performance"` // Polling/runtime performance- ConnectionHealth map[string]bool `json:"connectionHealth"` // Keep as is- Stats Stats `json:"stats"` // Runtime statistics- LastUpdate int64 `json:"lastUpdate"` // Unix timestamp- TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"` // Global temperature monitoring setting+ ActiveAlerts []Alert `json:"activeAlerts"` // Active alerts+ RecentlyResolved []ResolvedAlert `json:"recentlyResolved"` // Recently resolved alerts+ Metrics []Metric `json:"metrics"` // Time-series metrics+ Performance Performance `json:"performance"` // Polling/runtime performance+ ConnectionHealth map[string]bool `json:"connectionHealth"` // Keep as is+ Stats Stats `json:"stats"` // Runtime statistics+ LastUpdate int64 `json:"lastUpdate"` // Unix timestamp+ TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"` // Global temperature monitoring setting+ PVETagColors map[string]string `json:"pveTagColors"` // Tag name -> "#rrggbb" from Proxmox datacenter config// Unified resources - the new way to access all monitored entitiesResources []ResourceFrontend `json:"resources"`ConnectedInfrastructure []ConnectedInfrastructureItemFrontend `json:"connectedInfrastructure"`@@ -927,6 +928,9 @@ func (s StateFrontend) NormalizeCollections() StateFrontend {if s.ConnectionHealth == nil {s.ConnectionHealth = map[string]bool{}}+ if s.PVETagColors == nil {+ s.PVETagColors = map[string]string{}+ }if s.Performance.APICallDuration == nil {s.Performance.APICallDuration = map[string]float64{}}@@ -976,10 +980,11 @@ type ResourceFrontend struct {Uptime *int64 `json:"uptime,omitempty"`// Metadata- Tags []string `json:"tags"`- Labels map[string]string `json:"labels"`- LastSeen int64 `json:"lastSeen"` // Unix milliseconds- Alerts []ResourceAlertFrontend `json:"alerts"`+ Tags []string `json:"tags"`+ Labels map[string]string `json:"labels"`+ CustomURL string `json:"customUrl,omitempty"`+ LastSeen int64 `json:"lastSeen"` // Unix milliseconds+ Alerts []ResourceAlertFrontend `json:"alerts"`IncidentCount int `json:"incidentCount,omitempty"`IncidentCode string `json:"incidentCode,omitempty"`diff --git a/internal/models/state_snapshot.go b/internal/models/state_snapshot.goindex 2f2e87e8ef..8b64666984 100644--- a/internal/models/state_snapshot.go+++ b/internal/models/state_snapshot.go@@ -34,6 +34,7 @@ type StateSnapshot struct {RecentlyResolved []ResolvedAlert `json:"recentlyResolved"`LastUpdate time.Time `json:"lastUpdate"`TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"`+ PVETagColors map[string]string `json:"pveTagColors,omitempty"`}// EmptyStateSnapshot returns a normalized zero-value snapshot for runtime@@ -149,6 +150,9 @@ func (s *StateSnapshot) NormalizeCollections() {if s.ConnectionHealth == nil {s.ConnectionHealth = map[string]bool{}}+ if s.PVETagColors == nil {+ s.PVETagColors = map[string]string{}+ }s.Performance = s.Performance.NormalizeCollections()}@@ -187,6 +191,7 @@ func (s StateSnapshot) Clone() StateSnapshot {RecentlyResolved: cloneResolvedAlerts(s.RecentlyResolved),LastUpdate: s.LastUpdate,TemperatureMonitoringEnabled: s.TemperatureMonitoringEnabled,+ PVETagColors: cloneStringMap(s.PVETagColors),}for key, healthy := range s.ConnectionHealth {snapshot.ConnectionHealth[key] = healthy@@ -237,6 +242,7 @@ func (s *State) GetSnapshot() StateSnapshot {RecentlyResolved: cloneResolvedAlerts(s.RecentlyResolved),LastUpdate: s.LastUpdate,TemperatureMonitoringEnabled: s.TemperatureMonitoringEnabled,+ PVETagColors: cloneStringMap(s.PVETagColors),}snapshot.NormalizeCollections()@@ -584,5 +590,6 @@ func (s StateSnapshot) ToFrontend() StateFrontend {frontend.Stats = s.Statsfrontend.LastUpdate = s.LastUpdate.Unix() * 1000 // JavaScript timestampfrontend.TemperatureMonitoringEnabled = s.TemperatureMonitoringEnabled+ frontend.PVETagColors = cloneStringMap(s.PVETagColors)return frontend.NormalizeCollections()}diff --git a/internal/models/state_snapshot_frontend_test.go b/internal/models/state_snapshot_frontend_test.goindex 8b060cfe36..bb9cd07abf 100644--- a/internal/models/state_snapshot_frontend_test.go+++ b/internal/models/state_snapshot_frontend_test.go@@ -32,6 +32,7 @@ func TestStateSnapshotToFrontend_UsesConcreteStateContract(t *testing.T) {RecentlyResolved: []ResolvedAlert{},LastUpdate: now,TemperatureMonitoringEnabled: true,+ PVETagColors: map[string]string{"production": "#ff0000"},}.ToFrontend()if len(frontend.Metrics) != 1 || frontend.Metrics[0].ID != "node-1" {@@ -43,6 +44,9 @@ func TestStateSnapshotToFrontend_UsesConcreteStateContract(t *testing.T) {if frontend.Stats.Version != "v6.0.0" {t.Fatalf("expected concrete stats payload, got %#v", frontend.Stats)}+ if frontend.PVETagColors["production"] != "#ff0000" {+ t.Fatalf("expected PVE tag colors to survive frontend conversion, got %#v", frontend.PVETagColors)+ }encoded, err := json.Marshal(frontend)if err != nil {@@ -69,6 +73,9 @@ func TestStateSnapshotToFrontend_UsesConcreteStateContract(t *testing.T) {if connectedInfrastructure, ok := payload["connectedInfrastructure"].([]any); !ok || len(connectedInfrastructure) != 0 {t.Fatalf("expected connectedInfrastructure to serialize as an empty array, got %T (%v)", payload["connectedInfrastructure"], payload["connectedInfrastructure"])}+ if tagColors, ok := payload["pveTagColors"].(map[string]any); !ok || tagColors["production"] != "#ff0000" {+ t.Fatalf("expected pveTagColors to serialize as an object, got %T (%v)", payload["pveTagColors"], payload["pveTagColors"])+ }}func TestEmptyStateFrontend_UsesCanonicalCollectionShapes(t *testing.T) {diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex dbeeb94795..b186e574c1 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -670,7 +670,8 @@ func TestProxmoxGuestMemoryFallbackUsesInstanceScopedCachesAndAgentMeminfo(t *te"func (m *Monitor) getVMAgentMemAvailable(ctx context.Context, client PVEClientInterface, instanceName, node string, vmid int) (uint64, error) {","requestCtx, cancel := context.WithTimeout(ctx, vmAgentMemRequestTTL)","ttl := vmAgentMemCacheTTL",- "ttl = vmAgentMemNegativeTTL",+ "ttl = m.vmAgentMemNegativeCacheTTL(instanceName, node, vmid)",+ "vmAgentMemNegativeKnownGuestTTL = 30 * time.Second",},"guest_memory_sources.go": {"func shouldPreferGuestAgentMemAvailable(status *proxmox.VMStatus, memTotal uint64) bool {",@@ -795,9 +796,11 @@ func TestProxmoxGuestMemoryCarryForwardUsesCanonicalSnapshotStability(t *testing"Notes: snapshotNotes,",},"monitor_polling_vm.go": {- `prevSnapshot := m.previousGuestSnapshot(instanceName, "qemu", n.Node, vm.VMID)`,- "memUsed, memorySource, snapshotNotes := stabilizeGuestLowTrustMemory(",- "Notes: snapshotNotes,",+ "prevVMByID := prevGuests.vmsByID",+ "m.pollNodeVMsWithClusterResourceBuilder(ctx, instanceName, n.Node, vms, client, prevVMByID, vmIDToHostAgent)",+ },+ "monitor_pve_node_vm_builder.go": {+ "return m.collectClusterVMResources(ctx, instanceName, resources, client, prevVMByID, vmIDToHostAgent), templateSubjects",},}@@ -828,8 +831,7 @@ func TestProxmoxGuestDiskCarryForwardUsesCanonicalStabilityHelper(t *testing.T)"return nil, classifyGuestAgentDiskStatusError(err), false",},"monitor_polling_vm.go": {- "diskStatusReason = classifyGuestAgentDiskStatusError(err)",- "diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason = stabilizeGuestLowTrustDisk(",+ "m.pollNodeVMsWithClusterResourceBuilder(ctx, instanceName, n.Node, vms, client, prevVMByID, vmIDToHostAgent)",},}@@ -859,8 +861,8 @@ func TestProxmoxGuestDiskInventoryPrefersCanonicalLinkedHostAgentSource(t *testi`Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,},"monitor_polling_vm.go": {- "preferLinkedHostAgentDiskInventory(",- `Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,+ "vmIDToHostAgent := prevGuests.hostAgentsByVMID",+ "m.pollNodeVMsWithClusterResourceBuilder(ctx, instanceName, n.Node, vms, client, prevVMByID, vmIDToHostAgent)",},}@@ -960,8 +962,10 @@ func TestBackupOrphanDetectionUsesCanonicalInventoryReadinessScope(t *testing.T)"monitor_pve_guest_poll.go": {"m.updatePVEBackupTemplateSubjectsFromClusterResources(instanceName, resources)",},+ "monitor_pve_node_vm_builder.go": {+ `pveBackupTemplateSubjectKey(instanceName, "qemu", node, vm.VMID)`,+ },"monitor_polling_vm.go": {- `pveBackupTemplateSubjectKey(instanceName, "qemu", n.Node, vm.VMID)`,`m.updatePVEBackupTemplateSubjectsForType(instanceName, "qemu", qemuTemplateSubjects)`,},"monitor_polling_containers.go": {@@ -1500,7 +1504,7 @@ func TestProxmoxNodeDiskFallbackPrefersCanonicalSystemStorage(t *testing.T) {},"monitor_pve_storage.go": {"rank, ok := preferredNodeDiskFallbackRank(storage)",- `(modelNodes[i].Disk.Total == 0 || currentDiskSource == "" || currentDiskSource == "nodes-endpoint")`,+ `(modelNodes[i].Disk.Total == 0 || currentDiskSource == "")`,},}@@ -1520,10 +1524,10 @@ func TestProxmoxNodeDiskFallbackPrefersCanonicalSystemStorage(t *testing.T) {func TestProxmoxGuestPollersCarryPoolIntoCanonicalModels(t *testing.T) {requiredSnippets := map[string][]string{- "monitor_pve_guest_builders.go": {"Pool: strings.TrimSpace(res.Pool)"},- "monitor_pve_guest_lxc.go": {"Pool: strings.TrimSpace(res.Pool)"},- "monitor_polling_vm.go": {"Pool: strings.TrimSpace(vm.Pool)"},- "monitor_polling_containers.go": {"Pool: strings.TrimSpace(container.Pool)"},+ "monitor_pve_guest_builders.go": {"Pool: strings.TrimSpace(res.Pool)"},+ "monitor_pve_guest_lxc.go": {"Pool: strings.TrimSpace(res.Pool)"},+ "monitor_pve_node_vm_builder.go": {"Pool: vm.Pool"},+ "monitor_polling_containers.go": {"Pool: strings.TrimSpace(container.Pool)"},}for file, snippets := range requiredSnippets {@@ -1569,9 +1573,8 @@ func TestProxmoxGuestAgentContinuityUsesCanonicalEvidenceAndRetryPaths(t *testin},"monitor_polling_vm.go": {"prevVMByID := prevGuests.vmsByID",- "guestAgentAvailable := vm.Status == \"running\" &&",- "m.hasRecentGuestMetadataEvidence(instanceName, n.Node, vm.VMID, now)",- "if guestAgentAvailable && diskTotal > 0 {",+ "vmIDToHostAgent := prevGuests.hostAgentsByVMID",+ "m.pollNodeVMsWithClusterResourceBuilder(ctx, instanceName, n.Node, vms, client, prevVMByID, vmIDToHostAgent)",},}diff --git a/internal/monitoring/ceph.go b/internal/monitoring/ceph.goindex 068fc9f66b..2ece92bbb2 100644--- a/internal/monitoring/ceph.go+++ b/internal/monitoring/ceph.go@@ -193,6 +193,18 @@ func countCephMonitorDaemons(status *proxmox.CephStatus) int {if status.MonMap.NumMons > 0 {return status.MonMap.NumMons}+ if len(status.MonMap.Mons) > 0 {+ return len(status.MonMap.Mons)+ }+ if len(status.MonMap.Monitors) > 0 {+ return len(status.MonMap.Monitors)+ }+ if len(status.MonMap.QuorumNames) > 0 {+ return len(status.MonMap.QuorumNames)+ }+ if len(status.MonMap.Quorum) > 0 {+ return len(status.MonMap.Quorum)+ }return countServiceDaemons(status.ServiceMap.Services, "mon")}diff --git a/internal/monitoring/ceph_test.go b/internal/monitoring/ceph_test.goindex 42b9889205..13e89d83ad 100644--- a/internal/monitoring/ceph_test.go+++ b/internal/monitoring/ceph_test.go@@ -323,20 +323,80 @@ func TestCountServiceDaemons(t *testing.T) {func TestCountCephMonitorDaemons(t *testing.T) {t.Parallel()- status := &proxmox.CephStatus{- MonMap: proxmox.CephMonMap{NumMons: 3},- ServiceMap: proxmox.CephServiceMap{- Services: map[string]proxmox.CephServiceDefinition{- "mon": {- Daemons: map[string]proxmox.CephServiceDaemon{- "a": {Host: "node1", Status: "running"},+ tests := []struct {+ name string+ status *proxmox.CephStatus+ want int+ }{+ {+ name: "uses explicit mon count",+ status: &proxmox.CephStatus{+ MonMap: proxmox.CephMonMap{NumMons: 3},+ ServiceMap: proxmox.CephServiceMap{+ Services: map[string]proxmox.CephServiceDefinition{+ "mon": {+ Daemons: map[string]proxmox.CephServiceDaemon{+ "a": {Host: "node1", Status: "running"},+ },+ },},},},+ want: 3,+ },+ {+ name: "uses mons fallback",+ status: &proxmox.CephStatus{+ MonMap: proxmox.CephMonMap{+ Mons: []proxmox.CephMonitor{{Name: "a"}, {Name: "b"}},+ },+ },+ want: 2,+ },+ {+ name: "uses quorum names fallback",+ status: &proxmox.CephStatus{+ MonMap: proxmox.CephMonMap{+ QuorumNames: []string{"a", "b", "c"},+ },+ ServiceMap: proxmox.CephServiceMap{+ Services: map[string]proxmox.CephServiceDefinition{+ "mon": {+ Daemons: map[string]proxmox.CephServiceDaemon{+ "a": {Host: "node1", Status: "running"},+ },+ },+ },+ },+ },+ want: 3,+ },+ {+ name: "falls back to service map",+ status: &proxmox.CephStatus{+ ServiceMap: proxmox.CephServiceMap{+ Services: map[string]proxmox.CephServiceDefinition{+ "mon": {+ Daemons: map[string]proxmox.CephServiceDaemon{+ "a": {Host: "node1", Status: "running"},+ "b": {Host: "node2", Status: "running"},+ },+ },+ },+ },+ },+ want: 2,},}- if got := countCephMonitorDaemons(status); got != 3 {- t.Fatalf("countCephMonitorDaemons() = %d, want 3", got)++ for _, tc := range tests {+ tc := tc+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ if got := countCephMonitorDaemons(tc.status); got != tc.want {+ t.Fatalf("countCephMonitorDaemons() = %d, want %d", got, tc.want)+ }+ })}}diff --git a/internal/monitoring/guest_agent_work.go b/internal/monitoring/guest_agent_work.gonew file mode 100644index 0000000000..a7c593aeda--- /dev/null+++ b/internal/monitoring/guest_agent_work.go@@ -0,0 +1,69 @@+package monitoring++import (+ "context"+ "time"+)++func (m *Monitor) efficientQEMUWorkerCount(total int) int {+ if total <= 0 {+ return 0+ }++ limit := defaultGuestAgentVMMaxConcurrent+ if m != nil && m.guestAgentWorkSlots != nil && cap(m.guestAgentWorkSlots) > 0 {+ limit = cap(m.guestAgentWorkSlots)+ }+ if limit <= 0 || limit > total {+ return total+ }+ return limit+}++func (m *Monitor) acquireGuestAgentWorkSlot(ctx context.Context) bool {+ if m == nil || m.guestAgentWorkSlots == nil {+ return true+ }+ select {+ case m.guestAgentWorkSlots <- struct{}{}:+ return true+ case <-ctx.Done():+ return false+ }+}++func (m *Monitor) releaseGuestAgentWorkSlot() {+ if m == nil || m.guestAgentWorkSlots == nil {+ return+ }+ select {+ case <-m.guestAgentWorkSlots:+ default:+ }+}++func (m *Monitor) guestAgentVMWorkContext(ctx context.Context) (context.Context, context.CancelFunc) {+ if m == nil || m.guestAgentVMBudget <= 0 {+ return ctx, func() {}+ }+ return context.WithTimeout(ctx, m.guestAgentVMBudget)+}++func (m *Monitor) runGuestAgentVMWork(ctx context.Context, work func(context.Context)) bool {+ if !m.acquireGuestAgentWorkSlot(ctx) {+ return false+ }+ defer m.releaseGuestAgentWorkSlot()++ workCtx, cancel := m.guestAgentVMWorkContext(ctx)+ defer cancel()+ work(workCtx)+ return true+}++func guestAgentVMBudgetOrZero(m *Monitor) time.Duration {+ if m == nil {+ return 0+ }+ return m.guestAgentVMBudget+}diff --git a/internal/monitoring/guest_memory_agent.go b/internal/monitoring/guest_memory_agent.goindex a754b425ee..c09217f398 100644--- a/internal/monitoring/guest_memory_agent.go+++ b/internal/monitoring/guest_memory_agent.go@@ -3,14 +3,16 @@ package monitoringimport ("context""fmt"+ "strings""time")const (- vmAgentMemCacheTTL = 60 * time.Second // Cache guest-agent /proc/meminfo reads.- vmAgentMemRequestTTL = 3 * time.Second // Bound guest-agent file-read latency.- vmAgentMemNegativeTTL = 5 * time.Minute // Back off on unsupported or failing guests.- vmAgentMemCleanupMaxAge = 2 * vmAgentMemNegativeTTL+ vmAgentMemCacheTTL = 60 * time.Second // Cache guest-agent /proc/meminfo reads.+ vmAgentMemRequestTTL = 3 * time.Second // Bound guest-agent file-read latency.+ vmAgentMemNegativeTTL = 5 * time.Minute // Back off on unsupported or failing guests.+ vmAgentMemNegativeKnownGuestTTL = 30 * time.Second // Retry sooner for guests we know are non-Windows.+ vmAgentMemCleanupMaxAge = 2 * vmAgentMemNegativeTTL)type agentMemCacheEntry struct {@@ -43,7 +45,7 @@ func (m *Monitor) getVMAgentMemAvailable(ctx context.Context, client PVEClientInif entry, ok := m.vmAgentMemCache[cacheKey]; ok {ttl := vmAgentMemCacheTTLif entry.negative {- ttl = vmAgentMemNegativeTTL+ ttl = m.vmAgentMemNegativeCacheTTL(instanceName, node, vmid)}if now.Sub(entry.fetchedAt) < ttl {m.rrdCacheMu.RUnlock()@@ -75,3 +77,27 @@ func (m *Monitor) getVMAgentMemAvailable(ctx context.Context, client PVEClientInm.vmAgentMemCache[cacheKey] = agentMemCacheEntry{available: available, fetchedAt: now}return available, nil}++func (m *Monitor) vmAgentMemNegativeCacheTTL(instanceName, node string, vmid int) time.Duration {+ if m == nil {+ return vmAgentMemNegativeTTL+ }++ key := guestMetadataCacheKey(instanceName, node, vmid)+ m.guestMetadataMu.RLock()+ entry, ok := m.guestMetadataCache[key]+ m.guestMetadataMu.RUnlock()+ if !ok {+ return vmAgentMemNegativeTTL+ }++ osName := strings.ToLower(strings.TrimSpace(entry.osName))+ osVersion := strings.ToLower(strings.TrimSpace(entry.osVersion))+ if osName == "" && osVersion == "" {+ return vmAgentMemNegativeTTL+ }+ if strings.Contains(osName, "windows") || strings.Contains(osVersion, "windows") {+ return vmAgentMemNegativeTTL+ }+ return vmAgentMemNegativeKnownGuestTTL+}diff --git a/internal/monitoring/guest_memory_agent_test.go b/internal/monitoring/guest_memory_agent_test.goindex 78155d0dd9..dda34de9f3 100644--- a/internal/monitoring/guest_memory_agent_test.go+++ b/internal/monitoring/guest_memory_agent_test.go@@ -4,6 +4,7 @@ import ("context""errors""testing"+ "time""github.com/rcourtman/pulse-go-rewrite/pkg/proxmox")@@ -110,6 +111,74 @@ func TestGetVMAgentMemAvailableCachesResults(t *testing.T) {})}+func TestGetVMAgentMemAvailableRetriesKnownNonWindowsGuestSoonerAfterNegativeCache(t *testing.T) {+ t.Parallel()++ client := &guestMemoryAgentTestClient{+ stubPVEClient: &stubPVEClient{},+ memAvailable: 2 * 1024 * 1024 * 1024,+ }+ mon := &Monitor{+ guestMetadataCache: map[string]guestMetadataCacheEntry{+ guestMetadataCacheKey("pve1", "node1", 100): {+ osName: "Ubuntu",+ fetchedAt: time.Now(),+ },+ },+ vmAgentMemCache: map[string]agentMemCacheEntry{+ guestMemoryCacheKey("pve1", "node1", 100): {+ negative: true,+ fetchedAt: time.Now().Add(-vmAgentMemNegativeKnownGuestTTL - time.Second),+ },+ },+ }++ available, err := mon.getVMAgentMemAvailable(context.Background(), client, "pve1", "node1", 100)+ if err != nil {+ t.Fatalf("getVMAgentMemAvailable() error = %v", err)+ }+ if available != 2*1024*1024*1024 {+ t.Fatalf("getVMAgentMemAvailable() available = %d", available)+ }+ if client.memCalls != 1 {+ t.Fatalf("expected guest-agent meminfo retry, got %d calls", client.memCalls)+ }+}++func TestGetVMAgentMemAvailableKeepsLongNegativeCacheForWindowsGuest(t *testing.T) {+ t.Parallel()++ client := &guestMemoryAgentTestClient{+ stubPVEClient: &stubPVEClient{},+ memAvailable: 2 * 1024 * 1024 * 1024,+ }+ mon := &Monitor{+ guestMetadataCache: map[string]guestMetadataCacheEntry{+ guestMetadataCacheKey("pve1", "node1", 100): {+ osName: "Microsoft Windows",+ fetchedAt: time.Now(),+ },+ },+ vmAgentMemCache: map[string]agentMemCacheEntry{+ guestMemoryCacheKey("pve1", "node1", 100): {+ negative: true,+ fetchedAt: time.Now().Add(-vmAgentMemNegativeKnownGuestTTL - time.Second),+ },+ },+ }++ available, err := mon.getVMAgentMemAvailable(context.Background(), client, "pve1", "node1", 100)+ if err == nil {+ t.Fatal("expected cached negative result for Windows guest")+ }+ if available != 0 {+ t.Fatalf("expected no memavailable result, got %d", available)+ }+ if client.memCalls != 0 {+ t.Fatalf("expected Windows guest negative cache to suppress retry, got %d calls", client.memCalls)+ }+}+func TestResolveGuestStatusMemoryUsesGuestAgentMeminfoFallback(t *testing.T) {t.Parallel()diff --git a/internal/monitoring/guest_metadata.go b/internal/monitoring/guest_metadata.goindex 08cfd57e5b..ec955ed3cc 100644--- a/internal/monitoring/guest_metadata.go+++ b/internal/monitoring/guest_metadata.go@@ -23,12 +23,13 @@ const (// Guest agent timeout defaults (configurable via environment variables)// Increased from 3-5s to 10-15s to handle high-load environments better (refs #592)- defaultGuestAgentFSInfoTimeout = 15 * time.Second // GUEST_AGENT_FSINFO_TIMEOUT- defaultGuestAgentNetworkTimeout = 10 * time.Second // GUEST_AGENT_NETWORK_TIMEOUT- defaultGuestAgentOSInfoTimeout = 10 * time.Second // GUEST_AGENT_OSINFO_TIMEOUT- defaultGuestAgentVersionTimeout = 10 * time.Second // GUEST_AGENT_VERSION_TIMEOUT- defaultGuestAgentRetries = 1 // GUEST_AGENT_RETRIES (0 = no retry, 1 = one retry)- defaultGuestAgentRetryDelay = 500 * time.Millisecond+ defaultGuestAgentFSInfoTimeout = 15 * time.Second // GUEST_AGENT_FSINFO_TIMEOUT+ defaultGuestAgentNetworkTimeout = 10 * time.Second // GUEST_AGENT_NETWORK_TIMEOUT+ defaultGuestAgentOSInfoTimeout = 10 * time.Second // GUEST_AGENT_OSINFO_TIMEOUT+ defaultGuestAgentVersionTimeout = 10 * time.Second // GUEST_AGENT_VERSION_TIMEOUT+ defaultGuestAgentRetries = 1 // GUEST_AGENT_RETRIES (0 = no retry, 1 = one retry)+ defaultGuestAgentRetryDelay = 500 * time.Millisecond+ defaultGuestAgentVMMaxConcurrent = 8 // GUEST_AGENT_VM_MAX_CONCURRENT// Skip OS info calls after this many consecutive failures to avoid triggering buggy guest agents (refs #692)guestAgentOSInfoFailureThreshold = 3diff --git a/internal/monitoring/host_agent_temps.go b/internal/monitoring/host_agent_temps.goindex c31f538955..241d08f80a 100644--- a/internal/monitoring/host_agent_temps.go+++ b/internal/monitoring/host_agent_temps.go@@ -27,9 +27,15 @@ func shouldSkipTemperatureSSHCollection(hostAgentTemp *models.Temperature) boolreturn false}- // Host-agent CPU or NVMe readings are preferred, but SSH should still augment- // the node with SMART disk temperatures until the agent has reported SMART.- return hostAgentTemp.HasSMART+ if !hostAgentTemp.Available || !isHostAgentTemperatureRecent(hostAgentTemp.LastUpdate) {+ return false+ }++ if hostAgentTemp.HasSMART {+ return hostAgentTemp.HasSMART+ }++ return hostAgentTemp.HasCPU || hostAgentTemp.HasGPU || hostAgentTemp.HasNVMe}// getHostAgentTemperatureByID looks for a matching host agent by node ID first,diff --git a/internal/monitoring/host_agent_temps_test.go b/internal/monitoring/host_agent_temps_test.goindex 6b22813bbe..2bcfcb1c40 100644--- a/internal/monitoring/host_agent_temps_test.go+++ b/internal/monitoring/host_agent_temps_test.go@@ -166,16 +166,53 @@ func TestShouldSkipTemperatureSSHCollection(t *testing.T) {CPUPackage: 55,}if shouldSkipTemperatureSSHCollection(host) {- t.Fatal("expected CPU-only host agent temp not to skip SSH collection")+ t.Fatal("expected CPU-only host agent temp without a recent timestamp not to skip SSH collection")+ }+ })++ t.Run("recent cpu only host agent temp skips", func(t *testing.T) {+ host := &models.Temperature{+ Available: true,+ HasCPU: true,+ CPUPackage: 55,+ LastUpdate: time.Now(),+ }+ if !shouldSkipTemperatureSSHCollection(host) {+ t.Fatal("expected recent CPU-only host agent temp to skip SSH collection")+ }+ })++ t.Run("stale cpu only host agent temp does not skip", func(t *testing.T) {+ host := &models.Temperature{+ Available: true,+ HasCPU: true,+ CPUPackage: 55,+ LastUpdate: time.Now().Add(-3 * time.Minute),+ }+ if shouldSkipTemperatureSSHCollection(host) {+ t.Fatal("expected stale CPU-only host agent temp not to skip SSH collection")+ }+ })++ t.Run("unavailable host agent temp does not skip", func(t *testing.T) {+ host := &models.Temperature{+ Available: false,+ HasCPU: true,+ CPUPackage: 55,+ LastUpdate: time.Now(),+ }+ if shouldSkipTemperatureSSHCollection(host) {+ t.Fatal("expected unavailable host agent temp not to skip SSH collection")}})t.Run("host agent smart data skips", func(t *testing.T) {host := &models.Temperature{- Available: true,- HasCPU: true,- HasSMART: true,- SMART: []models.DiskTemp{{Device: "/dev/sda", Temperature: 35}},+ Available: true,+ HasCPU: true,+ HasSMART: true,+ SMART: []models.DiskTemp{{Device: "/dev/sda", Temperature: 35}},+ LastUpdate: time.Now(),}if !shouldSkipTemperatureSSHCollection(host) {t.Fatal("expected SMART-capable host agent temp to skip SSH collection")diff --git a/internal/monitoring/memory_source_catalog_test.go b/internal/monitoring/memory_source_catalog_test.goindex 7ae11d9a50..c41df929d0 100644--- a/internal/monitoring/memory_source_catalog_test.go+++ b/internal/monitoring/memory_source_catalog_test.go@@ -151,19 +151,19 @@ func TestMockVMPollingDefersMemoryHistoryToCanonicalSampler(t *testing.T) {func TestPollVMPrefersCanonicalLinkedHostAgentDiskInventory(t *testing.T) {t.Parallel()- data, err := os.ReadFile("monitor_polling_vm.go")+ data, err := os.ReadFile("monitor_pve_guest_builders.go")if err != nil {- t.Fatalf("failed to read monitor_polling_vm.go: %v", err)+ t.Fatalf("failed to read monitor_pve_guest_builders.go: %v", err)}source := string(data)for _, snippet := range []string{"preferLinkedHostAgentDiskInventory(",- `Bool("guestAgentDiskAvailable", diskFromAgent)`,+ `Bool("guestAgentDiskAvailable", state.diskFromAgent)`,`Msg("QEMU disk: preferring linked Pulse host agent disk inventory")`,} {if !strings.Contains(source, snippet) {- t.Fatalf("monitor_polling_vm.go must contain %q", snippet)+ t.Fatalf("monitor_pve_guest_builders.go must contain %q", snippet)}}}diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 2cf6c0f105..d7d81b82ea 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -993,12 +993,14 @@ type Monitor struct {guestMetadataRefreshJitter time.DurationguestMetadataRetryBackoff time.DurationguestMetadataHoldDuration time.Duration+ guestAgentWorkSlots chan struct{}// Configurable guest agent timeouts (refs #592)guestAgentFSInfoTimeout time.DurationguestAgentNetworkTimeout time.DurationguestAgentOSInfoTimeout time.DurationguestAgentVersionTimeout time.DurationguestAgentRetries int+ guestAgentVMBudget time.Durationexecutor PollExecutorbreakerBaseRetry time.DurationbreakerMaxDelay time.Duration@@ -1419,6 +1421,8 @@ func New(cfg *config.Config) (*Monitor, error) {guestAgentOSInfoTimeout := parsePositiveDurationEnv("GUEST_AGENT_OSINFO_TIMEOUT", defaultGuestAgentOSInfoTimeout)guestAgentVersionTimeout := parsePositiveDurationEnv("GUEST_AGENT_VERSION_TIMEOUT", defaultGuestAgentVersionTimeout)guestAgentRetries := parseNonNegativeIntEnv("GUEST_AGENT_RETRIES", defaultGuestAgentRetries)+ guestAgentVMBudget := parseDurationEnv("GUEST_AGENT_VM_BUDGET", 0)+ guestAgentVMMaxConcurrent := parseNonNegativeIntEnv("GUEST_AGENT_VM_MAX_CONCURRENT", defaultGuestAgentVMMaxConcurrent)// Initialize persistent metrics store (SQLite) with configurable retentionvar metricsStore *metrics.Store@@ -1547,6 +1551,7 @@ func New(cfg *config.Config) (*Monitor, error) {guestAgentOSInfoTimeout: guestAgentOSInfoTimeout,guestAgentVersionTimeout: guestAgentVersionTimeout,guestAgentRetries: guestAgentRetries,+ guestAgentVMBudget: guestAgentVMBudget,instanceInfoCache: make(map[string]*instanceInfo),pollStatusMap: make(map[string]*pollStatus),dlqInsightMap: make(map[string]*dlqInsight),@@ -1601,6 +1606,9 @@ func New(cfg *config.Config) (*Monitor, error) {if concurrency > 0 {m.guestMetadataSlots = make(chan struct{}, concurrency)}+ if guestAgentVMMaxConcurrent > 0 {+ m.guestAgentWorkSlots = make(chan struct{}, guestAgentVMMaxConcurrent)+ }if appriseConfig, err := m.configPersist.LoadAppriseConfig(); err == nil {m.notificationMgr.SetAppriseConfig(*appriseConfig)@@ -3751,6 +3759,7 @@ func (m *Monitor) buildBroadcastFrontendStateFromSnapshot(snapshot models.StateSunifiedView := m.currentUnifiedStateView()metricsTargetResolver := broadcastMetricsTargetResolver(unifiedView.readState)broadcastResources := unifiedresources.CoalescePresentationHostResources(unifiedView.resources)+ broadcastResources = m.applyDockerMetadataToUnifiedResources(broadcastResources)frontendState.Resources = convertResourcesForBroadcast(broadcastResources, metricsTargetResolver)frontendState.ConnectedInfrastructure = buildConnectedInfrastructure(broadcastResources, snapshot)if !unifiedView.freshness.IsZero() {@@ -4926,11 +4935,35 @@ func (m *Monitor) getResourcesForBroadcast() []models.ResourceFrontend {store := m.resourceStorem.mu.RUnlock()return convertResourcesForBroadcast(- m.getUnifiedResourcesForBroadcast(),+ m.applyDockerMetadataToUnifiedResources(m.getUnifiedResourcesForBroadcast()),broadcastMetricsTargetResolver(store),)}+func (m *Monitor) applyDockerMetadataToUnifiedResources(resources []unifiedresources.Resource) []unifiedresources.Resource {+ if len(resources) == 0 || m == nil || m.dockerMetadataStore == nil {+ return resources+ }++ out := make([]unifiedresources.Resource, len(resources))+ copy(out, resources)+ for i := range out {+ resource := &out[i]+ if resource.Type != unifiedresources.ResourceTypeAppContainer || strings.TrimSpace(resource.CustomURL) != "" || resource.Docker == nil {+ continue+ }+ hostID := strings.TrimSpace(resource.Docker.HostSourceID)+ containerID := strings.TrimSpace(resource.Docker.ContainerID)+ if hostID == "" || containerID == "" {+ continue+ }+ if meta := m.dockerMetadataStore.Get(fmt.Sprintf("%s:container:%s", hostID, containerID)); meta != nil {+ resource.CustomURL = strings.TrimSpace(meta.CustomURL)+ }+ }+ return out+}+// convertResourcesForBroadcast converts unified resources into the frontend payload shape.func convertResourcesForBroadcast(allResources []unifiedresources.Resource,@@ -5066,6 +5099,7 @@ func monitorResourceToConvertInput(resource unifiedresources.Resource) models.ReUptime: monitorUptime(resource),Tags: append([]string(nil), resource.Tags...),Labels: monitorLabels(resource),+ CustomURL: strings.TrimSpace(resource.CustomURL),LastSeenUnix: monitorLastSeenUnix(resource.LastSeen),IncidentCount: resource.IncidentCount,IncidentCode: resource.IncidentCode,diff --git a/internal/monitoring/monitor_docker_test.go b/internal/monitoring/monitor_docker_test.goindex 7807efc1af..66748665d8 100644--- a/internal/monitoring/monitor_docker_test.go+++ b/internal/monitoring/monitor_docker_test.go@@ -9,6 +9,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/mock""github.com/rcourtman/pulse-go-rewrite/internal/models"+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker")@@ -436,6 +437,60 @@ func TestApplyDockerReportSkipsMetadataMigrationForAmbiguousContainerNames(t *te}}+func TestApplyDockerMetadataToUnifiedResourcesAddsContainerCustomURL(t *testing.T) {+ monitor := newTestMonitor(t)+ if err := monitor.dockerMetadataStore.Set("docker-host-1:container:container-new", &config.DockerMetadata{+ CustomURL: " https://app.internal ",+ }); err != nil {+ t.Fatalf("seed docker metadata: %v", err)+ }++ resources := []unifiedresources.Resource{+ {+ ID: "resource:app-container:app",+ Type: unifiedresources.ResourceTypeAppContainer,+ Docker: &unifiedresources.DockerData{+ HostSourceID: " docker-host-1 ",+ ContainerID: " container-new ",+ },+ },+ }++ got := monitor.applyDockerMetadataToUnifiedResources(resources)+ if got[0].CustomURL != "https://app.internal" {+ t.Fatalf("CustomURL = %q, want migrated Docker metadata URL", got[0].CustomURL)+ }+ if resources[0].CustomURL != "" {+ t.Fatalf("applyDockerMetadataToUnifiedResources mutated input CustomURL to %q", resources[0].CustomURL)+ }+}++func TestApplyDockerMetadataToUnifiedResourcesKeepsResourceCustomURL(t *testing.T) {+ monitor := newTestMonitor(t)+ if err := monitor.dockerMetadataStore.Set("docker-host-1:container:container-new", &config.DockerMetadata{+ CustomURL: "https://metadata.internal",+ }); err != nil {+ t.Fatalf("seed docker metadata: %v", err)+ }++ resources := []unifiedresources.Resource{+ {+ ID: "resource:app-container:app",+ Type: unifiedresources.ResourceTypeAppContainer,+ CustomURL: "https://resource.internal",+ Docker: &unifiedresources.DockerData{+ HostSourceID: "docker-host-1",+ ContainerID: "container-new",+ },+ },+ }++ got := monitor.applyDockerMetadataToUnifiedResources(resources)+ if got[0].CustomURL != "https://resource.internal" {+ t.Fatalf("CustomURL = %q, want existing resource URL to win", got[0].CustomURL)+ }+}+func TestApplyDockerReportComputesContainerNetworkAndDiskRates(t *testing.T) {monitor := newTestMonitor(t)baseTime := time.Now().UTC()diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.goindex c964ff970b..daf044314b 100644--- a/internal/monitoring/monitor_extra_coverage_test.go+++ b/internal/monitoring/monitor_extra_coverage_test.go@@ -497,6 +497,22 @@ type mockPVEClientExtra struct {agentVersion string}+type delayedGuestAgentClient struct {+ mockPVEClientExtra+ fsDelay time.Duration+}++func (m *delayedGuestAgentClient) GetVMFSInfo(ctx context.Context, node string, vmid int) ([]proxmox.VMFileSystem, error) {+ if m.fsDelay > 0 {+ select {+ case <-time.After(m.fsDelay):+ case <-ctx.Done():+ return nil, ctx.Err()+ }+ }+ return m.mockPVEClientExtra.GetVMFSInfo(ctx, node, vmid)+}+func (m *mockPVEClientExtra) GetClusterResources(ctx context.Context, resourceType string) ([]proxmox.ClusterResource, error) {return m.resources, nil}@@ -649,6 +665,65 @@ func TestMonitor_PollVMsAndContainersEfficient_Extra(t *testing.T) {}}+func TestPollVMsWithNodesCompletesDiskQueriesWithinPollBudget(t *testing.T) {+ t.Setenv("PULSE_DATA_DIR", t.TempDir())++ m := &Monitor{+ state: models.NewState(),+ guestAgentFSInfoTimeout: 250 * time.Millisecond,+ guestAgentRetries: 0,+ guestAgentNetworkTimeout: 250 * time.Millisecond,+ guestAgentOSInfoTimeout: 250 * time.Millisecond,+ guestAgentVersionTimeout: 250 * time.Millisecond,+ guestMetadataCache: make(map[string]guestMetadataCacheEntry),+ guestMetadataLimiter: make(map[string]time.Time),+ rateTracker: NewRateTracker(),+ metricsHistory: NewMetricsHistory(100, time.Hour),+ alertManager: alerts.NewManager(),+ stalenessTracker: NewStalenessTracker(nil),+ nodeRRDMemCache: make(map[string]rrdMemCacheEntry),+ vmRRDMemCache: make(map[string]rrdMemCacheEntry),+ vmAgentMemCache: make(map[string]agentMemCacheEntry),+ guestAgentWorkSlots: make(chan struct{}, 3),+ }+ defer m.alertManager.Stop()++ client := &delayedGuestAgentClient{+ mockPVEClientExtra: mockPVEClientExtra{+ vms: []proxmox.VM{+ {VMID: 100, Name: "vm100", Node: "node1", Status: "running", CPUs: 2, MaxMem: 8 * 1024, Mem: 4 * 1024, MaxDisk: 100 * 1024 * 1024 * 1024},+ {VMID: 101, Name: "vm101", Node: "node1", Status: "running", CPUs: 2, MaxMem: 8 * 1024, Mem: 4 * 1024, MaxDisk: 100 * 1024 * 1024 * 1024},+ {VMID: 102, Name: "vm102", Node: "node1", Status: "running", CPUs: 2, MaxMem: 8 * 1024, Mem: 4 * 1024, MaxDisk: 100 * 1024 * 1024 * 1024},+ },+ vmStatus: &proxmox.VMStatus{+ Status: "running",+ Agent: proxmox.VMAgentField{Value: 1},+ MaxMem: 8 * 1024,+ Mem: 4 * 1024,+ },+ fsInfo: []proxmox.VMFileSystem{+ {Mountpoint: "/", TotalBytes: 100 * 1024 * 1024 * 1024, UsedBytes: 40 * 1024 * 1024 * 1024, Type: "ext4", Disk: "/dev/vda"},+ },+ },+ fsDelay: 60 * time.Millisecond,+ }++ ctx, cancel := context.WithTimeout(context.Background(), 120*time.Millisecond)+ defer cancel()++ m.pollVMsWithNodes(ctx, "pve1", "", false, client, []proxmox.Node{{Node: "node1", Status: "online"}}, map[string]string{"node1": "online"})++ state := m.GetState()+ if len(state.VMs) != 3 {+ t.Fatalf("expected all VM disk queries to complete inside poll budget, got %d VMs", len(state.VMs))+ }+ for _, vm := range state.VMs {+ if vm.Disk.Usage <= 0 {+ t.Fatalf("expected VM %d to keep guest-agent disk usage, got %+v", vm.VMID, vm.Disk)+ }+ }+}+func TestMonitor_EnrichContainerMetadata_Extra(t *testing.T) {m := &Monitor{state: models.NewState(),diff --git a/internal/monitoring/monitor_polling_vm.go b/internal/monitoring/monitor_polling_vm.goindex 4672276e8d..a77d101199 100644--- a/internal/monitoring/monitor_polling_vm.go+++ b/internal/monitoring/monitor_polling_vm.go@@ -2,22 +2,18 @@ package monitoringimport ("context"- "strings""sync""time"- "github.com/rcourtman/pulse-go-rewrite/internal/logging""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/internal/monitoring/errors""github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"- "github.com/rs/zerolog""github.com/rs/zerolog/log")func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clusterName string, isCluster bool, client PVEClientInterface, nodes []proxmox.Node, nodeEffectiveStatus map[string]string) {startTime := time.Now()- // Channel to collect VM results from each nodetype nodeResult struct {node stringvms []models.VM@@ -28,7 +24,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluresultChan := make(chan nodeResult, len(nodes))var wg sync.WaitGroup- // Count online nodes for loggingonlineNodes := 0for _, node := range nodes {if nodeEffectiveStatus[node.Node] == "online" {@@ -36,8 +31,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu}}- // Capture the previous guest context once per poll cycle so fallback behavior- // is based on a consistent pre-poll snapshot.prevGuests := m.previousGuestContextForInstance(instanceName)prevVMByID := prevGuests.vmsByIDvmIDToHostAgent := prevGuests.hostAgentsByVMID@@ -48,9 +41,7 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluInt("onlineNodes", onlineNodes).Msg("Starting parallel VM polling")- // Launch a goroutine for each online nodefor _, node := range nodes {- // Skip offline nodesif nodeEffectiveStatus[node.Node] != "online" {log.Debug().Str("node", node.Node).@@ -64,8 +55,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cludefer wg.Done()nodeStart := time.Now()-- // Fetch VMs for this nodevms, err := client.GetVMs(ctx, n.Node)if err != nil {monErr := errors.NewMonitorError(errors.ErrorTypeAPI, "get_vms", instanceName, err).WithNode(n.Node)@@ -74,536 +63,7 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clureturn}- var nodeVMs []models.VM- nodeTemplateSubjects := make(map[string]struct{})-- // Process each VM- for _, vm := range vms {- // Skip templates- if vm.Template == 1 {- if key := pveBackupTemplateSubjectKey(instanceName, "qemu", n.Node, vm.VMID); key != "" {- nodeTemplateSubjects[key] = struct{}{}- }- continue- }-- // Parse tags- var tags []string- if vm.Tags != "" {- tags = strings.Split(vm.Tags, ";")- }-- // Generate canonical guest ID: instance:node:vmid- guestID := makeGuestID(instanceName, n.Node, vm.VMID)- var prevVM *models.VM- if prev, ok := prevVMByID[guestID]; ok {- prevVM = &prev- }-- guestRaw := VMMemoryRaw{- ListingMem: vm.Mem,- ListingMaxMem: vm.MaxMem,- Agent: vm.Agent,- }- memorySource := "cluster-resources"-- // Initialize metrics from VM listing (may be 0 for disk I/O)- diskReadBytes := int64(vm.DiskRead)- diskWriteBytes := int64(vm.DiskWrite)- networkInBytes := int64(vm.NetIn)- networkOutBytes := int64(vm.NetOut)-- // Get memory info for running VMs (and agent status for disk)- memUsed := uint64(0)- memTotal := vm.MaxMem- var vmStatus *proxmox.VMStatus- var ipAddresses []string- var networkInterfaces []models.GuestNetworkInterface- var osName, osVersion, guestAgentVersion string-- if vm.Status == "running" {- // Try to get detailed VM status (but don't wait too long)- statusCtx, cancel := context.WithTimeout(ctx, 2*time.Second)- if status, err := client.GetVMStatus(statusCtx, n.Node, vm.VMID); err == nil {- vmStatus = status- guestRaw.StatusMaxMem = status.MaxMem- guestRaw.StatusMem = status.Mem- guestRaw.StatusFreeMem = status.FreeMem- guestRaw.Balloon = status.Balloon- guestRaw.BalloonMin = status.BalloonMin- guestRaw.Agent = status.Agent.Value- memTotal, memUsed, memorySource = m.resolveGuestStatusMemory(- ctx,- client,- instanceName,- vm.Name,- n.Node,- vm.VMID,- guestID,- status,- vmIDToHostAgent,- memTotal,- memorySource,- &guestRaw,- )- // Use actual disk I/O values from detailed status- diskReadBytes = int64(vmStatus.DiskRead)- diskWriteBytes = int64(vmStatus.DiskWrite)- networkInBytes = int64(vmStatus.NetIn)- networkOutBytes = int64(vmStatus.NetOut)- }- cancel()- }-- if vm.Status != "running" {- memorySource = "powered-off"- } else if vmStatus == nil {- memorySource = "status-unavailable"- }-- now := time.Now()- guestAgentAvailable := vm.Status == "running" &&- (shouldQueryGuestAgent(vmStatus, prevVM, now) ||- m.hasRecentGuestMetadataEvidence(instanceName, n.Node, vm.VMID, now))- if guestAgentAvailable {- guestIPs, guestIfaces, guestOSName, guestOSVersion, agentVersion := m.fetchGuestAgentMetadata(ctx, client, instanceName, n.Node, vm.Name, vm.VMID, vmStatus, vmStatus == nil)- if len(guestIPs) > 0 {- ipAddresses = guestIPs- }- if len(guestIfaces) > 0 {- networkInterfaces = guestIfaces- }- if guestOSName != "" {- osName = guestOSName- }- if guestOSVersion != "" {- osVersion = guestOSVersion- }- if agentVersion != "" {- guestAgentVersion = agentVersion- }- }-- // Calculate I/O rates after we have the actual values- sampleTime := time.Now()- currentMetrics := IOMetrics{- DiskRead: diskReadBytes,- DiskWrite: diskWriteBytes,- NetworkIn: networkInBytes,- NetworkOut: networkOutBytes,- Timestamp: sampleTime,- }- diskReadRate, diskWriteRate, netInRate, netOutRate := m.rateTracker.CalculateRates(guestID, currentMetrics)-- // Debug log disk I/O rates- if diskReadRate > 0 || diskWriteRate > 0 {- log.Debug().- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Float64("diskReadRate", diskReadRate).- Float64("diskWriteRate", diskWriteRate).- Int64("diskReadBytes", diskReadBytes).- Int64("diskWriteBytes", diskWriteBytes).- Msg("VM disk I/O rates calculated")- }-- // Set CPU to 0 for non-running VMs- cpuUsage := safeFloat(vm.CPU)- if vm.Status != "running" {- cpuUsage = 0- }-- // Calculate disk usage - start with allocated disk size- // NOTE: The Proxmox cluster/resources API always returns 0 for VM disk usage- // We must query the guest agent to get actual disk usage- diskUsed := vm.Disk- diskTotal := vm.MaxDisk- diskFree := diskTotal - diskUsed- diskUsage := safePercentage(float64(diskUsed), float64(diskTotal))- diskFromAgent := false- diskStatusReason := ""- var individualDisks []models.Disk-- // For stopped VMs, we can't get guest agent data- if vm.Status != "running" {- // Show allocated disk size for stopped VMs- if diskTotal > 0 {- diskUsage = -1 // Indicates "allocated size only"- diskStatusReason = "vm-stopped"- }- }-- // For running VMs, ALWAYS try to get filesystem info from guest agent- // The cluster/resources endpoint always returns 0 for disk usage- if guestAgentAvailable && diskTotal > 0 {- agentValue := 0- if vmStatus != nil {- agentValue = vmStatus.Agent.Value- }-- // Log the initial state- if logging.IsLevelEnabled(zerolog.DebugLevel) {- log.Debug().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Int("agent", agentValue).- Uint64("diskUsed", diskUsed).- Uint64("diskTotal", diskTotal).- Msg("VM has 0 disk usage, checking guest agent")- }-- // Check if agent is enabled- if vmStatus != nil && !vmStatus.Agent.IsAvailable() {- if vmStatus.Agent.IsEnabled() {- diskStatusReason = "agent-not-running"- } else {- diskStatusReason = "agent-disabled"- }- if logging.IsLevelEnabled(zerolog.DebugLevel) {- log.Debug().- Str("instance", instanceName).- Str("vm", vm.Name).- Bool("agentEnabled", vmStatus.Agent.IsEnabled()).- Msg("Guest agent is not currently queryable")- }- } else {- if logging.IsLevelEnabled(zerolog.DebugLevel) {- log.Debug().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Guest agent enabled, fetching filesystem info")- }-- // Filesystem info with configurable timeout and retry (refs #592)- fsInfoRaw, err := m.retryGuestAgentCall(ctx, m.guestAgentFSInfoTimeout, m.guestAgentRetries, func(ctx context.Context) (interface{}, error) {- return client.GetVMFSInfo(ctx, n.Node, vm.VMID)- })- var fsInfo []proxmox.VMFileSystem- if err == nil {- if fs, ok := fsInfoRaw.([]proxmox.VMFileSystem); ok {- fsInfo = fs- }- }- if err != nil {- // Handle errors- errStr := err.Error()- log.Warn().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Str("error", errStr).- Msg("Failed to get VM filesystem info from guest agent")-- diskStatusReason = classifyGuestAgentDiskStatusError(err)-- switch diskStatusReason {- case "agent-not-running":- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Guest agent enabled in VM config but not running inside guest OS. Install and start qemu-guest-agent in the VM")- case "permission-denied":- log.Warn().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Permission denied accessing guest agent. Verify Pulse user has VM.Monitor (PVE 8) or VM.Audit+VM.GuestAgent.Audit (PVE 9) permissions")- }- } else if len(fsInfo) == 0 {- diskStatusReason = "no-filesystems"- log.Warn().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Msg("Guest agent returned empty filesystem list")- } else {- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Int("filesystems", len(fsInfo)).- Msg("Got filesystem info from guest agent")- // Aggregate disk usage from all filesystems- // Fix for #425: Track seen devices to avoid counting duplicates- var totalBytes, usedBytes uint64- seenDevices := make(map[string]bool)-- for _, fs := range fsInfo {- // Log each filesystem for debugging- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Str("type", fs.Type).- Str("disk", fs.Disk).- Uint64("total", fs.TotalBytes).- Uint64("used", fs.UsedBytes).- Msg("Processing filesystem from guest agent")-- // Skip special filesystems and Windows System Reserved- // For Windows, mountpoints are like "C:\\" or "D:\\" - don't skip those- isWindowsDrive := len(fs.Mountpoint) >= 2 && fs.Mountpoint[1] == ':' && strings.Contains(fs.Mountpoint, "\\")-- if !isWindowsDrive {- if reason, skip := readOnlyFilesystemReason(fs.Type, fs.TotalBytes, fs.UsedBytes); skip {- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Str("type", fs.Type).- Str("skipReason", reason).- Uint64("total", fs.TotalBytes).- Uint64("used", fs.UsedBytes).- Msg("Skipping read-only filesystem from guest agent")- continue- }-- if fs.Type == "tmpfs" || fs.Type == "devtmpfs" ||- strings.HasPrefix(fs.Mountpoint, "/dev") ||- strings.HasPrefix(fs.Mountpoint, "/proc") ||- strings.HasPrefix(fs.Mountpoint, "/sys") ||- strings.HasPrefix(fs.Mountpoint, "/run") ||- fs.Mountpoint == "/boot/efi" ||- fs.Mountpoint == "System Reserved" ||- strings.Contains(fs.Mountpoint, "System Reserved") ||- strings.HasPrefix(fs.Mountpoint, "/snap") { // Skip snap mounts- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Str("type", fs.Type).- Msg("Skipping special filesystem")- continue- }- }-- // Skip if we've already seen this device (duplicate mount point)- if fs.Disk != "" && seenDevices[fs.Disk] {- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Str("disk", fs.Disk).- Msg("Skipping duplicate mount of same device")- continue- }-- // Only count real filesystems with valid data- if fs.TotalBytes > 0 {- // Mark this device as seen- if fs.Disk != "" {- seenDevices[fs.Disk] = true- }-- totalBytes += fs.TotalBytes- usedBytes += fs.UsedBytes- individualDisks = append(individualDisks, models.Disk{- Total: int64(fs.TotalBytes),- Used: int64(fs.UsedBytes),- Free: int64(fs.TotalBytes - fs.UsedBytes),- Usage: safePercentage(float64(fs.UsedBytes), float64(fs.TotalBytes)),- Mountpoint: fs.Mountpoint,- Type: fs.Type,- Device: fs.Disk,- })- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Str("disk", fs.Disk).- Uint64("added_total", fs.TotalBytes).- Uint64("added_used", fs.UsedBytes).- Msg("Adding filesystem to total")- } else {- log.Debug().- Str("vm", vm.Name).- Str("mountpoint", fs.Mountpoint).- Msg("Skipping filesystem with 0 total bytes")- }- }-- // If we got valid data from guest agent, use it- if totalBytes > 0 {- diskTotal = totalBytes- diskUsed = usedBytes- diskFree = totalBytes - usedBytes- diskUsage = safePercentage(float64(usedBytes), float64(totalBytes))- diskFromAgent = true- diskStatusReason = "" // Clear reason on success-- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("vmid", vm.VMID).- Uint64("totalBytes", totalBytes).- Uint64("usedBytes", usedBytes).- Float64("usage", diskUsage).- Msg("✓ Successfully retrieved disk usage from guest agent")- } else {- // Only special filesystems found - show allocated disk size instead- diskStatusReason = "special-filesystems-only"- if diskTotal > 0 {- diskUsage = -1 // Show as allocated size- }- log.Info().- Str("instance", instanceName).- Str("vm", vm.Name).- Int("filesystems_found", len(fsInfo)).- Msg("Guest agent provided filesystem info but no usable filesystems found (all were special mounts)")- }- }- }- } else if vm.Status == "running" && diskTotal > 0 {- // Running VM but no guest-agent evidence - show allocated disk- diskUsage = -1- if vmStatus == nil {- diskStatusReason = "no-status"- } else {- diskStatusReason = "no-agent"- }- }-- if vm.Status == "running" {- var preferred bool- diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason, preferred = preferLinkedHostAgentDiskInventory(- guestID,- vmIDToHostAgent,- diskTotal,- diskUsed,- diskFree,- diskUsage,- individualDisks,- diskStatusReason,- )- if preferred {- log.Debug().- Str("instance", instanceName).- Str("vm", vm.Name).- Str("node", n.Node).- Int("vmid", vm.VMID).- Bool("guestAgentDiskAvailable", diskFromAgent).- Float64("usage", diskUsage).- Msg("QEMU disk: preferring linked Pulse host agent disk inventory")- }- }- diskTotal, diskUsed, diskFree, diskUsage, individualDisks, diskStatusReason = stabilizeGuestLowTrustDisk(- prevVM,- vm.Status,- diskTotal,- diskUsed,- diskFree,- diskUsage,- individualDisks,- diskStatusReason,- diskFromAgent,- sampleTime,- )-- prevSnapshot := m.previousGuestSnapshot(instanceName, "qemu", n.Node, vm.VMID)- memUsed, memorySource, snapshotNotes := stabilizeGuestLowTrustMemory(- prevSnapshot,- vm.Status,- memorySource,- memTotal,- memUsed,- sampleTime,- guestAgentSignalsHealthy(- vmStatus,- diskFromAgent,- ipAddresses,- networkInterfaces,- osName,- osVersion,- guestAgentVersion,- ),- )-- memTotalBytes := clampToInt64(memTotal)- memUsedBytes := clampToInt64(memUsed)- if memTotalBytes > 0 && memUsedBytes > memTotalBytes {- memUsedBytes = memTotalBytes- }- memFreeBytes := memTotalBytes - memUsedBytes- if memFreeBytes < 0 {- memFreeBytes = 0- }- memory := models.Memory{- Total: memTotalBytes,- Used: memUsedBytes,- Free: memFreeBytes,- Usage: safePercentage(float64(memUsed), float64(memTotal)),- }- if guestRaw.Balloon > 0 {- memory.Balloon = clampToInt64(guestRaw.Balloon)- }-- // Create VM model- modelVM := models.VM{- ID: guestID,- VMID: vm.VMID,- Name: vm.Name,- Node: n.Node,- Pool: strings.TrimSpace(vm.Pool),- Instance: instanceName,- Status: vm.Status,- Type: "qemu",- CPU: cpuUsage,- CPUs: vm.CPUs,- Memory: memory,- Disk: models.Disk{- Total: int64(diskTotal),- Used: int64(diskUsed),- Free: int64(diskFree),- Usage: diskUsage,- },- Disks: individualDisks,- DiskStatusReason: diskStatusReason,- NetworkIn: max(0, int64(netInRate)),- NetworkOut: max(0, int64(netOutRate)),- DiskRead: max(0, int64(diskReadRate)),- DiskWrite: max(0, int64(diskWriteRate)),- Uptime: int64(vm.Uptime),- Template: vm.Template == 1,- LastSeen: sampleTime,- Tags: tags,- IPAddresses: ipAddresses,- OSName: osName,- OSVersion: osVersion,- AgentVersion: guestAgentVersion,- NetworkInterfaces: networkInterfaces,- }-- // Zero out metrics for non-running VMs- if vm.Status != "running" {- modelVM.CPU = 0- modelVM.Memory.Usage = 0- modelVM.Disk.Usage = 0- modelVM.NetworkIn = 0- modelVM.NetworkOut = 0- modelVM.DiskRead = 0- modelVM.DiskWrite = 0- }-- // Trigger guest metadata migration if old format exists- if m.guestMetadataStore != nil {- m.guestMetadataStore.GetWithLegacyMigration(guestID, instanceName, n.Node, vm.VMID)- }-- nodeVMs = append(nodeVMs, modelVM)-- m.recordGuestSnapshot(instanceName, modelVM.Type, n.Node, vm.VMID, GuestMemorySnapshot{- Name: vm.Name,- Status: vm.Status,- RetrievedAt: sampleTime,- MemorySource: memorySource,- FallbackReason: guestMemoryFallbackReason(memorySource),- Memory: modelVM.Memory,- Raw: guestRaw,- Notes: snapshotNotes,- })-- // Check alerts- m.alertManager.CheckGuest(modelVM, instanceName)- }-+ nodeVMs, nodeTemplateSubjects := m.pollNodeVMsWithClusterResourceBuilder(ctx, instanceName, n.Node, vms, client, prevVMByID, vmIDToHostAgent)nodeDuration := time.Since(nodeStart)log.Debug().Str("node", n.Node).@@ -615,13 +75,11 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu}(node)}- // Close channel when all goroutines completego func() {wg.Wait()close(resultChan)}()- // Collect results from all nodesvar allVMs []models.VMqemuTemplateSubjects := make(map[string]struct{})successfulNodes := 0@@ -630,20 +88,18 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clufor result := range resultChan {if result.err != nil {failedNodes++- } else {- successfulNodes++- allVMs = append(allVMs, result.vms...)- for key := range result.templateSubjects {- qemuTemplateSubjects[key] = struct{}{}- }+ continue+ }+ successfulNodes+++ allVMs = append(allVMs, result.vms...)+ for key := range result.templateSubjects {+ qemuTemplateSubjects[key] = struct{}{}}}if failedNodes == 0 && successfulNodes > 0 {m.updatePVEBackupTemplateSubjectsForType(instanceName, "qemu", qemuTemplateSubjects)}- // If we got ZERO VMs but had VMs before (likely cluster health issue),- // preserve previous VMs instead of clearing themif len(allVMs) == 0 && len(nodes) > 0 {allVMs = append(allVMs, prevGuests.vms...)prevVMCount := len(prevGuests.vms)@@ -657,10 +113,8 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, clu}}- // Update state with all VMsm.state.UpdateVMsForInstance(instanceName, allVMs)- // Record guest metrics history for running VMs (enables sparkline/trends view)if !shouldSkipNativeMockStateMetricWrites() {now := time.Now()for _, vm := range allVMs {@@ -672,7 +126,6 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluif vm.Disk.Usage >= 0 {m.metricsHistory.AddGuestMetric(vm.ID, "disk", vm.Disk.Usage, now)}- // Also write to persistent storeif m.metricsStore != nil {m.metricsStore.Write("vm", vm.ID, "cpu", vm.CPU*100, now)m.metricsStore.Write("vm", vm.ID, "memory", vm.Memory.Usage, now)@@ -692,7 +145,3 @@ func (m *Monitor) pollVMsWithNodes(ctx context.Context, instanceName string, cluDur("duration", duration).Msg("Parallel VM polling completed")}--// pollContainersWithNodes polls containers from all nodes in parallel using goroutines-// When the instance is part of a cluster, the cluster name is used for guest IDs to prevent duplicates-// when multiple cluster nodes are configured as separate PVE instances.diff --git a/internal/monitoring/monitor_pve.go b/internal/monitoring/monitor_pve.goindex cd9fa53e08..5d2a8fac00 100644--- a/internal/monitoring/monitor_pve.go+++ b/internal/monitoring/monitor_pve.go@@ -456,6 +456,25 @@ func (m *Monitor) fetchPVENodes(ctx context.Context, instanceName string, instanreturn nodes, client, nil}+func (m *Monitor) refreshPVETagColors(ctx context.Context, client PVEClientInterface) {+ type clusterOptionsGetter interface {+ GetClusterOptions(ctx context.Context) (*proxmox.ClusterOptions, error)+ }++ getter, ok := client.(clusterOptionsGetter)+ if !ok || getter == nil {+ return+ }++ opts, err := getter.GetClusterOptions(ctx)+ if err != nil || opts == nil {+ return+ }+ if colors := proxmox.ParseTagColorMap(opts.TagStyle); len(colors) > 0 {+ m.state.MergeTagColors(colors)+ }+}+func (m *Monitor) updatePVEConnectionHealth(ctx context.Context, instanceName string, client PVEClientInterface) string {connectionHealthStr := "healthy"if clusterClient, ok := client.(*proxmox.ClusterClient); ok {@@ -1028,6 +1047,7 @@ func (m *Monitor) pollPVEInstance(ctx context.Context, instanceName string, cliereturn}client = updatedClient+ m.refreshPVETagColors(ctx, client)// Check if client is a ClusterClient to determine health statusconnectionHealthStr := m.updatePVEConnectionHealth(ctx, instanceName, client)diff --git a/internal/monitoring/monitor_pve_guest_poll.go b/internal/monitoring/monitor_pve_guest_poll.goindex fe031935cd..c993b19fe3 100644--- a/internal/monitoring/monitor_pve_guest_poll.go+++ b/internal/monitoring/monitor_pve_guest_poll.go@@ -2,6 +2,7 @@ package monitoringimport ("context"+ "sync""github.com/rcourtman/pulse-go-rewrite/internal/models""github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"@@ -77,6 +78,7 @@ func (m *Monitor) collectGuestsFromClusterResources() ([]models.VM, []models.Container) {allVMs := make([]models.VM, 0, len(resources))allContainers := make([]models.Container, 0, len(resources))+ vmResources := make([]indexedClusterResource, 0, len(resources))for _, res := range resources {// Generate canonical guest ID: instance:node:vmid@@ -92,15 +94,11 @@ func (m *Monitor) collectGuestsFromClusterResources(switch res.Type {case "qemu":- var prevVM *models.VM- if prev, ok := prevVMByID[guestID]; ok {- prevVM = &prev- }- vm, ok := m.handleClusterVMResource(ctx, instanceName, res, guestID, client, prevVM, vmIDToHostAgent)- if !ok {- continue- }- allVMs = append(allVMs, vm)+ vmResources = append(vmResources, indexedClusterResource{+ order: len(vmResources),+ resource: res,+ guestID: guestID,+ })case "lxc":container, ok := m.handleClusterContainerResource(ctx, instanceName, res, guestID, client, prevContainerIsOCI)if !ok {@@ -110,9 +108,93 @@ func (m *Monitor) collectGuestsFromClusterResources(}}+ if len(vmResources) > 0 {+ allVMs = append(allVMs, m.collectClusterVMResources(ctx, instanceName, vmResources, client, prevVMByID, vmIDToHostAgent)...)+ }+return allVMs, allContainers}+type indexedClusterResource struct {+ order int+ resource proxmox.ClusterResource+ guestID string+}++type clusterVMResourceResult struct {+ order int+ vm models.VM+ ok bool+}++func (m *Monitor) collectClusterVMResources(+ ctx context.Context,+ instanceName string,+ resources []indexedClusterResource,+ client PVEClientInterface,+ prevVMByID map[string]models.VM,+ vmIDToHostAgent map[string]models.Host,+) []models.VM {+ resultCh := make(chan clusterVMResourceResult, len(resources))+ jobCh := make(chan indexedClusterResource, len(resources))+ var wg sync.WaitGroup++ workerCount := m.efficientQEMUWorkerCount(len(resources))+ for i := 0; i < workerCount; i++ {+ wg.Add(1)+ go func() {+ defer wg.Done()+ for entry := range jobCh {+ var result clusterVMResourceResult+ ran := m.runGuestAgentVMWork(ctx, func(workCtx context.Context) {+ var prevVM *models.VM+ if prev, ok := prevVMByID[entry.guestID]; ok {+ prevVM = &prev+ }+ vm, ok := m.handleClusterVMResource(workCtx, instanceName, entry.resource, entry.guestID, client, prevVM, vmIDToHostAgent)+ result = clusterVMResourceResult{+ order: entry.order,+ vm: vm,+ ok: ok,+ }+ })+ if !ran {+ result = clusterVMResourceResult{order: entry.order, ok: false}+ }+ resultCh <- result+ }+ }()+ }++ for _, entry := range resources {+ jobCh <- entry+ }+ close(jobCh)++ go func() {+ wg.Wait()+ close(resultCh)+ }()++ orderedVMs := make([]models.VM, len(resources))+ orderedOK := make([]bool, len(resources))+ for result := range resultCh {+ if result.order < 0 || result.order >= len(resources) || !result.ok {+ continue+ }+ orderedVMs[result.order] = result.vm+ orderedOK[result.order] = true+ }++ vms := make([]models.VM, 0, len(resources))+ for i, ok := range orderedOK {+ if ok {+ vms = append(vms, orderedVMs[i])+ }+ }+ return vms+}+func (m *Monitor) handleClusterVMResource(ctx context.Context,instanceName string,diff --git a/internal/monitoring/monitor_pve_node_vm_builder.go b/internal/monitoring/monitor_pve_node_vm_builder.gonew file mode 100644index 0000000000..28442f92e4--- /dev/null+++ b/internal/monitoring/monitor_pve_node_vm_builder.go@@ -0,0 +1,60 @@+package monitoring++import (+ "context"++ "github.com/rcourtman/pulse-go-rewrite/internal/models"+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"+)++func (m *Monitor) pollNodeVMsWithClusterResourceBuilder(+ ctx context.Context,+ instanceName string,+ node string,+ vms []proxmox.VM,+ client PVEClientInterface,+ prevVMByID map[string]models.VM,+ vmIDToHostAgent map[string]models.Host,+) ([]models.VM, map[string]struct{}) {+ templateSubjects := make(map[string]struct{})+ resources := make([]indexedClusterResource, 0, len(vms))++ for _, vm := range vms {+ if vm.Template == 1 {+ if key := pveBackupTemplateSubjectKey(instanceName, "qemu", node, vm.VMID); key != "" {+ templateSubjects[key] = struct{}{}+ }+ continue+ }++ guestID := makeGuestID(instanceName, node, vm.VMID)+ resources = append(resources, indexedClusterResource{+ order: len(resources),+ resource: proxmox.ClusterResource{+ ID: guestID,+ Type: "qemu",+ Node: node,+ Pool: vm.Pool,+ Status: vm.Status,+ Name: vm.Name,+ VMID: vm.VMID,+ CPU: vm.CPU,+ MaxCPU: vm.CPUs,+ Mem: vm.Mem,+ MaxMem: vm.MaxMem,+ Disk: vm.Disk,+ MaxDisk: vm.MaxDisk,+ NetIn: vm.NetIn,+ NetOut: vm.NetOut,+ DiskRead: vm.DiskRead,+ DiskWrite: vm.DiskWrite,+ Uptime: vm.Uptime,+ Template: vm.Template,+ Tags: vm.Tags,+ },+ guestID: guestID,+ })+ }++ return m.collectClusterVMResources(ctx, instanceName, resources, client, prevVMByID, vmIDToHostAgent), templateSubjects+}diff --git a/internal/monitoring/monitor_pve_storage.go b/internal/monitoring/monitor_pve_storage.goindex 6aa549621d..c2c0e146cd 100644--- a/internal/monitoring/monitor_pve_storage.go+++ b/internal/monitoring/monitor_pve_storage.go@@ -182,7 +182,7 @@ func (m *Monitor) applyStorageFallbackAndRecordNodeMetrics(for i := range modelNodes {currentDiskSource := nodeDiskSources[modelNodes[i].Name]if disk, exists := storageFallback[modelNodes[i].Name]; exists &&- (modelNodes[i].Disk.Total == 0 || currentDiskSource == "" || currentDiskSource == "nodes-endpoint") {+ (modelNodes[i].Disk.Total == 0 || currentDiskSource == "") {modelNodes[i].Disk = disklog.Debug().Str("node", modelNodes[i].Name).diff --git a/internal/monitoring/node_memory_sources_test.go b/internal/monitoring/node_memory_sources_test.goindex 0401a5d013..d36d01d833 100644--- a/internal/monitoring/node_memory_sources_test.go+++ b/internal/monitoring/node_memory_sources_test.go@@ -187,7 +187,7 @@ func TestResolveNodeDiskFallsBackToRootFSWithoutLinkedHost(t *testing.T) {}}-func TestPollPVEInstancePrefersCanonicalLocalStorageOverNodesEndpoint(t *testing.T) {+func TestPollPVEInstancePreservesNodesEndpointDiskWhenStorageFallbackExists(t *testing.T) {t.Setenv("PULSE_DATA_DIR", t.TempDir())client := &stubPVEClient{@@ -250,6 +250,64 @@ func TestPollPVEInstancePrefersCanonicalLocalStorageOverNodesEndpoint(t *testingt.Fatalf("expected one node in state, got %d", len(snapshot.Nodes))}+ node := snapshot.Nodes[0]+ wantTotal := int64(916 * 1024 * 1024 * 1024)+ wantUsed := int64(92 * 1024 * 1024 * 1024)+ wantFree := int64(824 * 1024 * 1024 * 1024)+ if node.Disk.Total != wantTotal || node.Disk.Used != wantUsed || node.Disk.Free != wantFree {+ t.Fatalf("node disk = %+v, want /nodes endpoint totals preserved", node.Disk)+ }+ if node.Disk.Usage < 10.0 || node.Disk.Usage > 10.1 {+ t.Fatalf("node disk usage = %.2f, want /nodes endpoint usage around 10.04", node.Disk.Usage)+ }+}++func TestPollPVEInstanceUsesStorageFallbackWhenNodeDiskUnavailable(t *testing.T) {+ t.Setenv("PULSE_DATA_DIR", t.TempDir())++ client := &stubPVEClient{+ nodes: []proxmox.Node{+ {+ Node: "nuc",+ Status: "online",+ CPU: 0.12,+ MaxCPU: 8,+ Mem: 4 * 1024 * 1024 * 1024,+ MaxMem: 8 * 1024 * 1024 * 1024,+ Disk: 0,+ MaxDisk: 0,+ Uptime: 3600,+ },+ },+ nodeStatus: nil,+ allStorage: []proxmox.Storage{{Storage: "local-zfs"}},+ storageByNode: map[string][]proxmox.Storage{+ "nuc": {+ {+ Storage: "local-zfs",+ Type: "zfspool",+ Content: "images,rootdir",+ Shared: 0,+ Total: 944 * 1024 * 1024 * 1024,+ Used: 313 * 1024 * 1024 * 1024,+ Available: 631 * 1024 * 1024 * 1024,+ },+ },+ },+ }++ mon := newTestPVEMonitor("test")+ defer mon.alertManager.Stop()+ defer mon.notificationMgr.Stop()+ mon.config.PVEInstances[0].MonitorStorage = true++ mon.pollPVEInstance(context.Background(), "test", client)++ snapshot := mon.state.GetSnapshot()+ if len(snapshot.Nodes) != 1 {+ t.Fatalf("expected one node in state, got %d", len(snapshot.Nodes))+ }+node := snapshot.Nodes[0]wantTotal := int64(944 * 1024 * 1024 * 1024)wantUsed := int64(313 * 1024 * 1024 * 1024)diff --git a/pkg/metrics/store.go b/pkg/metrics/store.goindex efc9966980..87231f205f 100644--- a/pkg/metrics/store.go+++ b/pkg/metrics/store.go@@ -135,6 +135,11 @@ type bufferedMetric struct {tier Tier}+type writeRequest struct {+ metrics []bufferedMetric+ done chan struct{}+}+type metricBatchKey struct {resourceType stringresourceID string@@ -170,7 +175,7 @@ type Store struct {buffer []bufferedMetric// Background workers- writeCh chan []bufferedMetric+ writeCh chan writeRequestmaintenanceCh chan maintenanceRequeststopCh chan struct{}doneCh chan struct{}@@ -224,7 +229,7 @@ func NewStore(config StoreConfig) (*Store, error) {db: db,config: config,buffer: make([]bufferedMetric, 0, config.WriteBufferSize),- writeCh: make(chan []bufferedMetric, 100), // Buffer for write batches+ writeCh: make(chan writeRequest, 100), // Buffer for write batchesmaintenanceCh: make(chan maintenanceRequest, 1),stopCh: make(chan struct{}),doneCh: make(chan struct{}),@@ -504,9 +509,9 @@ func (s *Store) WriteWithTier(resourceType, resourceID, metricType string, value}s.bufferMu.Lock()- defer s.bufferMu.Unlock()if s.stopping.Load() {+ s.bufferMu.Unlock()return}@@ -520,9 +525,13 @@ func (s *Store) WriteWithTier(resourceType, resourceID, metricType string, value})// Flush if buffer is full+ var toWrite []bufferedMetricif len(s.buffer) >= s.config.WriteBufferSize {- s.flushLocked()+ toWrite = s.detachBufferLocked()}+ s.bufferMu.Unlock()++ s.enqueueWrite(writeRequest{metrics: toWrite})}// WriteBatchSync writes metrics directly to the database without buffering.@@ -638,10 +647,11 @@ func (s *Store) runStartupMaintenance() {log.Info().Dur("duration", time.Since(start)).Msg("Deferred metrics startup maintenance completed")}-// flush writes buffered metrics to the database (caller must hold bufferMu)-func (s *Store) flushLocked() {+// detachBufferLocked returns the current in-memory buffer and resets it.+// Caller must hold bufferMu.+func (s *Store) detachBufferLocked() []bufferedMetric {if len(s.buffer) == 0 {- return+ return nil}// Copy buffer for writing@@ -649,17 +659,75 @@ func (s *Store) flushLocked() {copy(toWrite, s.buffer)s.buffer = s.buffer[:0]- // Send to serialized write channel+ return toWrite+}++// flush writes buffered metrics to the database (caller must hold bufferMu)+func (s *Store) flushLocked() {+ s.enqueueWrite(writeRequest{metrics: s.detachBufferLocked()})+}++func (s *Store) enqueueWrite(req writeRequest) {+ if len(req.metrics) == 0 && req.done == nil {+ return+ }+select {- case s.writeCh <- toWrite:+ case s.writeCh <- req:default:log.Warn().Str("component", "metrics_store").Str("action", "drop_write_batch").- Int("batch_size", len(toWrite)).+ Int("batch_size", len(req.metrics)).Int("write_queue_depth", len(s.writeCh)).Int("write_queue_capacity", cap(s.writeCh)).Msg("Metrics write channel full, dropping batch")+ if req.done != nil {+ close(req.done)+ }+ }+}++func (s *Store) enqueueAndWait(req writeRequest) {+ if req.done == nil {+ req.done = make(chan struct{})+ }++ s.writeCh <- req+ <-req.done+}++func (s *Store) drainBuffer() []bufferedMetric {+ s.bufferMu.Lock()+ defer s.bufferMu.Unlock()+ return s.detachBufferLocked()+}++func (s *Store) flushBufferedAsync() {+ s.enqueueWrite(writeRequest{metrics: s.drainBuffer()})+}++func (s *Store) processWriteRequests(requests []writeRequest) {+ if len(requests) == 0 {+ return+ }++ combined := make([]bufferedMetric, 0)+ doneChans := make([]chan struct{}, 0)+ for _, req := range requests {+ if len(req.metrics) > 0 {+ combined = append(combined, req.metrics...)+ }+ if req.done != nil {+ doneChans = append(doneChans, req.done)+ }+ }++ if len(combined) > 0 {+ s.writeBatch(combined)+ }+ for _, done := range doneChans {+ close(done)}}@@ -775,26 +843,25 @@ func coalesceMetricBatch(metrics []bufferedMetric) []bufferedMetric {return coalesced}-// coalesceQueuedBatches drains any already-queued write batches so the worker-// can commit them in a single SQLite transaction. This reduces WAL write-// amplification when the in-memory buffer flushes multiple times during one-// poll cycle.-func (s *Store) coalesceQueuedBatches(initial []bufferedMetric) []bufferedMetric {- if len(initial) == 0 {+// coalesceQueuedRequests drains any already-queued write requests so the worker+// can commit pending metrics in a single SQLite transaction while preserving+// Flush completion barriers.+func (s *Store) coalesceQueuedRequests(initial writeRequest) []writeRequest {+ if len(initial.metrics) == 0 && initial.done == nil {return nil}- combined := initial+ combined := []writeRequest{initial}for {select {case next, ok := <-s.writeCh:if !ok {return combined}- if len(next) == 0 {+ if len(next.metrics) == 0 && next.done == nil {continue}- combined = append(combined, next...)+ combined = append(combined, next)default:return combined}@@ -1402,24 +1469,22 @@ func (s *Store) backgroundWorker() {for {select {case <-s.stopCh:- // Final flush before stopping- s.Flush()- // Process remaining writes- close(s.writeCh)- var remaining []bufferedMetric- for batch := range s.writeCh {- if len(batch) == 0 {- continue- }- remaining = append(remaining, batch...)+ var remaining []writeRequest+ if batch := s.drainBuffer(); len(batch) > 0 {+ remaining = append(remaining, writeRequest{metrics: batch})}- if len(remaining) > 0 {- s.writeBatch(remaining)+ close(s.writeCh)+ for req := range s.writeCh {+ remaining = append(remaining, req)}+ s.processWriteRequests(remaining)return- case batch := <-s.writeCh:- s.writeBatch(s.coalesceQueuedBatches(batch))+ case req, ok := <-s.writeCh:+ if !ok {+ return+ }+ s.processWriteRequests(s.coalesceQueuedRequests(req))case maintenance := <-s.maintenanceCh:if maintenance.run != nil {@@ -1430,7 +1495,7 @@ func (s *Store) backgroundWorker() {}case <-flushTicker.C:- s.Flush()+ s.flushBufferedAsync()case <-rollupTicker.C:s.runRollup()@@ -1441,11 +1506,13 @@ func (s *Store) backgroundWorker() {}}-// Flush writes any buffered metrics to the database+// Flush writes any buffered metrics to the database and waits for all queued+// writes ahead of the flush barrier to become visible.func (s *Store) Flush() {- s.bufferMu.Lock()- defer s.bufferMu.Unlock()- s.flushLocked()+ if s == nil || s.stopping.Load() {+ return+ }+ s.enqueueAndWait(writeRequest{metrics: s.drainBuffer()})}// runRollup aggregates raw data into higher tiersdiff --git a/pkg/metrics/store_additional_test.go b/pkg/metrics/store_additional_test.goindex 3d7df634ab..91b52f3864 100644--- a/pkg/metrics/store_additional_test.go+++ b/pkg/metrics/store_additional_test.go@@ -79,22 +79,31 @@ func TestNormalizeRollupInterval(t *testing.T) {func TestStoreCoalesceQueuedBatches(t *testing.T) {store := &Store{- writeCh: make(chan []bufferedMetric, 4),+ writeCh: make(chan writeRequest, 4),}- initial := []bufferedMetric{- {resourceType: "vm", resourceID: "vm-1", metricType: "cpu", value: 10},+ initial := writeRequest{+ metrics: []bufferedMetric{+ {resourceType: "vm", resourceID: "vm-1", metricType: "cpu", value: 10},+ },}- store.writeCh <- []bufferedMetric{+ store.writeCh <- writeRequest{metrics: []bufferedMetric{{resourceType: "vm", resourceID: "vm-1", metricType: "memory", value: 20},- }- store.writeCh <- []bufferedMetric{+ }}+ store.writeCh <- writeRequest{metrics: []bufferedMetric{{resourceType: "vm", resourceID: "vm-2", metricType: "cpu", value: 30},- }+ }}- combined := store.coalesceQueuedBatches(initial)+ combined := store.coalesceQueuedRequests(initial)if len(combined) != 3 {- t.Fatalf("expected 3 combined metrics, got %d", len(combined))+ t.Fatalf("expected 3 combined requests, got %d", len(combined))+ }+ totalMetrics := 0+ for _, req := range combined {+ totalMetrics += len(req.metrics)+ }+ if totalMetrics != 3 {+ t.Fatalf("expected 3 combined metrics, got %d", totalMetrics)}if len(store.writeCh) != 0 {t.Fatalf("expected queued batches to be drained, got %d remaining", len(store.writeCh))@@ -281,17 +290,7 @@ func TestStoreClear(t *testing.T) {store.Write("vm", "v1", "cpu", 10.0, time.Now())store.Flush()- // Wait for data to be written (Flush is async via channel)- deadline := time.Now().Add(2 * time.Second)- var stats Stats- for time.Now().Before(deadline) {- stats = store.GetStats()- if stats.RawCount > 0 {- break- }- time.Sleep(50 * time.Millisecond)- }-+ stats := store.GetStats()if stats.RawCount == 0 {t.Fatal("expected data to be written before clearing")}@@ -365,17 +364,17 @@ func TestStoreFlushLockedLogsStructuredContextWhenWriteChannelFull(t *testing.T)tier: TierRaw,},},- writeCh: make(chan []bufferedMetric, 1),+ writeCh: make(chan writeRequest, 1),}- store.writeCh <- []bufferedMetric{{+ store.writeCh <- writeRequest{metrics: []bufferedMetric{{resourceType: "vm",resourceID: "vm-102",metricType: "memory",value: 12,timestamp: time.Unix(1000, 0),tier: TierRaw,- }}+ }}}store.flushLocked()@@ -398,6 +397,34 @@ func TestStoreFlushLockedLogsStructuredContextWhenWriteChannelFull(t *testing.T)}}+func TestStoreFlushMakesQueuedWritesVisible(t *testing.T) {+ dir := t.TempDir()+ cfg := DefaultConfig(dir)+ cfg.WriteBufferSize = 1+ cfg.FlushInterval = time.Hour++ store, err := NewStore(cfg)+ if err != nil {+ t.Fatalf("NewStore returned error: %v", err)+ }+ defer store.Close()++ ts := time.Now().UTC().Truncate(time.Second)+ store.Write("vm", "vm-1", "cpu", 42, ts)++ // With a buffer size of 1, the write above is already queued+ // asynchronously. Flush must still wait for that queued batch to commit.+ store.Flush()++ points, err := store.Query("vm", "vm-1", "cpu", ts.Add(-time.Second), ts.Add(time.Second), 0)+ if err != nil {+ t.Fatalf("Query failed: %v", err)+ }+ if len(points) != 1 || points[0].Value != 42 {+ t.Fatalf("expected flushed metric to be immediately visible, got %v", points)+ }+}+func TestNewStoreDefersStartupMaintenance(t *testing.T) {previousHook := startupMaintenanceHookdefer func() {diff --git a/pkg/metrics/store_downsample_test.go b/pkg/metrics/store_downsample_test.goindex da1f92401b..3c0d7756f2 100644--- a/pkg/metrics/store_downsample_test.go+++ b/pkg/metrics/store_downsample_test.go@@ -191,7 +191,7 @@ func TestStoreFlushLockedDropsWhenChannelFull(t *testing.T) {store := &Store{config: StoreConfig{WriteBufferSize: 1},buffer: []bufferedMetric{{resourceType: "vm", resourceID: "v3", metricType: "cpu", value: 1, timestamp: time.Now(), tier: TierRaw}},- writeCh: make(chan []bufferedMetric),+ writeCh: make(chan writeRequest),}store.bufferMu.Lock()diff --git a/pkg/proxmox/ceph.go b/pkg/proxmox/ceph.goindex 0e024fdcd8..87a15dc826 100644--- a/pkg/proxmox/ceph.go+++ b/pkg/proxmox/ceph.go@@ -62,7 +62,18 @@ type CephServiceDaemon struct {// CephMonMap captures monitor summary information.type CephMonMap struct {- NumMons int `json:"num_mons"`+ NumMons int `json:"num_mons"`+ Mons []CephMonitor `json:"mons,omitempty"`+ Monitors []CephMonitor `json:"monitors,omitempty"`+ QuorumNames []string `json:"quorum_names,omitempty"`+ Quorum []json.RawMessage `json:"quorum,omitempty"`+}++// CephMonitor captures a monitor entry from Ceph monmap payloads.+type CephMonitor struct {+ Name string `json:"name"`+ Rank int `json:"rank"`+ Addr string `json:"addr"`}func (m *CephMonMap) UnmarshalJSON(data []byte) error {@@ -71,6 +82,8 @@ func (m *CephMonMap) UnmarshalJSON(data []byte) error {NumMonsLegacy int `json:"numMons"`Mons []json.RawMessage `json:"mons"`Monitors []json.RawMessage `json:"monitors"`+ QuorumNames []string `json:"quorum_names"`+ Quorum []json.RawMessage `json:"quorum"`}var raw rawCephMonMap@@ -78,22 +91,73 @@ func (m *CephMonMap) UnmarshalJSON(data []byte) error {return err}- switch {- case raw.NumMons > 0:- m.NumMons = raw.NumMons- case raw.NumMonsLegacy > 0:- m.NumMons = raw.NumMonsLegacy- case len(raw.Mons) > 0:- m.NumMons = len(raw.Mons)- case len(raw.Monitors) > 0:- m.NumMons = len(raw.Monitors)- default:- m.NumMons = 0- }+ m.Mons = parseCephMonitors(raw.Mons)+ m.Monitors = parseCephMonitors(raw.Monitors)+ m.QuorumNames = trimNonEmptyStrings(raw.QuorumNames)+ m.Quorum = append(m.Quorum[:0], raw.Quorum...)++ m.NumMons = maxCephMonitorCount(+ raw.NumMons,+ raw.NumMonsLegacy,+ len(m.Mons),+ len(m.Monitors),+ len(m.QuorumNames),+ len(m.Quorum),+ )return nil}+func parseCephMonitors(rawMonitors []json.RawMessage) []CephMonitor {+ if len(rawMonitors) == 0 {+ return nil+ }++ monitors := make([]CephMonitor, 0, len(rawMonitors))+ for _, raw := range rawMonitors {+ var monitor CephMonitor+ if err := json.Unmarshal(raw, &monitor); err == nil {+ monitors = append(monitors, monitor)+ continue+ }++ var name string+ if err := json.Unmarshal(raw, &name); err == nil {+ monitors = append(monitors, CephMonitor{Name: strings.TrimSpace(name)})+ continue+ }++ monitors = append(monitors, CephMonitor{})+ }++ return monitors+}++func trimNonEmptyStrings(values []string) []string {+ if len(values) == 0 {+ return nil+ }++ result := make([]string, 0, len(values))+ for _, value := range values {+ trimmed := strings.TrimSpace(value)+ if trimmed != "" {+ result = append(result, trimmed)+ }+ }+ return result+}++func maxCephMonitorCount(values ...int) int {+ maxValue := 0+ for _, value := range values {+ if value > maxValue {+ maxValue = value+ }+ }+ return maxValue+}+// CephMgrMap captures manager summary information.type CephMgrMap struct {Available bool `json:"available"`diff --git a/pkg/proxmox/ceph_test.go b/pkg/proxmox/ceph_test.goindex 4b26eee70e..26a01abf56 100644--- a/pkg/proxmox/ceph_test.go+++ b/pkg/proxmox/ceph_test.go@@ -118,6 +118,63 @@ func TestGetCephStatusCountsMonitorArrayFallback(t *testing.T) {}}+func TestGetCephStatusCountsQuorumMonMapFallbacks(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/cluster/ceph/status" {+ http.NotFound(w, r)+ return+ }+ resp := map[string]interface{}{+ "data": map[string]interface{}{+ "fsid": "fsid-1",+ "health": map[string]interface{}{+ "status": "HEALTH_OK",+ "summary": []map[string]interface{}{},+ "checks": map[string]interface{}{},+ },+ "servicemap": map[string]interface{}{+ "services": map[string]interface{}{},+ },+ "monmap": map[string]interface{}{+ "monitors": []string{"mon-a", "mon-b"},+ "quorum_names": []string{+ "mon-a",+ "mon-b",+ "mon-c",+ },+ "quorum": []interface{}{0, 1, 2},+ },+ "mgrmap": map[string]interface{}{+ "available": true,+ "num_mgrs": 1,+ "active_name": "mgr-a",+ "standbys": []string{},+ },+ "osdmap": map[string]interface{}{},+ "pgmap": map[string]interface{}{},+ },+ }+ _ = json.NewEncoder(w).Encode(resp)+ }))+ defer server.Close()++ client := &Client{baseURL: server.URL, httpClient: server.Client()}+ status, err := client.GetCephStatus(context.Background())+ if err != nil {+ t.Fatalf("unexpected error: %v", err)+ }++ if status.MonMap.NumMons != 3 {+ t.Fatalf("expected quorum fallback to count 3 monitors, got %+v", status.MonMap)+ }+ if len(status.MonMap.Monitors) != 2 || status.MonMap.Monitors[0].Name != "mon-a" {+ t.Fatalf("expected monitor aliases to be preserved, got %+v", status.MonMap.Monitors)+ }+ if len(status.MonMap.QuorumNames) != 3 || len(status.MonMap.Quorum) != 3 {+ t.Fatalf("expected quorum metadata to be preserved, got %+v", status.MonMap)+ }+}+func TestGetCephStatusAcceptsStructuredManagerStandbys(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if r.URL.Path != "/cluster/ceph/status" {diff --git a/pkg/proxmox/client.go b/pkg/proxmox/client.goindex 7ee7ad90a9..4263dd6ab6 100644--- a/pkg/proxmox/client.go+++ b/pkg/proxmox/client.go@@ -2275,6 +2275,74 @@ func (c *Client) GetClusterResources(ctx context.Context, resourceType string) (return result.Data, nil}+// ClusterOptions holds selected Proxmox datacenter configuration options.+type ClusterOptions struct {+ TagStyle string `json:"tag-style,omitempty"`+}++// GetClusterOptions fetches datacenter-level options such as tag color config.+func (c *Client) GetClusterOptions(ctx context.Context) (*ClusterOptions, error) {+ resp, err := c.get(ctx, "/cluster/options")+ if err != nil {+ return nil, err+ }+ defer resp.Body.Close()++ var result struct {+ Data ClusterOptions `json:"data"`+ }+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {+ return nil, err+ }+ return &result.Data, nil+}++// ParseTagColorMap parses a Proxmox tag-style string and returns a map of+// lowercase tag name to "#rrggbb" hex color string.+// Example input: "color-map=production:ff0000;staging:ffaa00,ordering=config"+func ParseTagColorMap(tagStyle string) map[string]string {+ colors := make(map[string]string)+ for _, part := range strings.Split(tagStyle, ",") {+ part = strings.TrimSpace(part)+ if !strings.HasPrefix(part, "color-map=") {+ continue+ }+ for _, pair := range strings.Split(strings.TrimPrefix(part, "color-map="), ";") {+ fields := strings.Split(pair, ":")+ if len(fields) < 2 {+ continue+ }+ tag := strings.ToLower(strings.TrimSpace(fields[0]))+ hex := strings.TrimSpace(fields[1])+ hex = strings.TrimPrefix(hex, "#")+ if tag == "" || !isHexColorToken(hex) {+ continue+ }+ colors[tag] = "#" + strings.ToLower(hex)+ }+ }+ return colors+}++func isHexColorToken(value string) bool {+ switch len(value) {+ case 3, 6, 8:+ default:+ return false+ }++ for _, r := range value {+ switch {+ case r >= '0' && r <= '9':+ case r >= 'a' && r <= 'f':+ case r >= 'A' && r <= 'F':+ default:+ return false+ }+ }+ return true+}+// ZFSPoolStatus represents the status of a ZFS pool (list endpoint)type ZFSPoolStatus struct {Name string `json:"name"`diff --git a/pkg/proxmox/client_test.go b/pkg/proxmox/client_test.goindex 2e8e614f98..4e91daac42 100644--- a/pkg/proxmox/client_test.go+++ b/pkg/proxmox/client_test.go@@ -7,6 +7,7 @@ import ("math""net/http""net/http/httptest"+ "reflect""strconv""strings""testing"@@ -158,6 +159,46 @@ func TestDiskUnmarshalRPM(t *testing.T) {}}+func TestParseTagColorMap(t *testing.T) {+ tests := []struct {+ name string+ tagStyle string+ expected map[string]string+ }{+ {+ name: "parses documented proxmox background and text color format",+ tagStyle: "color-map=Production:000000:FFFFFF;staging:ffaa00:101010,ordering=config",+ expected: map[string]string{+ "production": "#000000",+ "staging": "#ffaa00",+ },+ },+ {+ name: "parses legacy single-color entries with leading hash",+ tagStyle: "ordering=config,color-map=backup:#ABCDEF;ops:123456",+ expected: map[string]string{+ "backup": "#abcdef",+ "ops": "#123456",+ },+ },+ {+ name: "ignores invalid color tokens",+ tagStyle: "color-map=good:00ff00;bad:zzzzzz;also-bad:12345",+ expected: map[string]string{+ "good": "#00ff00",+ },+ },+ }++ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ if got := ParseTagColorMap(tc.tagStyle); !reflect.DeepEqual(got, tc.expected) {+ t.Fatalf("ParseTagColorMap() = %#v, want %#v", got, tc.expected)+ }+ })+ }+}+func TestDiskUnmarshalJSON_InvalidJSON(t *testing.T) {var disk Diskerr := json.Unmarshal([]byte(`{invalid json`), &disk)diff --git a/pkg/proxmox/cluster_client.go b/pkg/proxmox/cluster_client.goindex 3d5f164237..ec32b4c389 100644--- a/pkg/proxmox/cluster_client.go+++ b/pkg/proxmox/cluster_client.go@@ -1360,6 +1360,20 @@ func (cc *ClusterClient) GetClusterResources(ctx context.Context, resourceType sreturn result, err}+// GetClusterOptions fetches datacenter options via the first healthy node.+func (cc *ClusterClient) GetClusterOptions(ctx context.Context) (*ClusterOptions, error) {+ var result *ClusterOptions+ err := cc.executeWithFailover(ctx, func(client *Client) error {+ opts, err := client.GetClusterOptions(ctx)+ if err != nil {+ return err+ }+ result = opts+ return nil+ })+ return result, err+}+// GetContainerStatus returns the status of a specific containerfunc (cc *ClusterClient) GetContainerStatus(ctx context.Context, node string, vmid int) (*Container, error) {var result *Containerdiff --git a/scripts/install.ps1 b/scripts/install.ps1index e4eafc55fb..e548867ff8 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -655,6 +655,26 @@ if ($processorArch -eq "ARM64" -or $processorArch64 -eq "ARM64") {}$ArchParam = "windows-$Arch"$DownloadUrl = "$Url/download/pulse-agent?arch=$ArchParam"+$ServerVersion = ""++try {+ $versionResponse = Invoke-WithOptionalInsecureTls -AllowInsecure $Insecure -CustomCaCertificate $CustomCaCertificate -Action {+ Invoke-WebRequest -Uri "$Url/api/version" -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop+ }+ if ($versionResponse -and $versionResponse.Content) {+ $versionInfo = $versionResponse.Content | ConvertFrom-Json+ if ($versionInfo -and $versionInfo.version) {+ $ServerVersion = [string]$versionInfo.version+ Write-Host "Pulse server version: $ServerVersion" -ForegroundColor Cyan+ }+ }+} catch {+}++if (-not [string]::IsNullOrWhiteSpace($ServerVersion)) {+ $escapedServerVersion = [Uri]::EscapeDataString($ServerVersion)+ $DownloadUrl = "$DownloadUrl&serverVersion=$escapedServerVersion"+}function Invoke-AgentDownloadPreflight {param([string]$Uri)@@ -816,6 +836,17 @@ if (Test-HasPinnedInstallerSignatureKey) {}}+$DownloadedVersion = ""+try {+ $DownloadedVersion = ((& $TempPath --version 2>$null) | Select-Object -First 1).Trim()+} catch {+ $DownloadedVersion = ""+}++if (-not [string]::IsNullOrWhiteSpace($ServerVersion) -and -not [string]::IsNullOrWhiteSpace($DownloadedVersion) -and $DownloadedVersion -ne $ServerVersion) {+ Write-Host "Warning: downloaded agent version ($DownloadedVersion) does not match Pulse server version ($ServerVersion). Check that Pulse is upgraded and that any reverse proxy is not serving a stale cached binary." -ForegroundColor Yellow+}+# --- Install Binary ---Write-Host "Installing binary..." -ForegroundColor Cyandiff --git a/scripts/install.sh b/scripts/install.shindex bff39b5dee..f79943e6f3 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -101,6 +101,19 @@ INSTALL_SIGNATURE_NAMESPACE="pulse-install"INSTALL_SIGNATURE_IDENTITY="pulse-installer"PINNED_INSTALLER_SSH_PUBLIC_KEY="__PULSE_INSTALLER_SSH_PUBLIC_KEY__"+ROOTLESS_RUNTIME_KIND=""+ROOTLESS_RUNTIME_SOCKET_PATH=""+ROOTLESS_RUNTIME_SOCKET_URI=""+ROOTLESS_RUNTIME_XDG_DIR=""++SYSTEMD_ENV_LINES=""+SHELL_EXPORT_LINES=""+PLIST_ENV_ENTRIES=""+PLIST_ENV_BLOCK=""+UPSTART_ENV_LINES=""+SED_EXPORT_LINES=""+APPLIED_SERVICE_ENV_KEYS="|"+# Track if flags were explicitly set (to override auto-detection)DOCKER_EXPLICIT="false"KUBERNETES_EXPLICIT="false"@@ -700,9 +713,7 @@ render_systemd_agent_unit() {local user_line=""local log_lines=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- env_line=$'\n'"Environment=${SSL_CERT_ENV_NAME}=${SSL_CERT_ENV_VALUE}"- fi+ env_line="$SYSTEMD_ENV_LINES"if [[ -n "$wants_targets" ]]; thenwants_line=$'\n'"Wants=${wants_targets}"fi@@ -743,11 +754,7 @@ render_freebsd_rc_agent_script() {local script_path="$1"local exec_path="$2"local exec_args="$3"- local ssl_cert_line=""-- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- ssl_cert_line="export ${SSL_CERT_ENV_NAME}=\"${SSL_CERT_ENV_VALUE}\""- fi+ local service_env_lines="$SHELL_EXPORT_LINES"cat > "$script_path" <<EOF#!/bin/sh@@ -815,7 +822,7 @@ pulse_agent_start()rm -f \${pidfile} \${child_pidfile}echo "Starting \${name}."- ${ssl_cert_line}+ ${service_env_lines}/usr/sbin/daemon -r -P \${pidfile} -p \${child_pidfile} -f "\${command}" \${command_args}fi}@@ -1018,11 +1025,7 @@ write_qnap_wrapper_script() {local wrapper_script="$1"local runtime_binary="$2"local stored_binary="$3"- local export_ssl_cert=""-- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- export_ssl_cert=$'\n'"export ${SSL_CERT_ENV_NAME}=\"${SSL_CERT_ENV_VALUE}\""- fi+ local service_env_lines="$SHELL_EXPORT_LINES"cat > "$wrapper_script" <<EOF#!/bin/sh@@ -1044,7 +1047,7 @@ sleep 2mkdir -p "$(dirname "$runtime_binary")" 2>/dev/null || truecp "${stored_binary}" "${runtime_binary}"-chmod +x "${runtime_binary}"${export_ssl_cert}+chmod +x "${runtime_binary}"${service_env_lines}# Watchdog loop: restart agent if it exits.RESTART_DELAY=5@@ -1123,6 +1126,73 @@ detect_docker() {log_warn "Podman binary found but 'podman info' failed."fifi+ if discover_rootless_container_runtime; then+ return 0+ fi+ return 1+}++discover_single_socket_match() {+ local pattern="$1"+ local matches=()+ local candidate=""++ for candidate in $pattern; do+ [[ -S "$candidate" ]] || continue+ matches+=("$candidate")+ done++ case "${#matches[@]}" in+ 0)+ return 1+ ;;+ 1)+ printf '%s\n' "${matches[0]}"+ return 0+ ;;+ *)+ printf '%s\n' "__AMBIGUOUS__"+ return 0+ ;;+ esac+}++discover_rootless_container_runtime() {+ local docker_match=""+ local podman_match=""++ ROOTLESS_RUNTIME_KIND=""+ ROOTLESS_RUNTIME_SOCKET_PATH=""+ ROOTLESS_RUNTIME_SOCKET_URI=""+ ROOTLESS_RUNTIME_XDG_DIR=""++ if [[ "$(uname -s)" != "Linux" ]]; then+ return 1+ fi++ docker_match=$(discover_single_socket_match "/run/user/*/docker.sock" || true)+ podman_match=$(discover_single_socket_match "/run/user/*/podman/podman.sock" || true)++ if [[ "$docker_match" == "__AMBIGUOUS__" ]]; then+ log_warn "Multiple rootless Docker sockets found under /run/user; not auto-selecting one."+ elif [[ -n "$docker_match" ]]; then+ ROOTLESS_RUNTIME_KIND="docker"+ ROOTLESS_RUNTIME_SOCKET_PATH="$docker_match"+ ROOTLESS_RUNTIME_SOCKET_URI="unix://${docker_match}"+ ROOTLESS_RUNTIME_XDG_DIR="$(dirname "$docker_match")"+ return 0+ fi++ if [[ "$podman_match" == "__AMBIGUOUS__" ]]; then+ log_warn "Multiple rootless Podman sockets found under /run/user; not auto-selecting one."+ elif [[ -n "$podman_match" ]]; then+ ROOTLESS_RUNTIME_KIND="podman"+ ROOTLESS_RUNTIME_SOCKET_PATH="$podman_match"+ ROOTLESS_RUNTIME_SOCKET_URI="unix://${podman_match}"+ ROOTLESS_RUNTIME_XDG_DIR="${podman_match%/podman/podman.sock}"+ return 0+ fi+return 1}@@ -1512,13 +1582,21 @@ while [[ $# -gt 0 ]]; do--token) PULSE_TOKEN="$2"; shift 2 ;;--interval) INTERVAL="$2"; shift 2 ;;--enable-host) ENABLE_HOST="true"; shift ;;+ --enable-host=true) ENABLE_HOST="true"; shift ;;+ --enable-host=false) ENABLE_HOST="false"; shift ;;--disable-host) ENABLE_HOST="false"; shift ;;--enable-docker) ENABLE_DOCKER="true"; DOCKER_EXPLICIT="true"; shift ;;+ --enable-docker=true) ENABLE_DOCKER="true"; DOCKER_EXPLICIT="true"; shift ;;+ --enable-docker=false) ENABLE_DOCKER="false"; DOCKER_EXPLICIT="true"; shift ;;--disable-docker) ENABLE_DOCKER="false"; DOCKER_EXPLICIT="true"; shift ;;--enable-kubernetes) ENABLE_KUBERNETES="true"; KUBERNETES_EXPLICIT="true"; shift ;;+ --enable-kubernetes=true) ENABLE_KUBERNETES="true"; KUBERNETES_EXPLICIT="true"; shift ;;+ --enable-kubernetes=false) ENABLE_KUBERNETES="false"; KUBERNETES_EXPLICIT="true"; shift ;;--disable-kubernetes) ENABLE_KUBERNETES="false"; KUBERNETES_EXPLICIT="true"; shift ;;--kubeconfig) KUBECONFIG_PATH="$2"; KUBERNETES_EXPLICIT="true"; ENABLE_KUBERNETES="true"; shift 2 ;;--enable-proxmox) ENABLE_PROXMOX="true"; PROXMOX_EXPLICIT="true"; shift ;;+ --enable-proxmox=true) ENABLE_PROXMOX="true"; PROXMOX_EXPLICIT="true"; shift ;;+ --enable-proxmox=false) ENABLE_PROXMOX="false"; PROXMOX_EXPLICIT="true"; shift ;;--disable-proxmox) ENABLE_PROXMOX="false"; PROXMOX_EXPLICIT="true"; shift ;;--proxmox-type) PROXMOX_TYPE="$2"; shift 2 ;;--insecure) INSECURE="true"; shift ;;@@ -1620,6 +1698,65 @@ if [[ -n "$CURL_CA_BUNDLE" ]]; thenfifi+service_env_has_key() {+ local env_key="$1"+ case "$APPLIED_SERVICE_ENV_KEYS" in+ *"|${env_key}|"*) return 0 ;;+ *) return 1 ;;+ esac+}++shell_export_value() {+ local value="$1"+ value="${value//\\/\\\\}"+ value="${value//\"/\\\"}"+ value="${value//\$/\\$}"+ value="${value//\`/\\\`}"+ printf '"%s"' "$value"+}++append_service_env() {+ local env_key="$1"+ local env_val="$2"+ local shell_value=""+ local plist_key=""+ local plist_value=""++ if [[ -z "$env_key" ]] || service_env_has_key "$env_key"; then+ return+ fi++ shell_value="$(shell_export_value "$env_val")"+ SYSTEMD_ENV_LINES+=$'\n'"Environment=\"${env_key}=${env_val}\""+ SHELL_EXPORT_LINES+=$'\n'"export ${env_key}=${shell_value}"+ UPSTART_ENV_LINES+=$'\n'"env ${env_key}=${env_val}"+ if [[ -n "$SED_EXPORT_LINES" ]]; then+ SED_EXPORT_LINES+="; "+ fi+ SED_EXPORT_LINES+="export ${env_key}=${shell_value}"++ plist_key="$(xml_escape "$env_key")"+ plist_value="$(xml_escape "$env_val")"+ PLIST_ENV_ENTRIES+="+ <key>${plist_key}</key>+ <string>${plist_value}</string>"+ APPLIED_SERVICE_ENV_KEYS+="${env_key}|"+}++finalize_plist_env_block() {+ PLIST_ENV_BLOCK=""+ if [[ -n "$PLIST_ENV_ENTRIES" ]]; then+ PLIST_ENV_BLOCK="+ <key>EnvironmentVariables</key>+ <dict>${PLIST_ENV_ENTRIES}+ </dict>"+ fi+}++if [[ -n "$SSL_CERT_ENV_NAME" ]]; then+ append_service_env "$SSL_CERT_ENV_NAME" "$SSL_CERT_ENV_VALUE"+fi+# --- Platform Auto-Detection ---# Only auto-detect if flags weren't explicitly setlog_info "Detecting available platforms..."@@ -1668,6 +1805,30 @@ if [[ "$ENABLE_PROXMOX" == "true" ]]; thenfifi+if [[ "$ENABLE_DOCKER" == "true" ]] && discover_rootless_container_runtime; then+ if [[ "$ROOTLESS_RUNTIME_KIND" == "docker" ]]; then+ if ! service_env_has_key "DOCKER_HOST"; then+ append_service_env "DOCKER_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"+ if ! service_env_has_key "XDG_RUNTIME_DIR"; then+ append_service_env "XDG_RUNTIME_DIR" "$ROOTLESS_RUNTIME_XDG_DIR"+ fi+ log_info "Using rootless Docker socket for agent service: ${ROOTLESS_RUNTIME_SOCKET_PATH}"+ fi+ elif [[ "$ROOTLESS_RUNTIME_KIND" == "podman" ]]; then+ if ! service_env_has_key "CONTAINER_HOST" && ! service_env_has_key "PODMAN_HOST"; then+ append_service_env "PULSE_DOCKER_RUNTIME" "podman"+ append_service_env "CONTAINER_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"+ append_service_env "PODMAN_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"+ if ! service_env_has_key "XDG_RUNTIME_DIR"; then+ append_service_env "XDG_RUNTIME_DIR" "$ROOTLESS_RUNTIME_XDG_DIR"+ fi+ log_info "Using rootless Podman socket for agent service: ${ROOTLESS_RUNTIME_SOCKET_PATH}"+ fi+ fi+fi++finalize_plist_env_block+# --- Uninstall Logic ---if [[ "$UNINSTALL" == "true" ]]; thenlog_info "Uninstalling ${AGENT_NAME} and cleaning up legacy agents..."@@ -2041,9 +2202,6 @@ esac# Construct arch param in format expected by download endpoint (e.g., linux-amd64)ARCH_PARAM="${OS}-${ARCH}"-DOWNLOAD_URL="${PULSE_URL}/download/${BINARY_NAME}?arch=${ARCH_PARAM}"-log_info "Downloading agent from ${DOWNLOAD_URL}..."-# Create temp file and register for cleanupTMP_BIN=$(mktemp)TMP_FILES+=("$TMP_BIN")@@ -2055,6 +2213,23 @@ CURL_ARGS=(-fsSL --connect-timeout 30 --max-time 300 -D "$TMP_HEADERS" -o "$TMP_if [[ "$INSECURE" == "true" ]]; then CURL_ARGS+=(-k); fiif [[ -n "$CURL_CA_BUNDLE" ]]; then CURL_ARGS+=(--cacert "$CURL_CA_BUNDLE"); fi+SERVER_VERSION=""+VERSION_CURL_ARGS=(-fsSL --connect-timeout 10 --max-time 30)+if [[ "$INSECURE" == "true" ]]; then VERSION_CURL_ARGS+=(-k); fi+if [[ -n "$CURL_CA_BUNDLE" ]]; then VERSION_CURL_ARGS+=(--cacert "$CURL_CA_BUNDLE"); fi+if server_version_json="$(curl "${VERSION_CURL_ARGS[@]}" "${PULSE_URL}/api/version" 2>/dev/null)"; then+ SERVER_VERSION="$(printf '%s' "$server_version_json" | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)"+fi++DOWNLOAD_QUERY="arch=${ARCH_PARAM}"+if [[ -n "$SERVER_VERSION" ]]; then+ DOWNLOAD_QUERY="${DOWNLOAD_QUERY}&serverVersion=${SERVER_VERSION}"+ log_info "Pulse server version: ${SERVER_VERSION}"+fi++DOWNLOAD_URL="${PULSE_URL}/download/${BINARY_NAME}?${DOWNLOAD_QUERY}"+log_info "Downloading agent from ${DOWNLOAD_URL}..."+if ! curl "${CURL_ARGS[@]}" "$DOWNLOAD_URL"; thenfail "Download failed. Check URL and connectivity." "$EXIT_DOWNLOAD_FAILED"fi@@ -2105,6 +2280,11 @@ log_info "Binary checksum verified"verify_download_signature "$TMP_BIN" "$SSH_SIGNATURE_HEADER"chmod +x "$TMP_BIN"+NEW_VERSION=$("$TMP_BIN" --version 2>/dev/null | head -1 || echo "unknown")++if [[ -n "$SERVER_VERSION" && -n "$NEW_VERSION" && "$NEW_VERSION" != "unknown" && "$NEW_VERSION" != "$SERVER_VERSION" ]]; then+ log_warn "Downloaded agent version (${NEW_VERSION}) does not match Pulse server version (${SERVER_VERSION}). Check that Pulse is upgraded and that any reverse proxy is not serving a stale cached binary."+fi# --- Upgrade Detection ---# Check if pulse-agent is already installed and handle upgrade gracefully@@ -2113,8 +2293,7 @@ UPGRADE_MODE=falseif [[ -x "${INSTALL_DIR}/${BINARY_NAME}" ]]; thenEXISTING_VERSION=$("${INSTALL_DIR}/${BINARY_NAME}" --version 2>/dev/null | head -1 || echo "unknown")- NEW_VERSION=$("$TMP_BIN" --version 2>/dev/null | head -1 || echo "unknown")-+if [[ -n "$EXISTING_VERSION" && "$EXISTING_VERSION" != "unknown" ]]; thenUPGRADE_MODE=truelog_info "Existing installation detected: $EXISTING_VERSION"@@ -2161,17 +2340,6 @@ if [[ "$OS" == "darwin" ]]; thenbuild_plist_program_arguments "${INSTALL_DIR}/${BINARY_NAME}"- PLIST_ENV=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- PLIST_SSL_CERT_ENV_VALUE=$(xml_escape "$SSL_CERT_ENV_VALUE")- PLIST_ENV="- <key>EnvironmentVariables</key>- <dict>- <key>${SSL_CERT_ENV_NAME}</key>- <string>${PLIST_SSL_CERT_ENV_VALUE}</string>- </dict>"- fi-cat > "$PLIST" <<EOF<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">@@ -2182,7 +2350,7 @@ if [[ "$OS" == "darwin" ]]; then<key>ProgramArguments</key><array>${PLIST_ARGS}- </array>${PLIST_ENV}+ </array>${PLIST_ENV_BLOCK}<key>RunAtLoad</key><true/><key>KeepAlive</key>@@ -2225,11 +2393,6 @@ if [[ -d /usr/syno ]] && [[ -f /etc/VERSION ]]; thenCONF="/etc/init/${AGENT_NAME}.conf"log_info "Configuring Upstart service at $CONF (DSM 6.x)..."- UPSTART_ENV=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- UPSTART_ENV=$'\n'"env ${SSL_CERT_ENV_NAME}=${SSL_CERT_ENV_VALUE}"- fi-cat > "$CONF" <<EOFdescription "Pulse Unified Agent"author "Pulse"@@ -2238,7 +2401,7 @@ start on syno.network.readystop on runlevel [06]respawn-respawn limit 5 10${UPSTART_ENV}+respawn limit 5 10${UPSTART_ENV_LINES}exec ${INSTALL_DIR}/${BINARY_NAME} ${EXEC_ARGS} >> ${LOG_FILE} 2>&1EOF@@ -2286,10 +2449,7 @@ if [[ -f /etc/unraid-version ]]; then# Create a wrapper script that will be called from /boot/config/go# This script copies from persistent storage to RAM disk on boot, then starts the agent- EXPORT_SSL_CERT_FILE=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- EXPORT_SSL_CERT_FILE=$'\n'"export ${SSL_CERT_ENV_NAME}=\"${SSL_CERT_ENV_VALUE}\""- fi+ EXPORT_SERVICE_ENV="$SHELL_EXPORT_LINES"WRAPPER_SCRIPT="${UNRAID_STORAGE_DIR}/start-pulse-agent.sh"cat > "$WRAPPER_SCRIPT" <<EOF@@ -2304,7 +2464,7 @@ sleep 2# Copy binary from persistent storage to RAM disk (needed after reboot)cp "${UNRAID_STORED_BINARY}" "${RUNTIME_BINARY}"-chmod +x "${RUNTIME_BINARY}"${EXPORT_SSL_CERT_FILE}+chmod +x "${RUNTIME_BINARY}"${EXPORT_SERVICE_ENV}# Watchdog loop: restart agent if it exits# Uses exponential backoff to prevent rapid restart loops@@ -2535,11 +2695,6 @@ if [[ "$TRUENAS" == true ]]; thenTRUENAS_LOG_TARGET="$TRUENAS_LOG_FILE"fi- SYSTEMD_ENV=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- SYSTEMD_ENV=$'\n'"Environment=${SSL_CERT_ENV_NAME}=${SSL_CERT_ENV_VALUE}"- fi-render_systemd_agent_unit "$TRUENAS_SERVICE_STORAGE" "${TRUENAS_RUNTIME_BINARY}" "${EXEC_ARGS}" "network-online.target docker.service" "network-online.target" "root" "${TRUENAS_LOG_TARGET}"elif [[ "$(uname -s)" == "FreeBSD" ]]; thenrender_freebsd_rc_agent_script "$TRUENAS_SERVICE_STORAGE" "${TRUENAS_RUNTIME_BINARY}" "${EXEC_ARGS}"@@ -2660,11 +2815,7 @@ INITEOFsed -i "s|INSTALL_DIR_PLACEHOLDER|${INSTALL_DIR}|g" "$INITSCRIPT"sed -i "s|BINARY_NAME_PLACEHOLDER|${BINARY_NAME}|g" "$INITSCRIPT"sed -i "s|EXEC_ARGS_PLACEHOLDER|${EXEC_ARGS}|g" "$INITSCRIPT"- SSL_CERT_LINE=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- SSL_CERT_LINE="export ${SSL_CERT_ENV_NAME}=\"${SSL_CERT_ENV_VALUE}\""- fi- sed -i "s|SSL_CERT_FILE_PLACEHOLDER|${SSL_CERT_LINE}|g" "$INITSCRIPT"+ sed -i "s|SSL_CERT_FILE_PLACEHOLDER|${SED_EXPORT_LINES}|g" "$INITSCRIPT"chmod +x "$INITSCRIPT"restart_openrc_agent_service@@ -2869,11 +3020,7 @@ INITEOFsed -i "s|INSTALL_DIR_PLACEHOLDER|${INSTALL_DIR}|g" "$INITSCRIPT"sed -i "s|BINARY_NAME_PLACEHOLDER|${BINARY_NAME}|g" "$INITSCRIPT"sed -i "s|EXEC_ARGS_PLACEHOLDER|${EXEC_ARGS}|g" "$INITSCRIPT"- SSL_CERT_LINE=""- if [[ -n "$SSL_CERT_ENV_NAME" ]]; then- SSL_CERT_LINE="export ${SSL_CERT_ENV_NAME}=\"${SSL_CERT_ENV_VALUE}\""- fi- sed -i "s|SSL_CERT_FILE_PLACEHOLDER|${SSL_CERT_LINE}|g" "$INITSCRIPT"+ sed -i "s|SSL_CERT_FILE_PLACEHOLDER|${SED_EXPORT_LINES}|g" "$INITSCRIPT"chmod +x "$INITSCRIPT"diff --git a/scripts/installtests/build_release_assets_test.go b/scripts/installtests/build_release_assets_test.goindex d9a6a4ac05..6086ea1f0d 100644--- a/scripts/installtests/build_release_assets_test.go+++ b/scripts/installtests/build_release_assets_test.go@@ -515,6 +515,33 @@ func TestDockerAndDemoBuildsUseCanonicalReleaseLdflags(t *testing.T) {}}+func TestAgentRuntimeImagePersistsAgentIdentityByDefault(t *testing.T) {+ dockerfileBytes, err := os.ReadFile(repoFile("Dockerfile"))+ if err != nil {+ t.Fatalf("read Dockerfile: %v", err)+ }+ dockerfile := string(dockerfileBytes)++ required := []string{+ `mkdir -p /var/lib/pulse-agent`,+ `PULSE_DISABLE_AUTO_UPDATE=true`,+ `PULSE_ENABLE_HOST=false`,+ `PULSE_ENABLE_DOCKER=true`,+ `PULSE_AGENT_ID_FILE=/var/lib/pulse-agent/agent-id`,+ `PULSE_STATE_DIR=/var/lib/pulse-agent`,+ `VOLUME ["/var/lib/pulse-agent"]`,+ `ENTRYPOINT ["/usr/local/bin/pulse-agent"]`,+ }+ for _, needle := range required {+ if !strings.Contains(dockerfile, needle) {+ t.Fatalf("Dockerfile agent_runtime missing persistent identity contract: %s", needle)+ }+ }+ if strings.Contains(dockerfile, `ENTRYPOINT ["/usr/local/bin/pulse-agent", "--enable-docker", "--enable-host=false"]`) {+ t.Fatal("agent_runtime must not hard-code module flags in ENTRYPOINT; env defaults keep user args overridable")+ }+}+func TestReleaseWorkflowsUseSecretSafeAttestedImageBuilds(t *testing.T) {createReleaseBytes, err := os.ReadFile(repoFile(".github", "workflows", "create-release.yml"))if err != nil {diff --git a/scripts/installtests/install_ps1_test.go b/scripts/installtests/install_ps1_test.goindex 5095d99b70..7c194698e5 100644--- a/scripts/installtests/install_ps1_test.go+++ b/scripts/installtests/install_ps1_test.go@@ -68,6 +68,28 @@ func TestInstallPS1AllowsMissingTokenForOptionalAuth(t *testing.T) {}}+func TestInstallPS1AgentDownloadIsServerVersionAware(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.ps1"))+ if err != nil {+ t.Fatalf("read install.ps1: %v", err)+ }++ script := string(content)+ required := []string{+ `Invoke-WebRequest -Uri "$Url/api/version"`,+ `$versionInfo = $versionResponse.Content | ConvertFrom-Json`,+ `$ServerVersion = [string]$versionInfo.version`,+ `$escapedServerVersion = [Uri]::EscapeDataString($ServerVersion)`,+ `$DownloadUrl = "$DownloadUrl&serverVersion=$escapedServerVersion"`,+ `downloaded agent version ($DownloadedVersion) does not match Pulse server version ($ServerVersion)`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.ps1 missing version-aware agent download behavior: %s", needle)+ }+ }+}+func TestInstallPS1AllowsOptionalAuthUninstallWithoutToken(t *testing.T) {content, err := os.ReadFile(repoFile("scripts", "install.ps1"))if err != nil {diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.goindex 10a14880d0..22d3b4fc1f 100644--- a/scripts/installtests/install_sh_test.go+++ b/scripts/installtests/install_sh_test.go@@ -3,6 +3,7 @@ package installtestsimport ("encoding/json""io"+ "net""net/http""net/http/httptest""os"@@ -70,6 +71,51 @@ func TestInstallSHAutoDetectProxmoxKeepsRuntimeTypeUnpinned(t *testing.T) {}}+func TestInstallSHAcceptsLegacyBooleanFlagValues(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))+ if err != nil {+ t.Fatalf("read install.sh: %v", err)+ }++ script := string(content)+ required := []string{+ `--enable-host=true) ENABLE_HOST="true"; shift ;;`,+ `--enable-host=false) ENABLE_HOST="false"; shift ;;`,+ `--enable-docker=true) ENABLE_DOCKER="true"; DOCKER_EXPLICIT="true"; shift ;;`,+ `--enable-docker=false) ENABLE_DOCKER="false"; DOCKER_EXPLICIT="true"; shift ;;`,+ `--enable-kubernetes=true) ENABLE_KUBERNETES="true"; KUBERNETES_EXPLICIT="true"; shift ;;`,+ `--enable-kubernetes=false) ENABLE_KUBERNETES="false"; KUBERNETES_EXPLICIT="true"; shift ;;`,+ `--enable-proxmox=true) ENABLE_PROXMOX="true"; PROXMOX_EXPLICIT="true"; shift ;;`,+ `--enable-proxmox=false) ENABLE_PROXMOX="false"; PROXMOX_EXPLICIT="true"; shift ;;`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh missing legacy boolean flag alias: %s", needle)+ }+ }+}++func TestInstallSHAgentDownloadIsServerVersionAware(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))+ if err != nil {+ t.Fatalf("read install.sh: %v", err)+ }++ script := string(content)+ required := []string{+ `"${PULSE_URL}/api/version"`,+ `SERVER_VERSION="$(printf '%s' "$server_version_json" | sed -n 's/.*"version"`,+ `DOWNLOAD_QUERY="${DOWNLOAD_QUERY}&serverVersion=${SERVER_VERSION}"`,+ `log_info "Pulse server version: ${SERVER_VERSION}"`,+ `Downloaded agent version (${NEW_VERSION}) does not match Pulse server version (${SERVER_VERSION})`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh missing version-aware agent download behavior: %s", needle)+ }+ }+}+func TestInstallSHAgentServiceSecurityDefaults(t *testing.T) {content, err := os.ReadFile(repoFile("scripts", "install.sh"))if err != nil {@@ -706,6 +752,107 @@ func TestInstallSHUsesSharedServiceRenderers(t *testing.T) {}}+func TestInstallSHPersistsRootlessContainerRuntimeServiceEnvironment(t *testing.T) {+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))+ if err != nil {+ t.Fatalf("read install.sh: %v", err)+ }++ script := string(content)+ required := []string{+ `ROOTLESS_RUNTIME_SOCKET_URI=""`,+ `discover_rootless_container_runtime() {`,+ `discover_single_socket_match "/run/user/*/docker.sock"`,+ `discover_single_socket_match "/run/user/*/podman/podman.sock"`,+ `append_service_env "DOCKER_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"`,+ `append_service_env "PULSE_DOCKER_RUNTIME" "podman"`,+ `append_service_env "CONTAINER_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"`,+ `append_service_env "PODMAN_HOST" "$ROOTLESS_RUNTIME_SOCKET_URI"`,+ `append_service_env "XDG_RUNTIME_DIR" "$ROOTLESS_RUNTIME_XDG_DIR"`,+ `env_line="$SYSTEMD_ENV_LINES"`,+ `local service_env_lines="$SHELL_EXPORT_LINES"`,+ `</array>${PLIST_ENV_BLOCK}`,+ `respawn limit 5 10${UPSTART_ENV_LINES}`,+ `sed -i "s|SSL_CERT_FILE_PLACEHOLDER|${SED_EXPORT_LINES}|g" "$INITSCRIPT"`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("install.sh missing rootless service environment persistence contract: %s", needle)+ }+ }+}++func TestInstallSHServiceEnvAccumulatorRendersRootlessSocketVariables(t *testing.T) {+ script := `+ APPLIED_SERVICE_ENV_KEYS="|"+ SYSTEMD_ENV_LINES=""+ SHELL_EXPORT_LINES=""+ UPSTART_ENV_LINES=""+ SED_EXPORT_LINES=""+ PLIST_ENV_ENTRIES=""+ PLIST_ENV_BLOCK=""+` + extractInstallShellFunction(t, "xml_escape") + `+` + extractInstallShellFunction(t, "service_env_has_key") + `+` + extractInstallShellFunction(t, "shell_export_value") + `+` + extractInstallShellFunction(t, "append_service_env") + `+` + extractInstallShellFunction(t, "finalize_plist_env_block") + `+ append_service_env "DOCKER_HOST" "unix:///run/user/1000/docker.sock"+ append_service_env "XDG_RUNTIME_DIR" "/run/user/1000"+ append_service_env "DOCKER_HOST" "unix:///run/user/2000/docker.sock"+ finalize_plist_env_block+ printf '%s\n---shell---\n%s\n---sed---\n%s\n---plist---\n%s\n' "$SYSTEMD_ENV_LINES" "$SHELL_EXPORT_LINES" "$SED_EXPORT_LINES" "$PLIST_ENV_BLOCK"+ `++ out, err := exec.Command("bash", "-c", script).CombinedOutput()+ if err != nil {+ t.Fatalf("bash: %v\n%s", err, out)+ }+ got := string(out)+ required := []string{+ `Environment="DOCKER_HOST=unix:///run/user/1000/docker.sock"`,+ `Environment="XDG_RUNTIME_DIR=/run/user/1000"`,+ `export DOCKER_HOST="unix:///run/user/1000/docker.sock"`,+ `export XDG_RUNTIME_DIR="/run/user/1000"`,+ `export DOCKER_HOST="unix:///run/user/1000/docker.sock"; export XDG_RUNTIME_DIR="/run/user/1000"`,+ `<key>DOCKER_HOST</key>`,+ `<string>unix:///run/user/1000/docker.sock</string>`,+ }+ for _, needle := range required {+ if !strings.Contains(got, needle) {+ t.Fatalf("service env output missing %s:\n%s", needle, got)+ }+ }+ if strings.Contains(got, "unix:///run/user/2000/docker.sock") {+ t.Fatalf("service env accumulator did not ignore duplicate key:\n%s", got)+ }+}++func TestInstallSHDiscoverSingleSocketMatch(t *testing.T) {+ tmpDir, err := os.MkdirTemp("/tmp", "pulse-sock-*")+ if err != nil {+ t.Fatalf("mktemp socket dir: %v", err)+ }+ defer os.RemoveAll(tmpDir)+ socketPath := filepath.Join(tmpDir, "docker.sock")+ listener, err := net.Listen("unix", socketPath)+ if err != nil {+ t.Fatalf("listen unix socket: %v", err)+ }+ defer listener.Close()++ script := `+` + extractInstallShellFunction(t, "discover_single_socket_match") + `+ discover_single_socket_match "` + filepath.ToSlash(tmpDir) + `/*.sock"+ `+ out, err := exec.Command("bash", "-c", script).CombinedOutput()+ if err != nil {+ t.Fatalf("bash: %v\n%s", err, out)+ }+ if strings.TrimSpace(string(out)) != filepath.ToSlash(socketPath) {+ t.Fatalf("socket match = %q, want %q", strings.TrimSpace(string(out)), filepath.ToSlash(socketPath))+ }+}+func TestInstallSHFreeBSDRendererUsesDaemonSupervisorPidfile(t *testing.T) {content, err := os.ReadFile(repoFile("scripts", "install.sh"))if err != nil {@@ -2236,6 +2383,8 @@ esac` + extractAutoUpdateFunction(t, "require_release_signature_verifier") + `` + extractAutoUpdateFunction(t, "verify_release_signature") + `` + extractAutoUpdateFunction(t, "resolve_install_script_url") + `+` + extractAutoUpdateFunction(t, "is_prerelease_tag") + `+ wait_for_service_active() { return 0; }` + extractAutoUpdateFunction(t, "perform_update") + `perform_update v9.9.9`diff --git a/scripts/installtests/uninstall_sensor_proxy_test.go b/scripts/installtests/uninstall_sensor_proxy_test.gonew file mode 100644index 0000000000..6a67274fae--- /dev/null+++ b/scripts/installtests/uninstall_sensor_proxy_test.go@@ -0,0 +1,119 @@+package installtests++import (+ "os"+ "os/exec"+ "path/filepath"+ "strings"+ "testing"+)++func TestUninstallSensorProxyScriptContract(t *testing.T) {+ scriptPath := repoFile("scripts", "uninstall-sensor-proxy.sh")+ content, err := os.ReadFile(scriptPath)+ if err != nil {+ t.Fatalf("read uninstall-sensor-proxy.sh: %v", err)+ }++ script := string(content)+ required := []string{+ `--remove-proxmox-access`,+ `pulse-sensor-proxy-selfheal.timer`,+ `pulse-sensor-cleanup.path`,+ `remove_managed_keys_from_authorized_keys_file()`,+ `cleanup_stale_sensor_proxy_mounts()`,+ `pulse-monitor@pam`,+ `# pulse-(managed|proxy)-key$`,+ }+ for _, needle := range required {+ if !strings.Contains(script, needle) {+ t.Fatalf("uninstall-sensor-proxy.sh missing cleanup contract: %s", needle)+ }+ }++ if out, err := exec.Command("bash", "-n", scriptPath).CombinedOutput(); err != nil {+ t.Fatalf("bash -n uninstall-sensor-proxy.sh: %v\n%s", err, out)+ }+}++func TestUninstallSensorProxyScriptRemovesTempFootprintAndManagedKeys(t *testing.T) {+ tmpDir := t.TempDir()+ binDir := filepath.Join(tmpDir, "bin")+ if err := os.MkdirAll(binDir, 0755); err != nil {+ t.Fatalf("mkdir bin dir: %v", err)+ }+ if err := os.WriteFile(filepath.Join(binDir, "systemctl"), []byte("#!/bin/sh\nexit 0\n"), 0755); err != nil {+ t.Fatalf("write systemctl stub: %v", err)+ }+ if err := os.WriteFile(filepath.Join(binDir, "pct"), []byte("#!/bin/sh\nexit 0\n"), 0755); err != nil {+ t.Fatalf("write pct stub: %v", err)+ }++ binaryPath := filepath.Join(tmpDir, "pulse-sensor-proxy")+ installRoot := filepath.Join(tmpDir, "install-root")+ servicePath := filepath.Join(tmpDir, "pulse-sensor-proxy.service")+ runtimeDir := filepath.Join(tmpDir, "run")+ socketPath := filepath.Join(runtimeDir, "pulse-sensor-proxy.sock")+ workDir := filepath.Join(tmpDir, "work")+ configDir := filepath.Join(tmpDir, "config")+ logDir := filepath.Join(tmpDir, "logs")+ authKeys := filepath.Join(tmpDir, "authorized_keys")++ for _, dir := range []string{installRoot, runtimeDir, workDir, configDir, logDir} {+ if err := os.MkdirAll(dir, 0755); err != nil {+ t.Fatalf("mkdir %s: %v", dir, err)+ }+ }+ for _, path := range []string{binaryPath, servicePath, socketPath, filepath.Join(installRoot, "bin", "pulse-sensor-proxy")} {+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {+ t.Fatalf("mkdir parent for %s: %v", path, err)+ }+ if err := os.WriteFile(path, []byte("legacy"), 0644); err != nil {+ t.Fatalf("write %s: %v", path, err)+ }+ }+ if err := os.WriteFile(authKeys, []byte(strings.Join([]string{+ "ssh-ed25519 AAAAlegacy1 pulse # pulse-managed-key",+ "ssh-ed25519 AAAAkeep user-key",+ "ssh-ed25519 AAAAlegacy2 pulse # pulse-proxy-key",+ "",+ }, "\n")), 0600); err != nil {+ t.Fatalf("write authorized_keys: %v", err)+ }++ cmd := exec.Command("bash", repoFile("scripts", "uninstall-sensor-proxy.sh"), "--uninstall", "--purge", "--quiet")+ cmd.Env = append(os.Environ(),+ "PATH="+binDir+string(os.PathListSeparator)+os.Getenv("PATH"),+ "PULSE_SENSOR_PROXY_BINARY_PATH="+binaryPath,+ "PULSE_SENSOR_PROXY_INSTALL_ROOT="+installRoot,+ "PULSE_SENSOR_PROXY_SERVICE_PATH="+servicePath,+ "PULSE_SENSOR_PROXY_RUNTIME_DIR="+runtimeDir,+ "PULSE_SENSOR_PROXY_SOCKET_PATH="+socketPath,+ "PULSE_SENSOR_PROXY_WORK_DIR="+workDir,+ "PULSE_SENSOR_PROXY_CONFIG_DIR="+configDir,+ "PULSE_SENSOR_PROXY_LOG_DIR="+logDir,+ "PULSE_SENSOR_PROXY_SERVICE_USER=pulse-sensor-proxy-test-user",+ "PULSE_SENSOR_PROXY_AUTHORIZED_KEYS_PATH="+authKeys,+ )+ if out, err := cmd.CombinedOutput(); err != nil {+ t.Fatalf("uninstall-sensor-proxy.sh failed: %v\n%s", err, out)+ }++ for _, path := range []string{binaryPath, installRoot, servicePath, runtimeDir, workDir, configDir, logDir} {+ if _, err := os.Stat(path); !os.IsNotExist(err) {+ t.Fatalf("expected %s to be removed, stat err=%v", path, err)+ }+ }++ content, err := os.ReadFile(authKeys)+ if err != nil {+ t.Fatalf("read authorized_keys: %v", err)+ }+ got := string(content)+ if strings.Contains(got, "pulse-managed-key") || strings.Contains(got, "pulse-proxy-key") {+ t.Fatalf("managed Pulse SSH keys were not removed:\n%s", got)+ }+ if !strings.Contains(got, "AAAAkeep") {+ t.Fatalf("non-Pulse SSH key was not preserved:\n%s", got)+ }+}diff --git a/scripts/release_control/resolve_release_promotion_test.py b/scripts/release_control/resolve_release_promotion_test.pyindex 34eff0139d..545f1b827d 100644--- a/scripts/release_control/resolve_release_promotion_test.py+++ b/scripts/release_control/resolve_release_promotion_test.py@@ -92,8 +92,8 @@ class ResolveReleasePromotionTest(unittest.TestCase):version="6.0.0",promoted_from_tag_input="v6.0.0-rc.6",rollback_version_input="v5.1.34",- ga_date_input="2026-06-03",- v5_eos_date_input="2026-09-01",+ ga_date_input="2026-06-04",+ v5_eos_date_input="2026-09-02",hotfix_exception=False,hotfix_reason_input="",release_notes_input=release_notes,@@ -107,8 +107,8 @@ class ResolveReleasePromotionTest(unittest.TestCase):self.assertEqual(metadata["promoted_from_tag"], "v6.0.0-rc.6")self.assertEqual(metadata["rollback_tag"], "v5.1.34")self.assertEqual(metadata["rollback_command"], "./scripts/install.sh --version v5.1.34")- self.assertEqual(metadata["ga_date"], "2026-06-03")- self.assertEqual(metadata["v5_eos_date"], "2026-09-01")+ self.assertEqual(metadata["ga_date"], "2026-06-04")+ self.assertEqual(metadata["v5_eos_date"], "2026-09-02")def test_stable_hotfix_requires_reason(self) -> None:with self.assertRaisesRegex(ValueError, "hotfix_reason is required"):diff --git a/scripts/uninstall-sensor-proxy.sh b/scripts/uninstall-sensor-proxy.shnew file mode 100755index 0000000000..17556daaed--- /dev/null+++ b/scripts/uninstall-sensor-proxy.sh@@ -0,0 +1,454 @@+#!/usr/bin/env bash+#+# Removes the legacy pulse-sensor-proxy footprint from a Proxmox host.+# Intended for users upgrading from older Pulse releases to the unified agent.++set -euo pipefail++BINARY_PATH="${PULSE_SENSOR_PROXY_BINARY_PATH:-/usr/local/bin/pulse-sensor-proxy}"+INSTALL_ROOT="${PULSE_SENSOR_PROXY_INSTALL_ROOT:-/opt/pulse/sensor-proxy}"+SERVICE_PATH="${PULSE_SENSOR_PROXY_SERVICE_PATH:-/etc/systemd/system/pulse-sensor-proxy.service}"+RUNTIME_DIR="${PULSE_SENSOR_PROXY_RUNTIME_DIR:-/run/pulse-sensor-proxy}"+SOCKET_PATH="${PULSE_SENSOR_PROXY_SOCKET_PATH:-${RUNTIME_DIR}/pulse-sensor-proxy.sock}"+WORK_DIR="${PULSE_SENSOR_PROXY_WORK_DIR:-/var/lib/pulse-sensor-proxy}"+CONFIG_DIR="${PULSE_SENSOR_PROXY_CONFIG_DIR:-/etc/pulse-sensor-proxy}"+LOG_DIR="${PULSE_SENSOR_PROXY_LOG_DIR:-/var/log/pulse/sensor-proxy}"+SERVICE_USER="${PULSE_SENSOR_PROXY_SERVICE_USER:-pulse-sensor-proxy}"+AUTHORIZED_KEYS_PATH="${PULSE_SENSOR_PROXY_AUTHORIZED_KEYS_PATH:-/root/.ssh/authorized_keys}"++QUIET=false+PURGE=false+REMOVE_PROXMOX_ACCESS=false++print_info() {+ if [[ "$QUIET" != "true" ]]; then+ printf '[INFO] %s\n' "$1"+ fi+}++print_warn() {+ printf '[WARN] %s\n' "$1" >&2+}++print_success() {+ if [[ "$QUIET" != "true" ]]; then+ printf '[ OK ] %s\n' "$1"+ fi+}++usage() {+ cat <<'EOF'+Usage: uninstall-sensor-proxy.sh [options]++Removes the legacy pulse-sensor-proxy footprint from a Proxmox host.++Options:+ --uninstall Accepted for compatibility with old instructions.+ --purge Remove persisted proxy state, config, logs, and service user/group.+ --remove-proxmox-access Remove pulse-monitor@pam API tokens/user after cleanup.+ --quiet Reduce informational output.+ --help Show this help text.+EOF+}++resolve_path() {+ local path="$1"+ local resolved=""++ if command -v readlink >/dev/null 2>&1; then+ resolved=$(readlink -f "$path" 2>/dev/null || true)+ if [[ -n "$resolved" ]]; then+ printf '%s\n' "$resolved"+ return 0+ fi+ fi++ if command -v python3 >/dev/null 2>&1; then+ python3 - "$path" <<'PY'+import os+import sys+print(os.path.realpath(sys.argv[1]))+PY+ return 0+ fi++ printf '%s\n' "$path"+}++systemctl_if_available() {+ if ! command -v systemctl >/dev/null 2>&1; then+ return 0+ fi+ systemctl "$@" >/dev/null 2>&1 || true+}++disable_legacy_units() {+ local unit=""+ local units=(+ pulse-sensor-proxy.service+ pulse-sensor-proxy-selfheal.timer+ pulse-sensor-proxy-selfheal.service+ pulse-sensor-cleanup.path+ pulse-sensor-cleanup.service+ )++ for unit in "${units[@]}"; do+ systemctl_if_available stop "$unit"+ systemctl_if_available disable "$unit"+ done+ systemctl_if_available daemon-reload+}++remove_managed_keys_from_authorized_keys_file() {+ local file="$1"+ local tmp_file=""++ if [[ ! -f "$file" ]]; then+ return 0+ fi++ tmp_file=$(mktemp)+ grep -v -E '# pulse-(managed|proxy)-key$' "$file" >"$tmp_file" 2>/dev/null || true+ if cmp -s "$tmp_file" "$file"; then+ rm -f "$tmp_file"+ return 0+ fi++ chmod --reference="$file" "$tmp_file" 2>/dev/null || chmod 600 "$tmp_file" 2>/dev/null || true+ chown --reference="$file" "$tmp_file" 2>/dev/null || true+ mv "$tmp_file" "$file"+}++cleanup_local_authorized_keys() {+ local auth_file=""+ auth_file=$(resolve_path "$AUTHORIZED_KEYS_PATH")+ remove_managed_keys_from_authorized_keys_file "$auth_file"+ print_success "Removed legacy Pulse SSH key entries from ${auth_file}"+}++is_local_host() {+ local target="$1"+ local local_ip=""+ local local_ips=""+ local local_hostnames=""++ local_ips="$(hostname -I 2>/dev/null || true)"+ for local_ip in $local_ips; do+ if [[ "$target" == "$local_ip" ]]; then+ return 0+ fi+ done++ local_hostnames="$(hostname 2>/dev/null || true) $(hostname -f 2>/dev/null || true)"+ case " ${local_hostnames} " in+ *" ${target} "*) return 0 ;;+ esac++ [[ "$target" == "127.0.0.1" || "$target" == "localhost" ]]+}++discover_cluster_node_addresses() {+ local node=""+ local node_ip=""++ if command -v pvesh >/dev/null 2>&1 && command -v python3 >/dev/null 2>&1; then+ while IFS= read -r node; do+ [[ -z "$node" ]] && continue+ node_ip=$(getent ahostsv4 "$node" 2>/dev/null | awk 'NR==1 {print $1}') || true+ if [[ -z "$node_ip" ]]; then+ node_ip=$(getent hosts "$node" 2>/dev/null | awk 'NR==1 {print $1}') || true+ fi+ [[ -n "$node_ip" ]] && printf '%s\n' "$node_ip"+ done < <(+ pvesh get /nodes --output-format json 2>/dev/null | python3 - <<'PY'+import json+import sys+try:+ data = json.load(sys.stdin)+except Exception:+ sys.exit(0)+if isinstance(data, list):+ for item in data:+ node = item.get("node")+ if node:+ print(node)+PY+ )+ return 0+ fi++ if command -v pvecm >/dev/null 2>&1; then+ pvecm status 2>/dev/null | awk '+ /0x[0-9a-f]+/ {+ for (i = 1; i <= NF; i++) {+ if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) print $i+ }+ }+ '+ fi+}++cleanup_remote_authorized_keys() {+ local host="$1"+ local remote_cmd='set -eu+auth="/root/.ssh/authorized_keys"+if [ -f "$auth" ]; then+ sed -i -e "/# pulse-managed-key$/d" -e "/# pulse-proxy-key$/d" "$auth"+fi'++ if ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=5 root@"$host" "$remote_cmd" >/dev/null 2>&1; then+ print_success "Removed legacy Pulse SSH key entries from ${host}"+ return 0+ fi+ print_warn "Unable to remove legacy Pulse SSH key entries from ${host}; clean up /root/.ssh/authorized_keys manually if needed"+ return 1+}++cleanup_cluster_authorized_keys() {+ local host=""+ local saw_nodes=false+ local status=0++ while IFS= read -r host; do+ [[ -z "$host" ]] && continue+ saw_nodes=true+ if is_local_host "$host"; then+ cleanup_local_authorized_keys+ else+ cleanup_remote_authorized_keys "$host" || status=1+ fi+ done < <(discover_cluster_node_addresses | sort -u)++ if [[ "$saw_nodes" != "true" ]]; then+ cleanup_local_authorized_keys+ fi+ return "$status"+}++main_section_snapshot_line() {+ local conf="$1"+ grep -n '^\[' "$conf" 2>/dev/null | head -1 | cut -d: -f1+}++cleanup_sensor_proxy_lines_in_conf() {+ local conf="$1"+ local snapshot_line="${2:-}"+ local tmp_file=""++ tmp_file=$(mktemp)+ if [[ -n "$snapshot_line" && "$snapshot_line" -gt 1 ]]; then+ awk -v snapshot_line="$snapshot_line" '+ NR < snapshot_line && ($0 ~ /^mp[0-9]+:.*pulse-sensor-proxy/ || $0 ~ /^lxc\.mount\.entry:.*pulse-sensor-proxy/) { next }+ { print }+ ' "$conf" >"$tmp_file"+ else+ awk '+ $0 ~ /^mp[0-9]+:.*pulse-sensor-proxy/ { next }+ $0 ~ /^lxc\.mount\.entry:.*pulse-sensor-proxy/ { next }+ { print }+ ' "$conf" >"$tmp_file"+ fi++ chmod --reference="$conf" "$tmp_file" 2>/dev/null || true+ chown --reference="$conf" "$tmp_file" 2>/dev/null || true+ mv "$tmp_file" "$conf"+}++cleanup_stale_sensor_proxy_mounts() {+ local ctid=""+ local conf=""+ local snapshot_line=""+ local status=""+ local was_running=false+ local mp_keys=""+ local mp_key=""+ local cleaned=0++ if ! command -v pct >/dev/null 2>&1; then+ return 0+ fi++ while IFS= read -r ctid; do+ [[ -z "$ctid" ]] && continue+ conf="/etc/pve/lxc/${ctid}.conf"+ [[ -f "$conf" ]] || continue+ grep -q 'pulse-sensor-proxy' "$conf" 2>/dev/null || continue++ print_info "Cleaning stale pulse-sensor-proxy mount entries from container ${ctid}"+ status=$(pct status "$ctid" 2>/dev/null | awk '{print $2}') || true+ was_running=false+ [[ "$status" == "running" ]] && was_running=true++ if [[ "$was_running" == "true" ]]; then+ timeout 30 pct stop "$ctid" >/dev/null 2>&1 || true+ sleep 2+ fi++ snapshot_line=$(main_section_snapshot_line "$conf")+ if [[ -n "$snapshot_line" && "$snapshot_line" -gt 1 ]]; then+ mp_keys=$(head -n "$((snapshot_line - 1))" "$conf" 2>/dev/null | grep -E '^mp[0-9]+:.*pulse-sensor-proxy' | sed 's/:.*//') || true+ else+ mp_keys=$(grep -E '^mp[0-9]+:.*pulse-sensor-proxy' "$conf" 2>/dev/null | sed 's/:.*//') || true+ fi++ while IFS= read -r mp_key; do+ [[ -z "$mp_key" ]] && continue+ timeout 15 pct set "$ctid" -delete "$mp_key" >/dev/null 2>&1 || true+ cleaned=$((cleaned + 1))+ done <<<"$mp_keys"++ cleanup_sensor_proxy_lines_in_conf "$conf" "$snapshot_line"++ if [[ "$was_running" == "true" ]]; then+ timeout 30 pct start "$ctid" >/dev/null 2>&1 || print_warn "Container ${ctid} was running before cleanup but could not be restarted automatically"+ fi+ done < <(pct list 2>/dev/null | tail -n +2 | awk '{print $1}')++ if (( cleaned > 0 )); then+ print_success "Removed legacy pulse-sensor-proxy mount entries from Proxmox LXC config(s)"+ fi+}++remove_path_if_present() {+ local path="$1"+ if [[ -e "$path" || -L "$path" ]]; then+ rm -rf "$path"+ print_success "Removed ${path}"+ fi+}++remove_legacy_files() {+ local path=""+ local files=(+ "$BINARY_PATH"+ /usr/local/bin/pulse-sensor-cleanup.sh+ "${INSTALL_ROOT}/bin/pulse-sensor-proxy"+ "${INSTALL_ROOT}/bin/pulse-sensor-cleanup.sh"+ "${INSTALL_ROOT}/bin/pulse-sensor-proxy-selfheal.sh"+ "${INSTALL_ROOT}/bin/pulse-sensor-wrapper.sh"+ "${INSTALL_ROOT}/install-sensor-proxy.sh"+ "$SERVICE_PATH"+ /etc/systemd/system/pulse-sensor-proxy-selfheal.service+ /etc/systemd/system/pulse-sensor-proxy-selfheal.timer+ /etc/systemd/system/pulse-sensor-cleanup.service+ /etc/systemd/system/pulse-sensor-cleanup.path+ "$SOCKET_PATH"+ "$RUNTIME_DIR"+ )++ for path in "${files[@]}"; do+ remove_path_if_present "$path"+ done++ if [[ "$PURGE" == "true" ]]; then+ remove_path_if_present "$INSTALL_ROOT"+ remove_path_if_present "$WORK_DIR"+ remove_path_if_present "$CONFIG_DIR"+ remove_path_if_present "$LOG_DIR"++ if id -u "$SERVICE_USER" >/dev/null 2>&1; then+ userdel --remove "$SERVICE_USER" >/dev/null 2>&1 || userdel "$SERVICE_USER" >/dev/null 2>&1 || print_warn "Failed to remove service user ${SERVICE_USER}"+ fi+ if getent group "$SERVICE_USER" >/dev/null 2>&1; then+ groupdel "$SERVICE_USER" >/dev/null 2>&1 || print_warn "Failed to remove service group ${SERVICE_USER}"+ fi+ else+ print_info "Preserving ${WORK_DIR}, ${CONFIG_DIR}, and ${LOG_DIR} (use --purge to remove them)"+ fi+}++remove_proxmox_access() {+ local token_ids=""+ local token_id=""++ if [[ "$REMOVE_PROXMOX_ACCESS" != "true" ]]; then+ return 0+ fi+ if ! command -v pveum >/dev/null 2>&1; then+ print_warn "pveum is not available; skipping pulse-monitor@pam cleanup"+ return 0+ fi++ if command -v python3 >/dev/null 2>&1; then+ token_ids=$(pveum user token list pulse-monitor@pam --output-format json 2>/dev/null | python3 - <<'PY'+import json+import sys+try:+ data = json.load(sys.stdin)+except Exception:+ sys.exit(0)+if isinstance(data, list):+ for item in data:+ token_id = item.get("tokenid")+ if token_id:+ print(token_id)+PY+ ) || true+ fi++ if [[ -z "$token_ids" ]]; then+ token_ids=$(pveum user token list pulse-monitor@pam 2>/dev/null | awk '+ {+ line=$0+ gsub(/\r/, "", line)+ gsub(/│/, "|", line)+ if (index(line, "|") == 0) next+ n = split(line, parts, "|")+ if (n < 3) next+ name = parts[2]+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", name)+ if (name != "" && name != "tokenid") print name+ }') || true+ fi++ while IFS= read -r token_id; do+ [[ -z "$token_id" ]] && continue+ pveum user token remove pulse-monitor@pam "$token_id" >/dev/null 2>&1 || print_warn "Failed to remove pulse-monitor@pam token ${token_id}"+ done <<<"$token_ids"++ pveum user delete pulse-monitor@pam >/dev/null 2>&1 || print_warn "pulse-monitor@pam was not removed; it may already be absent or still in use"+}++main() {+ while [[ $# -gt 0 ]]; do+ case "$1" in+ --uninstall)+ shift+ ;;+ --purge)+ PURGE=true+ shift+ ;;+ --remove-proxmox-access)+ REMOVE_PROXMOX_ACCESS=true+ shift+ ;;+ --quiet)+ QUIET=true+ shift+ ;;+ --help|-h)+ usage+ exit 0+ ;;+ *)+ printf 'Unknown option: %s\n' "$1" >&2+ usage >&2+ exit 1+ ;;+ esac+ done++ print_info "Starting legacy pulse-sensor-proxy cleanup"+ disable_legacy_units+ cleanup_cluster_authorized_keys || true+ cleanup_stale_sensor_proxy_mounts+ remove_legacy_files+ remove_proxmox_access+ systemctl_if_available daemon-reload+ print_success "Legacy pulse-sensor-proxy cleanup complete"+}++if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then+ main "$@"+fi