platformforge 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- platformforge/__init__.py +7 -0
- platformforge/__main__.py +5 -0
- platformforge/_forge_portal.py +913 -0
- platformforge/_graphstudio.py +376 -0
- platformforge/_graphview.py +181 -0
- platformforge/_installkit.py +1706 -0
- platformforge/agents/__init__.py +156 -0
- platformforge/agents/bench.py +61 -0
- platformforge/agents/contextpack.py +137 -0
- platformforge/agents/contracts.py +394 -0
- platformforge/agents/coordinators.py +98 -0
- platformforge/agents/critic.py +113 -0
- platformforge/agents/debate.py +161 -0
- platformforge/agents/executors.py +160 -0
- platformforge/agents/guardian.py +48 -0
- platformforge/agents/mirrors.py +240 -0
- platformforge/agents/orchestrator.py +295 -0
- platformforge/agents/planner.py +116 -0
- platformforge/agents/playbook.py +51 -0
- platformforge/agents/referee.py +132 -0
- platformforge/agents/reviewers.py +113 -0
- platformforge/agents/roster.py +893 -0
- platformforge/agents/runledger.py +85 -0
- platformforge/agents/runstore.py +74 -0
- platformforge/agents/specialists.py +73 -0
- platformforge/agents/taskspec.py +94 -0
- platformforge/agents/uniqueness.py +115 -0
- platformforge/agents/verifier.py +106 -0
- platformforge/aiplat/__init__.py +4 -0
- platformforge/aiplat/models.py +175 -0
- platformforge/analytics/__init__.py +6 -0
- platformforge/analytics/capacity.py +109 -0
- platformforge/analytics/debt.py +92 -0
- platformforge/analytics/dx.py +69 -0
- platformforge/analytics/finops_v4.py +171 -0
- platformforge/analytics/goldenpath.py +131 -0
- platformforge/analytics/history.py +233 -0
- platformforge/analytics/measurement.py +149 -0
- platformforge/analytics/models.py +127 -0
- platformforge/analytics/opsanalytics.py +119 -0
- platformforge/analytics/policyintel.py +139 -0
- platformforge/analytics/reliability.py +106 -0
- platformforge/analytics/soak.py +135 -0
- platformforge/analytics/store.py +254 -0
- platformforge/bench.py +174 -0
- platformforge/cases/__init__.py +13 -0
- platformforge/cases/casefile.py +106 -0
- platformforge/cases/context_audit.py +134 -0
- platformforge/cases/ledgers.py +174 -0
- platformforge/cases/replay.py +142 -0
- platformforge/cases/routing_audit.py +162 -0
- platformforge/caveman/__init__.py +11 -0
- platformforge/caveman/compress.py +156 -0
- platformforge/cicd/__init__.py +16 -0
- platformforge/cicd/backstage.py +51 -0
- platformforge/cicd/dockerfile.py +64 -0
- platformforge/cicd/github_actions.py +122 -0
- platformforge/cicd/gitlab_ci.py +56 -0
- platformforge/cicd/gitops.py +130 -0
- platformforge/cli/__init__.py +0 -0
- platformforge/cli/fleetcmd.py +457 -0
- platformforge/cli/main.py +3832 -0
- platformforge/cloud/__init__.py +8 -0
- platformforge/cloud/aws.py +254 -0
- platformforge/cloud/common.py +69 -0
- platformforge/cloud/multicloud.py +143 -0
- platformforge/collect/__init__.py +11 -0
- platformforge/collect/detect.py +254 -0
- platformforge/context/__init__.py +10 -0
- platformforge/context/capsule.py +60 -0
- platformforge/context/gateway.py +227 -0
- platformforge/context/refs.py +49 -0
- platformforge/context/sufficiency.py +50 -0
- platformforge/core/__init__.py +1 -0
- platformforge/core/hashing.py +39 -0
- platformforge/core/ownership.py +220 -0
- platformforge/core/receipts.py +74 -0
- platformforge/core/redaction.py +97 -0
- platformforge/core/store.py +119 -0
- platformforge/core/workspace.py +89 -0
- platformforge/data/contracts/agent-handoff.schema.json +26 -0
- platformforge/data/contracts/agent-run.schema.json +27 -0
- platformforge/data/contracts/agent-spec.schema.json +43 -0
- platformforge/data/contracts/capability.schema.json +23 -0
- platformforge/data/contracts/change-event.schema.json +22 -0
- platformforge/data/contracts/change-intent.schema.json +62 -0
- platformforge/data/contracts/change-plan.schema.json +43 -0
- platformforge/data/contracts/collector-receipt.schema.json +36 -0
- platformforge/data/contracts/context-pack.schema.json +29 -0
- platformforge/data/contracts/debate.schema.json +31 -0
- platformforge/data/contracts/distribution-manifest-v1.schema.json +81 -0
- platformforge/data/contracts/drift-event.schema.json +21 -0
- platformforge/data/contracts/fact.schema.json +35 -0
- platformforge/data/contracts/finding.schema.json +20 -0
- platformforge/data/contracts/graph-v2.schema.json +67 -0
- platformforge/data/contracts/graph.schema.json +40 -0
- platformforge/data/contracts/install-receipt-v1.schema.json +49 -0
- platformforge/data/contracts/observation.schema.json +93 -0
- platformforge/data/contracts/receipt.schema.json +21 -0
- platformforge/data/contracts/recommendation.schema.json +32 -0
- platformforge/data/contracts/refusal.schema.json +16 -0
- platformforge/data/contracts/slo-contract.schema.json +25 -0
- platformforge/data/contracts/task-spec.schema.json +37 -0
- platformforge/data/contracts/workspace-manifest-v1.schema.json +62 -0
- platformforge/data/evals/cases/agent-budget-exhaustion/case.yaml +6 -0
- platformforge/data/evals/cases/agent-conflicting-specialists/case.yaml +11 -0
- platformforge/data/evals/cases/agent-fleet-optimization/case.yaml +13 -0
- platformforge/data/evals/cases/agent-host-no-subagents/case.yaml +6 -0
- platformforge/data/evals/cases/agent-incident-multi/case.yaml +13 -0
- platformforge/data/evals/cases/agent-missing-evidence/case.yaml +6 -0
- platformforge/data/evals/cases/agent-multi-domain-audit/case.yaml +14 -0
- platformforge/data/evals/cases/agent-production-change/case.yaml +15 -0
- platformforge/data/evals/cases/agent-security-mandatory/case.yaml +12 -0
- platformforge/data/evals/cases/agent-simple-iac/case.yaml +14 -0
- platformforge/data/evals/cases/approval-integrity-seal/case.yaml +6 -0
- platformforge/data/evals/cases/capacity-hot/case.yaml +7 -0
- platformforge/data/evals/cases/capacity-hot/fixture/capacity.json +5 -0
- platformforge/data/evals/cases/catalog-noowner/case.yaml +7 -0
- platformforge/data/evals/cases/catalog-noowner/fixture/catalog-info.yaml +6 -0
- platformforge/data/evals/cases/contract-fact/case.yaml +5 -0
- platformforge/data/evals/cases/contract-fact/fixture/doc.json +2 -0
- platformforge/data/evals/cases/cosign-unverified/case.yaml +8 -0
- platformforge/data/evals/cases/cosign-unverified/fixture/sig.json +33 -0
- platformforge/data/evals/cases/expected-delta-refusal/case.yaml +6 -0
- platformforge/data/evals/cases/finops-noattr/case.yaml +9 -0
- platformforge/data/evals/cases/finops-noattr/fixture/costs.json +7 -0
- platformforge/data/evals/cases/fleet-inv-absent-allocation-unknown/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-centrality-not-criticality/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-correlation-not-causality/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-dx-no-person-metrics/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-federation-restricted-denied/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-federation-secret-denied/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-history-window-deterministic/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-low-util-not-deletable/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-member-key-deterministic/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-missing-denominator/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-partial-coverage-visible/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-plan-changeintent-only/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-report-all-cited/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-small-sample-confidence/case.yaml +7 -0
- platformforge/data/evals/cases/fleet-inv-uncertain-optimization-suppressed/case.yaml +7 -0
- platformforge/data/evals/cases/gha-dangerous/case.yaml +12 -0
- platformforge/data/evals/cases/gha-dangerous/fixture/.github/workflows/ci.yaml +11 -0
- platformforge/data/evals/cases/gitops-v2/case.yaml +11 -0
- platformforge/data/evals/cases/gitops-v2/fixture/argo.yaml +41 -0
- platformforge/data/evals/cases/graph-k8s-blast/case.yaml +7 -0
- platformforge/data/evals/cases/graph-k8s-blast/fixture/deploy.yaml +15 -0
- platformforge/data/evals/cases/iac-module-nopin/case.yaml +8 -0
- platformforge/data/evals/cases/iac-module-nopin/fixture/main.tf +3 -0
- platformforge/data/evals/cases/iac-plan-replace/case.yaml +8 -0
- platformforge/data/evals/cases/iac-plan-replace/fixture/plan.json +12 -0
- platformforge/data/evals/cases/iac-sg-open/case.yaml +8 -0
- platformforge/data/evals/cases/iac-sg-open/fixture/main.tf +9 -0
- platformforge/data/evals/cases/iam-oidc/case.yaml +8 -0
- platformforge/data/evals/cases/iam-oidc/fixture/policy.json +11 -0
- platformforge/data/evals/cases/iam-wildcard-positive/case.yaml +8 -0
- platformforge/data/evals/cases/iam-wildcard-positive/fixture/policy.json +3 -0
- platformforge/data/evals/cases/k8s-bad-actor/case.yaml +19 -0
- platformforge/data/evals/cases/k8s-bad-actor/fixture/app.yaml +97 -0
- platformforge/data/evals/cases/k8s-beta-api/case.yaml +8 -0
- platformforge/data/evals/cases/k8s-beta-api/fixture/cr.yaml +7 -0
- platformforge/data/evals/cases/k8s-dep-api-boundary/case.yaml +15 -0
- platformforge/data/evals/cases/k8s-dep-api-boundary/fixture/app.yaml +25 -0
- platformforge/data/evals/cases/k8s-dep-api-clean/case.yaml +12 -0
- platformforge/data/evals/cases/k8s-dep-api-clean/fixture/app.yaml +29 -0
- platformforge/data/evals/cases/k8s-dep-api-unknown/case.yaml +11 -0
- platformforge/data/evals/cases/k8s-dep-api-unknown/fixture/app.yaml +25 -0
- platformforge/data/evals/cases/k8s-dep-api-v120/case.yaml +12 -0
- platformforge/data/evals/cases/k8s-dep-api-v120/fixture/app.yaml +25 -0
- platformforge/data/evals/cases/k8s-dep-api-v129/case.yaml +9 -0
- platformforge/data/evals/cases/k8s-dep-api-v129/fixture/app.yaml +25 -0
- platformforge/data/evals/cases/k8s-hpa-noreq/case.yaml +8 -0
- platformforge/data/evals/cases/k8s-hpa-noreq/fixture/app.yaml +28 -0
- platformforge/data/evals/cases/k8s-limits-boundary/case.yaml +10 -0
- platformforge/data/evals/cases/k8s-limits-boundary/fixture/app.yaml +15 -0
- platformforge/data/evals/cases/k8s-limits-negative/case.yaml +8 -0
- platformforge/data/evals/cases/k8s-limits-negative/fixture/deploy.yaml +15 -0
- platformforge/data/evals/cases/k8s-limits-positive/case.yaml +8 -0
- platformforge/data/evals/cases/k8s-limits-positive/fixture/deploy.yaml +14 -0
- platformforge/data/evals/cases/k8s-nopdb/case.yaml +7 -0
- platformforge/data/evals/cases/k8s-nopdb/fixture/app.yaml +34 -0
- platformforge/data/evals/cases/knowledge-registry/case.yaml +10 -0
- platformforge/data/evals/cases/kyverno-dep/case.yaml +10 -0
- platformforge/data/evals/cases/kyverno-dep/fixture/pol.yaml +18 -0
- platformforge/data/evals/cases/kyverno-legacy/case.yaml +8 -0
- platformforge/data/evals/cases/kyverno-legacy/fixture/pol.yaml +7 -0
- platformforge/data/evals/cases/live-aws-collect/case.yaml +11 -0
- platformforge/data/evals/cases/live-aws-collect/fixture/aws/ec2_describe-vpcs.json +15 -0
- platformforge/data/evals/cases/live-aws-collect/fixture/aws/iam_list-users.denied.txt +1 -0
- platformforge/data/evals/cases/live-aws-collect/fixture/aws/sts_get-caller-identity.json +5 -0
- platformforge/data/evals/cases/live-drift/case.yaml +8 -0
- platformforge/data/evals/cases/live-drift/fixture/after.json +22 -0
- platformforge/data/evals/cases/live-drift/fixture/before.json +22 -0
- platformforge/data/evals/cases/live-incident/case.yaml +7 -0
- platformforge/data/evals/cases/live-incident/fixture/changes.json +8 -0
- platformforge/data/evals/cases/live-incident/fixture/incident.json +7 -0
- platformforge/data/evals/cases/live-k8s-collect/case.yaml +10 -0
- platformforge/data/evals/cases/live-k8s-collect/fixture/kubectl/get_configmaps.denied.txt +1 -0
- platformforge/data/evals/cases/live-k8s-collect/fixture/kubectl/get_deployments.apps.json +25 -0
- platformforge/data/evals/cases/live-k8s-collect/fixture/kubectl/get_pods.json +17 -0
- platformforge/data/evals/cases/live-k8s-collect/fixture/kubectl/get_secrets.json +13 -0
- platformforge/data/evals/cases/live-multicluster/case.yaml +7 -0
- platformforge/data/evals/cases/live-multicluster/fixture/clusters.json +6 -0
- platformforge/data/evals/cases/live-plan/case.yaml +7 -0
- platformforge/data/evals/cases/live-plan/fixture/drift.json +8 -0
- platformforge/data/evals/cases/live-reconcile/case.yaml +7 -0
- platformforge/data/evals/cases/live-reconcile/fixture/desired.json +7 -0
- platformforge/data/evals/cases/live-reconcile/fixture/observed.json +18 -0
- platformforge/data/evals/cases/live-secrets-boundary/case.yaml +8 -0
- platformforge/data/evals/cases/live-secrets-boundary/fixture/envelope.json +16 -0
- platformforge/data/evals/cases/live-temporal-graph/case.yaml +10 -0
- platformforge/data/evals/cases/live-temporal-graph/fixture/graph.json +22 -0
- platformforge/data/evals/cases/ops-approval/case.yaml +6 -0
- platformforge/data/evals/cases/ops-convergence/case.yaml +6 -0
- platformforge/data/evals/cases/ops-execution-safety/case.yaml +6 -0
- platformforge/data/evals/cases/ops-intent/case.yaml +6 -0
- platformforge/data/evals/cases/ops-planning/case.yaml +6 -0
- platformforge/data/evals/cases/ops-policy/case.yaml +6 -0
- platformforge/data/evals/cases/ops-rollback/case.yaml +6 -0
- platformforge/data/evals/cases/ops-verification/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-argocd-revision/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-blind-inverse/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-git-commit/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-impossible/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-k8s-annotation-restore/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-k8s-scale/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-material-tamper/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-terraform-replan/case.yaml +6 -0
- platformforge/data/evals/cases/rollback-unknown/case.yaml +6 -0
- platformforge/data/evals/cases/routing-specialist/case.yaml +9 -0
- platformforge/data/evals/cases/rtk-roundtrip/case.yaml +5 -0
- platformforge/data/evals/cases/rtk-roundtrip/fixture/verbose.txt +300 -0
- platformforge/data/evals/cases/sbom-vuln/case.yaml +9 -0
- platformforge/data/evals/cases/sbom-vuln/fixture/sbom.json +9 -0
- platformforge/data/evals/cases/secret-prose-mixed/fixture/app.env +1 -0
- platformforge/data/evals/cases/secret-prose-mixed/fixture/policy-notes.md +7 -0
- platformforge/data/evals/cases/secrets-noleak/case.yaml +5 -0
- platformforge/data/evals/cases/secrets-noleak/fixture/app.env +2 -0
- platformforge/data/evals/cases/slo-fastburn/case.yaml +8 -0
- platformforge/data/evals/cases/slo-fastburn/fixture/events.yaml +2 -0
- platformforge/data/evals/cases/slo-fastburn/fixture/slo.yaml +4 -0
- platformforge/data/evals/cases/slo-noinput/case.yaml +8 -0
- platformforge/data/evals/cases/slo-noinput/fixture/events.yaml +1 -0
- platformforge/data/evals/cases/slo-noinput/fixture/slo.yaml +4 -0
- platformforge/data/evals/cases/sot-conflict/case.yaml +6 -0
- platformforge/data/evals/cases/token-budget/case.yaml +6 -0
- platformforge/data/evals/cases/token-budget/fixture/big.py +50 -0
- platformforge/data/evals/cases/xr-delete/case.yaml +8 -0
- platformforge/data/evals/cases/xr-delete/fixture/xr.yaml +10 -0
- platformforge/data/evals/cases/xr-graph-chain/case.yaml +8 -0
- platformforge/data/evals/cases/xr-graph-chain/fixture/xrd.yaml +90 -0
- platformforge/data/evals/cases/xr-negative-crd/case.yaml +8 -0
- platformforge/data/evals/cases/xr-negative-crd/fixture/widget.yaml +19 -0
- platformforge/data/evals/cases/xr-upbound-mr/case.yaml +8 -0
- platformforge/data/evals/cases/xr-upbound-mr/fixture/bucket.yaml +12 -0
- platformforge/data/evals/qpt-bench/change-review/case.yaml +5 -0
- platformforge/data/evals/qpt-bench/change-review/fixture/plan.json +9 -0
- platformforge/data/evals/qpt-bench/gha-security/case.yaml +5 -0
- platformforge/data/evals/qpt-bench/gha-security/fixture/ci.yml +10 -0
- platformforge/data/evals/qpt-bench/iam-investigate/case.yaml +5 -0
- platformforge/data/evals/qpt-bench/iam-investigate/fixture/policy.json +6 -0
- platformforge/data/evals/qpt-bench/incident-analysis/case.yaml +5 -0
- platformforge/data/evals/qpt-bench/incident-analysis/fixture/query.json +5 -0
- platformforge/data/evals/qpt-bench/incident-analysis/fixture/rules.yaml +6 -0
- platformforge/data/evals/qpt-bench/k8s-review/case.yaml +6 -0
- platformforge/data/evals/qpt-bench/k8s-review/fixture/deploy.yaml +15 -0
- platformforge/data/evals/qpt-bench/tf-security/case.yaml +5 -0
- platformforge/data/evals/qpt-bench/tf-security/fixture/main.tf +17 -0
- platformforge/data/knowledge/aws/eks.yaml +20 -0
- platformforge/data/knowledge/aws/iam.yaml +28 -0
- platformforge/data/knowledge/aws/network-exposure.yaml +19 -0
- platformforge/data/knowledge/aws/organizations.yaml +19 -0
- platformforge/data/knowledge/crossplane/composition-providers.yaml +20 -0
- platformforge/data/knowledge/crossplane/managed-resources.yaml +26 -0
- platformforge/data/knowledge/crossplane/v1-v2.yaml +25 -0
- platformforge/data/knowledge/kubernetes/api-deprecations.yaml +33 -0
- platformforge/data/knowledge/kubernetes/autoscaling-rbac.yaml +27 -0
- platformforge/data/knowledge/kubernetes/gateway-api.yaml +20 -0
- platformforge/data/knowledge/kubernetes/pod-security.yaml +26 -0
- platformforge/data/knowledge/sources.yaml +516 -0
- platformforge/data/knowledge/terraform/lifecycle.yaml +18 -0
- platformforge/data/knowledge/terraform/plan-semantics.yaml +26 -0
- platformforge/data/lab/chaos-pod-kill/chaos.yaml +3 -0
- platformforge/data/lab/chaos-pod-kill/facts.json +13 -0
- platformforge/data/lab/fleets/acme/capacity.yaml +35 -0
- platformforge/data/lab/fleets/acme/costs.yaml +25 -0
- platformforge/data/lab/fleets/acme/events.yaml +41 -0
- platformforge/data/lab/fleets/acme/fleet.yaml +51 -0
- platformforge/data/lab/fleets/acme/graph.yaml +45 -0
- platformforge/data/lab/fleets/acme/policies.yaml +28 -0
- platformforge/data/lab/fleets/acme/requests.yaml +24 -0
- platformforge/data/lab/scenarios/argo-bad-rollout/expected.yaml +6 -0
- platformforge/data/lab/scenarios/argo-bad-rollout/fixture/app.yaml +9 -0
- platformforge/data/lab/scenarios/aws-dump/expected.yaml +19 -0
- platformforge/data/lab/scenarios/aws-dump/fixture/compute.json +4 -0
- platformforge/data/lab/scenarios/aws-dump/fixture/iam.json +7 -0
- platformforge/data/lab/scenarios/aws-dump/fixture/network.json +6 -0
- platformforge/data/lab/scenarios/aws-dump/fixture/org.json +4 -0
- platformforge/data/lab/scenarios/aws-dump/fixture/storage.json +4 -0
- platformforge/data/lab/scenarios/container-unsigned/expected.yaml +5 -0
- platformforge/data/lab/scenarios/container-unsigned/fixture/supply.json +11 -0
- platformforge/data/lab/scenarios/cost-idle-workload/expected.yaml +5 -0
- platformforge/data/lab/scenarios/cost-idle-workload/fixture/costs.json +12 -0
- platformforge/data/lab/scenarios/crossplane-platform/expected.yaml +16 -0
- platformforge/data/lab/scenarios/crossplane-platform/fixture/negative.yaml +18 -0
- platformforge/data/lab/scenarios/crossplane-platform/fixture/xrd.yaml +90 -0
- platformforge/data/lab/scenarios/demo-platform/expected.yaml +16 -0
- platformforge/data/lab/scenarios/demo-platform/fixture/.github/workflows/ci.yml +10 -0
- platformforge/data/lab/scenarios/demo-platform/fixture/deploy.yaml +16 -0
- platformforge/data/lab/scenarios/demo-platform/fixture/infra.tf +5 -0
- platformforge/data/lab/scenarios/fleet-ai/expected.yaml +12 -0
- platformforge/data/lab/scenarios/fleet-capacity/expected.yaml +12 -0
- platformforge/data/lab/scenarios/fleet-cost/expected.yaml +18 -0
- platformforge/data/lab/scenarios/fleet-federation/expected.yaml +11 -0
- platformforge/data/lab/scenarios/fleet-golden-path/expected.yaml +18 -0
- platformforge/data/lab/scenarios/fleet-op-hotspot/expected.yaml +11 -0
- platformforge/data/lab/scenarios/fleet-ownership/expected.yaml +17 -0
- platformforge/data/lab/scenarios/fleet-partial/expected.yaml +10 -0
- platformforge/data/lab/scenarios/fleet-policy-friction/expected.yaml +10 -0
- platformforge/data/lab/scenarios/fleet-recurring-incident/expected.yaml +12 -0
- platformforge/data/lab/scenarios/fleet-report/expected.yaml +13 -0
- platformforge/data/lab/scenarios/fleet-risk/expected.yaml +18 -0
- platformforge/data/lab/scenarios/gitops-drift/expected.yaml +6 -0
- platformforge/data/lab/scenarios/gitops-drift/fixture/app.yaml +12 -0
- platformforge/data/lab/scenarios/k8s-bad-readiness/expected.yaml +6 -0
- platformforge/data/lab/scenarios/k8s-bad-readiness/fixture/deploy.yaml +23 -0
- platformforge/data/lab/scenarios/k8s-bad-readiness/fixture/netpol.yaml +9 -0
- platformforge/data/lab/scenarios/k8s-missing-limits/expected.yaml +6 -0
- platformforge/data/lab/scenarios/k8s-missing-limits/fixture/deploy.yaml +26 -0
- platformforge/data/lab/scenarios/k8s-missing-limits/fixture/netpol.yaml +9 -0
- platformforge/data/lab/scenarios/k8s-single-replica/expected.yaml +5 -0
- platformforge/data/lab/scenarios/k8s-single-replica/fixture/deploy.yaml +26 -0
- platformforge/data/lab/scenarios/k8s-single-replica/fixture/netpol.yaml +4 -0
- platformforge/data/lab/scenarios/live-aws-collect/expected.yaml +4 -0
- platformforge/data/lab/scenarios/live-aws-collect/fixture/aws/ec2_describe-vpcs.json +15 -0
- platformforge/data/lab/scenarios/live-aws-collect/fixture/aws/iam_list-users.denied.txt +1 -0
- platformforge/data/lab/scenarios/live-aws-collect/fixture/aws/sts_get-caller-identity.json +5 -0
- platformforge/data/lab/scenarios/live-k8s-collect/expected.yaml +4 -0
- platformforge/data/lab/scenarios/live-k8s-collect/fixture/kubectl/get_configmaps.denied.txt +1 -0
- platformforge/data/lab/scenarios/live-k8s-collect/fixture/kubectl/get_deployments.apps.json +25 -0
- platformforge/data/lab/scenarios/live-k8s-collect/fixture/kubectl/get_pods.json +17 -0
- platformforge/data/lab/scenarios/live-k8s-collect/fixture/kubectl/get_secrets.json +13 -0
- platformforge/data/lab/scenarios/live-kind/expected.yaml +14 -0
- platformforge/data/lab/scenarios/live-kind/fixture/kubectl/get_configmaps.denied.txt +1 -0
- platformforge/data/lab/scenarios/live-kind/fixture/kubectl/get_deployments.apps.json +25 -0
- platformforge/data/lab/scenarios/live-kind/fixture/kubectl/get_pods.json +17 -0
- platformforge/data/lab/scenarios/live-kind/fixture/kubectl/get_secrets.json +13 -0
- platformforge/data/lab/scenarios/network-policy-missing/expected.yaml +6 -0
- platformforge/data/lab/scenarios/network-policy-missing/fixture/deploy.yaml +26 -0
- platformforge/data/lab/scenarios/ops-bad-rollout/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-bad-rollout/fixture/ops.yaml +33 -0
- platformforge/data/lab/scenarios/ops-break-glass/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-break-glass/fixture/ops.yaml +21 -0
- platformforge/data/lab/scenarios/ops-broken-selector/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-broken-selector/fixture/ops.yaml +21 -0
- platformforge/data/lab/scenarios/ops-changed-plan-hash/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-changed-plan-hash/fixture/ops.yaml +20 -0
- platformforge/data/lab/scenarios/ops-conflicting-operation/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-conflicting-operation/fixture/ops.yaml +21 -0
- platformforge/data/lab/scenarios/ops-expired-approval/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-expired-approval/fixture/ops.yaml +20 -0
- platformforge/data/lab/scenarios/ops-partial-failure/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-partial-failure/fixture/ops.yaml +24 -0
- platformforge/data/lab/scenarios/ops-policy-denial/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-policy-denial/fixture/ops.yaml +17 -0
- platformforge/data/lab/scenarios/ops-replica-drift/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-replica-drift/fixture/ops.yaml +28 -0
- platformforge/data/lab/scenarios/ops-rollback-annotate/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-rollback-annotate/fixture/ops.yaml +41 -0
- platformforge/data/lab/scenarios/ops-rollback-gitops/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-rollback-gitops/fixture/ops.yaml +38 -0
- platformforge/data/lab/scenarios/ops-rollback-impossible/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-rollback-impossible/fixture/ops.yaml +34 -0
- platformforge/data/lab/scenarios/ops-rollback-scale/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-rollback-scale/fixture/ops.yaml +40 -0
- platformforge/data/lab/scenarios/ops-rollback-terraform/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-rollback-terraform/fixture/ops.yaml +38 -0
- platformforge/data/lab/scenarios/ops-rollback-terraform/fixture/tf/tfplan.bin +1 -0
- platformforge/data/lab/scenarios/ops-stale-observation/expected.yaml +3 -0
- platformforge/data/lab/scenarios/ops-stale-observation/fixture/ops.yaml +20 -0
- platformforge/data/lab/scenarios/secret-exposure/expected.yaml +5 -0
- platformforge/data/lab/scenarios/secret-exposure/fixture/app.env +2 -0
- platformforge/data/lab/scenarios/slo-burn/expected.yaml +5 -0
- platformforge/data/lab/scenarios/slo-burn/fixture/events.yaml +2 -0
- platformforge/data/lab/scenarios/slo-burn/fixture/slo.yaml +4 -0
- platformforge/data/lab/scenarios/terraform-iam-wildcard/expected.yaml +5 -0
- platformforge/data/lab/scenarios/terraform-iam-wildcard/fixture/policy.json +14 -0
- platformforge/data/lab/scenarios/terraform-public-bucket/expected.yaml +6 -0
- platformforge/data/lab/scenarios/terraform-public-bucket/fixture/main.tf +5 -0
- platformforge/data/portable_skills/platformforge-agents/SKILL.md +47 -0
- platformforge/data/portable_skills/platformforge-change/SKILL.md +41 -0
- platformforge/data/portable_skills/platformforge-core/SKILL.md +62 -0
- platformforge/data/portable_skills/platformforge-economy/SKILL.md +42 -0
- platformforge/data/portable_skills/platformforge-finops/SKILL.md +34 -0
- platformforge/data/portable_skills/platformforge-fleet/SKILL.md +39 -0
- platformforge/data/portable_skills/platformforge-governance/SKILL.md +76 -0
- platformforge/data/portable_skills/platformforge-graph/SKILL.md +46 -0
- platformforge/data/portable_skills/platformforge-lab/SKILL.md +39 -0
- platformforge/data/portable_skills/platformforge-sdd/SKILL.md +39 -0
- platformforge/data/portable_skills/platformforge-security/SKILL.md +38 -0
- platformforge/data/portable_skills/platformforge-sre/SKILL.md +41 -0
- platformforge/data/rules/catalog/finops.yaml +26 -0
- platformforge/data/rules/catalog/gitops.yaml +161 -0
- platformforge/data/rules/catalog/iac.yaml +84 -0
- platformforge/data/rules/catalog/k8s.yaml +322 -0
- platformforge/data/rules/catalog/orchestration.yaml +99 -0
- platformforge/data/rules/catalog/product.yaml +42 -0
- platformforge/data/rules/catalog/routing.yaml +122 -0
- platformforge/data/rules/catalog/security.yaml +159 -0
- platformforge/data/rules/catalog/sre.yaml +67 -0
- platformforge/diagnose/__init__.py +75 -0
- platformforge/distribution/__init__.py +18 -0
- platformforge/distribution/bundle.py +127 -0
- platformforge/distribution/hostflow.py +247 -0
- platformforge/distribution/models.py +80 -0
- platformforge/distribution/service.py +225 -0
- platformforge/economy/__init__.py +27 -0
- platformforge/economy/bench.py +66 -0
- platformforge/economy/budget.py +198 -0
- platformforge/economy/cache.py +287 -0
- platformforge/economy/checkpoint.py +112 -0
- platformforge/economy/collection.py +142 -0
- platformforge/economy/doctor.py +207 -0
- platformforge/economy/engine.py +158 -0
- platformforge/economy/envelope.py +61 -0
- platformforge/economy/fleetpack.py +86 -0
- platformforge/economy/ledger.py +232 -0
- platformforge/economy/plan.py +131 -0
- platformforge/economy/pricing.py +101 -0
- platformforge/economy/qpt.py +286 -0
- platformforge/economy/reconcile.py +86 -0
- platformforge/economy/verifyplan.py +107 -0
- platformforge/economy/waste.py +123 -0
- platformforge/evals/__init__.py +16 -0
- platformforge/evals/coverage.py +140 -0
- platformforge/evals/fleet_invariants.py +260 -0
- platformforge/evals/ops_invariants.py +158 -0
- platformforge/evals/runner.py +541 -0
- platformforge/federation/__init__.py +4 -0
- platformforge/federation/node.py +135 -0
- platformforge/finops/__init__.py +14 -0
- platformforge/finops/alloc.py +31 -0
- platformforge/finops/costs.py +79 -0
- platformforge/finops/focus.py +100 -0
- platformforge/finops/graph_cost.py +51 -0
- platformforge/finops/ingest.py +144 -0
- platformforge/finops/insights.py +193 -0
- platformforge/finops/unit.py +36 -0
- platformforge/fleet/__init__.py +5 -0
- platformforge/fleet/loader.py +73 -0
- platformforge/fleet/models.py +155 -0
- platformforge/fleet/orggraph.py +172 -0
- platformforge/fleet/query.py +154 -0
- platformforge/forge/__init__.py +9 -0
- platformforge/forge/collect.py +88 -0
- platformforge/forge/delegate.py +77 -0
- platformforge/forge/manifest.py +106 -0
- platformforge/freeze/__init__.py +22 -0
- platformforge/freeze/exceptions.py +56 -0
- platformforge/freeze/manifest.py +167 -0
- platformforge/freeze/snapshots.py +108 -0
- platformforge/graph/__init__.py +39 -0
- platformforge/graph/backend.py +174 -0
- platformforge/graph/bench.py +245 -0
- platformforge/graph/build.py +130 -0
- platformforge/graph/delivery.py +183 -0
- platformforge/graph/diff.py +292 -0
- platformforge/graph/events.py +116 -0
- platformforge/graph/migrate.py +44 -0
- platformforge/graph/model.py +264 -0
- platformforge/graph/persist.py +97 -0
- platformforge/graph/query.py +290 -0
- platformforge/graph/temporal.py +78 -0
- platformforge/graph/vocab.py +63 -0
- platformforge/graphview.py +94 -0
- platformforge/iac/__init__.py +7 -0
- platformforge/iac/drift.py +53 -0
- platformforge/iac/plan.py +84 -0
- platformforge/iac/terraform.py +123 -0
- platformforge/install/__init__.py +1 -0
- platformforge/install/service.py +421 -0
- platformforge/k8s/__init__.py +8 -0
- platformforge/k8s/helm.py +152 -0
- platformforge/k8s/hubble.py +87 -0
- platformforge/k8s/manifests.py +513 -0
- platformforge/knowledge/__init__.py +1 -0
- platformforge/knowledge/packs.py +157 -0
- platformforge/knowledge/registry.py +249 -0
- platformforge/knowledge/select.py +127 -0
- platformforge/lab/__init__.py +5 -0
- platformforge/lab/chaos.py +71 -0
- platformforge/lab/fleetlab.py +351 -0
- platformforge/lab/opslab.py +271 -0
- platformforge/lab/runner.py +219 -0
- platformforge/live/__init__.py +36 -0
- platformforge/live/budget.py +92 -0
- platformforge/live/capability.py +80 -0
- platformforge/live/collectors/__init__.py +6 -0
- platformforge/live/collectors/aws.py +370 -0
- platformforge/live/collectors/aws_transport.py +98 -0
- platformforge/live/collectors/k8s.py +389 -0
- platformforge/live/collectors/k8s_transport.py +85 -0
- platformforge/live/cursors.py +48 -0
- platformforge/live/drift.py +130 -0
- platformforge/live/envelope.py +85 -0
- platformforge/live/federation.py +113 -0
- platformforge/live/fixtures.py +168 -0
- platformforge/live/identity.py +258 -0
- platformforge/live/incident.py +200 -0
- platformforge/live/models.py +435 -0
- platformforge/live/reconcile.py +382 -0
- platformforge/live/remediate.py +169 -0
- platformforge/live/store.py +256 -0
- platformforge/live/topology.py +249 -0
- platformforge/mcp/__init__.py +7 -0
- platformforge/mcp/parity.py +69 -0
- platformforge/mcp/registry.py +427 -0
- platformforge/mcp/server.py +84 -0
- platformforge/mcp/tools.py +732 -0
- platformforge/models/__init__.py +21 -0
- platformforge/models/base.py +214 -0
- platformforge/observe/__init__.py +26 -0
- platformforge/observe/capacity.py +39 -0
- platformforge/observe/dr.py +67 -0
- platformforge/observe/grafana.py +76 -0
- platformforge/observe/incident.py +58 -0
- platformforge/observe/otel.py +135 -0
- platformforge/observe/postmortem.py +72 -0
- platformforge/observe/prometheus.py +88 -0
- platformforge/observe/slo.py +125 -0
- platformforge/ops/__init__.py +8 -0
- platformforge/ops/actions.py +215 -0
- platformforge/ops/analytics.py +83 -0
- platformforge/ops/approval.py +275 -0
- platformforge/ops/autorem.py +101 -0
- platformforge/ops/config.py +175 -0
- platformforge/ops/engine.py +758 -0
- platformforge/ops/envelope.py +135 -0
- platformforge/ops/executors/__init__.py +1 -0
- platformforge/ops/executors/base.py +211 -0
- platformforge/ops/executors/git.py +77 -0
- platformforge/ops/executors/gitops.py +134 -0
- platformforge/ops/executors/terraform.py +84 -0
- platformforge/ops/gates.py +135 -0
- platformforge/ops/goldenpath.py +180 -0
- platformforge/ops/material.py +181 -0
- platformforge/ops/models.py +421 -0
- platformforge/ops/operation.py +335 -0
- platformforge/ops/opgraph.py +233 -0
- platformforge/ops/policy.py +275 -0
- platformforge/ops/preconditions.py +109 -0
- platformforge/ops/registry.py +101 -0
- platformforge/ops/risk.py +216 -0
- platformforge/ops/rollback.py +287 -0
- platformforge/ops/rollback_builders.py +163 -0
- platformforge/ops/runbook.py +269 -0
- platformforge/ops/simulate.py +125 -0
- platformforge/ops/source_of_truth.py +198 -0
- platformforge/ops/store.py +157 -0
- platformforge/ops/verify.py +190 -0
- platformforge/optimize/__init__.py +4 -0
- platformforge/optimize/engine.py +109 -0
- platformforge/optimize/models.py +68 -0
- platformforge/optimize/scan.py +196 -0
- platformforge/plan/__init__.py +107 -0
- platformforge/portable_cli.py +199 -0
- platformforge/portal_adapter.py +740 -0
- platformforge/portal_assets/chunk-7_l-b4Tr.js +1 -0
- platformforge/portal_assets/chunk-B0Iad6pD.js +1 -0
- platformforge/portal_assets/chunk-B605XnCF.js +1 -0
- platformforge/portal_assets/chunk-B7N3TXcn.js +1 -0
- platformforge/portal_assets/chunk-BAj6yGem.js +1 -0
- platformforge/portal_assets/chunk-BGUitn2r.js +1 -0
- platformforge/portal_assets/chunk-BVKnCv85.js +1 -0
- platformforge/portal_assets/chunk-BYyM9V_w.js +1 -0
- platformforge/portal_assets/chunk-BaQMhq-G.js +1 -0
- platformforge/portal_assets/chunk-BavOrxVm.js +1 -0
- platformforge/portal_assets/chunk-Bb0C24YV.js +1 -0
- platformforge/portal_assets/chunk-BfCFGPzs.js +1 -0
- platformforge/portal_assets/chunk-C2t4OUVu.js +1 -0
- platformforge/portal_assets/chunk-C3pI4QjU.js +1 -0
- platformforge/portal_assets/chunk-C4gpbtbP.js +1 -0
- platformforge/portal_assets/chunk-CGWeHhKY.js +1 -0
- platformforge/portal_assets/chunk-CJCT86Dr.js +1 -0
- platformforge/portal_assets/chunk-CXcsLDPJ.js +1 -0
- platformforge/portal_assets/chunk-CcjxoLxw.js +1 -0
- platformforge/portal_assets/chunk-D-gBPXHa.js +1 -0
- platformforge/portal_assets/chunk-D3eZogIe.js +1 -0
- platformforge/portal_assets/chunk-DQU0VyoQ.js +1 -0
- platformforge/portal_assets/chunk-DqWNkF1O.js +1 -0
- platformforge/portal_assets/chunk-DuPPkSIE.js +3 -0
- platformforge/portal_assets/chunk-DyIHOW_a.js +1 -0
- platformforge/portal_assets/chunk-Fx4zSGL5.js +1 -0
- platformforge/portal_assets/chunk-UBKt05Rg.js +1 -0
- platformforge/portal_assets/chunk-htnJDQEY.js +1 -0
- platformforge/portal_assets/chunk-kXRFMGqe.js +1 -0
- platformforge/portal_assets/chunk-qe3u763a.js +1 -0
- platformforge/portal_assets/favicon.ico +0 -0
- platformforge/portal_assets/index.html +13 -0
- platformforge/portal_assets/main-QDFVZK3T.js +5 -0
- platformforge/portal_assets/styles-MQEBDFDX.css +1 -0
- platformforge/product/__init__.py +10 -0
- platformforge/product/backstage.py +49 -0
- platformforge/product/catalog.py +74 -0
- platformforge/product/crossplane.py +341 -0
- platformforge/product/golden_paths/__init__.py +5 -0
- platformforge/product/golden_paths/engine.py +97 -0
- platformforge/product/golden_paths/library.yaml +198 -0
- platformforge/product/golden_paths/model.py +84 -0
- platformforge/product/maturity.py +107 -0
- platformforge/product/scorecards.py +84 -0
- platformforge/resources.py +36 -0
- platformforge/risk/__init__.py +5 -0
- platformforge/risk/engine.py +95 -0
- platformforge/risk/signals.py +49 -0
- platformforge/routing/__init__.py +13 -0
- platformforge/routing/decision.py +191 -0
- platformforge/routing/router.py +328 -0
- platformforge/rtk/__init__.py +9 -0
- platformforge/rtk/compact.py +127 -0
- platformforge/rtk/parsers.py +199 -0
- platformforge/rules/__init__.py +5 -0
- platformforge/rules/engine.py +345 -0
- platformforge/sandbox/__init__.py +7 -0
- platformforge/sandbox/env.py +151 -0
- platformforge/sandbox/review.py +92 -0
- platformforge/sdd/__init__.py +8 -0
- platformforge/sdd/lifecycle.py +239 -0
- platformforge/security/__init__.py +19 -0
- platformforge/security/cosign.py +67 -0
- platformforge/security/iam.py +112 -0
- platformforge/security/identity.py +84 -0
- platformforge/security/kyverno.py +106 -0
- platformforge/security/sbom.py +59 -0
- platformforge/security/scan.py +63 -0
- platformforge/security/slsa.py +86 -0
- platformforge/security/supply.py +62 -0
- platformforge/tokensave/__init__.py +20 -0
- platformforge/tokensave/budget.py +62 -0
- platformforge/tokensave/estimate.py +21 -0
- platformforge/tokensave/index.py +172 -0
- platformforge/tokensave/ledger.py +121 -0
- platformforge/tokensave/packs.py +285 -0
- platformforge/ui/__init__.py +28 -0
- platformforge/ui/app.py +465 -0
- platformforge/ui/home.py +113 -0
- platformforge/ui/i18n.py +143 -0
- platformforge/ui/kit.py +689 -0
- platformforge/ui/screen.py +628 -0
- platformforge/ui/tui.py +94 -0
- platformforge/ui/wizard.py +309 -0
- platformforge/workspace/__init__.py +13 -0
- platformforge/workspace/models.py +35 -0
- platformforge/workspace/service.py +69 -0
- platformforge-0.1.0.dist-info/METADATA +212 -0
- platformforge-0.1.0.dist-info/RECORD +659 -0
- platformforge-0.1.0.dist-info/WHEEL +4 -0
- platformforge-0.1.0.dist-info/entry_points.txt +3 -0
- platformforge-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Incident intelligence V3 (cycle §160–§176).
|
|
2
|
+
|
|
3
|
+
Canonical timeline joins: git change, CI build, artifact, deployment,
|
|
4
|
+
CloudTrail change, k8s event, runtime anomaly, alert, incident — every
|
|
5
|
+
event normalized to {timestamp, source, scope, resources, actor, facts,
|
|
6
|
+
confidence, kind}.
|
|
7
|
+
|
|
8
|
+
Candidate scoring is deterministic and factorized — every hypothesis
|
|
9
|
+
explains WHERE its rank came from (§170). Status vocabulary is closed:
|
|
10
|
+
confirmed needs causal evidence — correlation alone is never enough;
|
|
11
|
+
`root_cause: unresolved` is a valid, honest outcome (§174).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from platformforge.live.models import parse_ts
|
|
19
|
+
|
|
20
|
+
EVENT_SOURCES = ("git_change", "ci_build", "artifact", "deployment",
|
|
21
|
+
"cloudtrail", "k8s_event", "runtime_anomaly", "alert",
|
|
22
|
+
"incident", "manual")
|
|
23
|
+
|
|
24
|
+
# §170 — fixed factor weights; every candidate's score is reproducible
|
|
25
|
+
# and explainable from this table.
|
|
26
|
+
WEIGHTS = {"temporal": 0.25, "graph_distance": 0.15,
|
|
27
|
+
"blast_radius": 0.10, "scope_overlap": 0.10,
|
|
28
|
+
"change_type": 0.10, "freshness": 0.10,
|
|
29
|
+
"evidence_tier": 0.10, "runtime_correlation": 0.10}
|
|
30
|
+
|
|
31
|
+
MUTATING_ACTION_HINTS = ("create", "update", "put", "delete", "apply",
|
|
32
|
+
"deploy", "scale", "patch", "modify",
|
|
33
|
+
"attach", "detach")
|
|
34
|
+
|
|
35
|
+
HYPOTHESIS_STATUSES = ("confirmed", "supported", "candidate",
|
|
36
|
+
"contradicted", "unknown")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _ts(e: dict[str, Any]) -> float:
|
|
40
|
+
v = e.get("timestamp") or e.get("at") or e.get("ts") or ""
|
|
41
|
+
t = parse_ts(str(v))
|
|
42
|
+
return t.timestamp() if t else float(v) if str(v).replace(
|
|
43
|
+
".", "", 1).isdigit() else 0.0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def normalize_event(raw: dict[str, Any]) -> dict[str, Any]:
|
|
47
|
+
"""Any event source → canonical timeline event; scoring-relevant
|
|
48
|
+
extras (blast_radius, runtime_correlated, …) pass through."""
|
|
49
|
+
e = dict(raw)
|
|
50
|
+
e.update({
|
|
51
|
+
"timestamp": raw.get("timestamp") or raw.get("at") or "",
|
|
52
|
+
"at": _ts(raw),
|
|
53
|
+
"kind": raw.get("kind") or raw.get("source") or "event",
|
|
54
|
+
"source": raw.get("source", "unknown"),
|
|
55
|
+
"scope": raw.get("scope") or {
|
|
56
|
+
k: raw.get(k) for k in ("cluster", "namespace", "account",
|
|
57
|
+
"region") if raw.get(k)},
|
|
58
|
+
"resources": raw.get("resources") or raw.get("resource_ids") or
|
|
59
|
+
([raw.get("target")] if raw.get("target") else []),
|
|
60
|
+
"actor": raw.get("actor") or raw.get("user") or "",
|
|
61
|
+
"facts": raw.get("facts") or raw.get("fact_ids") or [],
|
|
62
|
+
"confidence": float(raw.get("confidence", 0.8)),
|
|
63
|
+
"summary": raw.get("summary") or raw.get("action")
|
|
64
|
+
or raw.get("message") or "",
|
|
65
|
+
"tier": raw.get("tier"), "freshness": raw.get("freshness", ""),
|
|
66
|
+
"causal": bool(raw.get("causal"))})
|
|
67
|
+
return e
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def build_timeline(events: list[dict[str, Any]]) -> dict[str, Any]:
|
|
71
|
+
norm = sorted((normalize_event(e) for e in events),
|
|
72
|
+
key=lambda e: (e["at"], e["kind"]))
|
|
73
|
+
by_source: dict[str, int] = {}
|
|
74
|
+
for e in norm:
|
|
75
|
+
by_source[e["kind"]] = by_source.get(e["kind"], 0) + 1
|
|
76
|
+
return {"timeline": norm, "counts": {"events": len(norm),
|
|
77
|
+
**by_source}}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _factor_scores(candidate: dict[str, Any], incident_at: float,
|
|
81
|
+
incident_resources: set[str],
|
|
82
|
+
window_s: float, graph=None) -> dict[str, float]:
|
|
83
|
+
dt = incident_at - _ts(candidate)
|
|
84
|
+
temporal = max(0.0, 1 - abs(dt) / window_s) if dt >= 0 else 0.0
|
|
85
|
+
c_res = set(candidate.get("resources") or
|
|
86
|
+
candidate.get("resource_ids") or [])
|
|
87
|
+
overlap = len(incident_resources & c_res) / \
|
|
88
|
+
max(1, len(incident_resources | c_res)) \
|
|
89
|
+
if incident_resources or c_res else 0.0
|
|
90
|
+
action = str(candidate.get("action") or candidate.get("kind") or "")
|
|
91
|
+
change_type = 1.0 if any(h in action.lower()
|
|
92
|
+
for h in MUTATING_ACTION_HINTS) else 0.3
|
|
93
|
+
fresh = {"fresh": 1.0, "aging": 0.6, "stale": 0.3,
|
|
94
|
+
"expired": 0.1}.get(candidate.get("freshness", ""), 0.5)
|
|
95
|
+
tier = candidate.get("tier")
|
|
96
|
+
tier_score = {0: 1.0, 1: 0.9, 2: 0.7, 3: 0.5,
|
|
97
|
+
4: 0.4, 5: 0.3}.get(tier, 0.5)
|
|
98
|
+
gd = 0.0
|
|
99
|
+
if graph is not None and incident_resources and c_res:
|
|
100
|
+
from platformforge.graph.query import blast_radius
|
|
101
|
+
for r in c_res:
|
|
102
|
+
if r in incident_resources:
|
|
103
|
+
gd = 1.0
|
|
104
|
+
break
|
|
105
|
+
try:
|
|
106
|
+
br = blast_radius(graph, r)["nodes"]
|
|
107
|
+
except (KeyError, TypeError, ValueError):
|
|
108
|
+
br = {}
|
|
109
|
+
for ir in incident_resources:
|
|
110
|
+
if ir in br:
|
|
111
|
+
gd = max(gd, max(0.0, 1 - 0.2 * br[ir]["depth"]))
|
|
112
|
+
blast = min(1.0, float(candidate.get("blast_radius", 0.0)))
|
|
113
|
+
runtime = 1.0 if candidate.get("runtime_correlated") else 0.0
|
|
114
|
+
return {"temporal": round(temporal, 3), "graph_distance": round(gd, 3),
|
|
115
|
+
"blast_radius": blast, "scope_overlap": round(overlap, 3),
|
|
116
|
+
"change_type": change_type, "freshness": fresh,
|
|
117
|
+
"evidence_tier": tier_score, "runtime_correlation": runtime}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def score_candidates(incident: dict[str, Any],
|
|
121
|
+
candidates: list[dict[str, Any]],
|
|
122
|
+
*, window_s: float = 3600,
|
|
123
|
+
graph=None) -> dict[str, Any]:
|
|
124
|
+
"""Deterministic ranked hypotheses with per-factor explanation."""
|
|
125
|
+
incident_at = _ts(incident)
|
|
126
|
+
res = set(incident.get("resources") or
|
|
127
|
+
incident.get("resource_ids") or [])
|
|
128
|
+
ranked = []
|
|
129
|
+
for c in candidates:
|
|
130
|
+
c = normalize_event(c) if "timestamp" in c or "at" in c else c
|
|
131
|
+
factors = _factor_scores(c, incident_at, res, window_s, graph)
|
|
132
|
+
score = round(sum(WEIGHTS[k] * factors[k] for k in WEIGHTS), 3)
|
|
133
|
+
dt = incident_at - _ts(c)
|
|
134
|
+
if c.get("contradicted") or dt < 0:
|
|
135
|
+
status = "contradicted" # change after incident ≠ cause
|
|
136
|
+
elif c.get("causal") and c.get("facts"):
|
|
137
|
+
status = "confirmed" # causal evidence present
|
|
138
|
+
elif score >= 0.65:
|
|
139
|
+
status = "supported"
|
|
140
|
+
elif score >= 0.3:
|
|
141
|
+
status = "candidate"
|
|
142
|
+
else:
|
|
143
|
+
status = "unknown"
|
|
144
|
+
ranked.append({"candidate": c.get("summary") or
|
|
145
|
+
c.get("action") or c.get("kind", "?"),
|
|
146
|
+
"resources": sorted(c.get("resources") or
|
|
147
|
+
c.get("resource_ids") or []),
|
|
148
|
+
"actor": c.get("actor", ""),
|
|
149
|
+
"timestamp": c.get("timestamp") or c.get("at"),
|
|
150
|
+
"score": score, "status": status,
|
|
151
|
+
"explain": {"factors": factors,
|
|
152
|
+
"weights": WEIGHTS,
|
|
153
|
+
"dt_seconds": round(dt, 1)}})
|
|
154
|
+
ranked.sort(key=lambda r: (-r["score"], r["candidate"]))
|
|
155
|
+
for i, r in enumerate(ranked):
|
|
156
|
+
r["rank"] = i + 1
|
|
157
|
+
return {"ranked": ranked,
|
|
158
|
+
"statuses": {s: sum(1 for r in ranked if r["status"] == s)
|
|
159
|
+
for s in HYPOTHESIS_STATUSES},
|
|
160
|
+
"note": "correlation ≠ causation — 'confirmed' requires "
|
|
161
|
+
"causal evidence, rank explains score only"}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def postmortem_v3(incident: dict[str, Any],
|
|
165
|
+
timeline: dict[str, Any],
|
|
166
|
+
ranked: dict[str, Any]) -> dict[str, Any]:
|
|
167
|
+
"""§174 — evidence-only postmortem draft. Root cause stays
|
|
168
|
+
`unresolved` unless a confirmed hypothesis exists (causal evidence,
|
|
169
|
+
not correlation)."""
|
|
170
|
+
hyps = ranked.get("ranked", [])
|
|
171
|
+
confirmed = [h for h in hyps if h["status"] == "confirmed"]
|
|
172
|
+
supported = [h for h in hyps if h["status"] == "supported"]
|
|
173
|
+
root = ({"status": "confirmed-candidate",
|
|
174
|
+
"evidence": confirmed[0],
|
|
175
|
+
"note": "causal evidence present — still requires human "
|
|
176
|
+
"sign-off"} if len(confirmed) == 1 else
|
|
177
|
+
{"status": "unresolved",
|
|
178
|
+
"reason": ("multiple confirmed candidates" if confirmed else
|
|
179
|
+
"no causal evidence — correlation only")})
|
|
180
|
+
unknowns = [h["candidate"] for h in hyps if h["status"] == "unknown"]
|
|
181
|
+
return {"postmortem": {
|
|
182
|
+
"title": incident.get("title", "incident"),
|
|
183
|
+
"incident_id": incident.get("incident_id", ""),
|
|
184
|
+
"status": "draft",
|
|
185
|
+
"timeline": timeline.get("timeline", []),
|
|
186
|
+
"impact": incident.get("impact", {}),
|
|
187
|
+
"observed_changes": confirmed + supported,
|
|
188
|
+
"runtime_signals": [e for e in timeline.get("timeline", [])
|
|
189
|
+
if e["kind"] in ("runtime_anomaly",
|
|
190
|
+
"alert")],
|
|
191
|
+
"candidate_causes": hyps,
|
|
192
|
+
"root_cause": root,
|
|
193
|
+
"unknowns": unknowns,
|
|
194
|
+
"follow_ups": [
|
|
195
|
+
"confirm or reject top hypothesis with independent evidence",
|
|
196
|
+
("verify declared state vs observed drift for affected "
|
|
197
|
+
"resources"),
|
|
198
|
+
"add regression coverage for the failing invariant"],
|
|
199
|
+
"note": "draft generated from evidence only — 'unresolved' is "
|
|
200
|
+
"a true state, not a template gap"}}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"""Cycle 3 — observation model. Canonical contracts for live evidence.
|
|
2
|
+
|
|
3
|
+
The load-bearing invariant: **OBSERVED ≠ COMPLETE**. Every observation
|
|
4
|
+
carries explicit scope + coverage + freshness so absence is only a
|
|
5
|
+
verdict when it was actually *seen to be absent* under a complete, fresh,
|
|
6
|
+
covering observation (ADR-0013/0014).
|
|
7
|
+
|
|
8
|
+
Runtime is not a provenance (cycle §4): `source_type=runtime` +
|
|
9
|
+
`tier=T0` on extracted facts keeps the distinction without inventing a
|
|
10
|
+
new provenance value.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import hashlib
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
from dataclasses import asdict, dataclass, field
|
|
19
|
+
from datetime import datetime, timezone
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
SCHEMA = "platformforge/observation/v1"
|
|
23
|
+
RECEIPT_SCHEMA = "platformforge/collector-receipt/v1"
|
|
24
|
+
CHANGE_EVENT_SCHEMA = "platformforge/change-event/v1"
|
|
25
|
+
DRIFT_EVENT_SCHEMA = "platformforge/drift-event/v1"
|
|
26
|
+
|
|
27
|
+
SOURCE_TYPES = ("observed", "runtime")
|
|
28
|
+
COVERAGE_STATUSES = ("complete", "partial", "sampled", "truncated",
|
|
29
|
+
"permission-limited", "unsupported", "unknown")
|
|
30
|
+
FRESHNESS_STATUSES = ("fresh", "aging", "stale", "expired", "unknown")
|
|
31
|
+
LIFECYCLES = ("present", "deleting", "deleted", "unknown")
|
|
32
|
+
BUDGET_OUTCOMES = ("complete", "reduced_scope", "sampled", "refused")
|
|
33
|
+
|
|
34
|
+
# §9 — default per-source TTLs (seconds); configurable per domain/source,
|
|
35
|
+
# never a hidden universal constant embedded in logic.
|
|
36
|
+
DEFAULT_FRESH_TTL: dict[str, int] = {
|
|
37
|
+
"runtime": 120, "kubernetes": 300, "aws": 3600, "default": 900}
|
|
38
|
+
|
|
39
|
+
_OBS_ID_RE = re.compile(r"^obs-[0-9a-f]{16}$")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def now_iso() -> str:
|
|
43
|
+
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def parse_ts(value: str | None) -> datetime | None:
|
|
47
|
+
if not value:
|
|
48
|
+
return None
|
|
49
|
+
try:
|
|
50
|
+
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
51
|
+
except ValueError:
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def iso(dt: datetime) -> str:
|
|
56
|
+
return dt.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def age_seconds(captured_at: str | None, at: datetime | None = None) -> float | None:
|
|
60
|
+
ts = parse_ts(captured_at)
|
|
61
|
+
if ts is None:
|
|
62
|
+
return None
|
|
63
|
+
return ((at or datetime.now(timezone.utc)) - ts).total_seconds()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def canonical_hash(obj: Any) -> str:
|
|
67
|
+
return hashlib.sha256(json.dumps(
|
|
68
|
+
obj, sort_keys=True, separators=(",", ":"), default=str
|
|
69
|
+
).encode()).hexdigest()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class ObservationScope:
|
|
74
|
+
"""§7 — WHAT WAS OBSERVED? Explicit, declarative, comparable."""
|
|
75
|
+
provider: str = ""
|
|
76
|
+
accounts: list[str] = field(default_factory=list)
|
|
77
|
+
regions: list[str] = field(default_factory=list)
|
|
78
|
+
services: list[str] = field(default_factory=list)
|
|
79
|
+
resource_types: list[str] = field(default_factory=list)
|
|
80
|
+
namespaces: list[str] = field(default_factory=list)
|
|
81
|
+
clusters: list[str] = field(default_factory=list)
|
|
82
|
+
selectors: dict[str, Any] = field(default_factory=dict)
|
|
83
|
+
exclusions: list[str] = field(default_factory=list)
|
|
84
|
+
|
|
85
|
+
def covers(self, target: dict[str, Any]) -> tuple[bool, str]:
|
|
86
|
+
"""Is `target` inside this scope? Conservative: an unset axis
|
|
87
|
+
means 'all' only if the axis was declared unbounded; otherwise
|
|
88
|
+
exclusion/omission wins (honest gaps)."""
|
|
89
|
+
checks = []
|
|
90
|
+
if self.accounts:
|
|
91
|
+
checks.append((target.get("account") in self.accounts,
|
|
92
|
+
f"account {target.get('account')} not in scope"))
|
|
93
|
+
if self.regions:
|
|
94
|
+
checks.append((target.get("region") in self.regions,
|
|
95
|
+
f"region {target.get('region')} not in scope"))
|
|
96
|
+
if self.namespaces:
|
|
97
|
+
checks.append((target.get("namespace") in self.namespaces,
|
|
98
|
+
f"namespace {target.get('namespace')} not in scope"))
|
|
99
|
+
if self.clusters:
|
|
100
|
+
checks.append((target.get("cluster") in self.clusters,
|
|
101
|
+
f"cluster {target.get('cluster')} not in scope"))
|
|
102
|
+
if self.resource_types:
|
|
103
|
+
checks.append((target.get("resource_type") in self.resource_types,
|
|
104
|
+
f"type {target.get('resource_type')} not in scope"))
|
|
105
|
+
excl = target.get("resource_id") or target.get("name") or ""
|
|
106
|
+
if excl and excl in self.exclusions:
|
|
107
|
+
checks.append((False, f"{excl} explicitly excluded"))
|
|
108
|
+
for ok, why in checks:
|
|
109
|
+
if not ok:
|
|
110
|
+
return False, why
|
|
111
|
+
return True, "in scope"
|
|
112
|
+
|
|
113
|
+
def to_dict(self) -> dict[str, Any]:
|
|
114
|
+
return {k: v for k, v in asdict(self).items() if v not in ([], {}, "")}
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def from_dict(cls, d: dict[str, Any] | None) -> ObservationScope:
|
|
118
|
+
return cls(**{k: v for k, v in (d or {}).items() if k in cls.__dataclass_fields__})
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@dataclass
|
|
122
|
+
class Coverage:
|
|
123
|
+
"""§8 — coverage is per-resource-type, never one global claim."""
|
|
124
|
+
status: str = "unknown"
|
|
125
|
+
per_resource_type: dict[str, str] = field(default_factory=dict)
|
|
126
|
+
reasons: list[str] = field(default_factory=list)
|
|
127
|
+
|
|
128
|
+
def __post_init__(self):
|
|
129
|
+
if self.status not in COVERAGE_STATUSES:
|
|
130
|
+
raise ValueError(f"invalid coverage status: {self.status}")
|
|
131
|
+
for rt, st in self.per_resource_type.items():
|
|
132
|
+
if st not in COVERAGE_STATUSES:
|
|
133
|
+
raise ValueError(f"invalid coverage for {rt}: {st}")
|
|
134
|
+
|
|
135
|
+
def for_type(self, resource_type: str) -> str:
|
|
136
|
+
return self.per_resource_type.get(resource_type, self.status)
|
|
137
|
+
|
|
138
|
+
def to_dict(self) -> dict[str, Any]:
|
|
139
|
+
d: dict[str, Any] = {"status": self.status}
|
|
140
|
+
if self.per_resource_type:
|
|
141
|
+
d["per_resource_type"] = dict(sorted(self.per_resource_type.items()))
|
|
142
|
+
if self.reasons:
|
|
143
|
+
d["reasons"] = self.reasons
|
|
144
|
+
return d
|
|
145
|
+
|
|
146
|
+
@classmethod
|
|
147
|
+
def from_dict(cls, d: dict[str, Any] | None) -> Coverage:
|
|
148
|
+
d = d or {}
|
|
149
|
+
return cls(status=d.get("status", "unknown"),
|
|
150
|
+
per_resource_type=dict(d.get("per_resource_type", {})),
|
|
151
|
+
reasons=list(d.get("reasons", [])))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@dataclass
|
|
155
|
+
class Freshness:
|
|
156
|
+
"""§9 — captured_at + fresh_until → status at a point in time."""
|
|
157
|
+
captured_at: str = ""
|
|
158
|
+
fresh_until: str = ""
|
|
159
|
+
status: str = "unknown"
|
|
160
|
+
|
|
161
|
+
def status_at(self, at: datetime | None = None,
|
|
162
|
+
ttl: int | None = None) -> str:
|
|
163
|
+
at = at or datetime.now(timezone.utc)
|
|
164
|
+
cap = parse_ts(self.captured_at)
|
|
165
|
+
if cap is None:
|
|
166
|
+
return "unknown"
|
|
167
|
+
until = parse_ts(self.fresh_until)
|
|
168
|
+
if until is None and ttl:
|
|
169
|
+
from datetime import timedelta
|
|
170
|
+
until = cap + timedelta(seconds=ttl)
|
|
171
|
+
age = (at - cap).total_seconds()
|
|
172
|
+
if until is None:
|
|
173
|
+
return "unknown"
|
|
174
|
+
if at > until:
|
|
175
|
+
span = (until - cap).total_seconds() or 1.0
|
|
176
|
+
return "expired" if age > span * 2 else "stale"
|
|
177
|
+
return "fresh" if age < 0.6 * (until - cap).total_seconds() else "aging"
|
|
178
|
+
|
|
179
|
+
def to_dict(self) -> dict[str, Any]:
|
|
180
|
+
d = {"captured_at": self.captured_at, "status": self.status}
|
|
181
|
+
if self.fresh_until:
|
|
182
|
+
d["fresh_until"] = self.fresh_until
|
|
183
|
+
return d
|
|
184
|
+
|
|
185
|
+
@classmethod
|
|
186
|
+
def from_dict(cls, d: dict[str, Any] | None) -> Freshness:
|
|
187
|
+
d = d or {}
|
|
188
|
+
return cls(captured_at=d.get("captured_at", ""),
|
|
189
|
+
fresh_until=d.get("fresh_until", ""),
|
|
190
|
+
status=d.get("status", "unknown"))
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@dataclass
|
|
194
|
+
class ObservedObject:
|
|
195
|
+
"""One provider-observed object inside an envelope."""
|
|
196
|
+
resource_id: str # provider-native (arn/uid/path)
|
|
197
|
+
resource_type: str # normalized kind (k8s:Deployment…)
|
|
198
|
+
attributes: dict[str, Any] = field(default_factory=dict) # redacted!
|
|
199
|
+
provider: str = ""
|
|
200
|
+
account: str = ""
|
|
201
|
+
region: str = ""
|
|
202
|
+
cluster: str = ""
|
|
203
|
+
namespace: str = ""
|
|
204
|
+
name: str = ""
|
|
205
|
+
uid: str = ""
|
|
206
|
+
lifecycle: str = "present" # present|deleting|deleted|unknown
|
|
207
|
+
deletion_evidence: str = "" # strong evidence type if deleted
|
|
208
|
+
content_hash: str = "" # canonical normalized fingerprint
|
|
209
|
+
observed_at: str = ""
|
|
210
|
+
artifact: str = "" # artifact://sha256/… for raw doc
|
|
211
|
+
|
|
212
|
+
def __post_init__(self):
|
|
213
|
+
if self.lifecycle not in LIFECYCLES:
|
|
214
|
+
raise ValueError(f"invalid lifecycle: {self.lifecycle}")
|
|
215
|
+
if self.lifecycle == "deleted" and not self.deletion_evidence:
|
|
216
|
+
raise ValueError(
|
|
217
|
+
"lifecycle=deleted requires deletion_evidence "
|
|
218
|
+
"(ADR-0013: missing-from-snapshot is not proof)")
|
|
219
|
+
|
|
220
|
+
def fingerprint(self) -> str:
|
|
221
|
+
"""§144 — canonical normalized hash for delta ingestion."""
|
|
222
|
+
return self.content_hash or canonical_hash({
|
|
223
|
+
"id": self.resource_id, "type": self.resource_type,
|
|
224
|
+
"attrs": self.attributes})
|
|
225
|
+
|
|
226
|
+
def to_dict(self) -> dict[str, Any]:
|
|
227
|
+
d = asdict(self)
|
|
228
|
+
if not self.content_hash:
|
|
229
|
+
d["content_hash"] = self.fingerprint()
|
|
230
|
+
return {k: v for k, v in d.items() if v not in ("", {}, [])}
|
|
231
|
+
|
|
232
|
+
@classmethod
|
|
233
|
+
def from_dict(cls, d: dict[str, Any]) -> ObservedObject:
|
|
234
|
+
return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__})
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
@dataclass
|
|
238
|
+
class CollectorReceipt:
|
|
239
|
+
"""§18 — every collection emits an auditable receipt."""
|
|
240
|
+
collector: str
|
|
241
|
+
collector_version: str
|
|
242
|
+
provider: str
|
|
243
|
+
started_at: str
|
|
244
|
+
completed_at: str = ""
|
|
245
|
+
scope: dict[str, Any] = field(default_factory=dict)
|
|
246
|
+
api_calls: int = 0
|
|
247
|
+
pages: int = 0
|
|
248
|
+
objects: int = 0
|
|
249
|
+
bytes: int = 0
|
|
250
|
+
throttles: int = 0
|
|
251
|
+
retries: int = 0
|
|
252
|
+
cache_hits: int = 0
|
|
253
|
+
errors: list[str] = field(default_factory=list)
|
|
254
|
+
permission_denied: list[dict[str, Any]] = field(default_factory=list)
|
|
255
|
+
unsupported: list[str] = field(default_factory=list)
|
|
256
|
+
cursor: str = ""
|
|
257
|
+
metadata_only: bool = True
|
|
258
|
+
fallback: str = ""
|
|
259
|
+
coverage: dict[str, Any] = field(default_factory=dict)
|
|
260
|
+
freshness: dict[str, Any] = field(default_factory=dict)
|
|
261
|
+
budget_outcome: str = "complete"
|
|
262
|
+
duration_s: float = 0.0
|
|
263
|
+
|
|
264
|
+
def __post_init__(self):
|
|
265
|
+
if self.budget_outcome not in BUDGET_OUTCOMES:
|
|
266
|
+
raise ValueError(f"invalid budget outcome: {self.budget_outcome}")
|
|
267
|
+
|
|
268
|
+
def to_dict(self) -> dict[str, Any]:
|
|
269
|
+
d = {"schema": RECEIPT_SCHEMA, **asdict(self)}
|
|
270
|
+
return d
|
|
271
|
+
|
|
272
|
+
@classmethod
|
|
273
|
+
def from_dict(cls, d: dict[str, Any]) -> CollectorReceipt:
|
|
274
|
+
return cls(**{k: v for k, v in d.items()
|
|
275
|
+
if k in cls.__dataclass_fields__})
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@dataclass
|
|
279
|
+
class ObservationEnvelope:
|
|
280
|
+
"""§6 — canonical live-observation artifact (observation/v1)."""
|
|
281
|
+
observation_id: str
|
|
282
|
+
collector: str
|
|
283
|
+
collector_version: str
|
|
284
|
+
provider: str
|
|
285
|
+
source_type: str # observed | runtime
|
|
286
|
+
captured_at: str
|
|
287
|
+
completed_at: str = ""
|
|
288
|
+
fresh_until: str = ""
|
|
289
|
+
scope: dict[str, Any] = field(default_factory=dict)
|
|
290
|
+
coverage: dict[str, Any] = field(default_factory=lambda: {"status": "unknown"})
|
|
291
|
+
pagination: dict[str, Any] = field(default_factory=dict)
|
|
292
|
+
permissions: dict[str, Any] = field(default_factory=dict)
|
|
293
|
+
errors: list[str] = field(default_factory=list)
|
|
294
|
+
objects: list[dict[str, Any]] = field(default_factory=list)
|
|
295
|
+
bytes: int = 0
|
|
296
|
+
hashes: dict[str, Any] = field(default_factory=dict)
|
|
297
|
+
receipt: dict[str, Any] = field(default_factory=dict)
|
|
298
|
+
|
|
299
|
+
def __post_init__(self):
|
|
300
|
+
if self.source_type not in SOURCE_TYPES:
|
|
301
|
+
raise ValueError(f"invalid source_type: {self.source_type}")
|
|
302
|
+
if not _OBS_ID_RE.match(self.observation_id):
|
|
303
|
+
raise ValueError(f"invalid observation_id: {self.observation_id}")
|
|
304
|
+
|
|
305
|
+
@classmethod
|
|
306
|
+
def new(cls, collector: str, version: str, provider: str,
|
|
307
|
+
source_type: str, scope: ObservationScope | dict | None = None,
|
|
308
|
+
captured_at: str | None = None, **kw) -> ObservationEnvelope:
|
|
309
|
+
sc = (scope.to_dict() if isinstance(scope, ObservationScope)
|
|
310
|
+
else (scope or {}))
|
|
311
|
+
obs_id = "obs-" + canonical_hash(
|
|
312
|
+
{"collector": collector, "provider": provider,
|
|
313
|
+
"captured_at": captured_at or "", "scope": sc})[:16]
|
|
314
|
+
return cls(observation_id=obs_id, collector=collector,
|
|
315
|
+
collector_version=version, provider=provider,
|
|
316
|
+
source_type=source_type,
|
|
317
|
+
captured_at=captured_at or now_iso(), scope=sc, **kw)
|
|
318
|
+
|
|
319
|
+
def coverage_status(self, resource_type: str = "") -> str:
|
|
320
|
+
cov = Coverage.from_dict(self.coverage)
|
|
321
|
+
return cov.for_type(resource_type) if resource_type else cov.status
|
|
322
|
+
|
|
323
|
+
def freshness_status_at(self, at: datetime | None = None) -> str:
|
|
324
|
+
f = Freshness.from_dict({"captured_at": self.captured_at,
|
|
325
|
+
"fresh_until": self.fresh_until})
|
|
326
|
+
return f.status_at(at, ttl=DEFAULT_FRESH_TTL.get(
|
|
327
|
+
self.provider, DEFAULT_FRESH_TTL["default"]))
|
|
328
|
+
|
|
329
|
+
def can_conclude_absent(self, target: dict[str, Any],
|
|
330
|
+
at: datetime | None = None) -> tuple[bool, str]:
|
|
331
|
+
"""§10 — absence is only provable when scope covers the target
|
|
332
|
+
AND coverage is complete for its type AND the snapshot is fresh.
|
|
333
|
+
Everything else → unresolved."""
|
|
334
|
+
in_scope, why = ObservationScope.from_dict(self.scope).covers(target)
|
|
335
|
+
if not in_scope:
|
|
336
|
+
return False, f"scope does not cover target: {why}"
|
|
337
|
+
cov = self.coverage_status(target.get("resource_type", ""))
|
|
338
|
+
if cov != "complete":
|
|
339
|
+
return False, f"coverage={cov} — absence unresolved"
|
|
340
|
+
fs = self.freshness_status_at(at)
|
|
341
|
+
if fs != "fresh":
|
|
342
|
+
return False, f"freshness={fs} — absence unresolved"
|
|
343
|
+
return True, "absence provable (scope+complete+fresh)"
|
|
344
|
+
|
|
345
|
+
def signature(self) -> str:
|
|
346
|
+
return self.hashes.get("envelope") or canonical_hash(
|
|
347
|
+
self.to_dict(include_hashes=False))
|
|
348
|
+
|
|
349
|
+
def to_dict(self, include_hashes: bool = True) -> dict[str, Any]:
|
|
350
|
+
d = {"schema": SCHEMA, "observation_id": self.observation_id,
|
|
351
|
+
"collector": self.collector,
|
|
352
|
+
"collector_version": self.collector_version,
|
|
353
|
+
"provider": self.provider, "source_type": self.source_type,
|
|
354
|
+
"captured_at": self.captured_at, "scope": self.scope,
|
|
355
|
+
"coverage": self.coverage, "objects": self.objects}
|
|
356
|
+
for k in ("completed_at", "fresh_until", "pagination",
|
|
357
|
+
"permissions", "bytes", "receipt"):
|
|
358
|
+
v = getattr(self, k)
|
|
359
|
+
if v not in ("", {}, [], 0):
|
|
360
|
+
d[k] = v
|
|
361
|
+
if self.errors:
|
|
362
|
+
d["errors"] = self.errors
|
|
363
|
+
if include_hashes:
|
|
364
|
+
h = dict(self.hashes)
|
|
365
|
+
h.setdefault("envelope", canonical_hash(
|
|
366
|
+
{k: v for k, v in d.items() if k != "hashes"}))
|
|
367
|
+
d["hashes"] = h
|
|
368
|
+
return d
|
|
369
|
+
|
|
370
|
+
@classmethod
|
|
371
|
+
def from_dict(cls, d: dict[str, Any]) -> ObservationEnvelope:
|
|
372
|
+
return cls(**{k: v for k, v in d.items()
|
|
373
|
+
if k in cls.__dataclass_fields__})
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
@dataclass
|
|
377
|
+
class ChangeEvent:
|
|
378
|
+
"""§78 — provider-observed change evidence (CloudTrail et al., T1)."""
|
|
379
|
+
event_id: str
|
|
380
|
+
timestamp: str
|
|
381
|
+
source: str # cloudtrail | k8s-event | …
|
|
382
|
+
action: str
|
|
383
|
+
actor: str = ""
|
|
384
|
+
resource_ids: list[str] = field(default_factory=list)
|
|
385
|
+
account: str = ""
|
|
386
|
+
region: str = ""
|
|
387
|
+
request: dict[str, Any] = field(default_factory=dict) # redacted!
|
|
388
|
+
result: str = "" # success|error
|
|
389
|
+
evidence: dict[str, Any] = field(default_factory=dict)
|
|
390
|
+
|
|
391
|
+
def to_dict(self) -> dict[str, Any]:
|
|
392
|
+
return {"schema": CHANGE_EVENT_SCHEMA,
|
|
393
|
+
**{k: v for k, v in asdict(self).items() if v not in ("", {}, [])}}
|
|
394
|
+
|
|
395
|
+
@classmethod
|
|
396
|
+
def from_dict(cls, d: dict[str, Any]) -> ChangeEvent:
|
|
397
|
+
return cls(**{k: v for k, v in d.items()
|
|
398
|
+
if k in cls.__dataclass_fields__})
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
@dataclass
|
|
402
|
+
class DriftEvent:
|
|
403
|
+
"""§113 — a classified change between two observations."""
|
|
404
|
+
drift_id: str
|
|
405
|
+
resource_id: str
|
|
406
|
+
drift_class: str # §102 set
|
|
407
|
+
before: dict[str, Any] = field(default_factory=dict)
|
|
408
|
+
after: dict[str, Any] = field(default_factory=dict)
|
|
409
|
+
facts: list[str] = field(default_factory=list)
|
|
410
|
+
change_event: str = "" # event_id if correlated
|
|
411
|
+
risk: str = ""
|
|
412
|
+
owner: str = ""
|
|
413
|
+
observed_at: str = ""
|
|
414
|
+
|
|
415
|
+
def to_dict(self) -> dict[str, Any]:
|
|
416
|
+
return {"schema": DRIFT_EVENT_SCHEMA,
|
|
417
|
+
**{k: v for k, v in asdict(self).items() if v not in ("", {}, [])}}
|
|
418
|
+
|
|
419
|
+
@classmethod
|
|
420
|
+
def from_dict(cls, d: dict[str, Any]) -> DriftEvent:
|
|
421
|
+
return cls(**{k: v for k, v in d.items()
|
|
422
|
+
if k in cls.__dataclass_fields__})
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
# §102 — normative drift classes (closed set; validated, not free-text)
|
|
426
|
+
DRIFT_CLASSES = (
|
|
427
|
+
"converged", "planned-not-applied", "observed-out-of-band",
|
|
428
|
+
"desired-missing-observed", "observed-orphan", "config-drift",
|
|
429
|
+
"identity-drift", "policy-drift", "security-drift", "network-drift",
|
|
430
|
+
"version-drift", "runtime-undeclared", "stale-observation",
|
|
431
|
+
"permission-unknown", "scope-mismatch", "uncomparable", "unknown")
|
|
432
|
+
|
|
433
|
+
# §125 — declared vs runtime behavior classes
|
|
434
|
+
BEHAVIOR_CLASSES = ("declared-and-observed", "observed-undeclared",
|
|
435
|
+
"declared-not-seen-in-window", "unknown")
|