Skip to content

Add per-instance safety config with rules, confirm mode, and global safety#318

Merged
clavery merged 3 commits intomainfrom
feature/safety-guard
Apr 6, 2026
Merged

Add per-instance safety config with rules, confirm mode, and global safety#318
clavery merged 3 commits intomainfrom
feature/safety-guard

Conversation

@clavery
Copy link
Copy Markdown
Collaborator

@clavery clavery commented Apr 4, 2026

Summary

  • SafetyGuard SDK class evaluates operations against configurable rules and safety levels, producing typed evaluations (allow/block/confirm)
  • Safety rules match by HTTP method+path, job ID, or CLI command ID using glob patterns — first-match-wins evaluation
  • Confirmation mode (confirm: true) softens level-based blocks into interactive prompts; non-interactive environments (MCP, CI) block instead
  • Per-instance config via safety object in dw.json with level, confirm, and rules
  • Global safety config loaded from {configDir}/safety.json or SFCC_SAFETY_CONFIG env var — merges with per-instance (level: max wins, confirm: OR, instance rules checked first)
  • withSafetyConfirmation utility for retry-after-confirm pattern (used by CLI, available for VS Code extension and SDK consumers)
  • Job commands (job:run, job:import, job:export) evaluate both job and command safety rules before execution
  • Dedicated Safety Mode guide page at /guide/safety

Test plan

  • Manual: dw.json with safety rules — verify blocking, allowing, confirming behavior
  • Manual: safety.json in config dir — verify global rules merge with per-instance
  • Manual: SFCC_SAFETY_CONFIG env var — verify override of global config path
  • Backward compat: SFCC_SAFETY_LEVEL env var still works when no config safety present

…afety.json

SafetyGuard evaluates operations against rules (allow/block/confirm) and
levels. Rules match by HTTP method+path, job ID, or CLI command ID with
glob patterns. Confirmation mode softens blocks into interactive prompts.

Global safety config loaded from {configDir}/safety.json or SFCC_SAFETY_CONFIG
env var. Merges with per-instance dw.json: level uses max, confirm uses OR,
instance rules take priority over global rules.
clavery added 2 commits April 3, 2026 21:54
When a job export or import passes safety evaluation, the subsequent
WebDAV DELETE (archive cleanup) was still caught by the HTTP middleware's
level check. Now the commands add a temporary rule allowing DELETE on
Impex paths for the duration of the operation.

Also adds SafetyGuard.temporarilyAddRule() for arbitrary temporary rules.
…und operations

- Evaluate command rules in BaseCommand.init() so every command is checked
  against safety rules automatically (e.g., { command: "code:deploy", action: "block" })
- Add temporary DELETE allow rules for code:deploy and code:watch to prevent
  internal WebDAV cleanup from being blocked by safety middleware
- Simplify job commands to only evaluate job-specific rules (command rules
  now handled generically)
- Update safety guide to document automatic command rule enforcement
@clavery clavery merged commit 6880a84 into main Apr 6, 2026
5 checks passed
@clavery clavery deleted the feature/safety-guard branch April 6, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant