@tencent-ai/codebuddy-code 2.109.2 → 2.109.3

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.
@@ -324,6 +324,43 @@ if _SESSION_ID:
324
324
  except Exception:
325
325
  pass
326
326
 
327
+ def _exit_bulk_guard_control(message):
328
+ try:
329
+ sys.stderr.write(message)
330
+ if not message.endswith("\n"):
331
+ sys.stderr.write("\n")
332
+ sys.stderr.flush()
333
+ finally:
334
+ raise SystemExit(1)
335
+
336
+ def _check_bulk_delete_guard(abs_path):
337
+ guard_path = os.environ.get("CODEBUDDY_SAFE_DELETE_BULK_GUARD")
338
+ node_bin = os.environ.get("CODEBUDDY_NODE_BIN")
339
+ if not os.environ.get("CODEBUDDY_SAFE_DELETE_BULK_STATE_DIR") \
340
+ or not os.environ.get("CODEBUDDY_TOOL_CALL_ID"):
341
+ return
342
+ if not guard_path or not node_bin or not os.path.isfile(guard_path):
343
+ _exit_bulk_guard_control(
344
+ "[safe-delete][SAFE_DELETE_BULK_GUARD_ERROR] msg=helper-unavailable guard=%s"
345
+ % (guard_path or "unset")
346
+ )
347
+ env = dict(os.environ)
348
+ env["NODE_OPTIONS"] = ""
349
+ try:
350
+ result = subprocess.run(
351
+ [node_bin, guard_path, "check", "--target", abs_path],
352
+ capture_output=True, text=True, timeout=10, env=env
353
+ )
354
+ except Exception as e:
355
+ _exit_bulk_guard_control(
356
+ "[safe-delete][SAFE_DELETE_BULK_GUARD_ERROR] %s" % e
357
+ )
358
+ if result.returncode != 0:
359
+ _exit_bulk_guard_control(
360
+ result.stderr.strip()
361
+ or "[safe-delete][SAFE_DELETE_BULK_GUARD_ERROR] exit %d" % result.returncode
362
+ )
363
+
327
364
  # -----------------------------------------------------------------------
328
365
  # genie-trash native binary 支持(优先路径,不可用自动降级)
329
366
  # 优先使用 GENIE_TRASH_DIR 环境变量(由 buildSafeDeleteEnv() 注入),
@@ -401,6 +438,7 @@ if _SESSION_ID:
401
438
  except Exception:
402
439
  pass
403
440
  raise OSError(message)
441
+ _check_bulk_delete_guard(abs_path)
404
442
  if _try_trash_via_binary(abs_path):
405
443
  _record_trash(abs_path)
406
444
  return True