bugx-cli 0.1.1 → 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 +13 -9
- package/core/README.md +1 -1
- package/core/assets/README.md +3 -2
- package/core/assets/bugx-social-preview.svg +71 -0
- package/core/assets/bugx-wechat-group.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/bugx.md +1 -1
- package/core/bugx_paths.py +2 -2
- package/core/cloud_sync/cloud_client.py +56 -5
- package/core/cloud_sync/consent.py +33 -3
- package/core/cloud_sync/flywheel_client.py +186 -24
- package/core/contracts/README.md +1 -1
- package/core/contracts/bugx-runtime-contract.md +1 -1
- package/core/contracts/bugx-worker.md +1 -1
- package/core/engine-integrity.json +122 -66
- package/core/infra/README.md +1 -1
- package/core/infra/build_info.py +2 -2
- package/core/launch_phases/README.md +6 -3
- package/core/launch_phases/finding_confirm_phase.py +168 -7
- package/core/launch_phases/post_phase.py +5 -5
- package/core/launch_phases/pre_recon_scout.py +13 -0
- package/core/launch_phases/report_sharing.py +3 -7
- package/core/launch_phases/round_orchestrator.py +114 -26
- package/core/launch_phases/semantic_recon.py +545 -0
- package/core/launch_phases/startup_version_gate.py +6 -2
- package/core/launch_phases/verify_loop.py +767 -0
- package/core/launch_phases/worker_prior.py +115 -0
- package/core/ledger/README.md +2 -1
- package/core/ledger/finding_verification.py +511 -2
- package/core/ledger/fp_ledger.py +255 -0
- package/core/metadata.txt +2 -2
- package/core/planning/README.md +2 -1
- package/core/planning/prompt_harness.py +50 -10
- package/core/planning/prompt_policy_engine.py +386 -0
- package/core/prompts/README.md +4 -2
- package/core/prompts/policies/prompt_policies.json +101 -0
- package/core/prompts/stages/stage_verify.defensive.md +42 -0
- package/core/prompts/stages/stage_verify.md +44 -0
- package/core/report_engine/report_share.py +0 -8
- package/core/retrieval/README.md +2 -1
- package/core/retrieval/pitfall_packs.py +277 -0
- package/core/runtime/README.md +1 -1
- package/core/runtime/global_telemetry.py +20 -0
- package/core/runtime/scenario_eval.py +1 -1
- package/core/supervisor/README.md +1 -1
- package/docs/07_distribution/01_README_NPM.md +13 -9
- package/ecosystem/integrations/dsh/mcp/package.json +1 -1
- package/ecosystem/integrations/dsh/ui/package.json +1 -1
- package/ecosystem/integrations/opencode/bugx-mcp-manifest.json +1 -1
- 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/interfaces/bin/bugx.js +7 -7
- package/interfaces/cli/bugx_cli/__init__.py +2 -2
- package/interfaces/cli/bugx_cli/cli.py +163 -67
- package/interfaces/cli/bugx_cli/commands/agent.py +122 -61
- package/interfaces/cli/bugx_cli/commands/audit.py +8 -7
- package/interfaces/cli/bugx_cli/commands/cloud.py +27 -19
- package/interfaces/cli/bugx_cli/commands/knowledge.py +3 -4
- package/interfaces/cli/bugx_cli/commands/plugin.py +3 -3
- package/interfaces/cli/bugx_cli/commands/plugin_claude.py +2 -2
- package/interfaces/cli/bugx_cli/commands/project.py +6 -13
- package/interfaces/cli/bugx_cli/commands/system.py +513 -158
- package/interfaces/cli/bugx_cli/common.py +6 -8
- package/interfaces/cli/bugx_cli/infra/engine_installer.py +21 -10
- package/interfaces/cli/bugx_cli/infra/host_sync.py +1 -1
- package/package.json +29 -15
- package/pyproject.toml +40 -1
- package/scripts/sync-version.mjs +1 -1
- package/core/assets/bugx-hero-cn.png +0 -0
- package/core/assets/bugx-hero-en.png +0 -0
|
@@ -47,9 +47,11 @@ from typing import Any, Mapping
|
|
|
47
47
|
|
|
48
48
|
if __package__:
|
|
49
49
|
from core.launch_phases.common import resolve_project_root, supervisor_state_path
|
|
50
|
+
from core.launch_phases import verify_loop
|
|
50
51
|
else: # pragma: no cover
|
|
51
52
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
52
53
|
from core.launch_phases.common import resolve_project_root, supervisor_state_path
|
|
54
|
+
from core.launch_phases import verify_loop
|
|
53
55
|
|
|
54
56
|
_SHELL_TOKENS = (";", "&&", "||", "`", "$(", ">", "<")
|
|
55
57
|
|
|
@@ -187,11 +189,25 @@ def confirm(
|
|
|
187
189
|
"""
|
|
188
190
|
from core.supervisor import audit_supervisor
|
|
189
191
|
from core.ledger import finding_confirmation
|
|
192
|
+
from core.ledger.finding_verification import (
|
|
193
|
+
diagnose_verification_error,
|
|
194
|
+
diagnose_verification_receipt,
|
|
195
|
+
snapshot_target_hashes,
|
|
196
|
+
validate_python_poc_pair,
|
|
197
|
+
verify_target_hashes_unchanged,
|
|
198
|
+
)
|
|
190
199
|
|
|
191
200
|
# 用模块级引用(可被测试替换);函数内重新 import 会绕过 monkeypatch。
|
|
192
201
|
root = resolve_project_root().resolve()
|
|
202
|
+
state_dir = supervisor_state_path().parent
|
|
193
203
|
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
194
204
|
state = supervisor.status()
|
|
205
|
+
findings_by_fp: dict[str, dict[str, Any]] = {}
|
|
206
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
207
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
208
|
+
f_fp = str(f_dict.get("fingerprint") or "").strip()
|
|
209
|
+
if f_fp:
|
|
210
|
+
findings_by_fp[f_fp] = f_dict
|
|
195
211
|
recipes = json.loads(Path(recipes_path).read_text(encoding="utf-8"))
|
|
196
212
|
if isinstance(recipes, dict):
|
|
197
213
|
recipes = [recipes]
|
|
@@ -212,6 +228,22 @@ def confirm(
|
|
|
212
228
|
print(f"[findings-confirm] ✗ oracle 文件不存在: {oracle_file}")
|
|
213
229
|
failed += 1
|
|
214
230
|
continue
|
|
231
|
+
vdir = verify_loop.verify_dir_for_finding(state_dir, fp)
|
|
232
|
+
finding_meta = findings_by_fp.get(fp, {"fingerprint": fp})
|
|
233
|
+
rel_file, _ = verify_loop._extract_target_file_and_line(finding_meta)
|
|
234
|
+
ast_diag = validate_python_poc_pair(
|
|
235
|
+
_strip_runner_wrapper(pos),
|
|
236
|
+
_strip_runner_wrapper(neg),
|
|
237
|
+
finding_key=fp,
|
|
238
|
+
attempt=1,
|
|
239
|
+
target_hints=(),
|
|
240
|
+
)
|
|
241
|
+
if ast_diag is not None:
|
|
242
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, ast_diag)
|
|
243
|
+
print(f"[findings-confirm] ✗ anti-gaming {fp[:44]} ({ast_diag.failure_code}): {ast_diag.summary} → {diag_path.name}")
|
|
244
|
+
failed += 1
|
|
245
|
+
continue
|
|
246
|
+
before_hashes = snapshot_target_hashes(root, [rel_file] if rel_file else [])
|
|
215
247
|
recipe = {
|
|
216
248
|
"positive": {"argv": _wrap_positive(pos),
|
|
217
249
|
"oracle": {"kind": "exit_code", "expected_exit_code": 1}},
|
|
@@ -222,14 +254,33 @@ def confirm(
|
|
|
222
254
|
"oracle_hash": hashlib.sha256(oracle_path.read_bytes()).hexdigest(),
|
|
223
255
|
}
|
|
224
256
|
try:
|
|
225
|
-
supervisor.verify_finding(finding=fp, recipe=recipe)
|
|
257
|
+
verify_res = supervisor.verify_finding(finding=fp, recipe=recipe)
|
|
226
258
|
except audit_supervisor.SupervisorError as exc:
|
|
227
|
-
|
|
259
|
+
diag = diagnose_verification_error(exc, attempt=1, finding_key=fp, stage="supervisor_verify")
|
|
260
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
261
|
+
print(f"[findings-confirm] ✗ verify {fp[:44]} ({diag.failure_code}): {str(exc)[:140]} → {diag_path.name}")
|
|
228
262
|
failed += 1
|
|
229
263
|
continue
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
264
|
+
tampered = verify_target_hashes_unchanged(root, before_hashes)
|
|
265
|
+
if tampered:
|
|
266
|
+
diag = diagnose_verification_error(
|
|
267
|
+
f"PoC modified target source file(s): {', '.join(tampered)}",
|
|
268
|
+
attempt=1, finding_key=fp, failure_code="source_tampered_rejected", stage="anti_tamper",
|
|
269
|
+
)
|
|
270
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
271
|
+
print(f"[findings-confirm] ✗ source-tampered {fp[:44]}: {tampered} → {diag_path.name}")
|
|
272
|
+
failed += 1
|
|
273
|
+
continue
|
|
274
|
+
receipt = verify_res.get("receipt") if isinstance(verify_res, Mapping) else {}
|
|
275
|
+
v_status = str(verify_res.get("status") or (receipt.get("status") if isinstance(receipt, Mapping) else ""))
|
|
276
|
+
if v_status and v_status != "CONFIRMED":
|
|
277
|
+
diag = diagnose_verification_receipt(receipt if isinstance(receipt, Mapping) else {}, attempt=1, finding_key=fp)
|
|
278
|
+
diag_path = verify_loop.record_attempt_diagnostic(vdir, diag)
|
|
279
|
+
print(f"[findings-confirm] ✗ verify-not-confirmed {fp[:44]} ({diag.failure_code}): {diag.summary} → {diag_path.name}")
|
|
280
|
+
failed += 1
|
|
281
|
+
continue
|
|
282
|
+
# F-RSI-20261118-009 / P0-D04:从输入 item 读取定级补录(原从 recipe 读取恒为 None)
|
|
283
|
+
recipe_severity = str(item.get("severity") or "").strip() or None
|
|
233
284
|
try:
|
|
234
285
|
supervisor.confirm_finding(
|
|
235
286
|
finding=fp, decision="confirmed",
|
|
@@ -327,6 +378,98 @@ def _reject_triplet(value: str) -> tuple[str, str, str]:
|
|
|
327
378
|
return parts[0].strip(), parts[1].strip(), parts[2].strip()
|
|
328
379
|
|
|
329
380
|
|
|
381
|
+
def prepare_verify_bundles(
|
|
382
|
+
fingerprints: list[str] | None = None,
|
|
383
|
+
*,
|
|
384
|
+
max_attempts: int = verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
385
|
+
) -> int:
|
|
386
|
+
"""为 pending 候选生成独立验证员盲审包 VerifyBundle(P0 D-01)。"""
|
|
387
|
+
from core.supervisor import audit_supervisor
|
|
388
|
+
|
|
389
|
+
max_attempts = verify_loop.normalize_max_attempts(max_attempts)
|
|
390
|
+
root = resolve_project_root().resolve()
|
|
391
|
+
state_dir = supervisor_state_path().parent
|
|
392
|
+
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
393
|
+
state = supervisor.status()
|
|
394
|
+
wanted = {fp.strip() for fp in (fingerprints or []) if fp and fp.strip()}
|
|
395
|
+
|
|
396
|
+
generated: list[dict[str, str]] = []
|
|
397
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
398
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
399
|
+
confirmation = f_dict.get("confirmation")
|
|
400
|
+
if isinstance(confirmation, dict) and confirmation.get("decision"):
|
|
401
|
+
continue
|
|
402
|
+
fp = str(f_dict.get("fingerprint") or "").strip()
|
|
403
|
+
if not fp or (wanted and fp not in wanted):
|
|
404
|
+
continue
|
|
405
|
+
bundle_path, _ = verify_loop.build_verify_bundle(
|
|
406
|
+
root, state_dir, f_dict, attempt=1, max_attempts=max_attempts,
|
|
407
|
+
)
|
|
408
|
+
generated.append({"fingerprint": fp, "bundle_path": str(bundle_path)})
|
|
409
|
+
print(f"[findings-confirm] ✓ verify-bundle {fp[:48]} → {bundle_path}")
|
|
410
|
+
|
|
411
|
+
if not generated:
|
|
412
|
+
print("[findings-confirm] 未找到匹配的 pending 候选")
|
|
413
|
+
return 1
|
|
414
|
+
print(f"[findings-confirm] 已生成 {len(generated)} 份盲审 VerifyBundle(协议:core/prompts/stages/stage_verify.md)")
|
|
415
|
+
return 0
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def run_verify_attempt_file(
|
|
419
|
+
attempt_path: Path,
|
|
420
|
+
*,
|
|
421
|
+
max_attempts: int = verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
422
|
+
) -> int:
|
|
423
|
+
"""消费独立验证员提交的单轮 attempt JSON 并执行引擎验证/自纠错推进(P0 D-02~D-05)。"""
|
|
424
|
+
from core.supervisor import audit_supervisor
|
|
425
|
+
|
|
426
|
+
max_attempts = verify_loop.normalize_max_attempts(max_attempts)
|
|
427
|
+
root = resolve_project_root().resolve()
|
|
428
|
+
state_dir = supervisor_state_path().parent
|
|
429
|
+
supervisor = audit_supervisor.Supervisor(root, state_path=supervisor_state_path())
|
|
430
|
+
state = supervisor.status()
|
|
431
|
+
findings_by_fp: dict[str, dict[str, Any]] = {}
|
|
432
|
+
for raw_f in getattr(state, "findings", ()) or ():
|
|
433
|
+
f_dict = raw_f if isinstance(raw_f, dict) else getattr(raw_f, "to_dict", dict)()
|
|
434
|
+
f_fp = str(f_dict.get("fingerprint") or "").strip()
|
|
435
|
+
if f_fp:
|
|
436
|
+
findings_by_fp[f_fp] = f_dict
|
|
437
|
+
|
|
438
|
+
payload = json.loads(Path(attempt_path).read_text(encoding="utf-8"))
|
|
439
|
+
items = payload if isinstance(payload, list) else [payload]
|
|
440
|
+
settled_any = False
|
|
441
|
+
has_failure = False
|
|
442
|
+
|
|
443
|
+
for item in items:
|
|
444
|
+
if not isinstance(item, Mapping):
|
|
445
|
+
has_failure = True
|
|
446
|
+
continue
|
|
447
|
+
fp = str(item.get("fingerprint") or "").strip()
|
|
448
|
+
if not fp or fp not in findings_by_fp:
|
|
449
|
+
print(f"[findings-confirm] ✗ 未知 finding fingerprint: {fp[:48]}")
|
|
450
|
+
has_failure = True
|
|
451
|
+
continue
|
|
452
|
+
result = verify_loop.execute_verify_attempt(
|
|
453
|
+
root=root,
|
|
454
|
+
state_dir=state_dir,
|
|
455
|
+
supervisor=supervisor,
|
|
456
|
+
finding=findings_by_fp[fp],
|
|
457
|
+
positive=str(item.get("positive") or ""),
|
|
458
|
+
negative=str(item.get("negative") or ""),
|
|
459
|
+
max_attempts=max_attempts,
|
|
460
|
+
)
|
|
461
|
+
status = str(result.get("status") or "")
|
|
462
|
+
print(json.dumps(result, ensure_ascii=False))
|
|
463
|
+
if status in {"CONFIRMED", "REJECTED", "STALLED"}:
|
|
464
|
+
settled_any = True
|
|
465
|
+
if status not in {"CONFIRMED"}:
|
|
466
|
+
has_failure = True
|
|
467
|
+
|
|
468
|
+
if settled_any:
|
|
469
|
+
_materialize_findings(root, supervisor)
|
|
470
|
+
return 0 if not has_failure else 1
|
|
471
|
+
|
|
472
|
+
|
|
330
473
|
def build_parser() -> argparse.ArgumentParser:
|
|
331
474
|
"""``bugx engine findings-confirm`` 的**唯一**参数契约。
|
|
332
475
|
|
|
@@ -338,7 +481,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
338
481
|
"""
|
|
339
482
|
parser = argparse.ArgumentParser(
|
|
340
483
|
prog="bugx engine findings-confirm",
|
|
341
|
-
description="Finding
|
|
484
|
+
description="Finding 确认一条龙与独立验证员盲审闭环:校验 recipe / 盲审包 → 引擎双正例+负对照实跑 → 诊断自纠错 → 物化确认块。",
|
|
342
485
|
)
|
|
343
486
|
parser.add_argument(
|
|
344
487
|
"recipes", nargs="?", metavar="RECIPE",
|
|
@@ -361,6 +504,18 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
361
504
|
"--from-verdicts", action="store_true",
|
|
362
505
|
help="输入文件是 judge verdicts(自动生成 recipe)而不是 recipe 本身",
|
|
363
506
|
)
|
|
507
|
+
parser.add_argument(
|
|
508
|
+
"--prepare-verify", nargs="*", metavar="FP",
|
|
509
|
+
help="为指定(或全部 pending)候选生成独立验证员盲审包 VerifyBundle(P0)",
|
|
510
|
+
)
|
|
511
|
+
parser.add_argument(
|
|
512
|
+
"--verify-attempt", dest="verify_attempt", metavar="ATTEMPT_JSON",
|
|
513
|
+
help="提交独立验证员单轮输出 JSON,执行 Anti-Gaming + 双正例负对照 + 报错诊断推进(P0)",
|
|
514
|
+
)
|
|
515
|
+
parser.add_argument(
|
|
516
|
+
"--max-attempts", dest="max_attempts", type=int, default=verify_loop.DEFAULT_MAX_ATTEMPTS,
|
|
517
|
+
help=f"单条 Finding 报错自纠错最大重试次数(1..{verify_loop.HARD_MAX_ATTEMPTS},默认 {verify_loop.DEFAULT_MAX_ATTEMPTS})",
|
|
518
|
+
)
|
|
364
519
|
return parser
|
|
365
520
|
|
|
366
521
|
|
|
@@ -370,13 +525,19 @@ def main(argv: list[str]) -> int:
|
|
|
370
525
|
args = parser.parse_args(argv)
|
|
371
526
|
except SystemExit as exc: # argparse 用 exit(2) 表示用法错误
|
|
372
527
|
return int(exc.code or 2)
|
|
528
|
+
if args.prepare_verify is not None:
|
|
529
|
+
return prepare_verify_bundles(args.prepare_verify, max_attempts=args.max_attempts)
|
|
530
|
+
if args.verify_attempt:
|
|
531
|
+
return run_verify_attempt_file(Path(args.verify_attempt), max_attempts=args.max_attempts)
|
|
373
532
|
rejects: list[tuple[str, str, str]] = list(args.reject or [])
|
|
374
533
|
source = args.recipe_opt or args.recipes
|
|
375
534
|
if not source:
|
|
376
535
|
parser.print_usage()
|
|
377
536
|
print(
|
|
378
537
|
"用法:bugx engine findings-confirm --recipe <recipes.json> "
|
|
379
|
-
"[--all-pending] [--reject <fp>:<class>:<reason> ...]"
|
|
538
|
+
"[--all-pending] [--reject <fp>:<class>:<reason> ...]\n"
|
|
539
|
+
" 或:bugx engine findings-confirm --prepare-verify [FP ...]\n"
|
|
540
|
+
" 或:bugx engine findings-confirm --verify-attempt <attempt.json> [--max-attempts 3]"
|
|
380
541
|
)
|
|
381
542
|
return 2
|
|
382
543
|
if args.from_verdicts:
|
|
@@ -299,7 +299,7 @@ def _refresh_acceptance_receipt_after_rebind() -> None:
|
|
|
299
299
|
|
|
300
300
|
|
|
301
301
|
def post(
|
|
302
|
-
final: bool = False,
|
|
302
|
+
final: bool = False, *, allow_incomplete: bool = False,
|
|
303
303
|
allow_serial: bool = False, dry_run: bool = False,
|
|
304
304
|
_post_attempt_token: object | None = None,
|
|
305
305
|
) -> int:
|
|
@@ -330,7 +330,7 @@ def post(
|
|
|
330
330
|
_begin_post_gate("runtime_load")
|
|
331
331
|
try:
|
|
332
332
|
result = _post_impl(
|
|
333
|
-
final=final,
|
|
333
|
+
final=final,
|
|
334
334
|
allow_incomplete=allow_incomplete,
|
|
335
335
|
allow_serial=allow_serial,
|
|
336
336
|
)
|
|
@@ -431,7 +431,7 @@ def _recovery_closeout_exemption_violation(
|
|
|
431
431
|
|
|
432
432
|
|
|
433
433
|
def _post_impl(
|
|
434
|
-
final: bool = False,
|
|
434
|
+
final: bool = False, *, allow_incomplete: bool = False,
|
|
435
435
|
allow_serial: bool = False,
|
|
436
436
|
) -> int:
|
|
437
437
|
# DES-06:``run_module_coverage`` 已下沉到共享层;``_round_result`` /
|
|
@@ -1044,7 +1044,7 @@ def _post_impl(
|
|
|
1044
1044
|
runtime = close_session(runtime.get("round_id") or runtime.get("lifecycle_id"), reason="completed")
|
|
1045
1045
|
_finish_post_gate("ok")
|
|
1046
1046
|
outcome = "INCOMPLETE" if (final and allow_incomplete) else "COMPLETE"
|
|
1047
|
-
share_state = maybe_share_lifecycle(runtime, lifecycle
|
|
1047
|
+
share_state = maybe_share_lifecycle(runtime, lifecycle)
|
|
1048
1048
|
refresh_startup_todo(
|
|
1049
1049
|
"report",
|
|
1050
1050
|
reason="Round 报告已封存,正在处理结论共享",
|
|
@@ -1173,7 +1173,7 @@ def _post_impl(
|
|
|
1173
1173
|
runtime.get("round_id") or runtime.get("lifecycle_id"),
|
|
1174
1174
|
reason="completed" if is_complete else "blocked",
|
|
1175
1175
|
)
|
|
1176
|
-
share_state = maybe_share_lifecycle(runtime, lifecycle
|
|
1176
|
+
share_state = maybe_share_lifecycle(runtime, lifecycle)
|
|
1177
1177
|
if is_complete:
|
|
1178
1178
|
share_phase = "share-pending" if share_state == "pending" else "share-completed"
|
|
1179
1179
|
else:
|
|
@@ -582,6 +582,19 @@ def run_recon_scout(
|
|
|
582
582
|
return []
|
|
583
583
|
|
|
584
584
|
|
|
585
|
+
def build_and_persist_semantic_overlay(
|
|
586
|
+
root: Path,
|
|
587
|
+
*,
|
|
588
|
+
llm_analyzer: Any = None,
|
|
589
|
+
max_files: int = 24,
|
|
590
|
+
) -> dict[str, Any]:
|
|
591
|
+
"""在 pre 阶段静态图谱之上叠加轻量语义侦察(隐式路由 / 鉴权边界 / 业务不变量,P2 / T-006)。"""
|
|
592
|
+
from core.launch_phases import semantic_recon
|
|
593
|
+
return semantic_recon.run_semantic_recon_overlay(
|
|
594
|
+
root, llm_analyzer=llm_analyzer, max_files=max_files, persist=True,
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
|
|
585
598
|
def match_unit_for_sink(units: list[str], rel_file: str, line: int | None) -> str | None:
|
|
586
599
|
if not units or not rel_file:
|
|
587
600
|
return None
|
|
@@ -170,8 +170,8 @@ def replay_share_pending(*, force: bool = False) -> None:
|
|
|
170
170
|
|
|
171
171
|
``submit`` 是自动重放授权;``local`` 的 share_pending 是**事后**通道——
|
|
172
172
|
旧实现对 ``local`` 硬短路,导致队列永不补偿(2026-11-09 复盘 4.3-2)。
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
现在使用 ``--replay-share-pending`` 显式授权即可在 ``local`` 下重放;
|
|
174
|
+
``none`` 仍是硬禁止(本轮不参与共享),只有显式把策略改为
|
|
175
175
|
``local``/``submit`` 才能清账。
|
|
176
176
|
"""
|
|
177
177
|
report_policy = _runtime_report_policy({})
|
|
@@ -312,7 +312,7 @@ def _maybe_enqueue_flywheel(runtime: dict, lifecycle: dict) -> None:
|
|
|
312
312
|
pass
|
|
313
313
|
|
|
314
314
|
|
|
315
|
-
def maybe_share_lifecycle(runtime: dict, lifecycle: dict
|
|
315
|
+
def maybe_share_lifecycle(runtime: dict, lifecycle: dict) -> str:
|
|
316
316
|
"""按已持久化 ``report_policy`` 处理封存报告,不再通过旧 flag 交互。
|
|
317
317
|
|
|
318
318
|
DOC-236 C6:若 L1 已采集并持久化 `report_policy`,则**按它执行且不再交互**
|
|
@@ -320,10 +320,6 @@ def maybe_share_lifecycle(runtime: dict, lifecycle: dict, share: str | None) ->
|
|
|
320
320
|
`submit` 直接无交互提交(私有)。
|
|
321
321
|
"""
|
|
322
322
|
report_policy = _runtime_report_policy(runtime)
|
|
323
|
-
if share is not None:
|
|
324
|
-
raise RuntimeError(
|
|
325
|
-
"旧的 share/--no-share 参数已移除;请在 L1 使用 report_policy=none|local|submit"
|
|
326
|
-
)
|
|
327
323
|
if report_policy == "none":
|
|
328
324
|
print(" (report_policy=none:本轮不参与结论共享与知识飞轮)")
|
|
329
325
|
return "completed"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
6
|
+
import argparse
|
|
6
7
|
import contextlib
|
|
7
8
|
import difflib
|
|
8
9
|
import hashlib
|
|
@@ -455,6 +456,66 @@ _KNOWN_CMDS = frozenset({
|
|
|
455
456
|
"coverage",
|
|
456
457
|
})
|
|
457
458
|
|
|
459
|
+
# The manual dispatchers use these argument shapes before opening a project.
|
|
460
|
+
# Other actions delegate argument parsing to their owning module.
|
|
461
|
+
_MANUAL_OPTIONS = {
|
|
462
|
+
"abort": ((), ("reason",)),
|
|
463
|
+
"bootstrap-coverage": (("confirm", "fresh-coverage"), ()),
|
|
464
|
+
"heartbeat": ((), ()),
|
|
465
|
+
"pause": ((), ()),
|
|
466
|
+
"polling": ((), ()),
|
|
467
|
+
"prompt": ((), ("stage",)),
|
|
468
|
+
"resume": ((), ()),
|
|
469
|
+
"workers": (
|
|
470
|
+
("execute", "dry-run", "brief"),
|
|
471
|
+
("count", "strategy", "provider", "model", "executable", "host",
|
|
472
|
+
"subagent-type", "max-workers", "stagger-seconds"),
|
|
473
|
+
),
|
|
474
|
+
}
|
|
475
|
+
_STARTUP_OPTIONS = (
|
|
476
|
+
("allow-serial", "approve-strategy", "autonomous", "bootstrap-coverage",
|
|
477
|
+
"ignore-global-budget", "json", "refresh-probes", "replay-share-pending"),
|
|
478
|
+
("cloud-sync", "commit-policy", "fix-mode", "host", "lesson-category", "lesson-query",
|
|
479
|
+
"life-kind", "max-round-wall-seconds", "polling", "profile", "report-policy",
|
|
480
|
+
"review-mode", "serial-reason", "session-recovery", "startup-action",
|
|
481
|
+
"startup-interaction", "strategy-plan", "tooling-choice"),
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def _manual_action_parser(command: str) -> argparse.ArgumentParser | None:
|
|
486
|
+
parser = argparse.ArgumentParser(prog=f"bugx engine {command}", allow_abbrev=False)
|
|
487
|
+
if command == "post":
|
|
488
|
+
parser.epilog = "结论共享由启动时设置的 --report-policy 控制。"
|
|
489
|
+
modes = parser.add_mutually_exclusive_group()
|
|
490
|
+
modes.add_argument("--dry-run", action="store_true", help="只评估结算快照")
|
|
491
|
+
modes.add_argument("--final", action="store_true", help="最终结算")
|
|
492
|
+
parser.add_argument("--allow-incomplete", action="store_true")
|
|
493
|
+
parser.add_argument("--allow-serial", action="store_true")
|
|
494
|
+
elif command in {"status", "control"}:
|
|
495
|
+
if command == "control":
|
|
496
|
+
parser.add_argument("action", nargs="?", default="status",
|
|
497
|
+
choices=("pause", "resume", "abort", "status"))
|
|
498
|
+
parser.add_argument("--reason")
|
|
499
|
+
parser.add_argument("--json", action="store_true")
|
|
500
|
+
else:
|
|
501
|
+
if command in {"pre", "audit"}:
|
|
502
|
+
switches, values = _STARTUP_OPTIONS
|
|
503
|
+
# [BEGIN DEV_ONLY: DEV_MODE_CLI_VALIDATION]
|
|
504
|
+
parser.add_argument("--dev", action="store_true")
|
|
505
|
+
# [END DEV_ONLY: DEV_MODE_CLI_VALIDATION]
|
|
506
|
+
elif command in _MANUAL_OPTIONS:
|
|
507
|
+
switches, values = _MANUAL_OPTIONS[command]
|
|
508
|
+
else:
|
|
509
|
+
return None
|
|
510
|
+
for name in switches:
|
|
511
|
+
parser.add_argument(f"--{name}", action="store_true")
|
|
512
|
+
number_types = {"count": int, "max-workers": int, "stagger-seconds": float} if command == "workers" else {}
|
|
513
|
+
for name in values:
|
|
514
|
+
parser.add_argument(f"--{name}", type=number_types.get(name, str))
|
|
515
|
+
if command == "polling":
|
|
516
|
+
parser.add_argument("policy", nargs="?", choices=("status", "auto", "manual"))
|
|
517
|
+
return parser
|
|
518
|
+
|
|
458
519
|
|
|
459
520
|
def _reject_legacy_share_policy(argv: list[str]) -> int | None:
|
|
460
521
|
"""Reject the removed pre flag before any project/runtime side effect."""
|
|
@@ -480,8 +541,47 @@ def main(argv: list[str]) -> int:
|
|
|
480
541
|
if legacy_share_policy is not None:
|
|
481
542
|
return legacy_share_policy
|
|
482
543
|
command = values[1] if len(values) > 1 else "status"
|
|
483
|
-
|
|
484
|
-
|
|
544
|
+
tail = values[2:]
|
|
545
|
+
if command in {"help", "--help", "-h"}:
|
|
546
|
+
if len(tail) > 1 or (tail and tail[0] not in _KNOWN_CMDS):
|
|
547
|
+
print("[launch_bugx] 未知帮助主题。", file=sys.stderr)
|
|
548
|
+
return 2
|
|
549
|
+
if tail and tail[0] not in {"help", "--help", "-h"}:
|
|
550
|
+
return main([values[0], tail[0], "--help"])
|
|
551
|
+
return _print_help()
|
|
552
|
+
if tail == ["help"]:
|
|
553
|
+
tail = ["--help"]
|
|
554
|
+
values[2:] = tail
|
|
555
|
+
options = None
|
|
556
|
+
if command in {"pre", "audit"} and "--allow-degraded" in tail and not {"-h", "--help"}.intersection(tail):
|
|
557
|
+
print("[launch_bugx] --allow-degraded 已移除。请修复缺失的安装或配置。", file=sys.stderr)
|
|
558
|
+
return 2
|
|
559
|
+
parser = _manual_action_parser(command)
|
|
560
|
+
if parser is not None:
|
|
561
|
+
if command in {"pre", "audit"} and {"-h", "--help"}.intersection(tail):
|
|
562
|
+
return _print_help()
|
|
563
|
+
removed_share = any(t.split("=", 1)[0] in {"--share", "--no-share"} for t in tail)
|
|
564
|
+
if command == "post" and removed_share and not {"-h", "--help"}.intersection(tail):
|
|
565
|
+
print("[launch_bugx] post 的共享选项已移除。请使用启动时的 --report-policy。", file=sys.stderr)
|
|
566
|
+
return 2
|
|
567
|
+
try:
|
|
568
|
+
options = parser.parse_args(tail)
|
|
569
|
+
except SystemExit as exc:
|
|
570
|
+
return int(exc.code)
|
|
571
|
+
if command == "control":
|
|
572
|
+
if options.reason is not None and options.action != "abort":
|
|
573
|
+
print("[launch_bugx] --reason 仅用于 control abort。", file=sys.stderr)
|
|
574
|
+
return 2
|
|
575
|
+
if options.json and options.action != "status":
|
|
576
|
+
print("[launch_bugx] --json 仅用于 control status。", file=sys.stderr)
|
|
577
|
+
return 2
|
|
578
|
+
if command == "post" and options.dry_run:
|
|
579
|
+
if options.allow_incomplete or options.allow_serial:
|
|
580
|
+
print("[launch_bugx] --dry-run 不接受结算授权选项。", file=sys.stderr)
|
|
581
|
+
return 2
|
|
582
|
+
return _post_dry_run_cli()
|
|
583
|
+
if command != "post":
|
|
584
|
+
return _main_impl(values, _options=options)
|
|
485
585
|
from core.launch_phases.post_observability import (
|
|
486
586
|
attempt_scope, current_attempt, log_attempt_finished,
|
|
487
587
|
record_unhandled_exception,
|
|
@@ -489,7 +589,7 @@ def main(argv: list[str]) -> int:
|
|
|
489
589
|
with attempt_scope("dispatcher") as attempt:
|
|
490
590
|
try:
|
|
491
591
|
result = _main_impl(
|
|
492
|
-
values, _post_attempt_token=attempt.attempt_token,
|
|
592
|
+
values, _post_attempt_token=attempt.attempt_token, _options=options,
|
|
493
593
|
)
|
|
494
594
|
except BaseException as exc:
|
|
495
595
|
exit_code = 130 if isinstance(exc, KeyboardInterrupt) else 1
|
|
@@ -511,6 +611,7 @@ def main(argv: list[str]) -> int:
|
|
|
511
611
|
|
|
512
612
|
def _main_impl(
|
|
513
613
|
argv: list[str], *, _post_attempt_token: object | None = None,
|
|
614
|
+
_options: argparse.Namespace | None = None,
|
|
514
615
|
) -> int:
|
|
515
616
|
if argv and (argv[0] in _KNOWN_CMDS or argv[0].startswith("-")):
|
|
516
617
|
argv = ["launch_bugx.py"] + list(argv)
|
|
@@ -519,7 +620,7 @@ def _main_impl(
|
|
|
519
620
|
if legacy_share_policy is not None:
|
|
520
621
|
return legacy_share_policy
|
|
521
622
|
_HELP_TOKENS = {"help", "--help", "-h"}
|
|
522
|
-
if cmd in _HELP_TOKENS or any(token in
|
|
623
|
+
if cmd in _HELP_TOKENS or any(token in {"--help", "-h"} for token in argv[2:]):
|
|
523
624
|
# 帮助契约要求三种写法都只读:`pre help` / `pre -h` 若不在这里截住,
|
|
524
625
|
# 会落进真实 pre 相位并写启动态,违反文档承诺。
|
|
525
626
|
return _print_help()
|
|
@@ -530,21 +631,13 @@ def _main_impl(
|
|
|
530
631
|
from core.runtime import project_init
|
|
531
632
|
|
|
532
633
|
if project_init.is_uninitialized_project(resolve_project_root()):
|
|
533
|
-
return status(as_json=
|
|
634
|
+
return status(as_json=_options.json)
|
|
534
635
|
except (OSError, ValueError, RuntimeError) as exc:
|
|
535
|
-
if
|
|
636
|
+
if _options.json:
|
|
536
637
|
print(json.dumps({"status": "BLOCKED", "reason": str(exc)}, ensure_ascii=False))
|
|
537
638
|
else:
|
|
538
639
|
print(f"[launch_bugx] ✗ 项目状态检查失败:{exc}")
|
|
539
640
|
return 1
|
|
540
|
-
if cmd in {"pre", "audit"} and "--allow-degraded" in argv[2:]:
|
|
541
|
-
# DOC-236 C1(A4):降级放行已废除。守卫必须位于**所有** pre/audit 出口
|
|
542
|
-
# 之前——放在尾部 dispatch 会被前置硬门禁(交互/版本/云/策略门禁)提前
|
|
543
|
-
# 返回绕过,从而变成"静默忽略"而不是"显式拒绝"。
|
|
544
|
-
print("[launch_bugx] ✗ --allow-degraded 已废除(DOC-236 C1 不允许降级):"
|
|
545
|
-
"请先自愈安装/配置;确无自动安装器的专有工具,"
|
|
546
|
-
"在 .bugx/config.json 的 tooling_exemptions 中显式豁免。")
|
|
547
|
-
return 1
|
|
548
641
|
# DOC-236 C5:只做轻量布局/config/fingerprint 准备;宿主、交互、Git、
|
|
549
642
|
# 版本与云门禁全部通过后才进入完整画像/探针/coverage pipeline。
|
|
550
643
|
# DOC-174 的 pending ticket 只做一次廉价恢复,不重新启动昂贵初始化。
|
|
@@ -587,8 +680,6 @@ def _main_impl(
|
|
|
587
680
|
except (OSError, ValueError, RuntimeError, subprocess.SubprocessError) as exc:
|
|
588
681
|
print(f"[launch_bugx] ✗ 项目初始化/续做失败:{exc}")
|
|
589
682
|
return 1
|
|
590
|
-
if cmd == "post" and "--dry-run" in argv[2:]:
|
|
591
|
-
return _post_dry_run_cli()
|
|
592
683
|
logger = None
|
|
593
684
|
if cmd == "post":
|
|
594
685
|
# Set up diagnostics before layout/version/runtime-path gates can reject.
|
|
@@ -824,8 +915,6 @@ def _main_impl(
|
|
|
824
915
|
try:
|
|
825
916
|
result: int
|
|
826
917
|
if cmd == "post":
|
|
827
|
-
_share = "share" if "--share" in argv[2:] else (
|
|
828
|
-
"no-share" if "--no-share" in argv[2:] else None)
|
|
829
918
|
post_started = time.monotonic()
|
|
830
919
|
phase_status = "failed"
|
|
831
920
|
try:
|
|
@@ -837,9 +926,9 @@ def _main_impl(
|
|
|
837
926
|
) as tracker:
|
|
838
927
|
try:
|
|
839
928
|
result = post(
|
|
840
|
-
final=
|
|
841
|
-
allow_incomplete=
|
|
842
|
-
allow_serial=
|
|
929
|
+
final=_options.final,
|
|
930
|
+
allow_incomplete=_options.allow_incomplete,
|
|
931
|
+
allow_serial=_options.allow_serial,
|
|
843
932
|
_post_attempt_token=_post_attempt_token,
|
|
844
933
|
)
|
|
845
934
|
phase_status = "ok" if result == 0 else "failed"
|
|
@@ -874,7 +963,7 @@ def _main_impl(
|
|
|
874
963
|
duration_seconds=round(phase_duration, 3),
|
|
875
964
|
)
|
|
876
965
|
elif cmd == "status":
|
|
877
|
-
result = status(as_json=
|
|
966
|
+
result = status(as_json=_options.json)
|
|
878
967
|
elif cmd == "polling":
|
|
879
968
|
value = argv[2] if len(argv) > 2 else None
|
|
880
969
|
result = polling(value)
|
|
@@ -892,7 +981,6 @@ def _main_impl(
|
|
|
892
981
|
fresh_coverage="--fresh-coverage" in argv[2:],
|
|
893
982
|
)
|
|
894
983
|
elif cmd in {"pre", "audit"}:
|
|
895
|
-
# `--allow-degraded` 已在 `_main_impl` 入口统一拒绝(A4),此处不再重复判定。
|
|
896
984
|
pre_args = argv[2:]
|
|
897
985
|
is_dev = dev_mode_requested
|
|
898
986
|
strategy_plan_val = None
|
|
@@ -941,15 +1029,15 @@ def _main_impl(
|
|
|
941
1029
|
host=_option_value(pre_args, "--host"),
|
|
942
1030
|
)
|
|
943
1031
|
elif cmd == "control":
|
|
944
|
-
sub =
|
|
1032
|
+
sub = _options.action
|
|
945
1033
|
if sub == "pause":
|
|
946
1034
|
result = pause()
|
|
947
1035
|
elif sub == "resume":
|
|
948
1036
|
result = resume()
|
|
949
1037
|
elif sub == "abort":
|
|
950
|
-
result = abort(
|
|
1038
|
+
result = abort(_options.reason)
|
|
951
1039
|
else:
|
|
952
|
-
result = status(as_json=
|
|
1040
|
+
result = status(as_json=_options.json)
|
|
953
1041
|
elif cmd == "findings-confirm":
|
|
954
1042
|
from core.launch_phases import finding_confirm_phase
|
|
955
1043
|
result = finding_confirm_phase.main(argv[2:])
|