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,1464 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""BugX 统一诊断日志。
|
|
3
|
+
|
|
4
|
+
日志是排查安装、宿主调用和运行异常的辅助记录,不替代生命周期事件、结论或
|
|
5
|
+
证据文件。已初始化的项目写入项目 ``.bugx/logs/bugx.jsonl``;尚未初始化的
|
|
6
|
+
目录回退到用户级 ``~/.bugx/logs/projects/<project_id>/bugx.jsonl``。
|
|
7
|
+
|
|
8
|
+
回退是必需的:``.bugx/logs/`` 由项目布局初始化器创建(DOC-001 §5.8),而
|
|
9
|
+
诊断日志是**每个命令**(包括 ``doctor``/``hosts`` 这类纯只读命令)都会产生
|
|
10
|
+
的副作用。若由日志引导来创建 ``<root>/.bugx``,任何在普通目录里的读操作都会
|
|
11
|
+
凭空造出一个"有 .bugx 但没有 manifest"的半初始化状态,并把该目录的
|
|
12
|
+
``git status`` 弄脏(BugX 不管理 ``.gitignore``)。采用标准库 logging,支持
|
|
13
|
+
JSONL、等级过滤、有限轮转和敏感字段脱敏。
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import contextvars
|
|
19
|
+
import datetime as dt
|
|
20
|
+
from contextlib import contextmanager
|
|
21
|
+
import hashlib
|
|
22
|
+
import json
|
|
23
|
+
import logging
|
|
24
|
+
import time
|
|
25
|
+
from logging.handlers import RotatingFileHandler
|
|
26
|
+
import os
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
import re
|
|
29
|
+
import statistics
|
|
30
|
+
import sys
|
|
31
|
+
import time
|
|
32
|
+
from typing import Any
|
|
33
|
+
import uuid
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
import fcntl
|
|
37
|
+
except ImportError: # pragma: no cover - Windows has no fcntl.
|
|
38
|
+
fcntl = None # type: ignore[assignment]
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
import msvcrt
|
|
42
|
+
except ImportError: # pragma: no cover - POSIX has no msvcrt.
|
|
43
|
+
msvcrt = None # type: ignore[assignment]
|
|
44
|
+
|
|
45
|
+
LOG_SCHEMA_VERSION = 2
|
|
46
|
+
_CORRELATION_CACHE: dict[str, Any] = {}
|
|
47
|
+
LOG_DIR_NAME = "logs"
|
|
48
|
+
LOG_FILE_NAME = "bugx.jsonl"
|
|
49
|
+
# 未初始化目录的日志回退根。默认 ``~/.bugx/logs``,与 ``BUGX_GLOBAL_CACHE_ROOT``
|
|
50
|
+
# / ``BUGX_GLOBAL_TELEMETRY_ROOT`` 同属"用户级、可被测试隔离"的一类覆盖点。
|
|
51
|
+
GLOBAL_LOG_ROOT_ENV = "BUGX_GLOBAL_LOG_ROOT"
|
|
52
|
+
GLOBAL_LOG_PROJECTS_DIR = "projects"
|
|
53
|
+
MAX_BYTES = 5 * 1024 * 1024
|
|
54
|
+
BACKUP_COUNT = 3
|
|
55
|
+
LOGGER_NAME = "bugx"
|
|
56
|
+
_SCOPED_SYNC_EXPORT: contextvars.ContextVar[bool] = contextvars.ContextVar(
|
|
57
|
+
"bugx_scoped_sync_export", default=False,
|
|
58
|
+
)
|
|
59
|
+
_CONTEXT_ENV = {
|
|
60
|
+
"trace_id": "BUGX_TRACE_ID",
|
|
61
|
+
"run_id": "BUGX_RUN_ID",
|
|
62
|
+
"lifecycle_id": "BUGX_LIFECYCLE_ID",
|
|
63
|
+
"round": "BUGX_ROUND",
|
|
64
|
+
"worker_id": "BUGX_WORKER_ID",
|
|
65
|
+
"finding_id": "BUGX_FINDING_ID",
|
|
66
|
+
"incident_id": "BUGX_INCIDENT_ID",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_SECRET_KEY = re.compile(
|
|
70
|
+
r"(?:token|password|passwd|secret|api[_-]?key|access[_-]?key|cookie|authorization"
|
|
71
|
+
r"|credential|private[_-]?key|auth)",
|
|
72
|
+
re.IGNORECASE,
|
|
73
|
+
)
|
|
74
|
+
# LLM 阶段统计与预算字段排除在敏感鉴权 Token 脱敏之外 (DOC-042)
|
|
75
|
+
_METRIC_TOKEN_KEY = re.compile(
|
|
76
|
+
r"(?:^|[_-])(?:tokens?_consumed|tokens?_budget|tokens?_breakdown|tokens?_count"
|
|
77
|
+
r"|prompt_tokens|completion_tokens|total_tokens|diff_tokens|actual_tokens"
|
|
78
|
+
r"|budget_tokens|tokens)$",
|
|
79
|
+
re.IGNORECASE,
|
|
80
|
+
)
|
|
81
|
+
# 值侧匹配允许引号包裹(token="abc" / secret='xyz'),引号计入前缀组,
|
|
82
|
+
# 结束引号保留在输出中,脱敏后仍是合法的引用片段。
|
|
83
|
+
_SECRET_VALUE = re.compile(
|
|
84
|
+
r"(?i)(bearer\s+|basic\s+|(?:token|password|passwd|secret|api[_-]?key|cookie"
|
|
85
|
+
r"|credential|private[_-]?key|auth)\s*[=:]\s*[\"']?)[^\s,;\"']+",
|
|
86
|
+
)
|
|
87
|
+
# 无 key 上下文的超长疑似 token(JWT / base64 私钥片段等)整段脱敏。
|
|
88
|
+
_LONG_TOKEN = re.compile(r"[A-Za-z0-9_-]{80,}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def is_initialized_project(root: Path) -> bool:
|
|
92
|
+
"""Return whether ``root`` already carries a BugX project manifest.
|
|
93
|
+
|
|
94
|
+
``.bugx/logs/`` belongs to the project layout and is created by the layout
|
|
95
|
+
initializer (``bugx init`` / ``bugx install``, DOC-001 §5.8). A directory
|
|
96
|
+
without ``.bugx/manifest.json`` has no project runtime to record evidence
|
|
97
|
+
in, so the diagnostic logger must not be the thing that creates one.
|
|
98
|
+
"""
|
|
99
|
+
manifest = Path(root).resolve() / ".bugx" / "manifest.json"
|
|
100
|
+
return manifest.is_file() and not manifest.is_symlink()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def global_log_root() -> Path:
|
|
104
|
+
"""Return the per-user fallback log root without creating it."""
|
|
105
|
+
override = os.environ.get(GLOBAL_LOG_ROOT_ENV)
|
|
106
|
+
if override:
|
|
107
|
+
return Path(override).expanduser()
|
|
108
|
+
return Path.home() / ".bugx" / LOG_DIR_NAME
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def project_log_id(root: Path) -> str:
|
|
112
|
+
"""Return the stable per-project key used to isolate fallback logs.
|
|
113
|
+
|
|
114
|
+
Mirrors ``bugx_paths._project_id`` so a fallback log can be traced back to
|
|
115
|
+
its directory without reading that directory's (absent) manifest.
|
|
116
|
+
"""
|
|
117
|
+
return hashlib.sha256(str(Path(root).resolve()).encode("utf-8")).hexdigest()[:16]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def global_log_path(root: Path) -> Path:
|
|
121
|
+
"""Return the fallback log path for a directory that is not a project."""
|
|
122
|
+
return (
|
|
123
|
+
global_log_root()
|
|
124
|
+
/ GLOBAL_LOG_PROJECTS_DIR
|
|
125
|
+
/ project_log_id(root)
|
|
126
|
+
/ LOG_FILE_NAME
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def log_path(root: Path, *, project_scoped: bool | None = None) -> Path:
|
|
131
|
+
"""Return the diagnostic log path without creating anything.
|
|
132
|
+
|
|
133
|
+
Initialized projects keep the documented ``<root>/.bugx/logs/bugx.jsonl``
|
|
134
|
+
location. Anything else falls back to the per-user store so that running a
|
|
135
|
+
read-only command from an arbitrary directory stays observationally
|
|
136
|
+
read-only instead of manufacturing project state.
|
|
137
|
+
"""
|
|
138
|
+
root = Path(root).resolve()
|
|
139
|
+
if project_scoped is None:
|
|
140
|
+
project_scoped = is_initialized_project(root)
|
|
141
|
+
if project_scoped:
|
|
142
|
+
return root / ".bugx" / LOG_DIR_NAME / LOG_FILE_NAME
|
|
143
|
+
return global_log_path(root)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _private_dir_chain(outer: Path, inner: Path, *, label: str) -> Path:
|
|
147
|
+
"""Create every level from ``outer`` down to ``inner`` as a 0700 directory.
|
|
148
|
+
|
|
149
|
+
``outer`` is the BugX-owned root (``<root>/.bugx`` or ``~/.bugx/logs``), so
|
|
150
|
+
an intermediate ``projects/<project_id>`` step cannot be left world
|
|
151
|
+
readable. Every level is checked for symlinks first: a linked component
|
|
152
|
+
could redirect the log outside the intended tree (SEC-14).
|
|
153
|
+
"""
|
|
154
|
+
try:
|
|
155
|
+
relative = inner.relative_to(outer)
|
|
156
|
+
except ValueError:
|
|
157
|
+
raise ValueError(f"{label}日志目录必须位于 {outer} 之内: {inner}") from None
|
|
158
|
+
chain = [outer]
|
|
159
|
+
for part in relative.parts:
|
|
160
|
+
chain.append(chain[-1] / part)
|
|
161
|
+
for candidate in chain:
|
|
162
|
+
if candidate.is_symlink() or (candidate.exists() and not candidate.is_dir()):
|
|
163
|
+
raise ValueError(f"拒绝写入不安全的{label}日志目录: {candidate}")
|
|
164
|
+
for candidate in chain:
|
|
165
|
+
candidate.mkdir(mode=0o700, exist_ok=True)
|
|
166
|
+
os.chmod(candidate, 0o700)
|
|
167
|
+
return inner
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
DEFAULT_SLOW_THRESHOLD_SECONDS = 30.0
|
|
171
|
+
_TRACEPARENT_RE = re.compile(
|
|
172
|
+
r"^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$", re.IGNORECASE
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def parse_traceparent(raw: str | None) -> dict[str, str] | None:
|
|
177
|
+
"""Parse a W3C traceparent header string into constituent fields.
|
|
178
|
+
|
|
179
|
+
Conforms to W3C TraceContext Level 1:
|
|
180
|
+
- Version 'ff' is rejected as invalid;
|
|
181
|
+
- All-zero trace_id or parent_id are rejected as invalid;
|
|
182
|
+
- Returns lower-case hex values if valid, else None.
|
|
183
|
+
"""
|
|
184
|
+
if not raw or not isinstance(raw, str):
|
|
185
|
+
return None
|
|
186
|
+
raw = raw.strip()
|
|
187
|
+
match = _TRACEPARENT_RE.match(raw)
|
|
188
|
+
if not match:
|
|
189
|
+
return None
|
|
190
|
+
version, trace_id, parent_id, flags = match.groups()
|
|
191
|
+
if version.lower() == "ff":
|
|
192
|
+
return None
|
|
193
|
+
if trace_id == "0" * 32:
|
|
194
|
+
return None
|
|
195
|
+
if parent_id == "0" * 16:
|
|
196
|
+
return None
|
|
197
|
+
return {
|
|
198
|
+
"version": version.lower(),
|
|
199
|
+
"trace_id": trace_id.lower(),
|
|
200
|
+
"parent_id": parent_id.lower(),
|
|
201
|
+
"trace_flags": flags.lower(),
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def generate_traceparent(trace_id: str | None = None, parent_id: str | None = None,
|
|
206
|
+
flags: str = "01") -> str:
|
|
207
|
+
"""Generate a standard W3C traceparent header string."""
|
|
208
|
+
clean_trace = trace_id.lower() if trace_id and len(trace_id) == 32 else uuid.uuid4().hex
|
|
209
|
+
clean_parent = parent_id.lower() if parent_id and len(parent_id) == 16 else uuid.uuid4().hex[:16]
|
|
210
|
+
return f"00-{clean_trace}-{clean_parent}-{flags}"
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def safe_value(value: Any, *, key: str = "") -> Any:
|
|
214
|
+
if key and _SECRET_KEY.search(key) and not _METRIC_TOKEN_KEY.search(key):
|
|
215
|
+
return "[REDACTED]"
|
|
216
|
+
if isinstance(value, dict):
|
|
217
|
+
return {str(k): safe_value(v, key=str(k)) for k, v in value.items()}
|
|
218
|
+
if isinstance(value, (list, tuple, set)):
|
|
219
|
+
return [safe_value(item, key=key) for item in value]
|
|
220
|
+
if isinstance(value, Path):
|
|
221
|
+
return str(value)
|
|
222
|
+
if isinstance(value, str):
|
|
223
|
+
redacted = _SECRET_VALUE.sub(r"\1[REDACTED]", value)
|
|
224
|
+
return _LONG_TOKEN.sub("[REDACTED]", redacted)
|
|
225
|
+
if value is None or isinstance(value, (bool, int, float)):
|
|
226
|
+
return value
|
|
227
|
+
return str(value)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class _JsonFormatter(logging.Formatter):
|
|
231
|
+
def format(self, record: logging.LogRecord) -> str:
|
|
232
|
+
timestamp = dt.datetime.fromtimestamp(
|
|
233
|
+
record.created, tz=dt.timezone.utc,
|
|
234
|
+
).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
235
|
+
payload: dict[str, Any] = {
|
|
236
|
+
"schema_version": LOG_SCHEMA_VERSION,
|
|
237
|
+
"timestamp": timestamp,
|
|
238
|
+
"level": record.levelname,
|
|
239
|
+
"logger": record.name,
|
|
240
|
+
"event": getattr(record, "bugx_event", "log"),
|
|
241
|
+
"message": record.getMessage(),
|
|
242
|
+
"pid": record.process,
|
|
243
|
+
}
|
|
244
|
+
try:
|
|
245
|
+
from core.infra import build_info
|
|
246
|
+
payload["build_id"] = build_info.get_build_id()
|
|
247
|
+
except Exception:
|
|
248
|
+
# 降级必须可区分(F-RSI-20261115-288):build_id 缺失时显式留痕,
|
|
249
|
+
# 让"日志缺字段"可被下游审计检索,而不是无声蒸发。
|
|
250
|
+
payload["build_id_unavailable"] = True
|
|
251
|
+
fields = getattr(record, "bugx_fields", {})
|
|
252
|
+
if isinstance(fields, dict):
|
|
253
|
+
payload.update(safe_value(fields))
|
|
254
|
+
if record.exc_info:
|
|
255
|
+
payload["exception"] = safe_value(self.formatException(record.exc_info))
|
|
256
|
+
return json.dumps(safe_value(payload), ensure_ascii=False, separators=(",", ":"))
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class _OtlpHttpHandler(logging.Handler):
|
|
260
|
+
"""Asynchronous HTTP exporter to push spans to OTLP endpoint (e.g. Arize Phoenix / Langfuse).
|
|
261
|
+
|
|
262
|
+
Degradation policy (F-RSI-20261115-288): telemetry/audit exports must
|
|
263
|
+
never silently disappear. TLS policy construction failures refuse to send
|
|
264
|
+
(fail-closed, no downgrade to the bare system trust store), send failures
|
|
265
|
+
are counted on the handler, and first/every-20th occurrence is surfaced on
|
|
266
|
+
stderr. Plaintext ``http://`` endpoints warn once at construction unless
|
|
267
|
+
``BUGX_OTLP_ALLOW_INSECURE=1`` acknowledges the choice.
|
|
268
|
+
"""
|
|
269
|
+
|
|
270
|
+
def __init__(self, endpoint: str) -> None:
|
|
271
|
+
super().__init__()
|
|
272
|
+
self.endpoint = endpoint
|
|
273
|
+
import threading
|
|
274
|
+
import urllib.request
|
|
275
|
+
self._request_mod = urllib.request
|
|
276
|
+
self._counter_lock = threading.Lock()
|
|
277
|
+
self.export_failure_count = 0
|
|
278
|
+
self.last_export_error: str | None = None
|
|
279
|
+
self.tls_degradation_count = 0
|
|
280
|
+
try:
|
|
281
|
+
from core.infra import build_info
|
|
282
|
+
self._scope_version = str(build_info.BASE_VERSION)
|
|
283
|
+
except Exception:
|
|
284
|
+
self._scope_version = "unknown"
|
|
285
|
+
if not endpoint.startswith("https://"):
|
|
286
|
+
self._warn_insecure_endpoint()
|
|
287
|
+
|
|
288
|
+
def _warn_insecure_endpoint(self) -> None:
|
|
289
|
+
"""Plaintext OTLP endpoints must be an explicit, visible choice."""
|
|
290
|
+
if os.environ.get("BUGX_OTLP_ALLOW_INSECURE", "").strip() == "1":
|
|
291
|
+
return
|
|
292
|
+
print(
|
|
293
|
+
f" ⚠ BUGX_OTLP_ENDPOINT 非 HTTPS ({self.endpoint}):诊断/审计 span 将"
|
|
294
|
+
"以明文传输。确需 http 端点时设置 BUGX_OTLP_ALLOW_INSECURE=1 显式确认。",
|
|
295
|
+
file=sys.stderr,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
def _warn_export_failure(self, kind: str) -> None:
|
|
299
|
+
"""Emit one bounded stderr line for an export failure.
|
|
300
|
+
|
|
301
|
+
Never the span payload, never a raise: the logging infrastructure must
|
|
302
|
+
not break the main flow, but its failures must stay observable. The
|
|
303
|
+
structured counters on this handler remain the machine-readable truth.
|
|
304
|
+
"""
|
|
305
|
+
detail = str(safe_value(self.last_export_error))[:200]
|
|
306
|
+
print(
|
|
307
|
+
f"[bugx-otlp] {kind} failed"
|
|
308
|
+
f" (export_failures={self.export_failure_count},"
|
|
309
|
+
f" tls_degradations={self.tls_degradation_count}): {detail}",
|
|
310
|
+
file=sys.stderr,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
314
|
+
fields = getattr(record, "bugx_fields", {})
|
|
315
|
+
if not isinstance(fields, dict):
|
|
316
|
+
return
|
|
317
|
+
trace_id = fields.get("trace_id")
|
|
318
|
+
span_id = fields.get("span_id")
|
|
319
|
+
if not trace_id or not span_id:
|
|
320
|
+
return
|
|
321
|
+
|
|
322
|
+
# A reusable launcher scope restores cwd/env before returning. Finish
|
|
323
|
+
# exports in that scope so their proxy/config reads cannot cross the
|
|
324
|
+
# restoration boundary. The existing request timeout is not a DNS or
|
|
325
|
+
# total wall-clock guarantee.
|
|
326
|
+
if _SCOPED_SYNC_EXPORT.get():
|
|
327
|
+
self._send_otlp(record, fields, trace_id, span_id)
|
|
328
|
+
return
|
|
329
|
+
|
|
330
|
+
# 异步线程发送,绝不阻塞主控或工具调用
|
|
331
|
+
import threading
|
|
332
|
+
t = threading.Thread(
|
|
333
|
+
target=self._send_otlp,
|
|
334
|
+
args=(record, fields, trace_id, span_id),
|
|
335
|
+
daemon=True,
|
|
336
|
+
)
|
|
337
|
+
t.start()
|
|
338
|
+
|
|
339
|
+
def _send_otlp(self, record: logging.LogRecord, fields: dict[str, Any], trace_id: str, span_id: str) -> None:
|
|
340
|
+
try:
|
|
341
|
+
start_time_ns = int(record.created * 1e9)
|
|
342
|
+
duration_ms = fields.get("duration_ms") or (float(fields.get("duration_seconds", 0)) * 1000)
|
|
343
|
+
end_time_ns = start_time_ns + int(float(duration_ms) * 1e6)
|
|
344
|
+
clean_trace = str(trace_id).lower().replace("-", "").zfill(32)[-32:]
|
|
345
|
+
clean_span = str(span_id).lower().replace("-", "").zfill(16)[-16:]
|
|
346
|
+
parent_id = fields.get("parent_span_id")
|
|
347
|
+
clean_parent = str(parent_id).lower().replace("-", "").zfill(16)[-16:] if parent_id else ""
|
|
348
|
+
|
|
349
|
+
attrs = []
|
|
350
|
+
for k, v in fields.items():
|
|
351
|
+
if k in {"trace_id", "span_id", "parent_span_id", "traceparent"}:
|
|
352
|
+
continue
|
|
353
|
+
attrs.append({
|
|
354
|
+
"key": str(k),
|
|
355
|
+
"value": {"stringValue": str(safe_value(v))},
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
event_name = getattr(record, "bugx_event", "log")
|
|
359
|
+
span = {
|
|
360
|
+
"traceId": clean_trace,
|
|
361
|
+
"spanId": clean_span,
|
|
362
|
+
"name": f"bugx.{event_name}",
|
|
363
|
+
"kind": 1, # SPAN_KIND_INTERNAL
|
|
364
|
+
"startTimeUnixNano": str(start_time_ns),
|
|
365
|
+
"endTimeUnixNano": str(end_time_ns),
|
|
366
|
+
"attributes": attrs,
|
|
367
|
+
"status": {"code": 2 if record.levelno >= logging.ERROR else 1},
|
|
368
|
+
}
|
|
369
|
+
if clean_parent:
|
|
370
|
+
span["parentSpanId"] = clean_parent
|
|
371
|
+
|
|
372
|
+
otlp_payload = {
|
|
373
|
+
"resourceSpans": [{
|
|
374
|
+
"resource": {
|
|
375
|
+
"attributes": [{
|
|
376
|
+
"key": "service.name",
|
|
377
|
+
"value": {"stringValue": "bugx"},
|
|
378
|
+
}],
|
|
379
|
+
},
|
|
380
|
+
"scopeSpans": [{
|
|
381
|
+
"scope": {"name": "bugx.tracer", "version": self._scope_version},
|
|
382
|
+
"spans": [span],
|
|
383
|
+
}],
|
|
384
|
+
}],
|
|
385
|
+
}
|
|
386
|
+
body = json.dumps(otlp_payload).encode("utf-8")
|
|
387
|
+
req = self._request_mod.Request(
|
|
388
|
+
self.endpoint,
|
|
389
|
+
data=body,
|
|
390
|
+
headers={"Content-Type": "application/json"},
|
|
391
|
+
method="POST",
|
|
392
|
+
)
|
|
393
|
+
kwargs: dict[str, Any] = {"timeout": 2.0}
|
|
394
|
+
if self.endpoint.startswith("https://"):
|
|
395
|
+
try:
|
|
396
|
+
from core.infra.client_metadata import tls_context
|
|
397
|
+
kwargs["context"] = tls_context(base_url=self.endpoint)
|
|
398
|
+
except Exception as exc:
|
|
399
|
+
# TLS 策略构造失败必须 fail-closed 且可见(F-RSI-20261115-288):
|
|
400
|
+
# client_metadata.tls_context 对 BUGX_CA_BUNDLE 配置错误会显式
|
|
401
|
+
# 抛错,静默吞掉会击穿其校验契约,把 https 上报降级为系统默认
|
|
402
|
+
# 信任库。这里拒绝发送并留下结构化计数 + 可见告警。
|
|
403
|
+
with self._counter_lock:
|
|
404
|
+
self.tls_degradation_count += 1
|
|
405
|
+
self.last_export_error = f"tls_policy: {type(exc).__name__}: {exc}"
|
|
406
|
+
surface = (
|
|
407
|
+
self.tls_degradation_count == 1
|
|
408
|
+
or self.tls_degradation_count % 20 == 0
|
|
409
|
+
)
|
|
410
|
+
if surface:
|
|
411
|
+
self._warn_export_failure("tls_policy")
|
|
412
|
+
return
|
|
413
|
+
with self._request_mod.urlopen(req, **kwargs) as resp:
|
|
414
|
+
pass
|
|
415
|
+
except Exception as exc:
|
|
416
|
+
# 上报失败不可静默(F-RSI-20261115-288):审计证据链可静默丢失与
|
|
417
|
+
# 本仓证据一致性门冲突。计数 + 有界 stderr 告警(首次与每第 20 次),
|
|
418
|
+
# 不抛出——logging 基础设施不得影响审计主流程。
|
|
419
|
+
with self._counter_lock:
|
|
420
|
+
self.export_failure_count += 1
|
|
421
|
+
self.last_export_error = f"{type(exc).__name__}: {exc}"
|
|
422
|
+
surface = (
|
|
423
|
+
self.export_failure_count == 1
|
|
424
|
+
or self.export_failure_count % 20 == 0
|
|
425
|
+
)
|
|
426
|
+
if surface:
|
|
427
|
+
self._warn_export_failure("export")
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
class _SecureRotatingFileHandler(RotatingFileHandler):
|
|
431
|
+
"""Private rotating handler with a process-wide rollover lock."""
|
|
432
|
+
|
|
433
|
+
def __init__(self, filename, *args, **kwargs): # type: ignore[no-untyped-def]
|
|
434
|
+
super().__init__(filename, *args, **kwargs)
|
|
435
|
+
self._bugx_lock_path = Path(f"{self.baseFilename}.lock")
|
|
436
|
+
if self._bugx_lock_path.is_symlink():
|
|
437
|
+
raise ValueError(f"拒绝使用符号链接日志锁: {self._bugx_lock_path}")
|
|
438
|
+
deadline = time.monotonic() + 10.0
|
|
439
|
+
while True:
|
|
440
|
+
try:
|
|
441
|
+
self._bugx_lock_path.touch(mode=0o600, exist_ok=True)
|
|
442
|
+
os.chmod(self._bugx_lock_path, 0o600)
|
|
443
|
+
self._bugx_lock_stream = self._bugx_lock_path.open("a+b")
|
|
444
|
+
break
|
|
445
|
+
except OSError:
|
|
446
|
+
if time.monotonic() >= deadline:
|
|
447
|
+
self._bugx_lock_stream = None # degrade gracefully
|
|
448
|
+
break
|
|
449
|
+
time.sleep(0.02)
|
|
450
|
+
|
|
451
|
+
@contextmanager
|
|
452
|
+
def _process_lock(self):
|
|
453
|
+
if self._bugx_lock_stream is None:
|
|
454
|
+
yield
|
|
455
|
+
return
|
|
456
|
+
if fcntl is not None:
|
|
457
|
+
deadline = time.monotonic() + 10.0
|
|
458
|
+
lock_mode = fcntl.LOCK_EX | getattr(fcntl, "LOCK_NB", 0)
|
|
459
|
+
while True:
|
|
460
|
+
try:
|
|
461
|
+
fcntl.flock(self._bugx_lock_stream.fileno(), lock_mode)
|
|
462
|
+
break
|
|
463
|
+
except OSError:
|
|
464
|
+
if time.monotonic() >= deadline:
|
|
465
|
+
raise
|
|
466
|
+
time.sleep(0.05)
|
|
467
|
+
try:
|
|
468
|
+
yield
|
|
469
|
+
finally:
|
|
470
|
+
fcntl.flock(self._bugx_lock_stream.fileno(), fcntl.LOCK_UN)
|
|
471
|
+
return
|
|
472
|
+
if msvcrt is not None:
|
|
473
|
+
# ``LK_LOCK`` can surface a sharing violation as PermissionError
|
|
474
|
+
# on Windows when another BugX process is rotating the same log.
|
|
475
|
+
# Use the non-blocking primitive and own the bounded wait here so
|
|
476
|
+
# a transient peer never crashes the install command.
|
|
477
|
+
deadline = time.monotonic() + 10.0
|
|
478
|
+
lock_mode = getattr(msvcrt, "LK_NBLCK", None)
|
|
479
|
+
if lock_mode is None: # pragma: no cover - old msvcrt fallback.
|
|
480
|
+
lock_mode = msvcrt.LK_LOCK
|
|
481
|
+
while True:
|
|
482
|
+
self._bugx_lock_stream.seek(0)
|
|
483
|
+
try:
|
|
484
|
+
msvcrt.locking(
|
|
485
|
+
self._bugx_lock_stream.fileno(), lock_mode, 1,
|
|
486
|
+
)
|
|
487
|
+
break
|
|
488
|
+
except OSError:
|
|
489
|
+
if time.monotonic() >= deadline:
|
|
490
|
+
raise
|
|
491
|
+
time.sleep(0.05)
|
|
492
|
+
try:
|
|
493
|
+
yield
|
|
494
|
+
finally:
|
|
495
|
+
self._bugx_lock_stream.seek(0)
|
|
496
|
+
msvcrt.locking(
|
|
497
|
+
self._bugx_lock_stream.fileno(), msvcrt.LK_UNLCK, 1,
|
|
498
|
+
)
|
|
499
|
+
return
|
|
500
|
+
yield
|
|
501
|
+
|
|
502
|
+
def _open(self): # type: ignore[no-untyped-def]
|
|
503
|
+
stream = super()._open()
|
|
504
|
+
try:
|
|
505
|
+
os.chmod(self.baseFilename, 0o600)
|
|
506
|
+
except OSError:
|
|
507
|
+
pass
|
|
508
|
+
return stream
|
|
509
|
+
|
|
510
|
+
def _write_jsonl_record(self, record: logging.LogRecord) -> str | None:
|
|
511
|
+
"""Write and flush one record, returning its event ID only on success.
|
|
512
|
+
|
|
513
|
+
``RotatingFileHandler.emit`` intentionally routes formatter and I/O
|
|
514
|
+
errors through ``handleError``. That behavior is useful for ordinary
|
|
515
|
+
diagnostics, but it cannot serve as an acknowledgement for post gates:
|
|
516
|
+
callers need to distinguish a flushed JSONL row from a silently dropped
|
|
517
|
+
one. Keep the handler's rollover policy and process lock, while making
|
|
518
|
+
the formatter/write/flush/close result explicit.
|
|
519
|
+
"""
|
|
520
|
+
event_fields = getattr(record, "bugx_fields", {})
|
|
521
|
+
event_id = event_fields.get("event_id") if isinstance(event_fields, dict) else None
|
|
522
|
+
|
|
523
|
+
# Closing the previous descriptor while holding the process lock keeps
|
|
524
|
+
# another process from rotating a file that this process still has open.
|
|
525
|
+
if self.stream is not None:
|
|
526
|
+
previous_stream = self.stream
|
|
527
|
+
self.stream = None
|
|
528
|
+
previous_stream.close()
|
|
529
|
+
|
|
530
|
+
try:
|
|
531
|
+
if self.shouldRollover(record):
|
|
532
|
+
self.doRollover()
|
|
533
|
+
if self.stream is None:
|
|
534
|
+
self.stream = self._open()
|
|
535
|
+
rendered = self.format(record)
|
|
536
|
+
line = rendered + self.terminator
|
|
537
|
+
written = self.stream.write(line)
|
|
538
|
+
if written != len(line):
|
|
539
|
+
raise OSError("short JSONL write")
|
|
540
|
+
self.stream.flush()
|
|
541
|
+
return event_id if isinstance(event_id, str) and event_id else None
|
|
542
|
+
finally:
|
|
543
|
+
if self.stream is not None:
|
|
544
|
+
stream = self.stream
|
|
545
|
+
self.stream = None
|
|
546
|
+
stream.close()
|
|
547
|
+
|
|
548
|
+
def emit(self, record: logging.LogRecord) -> None:
|
|
549
|
+
# Handler.lock covers threads. The lock file also covers independent CLI,
|
|
550
|
+
# MCP, and worker processes sharing one project log during rollover.
|
|
551
|
+
# A successful acknowledgement is attached to this LogRecord only after
|
|
552
|
+
# the exact event_id has been formatted, written, flushed, and closed.
|
|
553
|
+
event_fields = getattr(record, "bugx_fields", {})
|
|
554
|
+
event_id = event_fields.get("event_id") if isinstance(event_fields, dict) else None
|
|
555
|
+
try:
|
|
556
|
+
with self._process_lock():
|
|
557
|
+
acknowledged_id = self._write_jsonl_record(record)
|
|
558
|
+
except Exception:
|
|
559
|
+
# Do not call logging.Handler.handleError here: it may print event
|
|
560
|
+
# contents or an I/O traceback to stderr. log_event observes the
|
|
561
|
+
# missing acknowledgement and returns False to its caller.
|
|
562
|
+
setattr(record, "_bugx_jsonl_error_event_id", event_id)
|
|
563
|
+
return
|
|
564
|
+
if isinstance(event_id, str) and acknowledged_id == event_id:
|
|
565
|
+
setattr(record, "_bugx_jsonl_ack_event_id", acknowledged_id)
|
|
566
|
+
else:
|
|
567
|
+
setattr(record, "_bugx_jsonl_error_event_id", event_id)
|
|
568
|
+
|
|
569
|
+
def close(self) -> None:
|
|
570
|
+
try:
|
|
571
|
+
self._bugx_lock_stream.close()
|
|
572
|
+
except AttributeError:
|
|
573
|
+
pass
|
|
574
|
+
super().close()
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def _is_within(candidate: Path, base: Path) -> bool:
|
|
578
|
+
"""Return whether ``candidate`` sits under ``base`` (real-path boundary)."""
|
|
579
|
+
try:
|
|
580
|
+
candidate.relative_to(base.resolve())
|
|
581
|
+
except ValueError:
|
|
582
|
+
return False
|
|
583
|
+
return True
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def close_handlers_for_root(root: Path) -> int:
|
|
587
|
+
"""Close the diagnostic handlers owned by ``root`` and return the count.
|
|
588
|
+
|
|
589
|
+
One root can own two locations: the project log under ``<root>/.bugx`` and
|
|
590
|
+
the per-user fallback used while the project is not initialized yet.
|
|
591
|
+
Callers that delete or replace either tree (install rollback, reset,
|
|
592
|
+
uninstall) must release these handles first: on Windows an open handle
|
|
593
|
+
makes ``unlink``/``rmtree`` fail with WinError 32, masking the real error.
|
|
594
|
+
POSIX is unaffected but closing early is harmless.
|
|
595
|
+
"""
|
|
596
|
+
resolved_root = Path(root).expanduser().resolve()
|
|
597
|
+
bases = (resolved_root / ".bugx", global_log_path(resolved_root).parent)
|
|
598
|
+
closed = 0
|
|
599
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
600
|
+
for handler in list(logger.handlers):
|
|
601
|
+
handler_path = getattr(handler, "_bugx_log_path", None)
|
|
602
|
+
if not handler_path:
|
|
603
|
+
continue
|
|
604
|
+
# 真实路径边界判断:字符串 startswith 会误命中 <root>/.bugx-evil 等同级前缀
|
|
605
|
+
candidate = Path(str(handler_path).replace("/", os.sep)).resolve()
|
|
606
|
+
if not any(_is_within(candidate, base) for base in bases):
|
|
607
|
+
continue
|
|
608
|
+
try:
|
|
609
|
+
handler.close()
|
|
610
|
+
except OSError:
|
|
611
|
+
pass
|
|
612
|
+
finally:
|
|
613
|
+
logger.removeHandler(handler)
|
|
614
|
+
closed += 1
|
|
615
|
+
return closed
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
@contextmanager
|
|
619
|
+
def isolated_logger_scope():
|
|
620
|
+
"""Preserve the embedding process's BugX logger for one serialized call.
|
|
621
|
+
|
|
622
|
+
``configure`` replaces the shared logger's context and closes old handlers.
|
|
623
|
+
Detach them before an in-process launcher invocation so its configuration
|
|
624
|
+
cannot close the host's files or send sandbox events to the host's log.
|
|
625
|
+
The caller must serialize calls that configure this process-global logger.
|
|
626
|
+
Nested scopes preserve the outer scope's handlers and context in the same
|
|
627
|
+
way. Handlers created in this scope are closed on every exit path, including
|
|
628
|
+
exporters which do not have a ``_bugx_log_path``. Scope-owned exports finish
|
|
629
|
+
synchronously, before the runtime scope restores cwd/environment; outside
|
|
630
|
+
this context the normal CLI exporter remains asynchronous.
|
|
631
|
+
"""
|
|
632
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
633
|
+
handlers = list(logger.handlers)
|
|
634
|
+
level, propagate, disabled = logger.level, logger.propagate, logger.disabled
|
|
635
|
+
missing = object()
|
|
636
|
+
context = getattr(logger, "_bugx_context", missing)
|
|
637
|
+
export_token = _SCOPED_SYNC_EXPORT.set(True)
|
|
638
|
+
try:
|
|
639
|
+
for handler in handlers:
|
|
640
|
+
logger.removeHandler(handler)
|
|
641
|
+
try:
|
|
642
|
+
yield logger
|
|
643
|
+
finally:
|
|
644
|
+
for handler in list(logger.handlers):
|
|
645
|
+
logger.removeHandler(handler)
|
|
646
|
+
if handler not in handlers:
|
|
647
|
+
try:
|
|
648
|
+
handler.close()
|
|
649
|
+
except OSError:
|
|
650
|
+
pass
|
|
651
|
+
for handler in handlers:
|
|
652
|
+
logger.addHandler(handler)
|
|
653
|
+
logger.setLevel(level)
|
|
654
|
+
logger.propagate = propagate
|
|
655
|
+
logger.disabled = disabled
|
|
656
|
+
if context is missing:
|
|
657
|
+
if hasattr(logger, "_bugx_context"):
|
|
658
|
+
delattr(logger, "_bugx_context")
|
|
659
|
+
else:
|
|
660
|
+
logger._bugx_context = context # type: ignore[attr-defined]
|
|
661
|
+
finally:
|
|
662
|
+
_SCOPED_SYNC_EXPORT.reset(export_token)
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
def _level(value: str | int | None) -> int:
|
|
666
|
+
if value is None:
|
|
667
|
+
value = os.environ.get("BUGX_LOG_LEVEL", "INFO")
|
|
668
|
+
if isinstance(value, int):
|
|
669
|
+
return value
|
|
670
|
+
normalized = str(value).upper()
|
|
671
|
+
# ``getLevelNamesMapping`` was added after the oldest Python runtime still
|
|
672
|
+
# used by existing BugX projects. Keep the logger usable on 3.9/3.10 so
|
|
673
|
+
# a compatibility issue cannot hide the actual pre/status failure.
|
|
674
|
+
mapping = getattr(logging, "getLevelNamesMapping", None)
|
|
675
|
+
level_map = mapping() if mapping is not None else {
|
|
676
|
+
name: number for name, number in logging._nameToLevel.items()
|
|
677
|
+
}
|
|
678
|
+
level = level_map.get(normalized)
|
|
679
|
+
if not isinstance(level, int):
|
|
680
|
+
raise ValueError(f"无效日志等级: {value!r}(可选 DEBUG/INFO/WARNING/ERROR)")
|
|
681
|
+
return level
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
def configure(root: Path, *, command: str | None = None,
|
|
685
|
+
level: str | int | None = None,
|
|
686
|
+
trace_id: str | None = None,
|
|
687
|
+
project_scoped: bool | None = None) -> logging.Logger:
|
|
688
|
+
"""Configure and return the BugX logger for one project root.
|
|
689
|
+
|
|
690
|
+
``project_scoped`` forces the log into ``<root>/.bugx/logs`` (``True``) or
|
|
691
|
+
into the per-user fallback (``False``). The default ``None`` decides by
|
|
692
|
+
project state alone — deliberately the same rule as :func:`log_path`, so a
|
|
693
|
+
reader can never look somewhere the writer did not write. A directory
|
|
694
|
+
without ``.bugx/manifest.json`` falls back, because logging is a side
|
|
695
|
+
effect of every command and must never be what creates ``<root>/.bugx``.
|
|
696
|
+
|
|
697
|
+
Consequence: the invocation that *creates* the project (``bugx init`` /
|
|
698
|
+
``bugx install``) still logs to the fallback, since the manifest does not
|
|
699
|
+
exist yet when logging is configured. The project log then starts with the
|
|
700
|
+
next command; ``bugx init`` itself creates ``.bugx/logs/`` via the layout
|
|
701
|
+
initializer, as documented in DOC-001 §5.8.
|
|
702
|
+
|
|
703
|
+
Repeated calls in one process reuse the same handler. A later call for a
|
|
704
|
+
different project replaces the old handler, which keeps test runs and
|
|
705
|
+
embedded CLI calls isolated.
|
|
706
|
+
"""
|
|
707
|
+
root = root.expanduser().resolve()
|
|
708
|
+
if root.exists() and not root.is_dir():
|
|
709
|
+
raise ValueError(f"日志项目根目录不是目录: {root}")
|
|
710
|
+
if project_scoped is None:
|
|
711
|
+
project_scoped = is_initialized_project(root)
|
|
712
|
+
if project_scoped:
|
|
713
|
+
# Only bootstrap commands (init/install) and already-initialized
|
|
714
|
+
# projects reach this branch: the project layout owns <root>/.bugx.
|
|
715
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
716
|
+
bugx_root = root / ".bugx"
|
|
717
|
+
path = _private_dir_chain(
|
|
718
|
+
bugx_root, bugx_root / LOG_DIR_NAME, label="",
|
|
719
|
+
) / LOG_FILE_NAME
|
|
720
|
+
else:
|
|
721
|
+
path = global_log_path(root)
|
|
722
|
+
_private_dir_chain(global_log_root(), path.parent, label="回退")
|
|
723
|
+
lock_path = Path(f"{path}.lock")
|
|
724
|
+
if path.is_symlink() or lock_path.is_symlink():
|
|
725
|
+
raise ValueError(f"拒绝使用符号链接诊断日志: {path}")
|
|
726
|
+
path.touch(mode=0o600, exist_ok=True)
|
|
727
|
+
os.chmod(path, 0o600)
|
|
728
|
+
|
|
729
|
+
logger = logging.getLogger(LOGGER_NAME)
|
|
730
|
+
logger.setLevel(_level(level))
|
|
731
|
+
logger.propagate = False
|
|
732
|
+
context = {"command": command or "unknown"}
|
|
733
|
+
for field, env_name in _CONTEXT_ENV.items():
|
|
734
|
+
value = os.environ.get(env_name)
|
|
735
|
+
if value:
|
|
736
|
+
context[field] = value
|
|
737
|
+
traceparent_env = os.environ.get("TRACEPARENT")
|
|
738
|
+
parsed_tp = parse_traceparent(traceparent_env)
|
|
739
|
+
if parsed_tp is not None and trace_id is None:
|
|
740
|
+
context["trace_id"] = parsed_tp["trace_id"]
|
|
741
|
+
context["parent_span_id"] = parsed_tp["parent_id"]
|
|
742
|
+
span_id = uuid.uuid4().hex[:16]
|
|
743
|
+
context["span_id"] = span_id
|
|
744
|
+
context["traceparent"] = f"00-{parsed_tp['trace_id']}-{span_id}-{parsed_tp['trace_flags']}"
|
|
745
|
+
else:
|
|
746
|
+
assigned_trace = (
|
|
747
|
+
trace_id if trace_id is not None
|
|
748
|
+
else context.get("trace_id") or uuid.uuid4().hex
|
|
749
|
+
)
|
|
750
|
+
context["trace_id"] = assigned_trace
|
|
751
|
+
span_id = uuid.uuid4().hex[:16]
|
|
752
|
+
context["span_id"] = span_id
|
|
753
|
+
clean_32 = assigned_trace.lower().replace("-", "").zfill(32)[-32:]
|
|
754
|
+
context["traceparent"] = f"00-{clean_32}-{span_id}-01"
|
|
755
|
+
logger._bugx_context = context # type: ignore[attr-defined]
|
|
756
|
+
resolved_path = str(path.resolve())
|
|
757
|
+
existing = next(
|
|
758
|
+
(handler for handler in logger.handlers
|
|
759
|
+
if getattr(handler, "_bugx_log_path", None) == resolved_path),
|
|
760
|
+
None,
|
|
761
|
+
)
|
|
762
|
+
if existing is None:
|
|
763
|
+
for handler in list(logger.handlers):
|
|
764
|
+
if getattr(handler, "_bugx_handler", False):
|
|
765
|
+
logger.removeHandler(handler)
|
|
766
|
+
handler.close()
|
|
767
|
+
handler = _SecureRotatingFileHandler(
|
|
768
|
+
path, maxBytes=MAX_BYTES, backupCount=BACKUP_COUNT,
|
|
769
|
+
encoding="utf-8", delay=True,
|
|
770
|
+
)
|
|
771
|
+
handler._bugx_handler = True # type: ignore[attr-defined]
|
|
772
|
+
handler._bugx_log_path = resolved_path # type: ignore[attr-defined]
|
|
773
|
+
handler.setFormatter(_JsonFormatter())
|
|
774
|
+
handler.setLevel(logging.DEBUG)
|
|
775
|
+
logger.addHandler(handler)
|
|
776
|
+
|
|
777
|
+
otlp_endpoint = os.environ.get("BUGX_OTLP_ENDPOINT")
|
|
778
|
+
if otlp_endpoint:
|
|
779
|
+
otlp_handler = _OtlpHttpHandler(otlp_endpoint.strip())
|
|
780
|
+
otlp_handler._bugx_handler = True # type: ignore[attr-defined]
|
|
781
|
+
logger.addHandler(otlp_handler)
|
|
782
|
+
|
|
783
|
+
log_event(
|
|
784
|
+
logger, "logger_configured", "BugX 诊断日志已启用",
|
|
785
|
+
command=command or "unknown", log_file=str(path),
|
|
786
|
+
)
|
|
787
|
+
return logger
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def _correlation_ids() -> dict[str, Any]:
|
|
791
|
+
"""DOC-204 L2:关联 ID 注入(runtime.json 权威值优先)。
|
|
792
|
+
|
|
793
|
+
env(BUGX_RUN_ID 等)与 runtime 不一致 → 丢弃 env 值并记
|
|
794
|
+
log_correlation_mismatch(嫁接尝试成为可检安全信号);runtime 不可读
|
|
795
|
+
时 env 缺失省略(不伪造)。
|
|
796
|
+
"""
|
|
797
|
+
ids: dict[str, Any] = {}
|
|
798
|
+
data: dict[str, Any] | None = None
|
|
799
|
+
# 会话 runtime 的真实位置由 .bugx/current.json(bugx_paths 布局)指向;
|
|
800
|
+
# 读不到时按 cwd 相对 bugx-runtime.json 回退(独立协议测试布局)。
|
|
801
|
+
for cand in (Path(".bugx/current.json"), Path("bugx-runtime.json")):
|
|
802
|
+
try:
|
|
803
|
+
data = json.loads(cand.read_text(encoding="utf-8"))
|
|
804
|
+
break
|
|
805
|
+
except Exception:
|
|
806
|
+
continue
|
|
807
|
+
if isinstance(data, dict) and "lifecycle_id" in data and "run_id" not in data:
|
|
808
|
+
# current.json 只有 polling/lifecycle 指针——顺着找 lifecycle runtime
|
|
809
|
+
try:
|
|
810
|
+
life_rt = (
|
|
811
|
+
Path(".bugx/pollings") / str(data.get("polling_id") or "polling-unknown")
|
|
812
|
+
/ "lifecycles" / str(data.get("lifecycle_id") or "unknown")
|
|
813
|
+
/ "state" / "runtime.json"
|
|
814
|
+
)
|
|
815
|
+
merged = json.loads(life_rt.read_text(encoding="utf-8"))
|
|
816
|
+
merged.setdefault("polling_id", data.get("polling_id"))
|
|
817
|
+
merged.setdefault("lifecycle_id", data.get("lifecycle_id"))
|
|
818
|
+
data = merged
|
|
819
|
+
except Exception:
|
|
820
|
+
pass
|
|
821
|
+
env_map = {
|
|
822
|
+
"run_id": "BUGX_RUN_ID", "lifecycle_id": "BUGX_LIFECYCLE_ID",
|
|
823
|
+
"round": "BUGX_ROUND",
|
|
824
|
+
}
|
|
825
|
+
for field, env_name in env_map.items():
|
|
826
|
+
env_val = os.environ.get(env_name)
|
|
827
|
+
rt_val = (data or {}).get(field if field != "round" else "round")
|
|
828
|
+
if data is not None and rt_val is not None:
|
|
829
|
+
ids[field] = rt_val
|
|
830
|
+
elif env_val:
|
|
831
|
+
ids[field] = env_val
|
|
832
|
+
return ids
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
def log_event(logger: logging.Logger, event: str, message: str = "", *,
|
|
836
|
+
level: int = logging.INFO, exc_info: Any = None,
|
|
837
|
+
**fields: Any) -> bool:
|
|
838
|
+
"""Write one structured event and report local JSONL flush success.
|
|
839
|
+
|
|
840
|
+
``True`` means the configured local JSONL handler acknowledged this exact
|
|
841
|
+
event ID after formatter, write, flush, and close succeeded. Logger/handler
|
|
842
|
+
level filters, a missing local JSONL handler, or any local I/O failure return
|
|
843
|
+
``False``. Other handlers such as asynchronous OTLP do not affect this ack.
|
|
844
|
+
"""
|
|
845
|
+
context = dict(getattr(logger, "_bugx_context", {}))
|
|
846
|
+
# DOC-204 L2:关联 ID 注入(runtime 权威值优先;缺失省略不伪造)。
|
|
847
|
+
# 节流:_correlation_ids 的文件读取每次调用有开销,按 pid 缓存 60s。
|
|
848
|
+
global _CORRELATION_CACHE
|
|
849
|
+
now_mono = time.monotonic()
|
|
850
|
+
cached = _CORRELATION_CACHE.get("v")
|
|
851
|
+
if cached is None or now_mono - cached[0] > 60.0:
|
|
852
|
+
try:
|
|
853
|
+
cached = (now_mono, _correlation_ids())
|
|
854
|
+
except Exception:
|
|
855
|
+
cached = (now_mono, {})
|
|
856
|
+
_CORRELATION_CACHE["v"] = cached
|
|
857
|
+
for cid_key, cid_val in cached[1].items():
|
|
858
|
+
context.setdefault(cid_key, cid_val)
|
|
859
|
+
context.update(fields)
|
|
860
|
+
event_id = uuid.uuid4().hex
|
|
861
|
+
context["event_id"] = event_id
|
|
862
|
+
|
|
863
|
+
if logger.disabled or not logger.isEnabledFor(level):
|
|
864
|
+
return False
|
|
865
|
+
record_exc_info = exc_info
|
|
866
|
+
if not isinstance(record_exc_info, tuple):
|
|
867
|
+
record_exc_info = sys.exc_info() if record_exc_info else None
|
|
868
|
+
try:
|
|
869
|
+
pathname, lineno, function, _ = logger.findCaller(stack_info=False, stacklevel=2)
|
|
870
|
+
record = logger.makeRecord(
|
|
871
|
+
logger.name, level, pathname, lineno, message or event, (), record_exc_info,
|
|
872
|
+
function, extra={"bugx_event": event, "bugx_fields": context},
|
|
873
|
+
)
|
|
874
|
+
logger.handle(record)
|
|
875
|
+
except Exception:
|
|
876
|
+
# A non-JSONL observer must not turn an already-flushed local event into
|
|
877
|
+
# a false negative ack. If dispatch failed before a local ack, the event
|
|
878
|
+
# remains unavailable.
|
|
879
|
+
return (
|
|
880
|
+
getattr(locals().get("record"), "_bugx_jsonl_ack_event_id", None)
|
|
881
|
+
== event_id
|
|
882
|
+
)
|
|
883
|
+
return getattr(record, "_bugx_jsonl_ack_event_id", None) == event_id
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def log_phase(logger: logging.Logger, phase: str, *,
|
|
887
|
+
status: str = "ok", duration_seconds: float = 0.0,
|
|
888
|
+
tokens_consumed: int | None = None,
|
|
889
|
+
decision_reason: str = "", **fields: Any) -> None:
|
|
890
|
+
"""Log a named execution phase with elapsed duration, tokens consumed, and decision reason.
|
|
891
|
+
|
|
892
|
+
``phase`` is used for grouping and searching (e.g. "tools_kb", "pre_check",
|
|
893
|
+
"worker_execution", "settlement"). ``duration_seconds`` represents elapsed wall time.
|
|
894
|
+
``tokens_consumed`` represents model tokens used in this phase if available.
|
|
895
|
+
"""
|
|
896
|
+
if duration_seconds < 0:
|
|
897
|
+
duration_seconds = 0.0
|
|
898
|
+
tok_str = f" tokens={tokens_consumed}" if tokens_consumed is not None else ""
|
|
899
|
+
log_fields = dict(fields)
|
|
900
|
+
if tokens_consumed is not None:
|
|
901
|
+
log_fields["tokens_consumed"] = tokens_consumed
|
|
902
|
+
level = logging.ERROR if status == "failed" else logging.INFO
|
|
903
|
+
log_event(logger, f"phase.{phase}.finished",
|
|
904
|
+
f"phase={phase} duration={duration_seconds:.3f}s{tok_str} status={status}",
|
|
905
|
+
level=level,
|
|
906
|
+
phase=phase, status=status,
|
|
907
|
+
duration_seconds=round(duration_seconds, 3),
|
|
908
|
+
decision_reason=decision_reason,
|
|
909
|
+
**log_fields)
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
class TokenPhaseTracker:
|
|
913
|
+
"""阶段 Token 累计器,支持多分类记录与归因分析 (DOC-042)。"""
|
|
914
|
+
|
|
915
|
+
def __init__(self, phase: str, budget: int | None = None):
|
|
916
|
+
self.phase = phase
|
|
917
|
+
self.budget = budget
|
|
918
|
+
self._tokens_by_category: dict[str, int] = {}
|
|
919
|
+
self.status: str = "ok"
|
|
920
|
+
self.decision_reason: str = ""
|
|
921
|
+
self.error: str = ""
|
|
922
|
+
|
|
923
|
+
def mark_failed(self, reason: str = "", error: str = "") -> None:
|
|
924
|
+
"""标记该阶段执行失败并记录原因。"""
|
|
925
|
+
self.status = "failed"
|
|
926
|
+
if reason:
|
|
927
|
+
self.decision_reason = reason
|
|
928
|
+
if error or reason:
|
|
929
|
+
self.error = error or reason
|
|
930
|
+
|
|
931
|
+
def set_decision(self, reason: str) -> None:
|
|
932
|
+
"""记录阶段决策原因。"""
|
|
933
|
+
self.decision_reason = reason
|
|
934
|
+
|
|
935
|
+
def record(self, count: int, category: str = "other") -> None:
|
|
936
|
+
"""记录指定分类的 token 消耗。"""
|
|
937
|
+
if not isinstance(count, int) or isinstance(count, bool) or count < 0:
|
|
938
|
+
return
|
|
939
|
+
cat = str(category).strip().lower() or "other"
|
|
940
|
+
self._tokens_by_category[cat] = self._tokens_by_category.get(cat, 0) + count
|
|
941
|
+
|
|
942
|
+
@property
|
|
943
|
+
def total_tokens(self) -> int:
|
|
944
|
+
"""返回阶段累计消耗的总 Token 数。"""
|
|
945
|
+
return sum(self._tokens_by_category.values())
|
|
946
|
+
|
|
947
|
+
@property
|
|
948
|
+
def breakdown(self) -> dict[str, int]:
|
|
949
|
+
"""返回各分类的 Token 归因字典。"""
|
|
950
|
+
return dict(self._tokens_by_category)
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
@contextmanager
|
|
954
|
+
def metered_phase(logger: logging.Logger | None, phase: str, *,
|
|
955
|
+
token_budget: int | None = None,
|
|
956
|
+
slow_threshold_seconds: float | None = None,
|
|
957
|
+
decision_reason: str = "", **fields: Any):
|
|
958
|
+
"""Context manager to measure phase duration and token consumption.
|
|
959
|
+
|
|
960
|
+
Yields a TokenPhaseTracker to record token usage within the phase.
|
|
961
|
+
Triggers slow_operation_warning and token_anomaly_warning when thresholds are exceeded.
|
|
962
|
+
"""
|
|
963
|
+
tracker = TokenPhaseTracker(phase=phase, budget=token_budget)
|
|
964
|
+
if decision_reason:
|
|
965
|
+
tracker.set_decision(decision_reason)
|
|
966
|
+
if logger is None:
|
|
967
|
+
yield tracker
|
|
968
|
+
return
|
|
969
|
+
|
|
970
|
+
started = time.monotonic()
|
|
971
|
+
status = "ok"
|
|
972
|
+
error_msg = ""
|
|
973
|
+
try:
|
|
974
|
+
yield tracker
|
|
975
|
+
except Exception as exc:
|
|
976
|
+
status = "failed"
|
|
977
|
+
error_msg = str(exc)
|
|
978
|
+
raise
|
|
979
|
+
finally:
|
|
980
|
+
duration = max(0.0, time.monotonic() - started)
|
|
981
|
+
tokens = tracker.total_tokens
|
|
982
|
+
log_fields = dict(fields)
|
|
983
|
+
if tracker.status != "ok":
|
|
984
|
+
status = tracker.status
|
|
985
|
+
if tracker.decision_reason:
|
|
986
|
+
decision_reason = tracker.decision_reason
|
|
987
|
+
if tracker.error:
|
|
988
|
+
error_msg = tracker.error
|
|
989
|
+
if error_msg:
|
|
990
|
+
log_fields["error"] = error_msg
|
|
991
|
+
|
|
992
|
+
# 计算 Token 预算
|
|
993
|
+
budget = token_budget
|
|
994
|
+
if budget is None:
|
|
995
|
+
env_budget = os.environ.get(f"BUGX_TOKEN_BUDGET_{phase.upper()}")
|
|
996
|
+
if env_budget:
|
|
997
|
+
try:
|
|
998
|
+
budget = int(env_budget)
|
|
999
|
+
except ValueError:
|
|
1000
|
+
budget = None
|
|
1001
|
+
if budget is not None:
|
|
1002
|
+
log_fields["token_budget"] = budget
|
|
1003
|
+
if tracker.breakdown:
|
|
1004
|
+
log_fields["token_breakdown"] = tracker.breakdown
|
|
1005
|
+
|
|
1006
|
+
log_phase(
|
|
1007
|
+
logger, phase, status=status, duration_seconds=duration,
|
|
1008
|
+
tokens_consumed=tokens if tokens > 0 else None,
|
|
1009
|
+
decision_reason=decision_reason, **log_fields,
|
|
1010
|
+
)
|
|
1011
|
+
|
|
1012
|
+
# 慢耗时检测
|
|
1013
|
+
threshold = slow_threshold_seconds
|
|
1014
|
+
if threshold is None:
|
|
1015
|
+
env_thresh = os.environ.get("BUGX_SLOW_THRESHOLD_SECONDS")
|
|
1016
|
+
if env_thresh:
|
|
1017
|
+
try:
|
|
1018
|
+
threshold = float(env_thresh)
|
|
1019
|
+
except ValueError:
|
|
1020
|
+
threshold = DEFAULT_SLOW_THRESHOLD_SECONDS
|
|
1021
|
+
else:
|
|
1022
|
+
threshold = DEFAULT_SLOW_THRESHOLD_SECONDS
|
|
1023
|
+
if threshold > 0 and duration >= threshold:
|
|
1024
|
+
log_event(
|
|
1025
|
+
logger, "slow_operation_warning",
|
|
1026
|
+
f"阶段 {phase} 执行耗时 ({duration:.2f}s) 超过阈值 ({threshold:.2f}s)",
|
|
1027
|
+
level=logging.WARNING,
|
|
1028
|
+
phase=phase,
|
|
1029
|
+
duration_seconds=round(duration, 3),
|
|
1030
|
+
threshold_seconds=round(threshold, 3),
|
|
1031
|
+
status=status,
|
|
1032
|
+
**fields,
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
# 异常 Token 消耗检测
|
|
1036
|
+
if budget is not None and budget > 0 and tokens > budget:
|
|
1037
|
+
diff = tokens - budget
|
|
1038
|
+
log_event(
|
|
1039
|
+
logger, "token_anomaly_warning",
|
|
1040
|
+
f"阶段 {phase} 消耗 {tokens} tokens,超出预算 {budget}(超标 +{diff})",
|
|
1041
|
+
level=logging.WARNING,
|
|
1042
|
+
phase=phase,
|
|
1043
|
+
actual_tokens=tokens,
|
|
1044
|
+
budget_tokens=budget,
|
|
1045
|
+
diff_tokens=diff,
|
|
1046
|
+
token_breakdown=tracker.breakdown,
|
|
1047
|
+
status=status,
|
|
1048
|
+
**fields,
|
|
1049
|
+
)
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
@contextmanager
|
|
1053
|
+
def timed_phase(logger: logging.Logger | None, phase: str, *,
|
|
1054
|
+
token_budget: int | None = None,
|
|
1055
|
+
slow_threshold_seconds: float | None = None,
|
|
1056
|
+
decision_reason: str = "", **fields: Any):
|
|
1057
|
+
"""Context manager to measure phase duration and tokens (wraps metered_phase)."""
|
|
1058
|
+
with metered_phase(
|
|
1059
|
+
logger, phase, token_budget=token_budget, slow_threshold_seconds=slow_threshold_seconds,
|
|
1060
|
+
decision_reason=decision_reason, **fields,
|
|
1061
|
+
) as tracker:
|
|
1062
|
+
yield tracker
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
def log_dialogue(
|
|
1066
|
+
logger: logging.Logger | None,
|
|
1067
|
+
role: str,
|
|
1068
|
+
content: str,
|
|
1069
|
+
*,
|
|
1070
|
+
interaction_type: str = "chat",
|
|
1071
|
+
options: list[Any] | None = None,
|
|
1072
|
+
selected: Any = None,
|
|
1073
|
+
tokens: int | None = None,
|
|
1074
|
+
turn_id: int | None = None,
|
|
1075
|
+
**fields: Any,
|
|
1076
|
+
) -> None:
|
|
1077
|
+
"""记录人机交互与对话消息(自动脱敏与文本有界预算)。
|
|
1078
|
+
|
|
1079
|
+
用于记录用户输入、Agent 响应、门禁单选等交互,帮助复盘时对齐人类意图与 Agent 行为。
|
|
1080
|
+
"""
|
|
1081
|
+
if logger is None:
|
|
1082
|
+
return
|
|
1083
|
+
clean_content = str(content).strip()
|
|
1084
|
+
if len(clean_content) > 1000:
|
|
1085
|
+
clean_content = clean_content[:997] + "..."
|
|
1086
|
+
log_fields = dict(fields)
|
|
1087
|
+
log_fields.update({
|
|
1088
|
+
"role": role,
|
|
1089
|
+
"content_summary": clean_content,
|
|
1090
|
+
"interaction_type": interaction_type,
|
|
1091
|
+
})
|
|
1092
|
+
if options is not None:
|
|
1093
|
+
log_fields["options"] = [safe_value(opt) for opt in options]
|
|
1094
|
+
if selected is not None:
|
|
1095
|
+
log_fields["selected"] = safe_value(selected)
|
|
1096
|
+
if tokens is not None:
|
|
1097
|
+
log_fields["tokens"] = tokens
|
|
1098
|
+
if turn_id is not None:
|
|
1099
|
+
log_fields["turn_id"] = turn_id
|
|
1100
|
+
|
|
1101
|
+
log_event(
|
|
1102
|
+
logger,
|
|
1103
|
+
"dialogue_message",
|
|
1104
|
+
f"[{role.upper()}] ({interaction_type}) {clean_content[:120]}",
|
|
1105
|
+
level=logging.INFO,
|
|
1106
|
+
**log_fields,
|
|
1107
|
+
)
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
@contextmanager
|
|
1111
|
+
def metered_step(
|
|
1112
|
+
logger: logging.Logger | None,
|
|
1113
|
+
step_name: str,
|
|
1114
|
+
*,
|
|
1115
|
+
tool_name: str = "bash",
|
|
1116
|
+
tool_input: Any = None,
|
|
1117
|
+
step_index: int | None = None,
|
|
1118
|
+
slow_threshold_seconds: float = 5.0,
|
|
1119
|
+
**fields: Any,
|
|
1120
|
+
):
|
|
1121
|
+
"""用于追踪具体操作步骤(Bash 执行、工具调用、命令操作)的上下文管理器。
|
|
1122
|
+
|
|
1123
|
+
进入时记录 step_started,退出时记录 step_finished(含毫秒级耗时与状态),
|
|
1124
|
+
若耗时超出阈值则发出 slow_command_warning。
|
|
1125
|
+
"""
|
|
1126
|
+
if logger is None:
|
|
1127
|
+
yield
|
|
1128
|
+
return
|
|
1129
|
+
|
|
1130
|
+
started = time.monotonic()
|
|
1131
|
+
status = "ok"
|
|
1132
|
+
error_msg = ""
|
|
1133
|
+
exit_code: int | None = 0
|
|
1134
|
+
safe_input = safe_value(tool_input)
|
|
1135
|
+
if isinstance(safe_input, str) and len(safe_input) > 500:
|
|
1136
|
+
safe_input = safe_input[:497] + "..."
|
|
1137
|
+
|
|
1138
|
+
start_fields = dict(fields)
|
|
1139
|
+
start_fields.update({
|
|
1140
|
+
"step_name": step_name,
|
|
1141
|
+
"tool_name": tool_name,
|
|
1142
|
+
"tool_input": safe_input,
|
|
1143
|
+
})
|
|
1144
|
+
if step_index is not None:
|
|
1145
|
+
start_fields["step_index"] = step_index
|
|
1146
|
+
|
|
1147
|
+
log_event(
|
|
1148
|
+
logger,
|
|
1149
|
+
"step_started",
|
|
1150
|
+
f"开始执行步骤 [{step_name}] ({tool_name})",
|
|
1151
|
+
level=logging.INFO,
|
|
1152
|
+
**start_fields,
|
|
1153
|
+
)
|
|
1154
|
+
|
|
1155
|
+
try:
|
|
1156
|
+
yield
|
|
1157
|
+
except Exception as exc:
|
|
1158
|
+
status = "failed"
|
|
1159
|
+
error_msg = str(exc)
|
|
1160
|
+
exit_code = getattr(exc, "exit_code", getattr(exc, "returncode", 1))
|
|
1161
|
+
raise
|
|
1162
|
+
finally:
|
|
1163
|
+
duration = max(0.0, time.monotonic() - started)
|
|
1164
|
+
duration_ms = round(duration * 1000.0, 2)
|
|
1165
|
+
end_fields = dict(fields)
|
|
1166
|
+
end_fields.update({
|
|
1167
|
+
"step_name": step_name,
|
|
1168
|
+
"tool_name": tool_name,
|
|
1169
|
+
"duration_ms": duration_ms,
|
|
1170
|
+
"duration_seconds": round(duration, 3),
|
|
1171
|
+
"status": status,
|
|
1172
|
+
})
|
|
1173
|
+
if step_index is not None:
|
|
1174
|
+
end_fields["step_index"] = step_index
|
|
1175
|
+
if exit_code is not None:
|
|
1176
|
+
end_fields["exit_code"] = exit_code
|
|
1177
|
+
if error_msg:
|
|
1178
|
+
end_fields["error"] = error_msg
|
|
1179
|
+
|
|
1180
|
+
log_event(
|
|
1181
|
+
logger,
|
|
1182
|
+
"step_finished",
|
|
1183
|
+
f"步骤 [{step_name}] 完成 ({tool_name}, {duration_ms}ms, status={status})",
|
|
1184
|
+
level=logging.INFO if status == "ok" else logging.WARNING,
|
|
1185
|
+
**end_fields,
|
|
1186
|
+
)
|
|
1187
|
+
|
|
1188
|
+
if duration >= slow_threshold_seconds:
|
|
1189
|
+
log_event(
|
|
1190
|
+
logger,
|
|
1191
|
+
"slow_command_warning",
|
|
1192
|
+
f"步骤 [{step_name}] ({tool_name}) 执行耗时 ({duration:.2f}s) 超过阈值 ({slow_threshold_seconds:.2f}s)",
|
|
1193
|
+
level=logging.WARNING,
|
|
1194
|
+
step_name=step_name,
|
|
1195
|
+
tool_name=tool_name,
|
|
1196
|
+
tool_input=safe_input,
|
|
1197
|
+
duration_seconds=round(duration, 3),
|
|
1198
|
+
threshold_seconds=slow_threshold_seconds,
|
|
1199
|
+
**fields,
|
|
1200
|
+
)
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
@contextmanager
|
|
1204
|
+
def metered_gate(
|
|
1205
|
+
logger: logging.Logger | None,
|
|
1206
|
+
gate_name: str,
|
|
1207
|
+
*,
|
|
1208
|
+
phase: str = "environment",
|
|
1209
|
+
slow_threshold_seconds: float = 2.0,
|
|
1210
|
+
**fields: Any,
|
|
1211
|
+
):
|
|
1212
|
+
"""用于追踪启动门禁与策略校验子阶段的上下文管理器。
|
|
1213
|
+
|
|
1214
|
+
记录 gate_started 与 gate_finished,精准计算各门禁耗时毫秒数。
|
|
1215
|
+
"""
|
|
1216
|
+
if logger is None:
|
|
1217
|
+
yield
|
|
1218
|
+
return
|
|
1219
|
+
|
|
1220
|
+
started = time.monotonic()
|
|
1221
|
+
status = "ok"
|
|
1222
|
+
error_msg = ""
|
|
1223
|
+
gate_fields = dict(fields)
|
|
1224
|
+
gate_fields.update({"gate_name": gate_name, "phase": phase})
|
|
1225
|
+
|
|
1226
|
+
log_event(
|
|
1227
|
+
logger,
|
|
1228
|
+
"gate_started",
|
|
1229
|
+
f"开始评估门禁 [{gate_name}]",
|
|
1230
|
+
level=logging.INFO,
|
|
1231
|
+
**gate_fields,
|
|
1232
|
+
)
|
|
1233
|
+
|
|
1234
|
+
try:
|
|
1235
|
+
yield
|
|
1236
|
+
except Exception as exc:
|
|
1237
|
+
status = "blocked"
|
|
1238
|
+
error_msg = str(exc)
|
|
1239
|
+
raise
|
|
1240
|
+
finally:
|
|
1241
|
+
duration = max(0.0, time.monotonic() - started)
|
|
1242
|
+
duration_ms = round(duration * 1000.0, 2)
|
|
1243
|
+
finish_fields = dict(gate_fields)
|
|
1244
|
+
finish_fields.update({
|
|
1245
|
+
"duration_ms": duration_ms,
|
|
1246
|
+
"duration_seconds": round(duration, 3),
|
|
1247
|
+
"status": status,
|
|
1248
|
+
})
|
|
1249
|
+
if error_msg:
|
|
1250
|
+
finish_fields["error"] = error_msg
|
|
1251
|
+
|
|
1252
|
+
log_event(
|
|
1253
|
+
logger,
|
|
1254
|
+
"gate_finished",
|
|
1255
|
+
f"门禁 [{gate_name}] 评估完成 ({duration_ms}ms, status={status})",
|
|
1256
|
+
level=logging.INFO if status == "ok" else logging.WARNING,
|
|
1257
|
+
**finish_fields,
|
|
1258
|
+
)
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
def compact_output(
|
|
1262
|
+
text: str,
|
|
1263
|
+
*,
|
|
1264
|
+
max_chars: int = 2000,
|
|
1265
|
+
max_lines: int = 40,
|
|
1266
|
+
head_lines: int = 15,
|
|
1267
|
+
tail_lines: int = 10,
|
|
1268
|
+
persisted_log_path: Path | str | None = None,
|
|
1269
|
+
) -> str:
|
|
1270
|
+
"""输出刚性脱水截断,防止巨幅命令日志灌入宿主大模型导致注意力膨胀与极慢推理 (DOC-170)。
|
|
1271
|
+
|
|
1272
|
+
若文本行数与字符数均未超限,原样返回。
|
|
1273
|
+
若超限,提取「头部 N 行 + 中间包含错误/异常的关键行 + 尾部 M 行」,并标明截断行数与全量落盘路径。
|
|
1274
|
+
"""
|
|
1275
|
+
if not text:
|
|
1276
|
+
return ""
|
|
1277
|
+
lines = text.splitlines()
|
|
1278
|
+
if len(lines) <= max_lines and len(text) <= max_chars:
|
|
1279
|
+
return text
|
|
1280
|
+
|
|
1281
|
+
head = lines[:head_lines]
|
|
1282
|
+
tail = lines[-tail_lines:] if len(lines) > head_lines + tail_lines else []
|
|
1283
|
+
middle_pool = lines[head_lines:-tail_lines] if tail else []
|
|
1284
|
+
|
|
1285
|
+
# 智能提取中间的错误关键词行(最多 10 行)
|
|
1286
|
+
error_keywords = ("error", "fail", "warn", "exception", "traceback", "blocked", "fatal", "denied", "timeout")
|
|
1287
|
+
matched_middle: list[str] = []
|
|
1288
|
+
for line in middle_pool:
|
|
1289
|
+
lower = line.lower()
|
|
1290
|
+
if any(kw in lower for kw in error_keywords):
|
|
1291
|
+
matched_middle.append(f" [!] {line}")
|
|
1292
|
+
if len(matched_middle) >= 10:
|
|
1293
|
+
break
|
|
1294
|
+
|
|
1295
|
+
truncated_count = len(lines) - len(head) - len(tail)
|
|
1296
|
+
link_info = f",全量日志已保存至: {persisted_log_path}" if persisted_log_path else ""
|
|
1297
|
+
summary_banner = [
|
|
1298
|
+
f"... [已截断 {truncated_count} 行冗余输出以防止上下文膨胀{link_info}] ..."
|
|
1299
|
+
]
|
|
1300
|
+
|
|
1301
|
+
parts = list(head)
|
|
1302
|
+
if matched_middle:
|
|
1303
|
+
parts.append("--- [关键错误行摘要提取] ---")
|
|
1304
|
+
parts.extend(matched_middle)
|
|
1305
|
+
parts.append("----------------------------")
|
|
1306
|
+
parts.extend(summary_banner)
|
|
1307
|
+
parts.extend(tail)
|
|
1308
|
+
|
|
1309
|
+
result = "\n".join(parts)
|
|
1310
|
+
if len(result) > max_chars:
|
|
1311
|
+
result = result[:max_chars] + f"\n... [文本超出 {max_chars} 字符已切除] ..."
|
|
1312
|
+
return result
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
def get_context(logger: logging.Logger) -> dict[str, Any]:
|
|
1316
|
+
"""Return the current invocation context for child-process propagation."""
|
|
1317
|
+
return dict(getattr(logger, "_bugx_context", {}))
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
def request_context(logger: logging.Logger, request_id: object | None = None) -> dict[str, Any]:
|
|
1321
|
+
"""Create a fresh span context for one inbound request.
|
|
1322
|
+
|
|
1323
|
+
The configured logger span identifies the process; request spans must be
|
|
1324
|
+
unique so records from two MCP requests cannot be mistaken for one span.
|
|
1325
|
+
"""
|
|
1326
|
+
context = get_context(logger)
|
|
1327
|
+
parent_span_id = str(context.get("span_id") or uuid.uuid4().hex[:16])
|
|
1328
|
+
span_id = uuid.uuid4().hex[:16]
|
|
1329
|
+
trace_id = str(context.get("trace_id") or uuid.uuid4().hex)
|
|
1330
|
+
return {
|
|
1331
|
+
"request_id": request_id if request_id is not None else uuid.uuid4().hex,
|
|
1332
|
+
"parent_span_id": parent_span_id,
|
|
1333
|
+
"span_id": span_id,
|
|
1334
|
+
"traceparent": generate_traceparent(trace_id, span_id),
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
class McpRequestBatch:
|
|
1339
|
+
"""Aggregate contiguous low-value MCP request completions.
|
|
1340
|
+
|
|
1341
|
+
This is deliberately a logging-only guard: every request still gets a
|
|
1342
|
+
response, but repetitive idempotent reads do not consume one JSONL record
|
|
1343
|
+
each. The first/last request identities and latency totals keep the
|
|
1344
|
+
aggregate useful for diagnosing a polling client.
|
|
1345
|
+
"""
|
|
1346
|
+
|
|
1347
|
+
def __init__(self, method: str) -> None:
|
|
1348
|
+
self.method = method
|
|
1349
|
+
self._reset()
|
|
1350
|
+
|
|
1351
|
+
def _reset(self) -> None:
|
|
1352
|
+
self._count = 0
|
|
1353
|
+
self._first: dict[str, Any] = {}
|
|
1354
|
+
self._last: dict[str, Any] = {}
|
|
1355
|
+
self._first_seen = 0.0
|
|
1356
|
+
self._last_seen = 0.0
|
|
1357
|
+
self._first_monotonic = 0.0
|
|
1358
|
+
self._last_monotonic = 0.0
|
|
1359
|
+
self._intervals_ms: list[float] = []
|
|
1360
|
+
self._duration_total = 0.0
|
|
1361
|
+
self._duration_max = 0.0
|
|
1362
|
+
self._counters: dict[str, int] = {}
|
|
1363
|
+
|
|
1364
|
+
@property
|
|
1365
|
+
def count(self) -> int:
|
|
1366
|
+
return self._count
|
|
1367
|
+
|
|
1368
|
+
def record(self, fields: dict[str, Any], *, duration_ms: float,
|
|
1369
|
+
counters: dict[str, int] | None = None) -> None:
|
|
1370
|
+
now = time.time()
|
|
1371
|
+
if self._count == 0:
|
|
1372
|
+
self._first = dict(fields)
|
|
1373
|
+
self._first_seen = now
|
|
1374
|
+
self._first_monotonic = time.monotonic()
|
|
1375
|
+
self._last_monotonic = self._first_monotonic
|
|
1376
|
+
else:
|
|
1377
|
+
current_monotonic = time.monotonic()
|
|
1378
|
+
self._intervals_ms.append(
|
|
1379
|
+
max(0.0, current_monotonic - self._last_monotonic) * 1000
|
|
1380
|
+
)
|
|
1381
|
+
self._last_monotonic = current_monotonic
|
|
1382
|
+
self._last = dict(fields)
|
|
1383
|
+
self._last_seen = now
|
|
1384
|
+
self._count += 1
|
|
1385
|
+
self._duration_total += max(0.0, float(duration_ms))
|
|
1386
|
+
self._duration_max = max(self._duration_max, float(duration_ms))
|
|
1387
|
+
for key, value in (counters or {}).items():
|
|
1388
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
1389
|
+
self._counters[key] = self._counters.get(key, 0) + value
|
|
1390
|
+
|
|
1391
|
+
def due(self, *, max_count: int = 128,
|
|
1392
|
+
max_elapsed_seconds: float = 30.0) -> bool:
|
|
1393
|
+
"""Bound an open batch so a polling-only connection stays observable."""
|
|
1394
|
+
if self._count == 0:
|
|
1395
|
+
return False
|
|
1396
|
+
return (
|
|
1397
|
+
self._count >= max_count
|
|
1398
|
+
or time.monotonic() - self._first_monotonic >= max_elapsed_seconds
|
|
1399
|
+
)
|
|
1400
|
+
|
|
1401
|
+
def flush(self, logger: logging.Logger, **fields: Any) -> bool:
|
|
1402
|
+
"""Write one summary for the pending batch and clear it."""
|
|
1403
|
+
if self._count == 0:
|
|
1404
|
+
return False
|
|
1405
|
+
payload: dict[str, Any] = {
|
|
1406
|
+
"method": self.method,
|
|
1407
|
+
"request_count": self._count,
|
|
1408
|
+
"first_request_id": self._first.get("request_id"),
|
|
1409
|
+
"last_request_id": self._last.get("request_id"),
|
|
1410
|
+
"first_span_id": self._first.get("span_id"),
|
|
1411
|
+
"last_span_id": self._last.get("span_id"),
|
|
1412
|
+
"first_seen_at": self._first_seen,
|
|
1413
|
+
"last_seen_at": self._last_seen,
|
|
1414
|
+
"elapsed_ms": round(max(0.0, self._last_seen - self._first_seen) * 1000, 2),
|
|
1415
|
+
"duration_ms_total": round(self._duration_total, 2),
|
|
1416
|
+
"duration_ms_max": round(self._duration_max, 2),
|
|
1417
|
+
"duration_ms_avg": round(self._duration_total / self._count, 2),
|
|
1418
|
+
**self._counters,
|
|
1419
|
+
**fields,
|
|
1420
|
+
}
|
|
1421
|
+
if self._intervals_ms:
|
|
1422
|
+
payload.update({
|
|
1423
|
+
"interval_count": len(self._intervals_ms),
|
|
1424
|
+
"interval_ms_min": round(min(self._intervals_ms), 2),
|
|
1425
|
+
"interval_ms_max": round(max(self._intervals_ms), 2),
|
|
1426
|
+
"interval_ms_avg": round(
|
|
1427
|
+
sum(self._intervals_ms) / len(self._intervals_ms), 2,
|
|
1428
|
+
),
|
|
1429
|
+
"interval_ms_p50": round(statistics.median(self._intervals_ms), 2),
|
|
1430
|
+
})
|
|
1431
|
+
log_event(logger, "mcp_request_batch_finished", **payload)
|
|
1432
|
+
self._reset()
|
|
1433
|
+
return True
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
__all__ = [
|
|
1437
|
+
"BACKUP_COUNT",
|
|
1438
|
+
"DEFAULT_SLOW_THRESHOLD_SECONDS",
|
|
1439
|
+
"GLOBAL_LOG_ROOT_ENV",
|
|
1440
|
+
"LOG_FILE_NAME",
|
|
1441
|
+
"LOG_SCHEMA_VERSION",
|
|
1442
|
+
"MAX_BYTES",
|
|
1443
|
+
"TokenPhaseTracker",
|
|
1444
|
+
"McpRequestBatch",
|
|
1445
|
+
"request_context",
|
|
1446
|
+
"close_handlers_for_root",
|
|
1447
|
+
"compact_output",
|
|
1448
|
+
"configure",
|
|
1449
|
+
"generate_traceparent",
|
|
1450
|
+
"get_context",
|
|
1451
|
+
"global_log_path",
|
|
1452
|
+
"global_log_root",
|
|
1453
|
+
"is_initialized_project",
|
|
1454
|
+
"log_dialogue",
|
|
1455
|
+
"log_event",
|
|
1456
|
+
"log_phase",
|
|
1457
|
+
"log_path",
|
|
1458
|
+
"metered_gate",
|
|
1459
|
+
"metered_phase",
|
|
1460
|
+
"metered_step",
|
|
1461
|
+
"parse_traceparent",
|
|
1462
|
+
"project_log_id",
|
|
1463
|
+
"timed_phase",
|
|
1464
|
+
]
|