bugx-cli 0.1.0 → 0.1.1
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 +190 -186
- 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/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/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/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 +25 -6
- package/core/cloud_sync/cloud_onboard.py +42 -1
- package/core/cloud_sync/flywheel_client.py +16 -7
- 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 +591 -419
- 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 +2 -2
- package/core/launch_phases/SPEC.md +1 -1
- package/core/launch_phases/common.py +21 -2
- package/core/launch_phases/finding_confirm_phase.py +5 -1
- 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 +139 -3
- 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 +53 -36
- package/core/launch_phases/pre_state_builder.py +23 -176
- package/core/launch_phases/round_orchestrator.py +15 -32
- 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 +9 -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/worker_barriers.py +15 -5
- package/core/launch_phases/worker_orchestrator.py +105 -25
- package/core/ledger/README.md +1 -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 +44 -8
- 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 +1 -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 +7 -5
- 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/command_routing_en.md +2 -2
- package/core/prompts/command_routing_zh.md +2 -2
- package/core/prompts/stages/stage_repair.md +1 -1
- 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/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 +1 -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/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/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 +190 -186
- 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 +11 -4
- package/interfaces/cli/bugx_cli/commands/advisory.py +1 -1
- package/interfaces/cli/bugx_cli/commands/agent.py +339 -73
- package/interfaces/cli/bugx_cli/commands/audit.py +2 -2
- package/interfaces/cli/bugx_cli/commands/autonomous.py +1 -1
- package/interfaces/cli/bugx_cli/commands/cloud.py +4 -3
- 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 +2 -0
- package/interfaces/cli/bugx_cli/commands/lifecycle.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin.py +55 -20
- 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/report.py +2 -6
- package/interfaces/cli/bugx_cli/commands/system.py +11 -11
- package/interfaces/cli/bugx_cli/common.py +15 -7
- 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 +18 -10
- 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 +2 -1
- package/pyproject.toml +20 -8
- package/scripts/ensure-python.mjs +7 -7
- package/scripts/sync-version.mjs +10 -21
- package/scripts/test-npm-wrapper.mjs +1 -1
- 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
|
@@ -35,6 +35,7 @@ from core.launch_phases.common import (
|
|
|
35
35
|
child_environment,
|
|
36
36
|
run_child,
|
|
37
37
|
run_bounded,
|
|
38
|
+
sync_codebase_memory_env as _sync_codebase_memory_env,
|
|
38
39
|
bugx_paths,
|
|
39
40
|
)
|
|
40
41
|
import hashlib
|
|
@@ -272,6 +273,25 @@ def auto_recover_supervisor(
|
|
|
272
273
|
current = dict(snapshot) if isinstance(snapshot, Mapping) else {}
|
|
273
274
|
if not current.get("parallel_gate") or "next_action" not in current:
|
|
274
275
|
current = _supervisor_recovery_snapshot(supervisor)
|
|
276
|
+
# F-RSI-20261110-035:外部快照必须带 state 子对象——预算重置的参数
|
|
277
|
+
# 继承(max_rounds/max_wall_seconds/...)从 current["state"]["budget"]
|
|
278
|
+
# 读取;缺 state 时旧实现静默用默认值重置(红探针实测预算键全部丢失,
|
|
279
|
+
# 返回 "recovered" 伪装健康)。内部路径经 _supervisor_recovery_snapshot
|
|
280
|
+
# 构造(缺 state/gate 会 ValueError fail-closed),只有外部传入的
|
|
281
|
+
# snapshot 需要这道闸。
|
|
282
|
+
if isinstance(snapshot, Mapping) and not isinstance(current.get("state"), Mapping):
|
|
283
|
+
detail = (
|
|
284
|
+
"外部快照缺少 state 子对象:预算参数继承无法保证,"
|
|
285
|
+
"拒绝自动恢复(fail-closed)"
|
|
286
|
+
)
|
|
287
|
+
print(f"[supervisor] ✗ 自动恢复拒绝: {detail}")
|
|
288
|
+
return {
|
|
289
|
+
"status": "blocked",
|
|
290
|
+
"reason": "recovery_snapshot_missing_state",
|
|
291
|
+
"detail": detail,
|
|
292
|
+
"snapshot": current,
|
|
293
|
+
"events": [],
|
|
294
|
+
}
|
|
275
295
|
|
|
276
296
|
gate = current.get("parallel_gate")
|
|
277
297
|
gate = gate if isinstance(gate, Mapping) else {}
|
|
@@ -741,15 +761,6 @@ def _preflight_probe_summary(report: dict) -> str:
|
|
|
741
761
|
return f"{status}{suffix}{detail}"
|
|
742
762
|
|
|
743
763
|
|
|
744
|
-
def _sync_codebase_memory_env(profile: dict) -> None:
|
|
745
|
-
"""把 codebase-memory 探针结论同步到进程环境变量。"""
|
|
746
|
-
cb_probe = (profile.get("probes") or {}).get("codebase-memory")
|
|
747
|
-
if isinstance(cb_probe, dict):
|
|
748
|
-
os.environ["BUGX_USE_CODEBASE_MEMORY"] = (
|
|
749
|
-
"1" if cb_probe.get("status") == "READY" else "0"
|
|
750
|
-
)
|
|
751
|
-
|
|
752
|
-
|
|
753
764
|
# DES-13:启动前探针的执行真源已收敛到 probe_registry.preflight_probes(),
|
|
754
765
|
# 下列名称不再包含任何手写探针逻辑。它们仅为保持历史导入方
|
|
755
766
|
# (round_orchestrator 仍在 import 这些名字)可用而保留;一旦被真正调用,
|
|
@@ -991,6 +1002,31 @@ def host_entry_gate() -> int:
|
|
|
991
1002
|
return RESTART_REQUIRED
|
|
992
1003
|
|
|
993
1004
|
|
|
1005
|
+
def _map_supervisor_mcp_answer(value: str | None, *, allow_manual: bool = True) -> str | None:
|
|
1006
|
+
"""supervisor_mcp 选择值→动作映射单一真源(TTY / 信箱两通道共用)。
|
|
1007
|
+
|
|
1008
|
+
TTY 文本菜单经 ``ask_interaction`` 返回选项序号("1"/"2"/"3");信箱通道
|
|
1009
|
+
(``bugx interaction answer supervisor_mcp``)经 ``take_answer`` 返回结构化
|
|
1010
|
+
门禁的语义 value("install"/"manual"/"later")。两通道必须落到同一动作,
|
|
1011
|
+
否则语义答案会在 ask 内被消费(consumed_at 已置位)却被映射丢弃,门禁
|
|
1012
|
+
无限重发。
|
|
1013
|
+
"""
|
|
1014
|
+
low = (value or "").strip().lower()
|
|
1015
|
+
if low in {"1", "install"}:
|
|
1016
|
+
return "install"
|
|
1017
|
+
if low == "2":
|
|
1018
|
+
# 序号是位置语义:两选项形状(无 manual)的 "2" 就是 later。
|
|
1019
|
+
return "manual" if allow_manual else "later"
|
|
1020
|
+
if low == "manual":
|
|
1021
|
+
# 语义值只在三选项形状存在;两选项门禁收到过期 manual 必须 fail-closed。
|
|
1022
|
+
return "manual" if allow_manual else None
|
|
1023
|
+
if low == "3":
|
|
1024
|
+
return "later" if allow_manual else None
|
|
1025
|
+
if low == "later":
|
|
1026
|
+
return "later"
|
|
1027
|
+
return None
|
|
1028
|
+
|
|
1029
|
+
|
|
994
1030
|
def _prompt_supervisor_mcp(
|
|
995
1031
|
status: dict[str, object], *, allow_manual: bool = True,
|
|
996
1032
|
) -> str | None:
|
|
@@ -1009,14 +1045,7 @@ def _prompt_supervisor_mcp(
|
|
|
1009
1045
|
+ "。完成后必须重启宿主,再在新会话重新启动 BugX。"
|
|
1010
1046
|
),
|
|
1011
1047
|
)
|
|
1012
|
-
|
|
1013
|
-
if value == "1":
|
|
1014
|
-
return "install"
|
|
1015
|
-
if allow_manual and value == "2":
|
|
1016
|
-
return "manual"
|
|
1017
|
-
if value == ("3" if allow_manual else "2"):
|
|
1018
|
-
return "later"
|
|
1019
|
-
return None
|
|
1048
|
+
return _map_supervisor_mcp_answer(answered_value(result), allow_manual=allow_manual)
|
|
1020
1049
|
|
|
1021
1050
|
def supervisor_mcp_gate(*, review_mode: str | None,
|
|
1022
1051
|
autonomous: bool = False) -> str:
|
|
@@ -392,8 +392,14 @@ def bootstrap_coverage_manifest_locked(manifest: Path) -> bool:
|
|
|
392
392
|
with open(manifest, "a", encoding="utf-8") as f:
|
|
393
393
|
for bl in business_lines:
|
|
394
394
|
f.write(bl + "\n")
|
|
395
|
-
except Exception:
|
|
396
|
-
|
|
395
|
+
except Exception as exc:
|
|
396
|
+
# F-RSI-20261113-109:业务链路追加失败不得静默——清单缺业务行是
|
|
397
|
+
# 覆盖面缺口(judge 业务链路组合关单与业务单元派发都会错过),
|
|
398
|
+
# 骨架生成整体成功所以 fail-open,但缺口必须可观测(F-104/106 同款)。
|
|
399
|
+
print(
|
|
400
|
+
f"[launch_bugx] ⚠ 业务链路行追加失败,覆盖清单缺业务链路(组合关单/业务派发将错过): {exc}",
|
|
401
|
+
file=sys.stderr,
|
|
402
|
+
)
|
|
397
403
|
print(
|
|
398
404
|
f"[launch_bugx] ✓ 已自动生成覆盖清单骨架:{len(discovered)} 个最小单元"
|
|
399
405
|
"(module_coverage discover;Agent 开工后继续细化难度/工具/业务链路列)"
|
|
@@ -20,6 +20,7 @@ from core.launch_phases.common import (
|
|
|
20
20
|
supervisor_state_path,
|
|
21
21
|
child_environment,
|
|
22
22
|
run_child,
|
|
23
|
+
sync_codebase_memory_env as _sync_codebase_memory_env,
|
|
23
24
|
bugx_paths,
|
|
24
25
|
)
|
|
25
26
|
from core.launch_phases.session_runtime import (
|
|
@@ -595,15 +596,6 @@ def check_fix_regressions(root: Path | None = None) -> dict:
|
|
|
595
596
|
return _watchlist_error_report(exc)
|
|
596
597
|
|
|
597
598
|
|
|
598
|
-
def _sync_codebase_memory_env(profile: dict) -> None:
|
|
599
|
-
"""把 codebase-memory 探针结论同步到进程环境变量。"""
|
|
600
|
-
cb_probe = (profile.get("probes") or {}).get("codebase-memory")
|
|
601
|
-
if isinstance(cb_probe, dict):
|
|
602
|
-
os.environ["BUGX_USE_CODEBASE_MEMORY"] = (
|
|
603
|
-
"1" if cb_probe.get("status") == "READY" else "0"
|
|
604
|
-
)
|
|
605
|
-
|
|
606
|
-
|
|
607
599
|
def report_degraded_probes(*, refresh: bool = False,
|
|
608
600
|
degraded: list[dict] | None = None) -> list[dict]:
|
|
609
601
|
"""收集并显式汇报探针 DEGRADED 项;返回降级动作清单供写入准备记录。
|
|
@@ -66,10 +66,17 @@ _CONVENTION_MAX_LINES = 20
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
def sanitize_convention_line(line: str) -> str | None:
|
|
69
|
-
"""单行消毒:空行丢弃、门禁标记词行整行丢弃、反引号转义防破围栏。
|
|
69
|
+
"""单行消毒:空行丢弃、门禁标记词行整行丢弃、反引号转义防破围栏。
|
|
70
|
+
|
|
71
|
+
F-RSI-20261112-081:标记词匹配必须 casefold——conventions.json 属于
|
|
72
|
+
被审计项目(消毒边界注释自证其威胁模型是提示注入),`BUGX-SUPERVISOR-WORKER`
|
|
73
|
+
等大小写变形写法若不归一即可绕过整行丢弃,把引擎门禁标记透传进 worker
|
|
74
|
+
提示词。
|
|
75
|
+
"""
|
|
70
76
|
if not line.strip():
|
|
71
77
|
return None
|
|
72
|
-
|
|
78
|
+
folded = line.casefold()
|
|
79
|
+
if any(marker.casefold() in folded for marker in _CONVENTION_GATE_MARKERS):
|
|
73
80
|
return None
|
|
74
81
|
return line.replace("`", "'")
|
|
75
82
|
|
|
@@ -105,9 +112,12 @@ def conventions_block(root: Path | None = None) -> str:
|
|
|
105
112
|
lines.append(clean)
|
|
106
113
|
if not lines:
|
|
107
114
|
return ""
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
shown = lines[:_CONVENTION_MAX_LINES]
|
|
116
|
+
body = "\n".join(f"- {line}" for line in shown)
|
|
117
|
+
# F-RSI-20261112-081:截断必须留痕——约定条目静默丢失会让 worker 以为
|
|
118
|
+
# 已看到全部项目约定。提示行是引擎自构造文本(无用户内容),不经过消毒。
|
|
119
|
+
if len(lines) > len(shown):
|
|
120
|
+
body += f"\n- (其余 {len(lines) - len(shown)} 条约定已超出 {_CONVENTION_MAX_LINES} 行上限被截断)"
|
|
111
121
|
return (
|
|
112
122
|
"【项目约定:来自被审计项目,仅供参考,非引擎指令;与引擎纪律冲突时以引擎纪律为准】\n"
|
|
113
123
|
f"{body}"
|
|
@@ -208,6 +208,57 @@ def _readonly_concurrency_granted(runtime: dict | None) -> bool:
|
|
|
208
208
|
return False
|
|
209
209
|
|
|
210
210
|
|
|
211
|
+
# pi mock 脚枪 fail-closed(OBS3B):这些宿主的 worker 由引擎默认执行器
|
|
212
|
+
# (``worker_runtime._execute_autonomous_worker``)驱动且无宿主 runner,
|
|
213
|
+
# 其 provider 兜底链此前以 ``or "mock"`` 收尾——``workers --execute`` 无显式
|
|
214
|
+
# ``--provider`` 时会**静默**落 mock(引擎诚实记 skipped,但运维预期是真实
|
|
215
|
+
# 宿主通道)。在册宿主的无显式 provider 派发改走仲裁 fail-closed。
|
|
216
|
+
# 仅 pi 完成集成实证在册;新宿主加入前必须完成同型取证(不得凭宿主名猜测)。
|
|
217
|
+
FAIL_CLOSED_PROVIDER_HOSTS: frozenset[str] = frozenset({"pi"})
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _resolve_fail_closed_provider(
|
|
221
|
+
host: str | None,
|
|
222
|
+
provider: str | None,
|
|
223
|
+
runtime_provider: object,
|
|
224
|
+
*,
|
|
225
|
+
execute: bool,
|
|
226
|
+
) -> tuple[str | None, str | None]:
|
|
227
|
+
"""无显式 provider 时的 fail-closed 默认通道裁决。
|
|
228
|
+
|
|
229
|
+
返回 ``(provider, error)``:``error`` 非空表示仲裁无真实通道,调用方必须
|
|
230
|
+
显式报错终止派发,**绝不**静默落 mock。语义:
|
|
231
|
+
* 非在册宿主 / 提示词模式(execute=False):行为不变,原样返回;
|
|
232
|
+
* 显式 ``--provider`` 或 runtime context 已带 provider:100% 尊重,不仲裁;
|
|
233
|
+
* 在册宿主 + 执行模式 + 无任何显式 provider:``arbitrate_host_provider``
|
|
234
|
+
取最优真实通道;仲裁为空 / mock-only 时返回显式错误。
|
|
235
|
+
"""
|
|
236
|
+
host_key = str(host or "").strip().casefold()
|
|
237
|
+
if host_key not in FAIL_CLOSED_PROVIDER_HOSTS:
|
|
238
|
+
return provider, None
|
|
239
|
+
if not execute:
|
|
240
|
+
return provider, None
|
|
241
|
+
explicit = str(provider or "").strip()
|
|
242
|
+
if explicit:
|
|
243
|
+
return explicit, None
|
|
244
|
+
from_runtime = str(runtime_provider or "").strip()
|
|
245
|
+
if from_runtime:
|
|
246
|
+
return from_runtime, None
|
|
247
|
+
try:
|
|
248
|
+
from core.host_runtime.host_provider_arbitrator import arbitrate_host_provider
|
|
249
|
+
|
|
250
|
+
arbitrated, _model, _cand, _manifest = arbitrate_host_provider(host_key)
|
|
251
|
+
except (ImportError, OSError, ValueError, RuntimeError) as exc:
|
|
252
|
+
return None, (
|
|
253
|
+
f"{host_key} 无可用真实通道,需显式 --provider 或检查宿主配置"
|
|
254
|
+
f"(仲裁失败: {exc})"
|
|
255
|
+
)
|
|
256
|
+
channel = str(arbitrated or "").strip()
|
|
257
|
+
if not channel or channel.casefold() in {"mock", "none"}:
|
|
258
|
+
return None, f"{host_key} 无可用真实通道,需显式 --provider 或检查宿主配置"
|
|
259
|
+
return channel, None
|
|
260
|
+
|
|
261
|
+
|
|
211
262
|
def workers(
|
|
212
263
|
count: int | None = None,
|
|
213
264
|
strategy: str = "risk",
|
|
@@ -482,13 +533,15 @@ def workers(
|
|
|
482
533
|
|
|
483
534
|
# 2. 自适应并发容量动态计算
|
|
484
535
|
runtime_count = runtime.get("workers")
|
|
485
|
-
|
|
486
|
-
|
|
536
|
+
# F-RSI-20261112-077:0 不是合法并发请求(旧代码校验放行 0 后被下方
|
|
537
|
+
# ``count > 0`` 静默吞掉回退 ceiling——契约与实现不一致)。统一正整数语义。
|
|
538
|
+
if count is not None and (not isinstance(count, int) or isinstance(count, bool) or count <= 0):
|
|
539
|
+
print("✗ worker count 必须是正整数")
|
|
487
540
|
return 2
|
|
488
541
|
if runtime_count is not None and (
|
|
489
|
-
not isinstance(runtime_count, int) or isinstance(runtime_count, bool) or runtime_count
|
|
542
|
+
not isinstance(runtime_count, int) or isinstance(runtime_count, bool) or runtime_count <= 0
|
|
490
543
|
):
|
|
491
|
-
print("✗ runtime workers
|
|
544
|
+
print("✗ runtime workers 必须是正整数")
|
|
492
545
|
return 2
|
|
493
546
|
requested_limit = (
|
|
494
547
|
count if isinstance(count, int) and count > 0
|
|
@@ -587,16 +640,26 @@ def workers(
|
|
|
587
640
|
"capacity": capacity,
|
|
588
641
|
}, ensure_ascii=False, sort_keys=True))
|
|
589
642
|
return 0
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
643
|
+
# pi mock 脚枪 fail-closed(OBS3B):在册宿主以执行模式派发且无显式 provider
|
|
644
|
+
# 时,此前会经 supervisor worker_runtime 的 ``or "mock"`` 兜底**静默**落 mock。
|
|
645
|
+
# 这里在 claim 之前收口:仲裁出真实通道则采用(容量规划与任务装配同步感知),
|
|
646
|
+
# 仲裁无真实通道则显式报错终止——绝不静默落 mock,也绝不产生孤儿租约。
|
|
647
|
+
provider_before_fail_closed = provider
|
|
648
|
+
provider, fail_closed_err = _resolve_fail_closed_provider(
|
|
649
|
+
selected_host, provider, runtime.get("provider"),
|
|
650
|
+
execute=effective_execute,
|
|
651
|
+
)
|
|
652
|
+
if fail_closed_err:
|
|
653
|
+
print(f"✗ {fail_closed_err}")
|
|
654
|
+
return 2
|
|
655
|
+
if provider and provider != provider_before_fail_closed:
|
|
656
|
+
print(f" [{selected_host} 通道裁决] 无显式 --provider,fail-closed 选定仲裁最优真实通道: {provider}")
|
|
657
|
+
# 两阶段派发(F-RSI-20261112-077):先为**全部**候选任务包解析互斥作用域,
|
|
658
|
+
# 任何文件型单元解析失败都在**零 claim** 状态下 fail-closed——旧实现
|
|
659
|
+
# raise 发生在预占循环中间,前面已成功 claim 的租约成为无人执行的孤儿
|
|
660
|
+
# (占用并发槽位直到 300s 租约过期)。fail-closed 语义不变,孤儿窗口归零。
|
|
661
|
+
bundle_res_keys: list[list[str]] = []
|
|
594
662
|
for bundle in selected_bundles:
|
|
595
|
-
if len(assigned) >= limit:
|
|
596
|
-
break
|
|
597
|
-
worker_id, next_worker_index = _next_worker_id(
|
|
598
|
-
worker_prefix, worker_ids, next_worker_index,
|
|
599
|
-
)
|
|
600
663
|
res_keys = [f"unit:{u}" for u in bundle]
|
|
601
664
|
for u in bundle:
|
|
602
665
|
fp = None
|
|
@@ -632,6 +695,19 @@ def workers(
|
|
|
632
695
|
) from failure
|
|
633
696
|
if fp and f"file:{fp}" not in res_keys:
|
|
634
697
|
res_keys.append(f"file:{fp}")
|
|
698
|
+
bundle_res_keys.append(res_keys)
|
|
699
|
+
|
|
700
|
+
assigned = []
|
|
701
|
+
worker_prefix = _worker_id_prefix(state)
|
|
702
|
+
worker_ids = set(state.claims)
|
|
703
|
+
next_worker_index = 1
|
|
704
|
+
for bundle_index, bundle in enumerate(selected_bundles):
|
|
705
|
+
if len(assigned) >= limit:
|
|
706
|
+
break
|
|
707
|
+
worker_id, next_worker_index = _next_worker_id(
|
|
708
|
+
worker_prefix, worker_ids, next_worker_index,
|
|
709
|
+
)
|
|
710
|
+
res_keys = bundle_res_keys[bundle_index]
|
|
635
711
|
lease_secs = 300.0
|
|
636
712
|
try:
|
|
637
713
|
from core.supervisor import task_scheduler
|
|
@@ -659,16 +735,20 @@ def workers(
|
|
|
659
735
|
if not assigned:
|
|
660
736
|
print("✗ 没有成功预占可执行单元;请检查租约、资源冲突或目标漂移")
|
|
661
737
|
return 1
|
|
662
|
-
|
|
663
|
-
#
|
|
664
|
-
#
|
|
665
|
-
#
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
738
|
+
if scheduler is not None:
|
|
739
|
+
# 守卫(F-RSI-20261112-077):调度器装配失败时 scheduler=None 且
|
|
740
|
+
# ``sched`` 未定义——旧代码靠裸 ``except Exception`` 吞 NameError,
|
|
741
|
+
# 提速路径静默失效不可观测。显式守卫后该分支语义自明。
|
|
742
|
+
try:
|
|
743
|
+
# DOC-140 调度提速:复用它上面已经建好的调度器实例(行 555),
|
|
744
|
+
# 不再第二次构造——每次构造都要全仓建图 + 影响网络 + git diff;
|
|
745
|
+
# 并把整批 advance_cycle 包进 batch_history,只落盘一次。
|
|
746
|
+
with sched.batch_history():
|
|
747
|
+
for c in assigned:
|
|
748
|
+
for cu in c.unit_ids:
|
|
749
|
+
sched.advance_cycle(selected_unit_id=cu, candidate_units=candidates)
|
|
750
|
+
except Exception:
|
|
751
|
+
pass
|
|
672
752
|
try:
|
|
673
753
|
supervisor_state = supervisor_state_path()
|
|
674
754
|
state_display = str(supervisor_state.resolve().relative_to(resolve_project_root().resolve()))
|
|
@@ -1061,9 +1141,9 @@ def workers(
|
|
|
1061
1141
|
if selected_capacity is not None and (
|
|
1062
1142
|
not isinstance(selected_capacity, int)
|
|
1063
1143
|
or isinstance(selected_capacity, bool)
|
|
1064
|
-
or selected_capacity
|
|
1144
|
+
or selected_capacity <= 0
|
|
1065
1145
|
):
|
|
1066
|
-
print("✗ max_workers/worker_capacity
|
|
1146
|
+
print("✗ max_workers/worker_capacity 必须是正整数")
|
|
1067
1147
|
return 2
|
|
1068
1148
|
# 并发上限 = **多源约束取最小值**(系统资源 / 宿主容量 / provider 配额 / 请求值 /
|
|
1069
1149
|
# 待办数)。任何单源决定都会越界:机器只扛 2 路时接口给 10 没用,宿主只支持 5
|
package/core/ledger/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BugX Ledger (攻防复盘账本与错题经验库)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `1.
|
|
3
|
+
> **版本契约**: `0.1.1` | **所属分层**: `Layer 3: 并发协调、智能体编排与账本`
|
|
4
4
|
> **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md)
|
|
5
5
|
> **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
|
|
6
6
|
|
package/core/ledger/SPEC.md
CHANGED
|
@@ -21,5 +21,5 @@ from core.ledger import record_finding, load_session_ledger
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 5. Maintenance & Verification
|
|
24
|
-
-
|
|
24
|
+
- Verification is performed with short-lived tests outside the repository; no persistent `tests/` registry is retained.
|
|
25
25
|
- Changes to exported interfaces must be synchronized via `python3 scripts/gen_interface_spec.py --package core/ledger --write`.
|
package/core/ledger/_facade.py
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
等价性:``lesson_ledger`` 本身也只是「从各兄弟模块 re-export」的纯 Facade,
|
|
15
15
|
且经核对 **160 个导出名无一被多个模块重复导出**,因此「名字 → 模块」的映射
|
|
16
16
|
是**唯一确定**的,本表与 ``getattr(lesson_ledger, name)`` 必然解析到同一对象。
|
|
17
|
-
|
|
17
|
+
该等价性以映射表与 ``lesson_ledger.py`` 导入块的核对为准(160 名无重复导出,
|
|
18
|
+
名字→模块映射唯一确定)。
|
|
18
19
|
"""
|
|
19
20
|
|
|
20
21
|
from __future__ import annotations
|
|
@@ -36,6 +36,38 @@ _ledger = LedgerProxy()
|
|
|
36
36
|
# _ledger.SCHEMA_VERSION delegates to _ledger.SCHEMA_VERSION
|
|
37
37
|
FTS_COLUMNS = ("pattern_id", "category", "title", "root_cause", "reflection", "probes", "aliases")
|
|
38
38
|
|
|
39
|
+
#: F-134: 归档 root_hash 的**库外只读锚**文件名。root_hash 不能再只与 manifest
|
|
40
|
+
#: 同存 DB meta 由库内两份数据互证;必须另存到与 DB 物理分离的独立文件,
|
|
41
|
+
#: 深度校验以「DB manifest 重算值 vs 库外锚」判定,缺失/损坏一律 fail-closed。
|
|
42
|
+
ARCHIVE_ANCHOR_NAME = ".archive-root.anchor"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _archive_anchor_path(outdir: str | os.PathLike[str]) -> Path:
|
|
46
|
+
return Path(outdir) / ARCHIVE_ANCHOR_NAME
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _write_archive_anchor(anchor: Path, root_hash: str,
|
|
50
|
+
manifest: list[dict[str, Any]]) -> None:
|
|
51
|
+
"""把归档根哈希原子写入库外只读锚(与 SQLite DB 物理分离)。"""
|
|
52
|
+
payload = {
|
|
53
|
+
"archive_root_hash": root_hash,
|
|
54
|
+
"manifest_sha256": hashlib.sha256(_canon(manifest)).hexdigest(),
|
|
55
|
+
}
|
|
56
|
+
blob = json.dumps(payload, ensure_ascii=False, sort_keys=True).encode("utf-8")
|
|
57
|
+
fd, tmp_name = tempfile.mkstemp(prefix=".anchor-", suffix=".tmp", dir=anchor.parent)
|
|
58
|
+
tmp = Path(tmp_name)
|
|
59
|
+
try:
|
|
60
|
+
with os.fdopen(fd, "wb") as handle:
|
|
61
|
+
handle.write(blob)
|
|
62
|
+
handle.flush()
|
|
63
|
+
os.fsync(handle.fileno())
|
|
64
|
+
os.chmod(tmp, 0o444)
|
|
65
|
+
os.replace(tmp, anchor)
|
|
66
|
+
except BaseException:
|
|
67
|
+
if tmp.is_file():
|
|
68
|
+
tmp.unlink()
|
|
69
|
+
raise
|
|
70
|
+
|
|
39
71
|
|
|
40
72
|
class _ErrorMeta(type):
|
|
41
73
|
def __instancecheck__(cls, instance):
|
|
@@ -435,9 +467,25 @@ def validate_deep(path: str | os.PathLike[str]) -> dict[str, Any]:
|
|
|
435
467
|
archived_seq = _meta_value(c, "archive_last_seq")
|
|
436
468
|
if manifest:
|
|
437
469
|
root = hashlib.sha256(_canon(manifest)).hexdigest()
|
|
470
|
+
# F-134: 只比 DB 内 manifest 与 DB 内 archive_root_hash 不算完整性校验;
|
|
471
|
+
# 必须与库外只读锚互证,锚缺失/损坏/不符一律 fail-closed。
|
|
472
|
+
archive_dir = _meta_value(c, "archive_dir")
|
|
473
|
+
anchor = _archive_anchor_path(archive_dir) if archive_dir else None
|
|
474
|
+
if anchor is None or not anchor.is_file():
|
|
475
|
+
issues.append("archive_root_hash 库外锚缺失,拒绝通过深度校验")
|
|
476
|
+
else:
|
|
477
|
+
try:
|
|
478
|
+
anchor_data = json.loads(anchor.read_text(encoding="utf-8"))
|
|
479
|
+
except (OSError, ValueError) as exc:
|
|
480
|
+
issues.append(f"archive_root_hash 库外锚损坏: {exc}")
|
|
481
|
+
anchor_data = None
|
|
482
|
+
if anchor_data is not None:
|
|
483
|
+
if str(anchor_data.get("archive_root_hash", "")) != root:
|
|
484
|
+
issues.append("archive_root_hash 与库外锚不一致")
|
|
485
|
+
if str(anchor_data.get("manifest_sha256", "")) != root:
|
|
486
|
+
issues.append("archive manifest 摘要与库外锚不一致")
|
|
438
487
|
if _meta_value(c, "archive_root_hash") != root:
|
|
439
488
|
issues.append("archive_root_hash 与 manifest 不一致")
|
|
440
|
-
archive_dir = _meta_value(c, "archive_dir")
|
|
441
489
|
if not archive_dir or not Path(archive_dir).is_dir():
|
|
442
490
|
issues.append("archive_dir 缺失,无法验证归档段")
|
|
443
491
|
else:
|
|
@@ -482,7 +530,8 @@ def archive_events(path: str | os.PathLike[str], output_dir: str | os.PathLike[s
|
|
|
482
530
|
2) segment 以临时文件写入、fsync 后原子发布到最终路径;
|
|
483
531
|
3) 再开写事务:校验 head 未变 → 删除已归档区间 → 写入 manifest、
|
|
484
532
|
archive root hash、最后归档 seq/hash(新的连续起点证明)→ 提交;
|
|
485
|
-
|
|
533
|
+
同批把 root_hash 原子写入库外只读锚(与 DB 物理分离,F-134);
|
|
534
|
+
4) 发布成功但事务失败的进程内异常会删除未登记的 segment 文件与库外锚;
|
|
486
535
|
5) 进程中断留下的孤儿文件内容是确定性的,重跑会用相同字节覆盖收敛。
|
|
487
536
|
"""
|
|
488
537
|
if not isinstance(keep_tail, int) or isinstance(keep_tail, bool) or keep_tail < 0:
|
|
@@ -528,6 +577,8 @@ def archive_events(path: str | os.PathLike[str], output_dir: str | os.PathLike[s
|
|
|
528
577
|
fd, tmp_name = tempfile.mkstemp(prefix=".segment-", suffix=".tmp", dir=outdir)
|
|
529
578
|
tmp = Path(tmp_name)
|
|
530
579
|
published = False
|
|
580
|
+
anchor_path: Path | None = None
|
|
581
|
+
anchor_published = False
|
|
531
582
|
try:
|
|
532
583
|
with os.fdopen(fd, "wb") as handle:
|
|
533
584
|
handle.write(blob)
|
|
@@ -536,6 +587,11 @@ def archive_events(path: str | os.PathLike[str], output_dir: str | os.PathLike[s
|
|
|
536
587
|
os.replace(tmp, final)
|
|
537
588
|
published = True
|
|
538
589
|
|
|
590
|
+
# F-134: 库外只读锚与 DB 分离写入;若 DB 事务失败,异常路径一并撤销。
|
|
591
|
+
anchor_path = _archive_anchor_path(outdir)
|
|
592
|
+
_write_archive_anchor(anchor_path, root_hash, new_manifest)
|
|
593
|
+
anchor_published = True
|
|
594
|
+
|
|
539
595
|
def go(c):
|
|
540
596
|
if _meta_value(c, "head_hash") != head_snapshot:
|
|
541
597
|
raise LessonLedgerError("归档期间账本发生变化,拒绝提交本次归档")
|
|
@@ -567,6 +623,8 @@ def archive_events(path: str | os.PathLike[str], output_dir: str | os.PathLike[s
|
|
|
567
623
|
final.unlink()
|
|
568
624
|
elif tmp.is_file():
|
|
569
625
|
tmp.unlink()
|
|
626
|
+
if anchor_published and anchor_path is not None:
|
|
627
|
+
anchor_path.unlink()
|
|
570
628
|
except OSError:
|
|
571
629
|
pass
|
|
572
630
|
raise
|
package/core/ledger/cli.py
CHANGED
|
@@ -264,7 +264,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
264
264
|
if isinstance(result, dict):
|
|
265
265
|
result.setdefault("ledger_path", str(args.ledger))
|
|
266
266
|
print(json.dumps(result,ensure_ascii=False,indent=2)); return 0
|
|
267
|
-
except (LessonLedgerError,OSError,sqlite3.Error, json.JSONDecodeError) as exc:
|
|
267
|
+
except (LessonLedgerError, ValueError, OSError, sqlite3.Error, json.JSONDecodeError) as exc:
|
|
268
|
+
# F-RSI-20261115-135:ValueError 兜底——四个域异常类(LifecycleError/
|
|
269
|
+
# VerificationError/ConfirmationError/SensitiveSyncError)与
|
|
270
|
+
# life_ledger.finding_identity 的裸 ValueError 全是 ValueError 子类,
|
|
271
|
+
# 旧表漏捕 → 宿主拿到 traceback + rc=1 而非干净 rc=2 + 语义消息。
|
|
272
|
+
print(f"[lesson_ledger] ✗ {exc}", file=sys.stderr); return 2
|
|
268
273
|
|
|
269
274
|
|
|
270
275
|
if __name__ == "__main__": raise SystemExit(main())
|
|
@@ -154,10 +154,15 @@ def promote_pattern(project_ledger: str | os.PathLike[str],
|
|
|
154
154
|
cleaned = _sanitize_promotion_payload(cleaned)
|
|
155
155
|
|
|
156
156
|
# 写入全局库
|
|
157
|
+
# F-RSI-20261115-163:bundle_id 必须确定性(不含时间戳)——两段写入
|
|
158
|
+
# (全局导入→项目标记)无分布式事务,间隙失败后重试时旧实现秒级时间戳
|
|
159
|
+
# 使 bundle_id 变化 → import_patterns 幂等检查失效 → 撞「已有模式冲突」
|
|
160
|
+
# 防线 → 重试永远失败、项目库 promoted 标记永远补不上(卡死循环)。
|
|
161
|
+
# 确定性 bundle_id 让重试走 already_imported 幂等分支,标记事件照常补写。
|
|
157
162
|
g_db = database_path(global_ledger)
|
|
158
163
|
result = import_patterns(
|
|
159
164
|
g_db, [cleaned],
|
|
160
|
-
bundle_id=f"promote-{pid}
|
|
165
|
+
bundle_id=f"promote-{pid}",
|
|
161
166
|
reviewer=actor,
|
|
162
167
|
actor="publisher",
|
|
163
168
|
)
|
|
@@ -673,19 +673,25 @@ def confirmation_issues(finding: dict) -> list[str]:
|
|
|
673
673
|
|
|
674
674
|
|
|
675
675
|
def _evidence_paths(finding: dict) -> set[str]:
|
|
676
|
-
"""收集 finding 指向的源码路径(file/path/artifact_path/evidence[].path)。
|
|
676
|
+
"""收集 finding 指向的源码路径(file/path/artifact_path/evidence[].path)。
|
|
677
|
+
|
|
678
|
+
F-RSI-20261110-028:逐条 ``os.path.normpath`` 归一——oracle 侧 reference
|
|
679
|
+
经 ``resolve()`` 已是规范路径,证据侧此前只 ``lstrip("./")``,
|
|
680
|
+
``sub/../x.py`` 型别名会绕过 oracle 独立性重合检查(同一文件既当判据
|
|
681
|
+
又当证据)。与 F-019 路径别名漏并向同根因:路径比较前必须归一。
|
|
682
|
+
"""
|
|
677
683
|
paths: set[str] = set()
|
|
678
684
|
for key in ("file", "path", "artifact_path"):
|
|
679
685
|
value = finding.get(key)
|
|
680
686
|
if _nonempty(value):
|
|
681
|
-
paths.add(str(value).strip().lstrip("./"))
|
|
687
|
+
paths.add(os.path.normpath(str(value).strip().lstrip("./")))
|
|
682
688
|
evidence = finding.get("evidence")
|
|
683
689
|
if isinstance(evidence, list):
|
|
684
690
|
for item in evidence:
|
|
685
691
|
if isinstance(item, dict) and _nonempty(item.get("path")):
|
|
686
|
-
paths.add(str(item["path"]).strip().lstrip("./"))
|
|
692
|
+
paths.add(os.path.normpath(str(item["path"]).strip().lstrip("./")))
|
|
687
693
|
elif isinstance(item, str) and item.strip():
|
|
688
|
-
paths.add(item.strip().lstrip("./"))
|
|
694
|
+
paths.add(os.path.normpath(item.strip().lstrip("./")))
|
|
689
695
|
return paths
|
|
690
696
|
|
|
691
697
|
|
|
@@ -909,9 +915,16 @@ def apply_decision(
|
|
|
909
915
|
receipt: object = None, oracle: object = None, root_cause_verified: object = None,
|
|
910
916
|
remediation: object = None, target_platform: object = None,
|
|
911
917
|
rejection_class: object = None, root=None,
|
|
918
|
+
severity: object = None,
|
|
912
919
|
) -> dict:
|
|
913
|
-
"""
|
|
920
|
+
"""``severity``:确认方对 confirmed 报告的定级补录(F-RSI-20261118-009)。
|
|
921
|
+
|
|
922
|
+
triage 档 worker 的候选可能不携带 severity(初筛不定级是合法形态),
|
|
923
|
+
而 confirmed 门禁要求有效 severity——评级责任随确认动作落到确认方。
|
|
924
|
+
仅在 ``decision == "confirmed"`` 且确认方显式提供合法值(SEVERITY_ORDER
|
|
925
|
+
值域)时补写;finding 已有有效 severity 时不覆盖(worker 定级优先)。
|
|
914
926
|
|
|
927
|
+
唯一的 Finding 裁决写入口:合并证据 → 门禁自检 → 通过才返回新块。
|
|
915
928
|
失败一律抛 :class:`ConfirmationError`,调用方不得落盘——半成品 confirmed
|
|
916
929
|
正是 L1-ADV-D1 的成因(写入侧不校验读取侧门禁)。
|
|
917
930
|
"""
|
|
@@ -957,13 +970,42 @@ def apply_decision(
|
|
|
957
970
|
confirmation["decided_by"] = "confirm_finding"
|
|
958
971
|
work["confirmation"] = confirmation
|
|
959
972
|
if decision == "confirmed":
|
|
973
|
+
# F-RSI-20261118-009:确认方定级补录——仅补缺失/无效的 severity,
|
|
974
|
+
# 已有有效值(worker 定级)不覆盖;非法值 fail-closed 抛错。
|
|
975
|
+
if severity is not None:
|
|
976
|
+
normalized = str(severity).strip().lower()
|
|
977
|
+
from core.agent import agent_eval
|
|
978
|
+
if normalized not in agent_eval.SEVERITY_ORDER:
|
|
979
|
+
raise ConfirmationError(
|
|
980
|
+
f"severity 无效: {severity!r}(允许 {sorted(agent_eval.SEVERITY_ORDER)})"
|
|
981
|
+
)
|
|
982
|
+
current = str(work.get("severity") or "").strip().lower()
|
|
983
|
+
if current not in agent_eval.SEVERITY_ORDER:
|
|
984
|
+
work["severity"] = normalized
|
|
960
985
|
issues = confirmation_issues(work)
|
|
961
986
|
if issues:
|
|
962
987
|
raise ConfirmationError(
|
|
963
988
|
"确认门禁失败,拒绝写入不可收敛的 confirmed:" + ";".join(issues)
|
|
964
989
|
)
|
|
990
|
+
if issues:
|
|
991
|
+
raise ConfirmationError(
|
|
992
|
+
"确认门禁失败,拒绝写入不可收敛的 confirmed:" + ";".join(issues)
|
|
993
|
+
)
|
|
965
994
|
validate_confirmation(work)
|
|
966
|
-
|
|
995
|
+
severity_applied: str | None = None
|
|
996
|
+
if decision == "confirmed" and severity is not None:
|
|
997
|
+
normalized_sev = str(severity).strip().lower()
|
|
998
|
+
if normalized_sev in agent_eval.SEVERITY_ORDER:
|
|
999
|
+
current = str(work.get("severity") or "").strip().lower()
|
|
1000
|
+
if current not in agent_eval.SEVERITY_ORDER:
|
|
1001
|
+
work["severity"] = normalized_sev
|
|
1002
|
+
severity_applied = normalized_sev
|
|
1003
|
+
result: dict = {
|
|
1004
|
+
"confirmation": dict(confirmation),
|
|
1005
|
+
"remediation": None,
|
|
1006
|
+
"severity_applied": severity_applied,
|
|
1007
|
+
"severity_final": str(work.get("severity") or "") or None,
|
|
1008
|
+
}
|
|
967
1009
|
if remediation is not None:
|
|
968
1010
|
if not isinstance(remediation, Mapping):
|
|
969
1011
|
# 只说「必须是对象」是不可自愈的:worker 交了合理的人类可读建议
|