bugx-cli 0.0.0-stage → 0.1.1
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.
- package/LICENSE +55 -0
- package/README.md +284 -2
- package/core/CATALOG.json +141 -0
- package/core/README.md +254 -0
- package/core/adapters/README.md +35 -0
- package/core/adapters/android-interaction.json +81 -0
- package/core/adapters/android.json +24 -0
- package/core/adapters/desktop-macos.json +20 -0
- package/core/adapters/ios-interaction.json +34 -0
- package/core/adapters/ios.json +23 -0
- package/core/adapters/memory-macos.json +24 -0
- package/core/agent/README.md +51 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +766 -0
- package/core/agent/agent_eval.py +1155 -0
- package/core/agent/agent_execution.py +718 -0
- package/core/agent/agent_orchestrator.py +1351 -0
- package/core/agent/agent_targets.py +877 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +24 -0
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-avatar-1024.png +0 -0
- package/core/assets/bugx-avatar-512.png +0 -0
- package/core/assets/bugx-avatar-tight.svg +23 -0
- package/core/assets/bugx-avatar.svg +28 -0
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/project-layout.md +42 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/audit_packs/README.md +37 -0
- package/core/audit_packs/data-audit/manifest.json +94 -0
- package/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- package/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- package/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/desktop-audit/manifest.json +123 -0
- package/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- package/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- package/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- package/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- package/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- package/core/audit_packs/memory-testing.md +227 -0
- package/core/audit_packs/mobile-audit/manifest.json +155 -0
- package/core/audit_packs/mobile-audit/modules/android.md +19 -0
- package/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- package/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- package/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- package/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- package/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- package/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- package/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- package/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- package/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- package/core/audit_packs/native-audit/manifest.json +127 -0
- package/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- package/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- package/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- package/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- package/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- package/core/audit_packs/platform-testing.md +174 -0
- package/core/audit_packs/web-audit/manifest.json +191 -0
- package/core/audit_packs/web-audit/modules/graphql.md +5 -0
- package/core/audit_packs/web-audit/modules/h5.md +18 -0
- package/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- package/core/audit_packs/web-audit/modules/oauth.md +4 -0
- package/core/audit_packs/web-audit/modules/upload.md +4 -0
- package/core/audit_packs/web-audit/modules/websocket.md +4 -0
- package/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- package/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- package/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- package/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- package/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- package/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- package/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- package/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- package/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- package/core/autonomous_cve/INTERFACE.md +61 -0
- package/core/autonomous_cve/README.md +58 -0
- package/core/autonomous_cve/SPEC.md +25 -0
- package/core/autonomous_cve/__init__.py +109 -0
- package/core/autonomous_cve/attack_graph.py +1096 -0
- package/core/autonomous_cve/attack_graph_store.py +1868 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +465 -0
- package/core/autonomous_cve/ghsa_advisories.py +174 -0
- package/core/autonomous_cve/models.py +93 -0
- package/core/autonomous_cve/mutator.py +87 -0
- package/core/autonomous_cve/patcher.py +126 -0
- package/core/autonomous_cve/scout.py +278 -0
- package/core/autonomous_cve/synthesizer.py +207 -0
- package/core/autonomous_cve/verifier.py +103 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1881 -0
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/INTERFACE.md +32 -0
- package/core/cloud_sync/README.md +62 -0
- package/core/cloud_sync/SPEC.md +25 -0
- package/core/cloud_sync/__init__.py +23 -0
- package/core/cloud_sync/auto_sync.py +398 -0
- package/core/cloud_sync/cloud_client.py +1218 -0
- package/core/cloud_sync/cloud_onboard.py +743 -0
- package/core/cloud_sync/cloud_schema.py +648 -0
- package/core/cloud_sync/consent.py +81 -0
- package/core/cloud_sync/device_identity.py +307 -0
- package/core/cloud_sync/endpoint_router.py +415 -0
- package/core/cloud_sync/flywheel_client.py +769 -0
- package/core/cloud_sync/network_transport.py +296 -0
- package/core/cloud_sync/onboard_wizard.py +493 -0
- package/core/cloud_sync/sensitive_filter.py +285 -0
- package/core/cloud_sync/sync_pull.py +695 -0
- package/core/cloud_sync/sync_push.py +723 -0
- package/core/contracts/AGENT_GUIDE.md +359 -0
- package/core/contracts/README.md +34 -0
- package/core/contracts/bugx-blackbox.md +541 -0
- package/core/contracts/bugx-opencode.md +469 -0
- package/core/contracts/bugx-quick.md +44 -0
- package/core/contracts/bugx-runtime-contract.md +353 -0
- package/core/contracts/bugx-worker.md +470 -0
- package/core/contracts/engine_gap_contracts.py +473 -0
- package/core/coverage/README.md +70 -0
- package/core/coverage/__init__.py +106 -0
- package/core/coverage/coverage_ai_review.py +185 -0
- package/core/coverage/coverage_backfill.py +54 -0
- package/core/coverage/coverage_bootstrap.py +713 -0
- package/core/coverage/coverage_business.py +36 -0
- package/core/coverage/coverage_cli.py +715 -0
- package/core/coverage/coverage_discovery.py +1429 -0
- package/core/coverage/coverage_evidence.py +1024 -0
- package/core/coverage/coverage_forensics.py +124 -0
- package/core/coverage/coverage_gate.py +277 -0
- package/core/coverage/coverage_intelligence.py +734 -0
- package/core/coverage/coverage_manifest.py +396 -0
- package/core/coverage/coverage_platform.py +77 -0
- package/core/coverage/coverage_validate.py +241 -0
- package/core/coverage/module_coverage.py +157 -0
- package/core/dev_harness/INTERFACE.md +20 -0
- package/core/dev_harness/README.md +21 -0
- package/core/dev_harness/SPEC.md +25 -0
- package/core/dev_harness/__init__.py +5 -0
- package/core/dev_harness/interaction_preset.py +408 -0
- package/core/engine-integrity.json +2797 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +435 -0
- package/core/fuzzing/differential_oracle.py +1164 -0
- package/core/fuzzing/fuzz_input.py +1291 -0
- package/core/fuzzing/stateful_fuzzer.py +404 -0
- package/core/governance/README.md +61 -0
- package/core/governance/__init__.py +130 -0
- package/core/governance/capacity_planner.py +124 -0
- package/core/governance/dependency_lock.py +317 -0
- package/core/governance/goal_governor.py +754 -0
- package/core/governance/guide_budget.py +458 -0
- package/core/governance/lockdown.sh +50 -0
- package/core/governance/readonly_enforcer.py +154 -0
- package/core/governance/runtime_tool_gate.py +373 -0
- package/core/governance/secret_redactor.py +784 -0
- package/core/governance/token_budget.py +38 -0
- package/core/host_acp/INTERFACE.md +36 -0
- package/core/host_acp/README.md +51 -0
- package/core/host_acp/SPEC.md +25 -0
- package/core/host_acp/__init__.py +121 -0
- package/core/host_acp/base.py +111 -0
- package/core/host_acp/claude.py +99 -0
- package/core/host_acp/cline.py +298 -0
- package/core/host_acp/codex.py +300 -0
- package/core/host_acp/dsh.py +106 -0
- package/core/host_acp/opencode.py +209 -0
- package/core/host_acp/pi.py +94 -0
- package/core/host_acp/zcode.py +99 -0
- package/core/host_runtime/INTERFACE.md +24 -0
- package/core/host_runtime/README.md +62 -0
- package/core/host_runtime/SPEC.md +25 -0
- package/core/host_runtime/__init__.py +21 -0
- package/core/host_runtime/adapters.py +412 -0
- package/core/host_runtime/autonomous_runner.py +1152 -0
- package/core/host_runtime/cline.py +448 -0
- package/core/host_runtime/common.py +103 -0
- package/core/host_runtime/free_models.py +786 -0
- package/core/host_runtime/host_bootstrap.py +389 -0
- package/core/host_runtime/host_evaluators.py +761 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +831 -0
- package/core/host_runtime/host_registry.py +662 -0
- package/core/host_runtime/host_usage.py +127 -0
- package/core/host_runtime/mcp_process_tracker.py +509 -0
- package/core/host_runtime/mcp_registry_gate.py +379 -0
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/INTERFACE.md +51 -0
- package/core/hosts/README.md +67 -0
- package/core/hosts/SPEC.md +25 -0
- package/core/hosts/__init__.py +140 -0
- package/core/hosts/_base_usage.py +152 -0
- package/core/hosts/_codex_usage.py +297 -0
- package/core/hosts/_dsh_usage.py +184 -0
- package/core/hosts/_mcp_toml.py +365 -0
- package/core/hosts/_zcode_usage.py +269 -0
- package/core/hosts/base.py +479 -0
- package/core/hosts/claude.py +212 -0
- package/core/hosts/cline.py +229 -0
- package/core/hosts/codex.py +1006 -0
- package/core/hosts/dsh.py +526 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +308 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +41 -0
- package/core/infra/__init__.py +17 -0
- package/core/infra/build_info.py +105 -0
- package/core/infra/client_metadata.py +185 -0
- package/core/infra/json_utils.py +22 -0
- package/core/infra/python_runtime.py +540 -0
- package/core/infra/safe_xml.py +221 -0
- package/core/launch_bugx.py +118 -0
- package/core/launch_phases/INTERFACE.md +31 -0
- package/core/launch_phases/README.md +106 -0
- package/core/launch_phases/SPEC.md +25 -0
- package/core/launch_phases/__init__.py +29 -0
- package/core/launch_phases/candidate_revalidation.py +484 -0
- package/core/launch_phases/common.py +1060 -0
- package/core/launch_phases/finding_confirm_phase.py +391 -0
- package/core/launch_phases/finding_settlement.py +1432 -0
- package/core/launch_phases/findings_adjudication.py +666 -0
- package/core/launch_phases/findings_snapshot.py +357 -0
- package/core/launch_phases/judge_phase.py +848 -0
- package/core/launch_phases/lesson_context.py +536 -0
- package/core/launch_phases/lifecycle_reporter.py +627 -0
- package/core/launch_phases/orchestrator_controls.py +686 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +598 -0
- package/core/launch_phases/post_dry_run.py +817 -0
- package/core/launch_phases/post_observability.py +367 -0
- package/core/launch_phases/post_phase.py +1223 -0
- package/core/launch_phases/post_receipt.py +373 -0
- package/core/launch_phases/post_round_lifecycle.py +786 -0
- package/core/launch_phases/pre_phase.py +1029 -0
- package/core/launch_phases/pre_recon_scout.py +879 -0
- package/core/launch_phases/pre_state_builder.py +1133 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1116 -0
- package/core/launch_phases/session_runtime.py +1670 -0
- package/core/launch_phases/startup_gates.py +1050 -0
- package/core/launch_phases/startup_interaction.py +1003 -0
- package/core/launch_phases/startup_version_gate.py +879 -0
- package/core/launch_phases/supervisor_bridge.py +1253 -0
- package/core/launch_phases/supervisor_coverage.py +423 -0
- package/core/launch_phases/supervisor_degraded.py +1211 -0
- package/core/launch_phases/worker_barriers.py +424 -0
- package/core/launch_phases/worker_orchestrator.py +1246 -0
- package/core/launch_phases/worker_prior.py +749 -0
- package/core/ledger/INTERFACE.md +35 -0
- package/core/ledger/README.md +160 -0
- package/core/ledger/SPEC.md +25 -0
- package/core/ledger/__init__.py +67 -0
- package/core/ledger/_facade.py +227 -0
- package/core/ledger/archive_ops.py +630 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +275 -0
- package/core/ledger/export_ops.py +554 -0
- package/core/ledger/finding_confirmation.py +1316 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +730 -0
- package/core/ledger/finding_verification.py +405 -0
- package/core/ledger/incidents.py +1005 -0
- package/core/ledger/lesson-replay-cases.json +20 -0
- package/core/ledger/lesson_ledger.py +241 -0
- package/core/ledger/lesson_replay.py +272 -0
- package/core/ledger/life_ledger.py +668 -0
- package/core/ledger/mistake-book.md +130 -0
- package/core/ledger/patterns.py +684 -0
- package/core/ledger/receipt_contract.py +269 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +940 -0
- package/core/ledger/tool_experience.py +683 -0
- package/core/ledger/verify_life.py +1597 -0
- package/core/lesson-ledger.json +275 -0
- package/core/locales/README.md +19 -0
- package/core/locales/en-US.json +462 -0
- package/core/locales/zh-CN.json +462 -0
- package/core/mcp_handlers/INTERFACE.md +75 -0
- package/core/mcp_handlers/README.md +62 -0
- package/core/mcp_handlers/SPEC.md +25 -0
- package/core/mcp_handlers/__init__.py +128 -0
- package/core/mcp_handlers/base.py +717 -0
- package/core/mcp_handlers/channel_lifecycle.py +751 -0
- package/core/mcp_handlers/graph_handlers.py +222 -0
- package/core/mcp_handlers/knowledge_handlers.py +536 -0
- package/core/mcp_handlers/mining_handlers.py +586 -0
- package/core/mcp_handlers/resource_prompt_table.py +116 -0
- package/core/mcp_handlers/retrieval_handlers.py +249 -0
- package/core/mcp_handlers/rpc_server.py +470 -0
- package/core/mcp_handlers/supervisor_handlers.py +1461 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1030 -0
- package/core/mcp_runtime_support/README.md +21 -0
- package/core/mcp_runtime_support/__init__.py +1 -0
- package/core/mcp_runtime_support/common.py +363 -0
- package/core/mcp_runtime_support/environment.py +567 -0
- package/core/mcp_runtime_support/verifier.py +758 -0
- package/core/metadata.txt +4 -0
- package/core/planning/README.md +157 -0
- package/core/planning/__init__.py +242 -0
- package/core/planning/capability_plan.py +187 -0
- package/core/planning/capability_planner.py +195 -0
- package/core/planning/domain_archetype.py +542 -0
- package/core/planning/domain_router.py +269 -0
- package/core/planning/dynamic_flow_analyzer.py +533 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1246 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1704 -0
- package/core/planning/source_inspector.py +267 -0
- package/core/planning/spec_harvester.py +449 -0
- package/core/planning/target_sandbox_manager.py +573 -0
- package/core/planning/test_capability_verifier.py +1364 -0
- package/core/planning/tools-kb.md +38 -0
- package/core/planning/unit_kind.py +122 -0
- package/core/probes/INTERFACE.md +83 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +36 -0
- package/core/probes/__init__.py +76 -0
- package/core/probes/android_probe.py +552 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +647 -0
- package/core/probes/desktop_probe.py +342 -0
- package/core/probes/differential_probe.py +434 -0
- package/core/probes/efficiency_probe.py +232 -0
- package/core/probes/ios_binary_probe.py +472 -0
- package/core/probes/memory_probe.py +392 -0
- package/core/probes/miniprogram_probe.py +385 -0
- package/core/probes/mobile_probe.py +466 -0
- package/core/probes/native_probe.py +302 -0
- package/core/probes/openwiki_probe.py +263 -0
- package/core/probes/pattern_probe.py +453 -0
- package/core/probes/platform_probe.py +424 -0
- package/core/probes/probe_registry.py +1770 -0
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +1510 -0
- package/core/probes/sast_rules.py +1481 -0
- package/core/probes/sca_scanner.py +779 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +714 -0
- package/core/project_profiler/INTERFACE.md +62 -0
- package/core/project_profiler/README.md +53 -0
- package/core/project_profiler/SPEC.md +28 -0
- package/core/project_profiler/__init__.py +201 -0
- package/core/project_profiler/arbitrator.py +316 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +399 -0
- package/core/project_profiler/extractors.py +836 -0
- package/core/project_profiler/fingerprint.py +116 -0
- package/core/project_profiler/storage.py +258 -0
- package/core/project_profiler/strategy.py +301 -0
- package/core/prompts/README.md +35 -0
- package/core/prompts/codex_dialog_dispatch.md +9 -0
- package/core/prompts/command_routing_en.md +42 -0
- package/core/prompts/command_routing_zh.md +42 -0
- package/core/prompts/l0_router.md +47 -0
- package/core/prompts/rules/anti_patterns.md +16 -0
- package/core/prompts/rules/concurrency_rules.md +14 -0
- package/core/prompts/rules/memory_leak_rules.md +13 -0
- package/core/prompts/rules/prompt_injection_defense.md +13 -0
- package/core/prompts/stages/stage_explore.md +31 -0
- package/core/prompts/stages/stage_gate.md +43 -0
- package/core/prompts/stages/stage_mutate.md +42 -0
- package/core/prompts/stages/stage_repair.md +85 -0
- package/core/repair/README.md +74 -0
- package/core/repair/__init__.py +169 -0
- package/core/repair/fix_watchlist.py +391 -0
- package/core/repair/l7_dynamic.py +418 -0
- package/core/repair/l7_repair_loop.py +462 -0
- package/core/repair/l7_selfcheck.py +862 -0
- package/core/repair/minimize_repro.py +466 -0
- package/core/repair/patch_synthesizer.py +617 -0
- package/core/repair/regression_pack.py +379 -0
- package/core/repair/rsi_fixer.py +910 -0
- package/core/repair/rsi_loop.py +311 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +281 -0
- package/core/repair/self_heal.py +604 -0
- package/core/repair/test_generator.py +1108 -0
- package/core/repair/test_quality_auditor.py +410 -0
- package/core/repair/test_strategy.py +511 -0
- package/core/report_engine/INTERFACE.md +59 -0
- package/core/report_engine/README.md +69 -0
- package/core/report_engine/SPEC.md +28 -0
- package/core/report_engine/__init__.py +47 -0
- package/core/report_engine/attestation.py +228 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +418 -0
- package/core/report_engine/formal_report_builder.py +924 -0
- package/core/report_engine/html_renderers.py +696 -0
- package/core/report_engine/models.py +759 -0
- package/core/report_engine/pdf_exporter.py +231 -0
- package/core/report_engine/projects_assets.py +730 -0
- package/core/report_engine/report_client.py +743 -0
- package/core/report_engine/report_data_builder.py +388 -0
- package/core/report_engine/report_share.py +459 -0
- package/core/report_engine/sast_bridge.py +116 -0
- package/core/report_engine/server.py +832 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +168 -0
- package/core/report_engine/web_conformance.py +428 -0
- package/core/report_engine/workbench_assets.py +484 -0
- package/core/retrieval/INTERFACE.md +20 -0
- package/core/retrieval/README.md +161 -0
- package/core/retrieval/SPEC.md +25 -0
- package/core/retrieval/__init__.py +3 -0
- package/core/retrieval/code_analyzer.py +1720 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +240 -0
- package/core/retrieval/corpus_fetch.py +369 -0
- package/core/retrieval/graph_ego.py +597 -0
- package/core/retrieval/knowledge_auto.py +662 -0
- package/core/retrieval/knowledge_sources.py +168 -0
- package/core/retrieval/knowledge_sync.py +1003 -0
- package/core/retrieval/memory_store.py +480 -0
- package/core/retrieval/query_planner.py +1020 -0
- package/core/retrieval/rrf_engine.py +137 -0
- package/core/retrieval/slice_extractor.py +1209 -0
- package/core/retrieval/slice_normalizer.py +373 -0
- package/core/retrieval/slice_spec.py +357 -0
- package/core/retrieval/symbol_index.py +1151 -0
- package/core/retrieval/universal_code_matcher.py +622 -0
- package/core/retrieval/xerj_bridge.py +476 -0
- package/core/retrieval/xerj_supervisor.py +362 -0
- package/core/rules/README.md +33 -0
- package/core/rules/ios/PROVENANCE.json +30 -0
- package/core/rules/ios/crypto.yaml +36 -0
- package/core/rules/ios/network.yaml +20 -0
- package/core/rules/ios/resilience.yaml +47 -0
- package/core/rules/ios/storage.yaml +48 -0
- package/core/rules/mastg/LICENSE +173 -0
- package/core/rules/mastg/PROVENANCE.json +270 -0
- package/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- package/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- package/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- package/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- package/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- package/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- package/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- package/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- package/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- package/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- package/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- package/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- package/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- package/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- package/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- package/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- package/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- package/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- package/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- package/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- package/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- package/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- package/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- package/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- package/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- package/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- package/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- package/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- package/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- package/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- package/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- package/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- package/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- package/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- package/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- package/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- package/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- package/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- package/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- package/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- package/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- package/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- package/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- package/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- package/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- package/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- package/core/rules/miniprogram/PROVENANCE.json +26 -0
- package/core/rules/miniprogram/network.yaml +37 -0
- package/core/rules/miniprogram/platform.yaml +36 -0
- package/core/rules/miniprogram/storage.yaml +48 -0
- package/core/rules/mobsfscan-swift/LICENSE +165 -0
- package/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- package/core/rules/mobsfscan-swift/auth.yaml +59 -0
- package/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- package/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- package/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- package/core/rules/mobsfscan-swift/logging.yaml +23 -0
- package/core/rules/mobsfscan-swift/network.yaml +55 -0
- package/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- package/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- package/core/rules/mobsfscan-swift/storage.yaml +29 -0
- package/core/rules/mobsfscan-swift/webview.yaml +32 -0
- package/core/runtime/README.md +198 -0
- package/core/runtime/__init__.py +3 -0
- package/core/runtime/bugx_logging.py +1464 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +444 -0
- package/core/runtime/global_telemetry.py +549 -0
- package/core/runtime/incident_eval.py +148 -0
- package/core/runtime/interaction.py +605 -0
- package/core/runtime/interaction_store.py +435 -0
- package/core/runtime/interactive_menu.py +95 -0
- package/core/runtime/log_analytics.py +922 -0
- package/core/runtime/mining_quality_framework.py +1387 -0
- package/core/runtime/model_runner.py +732 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +478 -0
- package/core/runtime/project_graph.py +827 -0
- package/core/runtime/project_init.py +481 -0
- package/core/runtime/project_profile.py +224 -0
- package/core/runtime/project_settings.py +964 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +856 -0
- package/core/runtime/seed_drill.py +549 -0
- package/core/runtime/self_audit.py +550 -0
- package/core/runtime/session_profile.py +205 -0
- package/core/runtime/setup_ui_env.py +229 -0
- package/core/runtime/startup_environment.py +859 -0
- package/core/runtime/sync_store.py +1421 -0
- package/core/runtime/tool_install_targets.py +18 -0
- package/core/schemas/README.md +35 -0
- package/core/schemas/agent-graph.schema.json +368 -0
- package/core/schemas/attack-graph.schema.json +88 -0
- package/core/schemas/evidence-bundle.schema.json +33 -0
- package/core/schemas/skill-pack.schema.json +230 -0
- package/core/schemas/worker-checkpoint.schema.json +119 -0
- package/core/secure_atomic.py +289 -0
- package/core/seed_corpus/README.md +55 -0
- package/core/seed_corpus/c.txt +29 -0
- package/core/seed_corpus/cpp.txt +32 -0
- package/core/seed_corpus/css.txt +70 -0
- package/core/seed_corpus/go.txt +46 -0
- package/core/seed_corpus/java.txt +30 -0
- package/core/seed_corpus/javascript.txt +55 -0
- package/core/seed_corpus/kotlin.txt +28 -0
- package/core/seed_corpus/python.txt +71 -0
- package/core/seed_corpus/rust.txt +53 -0
- package/core/seed_corpus/swift.txt +29 -0
- package/core/seed_corpus/typescript.txt +29 -0
- package/core/skills/README.md +53 -0
- package/core/skills/__init__.py +189 -0
- package/core/skills/bugx_docs_mcp_server.py +418 -0
- package/core/skills/bugx_mcp_server.py +1161 -0
- package/core/skills/mcp_runtime.py +968 -0
- package/core/skills/mcp_session_proof.py +605 -0
- package/core/skills/mobile_ui_inspector.py +405 -0
- package/core/skills/skill_pack.py +1214 -0
- package/core/skills/skill_synthesizer.py +1153 -0
- package/core/skills/tools_kb.py +313 -0
- package/core/supervisor/INTERFACE.md +121 -0
- package/core/supervisor/README.md +209 -0
- package/core/supervisor/SPEC.md +25 -0
- package/core/supervisor/__init__.py +175 -0
- package/core/supervisor/audit_supervisor.py +1015 -0
- package/core/supervisor/budget_governor.py +1254 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1564 -0
- package/core/supervisor/checkpoint_sync.py +653 -0
- package/core/supervisor/claim_events.py +74 -0
- package/core/supervisor/claim_sync.py +590 -0
- package/core/supervisor/cli.py +812 -0
- package/core/supervisor/context_sync.py +55 -0
- package/core/supervisor/coverage_sync.py +115 -0
- package/core/supervisor/finding_commit.py +470 -0
- package/core/supervisor/finding_sync.py +688 -0
- package/core/supervisor/finding_workflow.py +676 -0
- package/core/supervisor/finish_policy.py +224 -0
- package/core/supervisor/finish_sync.py +185 -0
- package/core/supervisor/graph_sync.py +669 -0
- package/core/supervisor/lease_manager.py +788 -0
- package/core/supervisor/lifecycle_blocks.py +129 -0
- package/core/supervisor/next_round_sync.py +126 -0
- package/core/supervisor/observability.py +140 -0
- package/core/supervisor/recovery_sync.py +165 -0
- package/core/supervisor/rejection_remedies.py +355 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +544 -0
- package/core/supervisor/start_sync.py +87 -0
- package/core/supervisor/state_store.py +249 -0
- package/core/supervisor/supervisor_host.py +511 -0
- package/core/supervisor/supervisor_models.py +1143 -0
- package/core/supervisor/systemic_failure.py +104 -0
- package/core/supervisor/task_scheduler.py +1640 -0
- package/core/supervisor/worker_checkpoint.py +230 -0
- package/core/supervisor/worker_execution.py +265 -0
- package/core/supervisor/worker_handoff.py +192 -0
- package/core/supervisor/worker_lifecycle.py +396 -0
- package/core/supervisor/worker_runtime.py +1005 -0
- package/core/supervisor/worker_sync.py +89 -0
- package/core/supervisor_types/README.md +36 -0
- package/core/supervisor_types/__init__.py +0 -0
- package/core/supervisor_types/exceptions.py +52 -0
- package/core/supervisor_types/graph_models.py +357 -0
- package/core/supervisor_types/path_containment.py +151 -0
- package/core/supervisor_types/target_fingerprint.py +310 -0
- package/core/supervisor_types/worker_claim.py +411 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +26 -0
- package/core/webui/__init__.py +11 -0
- package/core/webui/adapters/__init__.py +27 -0
- package/core/webui/adapters/base.py +87 -0
- package/core/webui/adapters/bugx.py +102 -0
- package/core/webui/adapters/claude.py +222 -0
- package/core/webui/adapters/cline.py +407 -0
- package/core/webui/adapters/codex.py +260 -0
- package/core/webui/adapters/dsh.py +177 -0
- package/core/webui/adapters/opencode.py +218 -0
- package/core/webui/adapters/pi.py +272 -0
- package/core/webui/adapters/registry.py +100 -0
- package/core/webui/adapters/zcode.py +312 -0
- package/core/webui/api_routes_post.py +668 -0
- package/core/webui/dispatcher.py +1376 -0
- package/core/webui/docs_session_service.py +473 -0
- package/core/webui/handler.py +674 -0
- package/core/webui/ide_cloud_service.py +526 -0
- package/core/webui/mcp_inspector.py +1747 -0
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- package/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- package/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- package/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- package/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +55 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.js +9602 -0
- package/core/webui/static/sw.js +8 -0
- package/core/webui/workspace_service.py +218 -0
- package/docs/07_distribution/01_README_NPM.md +285 -0
- package/ecosystem/README.md +129 -0
- package/ecosystem/integrations/README.md +38 -0
- package/ecosystem/integrations/cline/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/dsh/agents/bugx.md +27 -0
- package/ecosystem/integrations/dsh/dsh-patch.yml +18 -0
- package/ecosystem/integrations/dsh/mcp/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/mcp/index.js +219 -0
- package/ecosystem/integrations/dsh/mcp/package.json +28 -0
- package/ecosystem/integrations/dsh/skills/bugx/SKILL.md +70 -0
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/integrations/dsh/ui/client.js +87 -0
- package/ecosystem/integrations/dsh/ui/cordis.patch.yml +4 -0
- package/ecosystem/integrations/dsh/ui/index.js +7 -0
- package/ecosystem/integrations/dsh/ui/package.json +27 -0
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +53 -0
- package/ecosystem/integrations/opencode/mcp-lock.json +3075 -0
- package/ecosystem/integrations/opencode/opencode.json +129 -0
- package/ecosystem/integrations/pi/extensions/bugx/README.md +12 -0
- package/ecosystem/integrations/pi/extensions/bugx/index.ts +299 -0
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +11 -0
- package/ecosystem/integrations/pi/skills/bugx/SKILL.md +69 -0
- package/ecosystem/integrations/qoder/CONNECTORS.md +54 -0
- package/ecosystem/integrations/qoder/connector-meta.json +21 -0
- package/ecosystem/integrations/workbuddy/connector-meta.json +19 -0
- package/ecosystem/integrations/workbuddy/icon.png +0 -0
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +70 -0
- package/ecosystem/plugins/README.md +37 -0
- package/ecosystem/plugins/bugx/.claude-plugin/marketplace.json +17 -0
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +16 -0
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +41 -0
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +19 -0
- package/ecosystem/plugins/bugx/agents/bugx-judge.md +71 -0
- package/ecosystem/plugins/bugx/agents/bugx-worker.md +31 -0
- package/ecosystem/plugins/bugx/agents/bugx.md +74 -0
- package/ecosystem/plugins/bugx/assets/bugx-avatar-512.png +0 -0
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +118 -0
- package/ecosystem/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +229 -0
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- package/interfaces/bin/bugx.js +117 -0
- package/interfaces/cli/bugx_cli/__init__.py +6 -0
- package/interfaces/cli/bugx_cli/cli.py +1685 -0
- package/interfaces/cli/bugx_cli/commands/__init__.py +1 -0
- package/interfaces/cli/bugx_cli/commands/advisory.py +94 -0
- package/interfaces/cli/bugx_cli/commands/agent.py +4210 -0
- package/interfaces/cli/bugx_cli/commands/audit.py +632 -0
- package/interfaces/cli/bugx_cli/commands/autonomous.py +260 -0
- package/interfaces/cli/bugx_cli/commands/cloud.py +1371 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1590 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +248 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +619 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +2763 -0
- package/interfaces/cli/bugx_cli/commands/patch.py +1014 -0
- package/interfaces/cli/bugx_cli/commands/plugin.py +2749 -0
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +1446 -0
- package/interfaces/cli/bugx_cli/commands/plugin_cline.py +269 -0
- package/interfaces/cli/bugx_cli/commands/plugin_codex.py +74 -0
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +729 -0
- package/interfaces/cli/bugx_cli/commands/plugin_qoder.py +216 -0
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +710 -0
- package/interfaces/cli/bugx_cli/commands/project.py +670 -0
- package/interfaces/cli/bugx_cli/commands/report.py +256 -0
- package/interfaces/cli/bugx_cli/commands/skill.py +251 -0
- package/interfaces/cli/bugx_cli/commands/stats.py +133 -0
- package/interfaces/cli/bugx_cli/commands/system.py +2567 -0
- package/interfaces/cli/bugx_cli/common.py +906 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1892 -0
- package/interfaces/cli/bugx_cli/hosts/__init__.py +80 -0
- package/interfaces/cli/bugx_cli/hosts/base.py +99 -0
- package/interfaces/cli/bugx_cli/hosts/registry.py +573 -0
- package/interfaces/cli/bugx_cli/hosts/template_engine.py +188 -0
- package/interfaces/cli/bugx_cli/infra/__init__.py +209 -0
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +851 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1945 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +548 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +826 -0
- package/interfaces/cli/bugx_cli/infra/security.py +339 -0
- package/package.json +99 -4
- package/pyproject.toml +258 -0
- package/scripts/ensure-python.mjs +97 -0
- package/scripts/isolate-npm-readme.mjs +40 -0
- package/scripts/runtime.lock.json +31 -0
- package/scripts/sync-version.mjs +26 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,1015 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""外部 Supervisor:用独立预算协调并发 bugx worker。
|
|
3
|
+
|
|
4
|
+
这个模块故意不执行 worker 命令,也不访问网络。worker 只提交结构化的
|
|
5
|
+
checkpoint,Supervisor 在文件锁内串行合并结果,并把每次状态变化写入
|
|
6
|
+
带 hash-chain 的不可变审计历史。
|
|
7
|
+
|
|
8
|
+
设计约束:
|
|
9
|
+
|
|
10
|
+
* ``life_score`` 只是评分字段,永远不参与预算计算;
|
|
11
|
+
* 所有状态写入都经过 workspace 内的文件锁和 ``os.replace`` 原子替换;
|
|
12
|
+
* claim 是一次性的 worker 身份,过期 claim 只能被标记为 expired,不能重用;
|
|
13
|
+
* reset_budget 只创建新的预算 epoch,不删除 findings、coverage 或 history;
|
|
14
|
+
* 覆盖未完成时,finish 只能产生 INCOMPLETE 或 BUDGET_EXHAUSTED。
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
# --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
|
|
19
|
+
import sys as _sys
|
|
20
|
+
from pathlib import Path as _Path
|
|
21
|
+
|
|
22
|
+
for _p in _Path(__file__).resolve().parents:
|
|
23
|
+
if (_p / "core" / "bugx.md").is_file():
|
|
24
|
+
if str(_p) not in _sys.path:
|
|
25
|
+
_sys.path.insert(0, str(_p))
|
|
26
|
+
break
|
|
27
|
+
del _p
|
|
28
|
+
|
|
29
|
+
import sys
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
_CURRENT_DIR = Path(__file__).resolve().parent
|
|
33
|
+
_CORE_DIR = _CURRENT_DIR.parent
|
|
34
|
+
_REPO_ROOT = _CORE_DIR.parent
|
|
35
|
+
|
|
36
|
+
import copy
|
|
37
|
+
from core.ledger import finding_lifecycle
|
|
38
|
+
import argparse
|
|
39
|
+
import errno
|
|
40
|
+
import json
|
|
41
|
+
import math
|
|
42
|
+
import os
|
|
43
|
+
import re
|
|
44
|
+
import core.secure_atomic as secure_atomic
|
|
45
|
+
import subprocess
|
|
46
|
+
import threading
|
|
47
|
+
import time
|
|
48
|
+
import uuid
|
|
49
|
+
from core.planning import unit_kind
|
|
50
|
+
from datetime import datetime, timezone
|
|
51
|
+
from contextlib import contextmanager
|
|
52
|
+
from dataclasses import dataclass, field, replace
|
|
53
|
+
from enum import Enum
|
|
54
|
+
from pathlib import Path
|
|
55
|
+
from typing import Callable, Iterable, Mapping, Sequence
|
|
56
|
+
|
|
57
|
+
try: # pragma: no cover - the fallback is for non-POSIX importability.
|
|
58
|
+
import fcntl
|
|
59
|
+
except ImportError: # pragma: no cover
|
|
60
|
+
fcntl = None # type: ignore[assignment]
|
|
61
|
+
try: # pragma: no cover - Windows-only module.
|
|
62
|
+
import msvcrt
|
|
63
|
+
except ImportError: # pragma: no cover
|
|
64
|
+
msvcrt = None # type: ignore[assignment]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@contextmanager
|
|
68
|
+
def _bounded_os_file_lock(
|
|
69
|
+
descriptor: int, lock_path: Path, deadline: float, timeout: float, *, shared: bool,
|
|
70
|
+
):
|
|
71
|
+
if fcntl is not None:
|
|
72
|
+
operation = fcntl.LOCK_SH if shared else fcntl.LOCK_EX
|
|
73
|
+
delay = 0.05
|
|
74
|
+
while True:
|
|
75
|
+
try:
|
|
76
|
+
fcntl.flock(descriptor, operation | fcntl.LOCK_NB)
|
|
77
|
+
break
|
|
78
|
+
except OSError as exc:
|
|
79
|
+
if exc.errno not in (errno.EACCES, errno.EAGAIN):
|
|
80
|
+
raise
|
|
81
|
+
remaining = deadline - time.monotonic()
|
|
82
|
+
if remaining <= 0:
|
|
83
|
+
raise TimeoutError(
|
|
84
|
+
f"Supervisor lock acquisition exceeded {timeout:.3g}s: {lock_path}"
|
|
85
|
+
) from exc
|
|
86
|
+
time.sleep(min(delay, remaining))
|
|
87
|
+
delay = min(delay * 2, 0.5)
|
|
88
|
+
try:
|
|
89
|
+
yield
|
|
90
|
+
finally:
|
|
91
|
+
fcntl.flock(descriptor, fcntl.LOCK_UN)
|
|
92
|
+
elif msvcrt is not None: # pragma: no cover - Windows-only
|
|
93
|
+
delay = 0.05
|
|
94
|
+
while True:
|
|
95
|
+
try:
|
|
96
|
+
msvcrt.locking(descriptor, msvcrt.LK_NBLCK, 1)
|
|
97
|
+
break
|
|
98
|
+
except OSError as exc:
|
|
99
|
+
remaining = deadline - time.monotonic()
|
|
100
|
+
if remaining <= 0:
|
|
101
|
+
raise TimeoutError(
|
|
102
|
+
f"Supervisor lock acquisition exceeded {timeout:.3g}s: {lock_path}"
|
|
103
|
+
) from exc
|
|
104
|
+
time.sleep(min(delay, remaining))
|
|
105
|
+
delay = min(delay * 2, 0.5)
|
|
106
|
+
try:
|
|
107
|
+
yield
|
|
108
|
+
finally:
|
|
109
|
+
msvcrt.locking(descriptor, msvcrt.LK_UNLCK, 1)
|
|
110
|
+
else: # pragma: no cover - unsupported platform
|
|
111
|
+
raise OSError("Supervisor lock 在当前平台不可用(fcntl 和 msvcrt 均缺失)")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
from core.supervisor import (
|
|
115
|
+
checkpoint_handler,
|
|
116
|
+
finding_workflow,
|
|
117
|
+
lifecycle_blocks,
|
|
118
|
+
round_governor,
|
|
119
|
+
worker_lifecycle,
|
|
120
|
+
)
|
|
121
|
+
from core.supervisor.supervisor_models import (
|
|
122
|
+
SCHEMA_VERSION,
|
|
123
|
+
DEFAULT_STATE_RELATIVE_PATH,
|
|
124
|
+
LEGACY_STATE_RELATIVE_PATH,
|
|
125
|
+
COVERAGE_PENDING,
|
|
126
|
+
COVERAGE_COVERED,
|
|
127
|
+
COVERAGE_BLOCKED,
|
|
128
|
+
COVERAGE_UNVERIFIED,
|
|
129
|
+
COVERAGE_PARTIAL,
|
|
130
|
+
COVERAGE_NOT_APPLICABLE,
|
|
131
|
+
COVERAGE_STALE,
|
|
132
|
+
COVERAGE_REMOVED,
|
|
133
|
+
COVERAGE_SUPERSEDED,
|
|
134
|
+
COVERAGE_CORRUPTED,
|
|
135
|
+
VALID_COVERAGE_STATES,
|
|
136
|
+
UNIT_LEVEL_DEBT,
|
|
137
|
+
GLOBAL_BLOCKED,
|
|
138
|
+
TERMINAL_COVERED,
|
|
139
|
+
SHA256_RE,
|
|
140
|
+
MAX_SIGNATURES_PER_CHECKPOINT,
|
|
141
|
+
MAX_RECENT_SIGNATURES,
|
|
142
|
+
MAX_SIGNATURE_LENGTH,
|
|
143
|
+
MAX_UNIT_NOTES,
|
|
144
|
+
MAX_UNIT_NOTE_LENGTH,
|
|
145
|
+
note_requests_deep_verification,
|
|
146
|
+
MAX_FINDINGS_PER_CHECKPOINT,
|
|
147
|
+
MAX_COVERAGE_PER_CHECKPOINT,
|
|
148
|
+
MAX_EVIDENCE_PER_CHECKPOINT,
|
|
149
|
+
MAX_COMMAND_LENGTH,
|
|
150
|
+
MAX_ARTIFACT_PATH_LENGTH,
|
|
151
|
+
# Compatibility export: tests and older callers use the chunk-size constant.
|
|
152
|
+
ARTIFACT_HASH_CHUNK_BYTES,
|
|
153
|
+
MAX_FINDING_FINGERPRINT_LENGTH,
|
|
154
|
+
MAX_FINDING_FIELD_LENGTH,
|
|
155
|
+
MAX_JSON_DEPTH,
|
|
156
|
+
MAX_JSON_KEYS,
|
|
157
|
+
MAX_LEASE_SECONDS,
|
|
158
|
+
MAX_WORKER_ATTEMPTS,
|
|
159
|
+
MAX_LIFECYCLE_BLOCKED_PER_GATE,
|
|
160
|
+
MAX_LONG_CALL_SECONDS,
|
|
161
|
+
Status,
|
|
162
|
+
SupervisorError,
|
|
163
|
+
NoRunError,
|
|
164
|
+
RunAlreadyStarted,
|
|
165
|
+
InvalidTransition,
|
|
166
|
+
BudgetExhausted,
|
|
167
|
+
ClaimRejected,
|
|
168
|
+
LeaseExpired,
|
|
169
|
+
RevisionConflict,
|
|
170
|
+
InvalidCheckpoint,
|
|
171
|
+
PersistenceError,
|
|
172
|
+
WorkspacePathError,
|
|
173
|
+
ConcurrencyNotSatisfied,
|
|
174
|
+
canonical_json,
|
|
175
|
+
workspace_fingerprint,
|
|
176
|
+
target_identity,
|
|
177
|
+
invalidate_git_head_cache,
|
|
178
|
+
git_target_fingerprint,
|
|
179
|
+
finite_number,
|
|
180
|
+
check_depth_and_keys,
|
|
181
|
+
RunBudget,
|
|
182
|
+
WorkerClaim,
|
|
183
|
+
GraphRun,
|
|
184
|
+
GraphTask,
|
|
185
|
+
AgentBinding,
|
|
186
|
+
BugRecord,
|
|
187
|
+
load_unit_notes,
|
|
188
|
+
RunState,
|
|
189
|
+
event_hash,
|
|
190
|
+
validate_history,
|
|
191
|
+
confined_path,
|
|
192
|
+
has_lexical_symlink,
|
|
193
|
+
confined_regular_file,
|
|
194
|
+
worker_artifact_root,
|
|
195
|
+
default_coverage_manifest,
|
|
196
|
+
atomic_write_bytes,
|
|
197
|
+
resolve_system_concurrency,
|
|
198
|
+
process_start_token,
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _normalize_lexical_system_alias(path: Path) -> Path:
|
|
203
|
+
"""Normalize macOS /tmp and /var aliases without following user links."""
|
|
204
|
+
absolute = Path(os.path.abspath(str(path)))
|
|
205
|
+
if sys.platform != "darwin":
|
|
206
|
+
return absolute
|
|
207
|
+
for name in ("tmp", "var"):
|
|
208
|
+
alias = Path("/") / name
|
|
209
|
+
try:
|
|
210
|
+
if alias.resolve(strict=True) != Path("/private") / name:
|
|
211
|
+
continue
|
|
212
|
+
return (Path("/private") / name) / absolute.relative_to(alias)
|
|
213
|
+
except (OSError, ValueError):
|
|
214
|
+
continue
|
|
215
|
+
return absolute
|
|
216
|
+
|
|
217
|
+
from core.supervisor import (
|
|
218
|
+
active_claim,
|
|
219
|
+
active_resource_keys,
|
|
220
|
+
append_event,
|
|
221
|
+
assert_target_fingerprint,
|
|
222
|
+
claimed_units_this_round,
|
|
223
|
+
close_parallel_round,
|
|
224
|
+
confirmation_gate,
|
|
225
|
+
coverage_evidence_path,
|
|
226
|
+
deadline_reasons,
|
|
227
|
+
drain_dangling_claims,
|
|
228
|
+
eligible_units,
|
|
229
|
+
ensure_live_for_work,
|
|
230
|
+
finding_key,
|
|
231
|
+
normalize_checkpoint_id,
|
|
232
|
+
normalize_coverage,
|
|
233
|
+
normalize_evidence,
|
|
234
|
+
enrich_gate_finding,
|
|
235
|
+
normalize_findings,
|
|
236
|
+
normalize_ids,
|
|
237
|
+
normalize_notes,
|
|
238
|
+
normalize_signatures,
|
|
239
|
+
normalize_worker_id,
|
|
240
|
+
mark_worker_attempts_exhausted,
|
|
241
|
+
observe_clock,
|
|
242
|
+
parallel_gate_result,
|
|
243
|
+
parallel_required,
|
|
244
|
+
publish_checkpoint_evidence,
|
|
245
|
+
recalibrate_round_budget,
|
|
246
|
+
reconcile_parallel,
|
|
247
|
+
refresh,
|
|
248
|
+
adaptive_lease_seconds,
|
|
249
|
+
apply_status_budget,
|
|
250
|
+
refresh_confirmation_gate,
|
|
251
|
+
resolve_session_coverage_ledger_path,
|
|
252
|
+
release_claim,
|
|
253
|
+
release_active_claims,
|
|
254
|
+
renew_claim,
|
|
255
|
+
mark_claim_expired,
|
|
256
|
+
session_coverage_complete,
|
|
257
|
+
ROUND_HEARTBEAT_TIMEOUT_SECONDS,
|
|
258
|
+
set_budget_exhausted,
|
|
259
|
+
soft_limit_reasons,
|
|
260
|
+
validate_parallel_capacity,
|
|
261
|
+
target_gate_result,
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
from core.supervisor.lease_manager import reclaim_orphan_leases
|
|
265
|
+
|
|
266
|
+
from core.supervisor import finding_sync
|
|
267
|
+
|
|
268
|
+
from core.supervisor import finish_sync
|
|
269
|
+
|
|
270
|
+
from core.supervisor import recovery_sync
|
|
271
|
+
|
|
272
|
+
from core.supervisor import start_sync
|
|
273
|
+
|
|
274
|
+
from core.supervisor import checkpoint_sync
|
|
275
|
+
|
|
276
|
+
from core.supervisor import claim_sync
|
|
277
|
+
|
|
278
|
+
from core.supervisor import next_round_sync
|
|
279
|
+
|
|
280
|
+
from core.supervisor import context_sync
|
|
281
|
+
|
|
282
|
+
from core.supervisor import worker_sync
|
|
283
|
+
|
|
284
|
+
from core.supervisor import graph_sync
|
|
285
|
+
|
|
286
|
+
from core.supervisor import coverage_sync
|
|
287
|
+
|
|
288
|
+
from core.supervisor.checkpoint_pipeline import (
|
|
289
|
+
attach_evidence_receipts,
|
|
290
|
+
checkpoint_payload_digest,
|
|
291
|
+
load_checkpoint_payload,
|
|
292
|
+
load_manifest_units,
|
|
293
|
+
merge_coverage_updates,
|
|
294
|
+
migrate_coverage,
|
|
295
|
+
validate_worker_artifacts,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
from core.supervisor.observability import (
|
|
299
|
+
build_decision_snapshot,
|
|
300
|
+
build_parallel_gate_snapshot,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
from core.supervisor.state_store import StateStore
|
|
304
|
+
|
|
305
|
+
import core.supervisor.checkpoint_handler as _ch
|
|
306
|
+
_assert_reproducible_contract = _ch._assert_reproducible_contract
|
|
307
|
+
_validate_incoming_findings = _ch._validate_incoming_findings
|
|
308
|
+
|
|
309
|
+
class Supervisor:
|
|
310
|
+
"""线程/进程安全的、只追加审计的外部 run Supervisor。"""
|
|
311
|
+
|
|
312
|
+
def __init__(
|
|
313
|
+
self,
|
|
314
|
+
workspace_root: str | os.PathLike[str],
|
|
315
|
+
budget: RunBudget | None = None,
|
|
316
|
+
*,
|
|
317
|
+
state_path: str | os.PathLike[str] | None = None,
|
|
318
|
+
clock: Callable[[], float] | None = None,
|
|
319
|
+
mono_clock: Callable[[], float] | None = None,
|
|
320
|
+
coverage_ledger_path: str | os.PathLike[str] | None = None,
|
|
321
|
+
) -> None:
|
|
322
|
+
root = Path(workspace_root).resolve()
|
|
323
|
+
if not root.is_dir():
|
|
324
|
+
raise WorkspacePathError(f"workspace_root 不是目录: {root}")
|
|
325
|
+
self.workspace_root = root
|
|
326
|
+
self.coverage_ledger_path = Path(coverage_ledger_path).resolve() if coverage_ledger_path else None
|
|
327
|
+
if state_path is not None:
|
|
328
|
+
raw_state = Path(state_path)
|
|
329
|
+
raw_rel = Path(state_path)
|
|
330
|
+
else:
|
|
331
|
+
canonical = root / DEFAULT_STATE_RELATIVE_PATH
|
|
332
|
+
legacy = root / LEGACY_STATE_RELATIVE_PATH
|
|
333
|
+
if not canonical.exists() and legacy.exists():
|
|
334
|
+
raw_state = legacy
|
|
335
|
+
raw_rel = LEGACY_STATE_RELATIVE_PATH
|
|
336
|
+
else:
|
|
337
|
+
raw_state = canonical
|
|
338
|
+
raw_rel = DEFAULT_STATE_RELATIVE_PATH
|
|
339
|
+
|
|
340
|
+
self.state_path = confined_path(root, raw_state)
|
|
341
|
+
self.lock_path = confined_path(
|
|
342
|
+
root, self.state_path.with_name(self.state_path.name + ".lock"),
|
|
343
|
+
)
|
|
344
|
+
self.backup_path = confined_path(
|
|
345
|
+
root, self.state_path.with_name(self.state_path.name + ".bak"),
|
|
346
|
+
)
|
|
347
|
+
# Keep lexical forms to detect inner symlinks when /var -> /private alias
|
|
348
|
+
# makes the canonical check miss the lexical symlink component.
|
|
349
|
+
try:
|
|
350
|
+
lexical_root = _normalize_lexical_system_alias(Path(workspace_root))
|
|
351
|
+
if state_path is None:
|
|
352
|
+
lexical_raw = lexical_root / raw_rel
|
|
353
|
+
else:
|
|
354
|
+
candidate = Path(state_path)
|
|
355
|
+
lexical_raw = (
|
|
356
|
+
_normalize_lexical_system_alias(candidate)
|
|
357
|
+
if candidate.is_absolute() else lexical_root / candidate
|
|
358
|
+
)
|
|
359
|
+
self._lexical_root = lexical_root
|
|
360
|
+
self._lexical_state_path = lexical_raw
|
|
361
|
+
self._lexical_backup_path = Path(str(lexical_raw) + ".bak")
|
|
362
|
+
self._lexical_lock_path = Path(str(lexical_raw) + ".lock")
|
|
363
|
+
except Exception:
|
|
364
|
+
# Fallback to canonical paths if lexical computation fails.
|
|
365
|
+
self._lexical_root = self.workspace_root
|
|
366
|
+
self._lexical_state_path = self.state_path
|
|
367
|
+
self._lexical_backup_path = self.backup_path
|
|
368
|
+
self._lexical_lock_path = self.lock_path
|
|
369
|
+
self._state_store = StateStore(
|
|
370
|
+
self.state_path, self.backup_path, self._lexical_root,
|
|
371
|
+
self._lexical_state_path, self._lexical_backup_path,
|
|
372
|
+
)
|
|
373
|
+
invalidate_git_head_cache(root)
|
|
374
|
+
self.target_fingerprint = workspace_fingerprint(root)
|
|
375
|
+
self._configured_budget = budget or RunBudget()
|
|
376
|
+
self._clock = clock or time.time
|
|
377
|
+
# A7 之后「租约是否过期」只读单调时钟(墙钟跳变不得改变结论),因此
|
|
378
|
+
# 过期语义的可测性要求单调时钟**同样可注入**。此前只有墙钟可注入,
|
|
379
|
+
# 假时钟驱动的用例在真实 monotonic 下永不过期 —— run_fault_matrix 的
|
|
380
|
+
# 「心跳丢失与租约回收」因此长期 reclaimed=False(门 5 无法闭合)。
|
|
381
|
+
# 只注入 ``clock`` 时它就是唯一权威时钟(两者同源),否则既有的假时钟
|
|
382
|
+
# 用例会出现「墙钟前进、单调钟不动」的自相矛盾。
|
|
383
|
+
# late binding:``mock.patch("time.monotonic")`` 必须能改变默认源。
|
|
384
|
+
self._mono_clock = mono_clock or (lambda: time.monotonic())
|
|
385
|
+
self._thread_lock = threading.RLock()
|
|
386
|
+
|
|
387
|
+
@property
|
|
388
|
+
def budget(self) -> RunBudget:
|
|
389
|
+
"""返回创建新 run 或 reset 使用的默认预算。"""
|
|
390
|
+
|
|
391
|
+
return self._configured_budget
|
|
392
|
+
|
|
393
|
+
@contextmanager
|
|
394
|
+
def _file_lock(self, timeout: float = 10.0):
|
|
395
|
+
if not math.isfinite(timeout) or timeout < 0:
|
|
396
|
+
raise ValueError("Supervisor lock timeout must be a finite non-negative number")
|
|
397
|
+
self.lock_path.parent.mkdir(parents=True, exist_ok=True)
|
|
398
|
+
deadline = time.monotonic() + timeout
|
|
399
|
+
if not self._thread_lock.acquire(timeout=timeout):
|
|
400
|
+
raise TimeoutError(
|
|
401
|
+
f"Supervisor lock acquisition exceeded {timeout:.3g}s: {self.lock_path}"
|
|
402
|
+
)
|
|
403
|
+
try:
|
|
404
|
+
with self._thread_lock:
|
|
405
|
+
if has_lexical_symlink(self._lexical_root, self._lexical_lock_path):
|
|
406
|
+
raise WorkspacePathError(f"拒绝使用符号链接 Supervisor 锁: {self.lock_path}")
|
|
407
|
+
flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
|
|
408
|
+
try:
|
|
409
|
+
descriptor = os.open(self.lock_path, flags, 0o600)
|
|
410
|
+
except OSError as exc:
|
|
411
|
+
raise WorkspacePathError(f"无法安全打开 Supervisor 锁: {self.lock_path}") from exc
|
|
412
|
+
with os.fdopen(descriptor, "a+", encoding="utf-8") as lock_handle:
|
|
413
|
+
with _bounded_os_file_lock(
|
|
414
|
+
lock_handle.fileno(), self.lock_path, deadline, timeout, shared=False,
|
|
415
|
+
):
|
|
416
|
+
yield
|
|
417
|
+
finally:
|
|
418
|
+
self._thread_lock.release()
|
|
419
|
+
|
|
420
|
+
@contextmanager
|
|
421
|
+
def _read_lock(self, timeout: float = 10.0):
|
|
422
|
+
"""共享读锁通道 (DOC-138 / S1-5):允许多个只读查询并发执行,消除读写竞争。"""
|
|
423
|
+
if not math.isfinite(timeout) or timeout < 0:
|
|
424
|
+
raise ValueError("Supervisor lock timeout must be a finite non-negative number")
|
|
425
|
+
self.lock_path.parent.mkdir(parents=True, exist_ok=True)
|
|
426
|
+
deadline = time.monotonic() + timeout
|
|
427
|
+
if not self._thread_lock.acquire(timeout=timeout):
|
|
428
|
+
raise TimeoutError(
|
|
429
|
+
f"Supervisor lock acquisition exceeded {timeout:.3g}s: {self.lock_path}"
|
|
430
|
+
)
|
|
431
|
+
try:
|
|
432
|
+
with self._thread_lock:
|
|
433
|
+
if has_lexical_symlink(self._lexical_root, self._lexical_lock_path):
|
|
434
|
+
raise WorkspacePathError(f"拒绝使用符号链接 Supervisor 锁: {self.lock_path}")
|
|
435
|
+
flags = os.O_RDWR | os.O_CREAT | getattr(os, "O_NOFOLLOW", 0)
|
|
436
|
+
try:
|
|
437
|
+
descriptor = os.open(self.lock_path, flags, 0o600)
|
|
438
|
+
except OSError as exc:
|
|
439
|
+
raise WorkspacePathError(f"无法安全打开 Supervisor 锁: {self.lock_path}") from exc
|
|
440
|
+
with os.fdopen(descriptor, "a+", encoding="utf-8") as lock_handle:
|
|
441
|
+
with _bounded_os_file_lock(
|
|
442
|
+
lock_handle.fileno(), self.lock_path, deadline, timeout, shared=True,
|
|
443
|
+
):
|
|
444
|
+
yield
|
|
445
|
+
finally:
|
|
446
|
+
self._thread_lock.release()
|
|
447
|
+
|
|
448
|
+
def _read_state_locked(self) -> RunState:
|
|
449
|
+
"""Fail-closed read through the dedicated snapshot store."""
|
|
450
|
+
# A5 recovery is forward-only and runs before any reader can pair a
|
|
451
|
+
# partially applied state with a report or seal.
|
|
452
|
+
from core.supervisor.finding_commit import recover_finding_commit
|
|
453
|
+
commit_root = self.state_path.parent.parent
|
|
454
|
+
if commit_root.resolve() == self.workspace_root.resolve():
|
|
455
|
+
commit_root = self.state_path.parent
|
|
456
|
+
if commit_root.is_dir():
|
|
457
|
+
recover_finding_commit(commit_root)
|
|
458
|
+
state = self._state_store.read()
|
|
459
|
+
# DOC-204 L6:裁剪旁路归档路径(lease_manager.append_event 消费)
|
|
460
|
+
try:
|
|
461
|
+
state._history_archive_path = str(
|
|
462
|
+
Path(self.state_path).parent / "supervisor.history.archive.jsonl"
|
|
463
|
+
)
|
|
464
|
+
except (AttributeError, TypeError):
|
|
465
|
+
pass
|
|
466
|
+
return state
|
|
467
|
+
|
|
468
|
+
def recover(self, reset_worker_attempts: bool = False) -> RunState:
|
|
469
|
+
"""Explicit, auditable recovery from the primary or its backup."""
|
|
470
|
+
return recovery_sync.recover(
|
|
471
|
+
self, reset_worker_attempts=reset_worker_attempts,
|
|
472
|
+
) # type: ignore[return-value]
|
|
473
|
+
|
|
474
|
+
def fix_finding_severity(
|
|
475
|
+
self,
|
|
476
|
+
*,
|
|
477
|
+
finding: str,
|
|
478
|
+
severity: str,
|
|
479
|
+
reason: str | None = None,
|
|
480
|
+
expected_revision: int | None = None,
|
|
481
|
+
) -> dict[str, object]:
|
|
482
|
+
"""DOC-230 §3.8 第 4 项:历史 severity 脏数据的修复通道(host / CLI)。
|
|
483
|
+
|
|
484
|
+
与 ``recover`` 同构——一次锁内、可审计的状态变更。边界:**只改 severity**,
|
|
485
|
+
绝不触碰 ``confirmation``(修复脏数据 ≠ 改裁决结论);值必须命中写侧
|
|
486
|
+
词表;**合法值之间改级必须给 `reason`**(severity 参与 Life 奖励与
|
|
487
|
+
minimum_severity 评分,静默改级会变成刷分/藏缺陷工具,见 C1/A12);
|
|
488
|
+
真实变更写 ``finding_severity_repaired`` 事件;幂等调用不推进 revision。
|
|
489
|
+
"""
|
|
490
|
+
return finding_sync.repair_finding_severity(
|
|
491
|
+
self,
|
|
492
|
+
finding=finding,
|
|
493
|
+
severity=severity,
|
|
494
|
+
reason=reason,
|
|
495
|
+
expected_revision=expected_revision,
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
def _persist_locked(self, state: RunState) -> None:
|
|
499
|
+
if not state.dirty:
|
|
500
|
+
return
|
|
501
|
+
snapshots: list[tuple[Path, bool, bytes | None]] = []
|
|
502
|
+
for path in (
|
|
503
|
+
self.state_path, self.backup_path, self._state_store.revision_path,
|
|
504
|
+
):
|
|
505
|
+
if path.is_symlink():
|
|
506
|
+
raise WorkspacePathError(f"拒绝回滚符号链接状态文件: {path}")
|
|
507
|
+
exists = path.exists()
|
|
508
|
+
if exists and not path.is_file():
|
|
509
|
+
raise PersistenceError(f"状态文件不是普通文件: {path}")
|
|
510
|
+
snapshots.append((path, exists, path.read_bytes() if exists else None))
|
|
511
|
+
|
|
512
|
+
state.revision += 1
|
|
513
|
+
pending = getattr(state, "_finding_commit_pending", None)
|
|
514
|
+
if isinstance(pending, Mapping):
|
|
515
|
+
from core.supervisor.finding_commit import commit_finding_transaction
|
|
516
|
+
state_bytes = json.dumps(
|
|
517
|
+
state.to_dict(), ensure_ascii=False, separators=(",", ":"),
|
|
518
|
+
sort_keys=True, allow_nan=False,
|
|
519
|
+
).encode("utf-8") + b"\n"
|
|
520
|
+
commit_root = self.state_path.parent.parent
|
|
521
|
+
if commit_root.resolve() == self.workspace_root.resolve():
|
|
522
|
+
commit_root = self.state_path.parent
|
|
523
|
+
commit_finding_transaction(
|
|
524
|
+
commit_root,
|
|
525
|
+
state_path=self.state_path,
|
|
526
|
+
backup_path=self.backup_path,
|
|
527
|
+
report_path=Path(str(pending["report_path"])),
|
|
528
|
+
seal_path=Path(str(pending["seal_path"])),
|
|
529
|
+
state_bytes=state_bytes,
|
|
530
|
+
report_bytes=bytes(pending["report_bytes"]),
|
|
531
|
+
seal_bytes=bytes(pending["seal_bytes"]),
|
|
532
|
+
request_id=str(pending.get("request_id") or uuid.uuid4()),
|
|
533
|
+
expected_revision=state.revision,
|
|
534
|
+
)
|
|
535
|
+
atomic_write_bytes(
|
|
536
|
+
self._state_store.revision_path,
|
|
537
|
+
f"{state.revision}\n".encode("ascii"),
|
|
538
|
+
)
|
|
539
|
+
try:
|
|
540
|
+
delattr(state, "_finding_commit_pending")
|
|
541
|
+
except AttributeError:
|
|
542
|
+
pass
|
|
543
|
+
state.dirty = False
|
|
544
|
+
return
|
|
545
|
+
try:
|
|
546
|
+
self._state_store.persist(state)
|
|
547
|
+
except BaseException as persist_error:
|
|
548
|
+
state.revision -= 1
|
|
549
|
+
state.dirty = True
|
|
550
|
+
try:
|
|
551
|
+
for path, existed, payload in snapshots:
|
|
552
|
+
if existed:
|
|
553
|
+
if path.is_symlink():
|
|
554
|
+
raise WorkspacePathError(
|
|
555
|
+
f"拒绝回滚符号链接状态文件: {path}"
|
|
556
|
+
)
|
|
557
|
+
atomic_write_bytes(path, payload or b"")
|
|
558
|
+
elif path.exists() or path.is_symlink():
|
|
559
|
+
if path.is_symlink() or not path.is_file():
|
|
560
|
+
raise WorkspacePathError(
|
|
561
|
+
f"拒绝删除异常状态文件: {path}"
|
|
562
|
+
)
|
|
563
|
+
path.unlink()
|
|
564
|
+
except BaseException as rollback_error:
|
|
565
|
+
raise PersistenceError(
|
|
566
|
+
"run-state 持久化失败且回滚失败,拒绝继续"
|
|
567
|
+
) from rollback_error
|
|
568
|
+
raise persist_error
|
|
569
|
+
state.dirty = False
|
|
570
|
+
|
|
571
|
+
def _mutate(
|
|
572
|
+
self,
|
|
573
|
+
operation: Callable[[RunState, float], object],
|
|
574
|
+
*,
|
|
575
|
+
before_persist: Callable[[], Callable[[], None] | None] | None = None,
|
|
576
|
+
) -> object:
|
|
577
|
+
"""执行一次锁内状态变更;可选 ``before_persist`` 建立可恢复边界。
|
|
578
|
+
|
|
579
|
+
传入 ``before_persist``(checkpoint 证据发布路径)时,``operation`` 与
|
|
580
|
+
``before_persist`` 先准备证据,再持久化 run-state;状态持久化失败时调用
|
|
581
|
+
证据回滚钩子。它是可恢复边界,不伪称跨文件原子提交;回滚失败则 fail-closed。
|
|
582
|
+
不传时保持既有语义 —— operation 抛出的拒绝/预算/租约事件仍会落盘(失败留痕)。
|
|
583
|
+
"""
|
|
584
|
+
atomic_pair = before_persist is not None
|
|
585
|
+
with self._file_lock():
|
|
586
|
+
state = self._read_state_locked()
|
|
587
|
+
now = float(self._clock())
|
|
588
|
+
rollback: Callable[[], None] | None = None
|
|
589
|
+
try:
|
|
590
|
+
result = operation(state, now)
|
|
591
|
+
if before_persist is not None:
|
|
592
|
+
rollback = before_persist()
|
|
593
|
+
except BaseException:
|
|
594
|
+
if not atomic_pair:
|
|
595
|
+
self._persist_locked(state)
|
|
596
|
+
raise
|
|
597
|
+
try:
|
|
598
|
+
self._persist_locked(state)
|
|
599
|
+
except BaseException as persist_error:
|
|
600
|
+
if rollback is not None:
|
|
601
|
+
try:
|
|
602
|
+
rollback()
|
|
603
|
+
except BaseException as rollback_error:
|
|
604
|
+
raise PersistenceError(
|
|
605
|
+
"checkpoint 事务回滚失败,拒绝继续"
|
|
606
|
+
) from rollback_error
|
|
607
|
+
raise persist_error
|
|
608
|
+
if isinstance(result, (RunState, WorkerClaim)):
|
|
609
|
+
return copy.deepcopy(result)
|
|
610
|
+
return result
|
|
611
|
+
|
|
612
|
+
def _query_readonly(self, operation: Callable[[RunState, float], object]) -> object:
|
|
613
|
+
"""查询入口:refresh 可能变更状态,因此读改写全程持有排他锁。
|
|
614
|
+
|
|
615
|
+
Clean queries still avoid disk writes and revision changes. Keep the
|
|
616
|
+
lock across the single operation pass so refresh side effects aren't
|
|
617
|
+
replayed against a newly read state.
|
|
618
|
+
"""
|
|
619
|
+
with self._file_lock():
|
|
620
|
+
state = self._read_state_locked()
|
|
621
|
+
now = float(self._clock())
|
|
622
|
+
result = operation(state, now)
|
|
623
|
+
if not state.dirty:
|
|
624
|
+
if isinstance(result, (RunState, WorkerClaim)):
|
|
625
|
+
return copy.deepcopy(result)
|
|
626
|
+
return result
|
|
627
|
+
# refresh can update counters/events or terminate a worker; don't
|
|
628
|
+
# release the lock and replay those effects on a second snapshot.
|
|
629
|
+
self._persist_locked(state)
|
|
630
|
+
if isinstance(result, (RunState, WorkerClaim)):
|
|
631
|
+
return copy.deepcopy(result)
|
|
632
|
+
return result
|
|
633
|
+
|
|
634
|
+
_release_active_claims = staticmethod(release_active_claims)
|
|
635
|
+
|
|
636
|
+
def _new_mutate(self, operation: Callable[[float], RunState]) -> RunState:
|
|
637
|
+
with self._file_lock():
|
|
638
|
+
# Fail closed on any existing persisted artifact; explicit recover
|
|
639
|
+
# is required before a new run can replace historical evidence.
|
|
640
|
+
self._state_store.ensure_new_run_allowed()
|
|
641
|
+
now = float(self._clock())
|
|
642
|
+
state = operation(now)
|
|
643
|
+
self._persist_locked(state)
|
|
644
|
+
return copy.deepcopy(state)
|
|
645
|
+
|
|
646
|
+
_append_event = staticmethod(append_event)
|
|
647
|
+
|
|
648
|
+
@staticmethod
|
|
649
|
+
def _check_revision(state: RunState, expected_revision: int | None) -> None:
|
|
650
|
+
if expected_revision is not None and expected_revision != state.revision:
|
|
651
|
+
raise RevisionConflict(
|
|
652
|
+
f"revision mismatch: expected={expected_revision}, actual={state.revision}"
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
def _active_claim(
|
|
656
|
+
self, state: RunState, worker_id: str, now: float, *,
|
|
657
|
+
require_running: bool = False,
|
|
658
|
+
) -> WorkerClaim:
|
|
659
|
+
"""实例包装:把可注入的单调时钟传给 ``active_claim``。
|
|
660
|
+
|
|
661
|
+
过期判定只读单调时钟,因此这里的 ``now_mono`` 必须与 ``_refresh``
|
|
662
|
+
同源;否则注入假时钟的用例会在真实的 ``time.monotonic()`` 下永不过期。
|
|
663
|
+
"""
|
|
664
|
+
return active_claim(
|
|
665
|
+
state, worker_id, now,
|
|
666
|
+
require_running=require_running,
|
|
667
|
+
now_mono=float(self._mono_clock()),
|
|
668
|
+
)
|
|
669
|
+
_apply_heartbeat_renewal = staticmethod(renew_claim)
|
|
670
|
+
_normalize_worker_id = staticmethod(normalize_worker_id)
|
|
671
|
+
_normalize_checkpoint_id = staticmethod(normalize_checkpoint_id)
|
|
672
|
+
_normalize_ids = staticmethod(normalize_ids)
|
|
673
|
+
_claimed_units_this_round = staticmethod(claimed_units_this_round)
|
|
674
|
+
_eligible_units = staticmethod(eligible_units)
|
|
675
|
+
_active_resource_keys = staticmethod(active_resource_keys)
|
|
676
|
+
_reconcile_parallel = staticmethod(reconcile_parallel)
|
|
677
|
+
_parallel_required = staticmethod(parallel_required)
|
|
678
|
+
_parallel_gate_result = staticmethod(parallel_gate_result)
|
|
679
|
+
_close_parallel_round = staticmethod(close_parallel_round)
|
|
680
|
+
_recalibrate_round_budget = staticmethod(recalibrate_round_budget)
|
|
681
|
+
_deadline_reasons = staticmethod(deadline_reasons)
|
|
682
|
+
_soft_limit_reasons = staticmethod(soft_limit_reasons)
|
|
683
|
+
_validate_parallel_capacity = staticmethod(validate_parallel_capacity)
|
|
684
|
+
_set_budget_exhausted = staticmethod(set_budget_exhausted)
|
|
685
|
+
|
|
686
|
+
def _refresh(self, state: RunState, now: float) -> None:
|
|
687
|
+
refresh(
|
|
688
|
+
state, now,
|
|
689
|
+
workspace_root=self.workspace_root,
|
|
690
|
+
now_mono=float(self._mono_clock()),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
def _crash_drain(self, state: RunState, now: float) -> list[str]:
|
|
694
|
+
"""Reclaim only leases proven dead or already past their deadline."""
|
|
695
|
+
return reclaim_orphan_leases(state, now)
|
|
696
|
+
|
|
697
|
+
def _refresh_status_budget(self, state: RunState, now: float) -> None:
|
|
698
|
+
"""Refresh live leases, then drain crash orphans before gate evaluation."""
|
|
699
|
+
self._refresh(state, now)
|
|
700
|
+
# Refresh runs first so a fresh live heartbeat can renew its lease. The
|
|
701
|
+
# drain then only releases claims proven dead or already lease-expired;
|
|
702
|
+
# submitted claims are not active and cannot be mistaken for crashes.
|
|
703
|
+
self._crash_drain(state, now)
|
|
704
|
+
apply_status_budget(state, now)
|
|
705
|
+
_ensure_live_for_work = staticmethod(ensure_live_for_work)
|
|
706
|
+
_finding_key = staticmethod(finding_key)
|
|
707
|
+
_normalize_findings = staticmethod(normalize_findings)
|
|
708
|
+
_enrich_gate_finding = staticmethod(enrich_gate_finding)
|
|
709
|
+
_normalize_notes = staticmethod(normalize_notes)
|
|
710
|
+
_normalize_signatures = staticmethod(normalize_signatures)
|
|
711
|
+
_confirmation_gate = staticmethod(confirmation_gate)
|
|
712
|
+
_refresh_confirmation_gate = staticmethod(refresh_confirmation_gate)
|
|
713
|
+
_normalize_coverage = staticmethod(normalize_coverage)
|
|
714
|
+
_normalize_evidence = staticmethod(normalize_evidence)
|
|
715
|
+
|
|
716
|
+
def _target_gate_result(self, state: RunState) -> dict[str, object]:
|
|
717
|
+
return target_gate_result(self.workspace_root, state)
|
|
718
|
+
|
|
719
|
+
def start(
|
|
720
|
+
self,
|
|
721
|
+
*,
|
|
722
|
+
life_score: float = 1.0,
|
|
723
|
+
coverage_units: Sequence[str] = (),
|
|
724
|
+
run_id: str | None = None,
|
|
725
|
+
project_id: str | None = None,
|
|
726
|
+
session_id: str | None = None,
|
|
727
|
+
round_id: str | None = None,
|
|
728
|
+
life_id: str | None = None,
|
|
729
|
+
plan_hash: str | None = None,
|
|
730
|
+
life_kind: str = "mine",
|
|
731
|
+
) -> RunState:
|
|
732
|
+
"""创建并持久化一个 run;不会覆盖已有 state。"""
|
|
733
|
+
|
|
734
|
+
if plan_hash is not None and (
|
|
735
|
+
not isinstance(plan_hash, str) or not SHA256_RE.fullmatch(plan_hash)
|
|
736
|
+
):
|
|
737
|
+
raise InvalidCheckpoint(
|
|
738
|
+
"plan_hash 必须是 64 位十六进制 SHA-256,"
|
|
739
|
+
"形如 " + "a" * 8 + "..." + "(共 64 字符,用 "
|
|
740
|
+
"`shasum -a 256 <plan-file>` 生成);不要传 None 或短哈希"
|
|
741
|
+
)
|
|
742
|
+
if life_kind not in {"mine", "fix"}:
|
|
743
|
+
raise InvalidCheckpoint("life_kind 必须是 mine 或 fix")
|
|
744
|
+
score = finite_number(life_score, "life_score")
|
|
745
|
+
raw_units = list(coverage_units)
|
|
746
|
+
if any(not isinstance(unit, str) or not unit.strip() for unit in raw_units):
|
|
747
|
+
raise InvalidCheckpoint(
|
|
748
|
+
"coverage_units 必须是非空且唯一的字符串,"
|
|
749
|
+
'形如 ["1-内部-ROOT", "2-外部-API"];'
|
|
750
|
+
"空数组会被视为未覆盖任何单元,重复项会导致统计失真"
|
|
751
|
+
)
|
|
752
|
+
units = [unit.strip() for unit in raw_units]
|
|
753
|
+
if len(set(units)) != len(units):
|
|
754
|
+
raise InvalidCheckpoint("coverage_units 不能包含仅空白差异的重复单元")
|
|
755
|
+
initial_eligible = [unit for unit in units if not unit_kind.is_business(unit)]
|
|
756
|
+
if not initial_eligible:
|
|
757
|
+
initial_eligible = units
|
|
758
|
+
self._validate_parallel_capacity(
|
|
759
|
+
self._configured_budget, len(initial_eligible),
|
|
760
|
+
)
|
|
761
|
+
|
|
762
|
+
invalidate_git_head_cache(self.workspace_root)
|
|
763
|
+
|
|
764
|
+
def create(now: float) -> RunState:
|
|
765
|
+
return start_sync.create_run(
|
|
766
|
+
self,
|
|
767
|
+
now,
|
|
768
|
+
score=score,
|
|
769
|
+
units=units,
|
|
770
|
+
run_id=run_id,
|
|
771
|
+
project_id=project_id,
|
|
772
|
+
session_id=session_id,
|
|
773
|
+
round_id=round_id,
|
|
774
|
+
life_id=life_id,
|
|
775
|
+
plan_hash=plan_hash,
|
|
776
|
+
life_kind=life_kind,
|
|
777
|
+
workspace_fingerprint=workspace_fingerprint,
|
|
778
|
+
)
|
|
779
|
+
|
|
780
|
+
return self._new_mutate(create)
|
|
781
|
+
|
|
782
|
+
def start_graph(
|
|
783
|
+
self,
|
|
784
|
+
*,
|
|
785
|
+
graph_id: str,
|
|
786
|
+
goal: str,
|
|
787
|
+
origin_root: str,
|
|
788
|
+
snapshot_digest: str,
|
|
789
|
+
tasks: Sequence[GraphTask | Mapping[str, object]],
|
|
790
|
+
expected_revision: int | None = None,
|
|
791
|
+
) -> GraphRun:
|
|
792
|
+
"""Attach a versioned agent graph to this run in the state transaction."""
|
|
793
|
+
|
|
794
|
+
return self._mutate(
|
|
795
|
+
lambda state, now: graph_sync.graph_start_sync(
|
|
796
|
+
self, state, now,
|
|
797
|
+
graph_id=graph_id,
|
|
798
|
+
goal=goal,
|
|
799
|
+
origin_root=origin_root,
|
|
800
|
+
snapshot_digest=snapshot_digest,
|
|
801
|
+
tasks=tasks,
|
|
802
|
+
expected_revision=expected_revision,
|
|
803
|
+
)
|
|
804
|
+
) # type: ignore[return-value]
|
|
805
|
+
|
|
806
|
+
def _coverage_evidence_path(self) -> Path | None:
|
|
807
|
+
return coverage_evidence_path(self.workspace_root, self.state_path)
|
|
808
|
+
|
|
809
|
+
def _assert_target_fingerprint(self, state: RunState, now: float) -> None:
|
|
810
|
+
assert_target_fingerprint(self.workspace_root, self.target_fingerprint, state, now)
|
|
811
|
+
|
|
812
|
+
def _publish_checkpoint_evidence(
|
|
813
|
+
self, evidence: Mapping[str, Mapping[str, object]],
|
|
814
|
+
) -> Callable[[], None] | None:
|
|
815
|
+
return publish_checkpoint_evidence(
|
|
816
|
+
self.workspace_root, self.state_path, evidence,
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
# DES-03:以下方法是 claim_worker 的状态变更体,由原先的嵌套闭包
|
|
820
|
+
# 提升而来;claim_worker 只保留归一化 + 适配调用。
|
|
821
|
+
# ---- Worker Lifecycle (core/supervisor/worker_lifecycle.py) ----
|
|
822
|
+
_apply_claim_operation = worker_lifecycle._apply_claim_operation
|
|
823
|
+
claim_worker = worker_lifecycle.claim_worker
|
|
824
|
+
start_worker = worker_lifecycle.start_worker
|
|
825
|
+
record_worker_failure = worker_lifecycle.record_worker_failure
|
|
826
|
+
heartbeat = worker_lifecycle.heartbeat
|
|
827
|
+
begin_long_call = worker_lifecycle.begin_long_call
|
|
828
|
+
record_tool_call = worker_lifecycle.record_tool_call
|
|
829
|
+
|
|
830
|
+
# ---- Checkpoint Pipeline (core/supervisor/checkpoint_handler.py) ----
|
|
831
|
+
_apply_checkpoint_operation = checkpoint_handler._apply_checkpoint_operation
|
|
832
|
+
_record_checkpoint_rejection = checkpoint_handler._record_checkpoint_rejection
|
|
833
|
+
_verify_readonly_claim = checkpoint_handler._verify_readonly_claim
|
|
834
|
+
submit_checkpoint = checkpoint_handler.submit_checkpoint
|
|
835
|
+
_commit_checkpoint_transaction = checkpoint_handler._commit_checkpoint_transaction
|
|
836
|
+
_commit_expired_claims = checkpoint_handler._commit_expired_claims
|
|
837
|
+
submit_graph_checkpoint = checkpoint_handler.submit_graph_checkpoint
|
|
838
|
+
|
|
839
|
+
# ---- Round Governor (core/supervisor/round_governor.py) ----
|
|
840
|
+
recalibrate_round_budget = round_governor.recalibrate_round_budget
|
|
841
|
+
_apply_next_round_operation = round_governor._apply_next_round_operation
|
|
842
|
+
next_round = round_governor.next_round
|
|
843
|
+
bind_context = round_governor.bind_context
|
|
844
|
+
_check_session_coverage_ledger = round_governor._check_session_coverage_ledger
|
|
845
|
+
finish = round_governor.finish
|
|
846
|
+
parallel_gate = round_governor.parallel_gate
|
|
847
|
+
_apply_reset_budget_operation = round_governor._apply_reset_budget_operation
|
|
848
|
+
reset_budget = round_governor.reset_budget
|
|
849
|
+
rebind_target = finding_workflow.rebind_target
|
|
850
|
+
|
|
851
|
+
# ---- Lifecycle Blocks (core/supervisor/lifecycle_blocks.py) ----
|
|
852
|
+
_count_lifecycle_blocks = staticmethod(lifecycle_blocks._count_lifecycle_blocks)
|
|
853
|
+
_lifecycle_block_fields = staticmethod(lifecycle_blocks._lifecycle_block_fields)
|
|
854
|
+
_release_owner_cancelled_debris = staticmethod(lifecycle_blocks._release_owner_cancelled_debris)
|
|
855
|
+
record_lifecycle_block = lifecycle_blocks.record_lifecycle_block
|
|
856
|
+
|
|
857
|
+
# ---- Finding Workflow (core/supervisor/finding_workflow.py) ----
|
|
858
|
+
reopen_finding = finding_workflow.reopen_finding
|
|
859
|
+
admit_business_unit = finding_workflow.admit_business_unit
|
|
860
|
+
_reinstate_covered_by_evidence = finding_workflow._reinstate_covered_by_evidence
|
|
861
|
+
_rescan_changed_scopes = finding_workflow._rescan_changed_scopes
|
|
862
|
+
_units_in_scopes = finding_workflow._units_in_scopes
|
|
863
|
+
_restore_not_applicable = finding_workflow._restore_not_applicable
|
|
864
|
+
_retarget_evidence = finding_workflow._retarget_evidence
|
|
865
|
+
sync_finding_decisions = finding_workflow.sync_finding_decisions
|
|
866
|
+
sync_finding_decisions_audited = finding_workflow.sync_finding_decisions_audited
|
|
867
|
+
freeze_report_snapshot = finding_workflow.freeze_report_snapshot
|
|
868
|
+
settle_report = finding_workflow.settle_report
|
|
869
|
+
_verification_recipe_digest = finding_workflow._verification_recipe_digest
|
|
870
|
+
_verification_precheck = finding_workflow._verification_precheck
|
|
871
|
+
_record_verification = finding_workflow._record_verification
|
|
872
|
+
confirm_finding = finding_workflow.confirm_finding
|
|
873
|
+
invalidate_coverage = finding_workflow.invalidate_coverage
|
|
874
|
+
verify_finding = finding_workflow.verify_finding
|
|
875
|
+
|
|
876
|
+
def fail(self, reason: str, *, expected_revision: int | None = None) -> RunState:
|
|
877
|
+
"""将 run 置为 FAILED;仍保留所有审计数据。"""
|
|
878
|
+
|
|
879
|
+
if not isinstance(reason, str) or not reason.strip():
|
|
880
|
+
raise InvalidCheckpoint("FAILED 必须提供 reason")
|
|
881
|
+
normalized_reason = reason.strip()
|
|
882
|
+
|
|
883
|
+
def operation(state: RunState, now: float) -> RunState:
|
|
884
|
+
# A caller may retry after the FAILED response was lost. The
|
|
885
|
+
# terminal result is already durable, so the same reason is an
|
|
886
|
+
# acknowledgement and must remain idempotent even with the
|
|
887
|
+
# revision observed before the first request.
|
|
888
|
+
if state.status == Status.FAILED and state.last_error == normalized_reason:
|
|
889
|
+
return state
|
|
890
|
+
self._check_revision(state, expected_revision)
|
|
891
|
+
if state.status == Status.COMPLETE:
|
|
892
|
+
raise InvalidTransition("COMPLETE run 不能改为 FAILED")
|
|
893
|
+
if state.status == Status.INCOMPLETE:
|
|
894
|
+
# D2:INCOMPLETE 是 finish 已收尾的终态(completed_at 已写、
|
|
895
|
+
# run_finished 已发),与 COMPLETE 同级,不得被 fail 改写。
|
|
896
|
+
raise InvalidTransition("INCOMPLETE run 不能改为 FAILED")
|
|
897
|
+
if state.status == Status.FAILED:
|
|
898
|
+
raise InvalidTransition("FAILED run 已经记录了不同的 reason")
|
|
899
|
+
self._refresh(state, now)
|
|
900
|
+
state.last_error = normalized_reason
|
|
901
|
+
state.status = Status.FAILED
|
|
902
|
+
# FAILED is terminal just like COMPLETE. Persist the terminal
|
|
903
|
+
# timestamp before the event is written so a subsequent process
|
|
904
|
+
# can reload/status the run without violating RunState invariants.
|
|
905
|
+
state.completed_at = now
|
|
906
|
+
self._release_active_claims(state, now, reason="run_failed")
|
|
907
|
+
self._append_event(
|
|
908
|
+
state, "run_failed", now, reason=state.last_error,
|
|
909
|
+
)
|
|
910
|
+
return state
|
|
911
|
+
|
|
912
|
+
return self._mutate(operation) # type: ignore[return-value]
|
|
913
|
+
|
|
914
|
+
def status(self) -> RunState:
|
|
915
|
+
"""重新从磁盘读取状态,并标记已过期 lease/硬时间预算。"""
|
|
916
|
+
|
|
917
|
+
def operation(state: RunState, now: float) -> RunState:
|
|
918
|
+
self._refresh_status_budget(state, now)
|
|
919
|
+
self._refresh_confirmation_gate(state)
|
|
920
|
+
return state
|
|
921
|
+
|
|
922
|
+
return self._query_readonly(operation) # type: ignore[return-value]
|
|
923
|
+
|
|
924
|
+
def status_with_gate(self) -> dict[str, object]:
|
|
925
|
+
"""在同一个文件锁快照中返回状态与并发门禁。
|
|
926
|
+
|
|
927
|
+
MCP 宿主通常需要同时读取状态和 gate。分两次调用会让 worker 在两次
|
|
928
|
+
读取之间完成 checkpoint,导致 UI 展示一组互不对应的快照;该方法把
|
|
929
|
+
回收、预算刷新和 gate 计算放进同一个原子读取窗口。
|
|
930
|
+
"""
|
|
931
|
+
|
|
932
|
+
def operation(state: RunState, now: float) -> dict[str, object]:
|
|
933
|
+
self._refresh_status_budget(state, now)
|
|
934
|
+
self._refresh_confirmation_gate(state)
|
|
935
|
+
gate = build_parallel_gate_snapshot(
|
|
936
|
+
state,
|
|
937
|
+
self._parallel_gate_result(state, now=now),
|
|
938
|
+
self._target_gate_result(state),
|
|
939
|
+
)
|
|
940
|
+
return {"state": state.to_dict(), "parallel_gate": gate}
|
|
941
|
+
|
|
942
|
+
return self._query_readonly(operation) # type: ignore[return-value]
|
|
943
|
+
|
|
944
|
+
def decision_snapshot(self) -> dict[str, object]:
|
|
945
|
+
"""决策专用只读快照 (DOC-154):在共享读锁内读取纯内存决策字段。
|
|
946
|
+
|
|
947
|
+
不执行任何写操作,不升级写事务,不更新 revision,返回用于收敛与停机判定的不可变数据字典。
|
|
948
|
+
"""
|
|
949
|
+
with self._read_lock():
|
|
950
|
+
state = self._read_state_locked()
|
|
951
|
+
now = float(self._clock())
|
|
952
|
+
return build_decision_snapshot(state, now)
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
__all__ = [
|
|
956
|
+
"BudgetExhausted",
|
|
957
|
+
"AgentBinding",
|
|
958
|
+
"BugRecord",
|
|
959
|
+
"COVERAGE_BLOCKED",
|
|
960
|
+
"COVERAGE_COVERED",
|
|
961
|
+
"COVERAGE_PENDING",
|
|
962
|
+
"ClaimRejected",
|
|
963
|
+
"ConcurrencyNotSatisfied",
|
|
964
|
+
"InvalidCheckpoint",
|
|
965
|
+
"InvalidTransition",
|
|
966
|
+
"LeaseExpired",
|
|
967
|
+
"NoRunError",
|
|
968
|
+
"PersistenceError",
|
|
969
|
+
"RevisionConflict",
|
|
970
|
+
"RunAlreadyStarted",
|
|
971
|
+
"RunBudget",
|
|
972
|
+
"GraphRun",
|
|
973
|
+
"GraphTask",
|
|
974
|
+
"RunState",
|
|
975
|
+
"Status",
|
|
976
|
+
"Supervisor",
|
|
977
|
+
"SupervisorError",
|
|
978
|
+
"WorkerClaim",
|
|
979
|
+
"WorkspacePathError",
|
|
980
|
+
"resolve_system_concurrency",
|
|
981
|
+
]
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
def _cli_budget(args: argparse.Namespace) -> RunBudget:
|
|
985
|
+
from core.supervisor.cli import cli_budget as impl
|
|
986
|
+
return impl(args)
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
def _cli_supervisor(args: argparse.Namespace) -> Supervisor:
|
|
990
|
+
from core.supervisor.cli import cli_supervisor as impl
|
|
991
|
+
return impl(args)
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
_manifest_units = load_manifest_units
|
|
995
|
+
_cli_payload = load_checkpoint_payload
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
def _cli_print(value: RunState | WorkerClaim | Mapping[str, object]) -> None:
|
|
999
|
+
from core.supervisor.cli import cli_print as impl
|
|
1000
|
+
return impl(value)
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
def _incident_hints(supervisor: "Supervisor", ledger: Path, limit: int) -> dict[str, object]:
|
|
1004
|
+
from core.supervisor.cli import incident_hints as impl
|
|
1005
|
+
return impl(supervisor, ledger, limit)
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
1009
|
+
"""兼容入口;CLI 解析和业务分发位于 ``supervisor.cli``。"""
|
|
1010
|
+
from core.supervisor import cli as cli_module
|
|
1011
|
+
return cli_module.main(argv, api=sys.modules[__name__])
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
if __name__ == "__main__":
|
|
1015
|
+
raise SystemExit(main())
|