[Feat] Add a persisted opt-in setting for DCG - #1061
Conversation
📝 WalkthroughWalkthroughThe PR adds a persisted, disabled-by-default Destructive Command Guard setting. It validates and propagates the setting, verifies installation before enabling it, updates the Auto-Approve UI, adds localized messages, and expands focused tests. ChangesDestructive Command Guard setting
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/types/src/__tests__/global-settings.test.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/types/src/global-settings.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. packages/types/src/vscode-extension-host.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5c460bd to
baade5f
Compare
e655ee2 to
28fb788
Compare
edelauna
left a comment
There was a problem hiding this comment.
looks good - mostly minor nits
baade5f to
e1a0c39
Compare
28fb788 to
f7ae3cb
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/webview/webviewMessageHandler.ts`:
- Around line 684-700: Validate
message.updatedSettings.destructiveCommandGuardEnabled before the persistence
loop, accepting only a boolean true/false value and normalizing or rejecting
malformed values such as the string "true" to false. Ensure only validated
literal true proceeds through ensureDcgInstalled, and add coverage for malformed
payload values while preserving the existing installation failure handling.
In `@webview-ui/src/i18n/locales/zh-TW/settings.json`:
- Around line 356-359: Update the description within the destructiveCommandGuard
translation to replace the second-person pronoun 你 with 您, preserving the rest
of the Traditional Chinese text unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 38571531-6a06-4ebf-8bc2-7a9b03ca3ea8
📒 Files selected for processing (47)
packages/types/src/__tests__/global-settings.test.tspackages/types/src/global-settings.tspackages/types/src/vscode-extension-host.tssrc/core/webview/ClineProvider.tssrc/core/webview/__tests__/ClineProvider.spec.tssrc/core/webview/__tests__/webviewMessageHandler.spec.tssrc/core/webview/webviewMessageHandler.tssrc/i18n/locales/ca/common.jsonsrc/i18n/locales/de/common.jsonsrc/i18n/locales/en/common.jsonsrc/i18n/locales/es/common.jsonsrc/i18n/locales/fr/common.jsonsrc/i18n/locales/hi/common.jsonsrc/i18n/locales/id/common.jsonsrc/i18n/locales/it/common.jsonsrc/i18n/locales/ja/common.jsonsrc/i18n/locales/ko/common.jsonsrc/i18n/locales/nl/common.jsonsrc/i18n/locales/pl/common.jsonsrc/i18n/locales/pt-BR/common.jsonsrc/i18n/locales/ru/common.jsonsrc/i18n/locales/tr/common.jsonsrc/i18n/locales/vi/common.jsonsrc/i18n/locales/zh-CN/common.jsonsrc/i18n/locales/zh-TW/common.jsonsrc/services/destructive-command-guard/index.tswebview-ui/src/components/settings/AutoApproveSettings.tsxwebview-ui/src/components/settings/SettingsView.tsxwebview-ui/src/components/settings/__tests__/AutoApproveSettings.spec.tsxwebview-ui/src/i18n/locales/ca/settings.jsonwebview-ui/src/i18n/locales/de/settings.jsonwebview-ui/src/i18n/locales/en/settings.jsonwebview-ui/src/i18n/locales/es/settings.jsonwebview-ui/src/i18n/locales/fr/settings.jsonwebview-ui/src/i18n/locales/hi/settings.jsonwebview-ui/src/i18n/locales/id/settings.jsonwebview-ui/src/i18n/locales/it/settings.jsonwebview-ui/src/i18n/locales/ja/settings.jsonwebview-ui/src/i18n/locales/ko/settings.jsonwebview-ui/src/i18n/locales/nl/settings.jsonwebview-ui/src/i18n/locales/pl/settings.jsonwebview-ui/src/i18n/locales/pt-BR/settings.jsonwebview-ui/src/i18n/locales/ru/settings.jsonwebview-ui/src/i18n/locales/tr/settings.jsonwebview-ui/src/i18n/locales/vi/settings.jsonwebview-ui/src/i18n/locales/zh-CN/settings.jsonwebview-ui/src/i18n/locales/zh-TW/settings.json
| if (message.updatedSettings.destructiveCommandGuardEnabled === true) { | ||
| try { | ||
| const { ensureDcgInstalled } = await import("../../services/destructive-command-guard") | ||
| const binaryPath = await ensureDcgInstalled(provider.context.globalStorageUri.fsPath) | ||
| if (!binaryPath) { | ||
| message.updatedSettings.destructiveCommandGuardEnabled = false | ||
| vscode.window.showErrorMessage(t("common:errors.destructiveCommandGuard.unavailable")) | ||
| } | ||
| } catch (error) { | ||
| message.updatedSettings.destructiveCommandGuardEnabled = false | ||
| vscode.window.showErrorMessage( | ||
| t("common:errors.destructiveCommandGuard.enableFailed", { | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }), | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Validate destructiveCommandGuardEnabled before persistence.
Only literal true invokes ensureDcgInstalled. A runtime payload with "true" skips installation and is later persisted unchanged by the loop at Line 801. Reject non-boolean values or normalize them to false before the loop. Add coverage for malformed values.
As per PR objectives, enabling the setting must verify DCG installation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/core/webview/webviewMessageHandler.ts` around lines 684 - 700, Validate
message.updatedSettings.destructiveCommandGuardEnabled before the persistence
loop, accepting only a boolean true/false value and normalizing or rejecting
malformed values such as the string "true" to false. Ensure only validated
literal true proceeds through ensureDcgInstalled, and add coverage for malformed
payload values while preserving the existing installation failure handling.
| "destructiveCommandGuard": { | ||
| "label": "啟用破壞性命令防護", | ||
| "description": "下載並使用適用於此平台的 Destructive Command Guard(DCG)。DCG 允許的命令會自動執行。被 DCG 阻擋的命令需要你核准後才能執行。啟用後,Zoo 的命令清單將停用。關閉此選項時,已下載的執行檔會保留。" | ||
| }, |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use consistent second-person terminology.
This description uses 你, while nearby settings strings predominantly use 您. Replace 你 with 您 to keep the Traditional Chinese UI consistent.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@webview-ui/src/i18n/locales/zh-TW/settings.json` around lines 356 - 359,
Update the description within the destructiveCommandGuard translation to replace
the second-person pronoun 你 with 您, preserving the rest of the Traditional
Chinese text unchanged.
* refactor: extract managed binary installation infrastructure Refs Zoo-Code-Org#1055 * fix: address managed binary review feedback * feat: add destructive command guard binary service Refs Zoo-Code-Org#1056 * test: strengthen DCG binary service coverage * feat: add persisted destructive command guard setting Refs Zoo-Code-Org#1057 * fix: clarify DCG enablement errors * test: cover DCG global setting schema * test: raise DCG setting patch coverage * fix: address DCG service review feedback * fix: address managed binary review feedback * test: cover managed binary cleanup boundaries * fix: address DCG binary service feedback * fix: finalize managed binary download handling * test: mirror download stream close events --------- Co-authored-by: Naved Merchant <14171946+navedmerchant@users.noreply.github.com> Co-authored-by: edelauna <54631123+edelauna@users.noreply.github.com>
Related GitHub Issue
Closes #1057
Part of #1049. Split from #1050.
Description
Adds the persisted
destructiveCommandGuardEnabledsetting across shared types, extension/provider state, SettingsView's local cached state, save handling, and Auto-Approve settings UI.Enabling verifies DCG installation. Failure normalizes the setting back to disabled and shows a localized error. Existing allowlist/denylist behavior remains available while DCG is disabled. This PR does not yet change command approval policy.
Stack
3 / 4 — base:
feat/dcg-binary-serviceDepends on PR 2 only for enable-time installation verification.
Test Procedure
Result: 183 extension and 11 webview tests passed; all type-checks, lint, and translation validation passed.
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Tests