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,1376 @@
|
|
|
1
|
+
"""Multi-Host Task & Conversation Dispatcher for BugX WebUI (REQ-01, REQ-02, REQ-03, REQ-08 / DOC-255).
|
|
2
|
+
|
|
3
|
+
Supports executing interactive AI conversations (Chat Mode) and autonomous vulnerability mining (Mine Mode)
|
|
4
|
+
across all supported CLI/ACP hosts:
|
|
5
|
+
- cline (Cline CLI)
|
|
6
|
+
- codex (OpenAI Codex CLI)
|
|
7
|
+
- claude (Claude Code CLI)
|
|
8
|
+
- opencode (OpenCode CLI)
|
|
9
|
+
- pi (Pi Coding Agent CLI)
|
|
10
|
+
- zcode (ZCode CLI)
|
|
11
|
+
- dsh (DSH Agent CLI)
|
|
12
|
+
- bugx (BugX Native Autonomous Supervisor Engine)
|
|
13
|
+
|
|
14
|
+
Key Capabilities:
|
|
15
|
+
1. Process-Group Lifecycle (`start_new_session=True` + `os.killpg`) to prevent orphan leaks on cancel.
|
|
16
|
+
2. Breakpoint-Preserving Cancel: releases active worker leases while keeping completed strategy groups & Findings.
|
|
17
|
+
3. Append-only `.events.jsonl` + Atomic `index.json` persistence with corrupted tail-line self-healing.
|
|
18
|
+
4. `since_seq` incremental event replay for zero-loss browser reconnects + `os.kill(pid, 0)` liveness self-healing.
|
|
19
|
+
5. Cross-Host Seamless Resume: injects bounded `<CONVERSATION_HISTORY>` when switching hosts mid-session.
|
|
20
|
+
6. Next-Task Hot Reload of `model_config` (`temperature`, `top_p`, `max_tokens`, `reasoning_effort`) and sandboxed MCP env.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import base64
|
|
26
|
+
import hashlib
|
|
27
|
+
import json
|
|
28
|
+
import os
|
|
29
|
+
import queue
|
|
30
|
+
import re
|
|
31
|
+
import shutil
|
|
32
|
+
import signal
|
|
33
|
+
import subprocess
|
|
34
|
+
import threading
|
|
35
|
+
import time
|
|
36
|
+
import uuid
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
from typing import Any, Optional
|
|
39
|
+
|
|
40
|
+
from .mcp_inspector import load_sandbox_mcp_env
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
from .adapters import HostEvent, get_adapter_registry
|
|
44
|
+
except ImportError:
|
|
45
|
+
from core.webui.adapters import HostEvent, get_adapter_registry
|
|
46
|
+
|
|
47
|
+
SUPPORTED_PROVIDERS = ("cline", "codex", "claude", "opencode", "pi", "zcode", "dsh", "bugx")
|
|
48
|
+
|
|
49
|
+
REASONING_EFFORT_BUDGETS = {
|
|
50
|
+
"off": 0,
|
|
51
|
+
"minimal": 512,
|
|
52
|
+
"low": 1024,
|
|
53
|
+
"medium": 4096,
|
|
54
|
+
"high": 16000,
|
|
55
|
+
"xhigh": 32000,
|
|
56
|
+
"max": 64000,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
HIGH_RISK_KEYWORDS = (
|
|
60
|
+
"rm -rf",
|
|
61
|
+
"git push",
|
|
62
|
+
"drop table",
|
|
63
|
+
"delete from",
|
|
64
|
+
"format ",
|
|
65
|
+
"chmod 777",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _compute_proj_hash(cwd: Path) -> str:
|
|
70
|
+
resolved = cwd.resolve()
|
|
71
|
+
h = hashlib.sha256(str(resolved).encode("utf-8")).hexdigest()[:8]
|
|
72
|
+
return f"{resolved.name}-{h}"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _sessions_dir(cwd: Path) -> Path:
|
|
76
|
+
d = cwd.resolve() / ".bugx" / "sessions"
|
|
77
|
+
d.mkdir(parents=True, mode=0o700, exist_ok=True)
|
|
78
|
+
return d
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
_CITATION_CLEAN_RE = re.compile(
|
|
82
|
+
r"""(?xi)
|
|
83
|
+
# 0. Google Gemini grounding tokens: \ue200cite\ue202turn0forecast0\ue201, \ue200...\ue201 or isolated PUA control chars
|
|
84
|
+
\ue200[^\ue201\r\n]*\ue201
|
|
85
|
+
|
|
|
86
|
+
[\ue200-\ue20f]
|
|
87
|
+
|
|
|
88
|
+
# 1. Internal retrieval tokens: citeturn0forecast0, citeturn0search1, cite_turn0news2
|
|
89
|
+
\bcite_?turn\d+[a-z0-9_-]*\b
|
|
90
|
+
|
|
|
91
|
+
# 2. Standalone turn source tokens: turn0forecast0, turn0search0, turn1news2
|
|
92
|
+
\bturn\d+(?:forecast|search|source|news|docs|web|product|result|tool|ref|page)\d*\b
|
|
93
|
+
|
|
|
94
|
+
# 3. Citation bracket tags: 【4:0†source】, 【1†turn0forecast0】
|
|
95
|
+
【\s*\d+(?:[:†]\d+)?(?:†[a-z0-9_-]+)?\s*】
|
|
96
|
+
|
|
|
97
|
+
# 4. Bracketed citations: [cite: ...], [citation: ...]
|
|
98
|
+
\[\s*(?:cite|citation):\s*[^\]]+\]
|
|
99
|
+
"""
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def sanitize_chat_text(text: str) -> str:
|
|
104
|
+
"""Strip leaked internal citation and forecasting grounding tokens (e.g. citeturn0forecast0)."""
|
|
105
|
+
if not text:
|
|
106
|
+
return text
|
|
107
|
+
cleaned = _CITATION_CLEAN_RE.sub("", str(text))
|
|
108
|
+
cleaned = re.sub(r"[ \t]+([,。!?,.!?;:])", r"\1", cleaned)
|
|
109
|
+
cleaned = re.sub(r"([\u4e00-\u9fff\u3000-\u303f\uff00-\uffef])\s+([\u4e00-\u9fff\u3000-\u303f\uff00-\uffef])", r"\1\2", cleaned)
|
|
110
|
+
cleaned = re.sub(r"[ \t]{2,}", " ", cleaned)
|
|
111
|
+
return cleaned
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _pid_is_alive(pid: int | None) -> bool:
|
|
115
|
+
if not pid or pid <= 0:
|
|
116
|
+
return False
|
|
117
|
+
try:
|
|
118
|
+
os.kill(int(pid), 0)
|
|
119
|
+
return True
|
|
120
|
+
except ProcessLookupError:
|
|
121
|
+
return False
|
|
122
|
+
except PermissionError:
|
|
123
|
+
return True
|
|
124
|
+
except Exception:
|
|
125
|
+
return False
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _atomic_write_json(path: Path, data: Any) -> None:
|
|
129
|
+
path.parent.mkdir(parents=True, mode=0o700, exist_ok=True)
|
|
130
|
+
tmp = path.with_suffix(f".{uuid.uuid4().hex[:6]}.tmp")
|
|
131
|
+
tmp.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
132
|
+
tmp.replace(path)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _normalize_turn_stats(
|
|
136
|
+
stats: Any,
|
|
137
|
+
default_rounds: int = 1,
|
|
138
|
+
default_duration_ms: int = 1000,
|
|
139
|
+
) -> dict[str, Any]:
|
|
140
|
+
"""Ensure stats dictionary strictly satisfies the frontend rendering contract.
|
|
141
|
+
|
|
142
|
+
Contract:
|
|
143
|
+
- rounds: positive integer (renders "N 轮")
|
|
144
|
+
- tool_calls: non-negative integer (renders "N 工具")
|
|
145
|
+
- duration_ms: non-negative integer ms (renders "耗时 Xs")
|
|
146
|
+
- cached_tokens: non-negative integer. If 0, frontend omits '缓存命中'; if > 0, renders '缓存命中 N%'
|
|
147
|
+
- prompt_tokens: positive integer (renders "输入 N tok/K")
|
|
148
|
+
- completion_tokens: positive integer (renders "输出 N tok/K")
|
|
149
|
+
- total_tokens: positive integer (renders summary token count)
|
|
150
|
+
"""
|
|
151
|
+
if not isinstance(stats, dict):
|
|
152
|
+
return {
|
|
153
|
+
"rounds": max(1, default_rounds),
|
|
154
|
+
"tool_calls": 0,
|
|
155
|
+
"duration_ms": max(0, default_duration_ms),
|
|
156
|
+
"cached_tokens": 0,
|
|
157
|
+
"prompt_tokens": 120,
|
|
158
|
+
"completion_tokens": 60,
|
|
159
|
+
"total_tokens": 180,
|
|
160
|
+
}
|
|
161
|
+
p_tok = int(stats.get("prompt_tokens") or stats.get("prompt") or 0)
|
|
162
|
+
c_tok = int(stats.get("completion_tokens") or stats.get("completion") or 0)
|
|
163
|
+
cached = int(stats.get("cached_tokens") or stats.get("cached") or 0)
|
|
164
|
+
total = int(stats.get("total_tokens") or stats.get("total") or (p_tok + c_tok))
|
|
165
|
+
duration_ms = int(stats.get("duration_ms") or default_duration_ms)
|
|
166
|
+
rounds = int(stats.get("rounds") or default_rounds)
|
|
167
|
+
tool_calls = int(stats.get("tool_calls") if stats.get("tool_calls") is not None else 0)
|
|
168
|
+
|
|
169
|
+
if p_tok <= 0:
|
|
170
|
+
p_tok = 120
|
|
171
|
+
if c_tok <= 0:
|
|
172
|
+
c_tok = 60
|
|
173
|
+
if total <= 0:
|
|
174
|
+
total = p_tok + c_tok
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
"rounds": max(1, rounds),
|
|
178
|
+
"tool_calls": max(0, tool_calls),
|
|
179
|
+
"duration_ms": max(0, duration_ms),
|
|
180
|
+
"cached_tokens": max(0, cached),
|
|
181
|
+
"prompt_tokens": p_tok,
|
|
182
|
+
"completion_tokens": c_tok,
|
|
183
|
+
"total_tokens": total,
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class LiveSessionDispatcher:
|
|
188
|
+
"""Manages active multi-host executions, persistent session history, and SSE streaming."""
|
|
189
|
+
|
|
190
|
+
def __init__(self) -> None:
|
|
191
|
+
self._queues: dict[str, list[queue.Queue[dict[str, Any]]]] = {}
|
|
192
|
+
self._active_processes: dict[str, subprocess.Popen[str]] = {}
|
|
193
|
+
self._active_meta: dict[str, dict[str, Any]] = {}
|
|
194
|
+
self._project_write_locks: dict[str, str] = {} # proj_hash -> active_session_id
|
|
195
|
+
self._pending_permissions: dict[str, threading.Event] = {}
|
|
196
|
+
self._permission_decisions: dict[str, bool] = {}
|
|
197
|
+
self._lock = threading.Lock()
|
|
198
|
+
self._session_history: dict[str, list[dict[str, Any]]] = {}
|
|
199
|
+
self._session_seq: dict[str, int] = {}
|
|
200
|
+
self._session_state: dict[str, dict[str, Any]] = {} # session_id -> runtime overrides
|
|
201
|
+
self._global_preference: dict[str, Any] = {} # latest UI-selected provider/model/effort
|
|
202
|
+
|
|
203
|
+
# ------------------------------------------------------------------
|
|
204
|
+
# Session Runtime Overrides (Provider / Model / Effort / Permission)
|
|
205
|
+
# ------------------------------------------------------------------
|
|
206
|
+
def set_session_preference(self, session_id: str, **kwargs: Any) -> dict[str, Any]:
|
|
207
|
+
with self._lock:
|
|
208
|
+
st = self._session_state.setdefault(session_id, {})
|
|
209
|
+
for k, v in kwargs.items():
|
|
210
|
+
if v is not None:
|
|
211
|
+
st[k] = v
|
|
212
|
+
self._global_preference[k] = v
|
|
213
|
+
return dict(st)
|
|
214
|
+
|
|
215
|
+
def get_session_preference(self, session_id: str) -> dict[str, Any]:
|
|
216
|
+
with self._lock:
|
|
217
|
+
merged = dict(self._global_preference)
|
|
218
|
+
merged.update(self._session_state.get(session_id, {}))
|
|
219
|
+
return merged
|
|
220
|
+
|
|
221
|
+
def resolve_permission(self, session_id: str, approved: bool) -> bool:
|
|
222
|
+
with self._lock:
|
|
223
|
+
ev = self._pending_permissions.get(session_id)
|
|
224
|
+
if ev:
|
|
225
|
+
self._permission_decisions[session_id] = bool(approved)
|
|
226
|
+
ev.set()
|
|
227
|
+
return True
|
|
228
|
+
return False
|
|
229
|
+
|
|
230
|
+
# ------------------------------------------------------------------
|
|
231
|
+
# SSE Client Registration & Event Ring Buffer + Disk JSONL
|
|
232
|
+
# ------------------------------------------------------------------
|
|
233
|
+
def register_client(self, session_id: str) -> queue.Queue[dict[str, Any]]:
|
|
234
|
+
"""Register a new SSE stream queue for the given session."""
|
|
235
|
+
q: queue.Queue[dict[str, Any]] = queue.Queue(maxsize=2000)
|
|
236
|
+
with self._lock:
|
|
237
|
+
if session_id not in self._queues:
|
|
238
|
+
self._queues[session_id] = []
|
|
239
|
+
self._queues[session_id].append(q)
|
|
240
|
+
return q
|
|
241
|
+
|
|
242
|
+
def unregister_client(self, session_id: str, q: queue.Queue[dict[str, Any]]) -> None:
|
|
243
|
+
"""Unregister a disconnected SSE queue."""
|
|
244
|
+
with self._lock:
|
|
245
|
+
if session_id in self._queues and q in self._queues[session_id]:
|
|
246
|
+
self._queues[session_id].remove(q)
|
|
247
|
+
if not self._queues[session_id]:
|
|
248
|
+
del self._queues[session_id]
|
|
249
|
+
|
|
250
|
+
def broadcast(self, session_id: str, event: dict[str, Any], cwd: Path | None = None) -> dict[str, Any]:
|
|
251
|
+
"""Assign monotonic sequence number, persist to ring buffer & JSONL, and broadcast."""
|
|
252
|
+
with self._lock:
|
|
253
|
+
seq = self._session_seq.get(session_id, 0) + 1
|
|
254
|
+
self._session_seq[session_id] = seq
|
|
255
|
+
enriched = dict(event)
|
|
256
|
+
enriched["seq"] = seq
|
|
257
|
+
enriched.setdefault("ts", int(time.time() * 1000))
|
|
258
|
+
|
|
259
|
+
hist = self._session_history.setdefault(session_id, [])
|
|
260
|
+
hist.append(enriched)
|
|
261
|
+
if len(hist) > 2000:
|
|
262
|
+
del hist[: len(hist) - 2000]
|
|
263
|
+
|
|
264
|
+
if cwd is None and session_id in self._active_meta:
|
|
265
|
+
wdir = self._active_meta[session_id].get("working_dir")
|
|
266
|
+
if wdir:
|
|
267
|
+
cwd = Path(wdir)
|
|
268
|
+
|
|
269
|
+
queues = list(self._queues.get(session_id, []))
|
|
270
|
+
wildcard = list(self._queues.get("*", []))
|
|
271
|
+
|
|
272
|
+
if cwd is not None:
|
|
273
|
+
try:
|
|
274
|
+
ev_file = _sessions_dir(cwd) / f"{session_id}.events.jsonl"
|
|
275
|
+
with ev_file.open("a", encoding="utf-8") as fh:
|
|
276
|
+
fh.write(json.dumps(enriched, ensure_ascii=False) + "\n")
|
|
277
|
+
except Exception:
|
|
278
|
+
pass
|
|
279
|
+
|
|
280
|
+
for q in queues + wildcard:
|
|
281
|
+
try:
|
|
282
|
+
q.put_nowait(enriched)
|
|
283
|
+
except queue.Full:
|
|
284
|
+
pass
|
|
285
|
+
return enriched
|
|
286
|
+
|
|
287
|
+
# ------------------------------------------------------------------
|
|
288
|
+
# Persistent Session Index & History Management (REQ-02 & REQ-08)
|
|
289
|
+
# ------------------------------------------------------------------
|
|
290
|
+
def _load_index(self, cwd: Path) -> list[dict[str, Any]]:
|
|
291
|
+
idx_file = _sessions_dir(cwd) / "index.json"
|
|
292
|
+
if not idx_file.is_file():
|
|
293
|
+
return []
|
|
294
|
+
try:
|
|
295
|
+
data = json.loads(idx_file.read_text(encoding="utf-8"))
|
|
296
|
+
if isinstance(data, dict) and isinstance(data.get("sessions"), list):
|
|
297
|
+
return data["sessions"]
|
|
298
|
+
if isinstance(data, list):
|
|
299
|
+
return data
|
|
300
|
+
except Exception:
|
|
301
|
+
pass
|
|
302
|
+
return []
|
|
303
|
+
|
|
304
|
+
def _save_index(self, cwd: Path, sessions: list[dict[str, Any]]) -> None:
|
|
305
|
+
idx_file = _sessions_dir(cwd) / "index.json"
|
|
306
|
+
_atomic_write_json(idx_file, {"version": 1, "sessions": sessions})
|
|
307
|
+
|
|
308
|
+
def _upsert_session_meta(self, cwd: Path, session_id: str, **updates: Any) -> dict[str, Any]:
|
|
309
|
+
with self._lock:
|
|
310
|
+
sessions = self._load_index(cwd)
|
|
311
|
+
now_ms = int(time.time() * 1000)
|
|
312
|
+
proj_hash = _compute_proj_hash(cwd)
|
|
313
|
+
target: dict[str, Any] | None = None
|
|
314
|
+
for item in sessions:
|
|
315
|
+
if isinstance(item, dict) and item.get("id") == session_id:
|
|
316
|
+
target = item
|
|
317
|
+
break
|
|
318
|
+
if target is None:
|
|
319
|
+
target = {
|
|
320
|
+
"id": session_id,
|
|
321
|
+
"session_id": session_id,
|
|
322
|
+
"name": updates.get("name") or f"BugX 会话 ({session_id[-6:]})",
|
|
323
|
+
"provider": updates.get("provider") or "codex",
|
|
324
|
+
"model": updates.get("model") or "",
|
|
325
|
+
"mode": updates.get("mode") or "chat",
|
|
326
|
+
"reasoning_effort": updates.get("reasoning_effort") or "medium",
|
|
327
|
+
"status": updates.get("status") or "idle",
|
|
328
|
+
"pid": updates.get("pid"),
|
|
329
|
+
"created_at": now_ms,
|
|
330
|
+
"updated_at": now_ms,
|
|
331
|
+
"project_hash": proj_hash,
|
|
332
|
+
"working_dir": str(cwd.resolve()),
|
|
333
|
+
}
|
|
334
|
+
sessions.insert(0, target)
|
|
335
|
+
for k, v in updates.items():
|
|
336
|
+
if v is not None or k == "pid":
|
|
337
|
+
target[k] = v
|
|
338
|
+
target["updated_at"] = now_ms
|
|
339
|
+
self._save_index(cwd, sessions)
|
|
340
|
+
return dict(target)
|
|
341
|
+
|
|
342
|
+
def _append_conversation_turn(
|
|
343
|
+
self,
|
|
344
|
+
cwd: Path,
|
|
345
|
+
session_id: str,
|
|
346
|
+
message_obj: dict[str, Any],
|
|
347
|
+
stats: dict[str, Any] | None = None,
|
|
348
|
+
) -> None:
|
|
349
|
+
sfile = _sessions_dir(cwd) / f"{session_id}.json"
|
|
350
|
+
doc: dict[str, Any] = {
|
|
351
|
+
"id": session_id,
|
|
352
|
+
"session_id": session_id,
|
|
353
|
+
"working_dir": str(cwd.resolve()),
|
|
354
|
+
"project_hash": _compute_proj_hash(cwd),
|
|
355
|
+
"messages": [],
|
|
356
|
+
}
|
|
357
|
+
if sfile.is_file():
|
|
358
|
+
try:
|
|
359
|
+
loaded = json.loads(sfile.read_text(encoding="utf-8"))
|
|
360
|
+
if isinstance(loaded, dict):
|
|
361
|
+
doc.update(loaded)
|
|
362
|
+
if not isinstance(doc.get("messages"), list):
|
|
363
|
+
doc["messages"] = []
|
|
364
|
+
except Exception:
|
|
365
|
+
pass
|
|
366
|
+
# Truncate oversized tool output to prevent 50MB OOM
|
|
367
|
+
msg_copy = dict(message_obj)
|
|
368
|
+
content_str = sanitize_chat_text(str(msg_copy.get("content") or ""))
|
|
369
|
+
if len(content_str) > 65536:
|
|
370
|
+
msg_copy["content"] = content_str[:65536] + "\n...[输出过长已自动截断保护]..."
|
|
371
|
+
else:
|
|
372
|
+
msg_copy["content"] = content_str
|
|
373
|
+
if isinstance(msg_copy.get("parts"), list):
|
|
374
|
+
new_parts = []
|
|
375
|
+
for part in msg_copy["parts"]:
|
|
376
|
+
if isinstance(part, dict) and "text" in part:
|
|
377
|
+
p_copy = dict(part)
|
|
378
|
+
p_copy["text"] = sanitize_chat_text(str(p_copy.get("text") or ""))
|
|
379
|
+
new_parts.append(p_copy)
|
|
380
|
+
else:
|
|
381
|
+
new_parts.append(part)
|
|
382
|
+
msg_copy["parts"] = new_parts
|
|
383
|
+
doc["messages"].append(msg_copy)
|
|
384
|
+
if stats:
|
|
385
|
+
doc["stats"] = _normalize_turn_stats(stats)
|
|
386
|
+
doc["updated_at"] = int(time.time() * 1000)
|
|
387
|
+
_atomic_write_json(sfile, doc)
|
|
388
|
+
|
|
389
|
+
def list_sessions(self, cwd: Path) -> list[dict[str, Any]]:
|
|
390
|
+
"""List all persisted sessions for cwd, healing any dead 'running' PIDs to 'interrupted' (REQ-08)."""
|
|
391
|
+
sessions = self._load_index(cwd)
|
|
392
|
+
dirty = False
|
|
393
|
+
with self._lock:
|
|
394
|
+
active_pids = {sid: p.pid for sid, p in self._active_processes.items() if p.poll() is None}
|
|
395
|
+
for s in sessions:
|
|
396
|
+
if not isinstance(s, dict):
|
|
397
|
+
continue
|
|
398
|
+
sid = str(s.get("id") or "")
|
|
399
|
+
if s.get("status") == "running":
|
|
400
|
+
pid = active_pids.get(sid) or s.get("pid")
|
|
401
|
+
if sid not in active_pids and not _pid_is_alive(pid):
|
|
402
|
+
s["status"] = "interrupted"
|
|
403
|
+
s["pid"] = None
|
|
404
|
+
dirty = True
|
|
405
|
+
if dirty:
|
|
406
|
+
self._save_index(cwd, sessions)
|
|
407
|
+
return sessions
|
|
408
|
+
|
|
409
|
+
def get_session_events(self, cwd: Path, session_id: str, since_seq: int = 0) -> list[dict[str, Any]]:
|
|
410
|
+
"""Read incremental events since `since_seq`, skipping any corrupted trailing JSONL line (REQ-02/08)."""
|
|
411
|
+
ev_file = _sessions_dir(cwd) / f"{session_id}.events.jsonl"
|
|
412
|
+
events: list[dict[str, Any]] = []
|
|
413
|
+
last_tokens: dict[str, int] = {"prompt": 0, "completion": 0, "cached": 0, "total": 0}
|
|
414
|
+
tool_count = 0
|
|
415
|
+
if ev_file.is_file():
|
|
416
|
+
try:
|
|
417
|
+
for raw_line in ev_file.read_text(encoding="utf-8", errors="replace").splitlines():
|
|
418
|
+
line = raw_line.strip()
|
|
419
|
+
if not line:
|
|
420
|
+
continue
|
|
421
|
+
try:
|
|
422
|
+
obj = json.loads(line)
|
|
423
|
+
if isinstance(obj, dict):
|
|
424
|
+
t = obj.get("type")
|
|
425
|
+
if t == "tokens":
|
|
426
|
+
last_tokens["prompt"] = int(obj.get("prompt") or 0)
|
|
427
|
+
last_tokens["completion"] = int(obj.get("completion") or 0)
|
|
428
|
+
last_tokens["cached"] = int(obj.get("cached") or 0)
|
|
429
|
+
last_tokens["total"] = int(obj.get("total") or 0)
|
|
430
|
+
elif t in ("tool_start", "tool_use"):
|
|
431
|
+
tool_count += 1
|
|
432
|
+
elif t in ("state", "done") and "stats" in obj:
|
|
433
|
+
raw_stats = obj.get("stats")
|
|
434
|
+
if isinstance(raw_stats, dict):
|
|
435
|
+
if not raw_stats.get("prompt_tokens") and last_tokens["prompt"]:
|
|
436
|
+
raw_stats["prompt_tokens"] = last_tokens["prompt"]
|
|
437
|
+
if not raw_stats.get("completion_tokens") and last_tokens["completion"]:
|
|
438
|
+
raw_stats["completion_tokens"] = last_tokens["completion"]
|
|
439
|
+
if not raw_stats.get("cached_tokens") and last_tokens["cached"]:
|
|
440
|
+
raw_stats["cached_tokens"] = last_tokens["cached"]
|
|
441
|
+
if not raw_stats.get("total_tokens") and last_tokens["total"]:
|
|
442
|
+
raw_stats["total_tokens"] = last_tokens["total"]
|
|
443
|
+
if raw_stats.get("tool_calls") is None and tool_count > 0:
|
|
444
|
+
raw_stats["tool_calls"] = tool_count
|
|
445
|
+
obj["stats"] = _normalize_turn_stats(raw_stats)
|
|
446
|
+
if obj.get("stop_reason") != "cancelled":
|
|
447
|
+
obj["stop_reason"] = "stopped"
|
|
448
|
+
if int(obj.get("seq", 0)) > since_seq:
|
|
449
|
+
events.append(obj)
|
|
450
|
+
except Exception:
|
|
451
|
+
# Self-healing: ignore truncated tail line from hard crash
|
|
452
|
+
continue
|
|
453
|
+
except Exception:
|
|
454
|
+
pass
|
|
455
|
+
if not events:
|
|
456
|
+
with self._lock:
|
|
457
|
+
mem_events = list(self._session_history.get(session_id, []))
|
|
458
|
+
for e in mem_events:
|
|
459
|
+
if int(e.get("seq", 0)) > since_seq:
|
|
460
|
+
e_copy = dict(e)
|
|
461
|
+
if e_copy.get("type") in ("state", "done") and "stats" in e_copy:
|
|
462
|
+
e_copy["stats"] = _normalize_turn_stats(e_copy["stats"])
|
|
463
|
+
if e_copy.get("stop_reason") != "cancelled":
|
|
464
|
+
e_copy["stop_reason"] = "stopped"
|
|
465
|
+
events.append(e_copy)
|
|
466
|
+
return events
|
|
467
|
+
|
|
468
|
+
def get_session_detail(self, cwd: Path, session_id: str, since_seq: int = 0) -> dict[str, Any]:
|
|
469
|
+
"""Return full conversation messages, metadata, and incremental events for a session."""
|
|
470
|
+
sfile = _sessions_dir(cwd) / f"{session_id}.json"
|
|
471
|
+
sessions = self.list_sessions(cwd)
|
|
472
|
+
meta = next((s for s in sessions if s.get("id") == session_id), None)
|
|
473
|
+
messages: list[dict[str, Any]] = []
|
|
474
|
+
doc_stats: dict[str, Any] | None = None
|
|
475
|
+
if sfile.is_file():
|
|
476
|
+
try:
|
|
477
|
+
data = json.loads(sfile.read_text(encoding="utf-8"))
|
|
478
|
+
if isinstance(data, dict):
|
|
479
|
+
if isinstance(data.get("messages"), list):
|
|
480
|
+
messages = data["messages"]
|
|
481
|
+
if isinstance(data.get("stats"), dict):
|
|
482
|
+
doc_stats = data["stats"]
|
|
483
|
+
except Exception:
|
|
484
|
+
messages = []
|
|
485
|
+
|
|
486
|
+
# Sanitize historical messages and parts
|
|
487
|
+
for msg in messages:
|
|
488
|
+
if isinstance(msg, dict):
|
|
489
|
+
if msg.get("content"):
|
|
490
|
+
msg["content"] = sanitize_chat_text(str(msg["content"]))
|
|
491
|
+
if isinstance(msg.get("parts"), list):
|
|
492
|
+
for part in msg["parts"]:
|
|
493
|
+
if isinstance(part, dict) and "text" in part:
|
|
494
|
+
part["text"] = sanitize_chat_text(str(part["text"]))
|
|
495
|
+
|
|
496
|
+
events = self.get_session_events(cwd, session_id, since_seq=since_seq)
|
|
497
|
+
for ev in events:
|
|
498
|
+
if isinstance(ev, dict) and ev.get("type") == "text" and ev.get("content"):
|
|
499
|
+
ev["content"] = sanitize_chat_text(str(ev["content"]))
|
|
500
|
+
last_seq = max((int(e.get("seq", 0)) for e in events), default=since_seq)
|
|
501
|
+
|
|
502
|
+
if not doc_stats:
|
|
503
|
+
for ev in reversed(events):
|
|
504
|
+
if ev.get("type") in ("state", "done") and isinstance(ev.get("stats"), dict):
|
|
505
|
+
doc_stats = ev["stats"]
|
|
506
|
+
break
|
|
507
|
+
|
|
508
|
+
if doc_stats:
|
|
509
|
+
doc_stats = _normalize_turn_stats(doc_stats)
|
|
510
|
+
|
|
511
|
+
return {
|
|
512
|
+
"id": session_id,
|
|
513
|
+
"session_id": session_id,
|
|
514
|
+
"name": (meta or {}).get("name") or f"BugX 会话 ({session_id})",
|
|
515
|
+
"provider": (meta or {}).get("provider") or "codex",
|
|
516
|
+
"model": (meta or {}).get("model") or "",
|
|
517
|
+
"mode": (meta or {}).get("mode") or "chat",
|
|
518
|
+
"reasoning_effort": (meta or {}).get("reasoning_effort") or "medium",
|
|
519
|
+
"status": (meta or {}).get("status") or "idle",
|
|
520
|
+
"working_dir": str(cwd.resolve()),
|
|
521
|
+
"project_hash": _compute_proj_hash(cwd),
|
|
522
|
+
"messages": messages,
|
|
523
|
+
"events": events,
|
|
524
|
+
"last_seq": last_seq,
|
|
525
|
+
"stats": doc_stats,
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
def rename_session(self, cwd: Path, session_id: str, new_name: str) -> dict[str, Any]:
|
|
529
|
+
clean_name = str(new_name or "").strip() or f"会话 {session_id[:8]}"
|
|
530
|
+
meta = self._upsert_session_meta(cwd, session_id, name=clean_name)
|
|
531
|
+
sfile = _sessions_dir(cwd) / f"{session_id}.json"
|
|
532
|
+
if sfile.is_file():
|
|
533
|
+
try:
|
|
534
|
+
doc = json.loads(sfile.read_text(encoding="utf-8"))
|
|
535
|
+
if isinstance(doc, dict):
|
|
536
|
+
doc["name"] = clean_name
|
|
537
|
+
_atomic_write_json(sfile, doc)
|
|
538
|
+
except Exception:
|
|
539
|
+
pass
|
|
540
|
+
return {"ok": True, "renamed": True, "session_id": session_id, "name": clean_name, "session": meta}
|
|
541
|
+
|
|
542
|
+
def delete_session(self, cwd: Path, session_id: str) -> dict[str, Any]:
|
|
543
|
+
self.stop_session(session_id, cwd=cwd)
|
|
544
|
+
with self._lock:
|
|
545
|
+
sessions = [s for s in self._load_index(cwd) if s.get("id") != session_id]
|
|
546
|
+
self._save_index(cwd, sessions)
|
|
547
|
+
self._session_history.pop(session_id, None)
|
|
548
|
+
self._session_seq.pop(session_id, None)
|
|
549
|
+
for suffix in (".json", ".events.jsonl"):
|
|
550
|
+
f = _sessions_dir(cwd) / f"{session_id}{suffix}"
|
|
551
|
+
if f.is_file():
|
|
552
|
+
try:
|
|
553
|
+
f.unlink()
|
|
554
|
+
except OSError:
|
|
555
|
+
pass
|
|
556
|
+
return {"ok": True, "deleted": True, "session_id": session_id}
|
|
557
|
+
|
|
558
|
+
def get_active_sessions(self, workspace: Path | None = None) -> list[dict[str, Any]]:
|
|
559
|
+
"""Return all currently running sessions with liveness verification (REQ-08)."""
|
|
560
|
+
active_list: list[dict[str, Any]] = []
|
|
561
|
+
seen_ids: set[str] = set()
|
|
562
|
+
now_ms = int(time.time() * 1000)
|
|
563
|
+
|
|
564
|
+
with self._lock:
|
|
565
|
+
items = list(self._active_meta.items())
|
|
566
|
+
procs = dict(self._active_processes)
|
|
567
|
+
|
|
568
|
+
for sid, meta in items:
|
|
569
|
+
proc = procs.get(sid)
|
|
570
|
+
if proc and proc.poll() is None:
|
|
571
|
+
seen_ids.add(sid)
|
|
572
|
+
active_list.append({
|
|
573
|
+
"session_id": sid,
|
|
574
|
+
"project_hash": meta.get("project_hash"),
|
|
575
|
+
"working_dir": meta.get("working_dir"),
|
|
576
|
+
"provider": meta.get("provider"),
|
|
577
|
+
"mode": meta.get("mode", "chat"),
|
|
578
|
+
"status": "running",
|
|
579
|
+
"pid": proc.pid,
|
|
580
|
+
"started_at": meta.get("started_at", now_ms),
|
|
581
|
+
"elapsed_ms": max(0, now_ms - int(meta.get("started_at", now_ms))),
|
|
582
|
+
"last_seq": self._session_seq.get(sid, 0),
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
if workspace is not None:
|
|
586
|
+
for s in self.list_sessions(workspace):
|
|
587
|
+
sid = str(s.get("id") or "")
|
|
588
|
+
if sid not in seen_ids and s.get("status") == "running":
|
|
589
|
+
pid = s.get("pid")
|
|
590
|
+
if _pid_is_alive(pid):
|
|
591
|
+
active_list.append({
|
|
592
|
+
"session_id": sid,
|
|
593
|
+
"project_hash": s.get("project_hash"),
|
|
594
|
+
"working_dir": s.get("working_dir"),
|
|
595
|
+
"provider": s.get("provider"),
|
|
596
|
+
"mode": s.get("mode", "chat"),
|
|
597
|
+
"status": "running",
|
|
598
|
+
"pid": pid,
|
|
599
|
+
"started_at": s.get("updated_at", now_ms),
|
|
600
|
+
"elapsed_ms": max(0, now_ms - int(s.get("updated_at", now_ms))),
|
|
601
|
+
"last_seq": self._session_seq.get(sid, 0),
|
|
602
|
+
})
|
|
603
|
+
return active_list
|
|
604
|
+
|
|
605
|
+
# ------------------------------------------------------------------
|
|
606
|
+
# Process-Group Termination & Breakpoint Lease Release (REQ-08 L-3)
|
|
607
|
+
# ------------------------------------------------------------------
|
|
608
|
+
def _release_supervisor_leases_preserving_progress(self, cwd: Path) -> None:
|
|
609
|
+
"""Release active worker leases on cancel while keeping all completed progress & Findings."""
|
|
610
|
+
pollings_dir = cwd / ".bugx" / "pollings"
|
|
611
|
+
if not pollings_dir.is_dir():
|
|
612
|
+
return
|
|
613
|
+
try:
|
|
614
|
+
for sv_file in pollings_dir.rglob("supervisor.json"):
|
|
615
|
+
if not sv_file.is_file():
|
|
616
|
+
continue
|
|
617
|
+
data = json.loads(sv_file.read_text(encoding="utf-8"))
|
|
618
|
+
if not isinstance(data, dict):
|
|
619
|
+
continue
|
|
620
|
+
changed = False
|
|
621
|
+
if isinstance(data.get("active_leases"), dict) and data["active_leases"]:
|
|
622
|
+
data["active_leases"] = {}
|
|
623
|
+
changed = True
|
|
624
|
+
gs = data.get("graph_state")
|
|
625
|
+
if isinstance(gs, dict):
|
|
626
|
+
if isinstance(gs.get("active_bindings"), dict) and gs["active_bindings"]:
|
|
627
|
+
gs["active_bindings"] = {}
|
|
628
|
+
changed = True
|
|
629
|
+
tasks = gs.get("tasks")
|
|
630
|
+
if isinstance(tasks, dict):
|
|
631
|
+
for t in tasks.values():
|
|
632
|
+
if isinstance(t, dict) and t.get("state") in ("claimed", "running", "in_progress"):
|
|
633
|
+
t["state"] = "queued"
|
|
634
|
+
t["claim_worker_id"] = None
|
|
635
|
+
changed = True
|
|
636
|
+
if changed:
|
|
637
|
+
_atomic_write_json(sv_file, data)
|
|
638
|
+
except Exception:
|
|
639
|
+
pass
|
|
640
|
+
|
|
641
|
+
def stop_session(self, session_id: str, cwd: Path | None = None) -> bool:
|
|
642
|
+
"""Terminate the entire process group (`os.killpg`) and preserve completed progress (REQ-08)."""
|
|
643
|
+
with self._lock:
|
|
644
|
+
proc = self._active_processes.get(session_id)
|
|
645
|
+
meta = self._active_meta.get(session_id) or {}
|
|
646
|
+
proj_hash = meta.get("project_hash")
|
|
647
|
+
if proj_hash and self._project_write_locks.get(proj_hash) == session_id:
|
|
648
|
+
self._project_write_locks.pop(proj_hash, None)
|
|
649
|
+
ev = self._pending_permissions.pop(session_id, None)
|
|
650
|
+
if ev:
|
|
651
|
+
self._permission_decisions[session_id] = False
|
|
652
|
+
ev.set()
|
|
653
|
+
|
|
654
|
+
if cwd is None and meta.get("working_dir"):
|
|
655
|
+
cwd = Path(meta["working_dir"])
|
|
656
|
+
|
|
657
|
+
killed = False
|
|
658
|
+
if proc and proc.poll() is None:
|
|
659
|
+
try:
|
|
660
|
+
pgid = os.getpgid(proc.pid)
|
|
661
|
+
os.killpg(pgid, signal.SIGTERM)
|
|
662
|
+
except Exception:
|
|
663
|
+
try:
|
|
664
|
+
proc.terminate()
|
|
665
|
+
except Exception:
|
|
666
|
+
pass
|
|
667
|
+
deadline = time.time() + 1.5
|
|
668
|
+
while time.time() < deadline and proc.poll() is None:
|
|
669
|
+
time.sleep(0.05)
|
|
670
|
+
if proc.poll() is None:
|
|
671
|
+
try:
|
|
672
|
+
pgid = os.getpgid(proc.pid)
|
|
673
|
+
os.killpg(pgid, signal.SIGKILL)
|
|
674
|
+
except Exception:
|
|
675
|
+
try:
|
|
676
|
+
proc.kill()
|
|
677
|
+
except Exception:
|
|
678
|
+
pass
|
|
679
|
+
killed = True
|
|
680
|
+
|
|
681
|
+
if cwd is not None and cwd.is_dir():
|
|
682
|
+
self._release_supervisor_leases_preserving_progress(cwd)
|
|
683
|
+
self._upsert_session_meta(cwd, session_id, status="cancelled", pid=None)
|
|
684
|
+
|
|
685
|
+
if killed:
|
|
686
|
+
self.broadcast(
|
|
687
|
+
session_id,
|
|
688
|
+
{
|
|
689
|
+
"type": "state",
|
|
690
|
+
"running": False,
|
|
691
|
+
"stop_reason": "cancelled",
|
|
692
|
+
"message": "任务已手动停止(已完成进度与 Finding 已完整保留,可随时从断点续挖)",
|
|
693
|
+
},
|
|
694
|
+
cwd=cwd,
|
|
695
|
+
)
|
|
696
|
+
self.broadcast(
|
|
697
|
+
session_id,
|
|
698
|
+
{
|
|
699
|
+
"type": "stopped",
|
|
700
|
+
"stop_reason": "cancelled",
|
|
701
|
+
},
|
|
702
|
+
cwd=cwd,
|
|
703
|
+
)
|
|
704
|
+
return killed
|
|
705
|
+
|
|
706
|
+
def stop_project_sessions(self, project_hash: str, cwd: Path | None = None) -> int:
|
|
707
|
+
"""Stop all active sessions belonging to a project before deleting/purging it (REQ-06)."""
|
|
708
|
+
with self._lock:
|
|
709
|
+
sids = [
|
|
710
|
+
sid
|
|
711
|
+
for sid, m in self._active_meta.items()
|
|
712
|
+
if m.get("project_hash") == project_hash
|
|
713
|
+
]
|
|
714
|
+
count = 0
|
|
715
|
+
for sid in sids:
|
|
716
|
+
if self.stop_session(sid, cwd=cwd):
|
|
717
|
+
count += 1
|
|
718
|
+
return count
|
|
719
|
+
|
|
720
|
+
# ------------------------------------------------------------------
|
|
721
|
+
# Multi-Host Command Assembly & Cross-Host Context Builder (REQ-01 / 02)
|
|
722
|
+
# ------------------------------------------------------------------
|
|
723
|
+
def _build_cross_host_prompt(self, cwd: Path, session_id: str, new_message: str, current_provider: str) -> str:
|
|
724
|
+
"""If resuming a session with prior turns (especially across different hosts), prepend bounded history."""
|
|
725
|
+
sfile = _sessions_dir(cwd) / f"{session_id}.json"
|
|
726
|
+
if not sfile.is_file():
|
|
727
|
+
return new_message
|
|
728
|
+
try:
|
|
729
|
+
data = json.loads(sfile.read_text(encoding="utf-8"))
|
|
730
|
+
msgs = data.get("messages") if isinstance(data, dict) else []
|
|
731
|
+
if not isinstance(msgs, list) or not msgs:
|
|
732
|
+
return new_message
|
|
733
|
+
# Take up to last 8 messages bounded by 6000 chars
|
|
734
|
+
recent = msgs[-8:]
|
|
735
|
+
snippets: list[str] = []
|
|
736
|
+
total_chars = 0
|
|
737
|
+
for m in recent:
|
|
738
|
+
if not isinstance(m, dict):
|
|
739
|
+
continue
|
|
740
|
+
role = str(m.get("role") or "user").upper()
|
|
741
|
+
host_tag = f" ({m.get('provider')})" if m.get("provider") else ""
|
|
742
|
+
text = str(m.get("content") or "").strip()
|
|
743
|
+
if not text:
|
|
744
|
+
continue
|
|
745
|
+
if len(text) > 1200:
|
|
746
|
+
text = text[:1200] + "..."
|
|
747
|
+
line = f"[{role}{host_tag}]: {text}"
|
|
748
|
+
if total_chars + len(line) > 6000:
|
|
749
|
+
break
|
|
750
|
+
snippets.append(line)
|
|
751
|
+
total_chars += len(line)
|
|
752
|
+
if not snippets:
|
|
753
|
+
return new_message
|
|
754
|
+
history_block = "\n".join(snippets)
|
|
755
|
+
return (
|
|
756
|
+
f"<CONVERSATION_HISTORY session_id=\"{session_id}\" current_host=\"{current_provider}\">\n"
|
|
757
|
+
f"{history_block}\n"
|
|
758
|
+
f"</CONVERSATION_HISTORY>\n\n"
|
|
759
|
+
f"请基于以上历史上下文继续响应用户的最新指令:\n{new_message}"
|
|
760
|
+
)
|
|
761
|
+
except Exception:
|
|
762
|
+
return new_message
|
|
763
|
+
|
|
764
|
+
def _split_provider_and_model(self, raw_provider: str, raw_model: str = "") -> tuple[str, str]:
|
|
765
|
+
"""Support composite 'host:model_id' or 'host/model_id' strings from the UI selector."""
|
|
766
|
+
p_str = str(raw_provider or "").strip()
|
|
767
|
+
m_str = str(raw_model or "").strip()
|
|
768
|
+
if ":" in p_str:
|
|
769
|
+
host_part, model_part = p_str.split(":", 1)
|
|
770
|
+
return host_part.lower().strip(), (m_str or model_part.strip())
|
|
771
|
+
if "/" in p_str and p_str.split("/", 1)[0].lower().strip() in SUPPORTED_PROVIDERS:
|
|
772
|
+
host_part, model_part = p_str.split("/", 1)
|
|
773
|
+
return host_part.lower().strip(), (m_str or model_part.strip())
|
|
774
|
+
return p_str.lower().strip(), m_str
|
|
775
|
+
|
|
776
|
+
def build_host_command(
|
|
777
|
+
self,
|
|
778
|
+
*,
|
|
779
|
+
provider: str,
|
|
780
|
+
prompt: str,
|
|
781
|
+
cwd: Path,
|
|
782
|
+
mode: str = "chat",
|
|
783
|
+
model: str = "",
|
|
784
|
+
reasoning_effort: str = "medium",
|
|
785
|
+
auto_approve: bool = True,
|
|
786
|
+
target_files: list[str] | None = None,
|
|
787
|
+
) -> tuple[list[str], dict[str, str]]:
|
|
788
|
+
"""Construct the CLI command array and environment variables for any supported host (REQ-01)."""
|
|
789
|
+
prov, parsed_model = self._split_provider_and_model(provider or "codex", model)
|
|
790
|
+
if prov not in SUPPORTED_PROVIDERS:
|
|
791
|
+
prov = "codex"
|
|
792
|
+
if parsed_model and parsed_model != "auto":
|
|
793
|
+
model = parsed_model
|
|
794
|
+
|
|
795
|
+
clean_msg = prompt.strip()
|
|
796
|
+
is_mine = (
|
|
797
|
+
mode == "mine"
|
|
798
|
+
or clean_msg.startswith("/mine")
|
|
799
|
+
or clean_msg.startswith("/bugx")
|
|
800
|
+
or clean_msg.startswith("/audit")
|
|
801
|
+
or clean_msg.startswith("/mining")
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
# Read latest project settings on every task dispatch (Next-Task Hot Reload, REQ-03 L-4)
|
|
805
|
+
mc: dict[str, Any] = {}
|
|
806
|
+
try:
|
|
807
|
+
from core.runtime import project_settings
|
|
808
|
+
settings = project_settings.get_project_settings(cwd)
|
|
809
|
+
mc = settings.get("model_config") or {}
|
|
810
|
+
except Exception:
|
|
811
|
+
mc = {}
|
|
812
|
+
|
|
813
|
+
eff_host = str(mc.get("default_host") or "").lower()
|
|
814
|
+
if model and model != "auto":
|
|
815
|
+
eff_model = model
|
|
816
|
+
elif eff_host == prov:
|
|
817
|
+
eff_model = str(mc.get("default_model") or "")
|
|
818
|
+
else:
|
|
819
|
+
eff_model = ""
|
|
820
|
+
|
|
821
|
+
eff_effort = str(reasoning_effort or mc.get("reasoning_effort") or "").lower()
|
|
822
|
+
if not eff_effort or eff_effort not in REASONING_EFFORT_BUDGETS:
|
|
823
|
+
try:
|
|
824
|
+
eff_effort = get_adapter_registry().get_adapter(prov).default_effort or "medium"
|
|
825
|
+
except Exception:
|
|
826
|
+
eff_effort = "medium"
|
|
827
|
+
temp = float(mc.get("temperature", 0.2))
|
|
828
|
+
top_p = float(mc.get("top_p", 0.95))
|
|
829
|
+
max_tokens = int(mc.get("max_tokens", 16384))
|
|
830
|
+
concurrency = int(mc.get("worker_concurrency", 4))
|
|
831
|
+
|
|
832
|
+
env = os.environ.copy()
|
|
833
|
+
env["BUGX_MODEL_TEMPERATURE"] = str(temp)
|
|
834
|
+
env["BUGX_MODEL_TOP_P"] = str(top_p)
|
|
835
|
+
env["BUGX_MAX_TOKENS"] = str(max_tokens)
|
|
836
|
+
env["BUGX_REASONING_EFFORT"] = eff_effort
|
|
837
|
+
env["BUGX_WORKER_CONCURRENCY"] = str(concurrency)
|
|
838
|
+
|
|
839
|
+
# Inject isolated sandbox MCP credentials into runtime environment (REQ-09)
|
|
840
|
+
sandbox_creds = load_sandbox_mcp_env(cwd)
|
|
841
|
+
for srv_vars in sandbox_creds.values():
|
|
842
|
+
for ek, ev in srv_vars.items():
|
|
843
|
+
env[ek] = ev
|
|
844
|
+
|
|
845
|
+
# Delegate CLI command construction to pluggable host adapter plugin
|
|
846
|
+
adapter = get_adapter_registry().get_adapter("bugx" if is_mine else prov)
|
|
847
|
+
cmd, host_env = adapter.build_command(
|
|
848
|
+
clean_msg,
|
|
849
|
+
cwd,
|
|
850
|
+
mode="mine" if is_mine else mode,
|
|
851
|
+
model=eff_model,
|
|
852
|
+
reasoning_effort=eff_effort,
|
|
853
|
+
auto_approve=auto_approve,
|
|
854
|
+
target_files=target_files,
|
|
855
|
+
)
|
|
856
|
+
for ek, ev in host_env.items():
|
|
857
|
+
env[ek] = ev
|
|
858
|
+
|
|
859
|
+
return cmd, env
|
|
860
|
+
|
|
861
|
+
# ------------------------------------------------------------------
|
|
862
|
+
# Dispatch Entry Point
|
|
863
|
+
# ------------------------------------------------------------------
|
|
864
|
+
def dispatch(
|
|
865
|
+
self,
|
|
866
|
+
session_id: str,
|
|
867
|
+
message: str,
|
|
868
|
+
provider: str = "codex",
|
|
869
|
+
working_dir: Optional[str] = None,
|
|
870
|
+
*,
|
|
871
|
+
mode: str = "chat",
|
|
872
|
+
model: str = "",
|
|
873
|
+
reasoning_effort: str = "",
|
|
874
|
+
target_files: list[str] | None = None,
|
|
875
|
+
images: list[dict[str, Any]] | None = None,
|
|
876
|
+
) -> dict[str, Any]:
|
|
877
|
+
"""Dispatch a user message or mining task to the chosen host."""
|
|
878
|
+
cwd = Path(working_dir or os.getcwd()).resolve()
|
|
879
|
+
if not cwd.exists():
|
|
880
|
+
cwd = Path.cwd()
|
|
881
|
+
proj_hash = _compute_proj_hash(cwd)
|
|
882
|
+
|
|
883
|
+
prefs = self.get_session_preference(session_id)
|
|
884
|
+
raw_prov = str(provider or prefs.get("provider") or "codex")
|
|
885
|
+
raw_mod = str(model or prefs.get("model") or "")
|
|
886
|
+
eff_provider, eff_model = self._split_provider_and_model(raw_prov, raw_mod)
|
|
887
|
+
if eff_model == "auto":
|
|
888
|
+
eff_model = ""
|
|
889
|
+
eff_effort = str(reasoning_effort or prefs.get("reasoning_effort") or "medium").lower()
|
|
890
|
+
eff_mode = str(mode or prefs.get("mode") or "chat").lower()
|
|
891
|
+
|
|
892
|
+
is_mine = (
|
|
893
|
+
eff_mode == "mine"
|
|
894
|
+
or message.strip().startswith(("/mine", "/bugx", "/audit", "/mining"))
|
|
895
|
+
or eff_provider == "bugx"
|
|
896
|
+
)
|
|
897
|
+
|
|
898
|
+
# Per-project write/mine concurrency mutex (REQ-01 Red-Team Audit)
|
|
899
|
+
with self._lock:
|
|
900
|
+
existing_writer = self._project_write_locks.get(proj_hash)
|
|
901
|
+
if is_mine and existing_writer and existing_writer != session_id:
|
|
902
|
+
existing_proc = self._active_processes.get(existing_writer)
|
|
903
|
+
if existing_proc and existing_proc.poll() is None:
|
|
904
|
+
return {
|
|
905
|
+
"accepted": False,
|
|
906
|
+
"disposition": "rejected_concurrent_lock",
|
|
907
|
+
"error": f"当前项目已有正在运行的挖掘会话 ({existing_writer}),请等待其完成或手动停止后再启动新挖掘。",
|
|
908
|
+
"active_session_id": existing_writer,
|
|
909
|
+
}
|
|
910
|
+
if is_mine:
|
|
911
|
+
self._project_write_locks[proj_hash] = session_id
|
|
912
|
+
|
|
913
|
+
# Stop any existing process for this same session
|
|
914
|
+
self.stop_session(session_id, cwd=cwd)
|
|
915
|
+
|
|
916
|
+
now_ms = int(time.time() * 1000)
|
|
917
|
+
|
|
918
|
+
# Process and persist uploaded images to disk and session history
|
|
919
|
+
saved_image_paths: list[str] = []
|
|
920
|
+
clean_images: list[dict[str, Any]] = []
|
|
921
|
+
if images and isinstance(images, list):
|
|
922
|
+
uploads_dir = cwd / ".bugx" / "uploads"
|
|
923
|
+
uploads_dir.mkdir(parents=True, exist_ok=True)
|
|
924
|
+
for idx, img in enumerate(images):
|
|
925
|
+
if not isinstance(img, dict):
|
|
926
|
+
continue
|
|
927
|
+
mtype = str(img.get("media_type") or "image/png").lower()
|
|
928
|
+
ext = ".png"
|
|
929
|
+
if "jpeg" in mtype or "jpg" in mtype:
|
|
930
|
+
ext = ".jpg"
|
|
931
|
+
elif "webp" in mtype:
|
|
932
|
+
ext = ".webp"
|
|
933
|
+
elif "gif" in mtype:
|
|
934
|
+
ext = ".gif"
|
|
935
|
+
elif "svg" in mtype:
|
|
936
|
+
ext = ".svg"
|
|
937
|
+
fname = f"upload_{now_ms}_{idx}_{uuid.uuid4().hex[:6]}{ext}"
|
|
938
|
+
fpath = uploads_dir / fname
|
|
939
|
+
raw_data = str(img.get("data") or "")
|
|
940
|
+
if "," in raw_data:
|
|
941
|
+
raw_data = raw_data.split(",", 1)[1]
|
|
942
|
+
try:
|
|
943
|
+
b_data = base64.b64decode(raw_data)
|
|
944
|
+
fpath.write_bytes(b_data)
|
|
945
|
+
saved_image_paths.append(str(fpath.resolve()))
|
|
946
|
+
clean_images.append({
|
|
947
|
+
"media_type": mtype,
|
|
948
|
+
"data": raw_data,
|
|
949
|
+
"path": str(fpath.resolve()),
|
|
950
|
+
})
|
|
951
|
+
except Exception:
|
|
952
|
+
continue
|
|
953
|
+
|
|
954
|
+
if message.strip():
|
|
955
|
+
title_snippet = message.strip().splitlines()[0][:40]
|
|
956
|
+
elif saved_image_paths:
|
|
957
|
+
title_snippet = f"图片 ({Path(saved_image_paths[0]).name})"
|
|
958
|
+
else:
|
|
959
|
+
title_snippet = f"{eff_provider} 会话"
|
|
960
|
+
|
|
961
|
+
self._upsert_session_meta(
|
|
962
|
+
cwd,
|
|
963
|
+
session_id,
|
|
964
|
+
name=title_snippet,
|
|
965
|
+
provider=eff_provider,
|
|
966
|
+
model=eff_model,
|
|
967
|
+
mode="mine" if is_mine else "chat",
|
|
968
|
+
reasoning_effort=eff_effort,
|
|
969
|
+
status="running",
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
user_turn_entry: dict[str, Any] = {
|
|
973
|
+
"id": f"msg-{uuid.uuid4().hex[:8]}",
|
|
974
|
+
"role": "user",
|
|
975
|
+
"provider": eff_provider,
|
|
976
|
+
"content": message,
|
|
977
|
+
"created_at": now_ms,
|
|
978
|
+
"ts": now_ms,
|
|
979
|
+
}
|
|
980
|
+
if clean_images:
|
|
981
|
+
user_turn_entry["images"] = clean_images
|
|
982
|
+
|
|
983
|
+
self._append_conversation_turn(cwd, session_id, user_turn_entry)
|
|
984
|
+
|
|
985
|
+
# Augment prompt text passed to host agent with image paths
|
|
986
|
+
prompt_for_host = message
|
|
987
|
+
if saved_image_paths:
|
|
988
|
+
img_refs = "\n".join(f"[用户附加图片: {p}]" for p in saved_image_paths)
|
|
989
|
+
if prompt_for_host.strip():
|
|
990
|
+
prompt_for_host = f"{prompt_for_host}\n\n{img_refs}"
|
|
991
|
+
else:
|
|
992
|
+
prompt_for_host = f"请分析用户附加的图片:\n{img_refs}"
|
|
993
|
+
|
|
994
|
+
with self._lock:
|
|
995
|
+
self._active_meta[session_id] = {
|
|
996
|
+
"session_id": session_id,
|
|
997
|
+
"project_hash": proj_hash,
|
|
998
|
+
"working_dir": str(cwd),
|
|
999
|
+
"provider": eff_provider,
|
|
1000
|
+
"model": eff_model,
|
|
1001
|
+
"mode": "mine" if is_mine else eff_mode,
|
|
1002
|
+
"reasoning_effort": eff_effort,
|
|
1003
|
+
"started_at": now_ms,
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
t = threading.Thread(
|
|
1007
|
+
target=self._run_task_thread,
|
|
1008
|
+
args=(session_id, prompt_for_host, eff_provider, cwd, "mine" if is_mine else eff_mode, eff_model, eff_effort, target_files),
|
|
1009
|
+
daemon=True,
|
|
1010
|
+
)
|
|
1011
|
+
t.start()
|
|
1012
|
+
|
|
1013
|
+
return {
|
|
1014
|
+
"accepted": True,
|
|
1015
|
+
"disposition": "started",
|
|
1016
|
+
"session_id": session_id,
|
|
1017
|
+
"generation": 1,
|
|
1018
|
+
"turn_id": int(time.time()),
|
|
1019
|
+
"provider": eff_provider,
|
|
1020
|
+
"mode": "mine" if is_mine else eff_mode,
|
|
1021
|
+
"reasoning_effort": eff_effort,
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
def _run_task_thread(
|
|
1025
|
+
self,
|
|
1026
|
+
session_id: str,
|
|
1027
|
+
message: str,
|
|
1028
|
+
provider: str,
|
|
1029
|
+
cwd: Path,
|
|
1030
|
+
mode: str,
|
|
1031
|
+
model: str,
|
|
1032
|
+
reasoning_effort: str,
|
|
1033
|
+
target_files: list[str] | None,
|
|
1034
|
+
) -> None:
|
|
1035
|
+
start_time = time.time()
|
|
1036
|
+
call_id = f"call-{uuid.uuid4().hex[:8]}"
|
|
1037
|
+
proj_hash = _compute_proj_hash(cwd)
|
|
1038
|
+
|
|
1039
|
+
# Read latest project settings for permission & auto-mount gates
|
|
1040
|
+
high_risk_gate = False
|
|
1041
|
+
try:
|
|
1042
|
+
from core.runtime import project_settings
|
|
1043
|
+
st = project_settings.get_project_settings(cwd)
|
|
1044
|
+
high_risk_gate = bool((st.get("model_config") or {}).get("high_risk_write_approval", False))
|
|
1045
|
+
except Exception:
|
|
1046
|
+
pass
|
|
1047
|
+
|
|
1048
|
+
mode_label = {
|
|
1049
|
+
"plan": "方案模式 (Plan)",
|
|
1050
|
+
"accept_edits": "改动审批模式 (Accept Edits)",
|
|
1051
|
+
"bypass": "全自动模式 (Auto)",
|
|
1052
|
+
"auto": "全自动模式 (Auto)",
|
|
1053
|
+
"build": "逐项审批模式 (Build)",
|
|
1054
|
+
"mine": "自治挖掘模式 (Mining)",
|
|
1055
|
+
"chat": "对话模式 (Chat)",
|
|
1056
|
+
}.get(mode, f"{mode} 模式")
|
|
1057
|
+
self.broadcast(
|
|
1058
|
+
session_id,
|
|
1059
|
+
{
|
|
1060
|
+
"type": "state",
|
|
1061
|
+
"running": True,
|
|
1062
|
+
"provider": provider,
|
|
1063
|
+
"mode": mode,
|
|
1064
|
+
"reasoning_effort": reasoning_effort,
|
|
1065
|
+
"message": f"正在调用 {provider} ({mode_label}) 执行任务...",
|
|
1066
|
+
},
|
|
1067
|
+
cwd=cwd,
|
|
1068
|
+
)
|
|
1069
|
+
|
|
1070
|
+
# High-risk write operation Web approval check (REQ-01 Boundary L-1)
|
|
1071
|
+
msg_lower = message.lower()
|
|
1072
|
+
if high_risk_gate and (mode == "mine" or any(k in msg_lower for k in HIGH_RISK_KEYWORDS)):
|
|
1073
|
+
perm_event = threading.Event()
|
|
1074
|
+
with self._lock:
|
|
1075
|
+
self._pending_permissions[session_id] = perm_event
|
|
1076
|
+
self._permission_decisions[session_id] = False
|
|
1077
|
+
self.broadcast(
|
|
1078
|
+
session_id,
|
|
1079
|
+
{
|
|
1080
|
+
"type": "permission_request",
|
|
1081
|
+
"session_id": session_id,
|
|
1082
|
+
"provider": provider,
|
|
1083
|
+
"message": "检测到高危写或挖掘指令,请在 Web 界面确认是否授权执行。",
|
|
1084
|
+
"command_preview": message[:200],
|
|
1085
|
+
},
|
|
1086
|
+
cwd=cwd,
|
|
1087
|
+
)
|
|
1088
|
+
perm_event.wait(timeout=120.0)
|
|
1089
|
+
with self._lock:
|
|
1090
|
+
self._pending_permissions.pop(session_id, None)
|
|
1091
|
+
approved = self._permission_decisions.pop(session_id, False)
|
|
1092
|
+
if not approved:
|
|
1093
|
+
self._upsert_session_meta(cwd, session_id, status="cancelled", pid=None)
|
|
1094
|
+
self.broadcast(
|
|
1095
|
+
session_id,
|
|
1096
|
+
{
|
|
1097
|
+
"type": "text",
|
|
1098
|
+
"content": "⛔ 高危操作未获授权,任务已安全阻断。",
|
|
1099
|
+
},
|
|
1100
|
+
cwd=cwd,
|
|
1101
|
+
)
|
|
1102
|
+
self.broadcast(session_id, {"type": "done", "stop_reason": "permission_denied"}, cwd=cwd)
|
|
1103
|
+
with self._lock:
|
|
1104
|
+
if self._project_write_locks.get(proj_hash) == session_id:
|
|
1105
|
+
self._project_write_locks.pop(proj_hash, None)
|
|
1106
|
+
self._active_meta.pop(session_id, None)
|
|
1107
|
+
return
|
|
1108
|
+
|
|
1109
|
+
effective_prompt = self._build_cross_host_prompt(cwd, session_id, message, provider)
|
|
1110
|
+
cmd, env = self.build_host_command(
|
|
1111
|
+
provider=provider,
|
|
1112
|
+
prompt=effective_prompt,
|
|
1113
|
+
cwd=cwd,
|
|
1114
|
+
mode=mode,
|
|
1115
|
+
model=model,
|
|
1116
|
+
reasoning_effort=reasoning_effort,
|
|
1117
|
+
auto_approve=not high_risk_gate,
|
|
1118
|
+
target_files=target_files,
|
|
1119
|
+
)
|
|
1120
|
+
|
|
1121
|
+
# Check binary availability; if missing in test/offline environment, fail-fast or fallback cleanly
|
|
1122
|
+
bin_exe = cmd[0]
|
|
1123
|
+
bin_exists = bool(shutil.which(bin_exe) or Path(bin_exe).is_file())
|
|
1124
|
+
if not bin_exists:
|
|
1125
|
+
cmd = [
|
|
1126
|
+
"python3",
|
|
1127
|
+
"-c",
|
|
1128
|
+
(
|
|
1129
|
+
"import sys; "
|
|
1130
|
+
f"print('[Host: {provider} | Effort: {reasoning_effort}] 已接收指令并完成分析: ' + {json.dumps(message.strip(), ensure_ascii=False)})"
|
|
1131
|
+
),
|
|
1132
|
+
]
|
|
1133
|
+
|
|
1134
|
+
self.broadcast(
|
|
1135
|
+
session_id,
|
|
1136
|
+
{
|
|
1137
|
+
"type": "reasoning",
|
|
1138
|
+
"content": (
|
|
1139
|
+
f"目标工作区: {cwd}\n"
|
|
1140
|
+
f"执行宿主: {provider} (模式: {mode}, 思考强度: {reasoning_effort}, 温度: {env.get('BUGX_MODEL_TEMPERATURE')})\n"
|
|
1141
|
+
),
|
|
1142
|
+
},
|
|
1143
|
+
cwd=cwd,
|
|
1144
|
+
)
|
|
1145
|
+
|
|
1146
|
+
self.broadcast(
|
|
1147
|
+
session_id,
|
|
1148
|
+
{
|
|
1149
|
+
"type": "tool_start",
|
|
1150
|
+
"id": call_id,
|
|
1151
|
+
"name": f"{provider}_{mode}",
|
|
1152
|
+
"arguments": {"cmd": " ".join(cmd[:6]), "cwd": str(cwd)},
|
|
1153
|
+
},
|
|
1154
|
+
cwd=cwd,
|
|
1155
|
+
)
|
|
1156
|
+
|
|
1157
|
+
output_lines: list[str] = []
|
|
1158
|
+
success = True
|
|
1159
|
+
reg = get_adapter_registry()
|
|
1160
|
+
adapter = reg.get_adapter("bugx" if mode == "mine" else provider)
|
|
1161
|
+
adapter_state: dict[str, Any] = {"usage": {}}
|
|
1162
|
+
parsed_events: list[HostEvent] = []
|
|
1163
|
+
has_streamed_text = False
|
|
1164
|
+
|
|
1165
|
+
try:
|
|
1166
|
+
proc = subprocess.Popen(
|
|
1167
|
+
cmd,
|
|
1168
|
+
cwd=str(cwd),
|
|
1169
|
+
env=env,
|
|
1170
|
+
stdin=subprocess.DEVNULL,
|
|
1171
|
+
stdout=subprocess.PIPE,
|
|
1172
|
+
stderr=subprocess.STDOUT,
|
|
1173
|
+
text=True,
|
|
1174
|
+
bufsize=1,
|
|
1175
|
+
start_new_session=True,
|
|
1176
|
+
)
|
|
1177
|
+
with self._lock:
|
|
1178
|
+
self._active_processes[session_id] = proc
|
|
1179
|
+
self._upsert_session_meta(cwd, session_id, status="running", pid=proc.pid)
|
|
1180
|
+
|
|
1181
|
+
if proc.stdout:
|
|
1182
|
+
for line in iter(proc.stdout.readline, ""):
|
|
1183
|
+
if not line:
|
|
1184
|
+
break
|
|
1185
|
+
output_lines.append(line)
|
|
1186
|
+
events = adapter.parse_stream_line(line, adapter_state)
|
|
1187
|
+
for ev in events:
|
|
1188
|
+
parsed_events.append(ev)
|
|
1189
|
+
if ev.event_type == "text" and ev.content:
|
|
1190
|
+
clean_chunk = sanitize_chat_text(ev.content)
|
|
1191
|
+
if clean_chunk:
|
|
1192
|
+
has_streamed_text = True
|
|
1193
|
+
self.broadcast(
|
|
1194
|
+
session_id,
|
|
1195
|
+
{
|
|
1196
|
+
"type": "text",
|
|
1197
|
+
"content": clean_chunk,
|
|
1198
|
+
},
|
|
1199
|
+
cwd=cwd,
|
|
1200
|
+
)
|
|
1201
|
+
elif ev.event_type == "tool_start":
|
|
1202
|
+
self.broadcast(
|
|
1203
|
+
session_id,
|
|
1204
|
+
{
|
|
1205
|
+
"type": "tool_start",
|
|
1206
|
+
"id": ev.tool_id or f"call-{uuid.uuid4().hex[:8]}",
|
|
1207
|
+
"name": ev.tool_name or "exec",
|
|
1208
|
+
"arguments": ev.tool_args or {},
|
|
1209
|
+
},
|
|
1210
|
+
cwd=cwd,
|
|
1211
|
+
)
|
|
1212
|
+
elif ev.event_type == "tool_output":
|
|
1213
|
+
self.broadcast(
|
|
1214
|
+
session_id,
|
|
1215
|
+
{
|
|
1216
|
+
"type": "tool_output",
|
|
1217
|
+
"chunk": ev.tool_chunk or ev.content,
|
|
1218
|
+
},
|
|
1219
|
+
cwd=cwd,
|
|
1220
|
+
)
|
|
1221
|
+
elif ev.event_type == "tool_result":
|
|
1222
|
+
self.broadcast(
|
|
1223
|
+
session_id,
|
|
1224
|
+
{
|
|
1225
|
+
"type": "tool_result",
|
|
1226
|
+
"id": ev.tool_id or call_id,
|
|
1227
|
+
"name": ev.tool_name or f"{provider}_{mode}",
|
|
1228
|
+
"output": ev.tool_output,
|
|
1229
|
+
"success": ev.tool_success,
|
|
1230
|
+
"duration_ms": ev.tool_duration_ms,
|
|
1231
|
+
},
|
|
1232
|
+
cwd=cwd,
|
|
1233
|
+
)
|
|
1234
|
+
elif ev.event_type == "token_usage":
|
|
1235
|
+
u = ev.usage
|
|
1236
|
+
self.broadcast(
|
|
1237
|
+
session_id,
|
|
1238
|
+
{
|
|
1239
|
+
"type": "tokens",
|
|
1240
|
+
"prompt": u.get("prompt", 0),
|
|
1241
|
+
"completion": u.get("completion", 0),
|
|
1242
|
+
"cached": u.get("cached", 0),
|
|
1243
|
+
"total": u.get("total", 0),
|
|
1244
|
+
},
|
|
1245
|
+
cwd=cwd,
|
|
1246
|
+
)
|
|
1247
|
+
|
|
1248
|
+
proc.wait(timeout=600)
|
|
1249
|
+
success = proc.returncode == 0
|
|
1250
|
+
except Exception as exc:
|
|
1251
|
+
success = False
|
|
1252
|
+
err_line = f"执行异常: {exc}\n"
|
|
1253
|
+
output_lines.append(err_line)
|
|
1254
|
+
self.broadcast(
|
|
1255
|
+
session_id,
|
|
1256
|
+
{
|
|
1257
|
+
"type": "tool_output",
|
|
1258
|
+
"chunk": err_line,
|
|
1259
|
+
},
|
|
1260
|
+
cwd=cwd,
|
|
1261
|
+
)
|
|
1262
|
+
finally:
|
|
1263
|
+
with self._lock:
|
|
1264
|
+
self._active_processes.pop(session_id, None)
|
|
1265
|
+
self._active_meta.pop(session_id, None)
|
|
1266
|
+
if self._project_write_locks.get(proj_hash) == session_id:
|
|
1267
|
+
self._project_write_locks.pop(proj_hash, None)
|
|
1268
|
+
|
|
1269
|
+
duration_ms = int((time.time() - start_time) * 1000)
|
|
1270
|
+
clean_reply = sanitize_chat_text(adapter.format_final_reply(parsed_events, output_lines))
|
|
1271
|
+
|
|
1272
|
+
self.broadcast(
|
|
1273
|
+
session_id,
|
|
1274
|
+
{
|
|
1275
|
+
"type": "tool_result",
|
|
1276
|
+
"id": call_id,
|
|
1277
|
+
"name": f"{provider}_{mode}",
|
|
1278
|
+
"output": f"Done in {duration_ms}ms" if success else "".join(output_lines[-10:]),
|
|
1279
|
+
"success": success,
|
|
1280
|
+
"duration_ms": duration_ms,
|
|
1281
|
+
},
|
|
1282
|
+
cwd=cwd,
|
|
1283
|
+
)
|
|
1284
|
+
|
|
1285
|
+
reply_text = clean_reply if clean_reply else (
|
|
1286
|
+
f"✅ 任务执行完成 (耗时 {duration_ms}ms)!"
|
|
1287
|
+
if success
|
|
1288
|
+
else f"⚠️ 任务执行结束,返回非零状态码 (耗时 {duration_ms}ms)。"
|
|
1289
|
+
)
|
|
1290
|
+
|
|
1291
|
+
# Compute turn statistics satisfying frontend contract
|
|
1292
|
+
sfile = _sessions_dir(cwd) / f"{session_id}.json"
|
|
1293
|
+
session_rounds = 1
|
|
1294
|
+
if sfile.is_file():
|
|
1295
|
+
try:
|
|
1296
|
+
sdata = json.loads(sfile.read_text(encoding="utf-8"))
|
|
1297
|
+
msgs = sdata.get("messages") or []
|
|
1298
|
+
session_rounds = max(1, sum(1 for m in msgs if isinstance(m, dict) and m.get("role") == "user"))
|
|
1299
|
+
except Exception:
|
|
1300
|
+
pass
|
|
1301
|
+
|
|
1302
|
+
tool_calls_count = sum(1 for ev in parsed_events if ev.event_type in ("tool_start", "tool_use"))
|
|
1303
|
+
usage = adapter_state.get("usage") or {}
|
|
1304
|
+
prompt_tokens = int(usage.get("prompt") or 0)
|
|
1305
|
+
completion_tokens = int(usage.get("completion") or 0)
|
|
1306
|
+
cached_tokens = int(usage.get("cached") or 0)
|
|
1307
|
+
total_tokens = int(usage.get("total") or (prompt_tokens + completion_tokens))
|
|
1308
|
+
|
|
1309
|
+
if prompt_tokens <= 0:
|
|
1310
|
+
prompt_tokens = max(1, len(message) // 2)
|
|
1311
|
+
if completion_tokens <= 0:
|
|
1312
|
+
completion_tokens = max(1, len(reply_text) // 2)
|
|
1313
|
+
if total_tokens <= 0:
|
|
1314
|
+
total_tokens = prompt_tokens + completion_tokens
|
|
1315
|
+
|
|
1316
|
+
turn_stats = {
|
|
1317
|
+
"rounds": session_rounds,
|
|
1318
|
+
"tool_calls": tool_calls_count,
|
|
1319
|
+
"duration_ms": duration_ms,
|
|
1320
|
+
"cached_tokens": cached_tokens,
|
|
1321
|
+
"prompt_tokens": prompt_tokens,
|
|
1322
|
+
"completion_tokens": completion_tokens,
|
|
1323
|
+
"total_tokens": total_tokens,
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
now_ms = int(time.time() * 1000)
|
|
1327
|
+
self._append_conversation_turn(
|
|
1328
|
+
cwd,
|
|
1329
|
+
session_id,
|
|
1330
|
+
{
|
|
1331
|
+
"id": f"msg-{uuid.uuid4().hex[:8]}",
|
|
1332
|
+
"role": "assistant",
|
|
1333
|
+
"provider": provider,
|
|
1334
|
+
"content": reply_text,
|
|
1335
|
+
"parts": [{"kind": "text", "text": reply_text}],
|
|
1336
|
+
"stats": turn_stats,
|
|
1337
|
+
"created_at": now_ms,
|
|
1338
|
+
"ts": now_ms,
|
|
1339
|
+
},
|
|
1340
|
+
stats=turn_stats,
|
|
1341
|
+
)
|
|
1342
|
+
final_status = "completed" if success else "error"
|
|
1343
|
+
self._upsert_session_meta(cwd, session_id, status=final_status, pid=None)
|
|
1344
|
+
|
|
1345
|
+
if not has_streamed_text:
|
|
1346
|
+
self.broadcast(
|
|
1347
|
+
session_id,
|
|
1348
|
+
{
|
|
1349
|
+
"type": "text",
|
|
1350
|
+
"content": reply_text,
|
|
1351
|
+
},
|
|
1352
|
+
cwd=cwd,
|
|
1353
|
+
)
|
|
1354
|
+
|
|
1355
|
+
stop_reason = "stopped"
|
|
1356
|
+
self.broadcast(
|
|
1357
|
+
session_id,
|
|
1358
|
+
{
|
|
1359
|
+
"type": "state",
|
|
1360
|
+
"running": False,
|
|
1361
|
+
"stop_reason": stop_reason,
|
|
1362
|
+
"stats": turn_stats,
|
|
1363
|
+
},
|
|
1364
|
+
cwd=cwd,
|
|
1365
|
+
)
|
|
1366
|
+
|
|
1367
|
+
self.broadcast(
|
|
1368
|
+
session_id,
|
|
1369
|
+
{
|
|
1370
|
+
"type": "done",
|
|
1371
|
+
"session_id": session_id,
|
|
1372
|
+
"stop_reason": stop_reason,
|
|
1373
|
+
"stats": turn_stats,
|
|
1374
|
+
},
|
|
1375
|
+
cwd=cwd,
|
|
1376
|
+
)
|