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
|
@@ -9,10 +9,12 @@ control once, then records the raw outputs and hashes generated by the engine.
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
+
import ast
|
|
12
13
|
import hashlib
|
|
13
14
|
import json
|
|
14
15
|
import math
|
|
15
16
|
import os
|
|
17
|
+
import re
|
|
16
18
|
import tempfile
|
|
17
19
|
import time
|
|
18
20
|
import uuid
|
|
@@ -115,6 +117,12 @@ def _oracle_case(value: object, field: str) -> dict[str, object]:
|
|
|
115
117
|
normalized["text"] = _text(value.get("text"), f"{field}.text", max_length=1024)
|
|
116
118
|
else:
|
|
117
119
|
normalized["path"] = _text(value.get("path"), f"{field}.path", max_length=256)
|
|
120
|
+
if "equals" not in value:
|
|
121
|
+
# F-RSI-20261115-122:equals 漏配会被 _matches 的 value == None
|
|
122
|
+
# 误判为命中(JSON 路径值恰为 null 时 None == None),漏配与
|
|
123
|
+
# 「期望 null」不可区分——构造期 fail-fast;显式传 null 保留
|
|
124
|
+
# (期望 null 值是合法判据语义)。
|
|
125
|
+
raise VerificationError(f"{field}.equals 缺失(期望 null 请显式传 null)")
|
|
118
126
|
normalized["equals"] = value.get("equals")
|
|
119
127
|
return normalized
|
|
120
128
|
|
|
@@ -301,7 +309,18 @@ def verify_finding(root: Path, finding: Mapping[str, object], recipe: Mapping[st
|
|
|
301
309
|
raise VerificationError("artifact_root 越界") from exc
|
|
302
310
|
verification_id = str(uuid.uuid4())
|
|
303
311
|
directory = base / verification_id
|
|
304
|
-
|
|
312
|
+
records: list[dict[str, object]] = []
|
|
313
|
+
# F-RSI-20261110-021:artifact_root 不可写(只读挂载/磁盘满/权限收紧)时
|
|
314
|
+
# 目录创建与 BLOCKED receipt 落盘都会 OSError——此前裸异常冒出 verify_finding,
|
|
315
|
+
# 上游只能靠 dispatch 兜底丢结构化语义。降级为内存 BLOCKED receipt:
|
|
316
|
+
# receipt_path 置 None + degraded 标记,双跑照常执行(结果不落盘但可审计)。
|
|
317
|
+
degraded_storage = False
|
|
318
|
+
try:
|
|
319
|
+
directory.mkdir(parents=True, exist_ok=False, mode=0o700)
|
|
320
|
+
except OSError as exc:
|
|
321
|
+
degraded_storage = True
|
|
322
|
+
directory = None
|
|
323
|
+
storage_error = f"artifact_root 不可写({type(exc).__name__}: {exc})"
|
|
305
324
|
records: list[dict[str, object]] = []
|
|
306
325
|
try:
|
|
307
326
|
for index in range(POSITIVE_RUNS_REQUIRED):
|
|
@@ -327,10 +346,20 @@ def verify_finding(root: Path, finding: Mapping[str, object], recipe: Mapping[st
|
|
|
327
346
|
"request_id": request_id,
|
|
328
347
|
"error": str(exc)[:512], "recipe_digest": spec.digest(),
|
|
329
348
|
}
|
|
330
|
-
|
|
349
|
+
if directory is not None:
|
|
350
|
+
try:
|
|
351
|
+
_atomic_json(directory / "receipt.json", receipt)
|
|
352
|
+
receipt["receipt_path"] = str(directory / "receipt.json")
|
|
353
|
+
except OSError:
|
|
354
|
+
pass # 落盘失败也返回内存 BLOCKED receipt(F-021 degraded)
|
|
355
|
+
else:
|
|
356
|
+
receipt["degraded"] = True
|
|
331
357
|
return receipt
|
|
332
|
-
positives_ok =
|
|
333
|
-
|
|
358
|
+
positives_ok = (
|
|
359
|
+
len(records) == POSITIVE_RUNS_REQUIRED + 1
|
|
360
|
+
and all(bool(item.get("oracle_matched")) for item in records[:POSITIVE_RUNS_REQUIRED])
|
|
361
|
+
)
|
|
362
|
+
negative_ok = bool(records[POSITIVE_RUNS_REQUIRED].get("oracle_matched"))
|
|
334
363
|
status = "CONFIRMED" if positives_ok and negative_ok else "CANDIDATE"
|
|
335
364
|
receipt: dict[str, object] = {
|
|
336
365
|
"protocol_version": PROTOCOL_VERSION,
|
|
@@ -347,14 +376,23 @@ def verify_finding(root: Path, finding: Mapping[str, object], recipe: Mapping[st
|
|
|
347
376
|
"recipe_digest": spec.digest(),
|
|
348
377
|
"oracle_reference": spec.oracle_reference,
|
|
349
378
|
"oracle_hash": spec.oracle_hash,
|
|
350
|
-
"positive_runs": records[:
|
|
351
|
-
"negative_control": records[
|
|
379
|
+
"positive_runs": records[:POSITIVE_RUNS_REQUIRED],
|
|
380
|
+
"negative_control": records[POSITIVE_RUNS_REQUIRED],
|
|
352
381
|
"raw_output_source": "engine",
|
|
353
|
-
"receipt_path": str(directory / "receipt.json"),
|
|
382
|
+
"receipt_path": str(directory / "receipt.json") if directory is not None else None,
|
|
354
383
|
"created_at": time.time(),
|
|
355
384
|
}
|
|
356
385
|
receipt["verification_digest"] = _sha256(_canonical(receipt))
|
|
357
|
-
|
|
386
|
+
if directory is not None:
|
|
387
|
+
try:
|
|
388
|
+
_atomic_json(directory / "receipt.json", receipt)
|
|
389
|
+
receipt["receipt_path"] = str(directory / "receipt.json")
|
|
390
|
+
except OSError:
|
|
391
|
+
receipt["degraded"] = True
|
|
392
|
+
receipt["receipt_path"] = None
|
|
393
|
+
else:
|
|
394
|
+
receipt["degraded"] = True
|
|
395
|
+
receipt["receipt_path"] = None
|
|
358
396
|
return receipt
|
|
359
397
|
|
|
360
398
|
|
|
@@ -363,7 +401,514 @@ def verify_finding_record(*args: Any, **kwargs: Any) -> dict[str, object]:
|
|
|
363
401
|
return verify_finding(*args, **kwargs)
|
|
364
402
|
|
|
365
403
|
|
|
404
|
+
DIAGNOSTIC_MAX_TEXT_BYTES = 4096
|
|
405
|
+
|
|
406
|
+
FAILURE_CODES = frozenset({
|
|
407
|
+
"shell_token_rejected",
|
|
408
|
+
"syntax_or_import_error",
|
|
409
|
+
"positive_not_triggered",
|
|
410
|
+
"positive_flaky",
|
|
411
|
+
"negative_false_trigger",
|
|
412
|
+
"negative_trivial_rejected",
|
|
413
|
+
"env_or_dependency_blocked",
|
|
414
|
+
"timeout_exceeded",
|
|
415
|
+
"source_tampered_rejected",
|
|
416
|
+
"verifier_stalled",
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
RETRYABLE_FAILURE_CODES = frozenset({
|
|
420
|
+
"shell_token_rejected",
|
|
421
|
+
"syntax_or_import_error",
|
|
422
|
+
"positive_not_triggered",
|
|
423
|
+
"negative_false_trigger",
|
|
424
|
+
"negative_trivial_rejected",
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
_REDACT_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = (
|
|
428
|
+
(re.compile(r"(?i)(bearer\s+)[A-Za-z0-9._\-]{12,}"), r"\1<REDACTED>"),
|
|
429
|
+
(re.compile(r"\b(?:sk|pk|ghp|gho|ghu|ghs|glpat|xoxb|xoxp)-[A-Za-z0-9_\-]{10,}\b"), "<REDACTED_TOKEN>"),
|
|
430
|
+
(re.compile(r"(?i)(\b(?:api[_-]?key|secret|token|password|passwd|access[_-]?key)\s*[:=]\s*['\"]?)([^\s'\",;]{6,})"), r"\1<REDACTED>"),
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
_TRIVIAL_BUILTINS = frozenset({
|
|
434
|
+
"print", "len", "str", "int", "float", "bool", "list", "dict", "set", "tuple",
|
|
435
|
+
"range", "repr", "type", "isinstance", "issubclass", "enumerate", "zip",
|
|
436
|
+
"min", "max", "sum", "abs", "round", "sorted", "reversed", "any", "all",
|
|
437
|
+
"chr", "ord", "id", "hash", "exit", "quit",
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
def _redact_and_truncate(text: object, *, limit: int = DIAGNOSTIC_MAX_TEXT_BYTES) -> str:
|
|
442
|
+
raw = text.decode("utf-8", errors="replace") if isinstance(text, bytes) else str(text or "")
|
|
443
|
+
for pattern, repl in _REDACT_PATTERNS:
|
|
444
|
+
raw = pattern.sub(repl, raw)
|
|
445
|
+
encoded = raw.encode("utf-8", errors="replace")
|
|
446
|
+
if len(encoded) <= limit:
|
|
447
|
+
return raw
|
|
448
|
+
truncated = encoded[:limit].decode("utf-8", errors="ignore")
|
|
449
|
+
return f"{truncated}\n...[truncated {len(encoded) - limit} bytes]"
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def _looks_like_syntax_or_import(stderr: str, stdout: str) -> bool:
|
|
453
|
+
combined = f"{stderr}\n{stdout}"
|
|
454
|
+
markers = (
|
|
455
|
+
"SyntaxError",
|
|
456
|
+
"IndentationError",
|
|
457
|
+
"TabError",
|
|
458
|
+
"ImportError",
|
|
459
|
+
"ModuleNotFoundError",
|
|
460
|
+
"NameError",
|
|
461
|
+
"AttributeError: module",
|
|
462
|
+
"BUGX_VERIFY_POSITIVE unexpected-error=SyntaxError",
|
|
463
|
+
"BUGX_VERIFY_POSITIVE unexpected-error=ImportError",
|
|
464
|
+
"BUGX_VERIFY_POSITIVE unexpected-error=ModuleNotFoundError",
|
|
465
|
+
"BUGX_VERIFY_POSITIVE unexpected-error=NameError",
|
|
466
|
+
)
|
|
467
|
+
return any(marker in combined for marker in markers)
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def _looks_like_env_blocked(stderr: str, stdout: str, error_text: str = "") -> bool:
|
|
471
|
+
combined = f"{error_text}\n{stderr}\n{stdout}".lower()
|
|
472
|
+
markers = (
|
|
473
|
+
"connection refused",
|
|
474
|
+
"no such file or directory: 'docker'",
|
|
475
|
+
"permission denied",
|
|
476
|
+
"operation not permitted",
|
|
477
|
+
"cannot connect to",
|
|
478
|
+
"address already in use",
|
|
479
|
+
"executable file not found",
|
|
480
|
+
"command not found",
|
|
481
|
+
)
|
|
482
|
+
return any(marker in combined for marker in markers)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
@dataclass(frozen=True)
|
|
486
|
+
class VerificationDiagnostic:
|
|
487
|
+
"""Engine-owned structured diagnostic for a failed verification attempt."""
|
|
488
|
+
|
|
489
|
+
finding_key: str
|
|
490
|
+
attempt: int
|
|
491
|
+
failure_code: str
|
|
492
|
+
stage: str
|
|
493
|
+
retryable: bool
|
|
494
|
+
summary: str
|
|
495
|
+
exit_code: int | None = None
|
|
496
|
+
stdout_excerpt: str = ""
|
|
497
|
+
stderr_excerpt: str = ""
|
|
498
|
+
receipt_status: str = ""
|
|
499
|
+
verification_id: str | None = None
|
|
500
|
+
created_at: float = 0.0
|
|
501
|
+
|
|
502
|
+
def to_dict(self) -> dict[str, object]:
|
|
503
|
+
return {
|
|
504
|
+
"finding_key": self.finding_key,
|
|
505
|
+
"attempt": self.attempt,
|
|
506
|
+
"failure_code": self.failure_code,
|
|
507
|
+
"stage": self.stage,
|
|
508
|
+
"retryable": self.retryable,
|
|
509
|
+
"summary": self.summary,
|
|
510
|
+
"exit_code": self.exit_code,
|
|
511
|
+
"stdout_excerpt": self.stdout_excerpt,
|
|
512
|
+
"stderr_excerpt": self.stderr_excerpt,
|
|
513
|
+
"receipt_status": self.receipt_status,
|
|
514
|
+
"verification_id": self.verification_id,
|
|
515
|
+
"created_at": self.created_at or time.time(),
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
def diagnose_verification_error(
|
|
520
|
+
exc_or_msg: object,
|
|
521
|
+
*,
|
|
522
|
+
attempt: int = 1,
|
|
523
|
+
finding_key: str = "",
|
|
524
|
+
failure_code: str | None = None,
|
|
525
|
+
stage: str = "precheck",
|
|
526
|
+
) -> VerificationDiagnostic:
|
|
527
|
+
"""Build a structured diagnostic from a precheck/supervisor/runtime error."""
|
|
528
|
+
text = _redact_and_truncate(str(exc_or_msg))
|
|
529
|
+
code = failure_code
|
|
530
|
+
if code not in FAILURE_CODES:
|
|
531
|
+
lowered = text.lower()
|
|
532
|
+
if "shell" in lowered or "禁字符" in text or "运算符" in text:
|
|
533
|
+
code = "shell_token_rejected"
|
|
534
|
+
elif "timeout" in lowered or "超时" in text:
|
|
535
|
+
code = "timeout_exceeded"
|
|
536
|
+
elif _looks_like_env_blocked(text, "", text):
|
|
537
|
+
code = "env_or_dependency_blocked"
|
|
538
|
+
elif _looks_like_syntax_or_import(text, ""):
|
|
539
|
+
code = "syntax_or_import_error"
|
|
540
|
+
else:
|
|
541
|
+
code = "positive_not_triggered"
|
|
542
|
+
return VerificationDiagnostic(
|
|
543
|
+
finding_key=finding_key,
|
|
544
|
+
attempt=attempt,
|
|
545
|
+
failure_code=code,
|
|
546
|
+
stage=stage,
|
|
547
|
+
retryable=code in RETRYABLE_FAILURE_CODES,
|
|
548
|
+
summary=text[:400],
|
|
549
|
+
stderr_excerpt=text,
|
|
550
|
+
receipt_status="ERROR",
|
|
551
|
+
created_at=time.time(),
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def diagnose_verification_receipt(
|
|
556
|
+
receipt: Mapping[str, object],
|
|
557
|
+
*,
|
|
558
|
+
attempt: int = 1,
|
|
559
|
+
finding_key: str = "",
|
|
560
|
+
) -> VerificationDiagnostic:
|
|
561
|
+
"""Classify an engine verification receipt into a deterministic failure_code."""
|
|
562
|
+
fkey = finding_key or str(receipt.get("finding_key") or "")
|
|
563
|
+
status = str(receipt.get("status") or "")
|
|
564
|
+
vid = receipt.get("verification_id")
|
|
565
|
+
vid_str = str(vid) if vid is not None else None
|
|
566
|
+
now = time.time()
|
|
567
|
+
|
|
568
|
+
if status == "BLOCKED":
|
|
569
|
+
err = _redact_and_truncate(receipt.get("error") or "verification blocked")
|
|
570
|
+
code = "timeout_exceeded" if "timeout" in err.lower() else "env_or_dependency_blocked"
|
|
571
|
+
return VerificationDiagnostic(
|
|
572
|
+
finding_key=fkey,
|
|
573
|
+
attempt=attempt,
|
|
574
|
+
failure_code=code,
|
|
575
|
+
stage="blocked",
|
|
576
|
+
retryable=False,
|
|
577
|
+
summary=err[:400],
|
|
578
|
+
stderr_excerpt=err,
|
|
579
|
+
receipt_status=status,
|
|
580
|
+
verification_id=vid_str,
|
|
581
|
+
created_at=now,
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
pos_runs = receipt.get("positive_runs")
|
|
585
|
+
pos_list = list(pos_runs) if isinstance(pos_runs, Sequence) else []
|
|
586
|
+
neg = receipt.get("negative_control")
|
|
587
|
+
neg_map = neg if isinstance(neg, Mapping) else {}
|
|
588
|
+
|
|
589
|
+
# 1. Timeout check across all runs
|
|
590
|
+
for idx, run in enumerate(pos_list, 1):
|
|
591
|
+
if isinstance(run, Mapping) and bool(run.get("timed_out")):
|
|
592
|
+
return VerificationDiagnostic(
|
|
593
|
+
finding_key=fkey,
|
|
594
|
+
attempt=attempt,
|
|
595
|
+
failure_code="timeout_exceeded",
|
|
596
|
+
stage=f"positive_run_{idx}",
|
|
597
|
+
retryable=False,
|
|
598
|
+
summary=f"positive run {idx} timed out",
|
|
599
|
+
exit_code=run.get("exit_code") if isinstance(run.get("exit_code"), int) else None,
|
|
600
|
+
stdout_excerpt=_redact_and_truncate(run.get("stdout")),
|
|
601
|
+
stderr_excerpt=_redact_and_truncate(run.get("stderr")),
|
|
602
|
+
receipt_status=status,
|
|
603
|
+
verification_id=vid_str,
|
|
604
|
+
created_at=now,
|
|
605
|
+
)
|
|
606
|
+
if bool(neg_map.get("timed_out")):
|
|
607
|
+
return VerificationDiagnostic(
|
|
608
|
+
finding_key=fkey,
|
|
609
|
+
attempt=attempt,
|
|
610
|
+
failure_code="timeout_exceeded",
|
|
611
|
+
stage="negative_control",
|
|
612
|
+
retryable=False,
|
|
613
|
+
summary="negative control timed out",
|
|
614
|
+
exit_code=neg_map.get("exit_code") if isinstance(neg_map.get("exit_code"), int) else None,
|
|
615
|
+
stdout_excerpt=_redact_and_truncate(neg_map.get("stdout")),
|
|
616
|
+
stderr_excerpt=_redact_and_truncate(neg_map.get("stderr")),
|
|
617
|
+
receipt_status=status,
|
|
618
|
+
verification_id=vid_str,
|
|
619
|
+
created_at=now,
|
|
620
|
+
)
|
|
621
|
+
|
|
622
|
+
# 2. Positive runs analysis
|
|
623
|
+
pos_matched = [bool(r.get("oracle_matched")) for r in pos_list if isinstance(r, Mapping)]
|
|
624
|
+
if len(pos_matched) >= 2 and any(pos_matched) and not all(pos_matched):
|
|
625
|
+
failed_idx = next(i for i, ok in enumerate(pos_matched) if not ok)
|
|
626
|
+
run = pos_list[failed_idx]
|
|
627
|
+
return VerificationDiagnostic(
|
|
628
|
+
finding_key=fkey,
|
|
629
|
+
attempt=attempt,
|
|
630
|
+
failure_code="positive_flaky",
|
|
631
|
+
stage=f"positive_run_{failed_idx + 1}",
|
|
632
|
+
retryable=False,
|
|
633
|
+
summary="positive runs disagreed across independent executions (non-deterministic)",
|
|
634
|
+
exit_code=run.get("exit_code") if isinstance(run.get("exit_code"), int) else None,
|
|
635
|
+
stdout_excerpt=_redact_and_truncate(run.get("stdout")),
|
|
636
|
+
stderr_excerpt=_redact_and_truncate(run.get("stderr")),
|
|
637
|
+
receipt_status=status,
|
|
638
|
+
verification_id=vid_str,
|
|
639
|
+
created_at=now,
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
if not pos_matched or not all(pos_matched):
|
|
643
|
+
run = pos_list[0] if pos_list and isinstance(pos_list[0], Mapping) else {}
|
|
644
|
+
stdout = _redact_and_truncate(run.get("stdout"))
|
|
645
|
+
stderr = _redact_and_truncate(run.get("stderr"))
|
|
646
|
+
if _looks_like_syntax_or_import(stderr, stdout):
|
|
647
|
+
code = "syntax_or_import_error"
|
|
648
|
+
summary = "positive PoC failed with syntax/import/name error"
|
|
649
|
+
elif _looks_like_env_blocked(stderr, stdout):
|
|
650
|
+
code = "env_or_dependency_blocked"
|
|
651
|
+
summary = "positive PoC blocked by missing environment or permission"
|
|
652
|
+
else:
|
|
653
|
+
code = "positive_not_triggered"
|
|
654
|
+
summary = f"positive PoC did not match oracle (exit_code={run.get('exit_code')})"
|
|
655
|
+
return VerificationDiagnostic(
|
|
656
|
+
finding_key=fkey,
|
|
657
|
+
attempt=attempt,
|
|
658
|
+
failure_code=code,
|
|
659
|
+
stage="positive_run_1",
|
|
660
|
+
retryable=code in RETRYABLE_FAILURE_CODES,
|
|
661
|
+
summary=summary,
|
|
662
|
+
exit_code=run.get("exit_code") if isinstance(run.get("exit_code"), int) else None,
|
|
663
|
+
stdout_excerpt=stdout,
|
|
664
|
+
stderr_excerpt=stderr,
|
|
665
|
+
receipt_status=status,
|
|
666
|
+
verification_id=vid_str,
|
|
667
|
+
created_at=now,
|
|
668
|
+
)
|
|
669
|
+
|
|
670
|
+
# 3. Negative control analysis
|
|
671
|
+
if not bool(neg_map.get("oracle_matched")):
|
|
672
|
+
stdout = _redact_and_truncate(neg_map.get("stdout"))
|
|
673
|
+
stderr = _redact_and_truncate(neg_map.get("stderr"))
|
|
674
|
+
if _looks_like_syntax_or_import(stderr, stdout):
|
|
675
|
+
code = "syntax_or_import_error"
|
|
676
|
+
summary = "negative control failed with syntax/import/name error"
|
|
677
|
+
elif _looks_like_env_blocked(stderr, stdout):
|
|
678
|
+
code = "env_or_dependency_blocked"
|
|
679
|
+
summary = "negative control blocked by missing environment or permission"
|
|
680
|
+
else:
|
|
681
|
+
code = "negative_false_trigger"
|
|
682
|
+
summary = f"negative control unexpectedly failed oracle (exit_code={neg_map.get('exit_code')})"
|
|
683
|
+
return VerificationDiagnostic(
|
|
684
|
+
finding_key=fkey,
|
|
685
|
+
attempt=attempt,
|
|
686
|
+
failure_code=code,
|
|
687
|
+
stage="negative_control",
|
|
688
|
+
retryable=code in RETRYABLE_FAILURE_CODES,
|
|
689
|
+
summary=summary,
|
|
690
|
+
exit_code=neg_map.get("exit_code") if isinstance(neg_map.get("exit_code"), int) else None,
|
|
691
|
+
stdout_excerpt=stdout,
|
|
692
|
+
stderr_excerpt=stderr,
|
|
693
|
+
receipt_status=status,
|
|
694
|
+
verification_id=vid_str,
|
|
695
|
+
created_at=now,
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
return VerificationDiagnostic(
|
|
699
|
+
finding_key=fkey,
|
|
700
|
+
attempt=attempt,
|
|
701
|
+
failure_code="positive_not_triggered",
|
|
702
|
+
stage="unknown",
|
|
703
|
+
retryable=True,
|
|
704
|
+
summary=f"verification receipt did not reach CONFIRMED (status={status})",
|
|
705
|
+
receipt_status=status,
|
|
706
|
+
verification_id=vid_str,
|
|
707
|
+
created_at=now,
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def _has_meaningful_target_activity(tree: ast.AST, target_hints: Sequence[str]) -> bool:
|
|
712
|
+
"""Reject trivial no-op negative controls (e.g. `pass`, `sys.exit(0)`, `print('ok')`)."""
|
|
713
|
+
has_import = False
|
|
714
|
+
non_trivial_call = False
|
|
715
|
+
imported_names: set[str] = set()
|
|
716
|
+
referenced_names: set[str] = set()
|
|
717
|
+
|
|
718
|
+
for node in ast.walk(tree):
|
|
719
|
+
if isinstance(node, ast.Import):
|
|
720
|
+
for alias in node.names:
|
|
721
|
+
root_name = alias.name.split(".")[0]
|
|
722
|
+
if root_name != "sys":
|
|
723
|
+
has_import = True
|
|
724
|
+
imported_names.add(alias.name)
|
|
725
|
+
imported_names.add(root_name)
|
|
726
|
+
if alias.asname:
|
|
727
|
+
imported_names.add(alias.asname)
|
|
728
|
+
elif isinstance(node, ast.ImportFrom):
|
|
729
|
+
mod = node.module or ""
|
|
730
|
+
if mod and mod.split(".")[0] != "sys":
|
|
731
|
+
has_import = True
|
|
732
|
+
if mod:
|
|
733
|
+
imported_names.add(mod)
|
|
734
|
+
imported_names.add(mod.split(".")[0])
|
|
735
|
+
for alias in node.names:
|
|
736
|
+
imported_names.add(alias.name)
|
|
737
|
+
if alias.asname:
|
|
738
|
+
imported_names.add(alias.asname)
|
|
739
|
+
elif isinstance(node, ast.Name):
|
|
740
|
+
referenced_names.add(node.id)
|
|
741
|
+
elif isinstance(node, ast.Attribute):
|
|
742
|
+
referenced_names.add(node.attr)
|
|
743
|
+
elif isinstance(node, ast.Call):
|
|
744
|
+
func = node.func
|
|
745
|
+
if isinstance(func, ast.Name):
|
|
746
|
+
if func.id not in _TRIVIAL_BUILTINS:
|
|
747
|
+
non_trivial_call = True
|
|
748
|
+
elif isinstance(func, ast.Attribute):
|
|
749
|
+
is_sys_exit = (
|
|
750
|
+
isinstance(func.value, ast.Name)
|
|
751
|
+
and func.value.id == "sys"
|
|
752
|
+
and func.attr == "exit"
|
|
753
|
+
)
|
|
754
|
+
if not is_sys_exit:
|
|
755
|
+
non_trivial_call = True
|
|
756
|
+
else:
|
|
757
|
+
non_trivial_call = True
|
|
758
|
+
|
|
759
|
+
if not (non_trivial_call or has_import):
|
|
760
|
+
return False
|
|
761
|
+
if not non_trivial_call:
|
|
762
|
+
return False
|
|
763
|
+
if target_hints:
|
|
764
|
+
all_tokens = imported_names | referenced_names
|
|
765
|
+
normalized_hints = {h.strip() for h in target_hints if isinstance(h, str) and h.strip()}
|
|
766
|
+
if normalized_hints and not any(
|
|
767
|
+
hint in token or token in hint
|
|
768
|
+
for hint in normalized_hints
|
|
769
|
+
for token in all_tokens
|
|
770
|
+
if len(token) >= 2
|
|
771
|
+
):
|
|
772
|
+
return False
|
|
773
|
+
return True
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def validate_python_poc_pair(
|
|
777
|
+
positive_code: str,
|
|
778
|
+
negative_code: str,
|
|
779
|
+
*,
|
|
780
|
+
finding_key: str = "",
|
|
781
|
+
attempt: int = 1,
|
|
782
|
+
target_hints: Sequence[str] = (),
|
|
783
|
+
) -> VerificationDiagnostic | None:
|
|
784
|
+
"""Anti-gaming static AST validation for positive/negative Python PoC bodies."""
|
|
785
|
+
pos_text = (positive_code or "").strip()
|
|
786
|
+
neg_text = (negative_code or "").strip()
|
|
787
|
+
if not pos_text or not neg_text:
|
|
788
|
+
return VerificationDiagnostic(
|
|
789
|
+
finding_key=finding_key,
|
|
790
|
+
attempt=attempt,
|
|
791
|
+
failure_code="syntax_or_import_error",
|
|
792
|
+
stage="ast_precheck",
|
|
793
|
+
retryable=True,
|
|
794
|
+
summary="positive and negative code bodies must both be non-empty",
|
|
795
|
+
created_at=time.time(),
|
|
796
|
+
)
|
|
797
|
+
if pos_text == neg_text:
|
|
798
|
+
return VerificationDiagnostic(
|
|
799
|
+
finding_key=finding_key,
|
|
800
|
+
attempt=attempt,
|
|
801
|
+
failure_code="negative_trivial_rejected",
|
|
802
|
+
stage="ast_precheck",
|
|
803
|
+
retryable=True,
|
|
804
|
+
summary="negative control must differ from positive payload",
|
|
805
|
+
created_at=time.time(),
|
|
806
|
+
)
|
|
807
|
+
try:
|
|
808
|
+
pos_tree = ast.parse(pos_text, filename="verification-positive")
|
|
809
|
+
except SyntaxError as exc:
|
|
810
|
+
return VerificationDiagnostic(
|
|
811
|
+
finding_key=finding_key,
|
|
812
|
+
attempt=attempt,
|
|
813
|
+
failure_code="syntax_or_import_error",
|
|
814
|
+
stage="ast_precheck",
|
|
815
|
+
retryable=True,
|
|
816
|
+
summary=f"positive SyntaxError: {exc}",
|
|
817
|
+
stderr_excerpt=str(exc),
|
|
818
|
+
created_at=time.time(),
|
|
819
|
+
)
|
|
820
|
+
try:
|
|
821
|
+
neg_tree = ast.parse(neg_text, filename="verification-negative")
|
|
822
|
+
except SyntaxError as exc:
|
|
823
|
+
return VerificationDiagnostic(
|
|
824
|
+
finding_key=finding_key,
|
|
825
|
+
attempt=attempt,
|
|
826
|
+
failure_code="syntax_or_import_error",
|
|
827
|
+
stage="ast_precheck",
|
|
828
|
+
retryable=True,
|
|
829
|
+
summary=f"negative SyntaxError: {exc}",
|
|
830
|
+
stderr_excerpt=str(exc),
|
|
831
|
+
created_at=time.time(),
|
|
832
|
+
)
|
|
833
|
+
if not _has_meaningful_target_activity(neg_tree, target_hints):
|
|
834
|
+
return VerificationDiagnostic(
|
|
835
|
+
finding_key=finding_key,
|
|
836
|
+
attempt=attempt,
|
|
837
|
+
failure_code="negative_trivial_rejected",
|
|
838
|
+
stage="ast_precheck",
|
|
839
|
+
retryable=True,
|
|
840
|
+
summary="negative control rejected as trivial no-op (must invoke target module/entry)",
|
|
841
|
+
created_at=time.time(),
|
|
842
|
+
)
|
|
843
|
+
if not _has_meaningful_target_activity(pos_tree, ()):
|
|
844
|
+
return VerificationDiagnostic(
|
|
845
|
+
finding_key=finding_key,
|
|
846
|
+
attempt=attempt,
|
|
847
|
+
failure_code="positive_not_triggered",
|
|
848
|
+
stage="ast_precheck",
|
|
849
|
+
retryable=True,
|
|
850
|
+
summary="positive PoC contains no meaningful call or module exercise",
|
|
851
|
+
created_at=time.time(),
|
|
852
|
+
)
|
|
853
|
+
return None
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
def snapshot_target_hashes(root: Path, rel_paths: Sequence[str]) -> dict[str, str]:
|
|
857
|
+
"""Compute SHA-256 hashes of target source files before PoC execution."""
|
|
858
|
+
resolved_root = Path(root).resolve()
|
|
859
|
+
hashes: dict[str, str] = {}
|
|
860
|
+
for raw in rel_paths:
|
|
861
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
862
|
+
continue
|
|
863
|
+
candidate = Path(raw.replace("\\", "/"))
|
|
864
|
+
if candidate.is_absolute() or ".." in candidate.parts:
|
|
865
|
+
continue
|
|
866
|
+
try:
|
|
867
|
+
target = (resolved_root / candidate).resolve()
|
|
868
|
+
target.relative_to(resolved_root)
|
|
869
|
+
except (OSError, ValueError):
|
|
870
|
+
continue
|
|
871
|
+
if target.is_file() and not target.is_symlink():
|
|
872
|
+
try:
|
|
873
|
+
hashes[str(target.relative_to(resolved_root))] = _sha256(target.read_bytes())
|
|
874
|
+
except OSError:
|
|
875
|
+
continue
|
|
876
|
+
return hashes
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
def verify_target_hashes_unchanged(root: Path, before: Mapping[str, str]) -> list[str]:
|
|
880
|
+
"""Return list of target relative paths modified or deleted during PoC execution."""
|
|
881
|
+
resolved_root = Path(root).resolve()
|
|
882
|
+
tampered: list[str] = []
|
|
883
|
+
for rel, expected_hash in before.items():
|
|
884
|
+
target = resolved_root / rel
|
|
885
|
+
if not target.is_file() or target.is_symlink():
|
|
886
|
+
tampered.append(rel)
|
|
887
|
+
continue
|
|
888
|
+
try:
|
|
889
|
+
actual_hash = _sha256(target.read_bytes())
|
|
890
|
+
except OSError:
|
|
891
|
+
tampered.append(rel)
|
|
892
|
+
continue
|
|
893
|
+
if actual_hash != expected_hash:
|
|
894
|
+
tampered.append(rel)
|
|
895
|
+
return tampered
|
|
896
|
+
|
|
897
|
+
|
|
366
898
|
__all__ = [
|
|
367
|
-
"PROTOCOL_VERSION",
|
|
368
|
-
"
|
|
899
|
+
"PROTOCOL_VERSION",
|
|
900
|
+
"DIAGNOSTIC_MAX_TEXT_BYTES",
|
|
901
|
+
"FAILURE_CODES",
|
|
902
|
+
"RETRYABLE_FAILURE_CODES",
|
|
903
|
+
"VerificationError",
|
|
904
|
+
"VerificationBlocked",
|
|
905
|
+
"VerificationRecipe",
|
|
906
|
+
"VerificationDiagnostic",
|
|
907
|
+
"verify_finding",
|
|
908
|
+
"verify_finding_record",
|
|
909
|
+
"diagnose_verification_receipt",
|
|
910
|
+
"diagnose_verification_error",
|
|
911
|
+
"validate_python_poc_pair",
|
|
912
|
+
"snapshot_target_hashes",
|
|
913
|
+
"verify_target_hashes_unchanged",
|
|
369
914
|
]
|