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,264 @@
|
|
|
1
|
+
"""Deterministic graph model conforming to contracts/graph.schema.json
|
|
2
|
+
(platformforge/graph/v1). Nodes and edges are derived from facts and carry
|
|
3
|
+
source_fact_ids; inferred edges are never presented as observed."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from platformforge.core.hashing import sha256_text
|
|
14
|
+
from platformforge.graph.vocab import EDGE_KINDS, NODE_KINDS, PROVENANCES, impact_of
|
|
15
|
+
|
|
16
|
+
SCHEMA = "platformforge/graph/v1"
|
|
17
|
+
SCHEMA_V2 = "platformforge/graph/v2"
|
|
18
|
+
SCHEMAS = (SCHEMA, SCHEMA_V2)
|
|
19
|
+
_SLUG_RE = re.compile(r"[^a-z0-9_.\-/]+")
|
|
20
|
+
|
|
21
|
+
_PROV_RANK = {"observed": 3, "planned": 2, "declared": 1, "inferred": 0}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _merge_evidence(a: tuple[dict, ...], b: tuple[dict, ...]) -> tuple[dict, ...]:
|
|
25
|
+
"""Union edge evidence records keyed by (provenance, source_type):
|
|
26
|
+
fact_ids merge, observed_at keeps the max. Every contributing layer
|
|
27
|
+
stays visible — observed never erases declared (ADR-0015)."""
|
|
28
|
+
by_key: dict[tuple[str, str], dict] = {}
|
|
29
|
+
for rec in (*a, *b):
|
|
30
|
+
key = (rec.get("provenance", "declared"), rec.get("source_type", ""))
|
|
31
|
+
cur = by_key.get(key)
|
|
32
|
+
if cur is None:
|
|
33
|
+
by_key[key] = dict(rec, fact_ids=list(rec.get("fact_ids", [])))
|
|
34
|
+
continue
|
|
35
|
+
cur["fact_ids"] = sorted(set(cur["fact_ids"]) | set(rec.get("fact_ids", [])))
|
|
36
|
+
if rec.get("observed_at", "") > cur.get("observed_at", ""):
|
|
37
|
+
cur["observed_at"] = rec["observed_at"]
|
|
38
|
+
return tuple(by_key[k] for k in sorted(by_key))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _merge_temporal(a: dict, b: dict) -> dict:
|
|
42
|
+
"""Temporal merge: windows span min→max, sample_count sums, expired
|
|
43
|
+
flag cleared by any new observation (fresh evidence revives)."""
|
|
44
|
+
if not a:
|
|
45
|
+
return dict(b)
|
|
46
|
+
if not b:
|
|
47
|
+
return dict(a)
|
|
48
|
+
out = dict(a)
|
|
49
|
+
for k in ("first_seen", "window_start"):
|
|
50
|
+
vals = [v for v in (a.get(k), b.get(k)) if v]
|
|
51
|
+
if vals:
|
|
52
|
+
out[k] = min(vals)
|
|
53
|
+
for k in ("last_seen", "window_end"):
|
|
54
|
+
vals = [v for v in (a.get(k), b.get(k)) if v]
|
|
55
|
+
if vals:
|
|
56
|
+
out[k] = max(vals)
|
|
57
|
+
if "sample_count" in a or "sample_count" in b:
|
|
58
|
+
out["sample_count"] = int(a.get("sample_count") or 0) + \
|
|
59
|
+
int(b.get("sample_count") or 0)
|
|
60
|
+
if not b.get("expired"):
|
|
61
|
+
out.pop("expired", None)
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def node_id(kind: str, label: str) -> str:
|
|
66
|
+
"""Deterministic node id: `kind/label` normalized."""
|
|
67
|
+
if kind not in NODE_KINDS:
|
|
68
|
+
raise ValueError(f"unknown node kind: {kind}")
|
|
69
|
+
slug = _SLUG_RE.sub("-", label.strip().lower()).strip("-")
|
|
70
|
+
if not slug:
|
|
71
|
+
raise ValueError("empty node label")
|
|
72
|
+
return f"{kind}/{slug}"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@dataclass(frozen=True)
|
|
76
|
+
class Node:
|
|
77
|
+
node_id: str
|
|
78
|
+
kind: str
|
|
79
|
+
label: str
|
|
80
|
+
attrs: dict[str, Any] = field(default_factory=dict)
|
|
81
|
+
source_fact_ids: tuple[str, ...] = ()
|
|
82
|
+
|
|
83
|
+
@classmethod
|
|
84
|
+
def make(cls, kind: str, label: str, attrs: dict[str, Any] | None = None,
|
|
85
|
+
fact_ids: Iterable[str] = ()) -> Node:
|
|
86
|
+
return cls(node_id=node_id(kind, label), kind=kind, label=label,
|
|
87
|
+
attrs=dict(attrs or {}),
|
|
88
|
+
source_fact_ids=tuple(sorted(set(fact_ids))))
|
|
89
|
+
|
|
90
|
+
def to_dict(self) -> dict[str, Any]:
|
|
91
|
+
d: dict[str, Any] = {"node_id": self.node_id, "kind": self.kind,
|
|
92
|
+
"label": self.label}
|
|
93
|
+
if self.attrs:
|
|
94
|
+
d["attrs"] = self.attrs
|
|
95
|
+
if self.source_fact_ids:
|
|
96
|
+
d["source_fact_ids"] = list(self.source_fact_ids)
|
|
97
|
+
return d
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True)
|
|
101
|
+
class Edge:
|
|
102
|
+
src: str
|
|
103
|
+
dst: str
|
|
104
|
+
kind: str
|
|
105
|
+
provenance: str = "declared" # effective (strongest) provenance
|
|
106
|
+
confidence: float = 1.0
|
|
107
|
+
source_fact_ids: tuple[str, ...] = ()
|
|
108
|
+
attrs: dict[str, Any] = field(default_factory=dict)
|
|
109
|
+
# v2 — per-layer evidence records; every contributing layer is kept
|
|
110
|
+
evidence: tuple[dict, ...] = ()
|
|
111
|
+
# v2 — temporal window for runtime edges
|
|
112
|
+
# {first_seen, last_seen, window_start, window_end, sample_count,
|
|
113
|
+
# expired: bool}
|
|
114
|
+
temporal: dict[str, Any] = field(default_factory=dict)
|
|
115
|
+
|
|
116
|
+
def __post_init__(self):
|
|
117
|
+
if self.kind not in EDGE_KINDS:
|
|
118
|
+
raise ValueError(f"unknown edge kind: {self.kind}")
|
|
119
|
+
if self.provenance not in PROVENANCES:
|
|
120
|
+
raise ValueError(f"bad provenance: {self.provenance}")
|
|
121
|
+
if not (0.0 <= self.confidence <= 1.0):
|
|
122
|
+
raise ValueError("confidence out of range")
|
|
123
|
+
for rec in self.evidence:
|
|
124
|
+
if rec.get("provenance", self.provenance) not in PROVENANCES:
|
|
125
|
+
raise ValueError(f"bad evidence provenance: {rec}")
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def eid(self) -> str:
|
|
129
|
+
return f"{self.src}->{self.dst}:{self.kind}"
|
|
130
|
+
|
|
131
|
+
def layers(self) -> tuple[dict, ...]:
|
|
132
|
+
"""All evidence layers. Edges loaded from v1 docs (no records)
|
|
133
|
+
synthesize a single layer from provenance+fact_ids on demand —
|
|
134
|
+
stored data is never rewritten (§94)."""
|
|
135
|
+
if self.evidence:
|
|
136
|
+
return self.evidence
|
|
137
|
+
return ({"provenance": self.provenance,
|
|
138
|
+
"fact_ids": list(self.source_fact_ids)},)
|
|
139
|
+
|
|
140
|
+
def to_dict(self) -> dict[str, Any]:
|
|
141
|
+
d: dict[str, Any] = {"from": self.src, "to": self.dst,
|
|
142
|
+
"kind": self.kind, "provenance": self.provenance,
|
|
143
|
+
"confidence": self.confidence}
|
|
144
|
+
if self.source_fact_ids:
|
|
145
|
+
d["source_fact_ids"] = list(self.source_fact_ids)
|
|
146
|
+
if self.evidence:
|
|
147
|
+
d["evidence"] = [dict(r) for r in self.evidence]
|
|
148
|
+
if self.temporal:
|
|
149
|
+
d["temporal"] = dict(self.temporal)
|
|
150
|
+
if self.attrs:
|
|
151
|
+
d["attrs"] = self.attrs
|
|
152
|
+
return d
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@dataclass
|
|
156
|
+
class Graph:
|
|
157
|
+
nodes: dict[str, Node] = field(default_factory=dict)
|
|
158
|
+
edges: dict[str, Edge] = field(default_factory=dict)
|
|
159
|
+
meta: dict[str, Any] = field(default_factory=dict)
|
|
160
|
+
|
|
161
|
+
def add_node(self, node: Node) -> Node:
|
|
162
|
+
existing = self.nodes.get(node.node_id)
|
|
163
|
+
if existing:
|
|
164
|
+
merged = Node(existing.node_id, existing.kind, existing.label,
|
|
165
|
+
attrs={**existing.attrs, **node.attrs},
|
|
166
|
+
source_fact_ids=tuple(sorted(
|
|
167
|
+
set(existing.source_fact_ids)
|
|
168
|
+
| set(node.source_fact_ids))))
|
|
169
|
+
self.nodes[node.node_id] = merged
|
|
170
|
+
return merged
|
|
171
|
+
self.nodes[node.node_id] = node
|
|
172
|
+
return node
|
|
173
|
+
|
|
174
|
+
def add_edge(self, edge: Edge) -> Edge:
|
|
175
|
+
if edge.src not in self.nodes or edge.dst not in self.nodes:
|
|
176
|
+
raise ValueError(f"edge endpoint missing: {edge.eid}")
|
|
177
|
+
existing = self.edges.get(edge.eid)
|
|
178
|
+
if existing:
|
|
179
|
+
stronger = existing if existing.confidence >= edge.confidence \
|
|
180
|
+
else edge
|
|
181
|
+
# §86–89 — effective provenance is the strongest *layer*;
|
|
182
|
+
# every contributing evidence record is preserved, never
|
|
183
|
+
# overwritten by a later/stronger layer.
|
|
184
|
+
provenance = max(
|
|
185
|
+
(existing.provenance, edge.provenance),
|
|
186
|
+
key=lambda p: _PROV_RANK[p])
|
|
187
|
+
merged = Edge(stronger.src, stronger.dst, stronger.kind,
|
|
188
|
+
provenance=provenance,
|
|
189
|
+
confidence=stronger.confidence,
|
|
190
|
+
source_fact_ids=tuple(sorted(
|
|
191
|
+
set(existing.source_fact_ids)
|
|
192
|
+
| set(edge.source_fact_ids))),
|
|
193
|
+
attrs={**existing.attrs, **edge.attrs},
|
|
194
|
+
evidence=_merge_evidence(existing.layers(),
|
|
195
|
+
edge.layers()),
|
|
196
|
+
temporal=_merge_temporal(existing.temporal,
|
|
197
|
+
edge.temporal))
|
|
198
|
+
self.edges[edge.eid] = merged
|
|
199
|
+
return merged
|
|
200
|
+
self.edges[edge.eid] = edge
|
|
201
|
+
return edge
|
|
202
|
+
|
|
203
|
+
# ── serialization ─────────────────────────────────────────
|
|
204
|
+
def to_dict(self, schema: str | None = None) -> dict[str, Any]:
|
|
205
|
+
"""v2 is auto-emitted iff any edge carries evidence/temporal —
|
|
206
|
+
otherwise the document stays v1 (existing readers unaffected)."""
|
|
207
|
+
if schema is None:
|
|
208
|
+
schema = SCHEMA_V2 if any(
|
|
209
|
+
e.evidence or e.temporal for e in self.edges.values()) \
|
|
210
|
+
else SCHEMA
|
|
211
|
+
if schema not in SCHEMAS:
|
|
212
|
+
raise ValueError(f"unknown graph schema: {schema}")
|
|
213
|
+
return {
|
|
214
|
+
"schema": schema,
|
|
215
|
+
"nodes": [self.nodes[k].to_dict() for k in sorted(self.nodes)],
|
|
216
|
+
"edges": [self.edges[k].to_dict() for k in sorted(self.edges)],
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
def to_json(self) -> str:
|
|
220
|
+
return json.dumps(self.to_dict(), sort_keys=True, indent=2)
|
|
221
|
+
|
|
222
|
+
@classmethod
|
|
223
|
+
def from_dict(cls, doc: dict[str, Any]) -> Graph:
|
|
224
|
+
if doc.get("schema") not in SCHEMAS:
|
|
225
|
+
raise ValueError(
|
|
226
|
+
f"not a platformforge graph document: {doc.get('schema')}")
|
|
227
|
+
g = cls()
|
|
228
|
+
for n in doc.get("nodes", []):
|
|
229
|
+
g.nodes[n["node_id"]] = Node(
|
|
230
|
+
node_id=n["node_id"], kind=n["kind"], label=n["label"],
|
|
231
|
+
attrs=n.get("attrs", {}),
|
|
232
|
+
source_fact_ids=tuple(n.get("source_fact_ids", [])))
|
|
233
|
+
for e in doc.get("edges", []):
|
|
234
|
+
evidence = tuple(dict(r) for r in e.get("evidence", []))
|
|
235
|
+
# v1 docs keep evidence empty — layers are synthesized lazily
|
|
236
|
+
# via edge.layers() so reading a v1 snapshot never rewrites
|
|
237
|
+
# its content hash (§94: migration is explicit, not silent).
|
|
238
|
+
g.edges[f"{e['from']}->{e['to']}:{e['kind']}"] = Edge(
|
|
239
|
+
src=e["from"], dst=e["to"], kind=e["kind"],
|
|
240
|
+
provenance=e.get("provenance", "declared"),
|
|
241
|
+
confidence=e.get("confidence", 1.0),
|
|
242
|
+
source_fact_ids=tuple(e.get("source_fact_ids", [])),
|
|
243
|
+
attrs=e.get("attrs", {}), evidence=evidence,
|
|
244
|
+
temporal=dict(e.get("temporal", {})))
|
|
245
|
+
return g
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def graph_hash(self) -> str:
|
|
249
|
+
return sha256_text(json.dumps(self.to_dict(), sort_keys=True))
|
|
250
|
+
|
|
251
|
+
def stats(self) -> dict[str, Any]:
|
|
252
|
+
by_kind: dict[str, int] = {}
|
|
253
|
+
for n in self.nodes.values():
|
|
254
|
+
by_kind[n.kind] = by_kind.get(n.kind, 0) + 1
|
|
255
|
+
by_edge: dict[str, int] = {}
|
|
256
|
+
for e in self.edges.values():
|
|
257
|
+
by_edge[e.kind] = by_edge.get(e.kind, 0) + 1
|
|
258
|
+
return {"nodes": len(self.nodes), "edges": len(self.edges),
|
|
259
|
+
"node_kinds": by_kind, "edge_kinds": by_edge,
|
|
260
|
+
"graph_hash": self.graph_hash}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def impact_class(edge_kind: str) -> str:
|
|
264
|
+
return impact_of(edge_kind)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Graph persistence: canonical JSON + content-addressed snapshots.
|
|
2
|
+
|
|
3
|
+
§6 — every snapshot carries an envelope: snapshot_id, timestamp, source,
|
|
4
|
+
source_type (desired|planned|observed|runtime), environment, workspace,
|
|
5
|
+
commit, provider, scope, graph_hash, fact_ids. Comparisons across types
|
|
6
|
+
(desired↔planned↔observed) use graph.diff.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import time
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from platformforge.graph.model import Graph
|
|
17
|
+
|
|
18
|
+
GRAPH_DIR = ".platformforge/graph"
|
|
19
|
+
|
|
20
|
+
SNAPSHOT_FIELDS = ("snapshot_id", "timestamp", "source", "source_type",
|
|
21
|
+
"environment", "workspace", "commit", "provider",
|
|
22
|
+
"scope", "graph_hash", "fact_ids")
|
|
23
|
+
SOURCE_TYPES = ("desired", "planned", "observed", "runtime")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def snapshot_meta(graph: Graph, *, source: str = "",
|
|
27
|
+
source_type: str = "desired", environment: str = "",
|
|
28
|
+
workspace: str = "", commit: str = "", provider: str = "",
|
|
29
|
+
scope: str = "", fact_ids: list[str] | None = None,
|
|
30
|
+
) -> dict[str, Any]:
|
|
31
|
+
if source_type not in SOURCE_TYPES:
|
|
32
|
+
raise ValueError(f"source_type must be one of {SOURCE_TYPES}")
|
|
33
|
+
all_fids = sorted({fid for n in graph.nodes.values()
|
|
34
|
+
for fid in getattr(n, "source_fact_ids", ())})
|
|
35
|
+
return {
|
|
36
|
+
"snapshot_id": f"gsnap-{graph.graph_hash[:16]}",
|
|
37
|
+
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
|
38
|
+
"source": source, "source_type": source_type,
|
|
39
|
+
"environment": environment, "workspace": workspace,
|
|
40
|
+
"commit": commit, "provider": provider, "scope": scope,
|
|
41
|
+
"graph_hash": graph.graph_hash,
|
|
42
|
+
"fact_ids": sorted(set(fact_ids or all_fids)),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def save(graph: Graph, root: str | Path, name: str = "current",
|
|
47
|
+
**meta_kwargs: Any) -> Path:
|
|
48
|
+
d = Path(root) / GRAPH_DIR
|
|
49
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
p = d / f"{name}.json"
|
|
51
|
+
p.write_text(graph.to_json() + "\n")
|
|
52
|
+
snap = d / "snapshots" / f"{graph.graph_hash}.json"
|
|
53
|
+
meta = d / "snapshots" / f"{graph.graph_hash}.meta.json"
|
|
54
|
+
if not snap.exists():
|
|
55
|
+
snap.parent.mkdir(parents=True, exist_ok=True)
|
|
56
|
+
snap.write_text(graph.to_json() + "\n")
|
|
57
|
+
meta.write_text(json.dumps(snapshot_meta(graph, **meta_kwargs),
|
|
58
|
+
indent=2, sort_keys=True) + "\n")
|
|
59
|
+
return p
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def load(root: str | Path, name: str = "current") -> Graph:
|
|
63
|
+
p = Path(root) / GRAPH_DIR / f"{name}.json"
|
|
64
|
+
if not p.exists():
|
|
65
|
+
raise FileNotFoundError(f"no graph named {name!r}")
|
|
66
|
+
return Graph.from_dict(json.loads(p.read_text()))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def load_snapshot(root: str | Path, graph_hash: str) -> Graph:
|
|
70
|
+
p = Path(root) / GRAPH_DIR / "snapshots" / f"{graph_hash}.json"
|
|
71
|
+
if not p.exists():
|
|
72
|
+
raise FileNotFoundError(f"no snapshot {graph_hash}")
|
|
73
|
+
return Graph.from_dict(json.loads(p.read_text()))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def snapshot_meta_of(root: str | Path, graph_hash: str) -> dict[str, Any]:
|
|
77
|
+
p = Path(root) / GRAPH_DIR / "snapshots" / f"{graph_hash}.meta.json"
|
|
78
|
+
if not p.exists():
|
|
79
|
+
return {}
|
|
80
|
+
return json.loads(p.read_text())
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def snapshots(root: str | Path) -> list[dict[str, Any]]:
|
|
84
|
+
d = Path(root) / GRAPH_DIR / "snapshots"
|
|
85
|
+
if not d.exists():
|
|
86
|
+
return []
|
|
87
|
+
out = []
|
|
88
|
+
for p in sorted(d.glob("*.json")):
|
|
89
|
+
if p.name.endswith(".meta.json"):
|
|
90
|
+
continue
|
|
91
|
+
entry: dict[str, Any] = {
|
|
92
|
+
"graph_hash": p.stem,
|
|
93
|
+
"saved_at": time.strftime(
|
|
94
|
+
"%Y-%m-%dT%H:%M:%SZ", time.gmtime(p.stat().st_mtime))}
|
|
95
|
+
entry.update(snapshot_meta_of(root, p.stem))
|
|
96
|
+
out.append(entry)
|
|
97
|
+
return out
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""Graph queries: deps, dependents, paths, blast radius, gap detectors.
|
|
2
|
+
|
|
3
|
+
Discipline (GRAPHFY.md): proximity is not causality — blast radius is
|
|
4
|
+
reported per impact class and per hop, never as one merged number."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections import deque
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from platformforge.graph.model import Edge, Graph, impact_class
|
|
12
|
+
|
|
13
|
+
DEPENDENCY_KINDS = frozenset(
|
|
14
|
+
["depends_on", "calls", "consumes", "reads", "writes", "uses_secret", "runs_on", "contained_by", "routes_to", "publishes_to", "provisioned_by"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _adj(g: Graph, reverse: bool = False,
|
|
18
|
+
kinds: frozenset[str] | None = None) -> dict[str, list[Edge]]:
|
|
19
|
+
adj: dict[str, list[Edge]] = {nid: [] for nid in g.nodes}
|
|
20
|
+
for e in g.edges.values():
|
|
21
|
+
if kinds is not None and e.kind not in kinds:
|
|
22
|
+
continue
|
|
23
|
+
(adj[e.dst] if reverse else adj[e.src]).append(e)
|
|
24
|
+
return adj
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def neighbors(g: Graph, nid: str, kind: str | None = None) -> list[Edge]:
|
|
28
|
+
return [e for e in _adj(g)[nid] if kind is None or e.kind == kind]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def dependencies(g: Graph, nid: str, transitive: bool = True,
|
|
32
|
+
max_depth: int = 64) -> dict[str, int]:
|
|
33
|
+
"""BFS downstream (what nid depends on) → {node_id: depth}."""
|
|
34
|
+
return _reach(g, nid, reverse=False, max_depth=max_depth) \
|
|
35
|
+
if transitive else {e.dst: 1 for e in
|
|
36
|
+
_adj(g, kinds=DEPENDENCY_KINDS)[nid]}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def dependents(g: Graph, nid: str, transitive: bool = True,
|
|
40
|
+
max_depth: int = 64) -> dict[str, int]:
|
|
41
|
+
"""BFS upstream (what depends on nid) → {node_id: depth}."""
|
|
42
|
+
return _reach(g, nid, reverse=True, max_depth=max_depth) \
|
|
43
|
+
if transitive else {e.src: 1 for e in
|
|
44
|
+
_adj(g, reverse=True,
|
|
45
|
+
kinds=DEPENDENCY_KINDS)[nid]}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _reach(g: Graph, nid: str, reverse: bool, max_depth: int,
|
|
49
|
+
kinds: frozenset[str] | None = DEPENDENCY_KINDS) -> dict[str, int]:
|
|
50
|
+
adj = _adj(g, reverse, kinds)
|
|
51
|
+
seen: dict[str, int] = {}
|
|
52
|
+
q: deque[tuple[str, int]] = deque([(nid, 0)])
|
|
53
|
+
while q:
|
|
54
|
+
cur, d = q.popleft()
|
|
55
|
+
if d >= max_depth:
|
|
56
|
+
continue
|
|
57
|
+
for e in adj.get(cur, []):
|
|
58
|
+
nxt = e.src if reverse else e.dst
|
|
59
|
+
if nxt not in seen and nxt != nid:
|
|
60
|
+
seen[nxt] = d + 1
|
|
61
|
+
q.append((nxt, d + 1))
|
|
62
|
+
return seen
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def paths(g: Graph, src: str, dst: str, max_paths: int = 16,
|
|
66
|
+
max_depth: int = 32) -> list[list[str]]:
|
|
67
|
+
"""Up to `max_paths` simple src→dst paths, shortest-first (BFS).
|
|
68
|
+
A work cap keeps dense graphs bounded — the freeze dogfood bench
|
|
69
|
+
showed DFS wandering for minutes before reaching a near dst."""
|
|
70
|
+
out: list[list[str]] = []
|
|
71
|
+
adj = _adj(g)
|
|
72
|
+
q = deque([(src, [src])])
|
|
73
|
+
expansions = 0
|
|
74
|
+
while q and len(out) < max_paths and expansions < 200_000:
|
|
75
|
+
cur, path = q.popleft()
|
|
76
|
+
expansions += 1
|
|
77
|
+
if cur == dst:
|
|
78
|
+
out.append(path)
|
|
79
|
+
continue
|
|
80
|
+
if len(path) > max_depth:
|
|
81
|
+
continue
|
|
82
|
+
for e in adj.get(cur, []):
|
|
83
|
+
if e.dst not in path:
|
|
84
|
+
q.append((e.dst, path + [e.dst]))
|
|
85
|
+
return out
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def blast_radius(g: Graph, nid: str, max_depth: int = 64) -> dict[str, Any]:
|
|
89
|
+
"""What breaks if nid breaks: upstream dependents (things that depend on
|
|
90
|
+
nid) decomposed by impact class and hop distance."""
|
|
91
|
+
adj_rev = _adj(g, reverse=True, kinds=DEPENDENCY_KINDS)
|
|
92
|
+
seen: dict[str, dict[str, Any]] = {}
|
|
93
|
+
q: deque[tuple[str, int, Edge | None]] = deque([(nid, 0, None)])
|
|
94
|
+
while q:
|
|
95
|
+
cur, d, _via = q.popleft()
|
|
96
|
+
if d >= max_depth:
|
|
97
|
+
continue
|
|
98
|
+
for e in adj_rev.get(cur, []):
|
|
99
|
+
if e.src == nid or e.src in seen:
|
|
100
|
+
continue
|
|
101
|
+
seen[e.src] = {"depth": d + 1,
|
|
102
|
+
"impact_class": impact_class(e.kind),
|
|
103
|
+
"via_edge": e.eid, "provenance": e.provenance}
|
|
104
|
+
q.append((e.src, d + 1, e))
|
|
105
|
+
by_class: dict[str, list[str]] = {}
|
|
106
|
+
for target, info in seen.items():
|
|
107
|
+
by_class.setdefault(info["impact_class"], []).append(target)
|
|
108
|
+
return {
|
|
109
|
+
"origin": nid,
|
|
110
|
+
"impacted_total": len(seen),
|
|
111
|
+
"by_class": {k: sorted(v) for k, v in sorted(by_class.items())},
|
|
112
|
+
"nodes": {k: seen[k] for k in sorted(seen)},
|
|
113
|
+
"note": "graph proximity is not proven causality; classes are "
|
|
114
|
+
"reported separately",
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def cycles(g: Graph, max_cycles: int = 100) -> list[list[str]]:
|
|
119
|
+
"""Detect dependency cycles via DFS (bounded)."""
|
|
120
|
+
color: dict[str, int] = {}
|
|
121
|
+
out: list[list[str]] = []
|
|
122
|
+
adj = _adj(g, kinds=DEPENDENCY_KINDS)
|
|
123
|
+
|
|
124
|
+
def dfs(u: str, stack: list[str]) -> None:
|
|
125
|
+
color[u] = 1
|
|
126
|
+
for e in adj.get(u, []):
|
|
127
|
+
if len(out) >= max_cycles:
|
|
128
|
+
return
|
|
129
|
+
if color.get(e.dst, 0) == 1 and e.dst in stack:
|
|
130
|
+
out.append(stack[stack.index(e.dst):] + [e.dst])
|
|
131
|
+
elif color.get(e.dst, 0) == 0:
|
|
132
|
+
dfs(e.dst, stack + [e.dst])
|
|
133
|
+
color[u] = 2
|
|
134
|
+
|
|
135
|
+
for n in sorted(g.nodes):
|
|
136
|
+
if color.get(n, 0) == 0 and len(out) < max_cycles:
|
|
137
|
+
dfs(n, [n])
|
|
138
|
+
return out
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def condensation(g: Graph,
|
|
142
|
+
kinds: frozenset[str] | None = DEPENDENCY_KINDS):
|
|
143
|
+
"""SCC condensation of the dependency graph (iterative Tarjan).
|
|
144
|
+
|
|
145
|
+
Returns (node→scc int, members per scc, condensed reverse adjacency
|
|
146
|
+
scc→[parent sccs]). Nodes inside one SCC reach each other, so every
|
|
147
|
+
blast cone decomposes as: own SCC members + members of ancestor SCCs.
|
|
148
|
+
"""
|
|
149
|
+
adj_fwd: dict[str, list[str]] = {n: [] for n in g.nodes}
|
|
150
|
+
for e in g.edges.values():
|
|
151
|
+
if kinds is None or e.kind in kinds:
|
|
152
|
+
adj_fwd[e.src].append(e.dst)
|
|
153
|
+
index: dict[str, int] = {}
|
|
154
|
+
low: dict[str, int] = {}
|
|
155
|
+
on_stack: set[str] = set()
|
|
156
|
+
stack: list[str] = []
|
|
157
|
+
scc_of: dict[str, int] = {}
|
|
158
|
+
members: list[list[str]] = []
|
|
159
|
+
t = 0
|
|
160
|
+
for root in g.nodes:
|
|
161
|
+
if root in index:
|
|
162
|
+
continue
|
|
163
|
+
work = [(root, 0)]
|
|
164
|
+
while work:
|
|
165
|
+
u, pi = work[-1]
|
|
166
|
+
if pi == 0:
|
|
167
|
+
index[u] = low[u] = t; t += 1
|
|
168
|
+
stack.append(u); on_stack.add(u)
|
|
169
|
+
recurse = False
|
|
170
|
+
nbrs = adj_fwd.get(u, [])
|
|
171
|
+
for i in range(pi, len(nbrs)):
|
|
172
|
+
v = nbrs[i]
|
|
173
|
+
if v not in index:
|
|
174
|
+
work[-1] = (u, i + 1)
|
|
175
|
+
work.append((v, 0))
|
|
176
|
+
recurse = True
|
|
177
|
+
break
|
|
178
|
+
if v in on_stack:
|
|
179
|
+
low[u] = min(low[u], index[v])
|
|
180
|
+
if recurse:
|
|
181
|
+
continue
|
|
182
|
+
work.pop()
|
|
183
|
+
if work:
|
|
184
|
+
p = work[-1][0]
|
|
185
|
+
low[p] = min(low[p], low[u])
|
|
186
|
+
if low[u] == index[u]:
|
|
187
|
+
comp = []
|
|
188
|
+
while True:
|
|
189
|
+
w = stack.pop()
|
|
190
|
+
on_stack.discard(w)
|
|
191
|
+
scc_of[w] = len(members)
|
|
192
|
+
comp.append(w)
|
|
193
|
+
if w == u:
|
|
194
|
+
break
|
|
195
|
+
members.append(comp)
|
|
196
|
+
rev: dict[int, list[int]] = {i: [] for i in range(len(members))}
|
|
197
|
+
seen_pair: set[tuple[int, int]] = set()
|
|
198
|
+
for e in g.edges.values():
|
|
199
|
+
if kinds is not None and e.kind not in kinds:
|
|
200
|
+
continue
|
|
201
|
+
a, b = scc_of.get(e.dst), scc_of.get(e.src)
|
|
202
|
+
if a is not None and b is not None and a != b \
|
|
203
|
+
and (a, b) not in seen_pair:
|
|
204
|
+
seen_pair.add((a, b))
|
|
205
|
+
rev[a].append(b)
|
|
206
|
+
return scc_of, members, rev
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _articulation_points(g: Graph) -> list[str]:
|
|
210
|
+
"""Undirected cut vertices (iterative Tarjan) — nodes whose removal
|
|
211
|
+
increases the component count of the dependency graph."""
|
|
212
|
+
adj: dict[str, set[str]] = {n: set() for n in g.nodes}
|
|
213
|
+
for e in g.edges.values():
|
|
214
|
+
if e.kind in DEPENDENCY_KINDS:
|
|
215
|
+
adj[e.src].add(e.dst)
|
|
216
|
+
adj[e.dst].add(e.src)
|
|
217
|
+
disc: dict[str, int] = {}
|
|
218
|
+
low: dict[str, int] = {}
|
|
219
|
+
parent: dict[str, str] = {}
|
|
220
|
+
aps: set[str] = set()
|
|
221
|
+
t = 0
|
|
222
|
+
for root in g.nodes:
|
|
223
|
+
if root in disc:
|
|
224
|
+
continue
|
|
225
|
+
stack = [(root, iter(sorted(adj[root])))]
|
|
226
|
+
disc[root] = low[root] = t; t += 1
|
|
227
|
+
parent[root] = ""
|
|
228
|
+
children = 0
|
|
229
|
+
while stack:
|
|
230
|
+
u, it = stack[-1]
|
|
231
|
+
advanced = False
|
|
232
|
+
for v in it:
|
|
233
|
+
if v not in disc:
|
|
234
|
+
parent[v] = u
|
|
235
|
+
children += 1 if u == root else 0
|
|
236
|
+
disc[v] = low[v] = t; t += 1
|
|
237
|
+
stack.append((v, iter(sorted(adj[v]))))
|
|
238
|
+
advanced = True
|
|
239
|
+
break
|
|
240
|
+
if v != parent.get(u):
|
|
241
|
+
low[u] = min(low[u], disc[v])
|
|
242
|
+
if not advanced:
|
|
243
|
+
stack.pop()
|
|
244
|
+
if stack:
|
|
245
|
+
p = stack[-1][0]
|
|
246
|
+
low[p] = min(low[p], low[u])
|
|
247
|
+
if p != root and low[u] >= disc[p]:
|
|
248
|
+
aps.add(p)
|
|
249
|
+
if children > 1:
|
|
250
|
+
aps.add(root)
|
|
251
|
+
return sorted(aps)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def gaps(g: Graph) -> dict[str, Any]:
|
|
255
|
+
"""Structural gaps: orphans, missing ownership/observability/protection,
|
|
256
|
+
unallocated cost, external exposure, single points of failure,
|
|
257
|
+
unreachable resources."""
|
|
258
|
+
fwd = _adj(g)
|
|
259
|
+
inbound = _adj(g, reverse=True)
|
|
260
|
+
orphans = [n for n in g.nodes if not fwd[n] and not inbound[n]]
|
|
261
|
+
owned = {e.dst for e in g.edges.values() if e.kind == "owns"}
|
|
262
|
+
observed = {e.src for e in g.edges.values() if e.kind == "observed_by"} | \
|
|
263
|
+
{e.dst for e in g.edges.values() if e.kind == "observed_by"}
|
|
264
|
+
secured = {e.src for e in g.edges.values() if e.kind == "secured_by"}
|
|
265
|
+
billed = {e.src for e in g.edges.values() if e.kind == "billed_to"}
|
|
266
|
+
exposed = {e.src for e in g.edges.values() if e.kind == "exposes"} | \
|
|
267
|
+
{nid for nid, n in g.nodes.items() if n.attrs.get("public")}
|
|
268
|
+
workloads = {nid for nid, n in g.nodes.items()
|
|
269
|
+
if n.kind in ("workload", "service", "component")}
|
|
270
|
+
resources = {nid for nid, n in g.nodes.items()
|
|
271
|
+
if n.kind in ("database", "bucket", "queue", "volume",
|
|
272
|
+
"cluster", "load_balancer")}
|
|
273
|
+
# unreachable: a workload/resource nothing depends on, calls, or
|
|
274
|
+
# exposes — present in the platform but dead-ended from consumers.
|
|
275
|
+
unreachable = sorted(
|
|
276
|
+
n for n in workloads | resources
|
|
277
|
+
if n not in orphans and not inbound[n] and n not in exposed)
|
|
278
|
+
return {
|
|
279
|
+
"orphans": sorted(orphans),
|
|
280
|
+
"ownership_gaps": sorted(n for n in workloads | resources
|
|
281
|
+
if n not in owned),
|
|
282
|
+
"unmonitored": sorted(n for n in workloads if n not in observed),
|
|
283
|
+
"unprotected": sorted(n for n in workloads | resources
|
|
284
|
+
if n not in secured),
|
|
285
|
+
"unallocated_cost": sorted(n for n in workloads | resources
|
|
286
|
+
if n not in billed),
|
|
287
|
+
"external_exposure": sorted(exposed),
|
|
288
|
+
"single_points_of_failure": _articulation_points(g),
|
|
289
|
+
"unreachable": unreachable,
|
|
290
|
+
}
|