bugx-cli 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bugx_cli/__init__.py +6 -0
- bugx_cli/cli.py +1685 -0
- bugx_cli/commands/__init__.py +1 -0
- bugx_cli/commands/advisory.py +94 -0
- bugx_cli/commands/agent.py +4210 -0
- bugx_cli/commands/audit.py +632 -0
- bugx_cli/commands/autonomous.py +260 -0
- bugx_cli/commands/cloud.py +1371 -0
- bugx_cli/commands/daemon.py +50 -0
- bugx_cli/commands/doctor.py +1590 -0
- bugx_cli/commands/goal.py +107 -0
- bugx_cli/commands/interaction.py +248 -0
- bugx_cli/commands/knowledge.py +619 -0
- bugx_cli/commands/lifecycle.py +2763 -0
- bugx_cli/commands/patch.py +1014 -0
- bugx_cli/commands/plugin.py +2749 -0
- bugx_cli/commands/plugin_claude.py +1446 -0
- bugx_cli/commands/plugin_cline.py +269 -0
- bugx_cli/commands/plugin_codex.py +74 -0
- bugx_cli/commands/plugin_funide.py +729 -0
- bugx_cli/commands/plugin_qoder.py +216 -0
- bugx_cli/commands/plugin_zcode.py +710 -0
- bugx_cli/commands/project.py +670 -0
- bugx_cli/commands/report.py +256 -0
- bugx_cli/commands/skill.py +251 -0
- bugx_cli/commands/stats.py +133 -0
- bugx_cli/commands/system.py +2567 -0
- bugx_cli/common.py +906 -0
- bugx_cli/host_adapters.py +1892 -0
- bugx_cli/hosts/__init__.py +80 -0
- bugx_cli/hosts/base.py +99 -0
- bugx_cli/hosts/registry.py +573 -0
- bugx_cli/hosts/template_engine.py +188 -0
- bugx_cli/infra/__init__.py +209 -0
- bugx_cli/infra/ai_advisor.py +851 -0
- bugx_cli/infra/engine_installer.py +1945 -0
- bugx_cli/infra/host_sync.py +548 -0
- bugx_cli/infra/mcp_advisor.py +826 -0
- bugx_cli/infra/security.py +339 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/bugx-mcp-manifest.json +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/CATALOG.json +141 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/README.md +254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android-interaction.json +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/android.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/desktop-macos.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios-interaction.json +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/ios.json +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/adapters/memory-macos.json +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/__init__.py +146 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_artifacts.py +766 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_eval.py +1155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_execution.py +718 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_orchestrator.py +1351 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_targets.py +877 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/agent_workspace.py +770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/agent/feature_baseline.py +150 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/README.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/LICENSE.txt +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/UPSTREAM.md +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/axe-core/axe.min.js +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-1024.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-512.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar-tight.svg +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-avatar.svg +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-cn.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-en.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/bugx-hero-zh.svg +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/codex.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/dsh.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/project-layout.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/assets/zcode.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/README.md +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/manifest.json +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/10-schema-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/20-query-and-integrity.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/data-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/manifest.json +123 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/00-scope.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/10-process-model.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/20-package-integrity.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/30-ui-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/desktop-audit/stages/80-evidence-regression.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/memory-testing.md +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/manifest.json +155 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/android.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/ios.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/miniprogram.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/modules/webview.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/10-platform-inventory.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/20-masvs-static.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/30-component-exposure.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/40-device-behavior.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/mobile-audit/stages/80-evidence-regression.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/manifest.json +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/00-scope.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/10-static-white-box.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/20-memory-concurrency.md +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/30-behavior-black-box.md +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/native-audit/stages/80-evidence-regression.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/platform-testing.md +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/manifest.json +191 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/graphql.md +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/h5.md +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/multi-tenant.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/oauth.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/upload.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/modules/websocket.md +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/00-scope.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/10-discovery.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/20-auth-session.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/30-authz-business.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/40-input-output.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/50-state-async.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/60-file-ssrf-deser.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/70-config-dependency.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/audit_packs/web-audit/stages/80-evidence-regression.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/INTERFACE.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/README.md +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/__init__.py +109 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph.py +1096 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/attack_graph_store.py +1868 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/audit_campaign.py +1232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/behavior_graph.py +465 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/ghsa_advisories.py +174 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/models.py +93 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/mutator.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/patcher.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/scout.py +278 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/synthesizer.py +207 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/autonomous_cve/verifier.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx.md +1299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/bugx_paths.py +1881 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cli-help.txt +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/INTERFACE.md +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/__init__.py +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/auto_sync.py +398 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_client.py +1218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_onboard.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/cloud_schema.py +648 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/consent.py +81 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/device_identity.py +307 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/endpoint_router.py +415 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/flywheel_client.py +769 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/network_transport.py +296 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/onboard_wizard.py +493 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sensitive_filter.py +285 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_pull.py +695 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/cloud_sync/sync_push.py +723 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/AGENT_GUIDE.md +359 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/README.md +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-blackbox.md +541 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-opencode.md +469 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-quick.md +44 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-runtime-contract.md +353 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/bugx-worker.md +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/contracts/engine_gap_contracts.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/README.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/__init__.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_ai_review.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_backfill.py +54 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_bootstrap.py +713 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_business.py +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_cli.py +715 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_discovery.py +1429 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_evidence.py +1024 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_forensics.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_gate.py +277 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_intelligence.py +734 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_manifest.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_platform.py +77 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/coverage_validate.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/coverage/module_coverage.py +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/__init__.py +5 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/dev_harness/interaction_preset.py +408 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/engine-integrity.json +2797 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/README.md +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/__init__.py +82 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/concurrency_fuzzer.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/differential_oracle.py +1164 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/fuzz_input.py +1291 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/fuzzing/stateful_fuzzer.py +404 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/README.md +61 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/__init__.py +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/capacity_planner.py +124 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/dependency_lock.py +317 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/goal_governor.py +754 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/guide_budget.py +458 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/lockdown.sh +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/readonly_enforcer.py +154 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/runtime_tool_gate.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/secret_redactor.py +784 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/governance/token_budget.py +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/INTERFACE.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/__init__.py +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/base.py +111 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/claude.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/cline.py +298 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/codex.py +300 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/dsh.py +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/opencode.py +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/pi.py +94 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_acp/zcode.py +99 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/INTERFACE.md +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/__init__.py +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/adapters.py +412 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/autonomous_runner.py +1152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/cline.py +448 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/common.py +103 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/free_models.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_bootstrap.py +389 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_evaluators.py +761 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_probe.py +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_provider_arbitrator.py +831 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_registry.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/host_usage.py +127 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_process_tracker.py +509 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/mcp_registry_gate.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/pi.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/host_runtime/provider_facts.py +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/INTERFACE.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/README.md +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/__init__.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_base_usage.py +152 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_codex_usage.py +297 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_dsh_usage.py +184 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_mcp_toml.py +365 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/_zcode_usage.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/base.py +479 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/claude.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/cline.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/codex.py +1006 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/dsh.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/opencode.py +358 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/pi.py +308 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/hosts/zcode.py +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/i18n.py +252 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/README.md +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/__init__.py +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/build_info.py +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/client_metadata.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/json_utils.py +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/python_runtime.py +540 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/infra/safe_xml.py +221 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_bugx.py +118 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/INTERFACE.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/README.md +106 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/__init__.py +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/candidate_revalidation.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/common.py +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_confirm_phase.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/finding_settlement.py +1432 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_adjudication.py +666 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/findings_snapshot.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/judge_phase.py +848 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lesson_context.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/lifecycle_reporter.py +627 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/orchestrator_controls.py +686 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_commit.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_coverage_sync.py +598 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_dry_run.py +817 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_observability.py +367 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_phase.py +1223 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_receipt.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/post_round_lifecycle.py +786 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_phase.py +1029 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_recon_scout.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/pre_state_builder.py +1133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/report_sharing.py +414 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/round_orchestrator.py +1116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/session_runtime.py +1670 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_gates.py +1050 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_interaction.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/startup_version_gate.py +879 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_bridge.py +1253 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_coverage.py +423 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/supervisor_degraded.py +1211 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_barriers.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_orchestrator.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/launch_phases/worker_prior.py +749 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/INTERFACE.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/README.md +160 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/__init__.py +67 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/_facade.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/archive_ops.py +630 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/auto_materialization.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/bug-log.md +22 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/cli.py +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/export_ops.py +554 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_confirmation.py +1316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_io.py +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_lifecycle.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/finding_verification.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/incidents.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson-replay-cases.json +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_ledger.py +241 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/lesson_replay.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/life_ledger.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/mistake-book.md +130 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/patterns.py +684 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/receipt_contract.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/schema.py +1192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/sync_ops.py +940 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/tool_experience.py +683 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/ledger/verify_life.py +1597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/lesson-ledger.json +275 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/README.md +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/en-US.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/locales/zh-CN.json +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/INTERFACE.md +75 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/README.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/__init__.py +128 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/base.py +717 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/channel_lifecycle.py +751 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/graph_handlers.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/knowledge_handlers.py +536 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/mining_handlers.py +586 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/resource_prompt_table.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/retrieval_handlers.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/rpc_server.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/supervisor_handlers.py +1461 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/telemetry_handlers.py +227 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_handlers/tool_table.py +1030 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/README.md +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/__init__.py +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/common.py +363 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/environment.py +567 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/mcp_runtime_support/verifier.py +758 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/metadata.txt +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/README.md +157 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/__init__.py +242 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_plan.py +187 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/capability_planner.py +195 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_archetype.py +542 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/domain_router.py +269 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/dynamic_flow_analyzer.py +533 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/impact_pruner.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/intent_adjudicator.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/judge_pipeline.py +1246 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/logic_analysis.py +419 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/prompt_harness.py +1704 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/source_inspector.py +267 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/spec_harvester.py +449 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/target_sandbox_manager.py +573 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/test_capability_verifier.py +1364 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/tools-kb.md +38 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/planning/unit_kind.py +122 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/INTERFACE.md +83 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/README.md +51 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/SPEC.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/__init__.py +76 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/android_probe.py +552 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/base.py +147 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/codebase_memory_probe.py +647 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/desktop_probe.py +342 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/differential_probe.py +434 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/efficiency_probe.py +232 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ios_binary_probe.py +472 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/memory_probe.py +392 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/miniprogram_probe.py +385 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/mobile_probe.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/native_probe.py +302 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/openwiki_probe.py +263 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/pattern_probe.py +453 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/platform_probe.py +424 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/probe_registry.py +1770 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_fixture_corpus.py +340 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_probe.py +1510 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sast_rules.py +1481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/sca_scanner.py +779 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_accessibility.py +149 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_audit.py +513 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_contract.py +273 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_evidence.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_measurements.py +314 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_repair.py +250 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_review.py +133 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_storybook.py +107 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_tokens.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/ui_visual_diff.py +131 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/probes/web_probe.py +714 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/INTERFACE.md +62 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/__init__.py +201 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/arbitrator.py +316 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/constants.py +247 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/detector.py +399 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/extractors.py +836 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/fingerprint.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/storage.py +258 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/project_profiler/strategy.py +301 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/codex_dialog_dispatch.md +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_en.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/command_routing_zh.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/l0_router.md +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/anti_patterns.md +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/concurrency_rules.md +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/memory_leak_rules.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/rules/prompt_injection_defense.md +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_explore.md +31 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_gate.md +43 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_mutate.md +42 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/prompts/stages/stage_repair.md +85 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/README.md +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/__init__.py +169 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/fix_watchlist.py +391 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_dynamic.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_repair_loop.py +462 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/l7_selfcheck.py +862 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/minimize_repro.py +466 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/patch_synthesizer.py +617 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/regression_pack.py +379 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_fixer.py +910 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_loop.py +311 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_repair.py +348 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_rounds.py +212 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/rsi_scope.py +281 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/self_heal.py +604 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_generator.py +1108 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_quality_auditor.py +410 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/repair/test_strategy.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/INTERFACE.md +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/README.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/SPEC.md +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/__init__.py +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/attestation.py +228 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/authority.py +255 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/finding_report.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/formal_report_builder.py +924 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/html_renderers.py +696 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/models.py +759 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/pdf_exporter.py +231 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/projects_assets.py +730 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_client.py +743 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_data_builder.py +388 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/report_share.py +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/sast_bridge.py +116 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/server.py +832 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/visual_report_builder.py +796 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web-conformance.md +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/web_conformance.py +428 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/report_engine/workbench_assets.py +484 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/INTERFACE.md +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/README.md +161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/code_analyzer.py +1720 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/codebase_memory_bridge.py +337 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/context_assembler.py +240 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/corpus_fetch.py +369 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/graph_ego.py +597 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_auto.py +662 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sources.py +168 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/knowledge_sync.py +1003 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/memory_store.py +480 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/query_planner.py +1020 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/rrf_engine.py +137 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_extractor.py +1209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_normalizer.py +373 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/slice_spec.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/symbol_index.py +1151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/universal_code_matcher.py +622 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_bridge.py +476 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/retrieval/xerj_supervisor.py +362 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/README.md +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/PROVENANCE.json +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/crypto.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/network.yaml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/resilience.yaml +47 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/ios/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/LICENSE +173 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/PROVENANCE.json +270 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-asymmetric-key-pair-used-for-multiple-purposes.yml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-backup-manifest.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-event-bound.yml +49 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-invalidated-enrollment.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-no-confirmation-required.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-biometric-validity-duration.yml +24 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-algorithms.yaml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-broken-encryption-modes.yaml +13 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-content-provider-exported.yml +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-custom-deeplink-scheme.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-dangerous-app-permissions.yaml +65 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-apis.yml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-data-unencrypted-shared-storage-no-user-interaction-manifest.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debuggable-flag.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-autoverify-missing.yml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-deeplink-unvalidated-parameter.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-device-passcode-present.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-fileprovider-broad-scope.yml +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-crypto-keys-usage.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-hardcoded-security-provider.yaml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-internal-communication.yml +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-implicit-intent-leaking-extras.yml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-input-field-usage.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-key-generation-with-insufficient-key-length.yml +21 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-keyboard-cache-input-types.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-local-storage-input-validation.yml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-native-debugger-checks.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-checkservertrusted.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-hostname-verification.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-insecure-trust-anchors.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-network-onreceivedsslerror.yml +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-non-random-use.yml +16 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-object-deserialization.yml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-overlay-protection.yml +68 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-pendingintent-mutable.yml +39 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-random-apis-insufficient-entropy.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-root-detection.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sdk-version.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications-manifest.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-notifications.yml +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sensitive-data-in-screenshot.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-sql-injection-contentprovider.yml +17 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-ssl-socket-hostnameverifier.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-strictmode.yml +10 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-system-alert-window.yml +9 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-allow-local-access.yml +15 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-bridges.yml +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-safebrowsing.yml +20 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mastg/mastg-android-webview-url-handlers.yml +41 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/PROVENANCE.json +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/network.yaml +37 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/platform.yaml +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/miniprogram/storage.yaml +48 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/LICENSE +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/PROVENANCE.json +58 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/auth.yaml +59 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/crypto.yaml +66 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/jailbreak.yaml +14 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/keyboard.yaml +34 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/logging.yaml +23 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/network.yaml +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/resilience.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/secrets.yaml +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/storage.yaml +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/rules/mobsfscan-swift/webview.yaml +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/README.md +198 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/__init__.py +3 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/bugx_logging.py +1464 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/daemon_runner.py +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/fixture_solidify.py +444 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/global_telemetry.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/incident_eval.py +148 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interaction_store.py +435 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/interactive_menu.py +95 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/log_analytics.py +922 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/mining_quality_framework.py +1387 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/model_runner.py +732 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/platform_adapter.py +579 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/prep_validate.py +478 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_graph.py +827 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_init.py +481 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_profile.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/project_settings.py +964 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/provider_window.py +97 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/resume_ticket.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/scenario_eval.py +856 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/seed_drill.py +549 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/self_audit.py +550 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/session_profile.py +205 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/setup_ui_env.py +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/startup_environment.py +859 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/sync_store.py +1421 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/runtime/tool_install_targets.py +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/README.md +35 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/agent-graph.schema.json +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/attack-graph.schema.json +88 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/evidence-bundle.schema.json +33 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/skill-pack.schema.json +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/schemas/worker-checkpoint.schema.json +119 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/secure_atomic.py +289 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/README.md +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/c.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/cpp.txt +32 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/css.txt +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/go.txt +46 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/java.txt +30 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/javascript.txt +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/kotlin.txt +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/python.txt +71 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/rust.txt +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/swift.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/seed_corpus/typescript.txt +29 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/README.md +53 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/__init__.py +189 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_docs_mcp_server.py +418 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/bugx_mcp_server.py +1161 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_runtime.py +968 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mcp_session_proof.py +605 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/mobile_ui_inspector.py +405 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_pack.py +1214 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/skill_synthesizer.py +1153 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/skills/tools_kb.py +313 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/INTERFACE.md +121 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/README.md +209 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/SPEC.md +25 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/__init__.py +175 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/audit_supervisor.py +1015 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/budget_governor.py +1254 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_handler.py +368 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_pipeline.py +1564 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/checkpoint_sync.py +653 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_events.py +74 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/claim_sync.py +590 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/cli.py +812 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/context_sync.py +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/coverage_sync.py +115 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_commit.py +470 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_sync.py +688 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finding_workflow.py +676 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_policy.py +224 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/finish_sync.py +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/graph_sync.py +669 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lease_manager.py +788 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/lifecycle_blocks.py +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/next_round_sync.py +126 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/observability.py +140 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/recovery_sync.py +165 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/rejection_remedies.py +355 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/round_governor.py +306 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/serial_authorization.py +544 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/start_sync.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/state_store.py +249 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_host.py +511 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/supervisor_models.py +1143 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/systemic_failure.py +104 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/task_scheduler.py +1640 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_checkpoint.py +230 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_execution.py +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_handoff.py +192 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_lifecycle.py +396 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_runtime.py +1005 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor/worker_sync.py +89 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/README.md +36 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/__init__.py +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/exceptions.py +52 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/graph_models.py +357 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/path_containment.py +151 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/target_fingerprint.py +310 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/supervisor_types/worker_claim.py +411 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/INTERFACE.md +50 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/README.md +57 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/SPEC.md +26 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/__init__.py +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/__init__.py +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/base.py +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/bugx.py +102 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/claude.py +222 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/cline.py +407 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/codex.py +260 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/dsh.py +177 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/opencode.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/pi.py +272 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/registry.py +100 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/adapters/zcode.py +312 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/api_routes_post.py +668 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/dispatcher.py +1376 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/docs_session_service.py +473 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/handler.py +674 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/ide_cloud_service.py +526 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/mcp_inspector.py +1747 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/00-base.css +1060 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/01-monitoring.css +802 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/02-header-actions.css +321 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/03-trigger-popover.css +697 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/04-composer.css +628 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/05-skills-center.css +878 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/06-mcp-center.css +623 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/07-skill-detail.css +265 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/08-files-management.css +167 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/09-files-center.css +386 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/10-icons.css +105 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/11-project-options.css +185 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/12-profile-tab.css +383 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-CXAsl8mr.js +333 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/index-DHQUtWtx.css +1 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-B8Z6Jvzv.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-400-normal-C44pakCn.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-Bb4u56_6.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-500-normal-BdVUvljg.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-CWV284fw.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-400-normal-DLkyKLvH.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-8-8HP2PF.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-cyrillic-ext-500-normal-DaDZE_Na.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-BccYJ-vZ.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-400-normal-Cw5-AHNN.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-By8GFJzz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-greek-500-normal-z-Q6FFuG.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-DJ5YJwmz.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-400-normal-Dn3IlU-Z.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-CUHe9xxf.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-500-normal-DVVamBqs.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-CEpydyUl.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-400-normal-Cp7z-ARB.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-BYjRCDVy.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-latin-ext-500-normal-D-qasQTj.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-BbG3LG1A.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-400-normal-DR1UuFon.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-8N8MYVKB.woff +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/assets/source-serif-4-vietnamese-500-normal-Bi3OSTTW.woff2 +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/design-tokens.css +113 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/favicon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/icon-192.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/index.html +55 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/manifest.webmanifest +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/project-settings.js +9602 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/static/sw.js +8 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/core/webui/workspace_service.py +218 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/agents/bugx.md +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/dsh-patch.yml +18 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/index.js +219 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/mcp/package.json +28 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/skills/bugx-dsh/SKILL.md +229 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/client.js +87 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/cordis.patch.yml +4 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/index.js +7 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/dsh/ui/package.json +27 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/mcp-lock.json +3075 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/opencode.json +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/README.md +12 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/index.ts +299 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/extensions/bugx/manifest.json +11 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/pi/skills/bugx/SKILL.md +69 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-claude/SKILL.md +326 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-opencode/SKILL.md +129 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/plugins/bugx/skills/bugx-zcode/SKILL.md +459 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/connector-meta.json +19 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/icon.png +0 -0
- bugx_cli-0.1.1.data/data/share/bugx-agent/workbuddy/skills/bugx/SKILL.md +70 -0
- bugx_cli-0.1.1.dist-info/METADATA +335 -0
- bugx_cli-0.1.1.dist-info/RECORD +762 -0
- bugx_cli-0.1.1.dist-info/WHEEL +5 -0
- bugx_cli-0.1.1.dist-info/entry_points.txt +2 -0
- bugx_cli-0.1.1.dist-info/licenses/LICENSE +55 -0
- bugx_cli-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1214 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""core/skill_pack.py - BugX 审计技能包(Skill Pack)加载、校验与流水线编译 (DOC-125)。
|
|
3
|
+
|
|
4
|
+
负责:
|
|
5
|
+
- 技能包 Manifest 契约加载与 JSON Schema 校验
|
|
6
|
+
- L1 行动清单 (≤300T) 与 L2 攻防手册物理隔离解析
|
|
7
|
+
- 流式 DAG 阶段流水线 (Stage Pipeline) 装配
|
|
8
|
+
- 动态可选模块 (Modules) 激活与裁剪
|
|
9
|
+
- 确定性 plan_hash 生成与工程级版本追踪
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import hashlib
|
|
15
|
+
import base64
|
|
16
|
+
import datetime as dt
|
|
17
|
+
import json
|
|
18
|
+
from functools import lru_cache
|
|
19
|
+
import os
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
import re
|
|
22
|
+
import shutil
|
|
23
|
+
import platform
|
|
24
|
+
import sys
|
|
25
|
+
import tarfile
|
|
26
|
+
import tempfile
|
|
27
|
+
from typing import Any, Iterable, Mapping
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
import jsonschema
|
|
31
|
+
except ImportError:
|
|
32
|
+
jsonschema = None # type: ignore[assignment]
|
|
33
|
+
|
|
34
|
+
try: # Ed25519 is optional for the immutable builtin layer only.
|
|
35
|
+
from cryptography.exceptions import InvalidSignature
|
|
36
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
|
|
37
|
+
except ImportError: # pragma: no cover - exercised on minimal installations.
|
|
38
|
+
InvalidSignature = Exception # type: ignore[assignment,misc]
|
|
39
|
+
Ed25519PublicKey = None # type: ignore[assignment,misc]
|
|
40
|
+
|
|
41
|
+
_CORE_DIR = Path(__file__).resolve().parent.parent if Path(__file__).resolve().parent.name == "skills" else Path(__file__).resolve().parent
|
|
42
|
+
if str(_CORE_DIR) not in sys.path: # 幂等:重复执行模块不得堆叠 sys.path
|
|
43
|
+
sys.path.insert(0, str(_CORE_DIR))
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
from core.infra.client_metadata import client_headers, tls_context
|
|
47
|
+
except ImportError:
|
|
48
|
+
try:
|
|
49
|
+
from core.infra.client_metadata import client_headers, tls_context
|
|
50
|
+
except ImportError:
|
|
51
|
+
client_headers, tls_context = None, None # type: ignore[assignment]
|
|
52
|
+
|
|
53
|
+
SKILLS_DIR_NAME = "skills"
|
|
54
|
+
AUDIT_PACKS_DIR_NAME = "audit_packs"
|
|
55
|
+
_AUDIT_PACKS_DIR = _CORE_DIR / AUDIT_PACKS_DIR_NAME
|
|
56
|
+
_LEGACY_SKILLS_DIR = _CORE_DIR / "prompts" / "skills"
|
|
57
|
+
DEFAULT_SKILLS_DIR = _AUDIT_PACKS_DIR if _AUDIT_PACKS_DIR.is_dir() else _LEGACY_SKILLS_DIR
|
|
58
|
+
DEFAULT_AUDIT_PACKS_DIR = DEFAULT_SKILLS_DIR
|
|
59
|
+
SCHEMA_PATH = _CORE_DIR / "schemas" / "skill-pack.schema.json"
|
|
60
|
+
|
|
61
|
+
_L1_START_TAG = "<!-- L1:START -->"
|
|
62
|
+
_L1_END_TAG = "<!-- L1:END -->"
|
|
63
|
+
_L2_START_TAG = "<!-- L2:START -->"
|
|
64
|
+
_L2_END_TAG = "<!-- L2:END -->"
|
|
65
|
+
|
|
66
|
+
# 简易 Token 估算:按 4 字符 ≈ 1 Token 预估,中英混合按字符/空格加权
|
|
67
|
+
MAX_L1_TOKEN_DEFAULT = 300
|
|
68
|
+
|
|
69
|
+
# Fixed distribution trust root. The corresponding private key is not stored
|
|
70
|
+
# in this repository; tests inject their own key through ``public_key``.
|
|
71
|
+
OFFICIAL_SKILL_PUBKEY = (
|
|
72
|
+
"c13a88e62636d9d382c3687e50931efd32ab6bdcee84e9ea2214b3a484c978ad"
|
|
73
|
+
)
|
|
74
|
+
_SKILL_ID_RE = re.compile(r"^[a-z0-9-]+$")
|
|
75
|
+
_SEMVER_RE = re.compile(r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$")
|
|
76
|
+
_OVERLAY_LAYERS = frozenset({"project", "global"})
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class SkillPackError(ValueError):
|
|
80
|
+
"""Base error for an invalid or unavailable skill pack."""
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class SkillSignatureError(SkillPackError):
|
|
84
|
+
"""The detached official Ed25519 signature is missing or invalid."""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class SkillCapabilityError(SkillPackError):
|
|
88
|
+
"""The local runtime cannot safely execute the requested skill profile."""
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class SkillDowngradeError(SkillPackError):
|
|
92
|
+
"""The candidate is older than the locally accepted stable version."""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def estimate_tokens(text: str) -> int:
|
|
96
|
+
"""保守估算文本的 Token 消耗量。"""
|
|
97
|
+
if not text:
|
|
98
|
+
return 0
|
|
99
|
+
# 粗略模型:英文单词 + 中文字符
|
|
100
|
+
words = len(re.findall(r"\b\w+\b", text))
|
|
101
|
+
cjk = len(re.findall(r"[\u4e00-\u9fff]", text))
|
|
102
|
+
other = len(text) // 4
|
|
103
|
+
return max(words + cjk, other, 1)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _canonical_json_bytes(obj: Any) -> bytes:
|
|
107
|
+
"""输出确定性排序紧凑 JSON 字节序列。"""
|
|
108
|
+
return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def compute_plan_hash(manifest: Mapping[str, Any]) -> str:
|
|
112
|
+
"""计算技能包 Manifest 的确定性 SHA-256 哈希 (plan_hash)。"""
|
|
113
|
+
digest = hashlib.sha256(_canonical_json_bytes(manifest)).hexdigest()
|
|
114
|
+
return f"sha256:{digest}"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def validate_manifest(manifest: Mapping[str, Any]) -> None:
|
|
118
|
+
"""使用 skill-pack.schema.json 严格校验 Manifest 格式。"""
|
|
119
|
+
if not isinstance(manifest, Mapping):
|
|
120
|
+
raise SkillPackError("Skill pack manifest 必须是 JSON 对象")
|
|
121
|
+
# DOC-126 names the field skill_version while DOC-125 used version. Keep
|
|
122
|
+
# both spellings readable, but normalize only for schema validation so the
|
|
123
|
+
# signed bytes and plan hash remain exactly the publisher's bytes.
|
|
124
|
+
candidate = dict(manifest)
|
|
125
|
+
if "version" not in candidate and "skill_version" in candidate:
|
|
126
|
+
candidate["version"] = candidate["skill_version"]
|
|
127
|
+
if jsonschema is None:
|
|
128
|
+
# Fallback 关键字段软校验
|
|
129
|
+
required = ["schema_version", "skill_id", "version", "scope", "applies_if", "stage_pipeline", "budgets"]
|
|
130
|
+
missing = [f for f in required if f not in candidate]
|
|
131
|
+
if missing:
|
|
132
|
+
raise ValueError(f"Skill pack manifest missing required fields: {missing}")
|
|
133
|
+
elif SCHEMA_PATH.is_file():
|
|
134
|
+
validator = _skill_pack_validator()
|
|
135
|
+
if validator is not None:
|
|
136
|
+
validator.validate(candidate)
|
|
137
|
+
|
|
138
|
+
_validate_runtime_tool_ids(candidate)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@lru_cache(maxsize=1)
|
|
142
|
+
def _skill_pack_validator():
|
|
143
|
+
"""编译一次 Skill pack schema 并复用。
|
|
144
|
+
|
|
145
|
+
此前每次校验都 ``json.load`` 整个 schema 文件再走 ``jsonschema.validate``,
|
|
146
|
+
后者会**重新编译** schema —— cProfile 实测 ``jsonschema`` 校验占
|
|
147
|
+
``test_cli_hosts`` 4 个 case 的 0.549s(9478 次 validator 调用),
|
|
148
|
+
折算 0.137s/case × 105 case ≈ 14.4s。schema 是仓库内静态资产(随 skill pack
|
|
149
|
+
版本发布),进程内缓存安全;文件缺失或 jsonschema 不可用时返回 None,
|
|
150
|
+
调用方保持"无 schema 即跳过"的既有语义。
|
|
151
|
+
"""
|
|
152
|
+
try:
|
|
153
|
+
import jsonschema
|
|
154
|
+
except ImportError: # pragma: no cover - jsonschema 是运行期可选依赖
|
|
155
|
+
return None
|
|
156
|
+
try:
|
|
157
|
+
with open(SCHEMA_PATH, "r", encoding="utf-8") as sf:
|
|
158
|
+
schema = json.load(sf)
|
|
159
|
+
return jsonschema.Draft202012Validator(schema)
|
|
160
|
+
except (OSError, ValueError, jsonschema.exceptions.SchemaError):
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def split_stage_content(markdown_text: str, max_l1_tokens: int = MAX_L1_TOKEN_DEFAULT) -> tuple[str, str]:
|
|
165
|
+
"""物理隔离提取 L1 行动清单 与 L2 攻防手册。
|
|
166
|
+
|
|
167
|
+
返回: (l1_checklist, l2_playbook)
|
|
168
|
+
"""
|
|
169
|
+
l1_text = ""
|
|
170
|
+
l2_text = ""
|
|
171
|
+
|
|
172
|
+
l1_match = re.search(
|
|
173
|
+
rf"{re.escape(_L1_START_TAG)}(.*?){re.escape(_L1_END_TAG)}",
|
|
174
|
+
markdown_text,
|
|
175
|
+
re.DOTALL,
|
|
176
|
+
)
|
|
177
|
+
if l1_match:
|
|
178
|
+
l1_text = l1_match.group(1).strip()
|
|
179
|
+
else:
|
|
180
|
+
# 未显式标记则取前 300 字符作为 L1
|
|
181
|
+
l1_text = markdown_text.strip()[:600]
|
|
182
|
+
|
|
183
|
+
l2_match = re.search(
|
|
184
|
+
rf"{re.escape(_L2_START_TAG)}(.*?){re.escape(_L2_END_TAG)}",
|
|
185
|
+
markdown_text,
|
|
186
|
+
re.DOTALL,
|
|
187
|
+
)
|
|
188
|
+
if l2_match:
|
|
189
|
+
l2_text = l2_match.group(1).strip()
|
|
190
|
+
else:
|
|
191
|
+
# 去掉 L1 后的剩余部分作为 L2
|
|
192
|
+
remainder = re.sub(
|
|
193
|
+
rf"{re.escape(_L1_START_TAG)}.*?{re.escape(_L1_END_TAG)}",
|
|
194
|
+
"",
|
|
195
|
+
markdown_text,
|
|
196
|
+
flags=re.DOTALL,
|
|
197
|
+
).strip()
|
|
198
|
+
l2_text = remainder
|
|
199
|
+
|
|
200
|
+
# 实施 L1 Token 预算硬隔离 (Hard Cap)
|
|
201
|
+
estimated_l1_tokens = estimate_tokens(l1_text)
|
|
202
|
+
if estimated_l1_tokens > max_l1_tokens:
|
|
203
|
+
# 截断并附上超预算警告
|
|
204
|
+
ratio = max_l1_tokens / float(estimated_l1_tokens)
|
|
205
|
+
char_cutoff = int(len(l1_text) * ratio)
|
|
206
|
+
l1_text = l1_text[:char_cutoff].rstrip() + f"\n... [L1 checklist budget exceeded ({max_l1_tokens}T), truncated]"
|
|
207
|
+
|
|
208
|
+
return l1_text, l2_text
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _version_tuple(value: object) -> tuple[int, int, int]:
|
|
212
|
+
text = str(value or "")
|
|
213
|
+
match = _SEMVER_RE.fullmatch(text)
|
|
214
|
+
if not match:
|
|
215
|
+
raise SkillPackError(f"技能包版本不是 SemVer: {value!r}")
|
|
216
|
+
return tuple(int(part) for part in match.groups()) # type: ignore[return-value]
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _decode_signature(value: bytes) -> bytes:
|
|
220
|
+
"""Decode raw, hex, or base64 detached signatures."""
|
|
221
|
+
# Do not strip raw binary signatures: a valid Ed25519 signature may end in
|
|
222
|
+
# a byte that happens to be ASCII whitespace.
|
|
223
|
+
if len(value) == 64:
|
|
224
|
+
return value
|
|
225
|
+
raw = value.strip()
|
|
226
|
+
try:
|
|
227
|
+
decoded = bytes.fromhex(raw.decode("ascii"))
|
|
228
|
+
if len(decoded) == 64:
|
|
229
|
+
return decoded
|
|
230
|
+
except (UnicodeDecodeError, ValueError):
|
|
231
|
+
pass
|
|
232
|
+
try:
|
|
233
|
+
decoded = base64.b64decode(raw, validate=True)
|
|
234
|
+
except (ValueError, base64.binascii.Error) as exc:
|
|
235
|
+
raise SkillSignatureError("manifest.sig 不是有效的 Ed25519 签名") from exc
|
|
236
|
+
if len(decoded) != 64:
|
|
237
|
+
raise SkillSignatureError("manifest.sig 长度无效")
|
|
238
|
+
return decoded
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _decode_public_key(value: str | bytes | None) -> bytes:
|
|
242
|
+
if value is None:
|
|
243
|
+
# The distribution key is a trust root. Environment overrides would
|
|
244
|
+
# let an untrusted process replace the key used for official packs.
|
|
245
|
+
value = OFFICIAL_SKILL_PUBKEY
|
|
246
|
+
raw = value if isinstance(value, bytes) else str(value).strip().encode("ascii")
|
|
247
|
+
if len(raw) == 32:
|
|
248
|
+
return raw
|
|
249
|
+
try:
|
|
250
|
+
decoded = bytes.fromhex(raw.decode("ascii"))
|
|
251
|
+
except (UnicodeDecodeError, ValueError):
|
|
252
|
+
try:
|
|
253
|
+
decoded = base64.b64decode(raw, validate=True)
|
|
254
|
+
except (ValueError, base64.binascii.Error) as b64_exc:
|
|
255
|
+
raise SkillSignatureError("官方技能公钥格式无效") from b64_exc
|
|
256
|
+
if len(decoded) != 32:
|
|
257
|
+
raise SkillSignatureError("官方技能公钥长度无效")
|
|
258
|
+
return decoded
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def verify_manifest_signature(manifest: Mapping[str, Any], signature_path: Path,
|
|
262
|
+
public_key: str | bytes | None = None) -> None:
|
|
263
|
+
"""Verify canonical manifest bytes with the embedded official Ed25519 key."""
|
|
264
|
+
if not signature_path.is_file() or signature_path.is_symlink():
|
|
265
|
+
raise SkillSignatureError(f"缺少 manifest.sig: {signature_path}")
|
|
266
|
+
signature = _decode_signature(signature_path.read_bytes())
|
|
267
|
+
payload = _canonical_json_bytes(manifest)
|
|
268
|
+
key = _decode_public_key(public_key)
|
|
269
|
+
if Ed25519PublicKey is not None:
|
|
270
|
+
try:
|
|
271
|
+
Ed25519PublicKey.from_public_bytes(key).verify(signature, payload)
|
|
272
|
+
return
|
|
273
|
+
except (InvalidSignature, ValueError) as exc:
|
|
274
|
+
raise SkillSignatureError("技能包 manifest Ed25519 验签失败") from exc
|
|
275
|
+
try: # pragma: no cover - fallback for environments without cryptography.
|
|
276
|
+
from nacl.signing import VerifyKey
|
|
277
|
+
VerifyKey(key).verify(payload, signature)
|
|
278
|
+
except Exception as exc: # noqa: BLE001
|
|
279
|
+
raise SkillSignatureError("技能包验签不可用或验签失败") from exc
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _validate_issued_at(value: object, *, now: dt.datetime | None = None) -> str:
|
|
283
|
+
if not isinstance(value, str) or not value.strip():
|
|
284
|
+
raise SkillPackError("Overlay manifest 缺少 issued_at")
|
|
285
|
+
text = value.strip()
|
|
286
|
+
try:
|
|
287
|
+
parsed = dt.datetime.fromisoformat(text.replace("Z", "+00:00"))
|
|
288
|
+
except ValueError as exc:
|
|
289
|
+
raise SkillPackError("issued_at 必须是 ISO-8601 UTC 时间戳") from exc
|
|
290
|
+
if parsed.tzinfo is None or parsed.utcoffset() != dt.timedelta(0):
|
|
291
|
+
raise SkillPackError("issued_at 必须明确标记 UTC(Z 或 +00:00)")
|
|
292
|
+
current = now or dt.datetime.now(dt.timezone.utc)
|
|
293
|
+
if parsed > current + dt.timedelta(minutes=5):
|
|
294
|
+
raise SkillPackError("issued_at 不能晚于当前 UTC 时间")
|
|
295
|
+
return parsed.astimezone(dt.timezone.utc).isoformat().replace("+00:00", "Z")
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def _atomic_json_write(path: Path, payload: Mapping[str, Any]) -> None:
|
|
299
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
300
|
+
fd, name = tempfile.mkstemp(prefix=f".{path.name}.", dir=str(path.parent))
|
|
301
|
+
try:
|
|
302
|
+
with os.fdopen(fd, "w", encoding="utf-8") as handle:
|
|
303
|
+
json.dump(dict(payload), handle, ensure_ascii=False, indent=2)
|
|
304
|
+
handle.write("\n")
|
|
305
|
+
handle.flush()
|
|
306
|
+
os.fsync(handle.fileno())
|
|
307
|
+
os.replace(name, path)
|
|
308
|
+
finally:
|
|
309
|
+
try:
|
|
310
|
+
os.unlink(name)
|
|
311
|
+
except FileNotFoundError:
|
|
312
|
+
pass
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
class SkillPackLoader:
|
|
316
|
+
"""Load Project Overlay > Global Overlay > immutable Core Builtin packs."""
|
|
317
|
+
|
|
318
|
+
def __init__(self, project_root: Path | str | None = None, *,
|
|
319
|
+
home: Path | str | None = None,
|
|
320
|
+
project_overlay: Path | str | None = None,
|
|
321
|
+
global_overlay: Path | str | None = None,
|
|
322
|
+
builtin_root: Path | str | None = None,
|
|
323
|
+
health_path: Path | str | None = None,
|
|
324
|
+
versions_path: Path | str | None = None,
|
|
325
|
+
public_key: str | bytes | None = None,
|
|
326
|
+
now: dt.datetime | None = None) -> None:
|
|
327
|
+
self.project_root = Path(project_root).expanduser().resolve() if project_root else None
|
|
328
|
+
self.home = Path(home).expanduser().resolve() if home else Path.home().resolve()
|
|
329
|
+
self.project_overlay = Path(project_overlay).expanduser().resolve() if project_overlay else (
|
|
330
|
+
self.project_root / ".bugx" / SKILLS_DIR_NAME if self.project_root else None
|
|
331
|
+
)
|
|
332
|
+
self.global_overlay = Path(global_overlay).expanduser().resolve() if global_overlay else (
|
|
333
|
+
self.home / ".bugx" / SKILLS_DIR_NAME / "official"
|
|
334
|
+
)
|
|
335
|
+
self.builtin_root = Path(builtin_root).expanduser().resolve() if builtin_root else DEFAULT_SKILLS_DIR
|
|
336
|
+
self.health_path = Path(health_path).expanduser().resolve() if health_path else self.home / ".bugx" / SKILLS_DIR_NAME / ".health.json"
|
|
337
|
+
self.versions_path = Path(versions_path).expanduser().resolve() if versions_path else self.home / ".bugx" / SKILLS_DIR_NAME / ".versions.json"
|
|
338
|
+
self.quarantine_root = self.home / ".bugx" / SKILLS_DIR_NAME / "quarantine"
|
|
339
|
+
self.public_key = public_key
|
|
340
|
+
self.now = now
|
|
341
|
+
|
|
342
|
+
@staticmethod
|
|
343
|
+
def capability_vector() -> dict[str, Any]:
|
|
344
|
+
"""Collect the bounded, non-secret capability vector sent to cloud."""
|
|
345
|
+
memory_mb = 0
|
|
346
|
+
try:
|
|
347
|
+
pages = int(os.sysconf("SC_PHYS_PAGES"))
|
|
348
|
+
page_size = int(os.sysconf("SC_PAGE_SIZE"))
|
|
349
|
+
memory_mb = max(0, (pages * page_size) // (1024 * 1024))
|
|
350
|
+
except (AttributeError, OSError, ValueError):
|
|
351
|
+
pass
|
|
352
|
+
return {
|
|
353
|
+
"os": platform.system().lower(),
|
|
354
|
+
"arch": platform.machine().lower(),
|
|
355
|
+
"python": f"{sys.version_info.major}.{sys.version_info.minor}",
|
|
356
|
+
"memory_mb": memory_mb,
|
|
357
|
+
"has_docker": shutil.which("docker") is not None,
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
def request_context(self, entitlements: Iterable[str] | str | None = None,
|
|
361
|
+
profile: str | None = None) -> dict[str, Any]:
|
|
362
|
+
if isinstance(entitlements, str):
|
|
363
|
+
values = [x.strip() for x in entitlements.split(",") if x.strip()]
|
|
364
|
+
else:
|
|
365
|
+
values = sorted({str(x).strip() for x in (entitlements or ()) if str(x).strip()})
|
|
366
|
+
headers = client_headers()
|
|
367
|
+
headers["X-BugX-Entitlements"] = ",".join(values)
|
|
368
|
+
return {
|
|
369
|
+
"headers": headers,
|
|
370
|
+
"capabilities": self.capability_vector(),
|
|
371
|
+
"profile": profile or "auto",
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
def request_headers(self, entitlements: Iterable[str] | str | None = None) -> dict[str, str]:
|
|
375
|
+
return dict(self.request_context(entitlements)["headers"])
|
|
376
|
+
|
|
377
|
+
build_request_headers = request_headers
|
|
378
|
+
|
|
379
|
+
def _layer_roots(self) -> list[tuple[str, Path]]:
|
|
380
|
+
roots: list[tuple[str, Path]] = []
|
|
381
|
+
if self.project_overlay is not None:
|
|
382
|
+
roots.append(("project", self.project_overlay))
|
|
383
|
+
roots.extend((("global", self.global_overlay), ("builtin", self.builtin_root)))
|
|
384
|
+
return roots
|
|
385
|
+
|
|
386
|
+
def _candidate_dirs(self, skill_id: str) -> list[tuple[str, Path]]:
|
|
387
|
+
candidates: list[tuple[str, Path]] = []
|
|
388
|
+
for layer, root in self._layer_roots():
|
|
389
|
+
base = root / skill_id
|
|
390
|
+
if layer in _OVERLAY_LAYERS and (self.quarantine_root / skill_id).is_dir():
|
|
391
|
+
continue
|
|
392
|
+
if (base / "manifest.json").is_file():
|
|
393
|
+
candidates.append((layer, base))
|
|
394
|
+
# A pack may carry separate full/lite manifests under one skill id.
|
|
395
|
+
if base.is_dir() and not base.is_symlink():
|
|
396
|
+
for profile_dir in sorted(base.iterdir()):
|
|
397
|
+
if profile_dir.is_dir() and not profile_dir.is_symlink() \
|
|
398
|
+
and (profile_dir / "manifest.json").is_file():
|
|
399
|
+
candidates.append((layer, profile_dir))
|
|
400
|
+
return candidates
|
|
401
|
+
|
|
402
|
+
@staticmethod
|
|
403
|
+
def _read_manifest(pack_dir: Path) -> dict[str, Any]:
|
|
404
|
+
manifest_path = pack_dir / "manifest.json"
|
|
405
|
+
if not manifest_path.is_file() or manifest_path.is_symlink():
|
|
406
|
+
raise FileNotFoundError(f"Skill pack manifest not found at {manifest_path}")
|
|
407
|
+
try:
|
|
408
|
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
409
|
+
except (OSError, UnicodeError, json.JSONDecodeError) as exc:
|
|
410
|
+
raise SkillPackError(f"无法读取技能包 manifest: {manifest_path}") from exc
|
|
411
|
+
validate_manifest(manifest)
|
|
412
|
+
return manifest
|
|
413
|
+
|
|
414
|
+
def _read_state(self, path: Path) -> dict[str, Any]:
|
|
415
|
+
if not path.is_file() or path.is_symlink():
|
|
416
|
+
return {}
|
|
417
|
+
try:
|
|
418
|
+
value = json.loads(path.read_text(encoding="utf-8"))
|
|
419
|
+
return value if isinstance(value, dict) else {}
|
|
420
|
+
except (OSError, UnicodeError, json.JSONDecodeError):
|
|
421
|
+
return {}
|
|
422
|
+
|
|
423
|
+
def _write_version(self, manifest: Mapping[str, Any]) -> None:
|
|
424
|
+
state = self._read_state(self.versions_path)
|
|
425
|
+
versions = state.setdefault("skills", {})
|
|
426
|
+
versions[str(manifest["skill_id"])] = {
|
|
427
|
+
"version": str(manifest["version"]),
|
|
428
|
+
"issued_at": manifest.get("issued_at"),
|
|
429
|
+
"plan_hash": compute_plan_hash(manifest),
|
|
430
|
+
}
|
|
431
|
+
_atomic_json_write(self.versions_path, state)
|
|
432
|
+
|
|
433
|
+
def _check_version(self, manifest: Mapping[str, Any], layer: str) -> str | None:
|
|
434
|
+
version = _version_tuple(manifest.get("version"))
|
|
435
|
+
issued = _validate_issued_at(manifest.get("issued_at"), now=self.now) if layer in _OVERLAY_LAYERS else None
|
|
436
|
+
if layer not in _OVERLAY_LAYERS:
|
|
437
|
+
return issued
|
|
438
|
+
previous = self._read_state(self.versions_path).get("skills", {}).get(str(manifest["skill_id"]), {})
|
|
439
|
+
if isinstance(previous, Mapping) and previous.get("version"):
|
|
440
|
+
old_version = _version_tuple(previous["version"])
|
|
441
|
+
if version < old_version:
|
|
442
|
+
raise SkillDowngradeError(
|
|
443
|
+
f"拒绝技能包降级: {manifest['skill_id']} {manifest['version']} < {previous['version']}"
|
|
444
|
+
)
|
|
445
|
+
if version == old_version and previous.get("issued_at"):
|
|
446
|
+
same_pack = previous.get("plan_hash") == compute_plan_hash(manifest)
|
|
447
|
+
if issued == str(previous["issued_at"]) and same_pack:
|
|
448
|
+
return issued
|
|
449
|
+
if issued <= str(previous["issued_at"]):
|
|
450
|
+
raise SkillDowngradeError("拒绝技能包重放:issued_at 未前进")
|
|
451
|
+
return issued
|
|
452
|
+
|
|
453
|
+
@staticmethod
|
|
454
|
+
def _requirements(manifest: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
455
|
+
value = manifest.get("required_capabilities", {})
|
|
456
|
+
if not isinstance(value, Mapping):
|
|
457
|
+
return {}
|
|
458
|
+
profile = str(manifest.get("profile") or "")
|
|
459
|
+
selected = value.get(profile)
|
|
460
|
+
return selected if isinstance(selected, Mapping) else value
|
|
461
|
+
|
|
462
|
+
@classmethod
|
|
463
|
+
def check_capabilities(cls, manifest: Mapping[str, Any], capabilities: Mapping[str, Any] | None = None) -> None:
|
|
464
|
+
current = dict(capabilities or cls.capability_vector())
|
|
465
|
+
requirements = cls._requirements(manifest)
|
|
466
|
+
for key in ("os", "arch"):
|
|
467
|
+
needed = requirements.get(key)
|
|
468
|
+
if needed and current.get(key) not in ({str(x).lower() for x in needed} if isinstance(needed, (list, tuple, set)) else {str(needed).lower()}):
|
|
469
|
+
raise SkillCapabilityError(f"技能包需要 {key}={needed},当前为 {current.get(key)}")
|
|
470
|
+
if requirements.get("has_docker") is True and not bool(current.get("has_docker")):
|
|
471
|
+
raise SkillCapabilityError("技能包需要 Docker,但当前环境不可用")
|
|
472
|
+
if requirements.get("memory_mb") is not None:
|
|
473
|
+
try:
|
|
474
|
+
current_mb = int(current.get("memory_mb") or 0)
|
|
475
|
+
needed_mb = int(requirements["memory_mb"])
|
|
476
|
+
if 0 < current_mb < needed_mb:
|
|
477
|
+
raise SkillCapabilityError(f"技能包需要至少 {needed_mb}MB 内存,当前仅 {current_mb}MB")
|
|
478
|
+
except (TypeError, ValueError) as exc:
|
|
479
|
+
raise SkillCapabilityError("技能包 memory_mb 能力声明无效") from exc
|
|
480
|
+
required_python = requirements.get("python")
|
|
481
|
+
if required_python:
|
|
482
|
+
actual = _version_tuple(f"{current.get('python', '0.0')}.0")
|
|
483
|
+
match = re.search(r"(\d+)(?:\.(\d+))?", str(required_python))
|
|
484
|
+
if match and actual[:2] < (int(match.group(1)), int(match.group(2) or 0)):
|
|
485
|
+
raise SkillCapabilityError(f"技能包需要 Python {required_python},当前为 {current.get('python')}")
|
|
486
|
+
|
|
487
|
+
def _load_candidate(self, layer: str, pack_dir: Path, *, capabilities: Mapping[str, Any] | None,
|
|
488
|
+
entitlements: set[str], profile: str | None,
|
|
489
|
+
unsigned_allowed: bool = False,
|
|
490
|
+
skip_version: bool = False,
|
|
491
|
+
record_version: bool = True) -> dict[str, Any]:
|
|
492
|
+
manifest = self._read_manifest(pack_dir)
|
|
493
|
+
if layer in _OVERLAY_LAYERS and not unsigned_allowed:
|
|
494
|
+
verify_manifest_signature(manifest, pack_dir / "manifest.sig", self.public_key)
|
|
495
|
+
if not skip_version:
|
|
496
|
+
self._check_version(manifest, layer)
|
|
497
|
+
candidate_profile = str(manifest.get("profile") or "")
|
|
498
|
+
if profile and profile != "auto" and candidate_profile and candidate_profile != profile \
|
|
499
|
+
and not (profile == "full" and candidate_profile == "lite"):
|
|
500
|
+
raise SkillCapabilityError(f"技能包 profile={candidate_profile or 'default'} 不满足请求 profile={profile}")
|
|
501
|
+
required_entitlements = {str(x) for x in (manifest.get("entitlements") or [])}
|
|
502
|
+
if not required_entitlements.issubset(entitlements):
|
|
503
|
+
missing = ", ".join(sorted(required_entitlements - entitlements))
|
|
504
|
+
raise SkillCapabilityError(f"技能包缺少订阅权益: {missing}")
|
|
505
|
+
self.check_capabilities(manifest, capabilities)
|
|
506
|
+
stages: dict[str, dict[str, Any]] = {}
|
|
507
|
+
stages_dir = pack_dir / "stages"
|
|
508
|
+
if stages_dir.is_dir():
|
|
509
|
+
for stage_file in sorted(stages_dir.glob("*.md")):
|
|
510
|
+
stage_id = stage_file.stem
|
|
511
|
+
content = stage_file.read_text(encoding="utf-8")
|
|
512
|
+
l1, l2 = split_stage_content(content, max_l1_tokens=manifest.get("budgets", {}).get("max_l1_checklist_tokens", MAX_L1_TOKEN_DEFAULT))
|
|
513
|
+
stages[stage_id] = {"file_path": str(stage_file), "l1_checklist": l1, "l2_playbook": l2, "full_text": content}
|
|
514
|
+
modules: dict[str, dict[str, Any]] = {}
|
|
515
|
+
modules_dir = pack_dir / "modules"
|
|
516
|
+
if modules_dir.is_dir():
|
|
517
|
+
for module_file in sorted(modules_dir.glob("*.md")):
|
|
518
|
+
modules[module_file.stem] = {"file_path": str(module_file), "content": module_file.read_text(encoding="utf-8")}
|
|
519
|
+
pack = {
|
|
520
|
+
"manifest": manifest,
|
|
521
|
+
"plan_hash": compute_plan_hash(manifest),
|
|
522
|
+
"stages": stages,
|
|
523
|
+
"modules": modules,
|
|
524
|
+
"pack_dir": str(pack_dir),
|
|
525
|
+
"source_layer": layer,
|
|
526
|
+
"profile": candidate_profile or "default",
|
|
527
|
+
"capabilities": dict(capabilities or self.capability_vector()),
|
|
528
|
+
}
|
|
529
|
+
if layer in _OVERLAY_LAYERS and not unsigned_allowed and record_version:
|
|
530
|
+
self._write_version(manifest)
|
|
531
|
+
return pack
|
|
532
|
+
|
|
533
|
+
@staticmethod
|
|
534
|
+
def _session_file(session_path: Path | str | None) -> Path | None:
|
|
535
|
+
if session_path is None:
|
|
536
|
+
return None
|
|
537
|
+
path = Path(session_path).expanduser()
|
|
538
|
+
return path / "session.json" if path.is_dir() or path.suffix == "" else path
|
|
539
|
+
|
|
540
|
+
def _pin(self, session_path: Path | str | None, pack: Mapping[str, Any]) -> None:
|
|
541
|
+
path = self._session_file(session_path)
|
|
542
|
+
if path is None:
|
|
543
|
+
return
|
|
544
|
+
state = self._read_state(path)
|
|
545
|
+
pinned = state.setdefault("pinned_skills", {})
|
|
546
|
+
skill_id = str(pack["manifest"]["skill_id"])
|
|
547
|
+
existing = pinned.get(skill_id)
|
|
548
|
+
if existing:
|
|
549
|
+
return
|
|
550
|
+
snapshot_path = path.parent / ".skill-packs" / skill_id / str(pack["manifest"]["version"])
|
|
551
|
+
if snapshot_path.exists():
|
|
552
|
+
shutil.rmtree(snapshot_path)
|
|
553
|
+
try:
|
|
554
|
+
snapshot_path.parent.mkdir(parents=True, exist_ok=True)
|
|
555
|
+
shutil.copytree(pack["pack_dir"], snapshot_path)
|
|
556
|
+
except OSError:
|
|
557
|
+
snapshot_path = None # type: ignore[assignment]
|
|
558
|
+
pinned[skill_id] = {
|
|
559
|
+
"version": pack["manifest"]["version"],
|
|
560
|
+
"plan_hash": pack["plan_hash"],
|
|
561
|
+
"source_layer": pack.get("source_layer"),
|
|
562
|
+
"snapshot_path": str(snapshot_path) if snapshot_path else None,
|
|
563
|
+
}
|
|
564
|
+
_atomic_json_write(path, state)
|
|
565
|
+
|
|
566
|
+
def load(self, skill_id: str, *, session_path: Path | str | None = None,
|
|
567
|
+
profile: str | None = None, entitlements: Iterable[str] | str | None = None,
|
|
568
|
+
capabilities: Mapping[str, Any] | None = None,
|
|
569
|
+
allow_degraded: bool = True) -> dict[str, Any]:
|
|
570
|
+
if not _SKILL_ID_RE.fullmatch(str(skill_id)):
|
|
571
|
+
raise SkillPackError(f"非法 skill_id: {skill_id!r}")
|
|
572
|
+
requested_entitlements = set(
|
|
573
|
+
x.strip() for x in (entitlements.split(",") if isinstance(entitlements, str) else (entitlements or ())) if str(x).strip()
|
|
574
|
+
)
|
|
575
|
+
session_file = self._session_file(session_path)
|
|
576
|
+
pinned = self._read_state(session_file).get("pinned_skills", {}).get(skill_id, {}) if session_file else {}
|
|
577
|
+
errors: list[Exception] = []
|
|
578
|
+
if pinned.get("snapshot_path"):
|
|
579
|
+
snapshot = Path(str(pinned["snapshot_path"])).expanduser().resolve()
|
|
580
|
+
if snapshot.is_dir() and not snapshot.is_symlink():
|
|
581
|
+
try:
|
|
582
|
+
layer = str(pinned.get("source_layer") or "builtin")
|
|
583
|
+
pack = self._load_candidate(
|
|
584
|
+
layer, snapshot, capabilities=capabilities, entitlements=requested_entitlements,
|
|
585
|
+
profile=profile, unsigned_allowed=layer == "builtin", skip_version=True,
|
|
586
|
+
)
|
|
587
|
+
if pack["plan_hash"] == pinned.get("plan_hash"):
|
|
588
|
+
pack["pinned_snapshot"] = True
|
|
589
|
+
return pack
|
|
590
|
+
except (OSError, SkillPackError, ValueError, UnicodeError) as exc:
|
|
591
|
+
errors.append(exc)
|
|
592
|
+
for layer, pack_dir in self._candidate_dirs(skill_id):
|
|
593
|
+
try:
|
|
594
|
+
manifest = self._read_manifest(pack_dir)
|
|
595
|
+
if pinned:
|
|
596
|
+
if str(manifest.get("version")) != str(pinned.get("version")):
|
|
597
|
+
continue
|
|
598
|
+
pack = self._load_candidate(
|
|
599
|
+
layer, pack_dir, capabilities=capabilities, entitlements=requested_entitlements,
|
|
600
|
+
profile=profile, unsigned_allowed=False,
|
|
601
|
+
)
|
|
602
|
+
if pinned and pinned.get("plan_hash") != pack["plan_hash"]:
|
|
603
|
+
continue
|
|
604
|
+
self._pin(session_path, pack)
|
|
605
|
+
return pack
|
|
606
|
+
except (OSError, SkillPackError, ValueError, UnicodeError) as exc:
|
|
607
|
+
errors.append(exc)
|
|
608
|
+
if pinned:
|
|
609
|
+
# A quarantined pinned overlay must not brick a Session; use the
|
|
610
|
+
# immutable builtin as the last safe boundary and expose the fact.
|
|
611
|
+
for layer, pack_dir in self._candidate_dirs(skill_id):
|
|
612
|
+
if layer != "builtin":
|
|
613
|
+
continue
|
|
614
|
+
try:
|
|
615
|
+
pack = self._load_candidate(layer, pack_dir, capabilities=capabilities,
|
|
616
|
+
entitlements=requested_entitlements, profile=None,
|
|
617
|
+
unsigned_allowed=True)
|
|
618
|
+
pack["pinned_fallback"] = True
|
|
619
|
+
return pack
|
|
620
|
+
except (OSError, SkillPackError, ValueError, UnicodeError) as exc:
|
|
621
|
+
errors.append(exc)
|
|
622
|
+
if errors and not allow_degraded:
|
|
623
|
+
raise errors[-1]
|
|
624
|
+
if errors:
|
|
625
|
+
# If no builtin survived, preserve the most actionable validation
|
|
626
|
+
# failure rather than hiding the security boundary.
|
|
627
|
+
raise errors[-1]
|
|
628
|
+
raise FileNotFoundError(f"Skill pack not found in overlays or builtin: {skill_id}")
|
|
629
|
+
|
|
630
|
+
def load_skill_pack(self, skill_id: str, **kwargs: Any) -> dict[str, Any]:
|
|
631
|
+
return self.load(skill_id, **kwargs)
|
|
632
|
+
|
|
633
|
+
def list_skill_ids(self) -> list[str]:
|
|
634
|
+
ids: set[str] = set()
|
|
635
|
+
for _layer, root in self._layer_roots():
|
|
636
|
+
if root.is_dir():
|
|
637
|
+
ids.update(p.name for p in root.iterdir() if p.is_dir() and _SKILL_ID_RE.fullmatch(p.name))
|
|
638
|
+
return sorted(ids)
|
|
639
|
+
|
|
640
|
+
def _health(self) -> dict[str, Any]:
|
|
641
|
+
value = self._read_state(self.health_path)
|
|
642
|
+
value.setdefault("skills", {})
|
|
643
|
+
return value
|
|
644
|
+
|
|
645
|
+
def record_success(self, skill_id: str) -> dict[str, Any]:
|
|
646
|
+
health = self._health()
|
|
647
|
+
item = health["skills"].setdefault(skill_id, {})
|
|
648
|
+
item.update({"consecutive_failures": 0, "last_status": "ok"})
|
|
649
|
+
_atomic_json_write(self.health_path, health)
|
|
650
|
+
return item
|
|
651
|
+
|
|
652
|
+
def record_crash(self, skill_id: str, pack_dir: Path | str | None = None,
|
|
653
|
+
error: object | None = None) -> dict[str, Any]:
|
|
654
|
+
health = self._health()
|
|
655
|
+
item = health["skills"].setdefault(skill_id, {})
|
|
656
|
+
item["consecutive_failures"] = int(item.get("consecutive_failures", 0) or 0) + 1
|
|
657
|
+
item["crash_count"] = int(item.get("crash_count", 0) or 0) + 1
|
|
658
|
+
item["last_status"] = "crash"
|
|
659
|
+
item["last_error"] = str(error or "")[:500]
|
|
660
|
+
if item["consecutive_failures"] >= 2:
|
|
661
|
+
source = Path(pack_dir).expanduser().resolve() if pack_dir else None
|
|
662
|
+
if source is None:
|
|
663
|
+
for layer, candidate in self._candidate_dirs(skill_id):
|
|
664
|
+
if layer in _OVERLAY_LAYERS:
|
|
665
|
+
source = candidate
|
|
666
|
+
break
|
|
667
|
+
if source and source.is_dir() and not source.is_symlink():
|
|
668
|
+
try:
|
|
669
|
+
source_is_overlay = False
|
|
670
|
+
try:
|
|
671
|
+
source.relative_to(self.global_overlay)
|
|
672
|
+
source_is_overlay = True
|
|
673
|
+
except ValueError:
|
|
674
|
+
if self.project_overlay is not None:
|
|
675
|
+
try:
|
|
676
|
+
source.relative_to(self.project_overlay)
|
|
677
|
+
source_is_overlay = True
|
|
678
|
+
except ValueError:
|
|
679
|
+
pass
|
|
680
|
+
if source_is_overlay:
|
|
681
|
+
self.quarantine_root.mkdir(parents=True, exist_ok=True)
|
|
682
|
+
target = self.quarantine_root / skill_id
|
|
683
|
+
if target.exists():
|
|
684
|
+
target = self.quarantine_root / f"{skill_id}-{int(dt.datetime.now().timestamp())}"
|
|
685
|
+
shutil.move(str(source), str(target))
|
|
686
|
+
item["quarantined"] = str(target)
|
|
687
|
+
item["circuit_breaker"] = "open"
|
|
688
|
+
except (OSError, ValueError):
|
|
689
|
+
pass
|
|
690
|
+
_atomic_json_write(self.health_path, health)
|
|
691
|
+
return item
|
|
692
|
+
|
|
693
|
+
def execute(self, skill_id: str, callback: Any, *args: Any, **kwargs: Any) -> Any:
|
|
694
|
+
"""Run one skill callback and feed its uncaught failure to the breaker."""
|
|
695
|
+
pack = self.load(skill_id, **kwargs.pop("load_options", {}))
|
|
696
|
+
try:
|
|
697
|
+
result = callback(pack, *args, **kwargs)
|
|
698
|
+
except Exception as exc:
|
|
699
|
+
self.record_crash(skill_id, pack.get("pack_dir"), exc)
|
|
700
|
+
raise
|
|
701
|
+
self.record_success(skill_id)
|
|
702
|
+
return result
|
|
703
|
+
|
|
704
|
+
def import_bundle(self, bundle: Path | str, *, target_root: Path | str | None = None) -> dict[str, Any]:
|
|
705
|
+
"""Verify and atomically import an offline signed skill archive."""
|
|
706
|
+
destination = Path(target_root).expanduser().resolve() if target_root else self.global_overlay
|
|
707
|
+
destination.mkdir(parents=True, exist_ok=True)
|
|
708
|
+
with tempfile.TemporaryDirectory(prefix="bugx-skill-import-") as temp_dir:
|
|
709
|
+
staging = Path(temp_dir)
|
|
710
|
+
with tarfile.open(Path(bundle).expanduser(), "r:*") as archive:
|
|
711
|
+
members = archive.getmembers()
|
|
712
|
+
for member in members:
|
|
713
|
+
name = Path(member.name)
|
|
714
|
+
if name.is_absolute() or ".." in name.parts or member.issym() or member.islnk():
|
|
715
|
+
raise SkillPackError("技能包归档包含不安全路径")
|
|
716
|
+
archive.extractall(staging)
|
|
717
|
+
manifests = list(staging.rglob("manifest.json"))
|
|
718
|
+
if len(manifests) != 1:
|
|
719
|
+
raise SkillPackError("离线技能包必须包含且仅包含一个 manifest.json")
|
|
720
|
+
pack_dir = manifests[0].parent
|
|
721
|
+
manifest = self._read_manifest(pack_dir)
|
|
722
|
+
self._load_candidate(
|
|
723
|
+
"global", pack_dir, capabilities=None, entitlements=set(), profile=None,
|
|
724
|
+
record_version=False,
|
|
725
|
+
)
|
|
726
|
+
skill_id = str(manifest["skill_id"])
|
|
727
|
+
target = destination / skill_id
|
|
728
|
+
old_manifest = target / "manifest.json"
|
|
729
|
+
if old_manifest.is_file():
|
|
730
|
+
old = self._read_manifest(target)
|
|
731
|
+
if _version_tuple(manifest["version"]) < _version_tuple(old["version"]):
|
|
732
|
+
raise SkillDowngradeError("离线技能包版本低于已安装版本")
|
|
733
|
+
publish = destination / f".{skill_id}.incoming"
|
|
734
|
+
if publish.exists():
|
|
735
|
+
shutil.rmtree(publish)
|
|
736
|
+
shutil.copytree(pack_dir, publish)
|
|
737
|
+
try:
|
|
738
|
+
if target.exists():
|
|
739
|
+
backup = destination / f".{skill_id}.previous"
|
|
740
|
+
if backup.exists():
|
|
741
|
+
shutil.rmtree(backup)
|
|
742
|
+
os.replace(target, backup)
|
|
743
|
+
os.replace(publish, target)
|
|
744
|
+
if 'backup' in locals() and backup.exists():
|
|
745
|
+
shutil.rmtree(backup)
|
|
746
|
+
finally:
|
|
747
|
+
if publish.exists():
|
|
748
|
+
shutil.rmtree(publish)
|
|
749
|
+
return self.load(skill_id)
|
|
750
|
+
|
|
751
|
+
def download_skill_pack(
|
|
752
|
+
self,
|
|
753
|
+
skill_id: str,
|
|
754
|
+
base_url: str | None = None,
|
|
755
|
+
*,
|
|
756
|
+
auth_token: str | None = None,
|
|
757
|
+
profile: str | None = None,
|
|
758
|
+
entitlements: Iterable[str] | str | None = None,
|
|
759
|
+
target_root: Path | str | None = None,
|
|
760
|
+
timeout: float = 15.0,
|
|
761
|
+
) -> dict[str, Any]:
|
|
762
|
+
"""Download, verify, and atomically install a signed skill pack from cloud."""
|
|
763
|
+
import urllib.request
|
|
764
|
+
import urllib.error
|
|
765
|
+
url_base = (
|
|
766
|
+
base_url
|
|
767
|
+
or os.environ.get("BUGX_CLOUD_API_BASE")
|
|
768
|
+
or os.environ.get("BUGX_CLOUD_API", "https://bugx.dev")
|
|
769
|
+
).rstrip("/")
|
|
770
|
+
url = f"{url_base}/api/v1/agent/skills/{skill_id}/bundle"
|
|
771
|
+
ctx = self.request_context(entitlements, profile)
|
|
772
|
+
headers = dict(ctx["headers"])
|
|
773
|
+
headers["Accept"] = "application/gzip, application/octet-stream"
|
|
774
|
+
if auth_token:
|
|
775
|
+
headers["Authorization"] = f"Bearer {auth_token}"
|
|
776
|
+
req = urllib.request.Request(url, headers=headers, method="GET")
|
|
777
|
+
try:
|
|
778
|
+
try:
|
|
779
|
+
if url.startswith("https://"):
|
|
780
|
+
resp_ctx = tls_context(base_url=url_base)
|
|
781
|
+
resp = urllib.request.urlopen(req, timeout=timeout, context=resp_ctx)
|
|
782
|
+
else:
|
|
783
|
+
resp = urllib.request.urlopen(req, timeout=timeout)
|
|
784
|
+
except TypeError:
|
|
785
|
+
resp = urllib.request.urlopen(req, timeout=timeout)
|
|
786
|
+
with resp:
|
|
787
|
+
raw_data = resp.read()
|
|
788
|
+
except urllib.error.HTTPError as exc:
|
|
789
|
+
raise SkillPackError(f"云端技能包拉取失败 (HTTP {exc.code}): {exc}") from exc
|
|
790
|
+
except (urllib.error.URLError, TimeoutError, OSError) as exc:
|
|
791
|
+
raise SkillPackError(f"云端技能包网络传输失败: {exc}") from exc
|
|
792
|
+
with tempfile.NamedTemporaryFile(suffix=".tar.gz", delete=False) as tmp_file:
|
|
793
|
+
tmp_path = Path(tmp_file.name)
|
|
794
|
+
tmp_file.write(raw_data)
|
|
795
|
+
try:
|
|
796
|
+
return self.import_bundle(tmp_path, target_root=target_root)
|
|
797
|
+
finally:
|
|
798
|
+
tmp_path.unlink(missing_ok=True)
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
def global_overlay_dir() -> Path:
|
|
802
|
+
"""返回官方/全局商业技能包 Overlay 存放路径。"""
|
|
803
|
+
home = Path(os.environ.get("BUGX_HOME", str(Path.home() / ".bugx"))).expanduser().resolve()
|
|
804
|
+
return home / SKILLS_DIR_NAME / "official"
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
def import_skill_bundle(bundle: Path | str, target_dir: Path | str | None = None) -> dict[str, Any]:
|
|
808
|
+
"""验证并原子导入离线签名技能包。"""
|
|
809
|
+
loader = SkillPackLoader(global_overlay=target_dir) if target_dir else SkillPackLoader()
|
|
810
|
+
pack = loader.import_bundle(bundle, target_root=target_dir)
|
|
811
|
+
manifest = pack.get("manifest", {})
|
|
812
|
+
return {
|
|
813
|
+
"skill_id": manifest.get("skill_id"),
|
|
814
|
+
"version": manifest.get("version"),
|
|
815
|
+
"path": pack.get("pack_dir"),
|
|
816
|
+
"plan_hash": pack.get("plan_hash"),
|
|
817
|
+
"pack": pack,
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
def pull_skill_pack(skill_id: str, **kwargs: Any) -> dict[str, Any]:
|
|
822
|
+
"""从云端拉取、验证并安装技能包。"""
|
|
823
|
+
return SkillPackLoader().download_skill_pack(skill_id, **kwargs)
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
def load_skill_pack(skill_id: str, skills_dir: Path | None = None, **kwargs: Any) -> dict[str, Any]:
|
|
827
|
+
"""Compatibility wrapper around :class:`SkillPackLoader`."""
|
|
828
|
+
if skills_dir is not None:
|
|
829
|
+
# Legacy callers pass the immutable builtin directory. Keep that
|
|
830
|
+
# compatibility path explicit; overlay candidates still go through
|
|
831
|
+
# the normal detached-signature check in SkillPackLoader.load().
|
|
832
|
+
loader_options = {
|
|
833
|
+
key: kwargs.pop(key) for key in (
|
|
834
|
+
"project_root", "home", "project_overlay", "global_overlay", "builtin_root",
|
|
835
|
+
"health_path", "versions_path", "public_key", "now",
|
|
836
|
+
) if key in kwargs
|
|
837
|
+
}
|
|
838
|
+
loader = SkillPackLoader(builtin_root=skills_dir, **loader_options)
|
|
839
|
+
return loader.load(skill_id, **kwargs)
|
|
840
|
+
loader_options = {
|
|
841
|
+
key: kwargs.pop(key) for key in (
|
|
842
|
+
"project_root", "home", "project_overlay", "global_overlay", "builtin_root",
|
|
843
|
+
"health_path", "versions_path", "public_key", "now",
|
|
844
|
+
) if key in kwargs
|
|
845
|
+
}
|
|
846
|
+
return SkillPackLoader(**loader_options).load(skill_id, **kwargs)
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
def find_matching_skill_packs(
|
|
850
|
+
classification: Mapping[str, Any],
|
|
851
|
+
skills_dir: Path | None = None,
|
|
852
|
+
*,
|
|
853
|
+
project_root: Path | str | None = None,
|
|
854
|
+
entitlements: Iterable[str] | str | None = None,
|
|
855
|
+
capabilities: Mapping[str, Any] | None = None,
|
|
856
|
+
) -> list[dict[str, Any]]:
|
|
857
|
+
"""根据项目的技术栈分类查找适用的技能包。"""
|
|
858
|
+
loader = (SkillPackLoader(project_root=project_root, builtin_root=skills_dir)
|
|
859
|
+
if skills_dir is not None else SkillPackLoader(project_root=project_root))
|
|
860
|
+
if skills_dir is not None:
|
|
861
|
+
ids = sorted(p.name for p in skills_dir.iterdir()
|
|
862
|
+
if p.is_dir() and _SKILL_ID_RE.fullmatch(p.name)) if skills_dir.is_dir() else []
|
|
863
|
+
else:
|
|
864
|
+
ids = loader.list_skill_ids()
|
|
865
|
+
|
|
866
|
+
forms = set(classification.get("forms") or [])
|
|
867
|
+
surfaces = set(classification.get("surfaces") or [])
|
|
868
|
+
frameworks = set(classification.get("frameworks") or [])
|
|
869
|
+
|
|
870
|
+
matches = []
|
|
871
|
+
for skill_id in ids:
|
|
872
|
+
try:
|
|
873
|
+
pack = loader.load(skill_id, entitlements=entitlements, capabilities=capabilities)
|
|
874
|
+
manifest = pack["manifest"]
|
|
875
|
+
except Exception:
|
|
876
|
+
continue
|
|
877
|
+
|
|
878
|
+
applies_if = manifest.get("applies_if", {})
|
|
879
|
+
req_forms = set(applies_if.get("forms") or [])
|
|
880
|
+
req_surfaces = set(applies_if.get("surfaces") or [])
|
|
881
|
+
req_frameworks = set(applies_if.get("frameworks") or [])
|
|
882
|
+
|
|
883
|
+
# 匹配逻辑:form 和 surface 只要有重叠即命中
|
|
884
|
+
form_match = not req_forms or bool(forms & req_forms)
|
|
885
|
+
surface_match = not req_surfaces or bool(surfaces & req_surfaces)
|
|
886
|
+
framework_match = not req_frameworks or bool(frameworks & req_frameworks)
|
|
887
|
+
|
|
888
|
+
if form_match and surface_match:
|
|
889
|
+
score = 0
|
|
890
|
+
if form_match:
|
|
891
|
+
score += len(forms & req_forms) * 2
|
|
892
|
+
if surface_match:
|
|
893
|
+
score += len(surfaces & req_surfaces) * 3
|
|
894
|
+
if framework_match and req_frameworks:
|
|
895
|
+
score += len(frameworks & req_frameworks) * 5
|
|
896
|
+
|
|
897
|
+
matches.append({
|
|
898
|
+
"skill_id": manifest["skill_id"],
|
|
899
|
+
"version": manifest["version"],
|
|
900
|
+
"score": score,
|
|
901
|
+
"manifest": manifest,
|
|
902
|
+
"plan_hash": compute_plan_hash(manifest),
|
|
903
|
+
})
|
|
904
|
+
|
|
905
|
+
matches.sort(key=lambda item: item["score"], reverse=True)
|
|
906
|
+
return matches
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
def runtime_requirements(manifest: Mapping[str, Any]) -> dict[str, list[dict[str, Any]]]:
|
|
910
|
+
"""归一化技能包的**运行时能力需求**(DOC-233 设计项 1)。
|
|
911
|
+
|
|
912
|
+
与 ``required_capabilities``(**主机环境**:os/arch/python/memory/docker)语义分离:
|
|
913
|
+
本字段只声明"挖掘需要哪些 MCP / 工具",供能力编排器消费。
|
|
914
|
+
|
|
915
|
+
工具缺省为必需项,只有显式 ``tier="optional"`` 才允许跳过;MCP
|
|
916
|
+
缺省仍为 optional。未声明该字段视为无运行时需求。
|
|
917
|
+
"""
|
|
918
|
+
raw = manifest.get("required_runtime")
|
|
919
|
+
if raw is None:
|
|
920
|
+
return {"mcp": [], "tools": []}
|
|
921
|
+
if not isinstance(raw, Mapping):
|
|
922
|
+
raise SkillPackError("required_runtime 必须是对象")
|
|
923
|
+
result: dict[str, list[dict[str, Any]]] = {"mcp": [], "tools": []}
|
|
924
|
+
for kind in ("mcp", "tools"):
|
|
925
|
+
items = raw.get(kind)
|
|
926
|
+
if items is None:
|
|
927
|
+
continue
|
|
928
|
+
if not isinstance(items, (list, tuple)):
|
|
929
|
+
raise SkillPackError(f"required_runtime.{kind} 必须是数组")
|
|
930
|
+
default_tier = "required" if kind == "tools" else "optional"
|
|
931
|
+
allowed_tiers = {"required", "optional"} if kind == "tools" else {
|
|
932
|
+
"optional", "hard_for_mcp_auto",
|
|
933
|
+
}
|
|
934
|
+
for item in items:
|
|
935
|
+
if isinstance(item, str) and item.strip():
|
|
936
|
+
if kind == "tools":
|
|
937
|
+
raise SkillPackError(
|
|
938
|
+
"required_runtime.tools 条目必须是带 stage_ids 的对象"
|
|
939
|
+
)
|
|
940
|
+
result[kind].append({"name": item.strip(), "tier": default_tier})
|
|
941
|
+
elif isinstance(item, Mapping):
|
|
942
|
+
name = str(item.get("name") or "").strip()
|
|
943
|
+
if not name:
|
|
944
|
+
raise SkillPackError(f"required_runtime.{kind} 条目缺少 name")
|
|
945
|
+
tier = str(item.get("tier", default_tier)).strip()
|
|
946
|
+
if tier not in allowed_tiers:
|
|
947
|
+
raise SkillPackError(
|
|
948
|
+
f"required_runtime.{kind}.{name} 的 tier 无效: {tier}"
|
|
949
|
+
)
|
|
950
|
+
requirement: dict[str, Any] = {"name": name, "tier": tier}
|
|
951
|
+
if kind == "tools":
|
|
952
|
+
stage_ids = item.get("stage_ids")
|
|
953
|
+
if not isinstance(stage_ids, (list, tuple)) or not stage_ids \
|
|
954
|
+
or any(not isinstance(stage, str) or not stage.strip()
|
|
955
|
+
for stage in stage_ids):
|
|
956
|
+
raise SkillPackError(
|
|
957
|
+
f"required_runtime.tools.{name}.stage_ids 必须是非空字符串数组"
|
|
958
|
+
)
|
|
959
|
+
normalized_stages = [stage.strip() for stage in stage_ids]
|
|
960
|
+
if len(set(normalized_stages)) != len(normalized_stages):
|
|
961
|
+
raise SkillPackError(
|
|
962
|
+
f"required_runtime.tools.{name}.stage_ids 不得包含重复阶段"
|
|
963
|
+
)
|
|
964
|
+
requirement["stage_ids"] = normalized_stages
|
|
965
|
+
if kind == "tools" and "targets" in item:
|
|
966
|
+
targets = item["targets"]
|
|
967
|
+
if not isinstance(targets, (list, tuple)) or not targets \
|
|
968
|
+
or any(not isinstance(target, str) or not target.strip()
|
|
969
|
+
for target in targets):
|
|
970
|
+
raise SkillPackError(
|
|
971
|
+
f"required_runtime.tools.{name}.targets 必须是非空字符串数组"
|
|
972
|
+
)
|
|
973
|
+
normalized_targets = [target.strip().casefold() for target in targets]
|
|
974
|
+
if len(set(normalized_targets)) != len(normalized_targets):
|
|
975
|
+
raise SkillPackError(
|
|
976
|
+
f"required_runtime.tools.{name}.targets 不得包含重复目标"
|
|
977
|
+
)
|
|
978
|
+
requirement["targets"] = normalized_targets
|
|
979
|
+
result[kind].append(requirement)
|
|
980
|
+
else:
|
|
981
|
+
raise SkillPackError(f"required_runtime.{kind} 包含无效条目")
|
|
982
|
+
return result
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
def _validate_runtime_tool_ids(manifest: Mapping[str, Any]) -> None:
|
|
986
|
+
"""Reject Skill tool declarations that have no trusted probe implementation."""
|
|
987
|
+
tool_requirements = runtime_requirements(manifest).get("tools", [])
|
|
988
|
+
if not tool_requirements:
|
|
989
|
+
return
|
|
990
|
+
raw_stages = manifest.get("stage_pipeline")
|
|
991
|
+
if not isinstance(raw_stages, (list, tuple)) or not raw_stages:
|
|
992
|
+
raise SkillPackError("required_runtime.tools 要求非空 stage_pipeline")
|
|
993
|
+
stage_ids: list[str] = []
|
|
994
|
+
for stage in raw_stages:
|
|
995
|
+
if not isinstance(stage, Mapping):
|
|
996
|
+
raise SkillPackError("stage_pipeline 包含无效阶段")
|
|
997
|
+
stage_id = str(stage.get("stage_id") or "").strip()
|
|
998
|
+
if not stage_id:
|
|
999
|
+
raise SkillPackError("stage_pipeline 阶段缺少 stage_id")
|
|
1000
|
+
stage_ids.append(stage_id)
|
|
1001
|
+
if len(set(stage_ids)) != len(stage_ids):
|
|
1002
|
+
raise SkillPackError("stage_pipeline.stage_id 必须唯一")
|
|
1003
|
+
valid_stage_ids = set(stage_ids)
|
|
1004
|
+
try:
|
|
1005
|
+
from core.probes import probe_registry
|
|
1006
|
+
except ImportError:
|
|
1007
|
+
try:
|
|
1008
|
+
from core import probe_registry # type: ignore[no-redef]
|
|
1009
|
+
except ImportError as exc:
|
|
1010
|
+
raise SkillPackError(
|
|
1011
|
+
"required_runtime.tools 无法校验:BugX probe 注册表不可用"
|
|
1012
|
+
) from exc
|
|
1013
|
+
|
|
1014
|
+
for item in tool_requirements:
|
|
1015
|
+
name = item["name"]
|
|
1016
|
+
unknown_stages = sorted(set(item["stage_ids"]) - valid_stage_ids)
|
|
1017
|
+
if unknown_stages:
|
|
1018
|
+
raise SkillPackError(
|
|
1019
|
+
f"required_runtime.tools.{name} 引用了未登记 stage_id: "
|
|
1020
|
+
+ ", ".join(unknown_stages)
|
|
1021
|
+
)
|
|
1022
|
+
descriptor = probe_registry.get_probe(name)
|
|
1023
|
+
if descriptor is None:
|
|
1024
|
+
raise SkillPackError(
|
|
1025
|
+
f"required_runtime.tools 引用了未注册的 BugX probe: {name}"
|
|
1026
|
+
)
|
|
1027
|
+
if item["tier"] == "required" and descriptor.lifecycle not in {
|
|
1028
|
+
"preflight", "runtime",
|
|
1029
|
+
}:
|
|
1030
|
+
raise SkillPackError(
|
|
1031
|
+
f"required_runtime.tools probe {name} 的 lifecycle 无效: "
|
|
1032
|
+
f"{descriptor.lifecycle}"
|
|
1033
|
+
)
|
|
1034
|
+
if item["tier"] == "required" and descriptor.lifecycle == "runtime" \
|
|
1035
|
+
and not descriptor.readiness_args:
|
|
1036
|
+
raise SkillPackError(
|
|
1037
|
+
f"required_runtime.tools 要求的 runtime probe {name} 未声明安全就绪动作"
|
|
1038
|
+
)
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
def compile_skill_plan(
|
|
1042
|
+
skill_id: str,
|
|
1043
|
+
classification: Mapping[str, Any],
|
|
1044
|
+
skills_dir: Path | None = None,
|
|
1045
|
+
*,
|
|
1046
|
+
project_root: Path | str | None = None,
|
|
1047
|
+
session_path: Path | str | None = None,
|
|
1048
|
+
profile: str | None = None,
|
|
1049
|
+
entitlements: Iterable[str] | str | None = None,
|
|
1050
|
+
capabilities: Mapping[str, Any] | None = None,
|
|
1051
|
+
) -> dict[str, Any] | None:
|
|
1052
|
+
"""为特定项目编译生成激活的技能包计划 (skill_plan)。"""
|
|
1053
|
+
try:
|
|
1054
|
+
loader = (SkillPackLoader(project_root=project_root, builtin_root=skills_dir)
|
|
1055
|
+
if skills_dir is not None else SkillPackLoader(project_root=project_root))
|
|
1056
|
+
pack = loader.load(
|
|
1057
|
+
skill_id, session_path=session_path, profile=profile,
|
|
1058
|
+
entitlements=entitlements, capabilities=capabilities)
|
|
1059
|
+
except (FileNotFoundError, ValueError):
|
|
1060
|
+
return None
|
|
1061
|
+
|
|
1062
|
+
manifest = pack["manifest"]
|
|
1063
|
+
surfaces = set(classification.get("surfaces") or [])
|
|
1064
|
+
|
|
1065
|
+
# 根据当前项目的实际表面动态激活可选模块 (Module Activation)
|
|
1066
|
+
active_modules = []
|
|
1067
|
+
for mod in manifest.get("optional_modules", []):
|
|
1068
|
+
if mod in surfaces or (mod == "upload" and "file" in surfaces) or (mod == "multi-tenant" and "auth" in surfaces):
|
|
1069
|
+
active_modules.append(mod)
|
|
1070
|
+
|
|
1071
|
+
return {
|
|
1072
|
+
"skill_id": manifest["skill_id"],
|
|
1073
|
+
"version": manifest["version"],
|
|
1074
|
+
"plan_hash": pack["plan_hash"],
|
|
1075
|
+
"stage_pipeline": manifest["stage_pipeline"],
|
|
1076
|
+
# Keep manifest runtime needs in the compiled plan passed to the stage
|
|
1077
|
+
# harness. Dropping them here made the worker plan lose its declared
|
|
1078
|
+
# tools even though runtime_requirements() had already normalized them.
|
|
1079
|
+
"required_runtime": runtime_requirements(manifest),
|
|
1080
|
+
"active_modules": active_modules,
|
|
1081
|
+
"budgets": manifest["budgets"],
|
|
1082
|
+
"experience_queries": manifest.get("experience_queries", {}),
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
def patch_skill_plan(
|
|
1087
|
+
plan: Mapping[str, Any],
|
|
1088
|
+
new_modules: Iterable[str],
|
|
1089
|
+
skills_dir: Path | None = None,
|
|
1090
|
+
*,
|
|
1091
|
+
project_root: Path | str | None = None,
|
|
1092
|
+
) -> tuple[dict[str, Any], list[str]]:
|
|
1093
|
+
"""在探索期动态打补丁激活可选模块 (DOC-125 动态自愈激活)。
|
|
1094
|
+
|
|
1095
|
+
返回: (patched_plan, added_modules)
|
|
1096
|
+
"""
|
|
1097
|
+
skill_id = str(plan.get("skill_id") or "")
|
|
1098
|
+
if not skill_id:
|
|
1099
|
+
return dict(plan), []
|
|
1100
|
+
|
|
1101
|
+
try:
|
|
1102
|
+
loader = (SkillPackLoader(project_root=project_root, builtin_root=skills_dir)
|
|
1103
|
+
if skills_dir is not None else SkillPackLoader(project_root=project_root))
|
|
1104
|
+
pack = loader.load(skill_id)
|
|
1105
|
+
except (FileNotFoundError, ValueError):
|
|
1106
|
+
return dict(plan), []
|
|
1107
|
+
|
|
1108
|
+
manifest = pack["manifest"]
|
|
1109
|
+
optional_allowed = set(manifest.get("optional_modules", []))
|
|
1110
|
+
|
|
1111
|
+
current_active = list(plan.get("active_modules") or [])
|
|
1112
|
+
current_set = set(current_active)
|
|
1113
|
+
|
|
1114
|
+
added = []
|
|
1115
|
+
for mod in new_modules:
|
|
1116
|
+
m = str(mod).strip().lower()
|
|
1117
|
+
if m in optional_allowed and m not in current_set and m not in added:
|
|
1118
|
+
added.append(m)
|
|
1119
|
+
|
|
1120
|
+
if not added:
|
|
1121
|
+
return dict(plan), []
|
|
1122
|
+
|
|
1123
|
+
patched = dict(plan)
|
|
1124
|
+
patched["active_modules"] = sorted(current_set | set(added))
|
|
1125
|
+
|
|
1126
|
+
# 重新计算 plan_hash:基于当前 plan 内容的确定性哈希
|
|
1127
|
+
raw_bytes = _canonical_json_bytes({
|
|
1128
|
+
"skill_id": patched.get("skill_id"),
|
|
1129
|
+
"version": patched.get("version"),
|
|
1130
|
+
"active_modules": patched.get("active_modules"),
|
|
1131
|
+
"stage_pipeline": patched.get("stage_pipeline"),
|
|
1132
|
+
"budgets": patched.get("budgets"),
|
|
1133
|
+
})
|
|
1134
|
+
patched["parent_plan_hash"] = plan.get("plan_hash")
|
|
1135
|
+
patched["plan_hash"] = f"sha256:{hashlib.sha256(raw_bytes).hexdigest()}"
|
|
1136
|
+
return patched, added
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
_SENSITIVE_PATTERNS: tuple[tuple[str, re.Pattern[str]], ...] = (
|
|
1140
|
+
("cloud_access_key", re.compile(r"\b(?:AKIA|ASIA)[0-9A-Z]{16}\b")),
|
|
1141
|
+
("private_key", re.compile(r"-----BEGIN [^-]{0,40}PRIVATE KEY-----")),
|
|
1142
|
+
# PE-20261004-005B:值部分不含点/冒号(文件路径:行号类散文不再误报),
|
|
1143
|
+
# 显式覆盖 "bearer <JWT/长token>"(旧式漏报);≥16 字符保持口令/hex 检出。
|
|
1144
|
+
# PE-20261008-001:原子组禁止回溯 + 值段紧跟中文视为散文——派生 signature
|
|
1145
|
+
# 是 "{category}: {title}"(如 "authorization: write_text_atomic 的…"),
|
|
1146
|
+
# category 恰为敏感词且 title 以 ≥16 字符标识符开头,不构成凭据赋值;
|
|
1147
|
+
# 真凭据值后不会紧跟中文散文。
|
|
1148
|
+
("credential_assignment", re.compile(
|
|
1149
|
+
r"(?i)\b(?:api[_-]?key|secret|token|password|passwd|authorization|cookie)"
|
|
1150
|
+
r"\s*[:=]\s*[\"']?(?:bearer\s+)?"
|
|
1151
|
+
# 负向先行:值为源文件引用(路径 + 源码扩展名 [+ :行号])时不算凭据
|
|
1152
|
+
r"(?![A-Za-z0-9_./-]*\.(?:py|js|ts|go|md|sql|json|ya?ml|txt|sh|rb|java|toml|cfg|ini|lock|whl|gemspec)\b(?::\d+)?)"
|
|
1153
|
+
r"(?>[A-Za-z0-9+/=_\-]{16,})(?!\s*[\u4e00-\u9fff])"
|
|
1154
|
+
)),
|
|
1155
|
+
("ip_address", re.compile(r"\b(?:10\.\d{1,3}\.\d{1,3}\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3})\b")),
|
|
1156
|
+
)
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
class CandidatePromotionGuard:
|
|
1160
|
+
"""DOC-125: 经验到 Skill Candidate 晋级硬门槛守卫 (Adversarial Regression Guard)。"""
|
|
1161
|
+
|
|
1162
|
+
@staticmethod
|
|
1163
|
+
def scan_sensitive(content: str) -> list[str]:
|
|
1164
|
+
"""扫描内容中是否包含敏感信息(API Key, Token, IP 等)。"""
|
|
1165
|
+
hits = []
|
|
1166
|
+
for name, pat in _SENSITIVE_PATTERNS:
|
|
1167
|
+
if pat.search(content):
|
|
1168
|
+
hits.append(name)
|
|
1169
|
+
return hits
|
|
1170
|
+
|
|
1171
|
+
@classmethod
|
|
1172
|
+
def evaluate_candidate(
|
|
1173
|
+
cls,
|
|
1174
|
+
candidate_record: Mapping[str, Any],
|
|
1175
|
+
) -> tuple[bool, list[str]]:
|
|
1176
|
+
"""评估候选经验是否满足 4 道晋级硬门槛。
|
|
1177
|
+
|
|
1178
|
+
门槛要求:
|
|
1179
|
+
1. 多周期验证:lifecycle_count >= 2 且 passed_tests >= 3;
|
|
1180
|
+
2. 对抗性样本库回放 (0 误报铁律):clean_code_false_positives == 0 且 fp_growth_rate <= 0.0;
|
|
1181
|
+
3. 敏感信息脱敏:绝无真实 Token、API Key、内网 IP 等;
|
|
1182
|
+
4. 提供确定性回滚依据 (rollback_target)。
|
|
1183
|
+
|
|
1184
|
+
返回: (passed, reasons)
|
|
1185
|
+
"""
|
|
1186
|
+
reasons = []
|
|
1187
|
+
|
|
1188
|
+
# 1. 多周期与用例验证
|
|
1189
|
+
lifecycles = int(candidate_record.get("lifecycle_count", 0))
|
|
1190
|
+
passed_tests = int(candidate_record.get("passed_tests", 0))
|
|
1191
|
+
if lifecycles < 2 or passed_tests < 3:
|
|
1192
|
+
reasons.append(
|
|
1193
|
+
f"多周期门槛未达标: lifecycles={lifecycles} (需>=2), passed_tests={passed_tests} (需>=3)"
|
|
1194
|
+
)
|
|
1195
|
+
|
|
1196
|
+
# 2. 对抗性干净样本库回放 (0 误报)
|
|
1197
|
+
clean_fps = int(candidate_record.get("clean_code_false_positives", 0))
|
|
1198
|
+
fp_growth = float(candidate_record.get("fp_growth_rate", 0.0))
|
|
1199
|
+
if clean_fps > 0 or fp_growth > 0.0:
|
|
1200
|
+
reasons.append(
|
|
1201
|
+
f"对抗性样本库回放未过: clean_fps={clean_fps} (必须=0), fp_growth={fp_growth} (必须<=0%)"
|
|
1202
|
+
)
|
|
1203
|
+
|
|
1204
|
+
# 3. 敏感信息脱敏硬扫描
|
|
1205
|
+
text_to_scan = json.dumps(dict(candidate_record), ensure_ascii=False)
|
|
1206
|
+
sensitive_hits = cls.scan_sensitive(text_to_scan)
|
|
1207
|
+
if sensitive_hits:
|
|
1208
|
+
reasons.append(f"发现敏感凭据未脱敏: {', '.join(sensitive_hits)}")
|
|
1209
|
+
|
|
1210
|
+
# 4. 回滚能力
|
|
1211
|
+
if not candidate_record.get("rollback_target"):
|
|
1212
|
+
reasons.append("缺少 rollback_target 回滚定位标识")
|
|
1213
|
+
|
|
1214
|
+
return len(reasons) == 0, reasons
|