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
package/core/hosts/pi.py
CHANGED
|
@@ -12,13 +12,16 @@
|
|
|
12
12
|
* engine_run ← 无头通道为 ``pi --approve -p <prompt>``,自治执行为 ``pi --approve -p <prompt> --mode json``;
|
|
13
13
|
无原生 Task / Subagent 编排(``native_task=False``)。
|
|
14
14
|
* worker_runtime← ``mode="process"``,最大并发 4 路;独立进程模式。
|
|
15
|
-
* mcp_write ← 配置容器键为 ``mcpServers``,项目级作用域为 ``.pi/mcp.json
|
|
15
|
+
* mcp_write ← 配置容器键为 ``mcpServers``,项目级作用域为 ``.pi/mcp.json``;
|
|
16
|
+
根绝对化在插件 ``bootstrap`` 写入路径落地(``Path.resolve()``
|
|
17
|
+
后落盘,dsh 同类 cwd 陷阱已消解)。
|
|
16
18
|
* acp ← 上游 ``pi 0.85.1`` 无 ACP 子命令/flag,由 ``core/host_acp/pi.py``
|
|
17
19
|
以 ``status="unavailable"`` 声明。
|
|
18
20
|
"""
|
|
19
21
|
|
|
20
22
|
from __future__ import annotations
|
|
21
23
|
|
|
24
|
+
import shutil
|
|
22
25
|
from pathlib import Path
|
|
23
26
|
|
|
24
27
|
from .base import (
|
|
@@ -33,7 +36,7 @@ from .base import (
|
|
|
33
36
|
WorkerRuntimeFacet,
|
|
34
37
|
)
|
|
35
38
|
|
|
36
|
-
__all__ = ["PLUGIN"]
|
|
39
|
+
__all__ = ["PLUGIN", "is_available", "run_static_degraded"]
|
|
37
40
|
|
|
38
41
|
_NAME = "pi"
|
|
39
42
|
|
|
@@ -83,6 +86,92 @@ def _agent_config_path(root: Path) -> Path:
|
|
|
83
86
|
return root / ".pi"
|
|
84
87
|
|
|
85
88
|
|
|
89
|
+
_MCP_SERVERS_KEY = "mcpServers"
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _absolutize_mcp_args(args: list[str], root_str: str, root: Path) -> list[str]:
|
|
93
|
+
"""把 server argv 里的 ``--root`` 与项目内 ``--db`` 绝对化到本项目。
|
|
94
|
+
|
|
95
|
+
只改写这两个 token 的**下一个**参数;其余 argv 逐字保留。
|
|
96
|
+
"""
|
|
97
|
+
resolved = list(args)
|
|
98
|
+
for index, token in enumerate(resolved):
|
|
99
|
+
if token == "--root" and index + 1 < len(resolved):
|
|
100
|
+
resolved[index + 1] = root_str
|
|
101
|
+
elif (
|
|
102
|
+
token == "--db"
|
|
103
|
+
and index + 1 < len(resolved)
|
|
104
|
+
and str(resolved[index + 1]).startswith(".bugx/")
|
|
105
|
+
):
|
|
106
|
+
resolved[index + 1] = str(root / str(resolved[index + 1]))
|
|
107
|
+
return resolved
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _bootstrap(root: Path, servers) -> dict:
|
|
111
|
+
"""把 BugX 的 MCP 通道写进项目级 ``.pi/mcp.json``(幂等、根绝对化)。
|
|
112
|
+
|
|
113
|
+
历史缺陷(与 dsh 已记录陷阱同类):条目曾写死 ``--root .``,假设 Pi 以被测
|
|
114
|
+
项目为 cwd spawn stdio MCP server。MCP server 由长驻 Pi 宿主进程 spawn,
|
|
115
|
+
cwd 是 Pi 自己的目录,``.`` 于是指向宿主目录而不是被审计项目。插件声明
|
|
116
|
+
``requires_absolutize=True`` 的语义在**本写入路径**落地:root 先
|
|
117
|
+
``Path.resolve()`` 绝对化,再落盘 ``--root``/``--db``。
|
|
118
|
+
|
|
119
|
+
幂等语义与 dsh 一致:不能用「命中就跳过」——那会让换了项目的用户永远停留
|
|
120
|
+
在旧根;只按传入的 BugX 自有 server 名逐字段比对重写,``mcpServers`` 下
|
|
121
|
+
他人的配置逐字保留。非对象形态的既有配置 fail-fast,绝不静默覆盖。
|
|
122
|
+
"""
|
|
123
|
+
import json
|
|
124
|
+
|
|
125
|
+
import core.secure_atomic as secure_atomic
|
|
126
|
+
|
|
127
|
+
resolved = Path(root).expanduser().resolve()
|
|
128
|
+
target = resolved / ".pi" / "mcp.json"
|
|
129
|
+
if target.is_symlink():
|
|
130
|
+
raise OSError(f"拒绝通过符号链接写入 Pi MCP 配置: {target}")
|
|
131
|
+
existed = target.exists()
|
|
132
|
+
payload: dict = {}
|
|
133
|
+
if existed:
|
|
134
|
+
try:
|
|
135
|
+
loaded = json.loads(target.read_text(encoding="utf-8"))
|
|
136
|
+
except (OSError, UnicodeError, ValueError) as exc:
|
|
137
|
+
raise OSError(f"Pi MCP 配置无法解析: {target}: {exc}") from exc
|
|
138
|
+
if not isinstance(loaded, dict):
|
|
139
|
+
raise OSError(
|
|
140
|
+
f"Pi MCP 配置顶层必须是对象: {target}。"
|
|
141
|
+
'合法形态为 {"mcpServers": {"<name>": {...}}};'
|
|
142
|
+
"若文件为空或只有一个列表,请重建为对象后再重试。"
|
|
143
|
+
)
|
|
144
|
+
payload = loaded
|
|
145
|
+
container = payload.get(_MCP_SERVERS_KEY)
|
|
146
|
+
if container is None:
|
|
147
|
+
container = {}
|
|
148
|
+
payload[_MCP_SERVERS_KEY] = container
|
|
149
|
+
if not isinstance(container, dict):
|
|
150
|
+
raise OSError(f"Pi MCP 配置 mcpServers 必须是对象: {target}")
|
|
151
|
+
root_str = str(resolved)
|
|
152
|
+
desired: dict[str, dict] = {}
|
|
153
|
+
for name, entry in dict(servers).items():
|
|
154
|
+
normalized = dict(entry)
|
|
155
|
+
args = normalized.get("args")
|
|
156
|
+
if isinstance(args, list) and all(isinstance(token, str) for token in args):
|
|
157
|
+
normalized["args"] = _absolutize_mcp_args(args, root_str, resolved)
|
|
158
|
+
desired[str(name)] = normalized
|
|
159
|
+
changed = any(container.get(name) != entry for name, entry in desired.items())
|
|
160
|
+
if not changed:
|
|
161
|
+
return {
|
|
162
|
+
"path": str(target), "changed": False, "created": False,
|
|
163
|
+
"servers": sorted(desired),
|
|
164
|
+
}
|
|
165
|
+
mode = target.stat().st_mode & 0o777 if existed else 0o600
|
|
166
|
+
container.update(dict(desired))
|
|
167
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
168
|
+
secure_atomic.atomic_write_json(target, payload, mode=mode)
|
|
169
|
+
return {
|
|
170
|
+
"path": str(target), "changed": True, "created": not existed,
|
|
171
|
+
"servers": sorted(desired),
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
86
175
|
PLUGIN = HostPlugin(
|
|
87
176
|
identity=IdentityFacet(
|
|
88
177
|
name=_NAME,
|
|
@@ -137,6 +226,15 @@ PLUGIN = HostPlugin(
|
|
|
137
226
|
max_concurrency=1,
|
|
138
227
|
requires_process_mode=True,
|
|
139
228
|
sandbox_sync=(),
|
|
229
|
+
# pi 无自有 CLI worker 协议:审计循环仍由引擎默认执行器
|
|
230
|
+
# (``worker_runtime._execute_autonomous_worker``)独家承载,本模块
|
|
231
|
+
# (``host_runtime.pi``)只做宿主 profile 预算透传(见下)。
|
|
232
|
+
runner_module="host_runtime.pi",
|
|
233
|
+
# 单 claim 墙钟预算:集成验证实测(2026-11-17)——pi 无 runner_module 时
|
|
234
|
+
# 模型 CLI 超时回落 tier 阶梯 recon=180s,codex 模型在 checkpoint 准备
|
|
235
|
+
# 阶段超过 180s 即被 ``run_model`` 击杀(与 E1 cline FAIL 同根因,
|
|
236
|
+
# build.566 只覆盖了 cline)。与 cline 同值 600s。
|
|
237
|
+
worker_timeout_seconds=600.0,
|
|
140
238
|
),
|
|
141
239
|
mcp_write=McpWriteFacet(
|
|
142
240
|
container_key="mcpServers",
|
|
@@ -145,7 +243,66 @@ PLUGIN = HostPlugin(
|
|
|
145
243
|
global_scope=None,
|
|
146
244
|
mirror_relpaths=(),
|
|
147
245
|
requires_absolutize=True,
|
|
246
|
+
# ``requires_absolutize`` 的落地点:引擎侧启动/自治引导(bootstrap_host_mcp)
|
|
247
|
+
# 委托本实现,落盘前把 --root/--db 绝对化(dsh 同类 cwd 陷阱)。
|
|
248
|
+
bootstrap=_bootstrap,
|
|
148
249
|
entry_extra={},
|
|
149
250
|
),
|
|
150
251
|
acp=AcpFacet(plugin=_NAME),
|
|
151
252
|
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def is_available() -> tuple[bool, str]:
|
|
256
|
+
"""降级契约:机械探活 Pi CLI 是否安装(零子进程 ``shutil.which``)。
|
|
257
|
+
|
|
258
|
+
宿主探活语义:CLI 缺失时无头 ``pi --approve -p``、自治通道与 Pi 扩展面
|
|
259
|
+
全部不可用,调用方必须走 ``run_static_degraded`` 输出静态事实声明,
|
|
260
|
+
禁止伪装宿主可用。
|
|
261
|
+
"""
|
|
262
|
+
path = shutil.which("pi")
|
|
263
|
+
if path is None:
|
|
264
|
+
return False, "pi 可执行文件未安装;headless(pi --approve -p)与自治通道不可用"
|
|
265
|
+
return True, path
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def run_static_degraded(root: Path | None = None) -> dict:
|
|
269
|
+
"""Pi CLI 缺失时的静态降级输出:只声明插件事实,绝不伪装宿主健康。
|
|
270
|
+
|
|
271
|
+
输出与宿主真实可用状态字段级可区分:``status="degraded"`` + ``degraded=True``
|
|
272
|
+
+ ``degraded_reason``,且 ``headless_available`` / ``native_task_available``
|
|
273
|
+
跟随真实探活结果;MCP 健康检查在 CLI 缺失时显式声明 ``unknown``。
|
|
274
|
+
"""
|
|
275
|
+
available, availability_detail = is_available()
|
|
276
|
+
return {
|
|
277
|
+
"plugin": _NAME,
|
|
278
|
+
"schema_version": 1,
|
|
279
|
+
"success": available,
|
|
280
|
+
"status": "degraded",
|
|
281
|
+
"degraded": True,
|
|
282
|
+
"degraded_reason": (
|
|
283
|
+
"static_facts_only" if available else "pi_cli_not_installed"
|
|
284
|
+
),
|
|
285
|
+
"probe_mode": "static_degraded",
|
|
286
|
+
"headless_available": available,
|
|
287
|
+
"native_task_available": bool(available and PLUGIN.engine_run.native_task),
|
|
288
|
+
"mcp_health": "unknown" if not available else "not_probed",
|
|
289
|
+
"identity": {
|
|
290
|
+
"executable": PLUGIN.identity.executable,
|
|
291
|
+
"aliases": list(PLUGIN.identity.aliases),
|
|
292
|
+
"markers": list(PLUGIN.identity.markers),
|
|
293
|
+
},
|
|
294
|
+
"agent_entry": PLUGIN.install.path,
|
|
295
|
+
"mcp_project_relpath": PLUGIN.mcp_write.project_relpath,
|
|
296
|
+
"mcp_global_scope": PLUGIN.mcp_write.global_scope,
|
|
297
|
+
"mcp_config_format": getattr(PLUGIN.mcp_write, "config_format", "json"),
|
|
298
|
+
"findings": [],
|
|
299
|
+
"evidence": {
|
|
300
|
+
"availability_detail": availability_detail,
|
|
301
|
+
"project_root": str(root) if root else None,
|
|
302
|
+
},
|
|
303
|
+
"metadata": {
|
|
304
|
+
"degraded_mode": "static_plugin_facts_only",
|
|
305
|
+
"acp": "unavailable(机读声明,见 core/host_acp/pi.py)",
|
|
306
|
+
"fallback": "宿主 CLI 缺失时由外层宿主/用户决策接管;BugX 不代装宿主 CLI",
|
|
307
|
+
},
|
|
308
|
+
}
|
package/core/infra/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# BugX Core Infrastructure & Primitives (核心基础设施与底层操作系统原语子系统)
|
|
2
2
|
|
|
3
|
-
> **版本契约**: `1.
|
|
3
|
+
> **版本契约**: `0.1.1` | **所属分层**: `Layer 0: 基础设施与操作系统抽象`
|
|
4
4
|
> **工程规范**: 参见 [`docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md`](../../docs/02_architecture/05_ARCH_NOMENCLATURE_GUIDE.md) 与 [`docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md`](../../docs/02_architecture/06_MODULE_GOVERNANCE_SPEC.md)
|
|
5
|
-
> **守卫机制**: `scripts/verify_directory_indices.py`
|
|
5
|
+
> **守卫机制**: `scripts/verify_directory_indices.py` (100% 物理条目索引覆盖)
|
|
6
6
|
|
|
7
7
|
`core/infra/` 构成了 BugX 微内核底层的纯净基础设施与底层操作系统原生能力抽象,为上层分析规划、攻防探针、并发调度与宿主集成提供高可靠、零脆弱性的基础原语支撑。
|
|
8
8
|
|
|
@@ -15,6 +15,7 @@ core/infra/
|
|
|
15
15
|
├── __init__.py # 统一导出门面
|
|
16
16
|
├── build_info.py # 固化单调自增 Build ID,提供运行时版本与编译元数据
|
|
17
17
|
├── client_metadata.py # 采集宿主硬件架构、操作系统版本与 Node/Python 运行时信息
|
|
18
|
+
├── json_utils.py # 严格 JSON 对象解析辅助,拒绝重复键
|
|
18
19
|
├── python_runtime.py # 探测并驱动独立的受控 Python 解释器执行隔离代码
|
|
19
20
|
└── safe_xml.py # 防御 XXE (XML 外部实体注入) 的安全解析适配器
|
|
20
21
|
```
|
|
@@ -28,6 +29,7 @@ core/infra/
|
|
|
28
29
|
| `__init__.py` | 统一导出门面 | 聚合导出核心基础设施与系统原语接口 | `__all__` |
|
|
29
30
|
| `build_info.py` | 构建信息固化 | 固化单调自增 Build ID,提供运行时版本、Build ID 与编译元数据查询 | `build_id`, `build_version` |
|
|
30
31
|
| `client_metadata.py` | 元数据采集器 | 采集当前宿主机硬件架构、操作系统内核与 Node/Python 运行时环境信息 | `collect_client_metadata` |
|
|
32
|
+
| `json_utils.py` | JSON 容器校验 | 构建并校验无重复键的 JSON 对象,供协议解析器复用 | `unique_json_object` |
|
|
31
33
|
| `python_runtime.py` | 隔离解释器 | 探测、校验并驱动独立的受控 Python 解释器环境执行隔离代码 | `transparent_reexec_if_needed`, `resolve_python` |
|
|
32
34
|
| `safe_xml.py` | 安全 XML 解析 | 防御 XXE (XML 外部实体注入)、DTD 实体膨胀与超深 XML 递归的安全解析适配器 | `parse_xml`, `parse_xml_file`, `XmlSecurityError` |
|
|
33
35
|
|
package/core/infra/__init__.py
CHANGED
|
@@ -4,12 +4,14 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from . import build_info
|
|
6
6
|
from . import client_metadata
|
|
7
|
+
from . import json_utils
|
|
7
8
|
from . import python_runtime
|
|
8
9
|
from . import safe_xml
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
11
12
|
"build_info",
|
|
12
13
|
"client_metadata",
|
|
14
|
+
"json_utils",
|
|
13
15
|
"python_runtime",
|
|
14
16
|
"safe_xml",
|
|
15
17
|
]
|
package/core/infra/build_info.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""BugX 构建标识与自增 Build ID 管理模块 (DOC-169).
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
语义版本号从 ``BUGX_VERSION`` 解析;源码模板只在构建 staging 时物化。
|
|
5
5
|
日常开发与提交通过单调自增、从 1 开始无上限递增的 Build ID 进行版本追踪。
|
|
6
6
|
"""
|
|
7
7
|
|
|
@@ -11,7 +11,23 @@ import os
|
|
|
11
11
|
import re
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
VERSION_ENV = "BUGX_VERSION"
|
|
15
|
+
VERSION_TOKEN = "0.1.1"
|
|
16
|
+
_DEFAULT_VERSION = "0.1.1"
|
|
17
|
+
_VERSION_RE = re.compile(r"^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def resolve_base_version(value: str | None = None) -> str:
|
|
21
|
+
"""Resolve the base version from ``BUGX_VERSION`` with one source fallback."""
|
|
22
|
+
candidate = (value or os.environ.get(VERSION_ENV) or _DEFAULT_VERSION).strip()
|
|
23
|
+
if candidate == VERSION_TOKEN:
|
|
24
|
+
candidate = os.environ.get(VERSION_ENV, _DEFAULT_VERSION).strip()
|
|
25
|
+
if not _VERSION_RE.fullmatch(candidate):
|
|
26
|
+
raise ValueError(f"invalid BugX version: {candidate!r}")
|
|
27
|
+
return candidate
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
BASE_VERSION = resolve_base_version()
|
|
15
31
|
_BUILD_ID_RE = re.compile(r"^build_id:\s*(\d+)", re.M)
|
|
16
32
|
|
|
17
33
|
|
|
@@ -73,14 +89,17 @@ def bump_build_id(root: Path | None = None) -> int:
|
|
|
73
89
|
|
|
74
90
|
|
|
75
91
|
def get_full_version_string(root: Path | None = None) -> str:
|
|
76
|
-
"""返回标准版本与 Build ID 组合字符串,例如 1.
|
|
92
|
+
"""返回标准版本与 Build ID 组合字符串,例如 0.1.1+build.627。"""
|
|
77
93
|
bid = get_build_id(root)
|
|
78
94
|
return f"{BASE_VERSION}+build.{bid}"
|
|
79
95
|
|
|
80
96
|
|
|
81
97
|
__all__ = [
|
|
82
98
|
"BASE_VERSION",
|
|
99
|
+
"VERSION_ENV",
|
|
100
|
+
"VERSION_TOKEN",
|
|
83
101
|
"bump_build_id",
|
|
84
102
|
"get_build_id",
|
|
85
103
|
"get_full_version_string",
|
|
104
|
+
"resolve_base_version",
|
|
86
105
|
]
|
|
@@ -65,7 +65,7 @@ def client_version(metadata_path: str | Path | None = None) -> str:
|
|
|
65
65
|
if value:
|
|
66
66
|
return value
|
|
67
67
|
try:
|
|
68
|
-
return importlib.metadata.version("bugx-
|
|
68
|
+
return importlib.metadata.version("bugx-cli")
|
|
69
69
|
except importlib.metadata.PackageNotFoundError:
|
|
70
70
|
return "unknown"
|
|
71
71
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Small JSON container helpers shared by protocol validators."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Iterable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def unique_json_object(
|
|
10
|
+
pairs: Iterable[tuple[str, Any]],
|
|
11
|
+
*,
|
|
12
|
+
error_factory: Callable[[str], Exception] | None = None,
|
|
13
|
+
) -> dict[str, Any]:
|
|
14
|
+
"""Build an object while rejecting duplicate JSON member names."""
|
|
15
|
+
result: dict[str, Any] = {}
|
|
16
|
+
for key, value in pairs:
|
|
17
|
+
if key in result:
|
|
18
|
+
if error_factory is None:
|
|
19
|
+
raise ValueError(f"duplicate JSON object key: {key}")
|
|
20
|
+
raise error_factory(key)
|
|
21
|
+
result[key] = value
|
|
22
|
+
return result
|
|
@@ -88,7 +88,7 @@ flowchart TD
|
|
|
88
88
|
| `SPEC.md` | 生命周期规范设计与状态迁移状态机真理文档 | 阶段规范与失败处理契约 |
|
|
89
89
|
| `startup_gates.py` | 启动前置安全门禁(文件树白名单、脏工作区检查、权限拦截) | `verify_startup_gates` |
|
|
90
90
|
| `startup_interaction.py` | 交互式问答决策引擎,根据终端能力与配置解析交互模式 | `resolve_startup_interaction` |
|
|
91
|
-
| `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `1.
|
|
91
|
+
| `startup_version_gate.py` | 版本硬门禁校验器,确保运行时版本严格等于 `0.1.1` 绝不漂移 | `assert_version_integrity` |
|
|
92
92
|
| `supervisor_bridge.py` | Supervisor 模块间解耦桥接层,提供轻量化调用门面 | `SupervisorBridge` |
|
|
93
93
|
| `supervisor_coverage.py` | 覆盖率生命周期继承器,支持空闲历史会话继承与动态分发 | `SupervisorCoverageSync` |
|
|
94
94
|
| `supervisor_degraded.py` | 降级容灾与探针就地自愈控制器,无损处理缺失依赖与环境 | `SupervisorDegradedCoordinator` |
|
|
@@ -100,7 +100,7 @@ flowchart TD
|
|
|
100
100
|
|
|
101
101
|
## 3. 核心设计契约与公理 (Design Axioms)
|
|
102
102
|
|
|
103
|
-
1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `1.
|
|
103
|
+
1. **版本绝对固化公理**:`startup_version_gate.py` 必须在任何业务逻辑启动前执行,基线版本严格锁定在 `0.1.1`,杜绝任何环境版本漂移。
|
|
104
104
|
2. **状态机单向流转与幂等性**:生命周期从 `Pre` $\rightarrow$ `Round` $\rightarrow$ `Worker` $\rightarrow$ `Judge` $\rightarrow$ `Settlement` $\rightarrow$ `Post` 严格单向流动,禁止逆流操作;重试必须走显式的轮次迭代(`advance_round_lifecycle`)。
|
|
105
105
|
3. **证据零伪造公理**:在 `findings_adjudication.py` 与 `candidate_revalidation.py` 中,所有缺陷判定必须有可执行的反事实测试证据,严禁仅凭模型推理文本定性。
|
|
106
106
|
4. **工作树物理安全红线**:`post_dry_run.py` 与 `post_commit.py` 严格遵守工作树保护宪法,未授权时绝对禁止覆盖用户未暂存的修改。
|
|
@@ -21,5 +21,5 @@ from core.launch_phases import run_pre_phase, run_post_phase
|
|
|
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/launch_phases --write`.
|
|
@@ -99,6 +99,25 @@ def is_runtime_started_this_process() -> bool:
|
|
|
99
99
|
return RUNTIME_STARTED_THIS_PROCESS
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
def option_value(args: list[str], option: str) -> str | None:
|
|
103
|
+
"""读取 ``--option value`` 或 ``--option=value`` 的轻量 CLI 参数。"""
|
|
104
|
+
for index, arg in enumerate(args):
|
|
105
|
+
if arg == option:
|
|
106
|
+
return args[index + 1] if index + 1 < len(args) else None
|
|
107
|
+
if arg.startswith(f"{option}="):
|
|
108
|
+
return arg.split("=", 1)[1]
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def sync_codebase_memory_env(profile: dict[str, Any]) -> None:
|
|
113
|
+
"""把 codebase-memory 探针结论同步到当前进程环境变量。"""
|
|
114
|
+
cb_probe = (profile.get("probes") or {}).get("codebase-memory")
|
|
115
|
+
if isinstance(cb_probe, dict):
|
|
116
|
+
os.environ["BUGX_USE_CODEBASE_MEMORY"] = (
|
|
117
|
+
"1" if cb_probe.get("status") == "READY" else "0"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
102
121
|
def set_runtime_started_this_process(value: bool = True) -> None:
|
|
103
122
|
_set_runtime_started_for_loaded_modules(value)
|
|
104
123
|
|
|
@@ -559,7 +578,7 @@ del _missing_gate_phases, _extra_gate_phases
|
|
|
559
578
|
# DES-18:仅保留 ``host_registry.SUPPORTED_HOSTS`` 中真实声明且可被识别的宿主。
|
|
560
579
|
# 历史清单混入 ``roo`` / ``windsurf`` / ``cursor`` / ``kline``——四者既不在
|
|
561
580
|
# 宿主声明内,也没有任何适配实现,属于「幽灵宿主名」,会被误当作已支持宿主
|
|
562
|
-
#
|
|
581
|
+
# 展示。一致性契约以本注释为准(HOST_DISPLAY_NAMES 键与宿主声明双向核对)。
|
|
563
582
|
HOST_DISPLAY_NAMES = {
|
|
564
583
|
"opencode": "OpenCode",
|
|
565
584
|
"claude": "Claude Code",
|
|
@@ -878,7 +897,7 @@ def _lifecycle_auto_mode() -> bool:
|
|
|
878
897
|
全部符号(``MODULE_COVERAGE`` / ``COVERAGE_EVIDENCE`` / ``resolve_project_root`` /
|
|
879
898
|
``coverage_manifest_path`` / ``run_child``)本就定义在这里;留在
|
|
880
899
|
``pre_phase`` 会让 ``post_phase`` 反向依赖前置阶段,与
|
|
881
|
-
``docs/02_architecture/
|
|
900
|
+
``docs/02_architecture/01_ARCHITECTURE.md`` 声明的单向流水线矛盾。
|
|
882
901
|
"""
|
|
883
902
|
try:
|
|
884
903
|
manifest = coverage_manifest_path()
|
|
@@ -227,6 +227,9 @@ def confirm(
|
|
|
227
227
|
print(f"[findings-confirm] ✗ verify {fp[:44]}: {str(exc)[:140]}")
|
|
228
228
|
failed += 1
|
|
229
229
|
continue
|
|
230
|
+
# F-RSI-20261118-009:recipe 可携带 severity(确认方定级补录)——
|
|
231
|
+
# triage 候选常缺 severity,确认动作随门禁要求补全报告字段。
|
|
232
|
+
recipe_severity = str(recipe.get("severity") or "").strip() or None
|
|
230
233
|
try:
|
|
231
234
|
supervisor.confirm_finding(
|
|
232
235
|
finding=fp, decision="confirmed",
|
|
@@ -234,6 +237,7 @@ def confirm(
|
|
|
234
237
|
root_cause_verified=True,
|
|
235
238
|
oracle={"tier": "differential", "provenance_kind": "runtime-invariant",
|
|
236
239
|
"reference": oracle_file},
|
|
240
|
+
severity=recipe_severity,
|
|
237
241
|
)
|
|
238
242
|
print(f"[findings-confirm] ✓ confirmed {fp[:52]}")
|
|
239
243
|
done += 1
|
|
@@ -330,7 +334,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
330
334
|
Worker 指令都写 ``--recipe <recipe.json>`` / ``--all-pending``,但 ``main()``
|
|
331
335
|
只手工扫 ``--from-verdicts`` / ``--reject``,把 ``--recipe`` 当成位置参数,
|
|
332
336
|
于是文档里的标准调用一律报「缺少 recipe 文件」。参数契约收敛到这里,
|
|
333
|
-
|
|
337
|
+
文档与实现的双向一致契约以本注释为准。
|
|
334
338
|
"""
|
|
335
339
|
parser = argparse.ArgumentParser(
|
|
336
340
|
prog="bugx engine findings-confirm",
|
|
@@ -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:
|