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
|
@@ -94,6 +94,13 @@ _EXECUTION_RECEIPT_FIELDS = frozenset({
|
|
|
94
94
|
_POC_CARRY_FIELDS = ("poc_cmd", "poc_input", "poc_negative_input")
|
|
95
95
|
MAX_CHECKPOINT_BYTES = 512 * 1024
|
|
96
96
|
_STAGED_EVIDENCE_TTL_NS = 10 * 60 * 1_000_000_000
|
|
97
|
+
# DEF-2:证据校验拒绝的有界自纠回路。首次校验 + ≤2 轮自纠 = 最多 3 次评估
|
|
98
|
+
# 机会;同因第三次仍失败则按既有语义中止并如实记录。自纠只做"真相保持"的
|
|
99
|
+
# 格式改写(path:line 拆分 / file→path 键名 / workspace 内绝对路径相对化 /
|
|
100
|
+
# 反斜杠归一 / line 数字字符串转整数),每一步改写都必须重新通过原契约的
|
|
101
|
+
# 真实文件校验才被采纳——契约本身不放宽,伪造 path 无法被自纠成有效证据。
|
|
102
|
+
MAX_EVIDENCE_SELFCORRECTION_ROUNDS = 2
|
|
103
|
+
_EVIDENCE_FEEDBACK_MAX_CHARS = 1600
|
|
97
104
|
|
|
98
105
|
|
|
99
106
|
def _preserve_poc_carry_fields(item: dict[str, object]) -> None:
|
|
@@ -517,6 +524,198 @@ def _verify_observation_artifacts(finding: dict, workspace_root: Path) -> list[s
|
|
|
517
524
|
return verify_observation_artifacts(finding, workspace_root)
|
|
518
525
|
|
|
519
526
|
|
|
527
|
+
def _repair_evidence_item(item: object, root: Path) -> object:
|
|
528
|
+
"""单条 evidence 项的真相保持格式自纠;无有效改写时原样返回。
|
|
529
|
+
|
|
530
|
+
每个候选改写必须通过 ``agent_eval.evidence_item_valid``(与契约同一
|
|
531
|
+
判定)才被采纳:自纠只能把"真实证据的格式写错"修正为契约形状,
|
|
532
|
+
绝不构造、猜测或放宽任何事实。DEF-2。
|
|
533
|
+
"""
|
|
534
|
+
from core.agent import agent_eval
|
|
535
|
+
|
|
536
|
+
if not isinstance(item, dict):
|
|
537
|
+
# "path:line" 字符串(worker 指令明令禁止的写法):按最后一处冒号
|
|
538
|
+
# 拆分;仅当拆分结果落在真实 workspace 文件上才采纳。
|
|
539
|
+
if isinstance(item, str):
|
|
540
|
+
text = item.strip()
|
|
541
|
+
path_part, sep, line_part = text.rpartition(":")
|
|
542
|
+
if (
|
|
543
|
+
sep
|
|
544
|
+
and path_part.strip()
|
|
545
|
+
and line_part.isdigit()
|
|
546
|
+
and len(line_part) <= 7
|
|
547
|
+
):
|
|
548
|
+
candidate: dict[str, object] = {
|
|
549
|
+
"path": path_part.strip(),
|
|
550
|
+
"line": int(line_part),
|
|
551
|
+
}
|
|
552
|
+
candidate = _repair_evidence_item(candidate, root)
|
|
553
|
+
if isinstance(candidate, dict) and agent_eval.evidence_item_valid(
|
|
554
|
+
candidate, root,
|
|
555
|
+
):
|
|
556
|
+
return candidate
|
|
557
|
+
return item
|
|
558
|
+
repaired = dict(item)
|
|
559
|
+
path = repaired.get("path")
|
|
560
|
+
if not isinstance(path, str) or not path.strip():
|
|
561
|
+
# {"file": ...} 键名自纠:worker 指令契约键是 path。
|
|
562
|
+
file_value = repaired.pop("file", None)
|
|
563
|
+
if isinstance(file_value, str) and file_value.strip():
|
|
564
|
+
repaired["path"] = file_value
|
|
565
|
+
path = repaired["path"]
|
|
566
|
+
if isinstance(path, str):
|
|
567
|
+
raw = path.strip()
|
|
568
|
+
candidate_path = Path(raw)
|
|
569
|
+
if candidate_path.is_absolute():
|
|
570
|
+
# workspace 内绝对路径 → 相对化(仍须是真实文件)。
|
|
571
|
+
try:
|
|
572
|
+
rel = candidate_path.resolve(strict=True).relative_to(
|
|
573
|
+
root.resolve()
|
|
574
|
+
)
|
|
575
|
+
raw = rel.as_posix()
|
|
576
|
+
except (OSError, ValueError):
|
|
577
|
+
pass
|
|
578
|
+
elif "\\" in raw:
|
|
579
|
+
# Windows 分隔符笔误 → 正斜杠(POSIX 语义下的格式自纠)。
|
|
580
|
+
raw = raw.replace("\\", "/")
|
|
581
|
+
if (
|
|
582
|
+
raw != path
|
|
583
|
+
and agent_eval.evidence_item_valid({**repaired, "path": raw}, root)
|
|
584
|
+
):
|
|
585
|
+
repaired["path"] = raw
|
|
586
|
+
# line 数字字符串 → int(仍须通过行数校验;布尔/越界一律不自纠)。
|
|
587
|
+
line = repaired.get("line")
|
|
588
|
+
if isinstance(line, str) and line.strip().isdigit():
|
|
589
|
+
candidate = dict(repaired)
|
|
590
|
+
candidate["line"] = int(line.strip())
|
|
591
|
+
if agent_eval.evidence_item_valid(candidate, root):
|
|
592
|
+
repaired = candidate
|
|
593
|
+
if repaired != item and agent_eval.evidence_item_valid(repaired, root):
|
|
594
|
+
return repaired
|
|
595
|
+
return item
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def _repair_finding_evidence(finding: dict, root: Path) -> dict | None:
|
|
599
|
+
"""对单个 finding 的 evidence 数组做有界格式自纠;无改写返回 None。"""
|
|
600
|
+
evidence = finding.get("evidence")
|
|
601
|
+
if not isinstance(evidence, list):
|
|
602
|
+
return None
|
|
603
|
+
changed = False
|
|
604
|
+
new_evidence: list[object] = []
|
|
605
|
+
for item in evidence:
|
|
606
|
+
repaired = _repair_evidence_item(item, root)
|
|
607
|
+
if repaired != item:
|
|
608
|
+
changed = True
|
|
609
|
+
new_evidence.append(repaired)
|
|
610
|
+
if not changed:
|
|
611
|
+
return None
|
|
612
|
+
repaired_finding = dict(finding)
|
|
613
|
+
repaired_finding["evidence"] = new_evidence
|
|
614
|
+
return repaired_finding
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
def finding_evidence_rejections(
|
|
618
|
+
findings: list[dict], workspace_root: Path,
|
|
619
|
+
) -> list[dict]:
|
|
620
|
+
"""结构化拒绝原因:每个证据无效 finding 的逐项违规(回注原料)。"""
|
|
621
|
+
from core.agent import agent_eval
|
|
622
|
+
|
|
623
|
+
records: list[dict] = []
|
|
624
|
+
for finding in findings:
|
|
625
|
+
violations = agent_eval.finding_evidence_violations(finding, workspace_root)
|
|
626
|
+
if violations:
|
|
627
|
+
records.append({
|
|
628
|
+
"finding_id": str(
|
|
629
|
+
finding.get("id") or finding.get("fingerprint") or "<unnamed>"
|
|
630
|
+
),
|
|
631
|
+
"violations": violations,
|
|
632
|
+
"correct_sample": agent_eval.CORRECT_EVIDENCE_SAMPLE,
|
|
633
|
+
})
|
|
634
|
+
return records
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def selfcorrect_finding_evidence(
|
|
638
|
+
findings: list[dict],
|
|
639
|
+
workspace_root: Path,
|
|
640
|
+
*,
|
|
641
|
+
max_rounds: int = MAX_EVIDENCE_SELFCORRECTION_ROUNDS,
|
|
642
|
+
) -> tuple[list[dict], list[dict]]:
|
|
643
|
+
"""DEF-2 有界证据自纠回路(finalize 有界重提语义的管道内等效通道)。
|
|
644
|
+
|
|
645
|
+
每轮先把当前违规 finding 的结构化拒绝原因记录下来(回注原料),再做
|
|
646
|
+
真相保持的格式改写,随后按**原契约**全量复检;最多 ``max_rounds`` 轮
|
|
647
|
+
(默认 2,与首次校验合计 3 次评估机会)。同因第三次仍失败由调用方按
|
|
648
|
+
既有语义中止;轮次记录如实保留每一轮的拒绝原因供回写与诊断。
|
|
649
|
+
返回 ``(自纠后的 findings, 轮次记录列表)``。
|
|
650
|
+
"""
|
|
651
|
+
from core.agent import agent_eval
|
|
652
|
+
|
|
653
|
+
rounds: list[dict] = []
|
|
654
|
+
current = findings
|
|
655
|
+
for round_no in range(1, max_rounds + 1):
|
|
656
|
+
rejection_records = finding_evidence_rejections(current, workspace_root)
|
|
657
|
+
if not rejection_records:
|
|
658
|
+
break
|
|
659
|
+
rejected_ids = {record["finding_id"] for record in rejection_records}
|
|
660
|
+
repaired: list[dict] = []
|
|
661
|
+
repaired_ids: list[str] = []
|
|
662
|
+
for finding in current:
|
|
663
|
+
fid = str(
|
|
664
|
+
finding.get("id") or finding.get("fingerprint") or "<unnamed>"
|
|
665
|
+
)
|
|
666
|
+
new_finding = (
|
|
667
|
+
_repair_finding_evidence(finding, workspace_root)
|
|
668
|
+
if fid in rejected_ids
|
|
669
|
+
else None
|
|
670
|
+
)
|
|
671
|
+
if new_finding is not None:
|
|
672
|
+
repaired_ids.append(fid)
|
|
673
|
+
repaired.append(new_finding)
|
|
674
|
+
else:
|
|
675
|
+
repaired.append(finding)
|
|
676
|
+
still_invalid = agent_eval.invalid_evidence_ids(repaired, workspace_root)
|
|
677
|
+
rounds.append({
|
|
678
|
+
"round": round_no,
|
|
679
|
+
"rejections": rejection_records,
|
|
680
|
+
"repaired_ids": repaired_ids,
|
|
681
|
+
"invalid_after": list(still_invalid),
|
|
682
|
+
})
|
|
683
|
+
current = repaired
|
|
684
|
+
if not still_invalid:
|
|
685
|
+
break
|
|
686
|
+
return current, rounds
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def _evidence_retry_prompt(
|
|
690
|
+
rejection_records: list[dict],
|
|
691
|
+
correction_rounds: list[dict],
|
|
692
|
+
) -> str:
|
|
693
|
+
"""把结构化拒绝原因渲染成可回注 worker 重试提示词的自纠文本(有界)。"""
|
|
694
|
+
from core.agent import agent_eval
|
|
695
|
+
|
|
696
|
+
lines = [
|
|
697
|
+
(
|
|
698
|
+
f"[evidence 自纠回路] 摄入侧已有界自纠 {len(correction_rounds)} 轮"
|
|
699
|
+
"仍未通过证据契约,本次 checkpoint 按既有语义拒绝:"
|
|
700
|
+
),
|
|
701
|
+
]
|
|
702
|
+
for record in rejection_records[:8]:
|
|
703
|
+
violations = record.get("violations") or []
|
|
704
|
+
lines.append(
|
|
705
|
+
f"- finding {record.get('finding_id')}: "
|
|
706
|
+
+ ";".join(str(v) for v in violations[:4])
|
|
707
|
+
)
|
|
708
|
+
lines.append(
|
|
709
|
+
"正确格式: " + agent_eval.CORRECT_EVIDENCE_SAMPLE
|
|
710
|
+
+ "(path=workspace 内真实文件的相对路径;line=正整数行号且 ≤ 文件行数);"
|
|
711
|
+
"请修正 evidence 后重新提交 checkpoint。"
|
|
712
|
+
)
|
|
713
|
+
text = "\n".join(lines)
|
|
714
|
+
if len(text) > _EVIDENCE_FEEDBACK_MAX_CHARS:
|
|
715
|
+
text = text[:_EVIDENCE_FEEDBACK_MAX_CHARS] + "…(截断)"
|
|
716
|
+
return text
|
|
717
|
+
|
|
718
|
+
|
|
520
719
|
def normalize_findings(
|
|
521
720
|
findings: Iterable[Mapping[str, object]] | None,
|
|
522
721
|
workspace_root: Path | None = None,
|
|
@@ -590,16 +789,49 @@ def normalize_findings(
|
|
|
590
789
|
)
|
|
591
790
|
result = [normalized[key] for key in sorted(normalized)]
|
|
592
791
|
if workspace_root is not None and result:
|
|
792
|
+
root_path = Path(workspace_root)
|
|
593
793
|
try:
|
|
594
794
|
from core.agent import agent_eval
|
|
595
795
|
|
|
596
|
-
invalid = agent_eval.invalid_evidence_ids(result,
|
|
796
|
+
invalid = agent_eval.invalid_evidence_ids(result, root_path)
|
|
597
797
|
except (ImportError, OSError, TypeError, ValueError) as exc:
|
|
598
798
|
raise InvalidCheckpoint(f"finding evidence 校验失败: {exc}") from exc
|
|
599
799
|
if invalid:
|
|
600
|
-
|
|
601
|
-
|
|
800
|
+
# DEF-2:证据校验拒绝不再直接中止 attempt——先走有界自纠回路
|
|
801
|
+
# (≤MAX_EVIDENCE_SELFCORRECTION_ROUNDS 轮)。每轮以结构化拒绝
|
|
802
|
+
# 原因为回注原料做真相保持的格式改写,改写后仍按原契约全量复检;
|
|
803
|
+
# 同因第三轮(首次校验 + 2 轮自纠)仍失败才按既有语义中止,
|
|
804
|
+
# 并把结构化拒绝原因 + 正确格式样例随拒绝带回(evidence_feedback),
|
|
805
|
+
# 使宿主/模型在下一通道(MCP 错误回包 / failure 回写 / finalize
|
|
806
|
+
# CLI)能拿到可执行的自纠指令。
|
|
807
|
+
result, correction_rounds = selfcorrect_finding_evidence(
|
|
808
|
+
result, root_path,
|
|
602
809
|
)
|
|
810
|
+
try:
|
|
811
|
+
invalid = agent_eval.invalid_evidence_ids(result, root_path)
|
|
812
|
+
except (ImportError, OSError, TypeError, ValueError) as exc:
|
|
813
|
+
raise InvalidCheckpoint(f"finding evidence 校验失败: {exc}") from exc
|
|
814
|
+
if invalid:
|
|
815
|
+
rejection_records = finding_evidence_rejections(result, root_path)
|
|
816
|
+
feedback = {
|
|
817
|
+
"schema_version": 1,
|
|
818
|
+
"contract": (
|
|
819
|
+
"finding.evidence 必须是对象数组:path 为 workspace 内"
|
|
820
|
+
"真实文件的相对路径,line 为正整数且不超过文件行数"
|
|
821
|
+
),
|
|
822
|
+
"correct_sample": agent_eval.CORRECT_EVIDENCE_SAMPLE,
|
|
823
|
+
"self_correction_rounds": len(correction_rounds),
|
|
824
|
+
"findings": rejection_records,
|
|
825
|
+
"retry_prompt": _evidence_retry_prompt(
|
|
826
|
+
rejection_records, correction_rounds,
|
|
827
|
+
),
|
|
828
|
+
}
|
|
829
|
+
exc = InvalidCheckpoint(
|
|
830
|
+
"finding 缺真实 workspace evidence: " + ", ".join(invalid)
|
|
831
|
+
+ ";" + feedback["retry_prompt"]
|
|
832
|
+
)
|
|
833
|
+
exc.evidence_feedback = feedback
|
|
834
|
+
raise exc
|
|
603
835
|
return result
|
|
604
836
|
|
|
605
837
|
|
|
@@ -623,13 +855,22 @@ def attach_evidence_receipts(
|
|
|
623
855
|
"""
|
|
624
856
|
if not findings or not isinstance(evidence, Mapping) or not evidence:
|
|
625
857
|
return
|
|
858
|
+
# F-RSI-20261110-044:关联键逐条 os.path.normpath 归一——coverage unit id
|
|
859
|
+
# 是路径形态(coverage_unit_id),worker 回传的 evidence 键/finding 的
|
|
860
|
+
# case_id 可能携带 "./x.py"/"sub/../x.py" 别名变体;不归一 = receipt
|
|
861
|
+
# **静默不附着**(关联不上保持原样),结算裁决器失去引擎台账可查。
|
|
862
|
+
# 与 F-019/F-028/F-029 同根因:路径比较前必须归一。非路径键
|
|
863
|
+
# (业务单元等)normpath 无斜杠时原样保留。
|
|
864
|
+
def _norm_unit_key(value: object) -> str:
|
|
865
|
+
return os.path.normpath(str(value).strip())
|
|
866
|
+
|
|
626
867
|
receipt_by_unit: dict[str, Mapping[str, object]] = {}
|
|
627
868
|
for unit, item in evidence.items():
|
|
628
869
|
if not isinstance(item, Mapping):
|
|
629
870
|
continue
|
|
630
871
|
receipt = item.get("execution_receipt")
|
|
631
872
|
if isinstance(receipt, Mapping) and receipt:
|
|
632
|
-
receipt_by_unit[
|
|
873
|
+
receipt_by_unit[_norm_unit_key(unit)] = receipt
|
|
633
874
|
if not receipt_by_unit:
|
|
634
875
|
return
|
|
635
876
|
for finding in findings:
|
|
@@ -639,8 +880,9 @@ def attach_evidence_receipts(
|
|
|
639
880
|
continue
|
|
640
881
|
for key in ("case_id", "unit"):
|
|
641
882
|
unit_key = str(finding.get(key) or "").strip()
|
|
642
|
-
|
|
643
|
-
|
|
883
|
+
normalized = _norm_unit_key(unit_key)
|
|
884
|
+
if normalized and normalized in receipt_by_unit:
|
|
885
|
+
finding["evidence_receipt"] = dict(receipt_by_unit[normalized])
|
|
644
886
|
break
|
|
645
887
|
|
|
646
888
|
|
|
@@ -215,12 +215,21 @@ def apply_checkpoint_operation(
|
|
|
215
215
|
)
|
|
216
216
|
expected_target = state.target_fingerprint or supervisor.target_fingerprint
|
|
217
217
|
target_drifted_units: list[str] = []
|
|
218
|
+
# F-RSI-20261118-002:记录 worker 实际提供的指纹(缺失记 None),事件层
|
|
219
|
+
# 一眼区分「worker 漏回填字段」与「worker 值漂移」两类根因(build.602 dsh
|
|
220
|
+
# 第三批真机排查实证:worker 侧漏回填是主形态,事件此前只有 expected 值)。
|
|
221
|
+
drift_worker_fingerprints: dict[str, str | None] = {}
|
|
218
222
|
for item_unit, item in incoming_evidence.items():
|
|
219
223
|
# This marker is Supervisor-owned; never trust a worker-supplied value.
|
|
220
224
|
item.pop("target_drifted", None)
|
|
221
225
|
item.pop("reproduced_crash", None)
|
|
222
226
|
if item.get("target_fingerprint") != expected_target:
|
|
223
227
|
target_drifted_units.append(item_unit)
|
|
228
|
+
raw_worker_fp = item.get("target_fingerprint")
|
|
229
|
+
drift_worker_fingerprints[item_unit] = (
|
|
230
|
+
str(raw_worker_fp)
|
|
231
|
+
if isinstance(raw_worker_fp, str) and raw_worker_fp else None
|
|
232
|
+
)
|
|
224
233
|
# New work remains fail-closed in claim/start paths. Checkpoint admission
|
|
225
234
|
# is the recovery boundary for a claim already in hand: budget exhaustion or
|
|
226
235
|
# a worker-reported target drift must not strand its valid artifacts.
|
|
@@ -386,6 +395,10 @@ def apply_checkpoint_operation(
|
|
|
386
395
|
checkpoint_id=checkpoint_key,
|
|
387
396
|
expected_target_fingerprint=expected_target,
|
|
388
397
|
evidence_units=sorted(target_drifted_units),
|
|
398
|
+
worker_target_fingerprints={
|
|
399
|
+
unit: drift_worker_fingerprints[unit]
|
|
400
|
+
for unit in sorted(drift_worker_fingerprints)
|
|
401
|
+
},
|
|
389
402
|
)
|
|
390
403
|
if claim.execution_state == "claimed":
|
|
391
404
|
if supervisor._parallel_required(state) and not budget_exhausted:
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
``supervisor.lease_manager`` 此前互为依赖——``lease_manager`` 在
|
|
6
6
|
``mark_claim_expired`` 里 `from supervisor import budget_governor`,而
|
|
7
7
|
``budget_governor`` 顶层从 ``lease_manager`` 导入 ``append_event`` 等原语。
|
|
8
|
-
|
|
8
|
+
双向依赖会让模块方向无法静态判定(导入图无环约束,人工核查为准)。
|
|
9
9
|
|
|
10
10
|
``append_event`` 只依赖 ``supervisor_models``(事件序列 / hash-chain / 裁剪归档),
|
|
11
11
|
与租约、预算语义无关,因此下沉到本模块:
|
|
@@ -106,8 +106,8 @@ def admit_business_unit(
|
|
|
106
106
|
raise InvalidCheckpoint("只允许授权业务 coverage unit")
|
|
107
107
|
if not isinstance(risk_score, (int, float)) or not math.isfinite(float(risk_score)):
|
|
108
108
|
raise InvalidCheckpoint(
|
|
109
|
-
"risk_score
|
|
110
|
-
"不要传 NaN / Infinity /
|
|
109
|
+
"risk_score 必须是 70-100 的有限数字,形如 87.5;"
|
|
110
|
+
"不要传 NaN / Infinity / 字符串形式的数值"
|
|
111
111
|
)
|
|
112
112
|
if not 70 <= float(risk_score) <= 100:
|
|
113
113
|
raise InvalidCheckpoint("只有 70 <= risk_score <= 100 的业务链路可提前准入")
|
|
@@ -542,6 +542,7 @@ def confirm_finding(
|
|
|
542
542
|
remediation: Mapping[str, object] | None = None,
|
|
543
543
|
oracle: Mapping[str, object] | None = None,
|
|
544
544
|
target_platform: str | None = None,
|
|
545
|
+
severity: str | None = None,
|
|
545
546
|
) -> RunState:
|
|
546
547
|
"""Host-owned Finding decision executed inside one Supervisor transaction.
|
|
547
548
|
|
|
@@ -564,9 +565,19 @@ def confirm_finding(
|
|
|
564
565
|
self._check_revision(state, expected_revision)
|
|
565
566
|
if state.status.value in {"complete", "failed"}:
|
|
566
567
|
raise InvalidTransition(f"run 已结束: {state.status.value}")
|
|
568
|
+
# 与 verify_finding(_verification_precheck)同语义:按 id-or-fingerprint
|
|
569
|
+
# 唯一匹配。findings-confirm 一条龙把 recipe 的 fingerprint 同时传给
|
|
570
|
+
# verify 与 confirm;旧实现只按 id 匹配,id≠fingerprint 时 confirm 恒报
|
|
571
|
+
# "Finding 不存在或身份不唯一"。唯一命中才通过,多命中/零命中仍拒绝
|
|
572
|
+
# (只放宽到唯一匹配,不放宽到模糊匹配)。
|
|
567
573
|
matches = [
|
|
568
574
|
item for item in state.findings
|
|
569
|
-
if isinstance(item, dict) and
|
|
575
|
+
if isinstance(item, dict) and key in {
|
|
576
|
+
str(item.get("fingerprint") or "").strip(),
|
|
577
|
+
str(item.get("id") or "").strip(),
|
|
578
|
+
str(item.get("finding_id") or "").strip(),
|
|
579
|
+
str(self._finding_key(item) or "").strip(),
|
|
580
|
+
}
|
|
570
581
|
]
|
|
571
582
|
if len(matches) != 1:
|
|
572
583
|
raise InvalidCheckpoint("Finding 不存在或身份不唯一")
|
|
@@ -579,16 +590,22 @@ def confirm_finding(
|
|
|
579
590
|
receipt=receipt, oracle=oracle,
|
|
580
591
|
root_cause_verified=root_cause_verified, remediation=remediation,
|
|
581
592
|
target_platform=target_platform, rejection_class=rejection_class,
|
|
582
|
-
root=self.workspace_root,
|
|
593
|
+
root=self.workspace_root, severity=severity,
|
|
583
594
|
)
|
|
584
595
|
target["confirmation"] = decided["confirmation"]
|
|
585
596
|
if decided["remediation"] is not None:
|
|
586
597
|
target["remediation"] = decided["remediation"]
|
|
598
|
+
# F-RSI-20261118-009:确认后 finding 的 severity 回写。apply_decision
|
|
599
|
+
# 在 deepcopy 副本上定级/补录,最终有效值经 severity_final 通道返回——
|
|
600
|
+
# 回写条件只看 severity_final 有效(severity_applied 仅标记「本轮新补」,
|
|
601
|
+
# worker 已带有效定级时为 None 但 severity_final 仍需同步到 target)。
|
|
602
|
+
if decided.get("severity_final"):
|
|
603
|
+
target["severity"] = decided["severity_final"]
|
|
587
604
|
self._append_event(
|
|
588
605
|
state,
|
|
589
606
|
"finding_confirmed" if decision == "confirmed" else "finding_rejected",
|
|
590
607
|
now,
|
|
591
|
-
finding_id=key,
|
|
608
|
+
finding_id=str(target.get("id") or key),
|
|
592
609
|
reason=str(reason).strip(),
|
|
593
610
|
channel="confirm_finding",
|
|
594
611
|
verification_id=decided["confirmation"].get("verification_id"),
|
|
@@ -210,7 +210,7 @@ def claimed_units_this_round(state: RunState) -> set[str]:
|
|
|
210
210
|
def eligible_units(state: RunState) -> set[str]:
|
|
211
211
|
"""Keep internal debt visible until all of it is retry-exhausted.
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
注意(契约,以本注释为准):本函数返回
|
|
214
214
|
的是**范围/可见性集合**,不是「此刻可申领集合」。因此:
|
|
215
215
|
|
|
216
216
|
* 内部单元**整体保留**(含已终态者),调用方不得据此假设可申领;
|
|
@@ -63,7 +63,12 @@ def _release_owner_cancelled_debris(
|
|
|
63
63
|
getattr(claim, "state", "") == "active"
|
|
64
64
|
and getattr(claim, "execution_state", "") == "claimed"
|
|
65
65
|
):
|
|
66
|
-
|
|
66
|
+
# F-RSI-20261118-008:写入端必须落在 from_dict 白名单内。曾写
|
|
67
|
+
# ``state="preempted"``(该状态未注册,读取端 post 结算直接
|
|
68
|
+
# PersistenceError——worktree post 硬失败实证);released 完全
|
|
69
|
+
# 对应本语义(「释放」),preempted_reason 保留历史原因供审计。
|
|
70
|
+
claim.state = "released"
|
|
71
|
+
claim.execution_state = "released"
|
|
67
72
|
claim.preempted_reason = "owner_cancelled_queue_debris"
|
|
68
73
|
released.append(worker_id)
|
|
69
74
|
if released:
|
|
@@ -71,31 +71,55 @@ REJECTION_REMEDIES: dict[str, dict[str, Any]] = {
|
|
|
71
71
|
cli=[["bugx", "supervisor", "status"]],
|
|
72
72
|
),
|
|
73
73
|
"expired_workers_require_retry": _entry(
|
|
74
|
-
meaning=
|
|
74
|
+
meaning=(
|
|
75
|
+
"存在 expired claim 形成的重试债,必须先接手原任务包。"
|
|
76
|
+
"注意:单元已 100% 沿链继承覆盖的 expired claim 已被标记"
|
|
77
|
+
" superseded_by_inheritance(事件 expired_claim_superseded_by_inheritance)"
|
|
78
|
+
"移出该集合不再重派;留在集合里的 claim 必有未覆盖单元,需按原包接手重派。"
|
|
79
|
+
),
|
|
75
80
|
category=CATEGORY_WORKER,
|
|
76
81
|
trigger={"gate_reason": "expired_workers_require_retry", "gate_field": "expired_workers"},
|
|
77
82
|
required_role="worker",
|
|
78
83
|
required_inputs=("worker_id", "recover_expired=true", "expected_revision"),
|
|
79
|
-
exit_conditions=(
|
|
84
|
+
exit_conditions=(
|
|
85
|
+
"expired_workers 为空(含被继承豁免标记 superseded 的 claim)",
|
|
86
|
+
"新 claim active 且 unit_ids/resource_keys 与原包一致",
|
|
87
|
+
),
|
|
80
88
|
next_actions=("RECLAIM_EXPIRED_WORKERS",),
|
|
81
89
|
fallback_actions=("STALLED_OR_RECOVER",),
|
|
82
90
|
steps=(
|
|
83
91
|
"以 recover_expired=true 接手同一 expired/released claim",
|
|
84
92
|
"接手失败时先确认没有 active claim,再由 host 显式 recover",
|
|
85
93
|
"recover 后重新读取 gate,再按原单元重新派发",
|
|
94
|
+
"expired_workers 里消失的 worker 不必追讨:其单元已沿链继承覆盖"
|
|
95
|
+
"(见 expired_claim_superseded_by_inheritance 事件快照)",
|
|
86
96
|
),
|
|
87
97
|
cli=[["bugx", "supervisor", "status"]],
|
|
88
98
|
mcp_tool="bugx_supervisor_claim",
|
|
89
99
|
),
|
|
90
100
|
"parallel_peak_below_two": _entry(
|
|
91
|
-
meaning=
|
|
101
|
+
meaning=(
|
|
102
|
+
"要求并行但本轮未观察到两个真实运行 worker。"
|
|
103
|
+
"恢复会话收口豁免(三条件全真且留痕 parallel_gate_inherited_closeout)"
|
|
104
|
+
"会移除该原因;非 --final post 不接受该豁免(D5 fail-closed)。"
|
|
105
|
+
),
|
|
92
106
|
category=CATEGORY_SCHEDULER,
|
|
93
107
|
trigger={"gate_reason": "parallel_peak_below_two"},
|
|
94
108
|
required_role="host",
|
|
95
109
|
required_inputs=("coverage_units", "max_concurrency"),
|
|
96
|
-
exit_conditions=(
|
|
110
|
+
exit_conditions=(
|
|
111
|
+
"本轮真实峰值至少为 2",
|
|
112
|
+
"或显式记录 serial_reason",
|
|
113
|
+
"或恢复结算三条件全真(owner_cancelled 证明在链 + covered 100% "
|
|
114
|
+
"继承/历史证据且本轮零新增 passed 记录 + 零新增 findings),"
|
|
115
|
+
"以 parallel_gate_inherited_closeout 留痕为准",
|
|
116
|
+
),
|
|
97
117
|
next_actions=("CLAIM_WORKERS",),
|
|
98
|
-
steps=(
|
|
118
|
+
steps=(
|
|
119
|
+
"派发两个不同单元并确认 worker-start 窗口重叠",
|
|
120
|
+
"恢复会话零挖掘收口时核对三条件快照"
|
|
121
|
+
"(gate.recovery_closeout_exemption.conditions),缺一即拒绝",
|
|
122
|
+
),
|
|
99
123
|
cli=[["bugx", "supervisor", "status"]],
|
|
100
124
|
),
|
|
101
125
|
"parallel_overlap_missing": _entry(
|
|
@@ -119,6 +143,29 @@ REJECTION_REMEDIES: dict[str, dict[str, Any]] = {
|
|
|
119
143
|
steps=("每个 worker 提交带 coverage/evidence 的 checkpoint",),
|
|
120
144
|
mcp_tool="bugx_supervisor_checkpoint",
|
|
121
145
|
),
|
|
146
|
+
"bookkeeping_only_no_real_parallel": _entry(
|
|
147
|
+
meaning=(
|
|
148
|
+
"并发峰值只由记账式 claim(judge 判读取证电池等,process_pid 为空"
|
|
149
|
+
"/零 token/心跳零推进)的重叠窗口构成,经真实性过滤后无真实并发——"
|
|
150
|
+
"第四批修复(假并发门禁)的 fail-closed 诚实化标注。"
|
|
151
|
+
),
|
|
152
|
+
category=CATEGORY_SCHEDULER,
|
|
153
|
+
trigger={"gate_reason": "bookkeeping_only_no_real_parallel",
|
|
154
|
+
"gate_field": "bookkeeping_workers"},
|
|
155
|
+
required_role="host",
|
|
156
|
+
required_inputs=("coverage_units", "max_concurrency"),
|
|
157
|
+
exit_conditions=(
|
|
158
|
+
"两个真实 worker(pid/tokens/心跳三选二)窗口重叠",
|
|
159
|
+
"或显式记录 serial_reason 走串行授权",
|
|
160
|
+
),
|
|
161
|
+
next_actions=("CLAIM_WORKERS",),
|
|
162
|
+
steps=(
|
|
163
|
+
"读取 bookkeeping_workers 清单确认均为记账 claim",
|
|
164
|
+
"派发两个真实 worker 并确认窗口重叠",
|
|
165
|
+
"或按串行授权契约显式降级(--allow-serial)",
|
|
166
|
+
),
|
|
167
|
+
cli=[["bugx", "supervisor", "status"]],
|
|
168
|
+
),
|
|
122
169
|
"max_wall_seconds": _entry(
|
|
123
170
|
meaning="run 级墙钟预算耗尽。",
|
|
124
171
|
category=CATEGORY_HOST,
|
|
@@ -100,17 +100,32 @@ def _require_text(value: object, name: str) -> str:
|
|
|
100
100
|
return value
|
|
101
101
|
|
|
102
102
|
|
|
103
|
+
# 引擎 lifecycle run_id 形态(supervisor_bridge._expected_supervisor_run_id):
|
|
104
|
+
# `lifecycle-{session_id}-{lifecycle_id}` 或裸 `lifecycle-{lifecycle_id}`,
|
|
105
|
+
# 全小写字母数字与连字符。恢复会话(DOC-RECOVERY-BINDING,session_runtime
|
|
106
|
+
# start_runtime)必须收养该 run_id 才能保持 runtime/Supervisor 身份一致;
|
|
107
|
+
# 授权身份校验必须接受同一磁盘形态,否则 resume 后的 pre --allow-serial
|
|
108
|
+
# 恒被拒(E1 遗留观察 #3 机制 b)。严格字符集保证确定性接受 ⇒ 身份哈希稳定。
|
|
109
|
+
_LIFECYCLE_RUN_ID_RE = re.compile(r"^lifecycle-[0-9a-z][0-9a-z-]{0,190}$")
|
|
110
|
+
|
|
111
|
+
|
|
103
112
|
def _require_runtime_uuid(value: object) -> str:
|
|
104
113
|
raw = _require_text(value, "runtime_run_uuid")
|
|
114
|
+
if _LIFECYCLE_RUN_ID_RE.fullmatch(raw):
|
|
115
|
+
return raw
|
|
105
116
|
try:
|
|
106
117
|
parsed = uuid.UUID(raw)
|
|
107
118
|
except (ValueError, AttributeError, TypeError) as exc:
|
|
108
|
-
raise SerialAuthorizationError(
|
|
119
|
+
raise SerialAuthorizationError(
|
|
120
|
+
"runtime_run_uuid must be a canonical UUID or engine lifecycle run_id"
|
|
121
|
+
) from exc
|
|
109
122
|
# launch_bugx runtime ids are uuid4().hex (32 lowercase hexadecimal
|
|
110
123
|
# characters); accept that real on-disk form and canonical dashed UUIDs.
|
|
111
124
|
# Reject uppercase and other UUID spellings so identity hashing stays stable.
|
|
112
125
|
if raw not in {str(parsed), parsed.hex}:
|
|
113
|
-
raise SerialAuthorizationError(
|
|
126
|
+
raise SerialAuthorizationError(
|
|
127
|
+
"runtime_run_uuid must be a canonical UUID or engine lifecycle run_id"
|
|
128
|
+
)
|
|
114
129
|
return raw
|
|
115
130
|
|
|
116
131
|
|
|
@@ -298,8 +313,18 @@ def _state_matches(
|
|
|
298
313
|
if state.budget.require_parallel is not False:
|
|
299
314
|
raise SerialAuthorizationError("Supervisor budget does not authorize serial execution")
|
|
300
315
|
current_budget_hash, current_reason_hash = _budget_snapshot(state)
|
|
316
|
+
# budget_epoch 是预算使用窗口计数器,不是能力(capability)。合法 epoch
|
|
317
|
+
# 续期(``reset_budget``,唯一会递增 ``budget_epoch`` 的状态变更,链上有
|
|
318
|
+
# ``budget_reset`` 事件)在继承原预算全部能力字段后推进计数器,而
|
|
319
|
+
# ``RunBudget.to_dict()`` 不含 epoch 或用量字段——``budget_snapshot_sha256``
|
|
320
|
+
# 因此跨续期稳定。若在这里比较 epoch 计数器,恢复会话自动续期后
|
|
321
|
+
# (pre/post 均如此)授权绑定恒被拒(真机 dsh post BLOCKED 根因:
|
|
322
|
+
# "Supervisor budget snapshot does not match capability")。能力契约保持
|
|
323
|
+
# **全内容相等**:任何预算字段变化(如 max_concurrency 被调小、
|
|
324
|
+
# serial_reason 变更)仍经 snapshot/reason 哈希比对拒绝;epoch 只允许
|
|
325
|
+
# 前进——回退不可能由任何状态变更产生,出现即 fail-closed 拒绝。
|
|
301
326
|
if (
|
|
302
|
-
state.budget_epoch
|
|
327
|
+
state.budget_epoch < budget_epoch
|
|
303
328
|
or current_budget_hash != budget_snapshot_sha256
|
|
304
329
|
or current_reason_hash != serial_reason_sha256
|
|
305
330
|
):
|
|
@@ -404,7 +429,26 @@ def issue_serial_authorization(
|
|
|
404
429
|
key: existing[key]
|
|
405
430
|
for key in _EVENT_FIELDS
|
|
406
431
|
}
|
|
407
|
-
|
|
432
|
+
# 与 _state_matches 同一契约:合法 epoch 续期(链上 budget_reset
|
|
433
|
+
# 事件)推进 budget_epoch 而不改变授权的能力内容(预算配置字典与
|
|
434
|
+
# serial_reason 均不变)。同一代际只能有一条授权事件(validate
|
|
435
|
+
# 侧唯一性不变式),因此续期后禁止追加新事件,只能 recovery 原
|
|
436
|
+
# 事件:除 epoch 派生字段(budget_epoch 及由 identity+epoch+
|
|
437
|
+
# snapshot 派生的 authorization_id)外逐字段严格相等,且 epoch
|
|
438
|
+
# 只允许原地或前进(回退 fail-closed 拒绝)。authorization_id 的
|
|
439
|
+
# 全部派生源(identity、budget_snapshot_sha256、epoch)都被其余
|
|
440
|
+
# 比较字段或本条 epoch 前向约束钉死,排除它不放松任何校验。
|
|
441
|
+
# 任何能力内容差异仍然拒绝。
|
|
442
|
+
compare_fields = _EVENT_FIELDS - {"budget_epoch", "authorization_id"}
|
|
443
|
+
capability_equal = all(
|
|
444
|
+
existing[key] == payload[key] for key in compare_fields
|
|
445
|
+
)
|
|
446
|
+
epoch_forward = (
|
|
447
|
+
not isinstance(actual_payload["budget_epoch"], bool)
|
|
448
|
+
and isinstance(actual_payload["budget_epoch"], int)
|
|
449
|
+
and actual_payload["budget_epoch"] <= payload["budget_epoch"]
|
|
450
|
+
)
|
|
451
|
+
if not capability_equal or not epoch_forward:
|
|
408
452
|
raise SerialAuthorizationError(
|
|
409
453
|
"orphan serial authorization does not match explicit pre inputs"
|
|
410
454
|
)
|
|
@@ -112,7 +112,7 @@ TRAVERSAL_STRATEGIES = frozenset({"auto", "dfs", "bfs", "hybrid"})
|
|
|
112
112
|
#: * ``supervisor_models.MAX_LEASE_SECONDS``(核心侧接受上限);
|
|
113
113
|
#: * ``bugx_mcp_server`` 的 ``lease_seconds.inputSchema.maximum``。
|
|
114
114
|
#: 三处漂移会让「推荐值」与「接受上限」脱节:调用方按推荐值申请却拿到更长的
|
|
115
|
-
#:
|
|
115
|
+
#: 租约,或反之。一致性契约以本注释为准。
|
|
116
116
|
LEASE_SECONDS_CEILING = 3600.0
|
|
117
117
|
_SENSITIVE_SURFACES = {
|
|
118
118
|
"auth": 3.0, "login": 3.0, "payment": 3.0, "billing": 3.0,
|
|
@@ -1038,7 +1038,7 @@ class AdaptiveConcurrencyController:
|
|
|
1038
1038
|
"Pages free", "Pages inactive", "Pages speculative",
|
|
1039
1039
|
"Pages purgeable", "File-backed pages",
|
|
1040
1040
|
):
|
|
1041
|
-
match = re.search(rf"^{re.escape(name)}
|
|
1041
|
+
match = re.search(rf"^{re.escape(name)}:\s+(\d+)", output, re.MULTILINE)
|
|
1042
1042
|
if match:
|
|
1043
1043
|
available_pages += int(match.group(1))
|
|
1044
1044
|
available = available_pages * int(page_match.group(1))
|
|
@@ -213,7 +213,14 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
213
213
|
artifacts=artifacts,
|
|
214
214
|
)
|
|
215
215
|
except (OSError, ValueError, audit_supervisor.SupervisorError) as exc:
|
|
216
|
-
|
|
216
|
+
payload = {"error": str(exc)}
|
|
217
|
+
# DEF-2:finalize 有界重提通道接线——摄入侧结构化拒绝原因
|
|
218
|
+
# (evidence_feedback:缺什么字段 / 哪个 path 不存在 / 正确格式样例 /
|
|
219
|
+
# 重试提示词)随错误一起回注,宿主与模型无需再从一行纯文本里猜。
|
|
220
|
+
feedback = getattr(exc, "evidence_feedback", None)
|
|
221
|
+
if isinstance(feedback, dict) and feedback:
|
|
222
|
+
payload["evidence_feedback"] = feedback
|
|
223
|
+
print(json.dumps(payload, ensure_ascii=False))
|
|
217
224
|
return 1
|
|
218
225
|
print(json.dumps(result, ensure_ascii=False, sort_keys=True))
|
|
219
226
|
return 0
|
|
@@ -985,8 +985,14 @@ def _execute_autonomous_worker(
|
|
|
985
985
|
for unit in unit_ids:
|
|
986
986
|
unit_findings = [f for f in findings if f.get("unit_id") == unit or f.get("file") == unit]
|
|
987
987
|
sched.record_audit_attempt(unit, findings_count=len(unit_findings))
|
|
988
|
-
except Exception:
|
|
989
|
-
|
|
988
|
+
except Exception as exc:
|
|
989
|
+
# F-RSI-20261112-104:UCB1 记账失败不得静默——调度质量退化(探索/
|
|
990
|
+
# 利用加权失真)应可观测。checkpoint 已提交(上一 try),此处只影响
|
|
991
|
+
# 下一轮调度倾斜,fail-open 合理但必须留痕。
|
|
992
|
+
print(
|
|
993
|
+
f"[worker-runtime] ⚠ UCB1 调度记账失败(不影响本批交付,下一轮调度倾斜退化): {exc}",
|
|
994
|
+
file=sys.stderr,
|
|
995
|
+
)
|
|
990
996
|
|
|
991
997
|
return {
|
|
992
998
|
"worker_id": worker_id,
|