CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
headlessSafetyWarnings.ts51 linesDownload Raw Back to utils
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7export const HEADLESS_YOLO_NO_SANDBOX_WARNING =8  'Warning: running headless with --yolo / approval-mode=yolo and no sandbox. ' +9  "All tool calls (shell, write, edit) auto-execute at this process's privilege level. " +10  'Enable a sandbox via --sandbox / QWEN_SANDBOX, or set ' +11  'QWEN_CODE_SUPPRESS_YOLO_WARNING=1 to silence this notice.';12 13/**14 * Returns a warning line to emit when running in YOLO without a sandbox in a15 * non-interactive run, or `null` when no warning is warranted: sandbox is16 * configured, we're already inside a sandbox, approval mode is not YOLO, or17 * the user explicitly suppressed the notice.18 *19 * The call site (gemini.tsx) is responsible for gating on20 * `!config.isInteractive()` — this helper deliberately ignores interactivity21 * so it stays pure and unit-testable.22 *23 * The `env` argument is injectable for tests; production callers omit it and24 * fall through to `process.env`.25 */26export function getHeadlessYoloSafetyWarning(27  config: {28    getApprovalMode(): string | undefined;29    getSandbox(): unknown;30  },31  env: NodeJS.ProcessEnv = process.env,32): string | null {33  // Keep this literal in sync with ApprovalMode.YOLO without importing core at runtime.34  if (config.getApprovalMode() !== 'yolo') return null;35  if (config.getSandbox()) return null;36  // `SANDBOX` is set by the sandbox transport itself: macOS seatbelt sets37  // it to `sandbox-exec`, Docker/Podman to the container name (e.g.38  // `qwen-code-sandbox`). Match the rest of the codebase39  // (sandboxConfig.ts, gemini.tsx, Footer.tsx, prompts.ts, …) which all40  // treat any non-empty value as "inside a sandbox". A strict 1/true41  // check here misfires inside real sandboxes, where the helper would42  // wrongly emit a "no sandbox" warning despite the run being contained.43  if (env['SANDBOX']) return null;44  if (isTruthyEnv(env['QWEN_CODE_SUPPRESS_YOLO_WARNING'])) return null;45  return HEADLESS_YOLO_NO_SANDBOX_WARNING;46}47 48function isTruthyEnv(val: string | undefined): boolean {49  return val === '1' || val === 'true';50}51 
basant307/AI_Governance_Project · CoolFace