bugx-cli 0.0.0-stage → 0.1.0
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 +280 -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 +50 -0
- package/core/agent/__init__.py +146 -0
- package/core/agent/agent_artifacts.py +764 -0
- package/core/agent/agent_eval.py +1073 -0
- package/core/agent/agent_execution.py +552 -0
- package/core/agent/agent_orchestrator.py +1345 -0
- package/core/agent/agent_targets.py +871 -0
- package/core/agent/agent_workspace.py +770 -0
- package/core/assets/README.md +24 -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/project-layout.md +42 -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 +1822 -0
- package/core/autonomous_cve/audit_campaign.py +1232 -0
- package/core/autonomous_cve/behavior_graph.py +459 -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 +100 -0
- package/core/bugx.md +1299 -0
- package/core/bugx_paths.py +1846 -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 +1199 -0
- package/core/cloud_sync/cloud_onboard.py +702 -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 +760 -0
- package/core/cloud_sync/network_transport.py +275 -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 +721 -0
- package/core/contracts/AGENT_GUIDE.md +362 -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 +390 -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 +859 -0
- package/core/coverage/coverage_evidence.py +977 -0
- package/core/coverage/coverage_forensics.py +115 -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 +236 -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 +2625 -0
- package/core/fuzzing/README.md +49 -0
- package/core/fuzzing/__init__.py +82 -0
- package/core/fuzzing/concurrency_fuzzer.py +382 -0
- package/core/fuzzing/differential_oracle.py +629 -0
- package/core/fuzzing/fuzz_input.py +1188 -0
- package/core/fuzzing/stateful_fuzzer.py +332 -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 +772 -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 +41 -0
- package/core/host_acp/cline.py +235 -0
- package/core/host_acp/codex.py +245 -0
- package/core/host_acp/dsh.py +48 -0
- package/core/host_acp/opencode.py +154 -0
- package/core/host_acp/pi.py +36 -0
- package/core/host_acp/zcode.py +41 -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 +435 -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 +721 -0
- package/core/host_runtime/host_probe.py +41 -0
- package/core/host_runtime/host_provider_arbitrator.py +777 -0
- package/core/host_runtime/host_registry.py +655 -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 +368 -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 +136 -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 +451 -0
- package/core/hosts/claude.py +157 -0
- package/core/hosts/cline.py +225 -0
- package/core/hosts/codex.py +948 -0
- package/core/hosts/dsh.py +518 -0
- package/core/hosts/opencode.py +358 -0
- package/core/hosts/pi.py +151 -0
- package/core/hosts/zcode.py +219 -0
- package/core/i18n.py +252 -0
- package/core/infra/README.md +39 -0
- package/core/infra/__init__.py +15 -0
- package/core/infra/build_info.py +86 -0
- package/core/infra/client_metadata.py +185 -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 +1041 -0
- package/core/launch_phases/finding_confirm_phase.py +387 -0
- package/core/launch_phases/finding_settlement.py +1245 -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 +791 -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 +682 -0
- package/core/launch_phases/post_commit.py +567 -0
- package/core/launch_phases/post_coverage_sync.py +591 -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 +1087 -0
- package/core/launch_phases/post_receipt.py +362 -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 +862 -0
- package/core/launch_phases/pre_state_builder.py +1286 -0
- package/core/launch_phases/report_sharing.py +414 -0
- package/core/launch_phases/round_orchestrator.py +1133 -0
- package/core/launch_phases/session_runtime.py +1623 -0
- package/core/launch_phases/startup_gates.py +1022 -0
- package/core/launch_phases/startup_interaction.py +947 -0
- package/core/launch_phases/startup_version_gate.py +873 -0
- package/core/launch_phases/supervisor_bridge.py +1224 -0
- package/core/launch_phases/supervisor_coverage.py +417 -0
- package/core/launch_phases/supervisor_degraded.py +1219 -0
- package/core/launch_phases/worker_barriers.py +414 -0
- package/core/launch_phases/worker_orchestrator.py +1166 -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 +226 -0
- package/core/ledger/archive_ops.py +572 -0
- package/core/ledger/auto_materialization.py +459 -0
- package/core/ledger/bug-log.md +22 -0
- package/core/ledger/cli.py +270 -0
- package/core/ledger/export_ops.py +549 -0
- package/core/ledger/finding_confirmation.py +1274 -0
- package/core/ledger/finding_io.py +299 -0
- package/core/ledger/finding_lifecycle.py +307 -0
- package/core/ledger/finding_verification.py +369 -0
- package/core/ledger/incidents.py +999 -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 +681 -0
- package/core/ledger/receipt_contract.py +253 -0
- package/core/ledger/schema.py +1192 -0
- package/core/ledger/sync_ops.py +935 -0
- package/core/ledger/tool_experience.py +682 -0
- package/core/ledger/verify_life.py +1526 -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 +697 -0
- package/core/mcp_handlers/channel_lifecycle.py +696 -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 +239 -0
- package/core/mcp_handlers/rpc_server.py +465 -0
- package/core/mcp_handlers/supervisor_handlers.py +1435 -0
- package/core/mcp_handlers/telemetry_handlers.py +227 -0
- package/core/mcp_handlers/tool_table.py +1015 -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 +605 -0
- package/core/mcp_runtime_support/verifier.py +810 -0
- package/core/metadata.txt +5 -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 +267 -0
- package/core/planning/dynamic_flow_analyzer.py +328 -0
- package/core/planning/impact_pruner.py +435 -0
- package/core/planning/intent_adjudicator.py +175 -0
- package/core/planning/judge_pipeline.py +1163 -0
- package/core/planning/logic_analysis.py +419 -0
- package/core/planning/prompt_harness.py +1702 -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 +73 -0
- package/core/probes/README.md +51 -0
- package/core/probes/SPEC.md +26 -0
- package/core/probes/__init__.py +70 -0
- package/core/probes/android_probe.py +384 -0
- package/core/probes/base.py +147 -0
- package/core/probes/codebase_memory_probe.py +590 -0
- package/core/probes/desktop_probe.py +238 -0
- package/core/probes/differential_probe.py +356 -0
- package/core/probes/efficiency_probe.py +168 -0
- package/core/probes/ios_binary_probe.py +368 -0
- package/core/probes/memory_probe.py +326 -0
- package/core/probes/miniprogram_probe.py +323 -0
- package/core/probes/mobile_probe.py +281 -0
- package/core/probes/native_probe.py +214 -0
- package/core/probes/openwiki_probe.py +193 -0
- package/core/probes/pattern_probe.py +347 -0
- package/core/probes/platform_probe.py +343 -0
- package/core/probes/probe_registry.py +1669 -0
- package/core/probes/sast_probe.py +1009 -0
- package/core/probes/sast_rules.py +841 -0
- package/core/probes/sca_scanner.py +731 -0
- package/core/probes/web_probe.py +359 -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 +311 -0
- package/core/project_profiler/constants.py +247 -0
- package/core/project_profiler/detector.py +392 -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 +265 -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 +465 -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 +313 -0
- package/core/repair/rsi_repair.py +348 -0
- package/core/repair/rsi_rounds.py +212 -0
- package/core/repair/rsi_scope.py +262 -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 +224 -0
- package/core/report_engine/authority.py +255 -0
- package/core/report_engine/finding_report.py +417 -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 +761 -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 +822 -0
- package/core/report_engine/visual_report_builder.py +796 -0
- package/core/report_engine/web-conformance.md +63 -0
- package/core/report_engine/web_conformance.py +459 -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 +1684 -0
- package/core/retrieval/codebase_memory_bridge.py +337 -0
- package/core/retrieval/context_assembler.py +234 -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 +909 -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 +1132 -0
- package/core/retrieval/universal_code_matcher.py +437 -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 +1393 -0
- package/core/runtime/daemon_runner.py +623 -0
- package/core/runtime/fixture_solidify.py +449 -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 +769 -0
- package/core/runtime/platform_adapter.py +579 -0
- package/core/runtime/prep_validate.py +476 -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 +963 -0
- package/core/runtime/provider_window.py +97 -0
- package/core/runtime/resume_ticket.py +115 -0
- package/core/runtime/scenario_eval.py +814 -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 +416 -0
- package/core/skills/bugx_mcp_server.py +1134 -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 +760 -0
- package/core/supervisor/checkpoint_handler.py +368 -0
- package/core/supervisor/checkpoint_pipeline.py +1322 -0
- package/core/supervisor/checkpoint_sync.py +640 -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 +659 -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 +124 -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 +308 -0
- package/core/supervisor/round_governor.py +306 -0
- package/core/supervisor/serial_authorization.py +500 -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 +223 -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 +999 -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 +402 -0
- package/core/webui/INTERFACE.md +50 -0
- package/core/webui/README.md +57 -0
- package/core/webui/SPEC.md +25 -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 +218 -0
- package/core/webui/adapters/cline.py +399 -0
- package/core/webui/adapters/codex.py +256 -0
- package/core/webui/adapters/dsh.py +173 -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 +1743 -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/favicon.png +0 -0
- package/core/webui/static/icon-192.png +0 -0
- package/core/webui/static/index.html +42 -0
- package/core/webui/static/manifest.webmanifest +19 -0
- package/core/webui/static/project-settings.css +6458 -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 +281 -0
- package/docs/07_distribution/README.md +16 -0
- package/docs/README.md +121 -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 +3067 -0
- package/ecosystem/integrations/opencode/opencode.json +118 -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/README.md +143 -0
- package/interfaces/bin/README.md +35 -0
- package/interfaces/bin/bugx.js +80 -0
- package/interfaces/cli/README.md +90 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -0
- package/interfaces/cli/bugx_cli/cli.py +1678 -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 +3944 -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 +1370 -0
- package/interfaces/cli/bugx_cli/commands/daemon.py +50 -0
- package/interfaces/cli/bugx_cli/commands/doctor.py +1345 -0
- package/interfaces/cli/bugx_cli/commands/goal.py +107 -0
- package/interfaces/cli/bugx_cli/commands/interaction.py +244 -0
- package/interfaces/cli/bugx_cli/commands/knowledge.py +617 -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 +2714 -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 +728 -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 +260 -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 +898 -0
- package/interfaces/cli/bugx_cli/host_adapters.py +1917 -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 +571 -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 +721 -0
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +1937 -0
- package/interfaces/cli/bugx_cli/infra/host_sync.py +545 -0
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +755 -0
- package/interfaces/cli/bugx_cli/infra/security.py +332 -0
- package/package.json +98 -4
- package/pyproject.toml +246 -0
- package/scripts/README.md +118 -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 +37 -0
- package/scripts/test-npm-wrapper.mjs +265 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Automatic project knowledge materialization for ``review_mode=mcp-auto``.
|
|
3
|
+
|
|
4
|
+
This module only turns confirmed findings into candidate ledger records and
|
|
5
|
+
their first bound validation feedback. It does not activate knowledge or
|
|
6
|
+
bypass the existing review/confirmation gates.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
# --- 引擎导入根(直接执行脚本时自举 core.* 命名空间)---
|
|
10
|
+
import sys as _sys
|
|
11
|
+
from pathlib import Path as _Path
|
|
12
|
+
|
|
13
|
+
for _p in _Path(__file__).resolve().parents:
|
|
14
|
+
if (_p / "core" / "bugx.md").is_file():
|
|
15
|
+
if str(_p) not in _sys.path:
|
|
16
|
+
_sys.path.insert(0, str(_p))
|
|
17
|
+
break
|
|
18
|
+
del _p
|
|
19
|
+
import sys
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
from typing import Any, Mapping
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_CATEGORY_RULES = (
|
|
28
|
+
("secrets", ("secret", "credential", "password", "api key", "apikey", "凭据", "密钥")),
|
|
29
|
+
("authorization", ("authorization", "access control", "permission", "privilege", "越权", "权限")),
|
|
30
|
+
("injection", ("sql injection", "command injection", "template injection", "注入")),
|
|
31
|
+
("concurrency", ("race condition", "deadlock", "并发", "竞态", "死锁")),
|
|
32
|
+
("dependency", ("dependency", "third-party", "package", "library", "组件", "依赖")),
|
|
33
|
+
("api-contract", ("api contract", "schema", "request", "response", "接口契约")),
|
|
34
|
+
("input-boundary", ("input", "validation", "boundary", "输入", "校验", "边界")),
|
|
35
|
+
("partial-failure", ("partial failure", "rollback", "timeout", "超时", "回滚")),
|
|
36
|
+
("ordering", ("ordering", "sequence", "顺序", "时序")),
|
|
37
|
+
("type-assumption", ("type error", "type assumption", "类型假设", "类型错误")),
|
|
38
|
+
("performance", ("performance", "slow", "latency", "性能", "延迟")),
|
|
39
|
+
("ui", ("frontend", "browser", "render", "layout", "界面", "前端", "浏览器")),
|
|
40
|
+
("regression", ("regression", "回归")),
|
|
41
|
+
)
|
|
42
|
+
_ID_RE = re.compile(r"^L-[0-9a-f]{12}$")
|
|
43
|
+
_SOURCE_REF = "auto://confirmed-finding"
|
|
44
|
+
_REDACTION_PLACEHOLDER = re.compile(r"\{\{REDACTED_[A-Z0-9_]+\}\}")
|
|
45
|
+
_REDACTION_TOKEN = "{{REDACTED_SECRET_V1}}"
|
|
46
|
+
_CREDENTIAL_ASSIGNMENT = re.compile(
|
|
47
|
+
r"(?i)(?<![\w-])credentials?\s*[:=]\s*(?:\"[^\"]*\"|'[^']*'|[^\s,;]+)"
|
|
48
|
+
)
|
|
49
|
+
_PATTERN_TEXT_FIELDS = (
|
|
50
|
+
"category", "title", "root_cause", "reflection", "severity", "language",
|
|
51
|
+
"cwe_id", "error_signature", "before_code", "after_code", "fix_summary",
|
|
52
|
+
"repro_oracle",
|
|
53
|
+
)
|
|
54
|
+
_PATTERN_TEXT_LIST_FIELDS = (
|
|
55
|
+
"probes", "negative_controls", "evidence_requirements", "applicability",
|
|
56
|
+
"false_positive_patterns", "oracle_hints", "tags", "playbook",
|
|
57
|
+
"attempts_tried", "successful_solution", "aliases", "source_refs",
|
|
58
|
+
)
|
|
59
|
+
_INCIDENT_TEXT_FIELDS = (
|
|
60
|
+
"signature", "summary", "context", "before_snippet", "after_snippet", "decision",
|
|
61
|
+
)
|
|
62
|
+
_MAX_REDACT_CACHE_SIZE = 2048
|
|
63
|
+
_MEMO_REDACT: dict[tuple[str, str | None], Any] = {}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _quick_redact_text(value: Any, *, language: str | None = None) -> Any:
|
|
67
|
+
"""带边界容量缓存的快速脱敏助手 (L5-OPT-3)。"""
|
|
68
|
+
if not isinstance(value, str) or not value:
|
|
69
|
+
return value
|
|
70
|
+
cache_key = (value, language)
|
|
71
|
+
if cache_key in _MEMO_REDACT:
|
|
72
|
+
return _MEMO_REDACT[cache_key]
|
|
73
|
+
from core.governance.secret_redactor import redact_text as _orig_redact
|
|
74
|
+
cleaned = _orig_redact(value, language=language)
|
|
75
|
+
if len(_MEMO_REDACT) >= _MAX_REDACT_CACHE_SIZE:
|
|
76
|
+
_MEMO_REDACT.clear()
|
|
77
|
+
_MEMO_REDACT[cache_key] = cleaned
|
|
78
|
+
return cleaned
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _text(value: Any, limit: int = 2000) -> str:
|
|
82
|
+
if value is None:
|
|
83
|
+
return ""
|
|
84
|
+
return " ".join(str(value).split())[:limit]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _thaw_snapshot_value(value: Any) -> Any:
|
|
88
|
+
"""Copy an immutable FindingsSnapshot value into validator-compatible containers.
|
|
89
|
+
|
|
90
|
+
Findings snapshots are recursively frozen before they cross the settlement
|
|
91
|
+
boundary. ``finding_confirmation`` intentionally validates the JSON
|
|
92
|
+
protocol using ordinary ``dict``/``list`` containers, so a shallow
|
|
93
|
+
``dict(item)`` leaves nested ``MappingProxyType`` and tuple values that are
|
|
94
|
+
rejected as malformed. This copy remains transient: only the sanitized
|
|
95
|
+
projection built later can reach the ledger.
|
|
96
|
+
"""
|
|
97
|
+
if isinstance(value, Mapping):
|
|
98
|
+
return {key: _thaw_snapshot_value(item) for key, item in value.items()}
|
|
99
|
+
if isinstance(value, (list, tuple)):
|
|
100
|
+
return [_thaw_snapshot_value(item) for item in value]
|
|
101
|
+
return value
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _category(value: Any) -> str:
|
|
105
|
+
raw = _text(value, 120).casefold()
|
|
106
|
+
return re.sub(r"[^\w\u4e00-\u9fff]+", "-", raw, flags=re.UNICODE).strip("-")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _finding_text(finding: Mapping[str, Any]) -> str:
|
|
110
|
+
values = [
|
|
111
|
+
finding.get(key)
|
|
112
|
+
for key in ("title", "root_cause", "summary", "description", "reproduction", "error_signature", "signature")
|
|
113
|
+
]
|
|
114
|
+
values.extend(
|
|
115
|
+
item.get("path")
|
|
116
|
+
for item in finding.get("evidence") or []
|
|
117
|
+
if isinstance(item, Mapping)
|
|
118
|
+
)
|
|
119
|
+
return _text(" ".join(str(item) for item in values if item), 6000).casefold()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def classify_finding(finding: Mapping[str, Any], profile: Mapping[str, Any] | None = None) -> str:
|
|
123
|
+
"""Return an explicit category first, then a stable keyword category."""
|
|
124
|
+
for key in ("category", "bug_type", "finding_type", "kind"):
|
|
125
|
+
value = _category(finding.get(key))
|
|
126
|
+
if value:
|
|
127
|
+
return value
|
|
128
|
+
haystack = _finding_text(finding)
|
|
129
|
+
for category, keywords in _CATEGORY_RULES:
|
|
130
|
+
if any(keyword.casefold() in haystack for keyword in keywords):
|
|
131
|
+
return category
|
|
132
|
+
return "uncategorized"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _profile_tags(profile: Mapping[str, Any] | None) -> dict[str, list[str]]:
|
|
136
|
+
if not profile:
|
|
137
|
+
return {}
|
|
138
|
+
try:
|
|
139
|
+
from core.runtime import project_profile
|
|
140
|
+
return project_profile.routing_tags(profile)
|
|
141
|
+
except (ImportError, TypeError, ValueError, AttributeError):
|
|
142
|
+
return {}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _finding_fingerprint(finding: Mapping[str, Any]) -> str:
|
|
146
|
+
from core.ledger import life_ledger
|
|
147
|
+
return life_ledger.finding_fingerprint(dict(finding))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _oracle_reference(finding: Mapping[str, Any]) -> str:
|
|
151
|
+
confirmation = finding.get("confirmation")
|
|
152
|
+
oracle = confirmation.get("oracle") if isinstance(confirmation, Mapping) else None
|
|
153
|
+
return _text((oracle or {}).get("reference"), 1000) if isinstance(oracle, Mapping) else ""
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def build_pattern_payload(
|
|
157
|
+
finding: Mapping[str, Any], profile: Mapping[str, Any] | None = None,
|
|
158
|
+
*, finding_fingerprints: list[str] | None = None,
|
|
159
|
+
) -> dict[str, Any]:
|
|
160
|
+
category = classify_finding(finding, profile)
|
|
161
|
+
title = _quick_redact_text(_text(finding.get("title"), 2000) or "confirmed finding")
|
|
162
|
+
root_cause = _quick_redact_text(_text(finding.get("root_cause"), 4000) or title)
|
|
163
|
+
reproduction = _quick_redact_text(_text(finding.get("reproduction"), 1600))
|
|
164
|
+
oracle = _oracle_reference(finding)
|
|
165
|
+
fingerprints = finding_fingerprints or [_finding_fingerprint(finding)]
|
|
166
|
+
tags = ["auto-generated", category]
|
|
167
|
+
payload: dict[str, Any] = {
|
|
168
|
+
"category": category,
|
|
169
|
+
"title": title,
|
|
170
|
+
"root_cause": root_cause,
|
|
171
|
+
"reflection": "自动复盘:confirmed Finding 已通过确认门禁,等待人工治理晋级。",
|
|
172
|
+
"probes": ["confirmed-finding"],
|
|
173
|
+
"negative_controls": [],
|
|
174
|
+
"evidence_requirements": ["finding_confirmation:confirmed"],
|
|
175
|
+
"applicability": ["project-ledger"],
|
|
176
|
+
"false_positive_patterns": [],
|
|
177
|
+
"oracle_hints": ["confirmation-state:confirmed"],
|
|
178
|
+
"tags": tags,
|
|
179
|
+
"playbook": ["复核 Finding 证据并补充修前/修后决策链"],
|
|
180
|
+
"attempts_tried": [],
|
|
181
|
+
"successful_solution": [],
|
|
182
|
+
"aliases": [],
|
|
183
|
+
"source_refs": [_SOURCE_REF],
|
|
184
|
+
"finding_fingerprints": sorted(set(fingerprints)),
|
|
185
|
+
"status": "candidate",
|
|
186
|
+
"routing_tags": _profile_tags(profile),
|
|
187
|
+
"severity": _text(finding.get("severity"), 20).upper(),
|
|
188
|
+
"language": _text(finding.get("language") or finding.get("language_version"), 50),
|
|
189
|
+
"cwe_id": _text(finding.get("cwe_id"), 20),
|
|
190
|
+
"error_signature": _text(finding.get("error_signature") or finding.get("signature"), 500),
|
|
191
|
+
"before_code": _text(finding.get("before_code"), 4000),
|
|
192
|
+
"after_code": _text(finding.get("after_code"), 4000),
|
|
193
|
+
"fix_summary": _text(finding.get("fix_summary"), 1800),
|
|
194
|
+
"repro_oracle": reproduction or oracle or "confirmed finding",
|
|
195
|
+
}
|
|
196
|
+
return payload
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def build_incident_payload(
|
|
200
|
+
finding: Mapping[str, Any], pattern_id: str, runtime: Mapping[str, Any], round_no: int,
|
|
201
|
+
profile: Mapping[str, Any] | None = None, *, finding_fingerprint: str | None = None,
|
|
202
|
+
) -> dict[str, Any]:
|
|
203
|
+
from core.ledger import lesson_ledger as ledger
|
|
204
|
+
|
|
205
|
+
category = classify_finding(finding, profile)
|
|
206
|
+
title = _quick_redact_text(_text(finding.get("title"), 2000) or "confirmed finding")
|
|
207
|
+
root_cause = _quick_redact_text(_text(finding.get("root_cause"), 3000) or title)
|
|
208
|
+
reproduction = _quick_redact_text(_text(finding.get("reproduction"), 2200) or "confirmed finding")
|
|
209
|
+
signature = _text(
|
|
210
|
+
finding.get("error_signature") or finding.get("signature") or f"{category}: {title}",
|
|
211
|
+
500,
|
|
212
|
+
)
|
|
213
|
+
fingerprint = finding_fingerprint or _finding_fingerprint(finding)
|
|
214
|
+
return {
|
|
215
|
+
# Compute the stable identity from raw text and the raw Finding fingerprint
|
|
216
|
+
# before redaction. Only the opaque ID is persisted.
|
|
217
|
+
"incident_id": ledger.incident_id(
|
|
218
|
+
signature, title, None, finding_fingerprint=fingerprint,
|
|
219
|
+
),
|
|
220
|
+
"signature": signature,
|
|
221
|
+
"summary": title,
|
|
222
|
+
"context": f"{root_cause};复现:{reproduction}",
|
|
223
|
+
"before_snippet": _text(finding.get("before_code"), 6000) or "",
|
|
224
|
+
"after_snippet": _text(finding.get("after_code"), 6000) or "",
|
|
225
|
+
"decision": _text(finding.get("fix_summary"), 4000) or "",
|
|
226
|
+
"duration_seconds": 0,
|
|
227
|
+
"lifecycle_id": _text(runtime.get("lifecycle_id"), 200),
|
|
228
|
+
"round": round_no,
|
|
229
|
+
"pattern_id": pattern_id,
|
|
230
|
+
"status": "candidate",
|
|
231
|
+
"routing_tags": _profile_tags(profile),
|
|
232
|
+
"finding_fingerprint": fingerprint,
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _guard(payload: Mapping[str, Any], label: str) -> None:
|
|
237
|
+
from core.retrieval import knowledge_sync
|
|
238
|
+
try:
|
|
239
|
+
knowledge_sync.enforce_credential_block(payload, label=label)
|
|
240
|
+
except Exception:
|
|
241
|
+
# The current guard embeds a credential prefix in its exception. Keep the
|
|
242
|
+
# failure closed while ensuring post/stdout/logs cannot echo Finding data.
|
|
243
|
+
raise ValueError("auto_materialization_credential_blocked") from None
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _load_findings_snapshot(runtime: Mapping[str, Any]):
|
|
247
|
+
from core.launch_phases.finding_settlement import capture_findings_snapshot
|
|
248
|
+
|
|
249
|
+
return capture_findings_snapshot(dict(runtime))
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def load_confirmed_findings(runtime: Mapping[str, Any]) -> list[dict[str, Any]]:
|
|
253
|
+
"""Return confirmed inputs from one validated, bounded Finding snapshot."""
|
|
254
|
+
snapshot = _load_findings_snapshot(runtime)
|
|
255
|
+
if snapshot is None:
|
|
256
|
+
return []
|
|
257
|
+
from core.ledger import finding_confirmation
|
|
258
|
+
return [dict(item) for item in snapshot.findings if finding_confirmation.is_confirmed(item)]
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _plans(
|
|
262
|
+
path: str | Path, findings: list[dict[str, Any]], profile: Mapping[str, Any] | None,
|
|
263
|
+
*, ledger_state: Mapping[str, Any] | None = None,
|
|
264
|
+
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
|
265
|
+
from core.ledger import lesson_ledger as ledger
|
|
266
|
+
|
|
267
|
+
stored = (ledger_state or ledger.read(path)).get("lessons", {})
|
|
268
|
+
by_fingerprint = {
|
|
269
|
+
fingerprint: key
|
|
270
|
+
for key, item in stored.items()
|
|
271
|
+
for fingerprint in item.get("finding_fingerprints", [])
|
|
272
|
+
}
|
|
273
|
+
planned: list[dict[str, Any]] = []
|
|
274
|
+
grouped: dict[str, dict[str, Any]] = {}
|
|
275
|
+
for finding in findings:
|
|
276
|
+
fingerprint = _finding_fingerprint(finding)
|
|
277
|
+
confirmation_digest = ledger.confirmed_finding_digest({"finding": finding})
|
|
278
|
+
category = classify_finding(finding, profile)
|
|
279
|
+
# DOC-203 缺陷修补(build.49):root_cause/title 是 sync 身份锁字段,
|
|
280
|
+
# 修复轮之前无法改写;当它们引用字面示例凭据形态(如 root_cause 描述
|
|
281
|
+
# "凭据回显"缺陷时必引 sk- 形态示例)时,复盘 Pattern 的凭据扫描与
|
|
282
|
+
# sync 身份锁互斥、post 永远无法收敛。Pattern 文本入账前先走引擎
|
|
283
|
+
# 统一脱敏(typed {{REDACTED_*}} 是 enforce_credential_block 明文
|
|
284
|
+
# 放行形态),技术语义保留、凭据形态消除。
|
|
285
|
+
title = _quick_redact_text(
|
|
286
|
+
_text(finding.get("title"), 2000) or "confirmed finding")
|
|
287
|
+
root = _quick_redact_text(
|
|
288
|
+
_text(finding.get("root_cause"), 4000)) or title
|
|
289
|
+
explicit = finding.get("pattern_id")
|
|
290
|
+
pattern_id = str(explicit) if isinstance(explicit, str) and _ID_RE.fullmatch(explicit) else None
|
|
291
|
+
pattern_id = pattern_id or by_fingerprint.get(fingerprint)
|
|
292
|
+
pattern_id = pattern_id or ledger.lesson_id(category, title, root)
|
|
293
|
+
plan = {
|
|
294
|
+
"finding": finding, "fingerprint": fingerprint,
|
|
295
|
+
"confirmation_digest": confirmation_digest, "pattern_id": pattern_id,
|
|
296
|
+
}
|
|
297
|
+
planned.append(plan)
|
|
298
|
+
if pattern_id not in grouped:
|
|
299
|
+
grouped[pattern_id] = build_pattern_payload(
|
|
300
|
+
finding, profile, finding_fingerprints=[fingerprint],
|
|
301
|
+
)
|
|
302
|
+
grouped[pattern_id]["pattern_id"] = pattern_id
|
|
303
|
+
else:
|
|
304
|
+
grouped[pattern_id]["finding_fingerprints"].append(fingerprint)
|
|
305
|
+
return planned, {key: value for key, value in grouped.items() if key not in stored}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _confirmed_snapshot_inputs(
|
|
309
|
+
runtime: Mapping[str, Any], round_result: Mapping[str, Any], snapshot: Any,
|
|
310
|
+
) -> list[dict[str, Any]]:
|
|
311
|
+
from core.ledger import finding_confirmation
|
|
312
|
+
|
|
313
|
+
settled_round = round_result.get("round")
|
|
314
|
+
if (
|
|
315
|
+
not isinstance(settled_round, int)
|
|
316
|
+
or isinstance(settled_round, bool)
|
|
317
|
+
or settled_round < 1
|
|
318
|
+
):
|
|
319
|
+
raise ValueError("confirmed_finding_round_invalid")
|
|
320
|
+
runtime_round = runtime.get("round")
|
|
321
|
+
if runtime_round is not None:
|
|
322
|
+
if (
|
|
323
|
+
not isinstance(runtime_round, int)
|
|
324
|
+
or isinstance(runtime_round, bool)
|
|
325
|
+
or runtime_round < 1
|
|
326
|
+
):
|
|
327
|
+
raise ValueError("runtime_round_invalid")
|
|
328
|
+
if runtime_round != settled_round:
|
|
329
|
+
# DOC-D1:恢复/续轮场景下 runtime.round 可能已推进(next-round)而
|
|
330
|
+
# 被结算轮次仍是上一轮——这不是数据损坏,是轮次身份的**时序差**。
|
|
331
|
+
# 判定改用事实锚:只要 runtime.round ≥ settled_round 即视为同一条
|
|
332
|
+
# 结算链(forward-consistent);回退(<)才是真异常。
|
|
333
|
+
if runtime_round < settled_round:
|
|
334
|
+
raise ValueError(
|
|
335
|
+
"confirmed_finding_round_mismatch: runtime.round "
|
|
336
|
+
f"({runtime_round}) 落后于被结算轮次 ({settled_round});"
|
|
337
|
+
"请勿在 next-round 后回退 runtime"
|
|
338
|
+
)
|
|
339
|
+
print(
|
|
340
|
+
f"[knowledge_auto] runtime.round={runtime_round} 已领先被结算"
|
|
341
|
+
f"轮次 {settled_round}(next-round 先行),按结算链继续复盘"
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
if snapshot is None:
|
|
345
|
+
findings: list[dict[str, Any]] = []
|
|
346
|
+
else:
|
|
347
|
+
expected_binding = getattr(snapshot, "expected_binding", None)
|
|
348
|
+
if expected_binding is None:
|
|
349
|
+
# ``finding_io`` deliberately preserves the existing unbound
|
|
350
|
+
# report exception for the non-project legacy layout. Keep that
|
|
351
|
+
# policy at the materialization boundary too; a formal snapshot
|
|
352
|
+
# can never arrive here without an expected binding because the
|
|
353
|
+
# shared validator rejects it during capture.
|
|
354
|
+
if getattr(snapshot, "layout_policy", None) != "legacy":
|
|
355
|
+
raise ValueError("findings_snapshot_binding_missing")
|
|
356
|
+
elif not isinstance(expected_binding, Mapping):
|
|
357
|
+
raise ValueError("findings_snapshot_binding_missing")
|
|
358
|
+
else:
|
|
359
|
+
expected_runtime_binding = {
|
|
360
|
+
"runtime_run_uuid": runtime.get("run_id"),
|
|
361
|
+
"lifecycle_id": runtime.get("lifecycle_id"),
|
|
362
|
+
"round": runtime.get("round"),
|
|
363
|
+
"polling_id": runtime.get("polling_id"),
|
|
364
|
+
}
|
|
365
|
+
# DOC-D1 forward-consistent(与下方 confirmed 校验同语义,2026-11-09
|
|
366
|
+
# 实测修复 findings_snapshot_round_mismatch 死锁):next-round 先把
|
|
367
|
+
# runtime.round 推进后,快照 binding 里记的是被结算轮次——身份
|
|
368
|
+
# (run_uuid/lifecycle/polling)必须逐字一致;round 允许 runtime
|
|
369
|
+
# 领先(≥ settled_round),回退才是真异常。
|
|
370
|
+
binding = dict(expected_binding)
|
|
371
|
+
for key in ("runtime_run_uuid", "lifecycle_id", "polling_id"):
|
|
372
|
+
if binding.get(key) != expected_runtime_binding.get(key):
|
|
373
|
+
raise ValueError(
|
|
374
|
+
"findings_snapshot_binding_mismatch: "
|
|
375
|
+
f"{key} 快照={binding.get(key)!r} runtime="
|
|
376
|
+
f"{expected_runtime_binding.get(key)!r}"
|
|
377
|
+
)
|
|
378
|
+
bound_round = binding.get("round")
|
|
379
|
+
if bound_round != settled_round:
|
|
380
|
+
raise ValueError(
|
|
381
|
+
"findings_snapshot_round_mismatch: 快照绑定轮 "
|
|
382
|
+
f"({bound_round}) 与被结算轮次 ({settled_round}) 不一致"
|
|
383
|
+
)
|
|
384
|
+
runtime_round = runtime.get("round")
|
|
385
|
+
if (
|
|
386
|
+
not isinstance(runtime_round, int) or isinstance(runtime_round, bool)
|
|
387
|
+
):
|
|
388
|
+
runtime_round = bound_round
|
|
389
|
+
if runtime_round < settled_round:
|
|
390
|
+
raise ValueError(
|
|
391
|
+
"findings_snapshot_round_mismatch: runtime.round "
|
|
392
|
+
f"({runtime_round}) 落后于快照绑定轮 ({settled_round})"
|
|
393
|
+
)
|
|
394
|
+
# The snapshot constructor has already passed the shared pure validator
|
|
395
|
+
# against this exact payload and its no-follow artifact metadata.
|
|
396
|
+
findings = []
|
|
397
|
+
for item in snapshot.findings:
|
|
398
|
+
candidate = _thaw_snapshot_value(item)
|
|
399
|
+
if finding_confirmation.is_confirmed(candidate):
|
|
400
|
+
findings.append(candidate)
|
|
401
|
+
expected_findings = round_result.get("findings", 0)
|
|
402
|
+
credited = round_result.get("credited", 0)
|
|
403
|
+
for name, value in (("findings", expected_findings), ("credited", credited)):
|
|
404
|
+
if (
|
|
405
|
+
not isinstance(value, int)
|
|
406
|
+
or isinstance(value, bool)
|
|
407
|
+
or value < 0
|
|
408
|
+
):
|
|
409
|
+
raise ValueError(f"confirmed_finding_{name}_invalid")
|
|
410
|
+
from core.launch_phases.finding_settlement import credited_cap
|
|
411
|
+
if expected_findings != len(findings) or credited != min(len(findings), credited_cap()):
|
|
412
|
+
raise ValueError(
|
|
413
|
+
"confirmed_finding_settlement_mismatch: "
|
|
414
|
+
f"confirmed={len(findings)} settled={expected_findings}/{credited}"
|
|
415
|
+
)
|
|
416
|
+
return findings
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def _redact_text(redactor: Any, value: Any, *, language: str | None = None) -> Any:
|
|
420
|
+
if not isinstance(value, str):
|
|
421
|
+
return value
|
|
422
|
+
cache_key = (value, language)
|
|
423
|
+
if cache_key in _MEMO_REDACT:
|
|
424
|
+
return _MEMO_REDACT[cache_key]
|
|
425
|
+
try:
|
|
426
|
+
# The shared redactor's assignment vocabulary deliberately covers
|
|
427
|
+
# passwords/tokens/API keys; automatic Finding summaries also contain
|
|
428
|
+
# the plain-English ``credential=...`` spelling, so close that local
|
|
429
|
+
# gap before delegating the remaining text to the shared redactor.
|
|
430
|
+
value = _CREDENTIAL_ASSIGNMENT.sub(_REDACTION_TOKEN, value)
|
|
431
|
+
cleaned = redactor.redact_text(value, language=language)
|
|
432
|
+
cleaned = _REDACTION_PLACEHOLDER.sub(_REDACTION_TOKEN, cleaned)
|
|
433
|
+
# The shared scanner also sees JSON quoting around the text leaf. A
|
|
434
|
+
# redacted assignment followed by prose can then look like one large,
|
|
435
|
+
# unredacted value to its quoted-assignment rule. If that serialized
|
|
436
|
+
# leaf still triggers the scanner, discard the whole free-text leaf;
|
|
437
|
+
# retaining only a typed marker stays safe and keeps the ledger write
|
|
438
|
+
# fail-closed for fields the redactor cannot fully normalize.
|
|
439
|
+
import json
|
|
440
|
+
from core.governance.secret_redactor import find_unredacted_secrets
|
|
441
|
+
if find_unredacted_secrets(json.dumps(cleaned, ensure_ascii=False)):
|
|
442
|
+
res = _REDACTION_TOKEN
|
|
443
|
+
else:
|
|
444
|
+
res = cleaned
|
|
445
|
+
if len(_MEMO_REDACT) >= _MAX_REDACT_CACHE_SIZE:
|
|
446
|
+
_MEMO_REDACT.clear()
|
|
447
|
+
_MEMO_REDACT[cache_key] = res
|
|
448
|
+
return res
|
|
449
|
+
except Exception:
|
|
450
|
+
raise ValueError("auto_materialization_redaction_failed") from None
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def _sanitize_projection(projection: dict[str, Any]) -> dict[str, Any]:
|
|
454
|
+
"""Redact only explicitly allowlisted free-text leaves in the projection."""
|
|
455
|
+
try:
|
|
456
|
+
from core.governance.secret_redactor import SecretRedactor
|
|
457
|
+
with SecretRedactor(max_mappings=4096, redact_pii=True) as redactor:
|
|
458
|
+
for item in projection["patterns"]:
|
|
459
|
+
language = item.get("language") if isinstance(item.get("language"), str) else None
|
|
460
|
+
for key in _PATTERN_TEXT_FIELDS:
|
|
461
|
+
if key in item:
|
|
462
|
+
item[key] = _redact_text(redactor, item[key], language=language)
|
|
463
|
+
for key in _PATTERN_TEXT_LIST_FIELDS:
|
|
464
|
+
values = item.get(key)
|
|
465
|
+
if isinstance(values, list):
|
|
466
|
+
item[key] = [_redact_text(redactor, value, language=language) for value in values]
|
|
467
|
+
tags = item.get("routing_tags")
|
|
468
|
+
if isinstance(tags, Mapping):
|
|
469
|
+
item["routing_tags"] = {
|
|
470
|
+
key: [_redact_text(redactor, value) for value in values]
|
|
471
|
+
if isinstance(values, list) else values
|
|
472
|
+
for key, values in tags.items()
|
|
473
|
+
}
|
|
474
|
+
for item in projection["incidents"]:
|
|
475
|
+
for key in _INCIDENT_TEXT_FIELDS:
|
|
476
|
+
if key in item:
|
|
477
|
+
item[key] = _redact_text(redactor, item[key])
|
|
478
|
+
tags = item.get("routing_tags")
|
|
479
|
+
if isinstance(tags, Mapping):
|
|
480
|
+
item["routing_tags"] = {
|
|
481
|
+
key: [_redact_text(redactor, value) for value in values]
|
|
482
|
+
if isinstance(values, list) else values
|
|
483
|
+
for key, values in tags.items()
|
|
484
|
+
}
|
|
485
|
+
review = projection["review"]
|
|
486
|
+
if isinstance(review.get("no_new_lesson_reason"), str):
|
|
487
|
+
review["no_new_lesson_reason"] = _redact_text(
|
|
488
|
+
redactor, review["no_new_lesson_reason"],
|
|
489
|
+
)
|
|
490
|
+
for item in review.get("feedback", []):
|
|
491
|
+
item["signature"] = _redact_text(redactor, item.get("signature"))
|
|
492
|
+
for item in projection["tool_feedback"]:
|
|
493
|
+
item["category"] = _redact_text(redactor, item.get("category"))
|
|
494
|
+
except ValueError as exc:
|
|
495
|
+
if str(exc).startswith("auto_materialization_"):
|
|
496
|
+
raise
|
|
497
|
+
raise ValueError("auto_materialization_redaction_failed") from None
|
|
498
|
+
except Exception:
|
|
499
|
+
raise ValueError("auto_materialization_redaction_failed") from None
|
|
500
|
+
return projection
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
def _build_projection(
|
|
504
|
+
ledger_path: str | Path, runtime: Mapping[str, Any], round_result: Mapping[str, Any],
|
|
505
|
+
profile: Mapping[str, Any] | None, snapshot: Any, *, include_incidents: bool,
|
|
506
|
+
) -> tuple[dict[str, Any], list[dict[str, Any]], list[str], str]:
|
|
507
|
+
from core.ledger import lesson_ledger as ledger
|
|
508
|
+
|
|
509
|
+
findings = _confirmed_snapshot_inputs(runtime, round_result, snapshot)
|
|
510
|
+
state = ledger.read(ledger_path)
|
|
511
|
+
plans, missing_patterns = _plans(
|
|
512
|
+
ledger_path, findings, profile, ledger_state=state,
|
|
513
|
+
)
|
|
514
|
+
round_no = int(round_result.get("round") or 0)
|
|
515
|
+
if round_no < 1:
|
|
516
|
+
raise ValueError("自动复盘缺少有效 round")
|
|
517
|
+
life = _text(runtime.get("lifecycle_id"), 200)
|
|
518
|
+
polling = _text(runtime.get("polling_id"), 200)
|
|
519
|
+
credited = int(round_result.get("credited", 0) or 0)
|
|
520
|
+
credited_plans = plans[:credited]
|
|
521
|
+
new_pattern_ids = set(missing_patterns)
|
|
522
|
+
all_pattern_ids = sorted({str(item["pattern_id"]) for item in plans})
|
|
523
|
+
|
|
524
|
+
review_details = ledger.review_details(ledger_path, life, round_no, polling) or {}
|
|
525
|
+
expected_review_fingerprints = sorted(
|
|
526
|
+
item["fingerprint"] for item in credited_plans
|
|
527
|
+
)
|
|
528
|
+
supersede_stale = bool(review_details) and (
|
|
529
|
+
int(review_details.get("finding_count", -1)) != len(findings)
|
|
530
|
+
or int(review_details.get("credited_count", -1)) != credited
|
|
531
|
+
or sorted(review_details.get("finding_fingerprints", []))
|
|
532
|
+
!= expected_review_fingerprints
|
|
533
|
+
or sorted(review_details.get("pattern_ids", [])) != all_pattern_ids
|
|
534
|
+
)
|
|
535
|
+
if review_details and not supersede_stale:
|
|
536
|
+
no_new_lesson_reason = review_details.get("reason")
|
|
537
|
+
else:
|
|
538
|
+
no_new_lesson_reason = (
|
|
539
|
+
None if new_pattern_ids else (
|
|
540
|
+
"自动复盘:本轮 confirmed Finding 已匹配现有 Pattern"
|
|
541
|
+
if findings else "自动复盘:本轮没有 confirmed Finding"
|
|
542
|
+
)
|
|
543
|
+
)
|
|
544
|
+
review = {
|
|
545
|
+
"actor": "supervisor", "lifecycle_id": life, "polling_id": polling,
|
|
546
|
+
"round": round_no, "finding_count": len(findings),
|
|
547
|
+
"credited_count": credited,
|
|
548
|
+
"pattern_ids": all_pattern_ids,
|
|
549
|
+
"finding_fingerprints": [item["fingerprint"] for item in credited_plans],
|
|
550
|
+
"feedback": [
|
|
551
|
+
{
|
|
552
|
+
"pattern_id": item["pattern_id"], "outcome": "hit",
|
|
553
|
+
"finding_fingerprint": item["fingerprint"],
|
|
554
|
+
"confirmation_digest": item["confirmation_digest"],
|
|
555
|
+
"signature": (
|
|
556
|
+
item["finding"].get("error_signature")
|
|
557
|
+
or item["finding"].get("signature")
|
|
558
|
+
),
|
|
559
|
+
"run_id": runtime.get("run_id"),
|
|
560
|
+
}
|
|
561
|
+
for item in credited_plans
|
|
562
|
+
],
|
|
563
|
+
"no_new_lesson_reason": no_new_lesson_reason,
|
|
564
|
+
"supersede": supersede_stale,
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
incidents: list[dict[str, Any]] = []
|
|
568
|
+
all_incident_ids: list[str] = []
|
|
569
|
+
existing_incident_ids = {
|
|
570
|
+
str(item.get("incident_id")) for item in ledger.list_incidents(ledger_path)
|
|
571
|
+
if item.get("incident_id")
|
|
572
|
+
} if include_incidents else set()
|
|
573
|
+
tool_feedback: list[dict[str, Any]] = []
|
|
574
|
+
for item in plans:
|
|
575
|
+
if include_incidents:
|
|
576
|
+
raw_incident = build_incident_payload(
|
|
577
|
+
item["finding"], item["pattern_id"], runtime, round_no, profile,
|
|
578
|
+
finding_fingerprint=item["fingerprint"],
|
|
579
|
+
)
|
|
580
|
+
incident_id = str(raw_incident["incident_id"])
|
|
581
|
+
all_incident_ids.append(incident_id)
|
|
582
|
+
if incident_id not in existing_incident_ids:
|
|
583
|
+
incidents.append(raw_incident)
|
|
584
|
+
if include_incidents and item in credited_plans and item["finding"].get("tools"):
|
|
585
|
+
tool_feedback.append({
|
|
586
|
+
"lifecycle_id": life, "round": round_no,
|
|
587
|
+
"category": classify_finding(item["finding"], profile),
|
|
588
|
+
"tools": item["finding"].get("tools"), "outcome": "hit",
|
|
589
|
+
"finding_fingerprint": item["fingerprint"],
|
|
590
|
+
"confirmation_digest": item["confirmation_digest"],
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
projection = _sanitize_projection({
|
|
594
|
+
"schema_version": 1,
|
|
595
|
+
"review": review,
|
|
596
|
+
"patterns": list(missing_patterns.values()),
|
|
597
|
+
"incidents": incidents,
|
|
598
|
+
"tool_feedback": tool_feedback,
|
|
599
|
+
})
|
|
600
|
+
_guard(projection, "自动知识 projection")
|
|
601
|
+
return projection, plans, all_incident_ids, str(state["state_hash"])
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def ensure_auto_review(
|
|
605
|
+
ledger_path: str | Path, runtime: Mapping[str, Any], round_result: Mapping[str, Any],
|
|
606
|
+
profile: Mapping[str, Any] | None = None, *, findings_snapshot: Any = None,
|
|
607
|
+
findings_snapshot_loaded: bool = False,
|
|
608
|
+
) -> dict[str, Any]:
|
|
609
|
+
"""Atomically create the current review and candidate Patterns."""
|
|
610
|
+
from core.ledger import lesson_ledger as ledger
|
|
611
|
+
snapshot = (
|
|
612
|
+
findings_snapshot
|
|
613
|
+
if findings_snapshot_loaded or findings_snapshot is not None
|
|
614
|
+
else _load_findings_snapshot(runtime)
|
|
615
|
+
)
|
|
616
|
+
projection, plans, _incident_ids, expected_hash = _build_projection(
|
|
617
|
+
ledger_path, runtime, round_result, profile, snapshot, include_incidents=False,
|
|
618
|
+
)
|
|
619
|
+
result = ledger.apply_auto_materialization(ledger_path, projection, expected_hash)
|
|
620
|
+
result["plans"] = [
|
|
621
|
+
{"finding_fingerprint": item["fingerprint"], "pattern_id": item["pattern_id"]}
|
|
622
|
+
for item in plans
|
|
623
|
+
]
|
|
624
|
+
return result
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
def materialize_confirmed_knowledge(
|
|
628
|
+
ledger_path: str | Path, runtime: Mapping[str, Any], round_result: Mapping[str, Any],
|
|
629
|
+
profile: Mapping[str, Any] | None = None, *, findings_snapshot: Any = None,
|
|
630
|
+
findings_snapshot_loaded: bool = False,
|
|
631
|
+
) -> dict[str, Any]:
|
|
632
|
+
"""Atomically materialize sanitized Patterns, review, Incidents and tool feedback."""
|
|
633
|
+
from core.ledger import lesson_ledger as ledger
|
|
634
|
+
snapshot = (
|
|
635
|
+
findings_snapshot
|
|
636
|
+
if findings_snapshot_loaded or findings_snapshot is not None
|
|
637
|
+
else _load_findings_snapshot(runtime)
|
|
638
|
+
)
|
|
639
|
+
projection, plans, incident_ids, expected_hash = _build_projection(
|
|
640
|
+
ledger_path, runtime, round_result, profile, snapshot, include_incidents=True,
|
|
641
|
+
)
|
|
642
|
+
result = ledger.apply_auto_materialization(ledger_path, projection, expected_hash)
|
|
643
|
+
already_present = len(incident_ids) - len(projection["incidents"])
|
|
644
|
+
result.update({
|
|
645
|
+
"patterns": len({item["pattern_id"] for item in plans}),
|
|
646
|
+
"incidents_reused": int(result.get("incidents_reused", 0)) + already_present,
|
|
647
|
+
"incident_ids": incident_ids,
|
|
648
|
+
"signature_keys": [f"sig-v1:{item['fingerprint']}" for item in plans],
|
|
649
|
+
"review_status": result.get("review_status") or result.get("status"),
|
|
650
|
+
})
|
|
651
|
+
return result
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
def _self_check() -> None:
|
|
655
|
+
finding = {"id": "x", "title": "SQL injection", "root_cause": "untrusted query input"}
|
|
656
|
+
assert classify_finding(finding) == "injection"
|
|
657
|
+
assert classify_finding({**finding, "category": "custom"}) == "custom"
|
|
658
|
+
assert _SOURCE_REF == "auto://confirmed-finding"
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
if __name__ == "__main__":
|
|
662
|
+
_self_check()
|