bugx-cli 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -185
- package/core/README.md +2 -2
- package/core/agent/README.md +2 -1
- package/core/agent/agent_artifacts.py +8 -6
- package/core/agent/agent_eval.py +136 -54
- package/core/agent/agent_execution.py +218 -52
- package/core/agent/agent_orchestrator.py +14 -8
- package/core/agent/agent_targets.py +8 -2
- package/core/agent/feature_baseline.py +150 -0
- package/core/assets/README.md +3 -2
- package/core/assets/axe-core/LICENSE-3RD-PARTY.txt +66 -0
- package/core/assets/axe-core/LICENSE.txt +362 -0
- package/core/assets/axe-core/UPSTREAM.md +10 -0
- package/core/assets/axe-core/axe.min.js +12 -0
- package/core/assets/bugx-hero-en.svg +74 -0
- package/core/assets/bugx-hero-zh.svg +74 -0
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.png +0 -0
- package/core/assets/codex.png +0 -0
- package/core/assets/dsh.png +0 -0
- package/core/assets/webui-chatgpt.jpg +0 -0
- package/core/assets/webui-session.jpg +0 -0
- package/core/assets/webui-skills.jpg +0 -0
- package/core/assets/webui-studio.jpg +0 -0
- package/core/assets/webui-zcode.jpg +0 -0
- package/core/assets/zcode.png +0 -0
- package/core/audit_packs/README.md +2 -0
- package/core/audit_packs/pitfalls/auth_crypto.json +64 -0
- package/core/audit_packs/pitfalls/file_ssrf_cmd.json +64 -0
- package/core/audit_packs/pitfalls/go_backend.json +66 -0
- package/core/audit_packs/pitfalls/java_spring.json +64 -0
- package/core/audit_packs/pitfalls/js_ts_web.json +67 -0
- package/core/audit_packs/pitfalls/python_web.json +82 -0
- package/core/autonomous_cve/SPEC.md +1 -1
- package/core/autonomous_cve/attack_graph_store.py +152 -106
- package/core/autonomous_cve/behavior_graph.py +8 -2
- package/core/autonomous_cve/verifier.py +4 -1
- package/core/bugx.md +1 -1
- package/core/bugx_paths.py +43 -8
- package/core/cli-help.txt +66 -0
- package/core/cloud_sync/SPEC.md +1 -1
- package/core/cloud_sync/cloud_client.py +81 -11
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -15
- package/core/cloud_sync/network_transport.py +24 -3
- package/core/cloud_sync/sensitive_filter.py +2 -2
- package/core/cloud_sync/sync_push.py +12 -10
- package/core/contracts/AGENT_GUIDE.md +6 -9
- package/core/contracts/README.md +2 -2
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/contracts/engine_gap_contracts.py +86 -3
- package/core/coverage/coverage_discovery.py +599 -29
- package/core/coverage/coverage_evidence.py +47 -0
- package/core/coverage/coverage_forensics.py +9 -0
- package/core/coverage/coverage_validate.py +6 -1
- package/core/dev_harness/SPEC.md +1 -1
- package/core/engine-integrity.json +670 -442
- package/core/fuzzing/concurrency_fuzzer.py +53 -0
- package/core/fuzzing/differential_oracle.py +562 -27
- package/core/fuzzing/fuzz_input.py +109 -6
- package/core/fuzzing/stateful_fuzzer.py +72 -0
- package/core/governance/secret_redactor.py +22 -10
- package/core/host_acp/SPEC.md +1 -1
- package/core/host_acp/__init__.py +4 -4
- package/core/host_acp/claude.py +59 -1
- package/core/host_acp/cline.py +64 -1
- package/core/host_acp/codex.py +56 -1
- package/core/host_acp/dsh.py +59 -1
- package/core/host_acp/opencode.py +56 -1
- package/core/host_acp/pi.py +59 -1
- package/core/host_acp/zcode.py +59 -1
- package/core/host_runtime/SPEC.md +1 -1
- package/core/host_runtime/adapters.py +1 -1
- package/core/host_runtime/cline.py +13 -0
- package/core/host_runtime/host_evaluators.py +44 -4
- package/core/host_runtime/host_probe.py +1 -1
- package/core/host_runtime/host_provider_arbitrator.py +116 -62
- package/core/host_runtime/host_registry.py +15 -8
- package/core/host_runtime/mcp_registry_gate.py +12 -1
- package/core/host_runtime/pi.py +102 -0
- package/core/host_runtime/provider_facts.py +66 -0
- package/core/hosts/SPEC.md +1 -1
- package/core/hosts/__init__.py +6 -2
- package/core/hosts/_dsh_usage.py +1 -1
- package/core/hosts/base.py +32 -4
- package/core/hosts/claude.py +55 -0
- package/core/hosts/cline.py +6 -2
- package/core/hosts/codex.py +58 -0
- package/core/hosts/dsh.py +9 -1
- package/core/hosts/opencode.py +6 -6
- package/core/hosts/pi.py +159 -2
- package/core/infra/README.md +4 -2
- package/core/infra/__init__.py +2 -0
- package/core/infra/build_info.py +22 -3
- package/core/infra/client_metadata.py +1 -1
- package/core/infra/json_utils.py +22 -0
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +170 -5
- package/core/launch_phases/finding_settlement.py +188 -1
- package/core/launch_phases/judge_phase.py +69 -12
- package/core/launch_phases/orchestrator_controls.py +11 -7
- package/core/launch_phases/post_coverage_sync.py +9 -2
- package/core/launch_phases/post_phase.py +144 -8
- package/core/launch_phases/post_receipt.py +12 -1
- package/core/launch_phases/pre_phase.py +3 -3
- package/core/launch_phases/pre_recon_scout.py +66 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +129 -58
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/session_runtime.py +56 -9
- package/core/launch_phases/startup_gates.py +36 -8
- package/core/launch_phases/startup_interaction.py +68 -12
- package/core/launch_phases/startup_version_gate.py +13 -3
- package/core/launch_phases/supervisor_bridge.py +46 -17
- package/core/launch_phases/supervisor_coverage.py +8 -2
- package/core/launch_phases/supervisor_degraded.py +1 -9
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/SPEC.md +1 -1
- package/core/ledger/_facade.py +2 -1
- package/core/ledger/archive_ops.py +60 -2
- package/core/ledger/cli.py +6 -1
- package/core/ledger/export_ops.py +6 -1
- package/core/ledger/finding_confirmation.py +48 -6
- package/core/ledger/finding_lifecycle.py +428 -5
- package/core/ledger/finding_verification.py +555 -10
- package/core/ledger/fp_ledger.py +255 -0
- package/core/ledger/incidents.py +10 -4
- package/core/ledger/patterns.py +10 -7
- package/core/ledger/receipt_contract.py +17 -1
- package/core/ledger/sync_ops.py +21 -16
- package/core/ledger/tool_experience.py +2 -1
- package/core/ledger/verify_life.py +88 -17
- package/core/locales/en-US.json +2 -2
- package/core/locales/zh-CN.json +2 -2
- package/core/mcp_handlers/SPEC.md +1 -1
- package/core/mcp_handlers/base.py +23 -3
- package/core/mcp_handlers/channel_lifecycle.py +85 -30
- package/core/mcp_handlers/retrieval_handlers.py +11 -1
- package/core/mcp_handlers/rpc_server.py +6 -1
- package/core/mcp_handlers/supervisor_handlers.py +32 -6
- package/core/mcp_handlers/tool_table.py +15 -0
- package/core/mcp_runtime_support/environment.py +0 -38
- package/core/mcp_runtime_support/verifier.py +0 -52
- package/core/metadata.txt +2 -3
- package/core/planning/README.md +2 -1
- package/core/planning/domain_router.py +4 -2
- package/core/planning/dynamic_flow_analyzer.py +219 -14
- package/core/planning/judge_pipeline.py +87 -4
- package/core/planning/prompt_harness.py +57 -15
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/planning/spec_harvester.py +4 -4
- package/core/probes/INTERFACE.md +11 -1
- package/core/probes/SPEC.md +11 -1
- package/core/probes/__init__.py +46 -40
- package/core/probes/android_probe.py +177 -9
- package/core/probes/codebase_memory_probe.py +57 -0
- package/core/probes/desktop_probe.py +104 -0
- package/core/probes/differential_probe.py +99 -21
- package/core/probes/efficiency_probe.py +64 -0
- package/core/probes/ios_binary_probe.py +105 -1
- package/core/probes/memory_probe.py +66 -0
- package/core/probes/miniprogram_probe.py +75 -13
- package/core/probes/mobile_probe.py +215 -30
- package/core/probes/native_probe.py +88 -0
- package/core/probes/openwiki_probe.py +70 -0
- package/core/probes/pattern_probe.py +106 -0
- package/core/probes/platform_probe.py +81 -0
- package/core/probes/probe_registry.py +108 -7
- package/core/probes/sast_fixture_corpus.py +340 -0
- package/core/probes/sast_probe.py +553 -52
- package/core/probes/sast_rules.py +668 -28
- package/core/probes/sca_scanner.py +48 -0
- package/core/probes/ui_accessibility.py +149 -0
- package/core/probes/ui_audit.py +513 -0
- package/core/probes/ui_contract.py +273 -0
- package/core/probes/ui_evidence.py +212 -0
- package/core/probes/ui_measurements.py +314 -0
- package/core/probes/ui_repair.py +250 -0
- package/core/probes/ui_review.py +133 -0
- package/core/probes/ui_storybook.py +107 -0
- package/core/probes/ui_tokens.py +185 -0
- package/core/probes/ui_visual_diff.py +131 -0
- package/core/probes/web_probe.py +373 -18
- package/core/project_profiler/SPEC.md +1 -1
- package/core/project_profiler/arbitrator.py +6 -1
- package/core/project_profiler/detector.py +8 -1
- package/core/project_profiler/strategy.py +51 -15
- package/core/prompts/README.md +4 -2
- package/core/prompts/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_repair.md +1 -1
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/repair/README.md +1 -1
- package/core/repair/l7_repair_loop.py +1 -4
- package/core/repair/rsi_fixer.py +4 -4
- package/core/repair/rsi_loop.py +1 -3
- package/core/repair/rsi_repair.py +7 -7
- package/core/repair/rsi_scope.py +27 -8
- package/core/report_engine/SPEC.md +1 -1
- package/core/report_engine/attestation.py +8 -4
- package/core/report_engine/finding_report.py +2 -1
- package/core/report_engine/models.py +7 -9
- package/core/report_engine/report_share.py +0 -8
- package/core/report_engine/sast_bridge.py +2 -2
- package/core/report_engine/server.py +18 -8
- package/core/report_engine/web-conformance.md +123 -18
- package/core/report_engine/web_conformance.py +21 -52
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/SPEC.md +1 -1
- package/core/retrieval/code_analyzer.py +50 -14
- package/core/retrieval/context_assembler.py +7 -1
- package/core/retrieval/knowledge_sync.py +108 -14
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/retrieval/symbol_index.py +25 -6
- package/core/retrieval/universal_code_matcher.py +234 -49
- package/core/runtime/README.md +1 -1
- package/core/runtime/bugx_logging.py +78 -7
- package/core/runtime/fixture_solidify.py +5 -10
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/incident_eval.py +1 -1
- package/core/runtime/model_runner.py +4 -41
- package/core/runtime/platform_adapter.py +2 -2
- package/core/runtime/prep_validate.py +4 -2
- package/core/runtime/project_settings.py +2 -1
- package/core/runtime/scenario_eval.py +50 -8
- package/core/skills/bugx_docs_mcp_server.py +3 -1
- package/core/skills/bugx_mcp_server.py +29 -2
- package/core/skills/tools_kb.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/core/supervisor/SPEC.md +1 -1
- package/core/supervisor/budget_governor.py +503 -9
- package/core/supervisor/checkpoint_pipeline.py +248 -6
- package/core/supervisor/checkpoint_sync.py +13 -0
- package/core/supervisor/claim_events.py +1 -1
- package/core/supervisor/finding_workflow.py +22 -5
- package/core/supervisor/lease_manager.py +1 -1
- package/core/supervisor/lifecycle_blocks.py +6 -1
- package/core/supervisor/rejection_remedies.py +52 -5
- package/core/supervisor/serial_authorization.py +48 -4
- package/core/supervisor/task_scheduler.py +2 -2
- package/core/supervisor/worker_checkpoint.py +8 -1
- package/core/supervisor/worker_runtime.py +8 -2
- package/core/supervisor_types/worker_claim.py +9 -0
- package/core/webui/README.md +1 -1
- package/core/webui/SPEC.md +2 -1
- package/core/webui/adapters/claude.py +5 -1
- package/core/webui/adapters/cline.py +10 -2
- package/core/webui/adapters/codex.py +5 -1
- package/core/webui/adapters/dsh.py +5 -1
- package/core/webui/docs_session_service.py +2 -2
- package/core/webui/mcp_inspector.py +11 -7
- package/core/webui/static/00-base.css +1060 -0
- package/core/webui/static/01-monitoring.css +802 -0
- package/core/webui/static/02-header-actions.css +321 -0
- package/core/webui/static/03-trigger-popover.css +697 -0
- package/core/webui/static/04-composer.css +628 -0
- package/core/webui/static/05-skills-center.css +878 -0
- package/core/webui/static/06-mcp-center.css +623 -0
- package/core/webui/static/07-skill-detail.css +265 -0
- package/core/webui/static/08-files-management.css +167 -0
- package/core/webui/static/09-files-center.css +386 -0
- package/core/webui/static/10-icons.css +105 -0
- package/core/webui/static/11-project-options.css +185 -0
- package/core/webui/static/12-profile-tab.css +383 -0
- package/core/webui/static/design-tokens.css +113 -0
- package/core/webui/static/index.html +14 -1
- package/core/webui/workspace_service.py +1 -1
- package/docs/07_distribution/01_README_NPM.md +193 -185
- package/ecosystem/integrations/README.md +1 -1
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +4 -4
- package/ecosystem/integrations/opencode/mcp-lock.json +14 -6
- package/ecosystem/integrations/opencode/opencode.json +23 -12
- package/ecosystem/integrations/pi/extensions/bugx/manifest.json +1 -1
- package/ecosystem/integrations/qoder/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/connector-meta.json +1 -1
- package/ecosystem/integrations/workbuddy/skills/bugx/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/.claude-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.codex-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/.zcode-plugin/plugin.json +1 -1
- package/ecosystem/plugins/bugx/skills/bugx/SKILL.md +2 -2
- package/ecosystem/plugins/bugx/skills/bugx-dsh/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-opencode/SKILL.md +1 -1
- package/ecosystem/plugins/bugx/skills/bugx-zcode/SKILL.md +1 -1
- package/interfaces/bin/bugx.js +37 -0
- package/interfaces/cli/bugx_cli/__init__.py +4 -2
- package/interfaces/cli/bugx_cli/cli.py +172 -69
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +461 -134
- package/interfaces/cli/bugx_cli/commands/audit.py +10 -9
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +31 -22
- package/interfaces/cli/bugx_cli/commands/doctor.py +449 -204
- package/interfaces/cli/bugx_cli/commands/interaction.py +5 -1
- package/interfaces/cli/bugx_cli/commands/knowledge.py +5 -4
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +58 -23
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +7 -7
- package/interfaces/cli/bugx_cli/commands/plugin_funide.py +2 -1
- package/interfaces/cli/bugx_cli/commands/plugin_zcode.py +1 -1
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +524 -169
- package/interfaces/cli/bugx_cli/common.py +21 -15
- package/interfaces/cli/bugx_cli/host_adapters.py +29 -54
- package/interfaces/cli/bugx_cli/hosts/registry.py +8 -6
- package/interfaces/cli/bugx_cli/infra/ai_advisor.py +157 -27
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +35 -16
- package/interfaces/cli/bugx_cli/infra/host_sync.py +11 -8
- package/interfaces/cli/bugx_cli/infra/mcp_advisor.py +76 -5
- package/interfaces/cli/bugx_cli/infra/security.py +13 -6
- package/package.json +30 -15
- package/pyproject.toml +60 -9
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
- package/core/webui/static/project-settings.css +0 -6458
- package/docs/07_distribution/README.md +0 -16
- package/docs/README.md +0 -121
- package/interfaces/README.md +0 -143
- package/interfaces/bin/README.md +0 -35
- package/interfaces/cli/README.md +0 -90
- package/scripts/README.md +0 -118
|
@@ -47,9 +47,11 @@ from typing import Any, Mapping
|
|
|
47
47
|
|
|
48
48
|
if __package__:
|
|
49
49
|
from core.launch_phases.common import resolve_project_root, supervisor_state_path
|
|
50
|
+
from core.launch_phases import verify_loop
|
|
50
51
|
else: # pragma: no cover
|
|
51
52
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
52
53
|
from core.launch_phases.common import resolve_project_root, supervisor_state_path
|
|
54
|
+
from core.launch_phases import verify_loop
|
|
53
55
|
|
|
54
56
|
_SHELL_TOKENS = (";", "&&", "||", "`", "$(", ">", "<")
|
|
55
57
|
|
|
@@ -187,11 +189,25 @@ def confirm(
|
|
|
187
189
|
"""
|
|
188
190
|
from core.supervisor import audit_supervisor
|
|
189
191
|
from core.ledger import finding_confirmation
|
|
192
|
+
from core.ledger.finding_verification import (
|
|
193
|
+
diagnose_verification_error,
|
|
194
|
+
diagnose_verification_receipt,
|
|
195
|
+
snapshot_target_hashes,
|
|
196
|
+
validate_python_poc_pair,
|
|
197
|
+
verify_target_hashes_unchanged,
|
|
198
|
+
)
|
|
190
199
|
|
|
191
200
|
# 用模块级引用(可被测试替换);函数内重新 import 会绕过 monkeypatch。
|
|
192
201
|
root = resolve_project_root().resolve()
|
|
202
|
+
state_dir = supervisor_state_path().parent
|
|
193
203
|
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
194
204
|
state = supervisor.status()
|
|
205
|
+
findings_by_fp: dict[str, dict[str, Any]] = {}
|
|
206
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
207
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
208
|
+
f_fp = str(f_dict.get("fingerprint") or "").strip()
|
|
209
|
+
if f_fp:
|
|
210
|
+
findings_by_fp[f_fp] = f_dict
|
|
195
211
|
recipes = json.loads(Path(recipes_path).read_text(encoding="utf-8"))
|
|
196
212
|
if isinstance(recipes, dict):
|
|
197
213
|
recipes = [recipes]
|
|
@@ -212,6 +228,22 @@ def confirm(
|
|
|
212
228
|
print(f"[findings-confirm] ✗ oracle 文件不存在: {oracle_file}")
|
|
213
229
|
failed += 1
|
|
214
230
|
continue
|
|
231
|
+
vdir = verify_loop.verify_dir_for_finding(state_dir, fp)
|
|
232
|
+
finding_meta = findings_by_fp.get(fp, {"fingerprint": fp})
|
|
233
|
+
rel_file, _ = verify_loop._extract_target_file_and_line(finding_meta)
|
|
234
|
+
ast_diag = validate_python_poc_pair(
|
|
235
|
+
_strip_runner_wrapper(pos),
|
|
236
|
+
_strip_runner_wrapper(neg),
|
|
237
|
+
finding_key=fp,
|
|
238
|
+
attempt=1,
|
|
239
|
+
target_hints=(),
|
|
240
|
+
)
|
|
241
|
+
if ast_diag is not None:
|
|
242
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, ast_diag)
|
|
243
|
+
print(f"[findings-confirm] ✗ anti-gaming {fp[:44]} ({ast_diag.failure_code}): {ast_diag.summary} → {diag_path.name}")
|
|
244
|
+
failed += 1
|
|
245
|
+
continue
|
|
246
|
+
before_hashes = snapshot_target_hashes(root, [rel_file] if rel_file else [])
|
|
215
247
|
recipe = {
|
|
216
248
|
"positive": {"argv": _wrap_positive(pos),
|
|
217
249
|
"oracle": {"kind": "exit_code", "expected_exit_code": 1}},
|
|
@@ -222,11 +254,33 @@ def confirm(
|
|
|
222
254
|
"oracle_hash": hashlib.sha256(oracle_path.read_bytes()).hexdigest(),
|
|
223
255
|
}
|
|
224
256
|
try:
|
|
225
|
-
supervisor.verify_finding(finding=fp, recipe=recipe)
|
|
257
|
+
verify_res = supervisor.verify_finding(finding=fp, recipe=recipe)
|
|
226
258
|
except audit_supervisor.SupervisorError as exc:
|
|
227
|
-
|
|
259
|
+
diag = diagnose_verification_error(exc, attempt=1, finding_key=fp, stage="supervisor_verify")
|
|
260
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
261
|
+
print(f"[findings-confirm] ✗ verify {fp[:44]} ({diag.failure_code}): {str(exc)[:140]} → {diag_path.name}")
|
|
228
262
|
failed += 1
|
|
229
263
|
continue
|
|
264
|
+
tampered = verify_target_hashes_unchanged(root, before_hashes)
|
|
265
|
+
if tampered:
|
|
266
|
+
diag = diagnose_verification_error(
|
|
267
|
+
f"PoC modified target source file(s): {', '.join(tampered)}",
|
|
268
|
+
attempt=1, finding_key=fp, failure_code="source_tampered_rejected", stage="anti_tamper",
|
|
269
|
+
)
|
|
270
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
271
|
+
print(f"[findings-confirm] ✗ source-tampered {fp[:44]}: {tampered} → {diag_path.name}")
|
|
272
|
+
failed += 1
|
|
273
|
+
continue
|
|
274
|
+
receipt = verify_res.get("receipt") if isinstance(verify_res, Mapping) else {}
|
|
275
|
+
v_status = str(verify_res.get("status") or (receipt.get("status") if isinstance(receipt, Mapping) else ""))
|
|
276
|
+
if v_status and v_status != "CONFIRMED":
|
|
277
|
+
diag = diagnose_verification_receipt(receipt if isinstance(receipt, Mapping) else {}, attempt=1, finding_key=fp)
|
|
278
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
279
|
+
print(f"[findings-confirm] ✗ verify-not-confirmed {fp[:44]} ({diag.failure_code}): {diag.summary} → {diag_path.name}")
|
|
280
|
+
failed += 1
|
|
281
|
+
continue
|
|
282
|
+
# F-RSI-20261118-009 / P0-D04:从输入 item 读取定级补录(原从 recipe 读取恒为 None)
|
|
283
|
+
recipe_severity = str(item.get("severity") or "").strip() or None
|
|
230
284
|
try:
|
|
231
285
|
supervisor.confirm_finding(
|
|
232
286
|
finding=fp, decision="confirmed",
|
|
@@ -234,6 +288,7 @@ def confirm(
|
|
|
234
288
|
root_cause_verified=True,
|
|
235
289
|
oracle={"tier": "differential", "provenance_kind": "runtime-invariant",
|
|
236
290
|
"reference": oracle_file},
|
|
291
|
+
severity=recipe_severity,
|
|
237
292
|
)
|
|
238
293
|
print(f"[findings-confirm] ✓ confirmed {fp[:52]}")
|
|
239
294
|
done += 1
|
|
@@ -323,6 +378,98 @@ def _reject_triplet(value: str) -> tuple[str, str, str]:
|
|
|
323
378
|
return parts[0].strip(), parts[1].strip(), parts[2].strip()
|
|
324
379
|
|
|
325
380
|
|
|
381
|
+
def prepare_verify_bundles(
|
|
382
|
+
fingerprints: list[str] | None = None,
|
|
383
|
+
*,
|
|
384
|
+
max_attempts: int = verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
385
|
+
) -> int:
|
|
386
|
+
"""为 pending 候选生成独立验证员盲审包 VerifyBundle(P0 D-01)。"""
|
|
387
|
+
from core.supervisor import audit_supervisor
|
|
388
|
+
|
|
389
|
+
max_attempts = verify_loop.normalize_max_attempts(max_attempts)
|
|
390
|
+
root = resolve_project_root().resolve()
|
|
391
|
+
state_dir = supervisor_state_path().parent
|
|
392
|
+
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
393
|
+
state = supervisor.status()
|
|
394
|
+
wanted = {fp.strip() for fp in (fingerprints or []) if fp and fp.strip()}
|
|
395
|
+
|
|
396
|
+
generated: list[dict[str, str]] = []
|
|
397
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
398
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
399
|
+
confirmation = f_dict.get("confirmation")
|
|
400
|
+
if isinstance(confirmation, dict) and confirmation.get("decision"):
|
|
401
|
+
continue
|
|
402
|
+
fp = str(f_dict.get("fingerprint") or "").strip()
|
|
403
|
+
if not fp or (wanted and fp not in wanted):
|
|
404
|
+
continue
|
|
405
|
+
bundle_path, _ = verify_loop.build_verify_bundle(
|
|
406
|
+
root, state_dir, f_dict, attempt=1, max_attempts=max_attempts,
|
|
407
|
+
)
|
|
408
|
+
generated.append({"fingerprint": fp, "bundle_path": str(bundle_path)})
|
|
409
|
+
print(f"[findings-confirm] ✓ verify-bundle {fp[:48]} → {bundle_path}")
|
|
410
|
+
|
|
411
|
+
if not generated:
|
|
412
|
+
print("[findings-confirm] 未找到匹配的 pending 候选")
|
|
413
|
+
return 1
|
|
414
|
+
print(f"[findings-confirm] 已生成 {len(generated)} 份盲审 VerifyBundle(协议:core/prompts/stages/stage_verify.md)")
|
|
415
|
+
return 0
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def run_verify_attempt_file(
|
|
419
|
+
attempt_path: Path,
|
|
420
|
+
*,
|
|
421
|
+
max_attempts: int = verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
422
|
+
) -> int:
|
|
423
|
+
"""消费独立验证员提交的单轮 attempt JSON 并执行引擎验证/自纠错推进(P0 D-02~D-05)。"""
|
|
424
|
+
from core.supervisor import audit_supervisor
|
|
425
|
+
|
|
426
|
+
max_attempts = verify_loop.normalize_max_attempts(max_attempts)
|
|
427
|
+
root = resolve_project_root().resolve()
|
|
428
|
+
state_dir = supervisor_state_path().parent
|
|
429
|
+
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
430
|
+
state = supervisor.status()
|
|
431
|
+
findings_by_fp: dict[str, dict[str, Any]] = {}
|
|
432
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
433
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
434
|
+
f_fp = str(f_dict.get("fingerprint") or "").strip()
|
|
435
|
+
if f_fp:
|
|
436
|
+
findings_by_fp[f_fp] = f_dict
|
|
437
|
+
|
|
438
|
+
payload = json.loads(Path(attempt_path).read_text(encoding="utf-8"))
|
|
439
|
+
items = payload if isinstance(payload, list) else [payload]
|
|
440
|
+
settled_any = False
|
|
441
|
+
has_failure = False
|
|
442
|
+
|
|
443
|
+
for item in items:
|
|
444
|
+
if not isinstance(item, Mapping):
|
|
445
|
+
has_failure = True
|
|
446
|
+
continue
|
|
447
|
+
fp = str(item.get("fingerprint") or "").strip()
|
|
448
|
+
if not fp or fp not in findings_by_fp:
|
|
449
|
+
print(f"[findings-confirm] ✗ 未知 finding fingerprint: {fp[:48]}")
|
|
450
|
+
has_failure = True
|
|
451
|
+
continue
|
|
452
|
+
result = verify_loop.execute_verify_attempt(
|
|
453
|
+
root=root,
|
|
454
|
+
state_dir=state_dir,
|
|
455
|
+
supervisor=supervisor,
|
|
456
|
+
finding=findings_by_fp[fp],
|
|
457
|
+
positive=str(item.get("positive") or ""),
|
|
458
|
+
negative=str(item.get("negative") or ""),
|
|
459
|
+
max_attempts=max_attempts,
|
|
460
|
+
)
|
|
461
|
+
status = str(result.get("status") or "")
|
|
462
|
+
print(json.dumps(result, ensure_ascii=False))
|
|
463
|
+
if status in {"CONFIRMED", "REJECTED", "STALLED"}:
|
|
464
|
+
settled_any = True
|
|
465
|
+
if status not in {"CONFIRMED"}:
|
|
466
|
+
has_failure = True
|
|
467
|
+
|
|
468
|
+
if settled_any:
|
|
469
|
+
_materialize_findings(root, supervisor)
|
|
470
|
+
return 0 if not has_failure else 1
|
|
471
|
+
|
|
472
|
+
|
|
326
473
|
def build_parser() -> argparse.ArgumentParser:
|
|
327
474
|
"""``bugx engine findings-confirm`` 的**唯一**参数契约。
|
|
328
475
|
|
|
@@ -330,11 +477,11 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
330
477
|
Worker 指令都写 ``--recipe <recipe.json>`` / ``--all-pending``,但 ``main()``
|
|
331
478
|
只手工扫 ``--from-verdicts`` / ``--reject``,把 ``--recipe`` 当成位置参数,
|
|
332
479
|
于是文档里的标准调用一律报「缺少 recipe 文件」。参数契约收敛到这里,
|
|
333
|
-
|
|
480
|
+
文档与实现的双向一致契约以本注释为准。
|
|
334
481
|
"""
|
|
335
482
|
parser = argparse.ArgumentParser(
|
|
336
483
|
prog="bugx engine findings-confirm",
|
|
337
|
-
description="Finding
|
|
484
|
+
description="Finding 确认一条龙与独立验证员盲审闭环:校验 recipe / 盲审包 → 引擎双正例+负对照实跑 → 诊断自纠错 → 物化确认块。",
|
|
338
485
|
)
|
|
339
486
|
parser.add_argument(
|
|
340
487
|
"recipes", nargs="?", metavar="RECIPE",
|
|
@@ -357,6 +504,18 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
357
504
|
"--from-verdicts", action="store_true",
|
|
358
505
|
help="输入文件是 judge verdicts(自动生成 recipe)而不是 recipe 本身",
|
|
359
506
|
)
|
|
507
|
+
parser.add_argument(
|
|
508
|
+
"--prepare-verify", nargs="*", metavar="FP",
|
|
509
|
+
help="为指定(或全部 pending)候选生成独立验证员盲审包 VerifyBundle(P0)",
|
|
510
|
+
)
|
|
511
|
+
parser.add_argument(
|
|
512
|
+
"--verify-attempt", dest="verify_attempt", metavar="ATTEMPT_JSON",
|
|
513
|
+
help="提交独立验证员单轮输出 JSON,执行 Anti-Gaming + 双正例负对照 + 报错诊断推进(P0)",
|
|
514
|
+
)
|
|
515
|
+
parser.add_argument(
|
|
516
|
+
"--max-attempts", dest="max_attempts", type=int, default=verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
517
|
+
help=f"单条 Finding 报错自纠错最大重试次数(1..{verify_loop.HARD_MAX_ATTEMPTS},默认 {verify_loop.DEFAULT_MAX_ATTEMPTS})",
|
|
518
|
+
)
|
|
360
519
|
return parser
|
|
361
520
|
|
|
362
521
|
|
|
@@ -366,13 +525,19 @@ def main(argv: list[str]) -> int:
|
|
|
366
525
|
args = parser.parse_args(argv)
|
|
367
526
|
except SystemExit as exc: # argparse 用 exit(2) 表示用法错误
|
|
368
527
|
return int(exc.code or 2)
|
|
528
|
+
if args.prepare_verify is not None:
|
|
529
|
+
return prepare_verify_bundles(args.prepare_verify, max_attempts=args.max_attempts)
|
|
530
|
+
if args.verify_attempt:
|
|
531
|
+
return run_verify_attempt_file(Path(args.verify_attempt), max_attempts=args.max_attempts)
|
|
369
532
|
rejects: list[tuple[str, str, str]] = list(args.reject or [])
|
|
370
533
|
source = args.recipe_opt or args.recipes
|
|
371
534
|
if not source:
|
|
372
535
|
parser.print_usage()
|
|
373
536
|
print(
|
|
374
537
|
"用法:bugx engine findings-confirm --recipe <recipes.json> "
|
|
375
|
-
"[--all-pending] [--reject <fp>:<class>:<reason> ...]"
|
|
538
|
+
"[--all-pending] [--reject <fp>:<class>:<reason> ...]\n"
|
|
539
|
+
" 或:bugx engine findings-confirm --prepare-verify [FP ...]\n"
|
|
540
|
+
" 或:bugx engine findings-confirm --verify-attempt <attempt.json> [--max-attempts 3]"
|
|
376
541
|
)
|
|
377
542
|
return 2
|
|
378
543
|
if args.from_verdicts:
|
|
@@ -172,6 +172,174 @@ def _findings_binding_is_stale(path: Path, runtime: dict) -> bool:
|
|
|
172
172
|
)
|
|
173
173
|
|
|
174
174
|
|
|
175
|
+
def _finding_decision_state(item: Mapping[str, Any]) -> str:
|
|
176
|
+
"""裁决态归一:confirmed/rejected 之外(含确认块缺失或非法)一律 candidate。
|
|
177
|
+
|
|
178
|
+
与 auto_build 的口径一致——非法 confirmation 块会被 pop 掉,快照里等价于
|
|
179
|
+
candidate;这里不重复抛错,只做决定性归一。
|
|
180
|
+
"""
|
|
181
|
+
confirmation = item.get("confirmation") if isinstance(item, Mapping) else None
|
|
182
|
+
if isinstance(confirmation, Mapping):
|
|
183
|
+
state = str(confirmation.get("state") or "").strip().lower()
|
|
184
|
+
if state in {"confirmed", "rejected"}:
|
|
185
|
+
return state
|
|
186
|
+
return "candidate"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _finding_identity_keys(item: Mapping[str, Any]) -> list[str]:
|
|
190
|
+
"""finding 身份键(id / finding_id / fingerprint),去重保序。"""
|
|
191
|
+
keys: list[str] = []
|
|
192
|
+
for field_name in ("id", "finding_id", "fingerprint"):
|
|
193
|
+
value = str(item.get(field_name) or "").strip() if isinstance(item, Mapping) else ""
|
|
194
|
+
if value and value not in keys:
|
|
195
|
+
keys.append(value)
|
|
196
|
+
return keys
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def findings_json_stale_vs_authority(runtime: dict) -> str | None:
|
|
200
|
+
"""派生 findings.json 与 Supervisor 权威态的确认态/revision 一致性检查。
|
|
201
|
+
|
|
202
|
+
缺陷(2026-11-17 obs-2,dsh 重验实证):settle_findings_path 的 stale 判定
|
|
203
|
+
只看 run_id/lifecycle binding,同一 run 内**先于裁决**生成的 findings.json
|
|
204
|
+
会让 post 跳过 auto_build,把旧候选视图直接拿去结算(09:33 裁决后必须手动
|
|
205
|
+
删除派生文件)。这里追加两条从严信号:
|
|
206
|
+
|
|
207
|
+
* revision 信号:派生文件记录的 ``supervisor_binding.findings_revision``
|
|
208
|
+
落后于权威态(新 finding 已同步进 Supervisor 而视图未重建)→ stale;
|
|
209
|
+
* 确认态信号:权威终态(confirmed/rejected)必须在派生视图中以**同态**
|
|
210
|
+
出现——落后(candidate)或篡改反向(rejected↔confirmed)都是 stale;
|
|
211
|
+
权威 candidate 允许派生侧保留 candidate 或裁决器补证的 confirmed。
|
|
212
|
+
|
|
213
|
+
返回 None 表示一致(或无法可靠判定——交由快照校验兜底,绝不因检查自身
|
|
214
|
+
失败而放大阻断);返回字符串为 stale 原因,调用方应归档旧文件并重建。
|
|
215
|
+
"""
|
|
216
|
+
path = settle_findings_path(runtime)
|
|
217
|
+
if path is None or not path.is_file() or path.is_symlink():
|
|
218
|
+
return None
|
|
219
|
+
try:
|
|
220
|
+
derived = json.loads(path.read_text(encoding="utf-8"))
|
|
221
|
+
except (OSError, ValueError):
|
|
222
|
+
return None
|
|
223
|
+
if not isinstance(derived, dict):
|
|
224
|
+
return None
|
|
225
|
+
derived_findings = derived.get("findings")
|
|
226
|
+
if not isinstance(derived_findings, list):
|
|
227
|
+
return None
|
|
228
|
+
root = Path(os.path.abspath(os.fspath(resolve_project_root())))
|
|
229
|
+
from core.launch_phases.post_dry_run import RootReader, SnapshotInvalid
|
|
230
|
+
|
|
231
|
+
authority_reader = None
|
|
232
|
+
close_authority = False
|
|
233
|
+
try:
|
|
234
|
+
try:
|
|
235
|
+
project_reader = RootReader(root)
|
|
236
|
+
except SnapshotInvalid:
|
|
237
|
+
return None
|
|
238
|
+
try:
|
|
239
|
+
supervisor_payload, authority_reader, close_authority = (
|
|
240
|
+
_load_authoritative_supervisor(runtime, root, project_reader)
|
|
241
|
+
)
|
|
242
|
+
finally:
|
|
243
|
+
project_reader.close()
|
|
244
|
+
if not isinstance(supervisor_payload, dict):
|
|
245
|
+
return None
|
|
246
|
+
authority_findings = supervisor_payload.get("findings")
|
|
247
|
+
if not isinstance(authority_findings, list):
|
|
248
|
+
return None
|
|
249
|
+
# 信号一:finding 同步代 revision(新增 finding 未进派生视图)。
|
|
250
|
+
binding = derived.get("supervisor_binding")
|
|
251
|
+
if isinstance(binding, Mapping):
|
|
252
|
+
recorded_raw = binding.get("findings_revision")
|
|
253
|
+
recorded = recorded_raw if (
|
|
254
|
+
isinstance(recorded_raw, int) and not isinstance(recorded_raw, bool)
|
|
255
|
+
) else None
|
|
256
|
+
authority_revision = supervisor_payload.get("findings_revision")
|
|
257
|
+
if (
|
|
258
|
+
recorded is not None
|
|
259
|
+
and isinstance(authority_revision, int)
|
|
260
|
+
and not isinstance(authority_revision, bool)
|
|
261
|
+
and recorded != authority_revision
|
|
262
|
+
):
|
|
263
|
+
return (
|
|
264
|
+
f"supervisor_binding.findings_revision={recorded} 落后于权威态 "
|
|
265
|
+
f"{authority_revision}"
|
|
266
|
+
)
|
|
267
|
+
# 信号二:逐条确认态必须不落后于权威终态。
|
|
268
|
+
derived_index: dict[str, list[dict]] = {}
|
|
269
|
+
for item in derived_findings:
|
|
270
|
+
if isinstance(item, dict):
|
|
271
|
+
for key in _finding_identity_keys(item):
|
|
272
|
+
derived_index.setdefault(key, []).append(item)
|
|
273
|
+
matched: set[int] = set()
|
|
274
|
+
for authority in authority_findings:
|
|
275
|
+
if not isinstance(authority, dict):
|
|
276
|
+
continue
|
|
277
|
+
label = str(authority.get("id") or authority.get("fingerprint") or "?")
|
|
278
|
+
candidates: list[dict] = []
|
|
279
|
+
seen: set[int] = set()
|
|
280
|
+
for key in _finding_identity_keys(authority):
|
|
281
|
+
for item in derived_index.get(key, []):
|
|
282
|
+
marker = id(item)
|
|
283
|
+
if marker not in seen:
|
|
284
|
+
seen.add(marker)
|
|
285
|
+
candidates.append(item)
|
|
286
|
+
if len(candidates) != 1:
|
|
287
|
+
return f"权威 finding {label} 在派生视图中缺失或不唯一"
|
|
288
|
+
derived_item = candidates[0]
|
|
289
|
+
matched.add(id(derived_item))
|
|
290
|
+
authority_state = _finding_decision_state(authority)
|
|
291
|
+
derived_state = _finding_decision_state(derived_item)
|
|
292
|
+
if authority_state in {"confirmed", "rejected"}:
|
|
293
|
+
if derived_state != authority_state:
|
|
294
|
+
return (
|
|
295
|
+
f"权威 finding {label} 终态={authority_state},"
|
|
296
|
+
f"派生视图为 {derived_state}(落后或反向)"
|
|
297
|
+
)
|
|
298
|
+
elif derived_state == "rejected":
|
|
299
|
+
return f"权威 finding {label} 是 candidate,派生视图却是 rejected"
|
|
300
|
+
for item in derived_findings:
|
|
301
|
+
if isinstance(item, dict) and id(item) not in matched:
|
|
302
|
+
return "派生视图存在权威态之外的 finding"
|
|
303
|
+
return None
|
|
304
|
+
except FindingsSnapshotError:
|
|
305
|
+
return None
|
|
306
|
+
except Exception:
|
|
307
|
+
return None
|
|
308
|
+
finally:
|
|
309
|
+
if close_authority and authority_reader is not None:
|
|
310
|
+
try:
|
|
311
|
+
authority_reader.close()
|
|
312
|
+
except Exception:
|
|
313
|
+
pass
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def refresh_stale_findings_json(runtime: dict) -> str | None:
|
|
317
|
+
"""post auto_build 前置刷新:派生视图落后于权威态时归档旧文件并放行重建。
|
|
318
|
+
|
|
319
|
+
与 :func:`archive_stale_findings_binding`(跨 run 的 binding 归档)互补:
|
|
320
|
+
本函数处理**同 run 内**确认态/revision 落后。一致文件不动(幂等);判定
|
|
321
|
+
为 stale 时把旧文件改名 ``.stale-backup``(冲突时追加时间戳,绝不覆盖)
|
|
322
|
+
并返回人读原因,settle_findings_path 随即返回 None,调用方走 auto_build
|
|
323
|
+
从权威态重建。
|
|
324
|
+
"""
|
|
325
|
+
if settle_findings_path(runtime) is None:
|
|
326
|
+
return None
|
|
327
|
+
reason = findings_json_stale_vs_authority(runtime)
|
|
328
|
+
if reason is None:
|
|
329
|
+
return None
|
|
330
|
+
path = settle_findings_path(runtime)
|
|
331
|
+
if path is None or not path.is_file():
|
|
332
|
+
return None
|
|
333
|
+
backup = path.with_name(path.name + ".stale-backup")
|
|
334
|
+
if backup.exists():
|
|
335
|
+
backup = path.with_name(f"{path.name}.stale-backup-{int(time.time())}")
|
|
336
|
+
os.replace(path, backup)
|
|
337
|
+
return (
|
|
338
|
+
f"派生 findings.json 落后于 Supervisor 权威态({reason});"
|
|
339
|
+
f"已归档为 {backup.name},将从权威态重建"
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
|
|
175
343
|
def _lifecycle_findings_path(runtime: dict) -> Path:
|
|
176
344
|
return lifecycle_root_for(runtime) / "findings.json"
|
|
177
345
|
|
|
@@ -355,7 +523,12 @@ def gate_confirmed_findings(
|
|
|
355
523
|
# 收集未终态候选的详细信息以供宿主 Agent 智能升阶
|
|
356
524
|
pending_ids = [
|
|
357
525
|
str(f.get("id"))
|
|
358
|
-
|
|
526
|
+
# F-RSI-20261112-080:`.get("confirmation", {})` 的默认值只在键
|
|
527
|
+
# 缺失时生效——键存在但为 null 时拿到 None,直链 .get 即
|
|
528
|
+
# AttributeError,整个结算门禁以未处理异常形态崩溃(is_confirmed
|
|
529
|
+
# 走 _confirmation 的 isinstance 防御不崩,两处语义漂移)。
|
|
530
|
+
# `or {}` 同时覆盖缺失与 null。
|
|
531
|
+
for f in findings if not finding_confirmation.is_confirmed(f) and (f.get("confirmation") or {}).get("state") != "rejected"
|
|
359
532
|
]
|
|
360
533
|
escalation_note = (
|
|
361
534
|
f"findings 存在 {pending} 个未终态候选({', '.join(pending_ids[:5])}),计命结算被拒:"
|
|
@@ -592,6 +765,14 @@ def _sum_token_records(value: object) -> int:
|
|
|
592
765
|
Supervisor snapshots have existed with both an aggregate field and a
|
|
593
766
|
per-lease mapping. Once an aggregate is present it is authoritative for
|
|
594
767
|
that subtree; otherwise nested records are summed.
|
|
768
|
+
|
|
769
|
+
契约(F-RSI-20261112-082 取证固化,2026-11-12):``_TOKEN_COLLECTIONS``
|
|
770
|
+
命中后只消费该子树(丢弃兄弟键)——这在当前真实 schema 链上不可达:
|
|
771
|
+
RunState.to_dict 顶层不经本函数(``_supervisor_token_total`` 显式分层),
|
|
772
|
+
claims dict 的键是 worker_id,claim/unit 记录必先命中 _TOKEN_FIELDS 的
|
|
773
|
+
``tokens_consumed`` 聚合字段。若未来新增「collection 键与 token 携带键
|
|
774
|
+
并存」的写入形态,必须同步扩展 ``_supervisor_token_total`` 的分层或把
|
|
775
|
+
兄弟键并入求和,否则兄弟 token 会被静默丢弃。
|
|
595
776
|
"""
|
|
596
777
|
if isinstance(value, Mapping):
|
|
597
778
|
for key in _TOKEN_FIELDS:
|
|
@@ -1114,6 +1295,12 @@ def auto_build_findings_json(runtime: dict) -> str | None:
|
|
|
1114
1295
|
"lifecycle_id": lifecycle_id,
|
|
1115
1296
|
"round": round_no,
|
|
1116
1297
|
},
|
|
1298
|
+
# obs-2(2026-11-17):记录构建时的权威 finding 同步代,供
|
|
1299
|
+
# findings_json_stale_vs_authority 检测"先于裁决/后续同步生成的
|
|
1300
|
+
# 陈旧派生视图";确认态一致性由逐条 confirmation 对比兜底。
|
|
1301
|
+
"supervisor_binding": {
|
|
1302
|
+
"findings_revision": supervisor_payload.get("findings_revision"),
|
|
1303
|
+
},
|
|
1117
1304
|
"findings": merged,
|
|
1118
1305
|
}
|
|
1119
1306
|
try:
|
|
@@ -481,20 +481,38 @@ def _merge_fingerprint_variants(state: Any, findings: list[dict[str, Any]]) -> i
|
|
|
481
481
|
return out
|
|
482
482
|
|
|
483
483
|
def slug_tokens(fingerprint: str) -> set[str]:
|
|
484
|
-
"""指纹最后一段短 slug 的语义词集合(≥3 字符;过滤通用词)。
|
|
484
|
+
"""指纹最后一段短 slug 的语义词集合(≥3 字符;过滤通用词)。
|
|
485
|
+
|
|
486
|
+
F-RSI-20261110-019 v2:通用词表补 app/web/ui/api/lib/util——这些词
|
|
487
|
+
在骨架型 slug(app-crash-loop / api-key-leak / web-socket-timeout)
|
|
488
|
+
里精确共享会造成「不同缺陷同词」误并,与 src/core/py 同性质。
|
|
489
|
+
"""
|
|
485
490
|
slug = fingerprint.rsplit("::", 1)[-1]
|
|
486
|
-
generic = {"src", "core", "py", "test", "tests", "main", "module"
|
|
491
|
+
generic = {"src", "core", "py", "test", "tests", "main", "module",
|
|
492
|
+
"app", "web", "ui", "api", "lib", "util"}
|
|
487
493
|
return {
|
|
488
494
|
tok.lower() for tok in re.split(r"[-_]", slug)
|
|
489
495
|
if len(tok) >= 3 and tok.lower() not in generic
|
|
490
496
|
}
|
|
491
497
|
|
|
492
498
|
def tokens_related(t1: set[str], t2: set[str]) -> bool:
|
|
493
|
-
"""
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
499
|
+
"""F-RSI-20261110-019 v2 误并向修复:判据从「任意前缀对」收紧为
|
|
500
|
+
「精确共享 token」或「≥2 个前缀关系 token 对」。
|
|
501
|
+
|
|
502
|
+
- 精确共享:同缺陷变体几乎必然共享缺陷名词(injection/traversal/
|
|
503
|
+
fstring)——sql-injection vs sqli-injection 精确共享 injection。
|
|
504
|
+
- ≥2 前缀对:纯缩写变体(path-traversal-read vs pth-traversal-write
|
|
505
|
+
的 pth/path + traversal)仍归并。
|
|
506
|
+
- 单一 3 字符前缀对不再归并:sqlite/sql、auth/author、eval/evaluator
|
|
507
|
+
是**不同缺陷**共享字母偶然前缀(红探针 A1-A3 实锤误并)。
|
|
508
|
+
"""
|
|
509
|
+
if t1 & t2:
|
|
510
|
+
return True
|
|
511
|
+
prefix_pairs = sum(
|
|
512
|
+
1 for a in t1 for b in t2
|
|
513
|
+
if a.startswith(b) or b.startswith(a)
|
|
497
514
|
)
|
|
515
|
+
return prefix_pairs >= 2
|
|
498
516
|
|
|
499
517
|
merged = 0
|
|
500
518
|
existing = [
|
|
@@ -518,6 +536,27 @@ def _merge_fingerprint_variants(state: Any, findings: list[dict[str, Any]]) -> i
|
|
|
518
536
|
return merged
|
|
519
537
|
|
|
520
538
|
|
|
539
|
+
def _roundup_package(slug: str, judge_dir: Path) -> dict[str, Any] | None:
|
|
540
|
+
"""取该单元最新的 roundup 增广包(F-RSI-20261115-120)。
|
|
541
|
+
|
|
542
|
+
无 round_no 的历史包不参与一跳判定(视为历史数据跳过);同 slug 多包
|
|
543
|
+
时取目录时间戳最新的一个。目录不可读或解析失败返回 None。"""
|
|
544
|
+
best: tuple[float, Path] | None = None
|
|
545
|
+
for p in judge_dir.glob(f"roundup-*/{slug}.json"):
|
|
546
|
+
try:
|
|
547
|
+
ts = float(p.parent.name.split("-", 1)[1])
|
|
548
|
+
except (IndexError, ValueError):
|
|
549
|
+
ts = p.stat().st_mtime
|
|
550
|
+
if best is None or ts > best[0]:
|
|
551
|
+
best = (ts, p)
|
|
552
|
+
if best is None:
|
|
553
|
+
return None
|
|
554
|
+
try:
|
|
555
|
+
return json.loads(best[1].read_text(encoding="utf-8"))
|
|
556
|
+
except (OSError, json.JSONDecodeError):
|
|
557
|
+
return None
|
|
558
|
+
|
|
559
|
+
|
|
521
560
|
def settle(verdicts_path: Path) -> int:
|
|
522
561
|
"""裁决收口:复现实跑取证 + 机械 checkpoint。"""
|
|
523
562
|
root = resolve_project_root()
|
|
@@ -531,6 +570,14 @@ def settle(verdicts_path: Path) -> int:
|
|
|
531
570
|
state = supervisor.status()
|
|
532
571
|
fingerprint = state.target_fingerprint or supervisor.target_fingerprint
|
|
533
572
|
accepted = rejected = 0
|
|
573
|
+
# F-RSI-20261112-079:无合法 verdict 条目时旧实现返回 rc=0(accepted=0
|
|
574
|
+
# rejected=0 的「假成功」)——输入垃圾文件与全部成功不可区分,宿主会
|
|
575
|
+
# 把结账失败当完成。诚实 rc:零合法条目=结账未发生=rc 1。
|
|
576
|
+
if not any(
|
|
577
|
+
isinstance(v, Mapping) and v.get("unit_id") for v in verdicts
|
|
578
|
+
):
|
|
579
|
+
print(f"[judge] ✗ {verdicts_path} 内没有可结算的 verdict 条目(缺 unit_id 或非对象),拒绝假成功")
|
|
580
|
+
return 1
|
|
534
581
|
for verdict in verdicts:
|
|
535
582
|
if not isinstance(verdict, Mapping) or not verdict.get("unit_id"):
|
|
536
583
|
continue
|
|
@@ -559,10 +606,16 @@ def settle(verdicts_path: Path) -> int:
|
|
|
559
606
|
battery_evidence = _battery_evidence_for(root, claim_state)
|
|
560
607
|
requests = verdict.get("probe_requests")
|
|
561
608
|
slug_u = judge_pipeline.unit_parts(unit_id)[0].replace("/", "_") or "unit"
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
609
|
+
current_round = int(getattr(state, "round_no", 1) or 1)
|
|
610
|
+
# F-RSI-20261115-120:一跳上限绑定当前轮(用户裁决 2026-11-15:每轮
|
|
611
|
+
# 全量重测,上轮忽视细节轮间必须可再探)——旧实现 glob 全部历史
|
|
612
|
+
# roundup 目录使禁令跨轮永续。轮内仍保持一跳(防 judge 反复要探针失控)。
|
|
613
|
+
round_pkg = _roundup_package(slug_u, _judge_dir())
|
|
614
|
+
if (round_pkg is not None
|
|
615
|
+
and int(round_pkg.get("round_no") or 0) == current_round):
|
|
616
|
+
requests = None # 本轮已定向探针过,禁止本轮内二跳
|
|
617
|
+
print(f"[judge] ⛔ {unit_id} 本轮已定向探针过(一跳上限),剥除重复探针请求")
|
|
618
|
+
_judge_log("hop_cap_stripped", unit=unit_id, round_no=current_round)
|
|
566
619
|
if (verdict.get("verdict") == "insufficient_data"
|
|
567
620
|
and requests and not verdict.get("probe_round")):
|
|
568
621
|
# 定向探针一跳:宿主执行 judge 指定的探针,把增广证据打包回给
|
|
@@ -580,6 +633,7 @@ def settle(verdicts_path: Path) -> int:
|
|
|
580
633
|
unit_id, root, battery_evidence + probe_evidence)
|
|
581
634
|
if augmented is not None:
|
|
582
635
|
augmented["probe_round"] = 1
|
|
636
|
+
augmented["round_no"] = current_round # F-RSI-20261115-120:一跳判定按轮
|
|
583
637
|
augmented["_claim"] = {
|
|
584
638
|
"worker_id": worker_id,
|
|
585
639
|
"lease_id": claim_state.lease_id,
|
|
@@ -614,10 +668,14 @@ def settle(verdicts_path: Path) -> int:
|
|
|
614
668
|
verdict, battery_evidence, reproduction,
|
|
615
669
|
)
|
|
616
670
|
if payload is None:
|
|
671
|
+
# F-RSI-20261112-079:防御分支(上游唯一 None 条件=unit_ids 空,
|
|
672
|
+
# 与 claim_state 命中条件互斥,常态不可达)——保留兜底但 id 必须
|
|
673
|
+
# 与正常路径同构含 uuid 段,防止同 worker 多次 blocked 撞
|
|
674
|
+
# checkpoint 幂等分支的「payload 不一致拒绝重放」。
|
|
617
675
|
print(f"[judge] {unit_id}:无可绑定证据,标 blocked")
|
|
618
676
|
supervisor.submit_checkpoint(
|
|
619
677
|
worker_id,
|
|
620
|
-
checkpoint_id=f"judge-{worker_id}-blocked",
|
|
678
|
+
checkpoint_id=f"judge-{worker_id}-blocked-{uuid.uuid4().hex[:8]}",
|
|
621
679
|
coverage={unit_id: "blocked"},
|
|
622
680
|
notes={unit_id: "judge battery produced no bindable evidence"},
|
|
623
681
|
)
|
|
@@ -731,7 +789,6 @@ def settle_dir(path: Path) -> int:
|
|
|
731
789
|
continue
|
|
732
790
|
if data is None:
|
|
733
791
|
continue
|
|
734
|
-
continue
|
|
735
792
|
entries = data if isinstance(data, list) else [data]
|
|
736
793
|
for entry in entries:
|
|
737
794
|
# PE-20261109-003:目录收割只认显式 verdict 字段。带 unit_id 但缺
|
|
@@ -32,6 +32,7 @@ from core.launch_phases.common import (
|
|
|
32
32
|
VERIFY,
|
|
33
33
|
child_environment,
|
|
34
34
|
format_duration,
|
|
35
|
+
option_value as _common_option_value,
|
|
35
36
|
resolve_project_root,
|
|
36
37
|
run_verify_life,
|
|
37
38
|
uses_project_layout,
|
|
@@ -78,13 +79,7 @@ from core.launch_phases.supervisor_bridge import (
|
|
|
78
79
|
get_supervisor,
|
|
79
80
|
)
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
for i, arg in enumerate(args):
|
|
83
|
-
if arg == option:
|
|
84
|
-
return args[i + 1] if i + 1 < len(args) else None
|
|
85
|
-
if arg.startswith(f"{option}="):
|
|
86
|
-
return arg.split("=", 1)[1]
|
|
87
|
-
return None
|
|
82
|
+
_option_value = _common_option_value
|
|
88
83
|
|
|
89
84
|
|
|
90
85
|
#: 公开别名:同包延迟导入方(candidate_revalidation)必须用公开名——架构棘轮
|
|
@@ -653,6 +648,15 @@ def print_help() -> int:
|
|
|
653
648
|
`name==version --hash=sha256:<64hex>`。安装强制
|
|
654
649
|
--require-hashes --no-deps --only-binary=:all:,
|
|
655
650
|
在中性临时目录执行且清空 PIP_*/PYTHON* 环境变量
|
|
651
|
+
judge [选项] 对 pending 单元批量预占+电池取证并输出判读包
|
|
652
|
+
(--all 按文件分组一次领完;--settle <verdicts.json>
|
|
653
|
+
裁决收口;--settle-dir <dir> 收割目录统一结算)
|
|
654
|
+
findings-confirm [选项] Finding 确认门禁:对已裁决候选做终态确认
|
|
655
|
+
coverage <子命令> 覆盖治理(review-packages/review-apply/status 等,
|
|
656
|
+
见 bugx engine coverage --help)
|
|
657
|
+
audit [选项] 在隔离副本中启动图审计或全息攻防渗透审计
|
|
658
|
+
prompt [--stage <name>] 输出指定阶段的 Stage Harness 任务包
|
|
659
|
+
daemon [选项] 自治持续挖掘常驻守护进程管理
|
|
656
660
|
help | --help | -h 显示本说明
|
|
657
661
|
|
|
658
662
|
保护边界
|
|
@@ -417,8 +417,15 @@ def close_session(final_round_id: str | None = None, *, reason: str = "completed
|
|
|
417
417
|
"rounds_count": int(state.get("polling_round", 1) or 1),
|
|
418
418
|
"status": final_state,
|
|
419
419
|
})
|
|
420
|
-
except Exception:
|
|
421
|
-
|
|
420
|
+
except Exception as exc:
|
|
421
|
+
# F-RSI-20261113-112:遥测上报失败不得静默——tokens_consumed 是
|
|
422
|
+
# 全局每日预算熔断(DOC-049)与账单观测的输入,静默丢失=计量
|
|
423
|
+
# 缺口。fail-open 保留(遥测不阻断结算),但缺口必须可观测
|
|
424
|
+
# (F-104/106/109 同款守卫系列第 4 处)。
|
|
425
|
+
print(
|
|
426
|
+
f"[post] ⚠ 会话遥测上报失败(全局 token 计量将缺口本次消耗): {exc}",
|
|
427
|
+
file=sys.stderr,
|
|
428
|
+
)
|
|
422
429
|
return runtime_summary(current)
|
|
423
430
|
|
|
424
431
|
|