Skip to content

[Feat] Add a persisted opt-in setting for DCG - #1061

Merged
edelauna merged 21 commits into
mainfrom
feat/dcg-setting
Aug 5, 2026
Merged

[Feat] Add a persisted opt-in setting for DCG#1061
edelauna merged 21 commits into
mainfrom
feat/dcg-setting

Conversation

@navedmerchant

@navedmerchant navedmerchant commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

Closes #1057
Part of #1049. Split from #1050.

Description

Adds the persisted destructiveCommandGuardEnabled setting 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-service

Depends on PR 2 only for enable-time installation verification.

Test Procedure

pnpm --dir src exec vitest run core/webview/__tests__/ClineProvider.spec.ts core/webview/__tests__/webviewMessageHandler.spec.ts
pnpm --dir webview-ui exec vitest run src/components/settings/__tests__/AutoApproveSettings.spec.tsx
pnpm --dir packages/types check-types
pnpm --dir src check-types
pnpm --dir webview-ui check-types
node scripts/find-missing-translations.js --area=core
node scripts/find-missing-translations.js --area=webview

Result: 183 extension and 11 webview tests passed; all type-checks, lint, and translation validation passed.

Checklist

  • Full setting round trip implemented
  • SettingsView uses local cached state
  • Tests/type-check/lint/i18n checks passing

Summary by CodeRabbit

  • New Features

    • Added an optional Destructive Command Guard for automatically approved terminal commands.
    • The guard is disabled by default and can be enabled from Execute settings.
    • Existing allowed and denied command controls are hidden while the guard is active.
    • Added localized setting labels, descriptions, and error messages across supported languages.
  • Bug Fixes

    • Enabling the guard now reports installation or platform availability failures and safely remains disabled.
  • Tests

    • Added coverage for settings persistence, validation, toggling, installation failures, and conditional controls.

@navedmerchant navedmerchant added the enhancement New feature or request label Jul 30, 2026
@navedmerchant navedmerchant added the enhancement New feature or request label Jul 30, 2026
@navedmerchant navedmerchant self-assigned this Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Destructive Command Guard setting

Layer / File(s) Summary
Shared setting and provider state
packages/types/src/..., src/core/webview/ClineProvider.ts, src/core/webview/__tests__/ClineProvider.spec.ts
The optional boolean setting is added to shared state and defaults to false. Provider state and webview state include the persisted value.
Enablement and installation flow
src/services/destructive-command-guard/index.ts, src/core/webview/webviewMessageHandler.ts, src/core/webview/__tests__/webviewMessageHandler.spec.ts, src/i18n/locales/*/common.json
Enabling the setting verifies or installs DCG before persistence. Failures save false and display localized errors.
Settings UI and localized descriptions
webview-ui/src/components/settings/..., webview-ui/src/i18n/locales/*/settings.json
The Auto-Approve view adds the guard checkbox and hides allowed and denied command editors while it is enabled. UI tests cover buffering, defaults, toggling, and visibility.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: hannesrudolph

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a persisted opt-in setting for Destructive Command Guard.
Linked Issues check ✅ Passed The changes implement the persisted setting, state round trip, installation validation, localized errors, UI behavior, and focused tests required by issue [#1057].
Out of Scope Changes check ✅ Passed All changes support the persisted Destructive Command Guard setting, its validation, localization, state handling, UI, and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dcg-setting

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/types/src/__tests__/global-settings.test.ts

ESLint 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.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

packages/types/src/vscode-extension-host.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 8 others

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ui/src/components/settings/AutoApproveSettings.tsx 68.42% 0 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 30, 2026
@navedmerchant
navedmerchant force-pushed the feat/dcg-binary-service branch from 5c460bd to baade5f Compare July 30, 2026 04:50
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 30, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good - mostly minor nits

Comment thread src/core/webview/webviewMessageHandler.ts Outdated
Comment thread src/i18n/locales/en/common.json Outdated
@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 31, 2026
@navedmerchant
navedmerchant force-pushed the feat/dcg-binary-service branch from baade5f to e1a0c39 Compare August 1, 2026 17:17
@github-actions github-actions Bot removed the awaiting-author PR is waiting for the author to address requested changes label Aug 1, 2026
@github-actions github-actions Bot added the awaiting-author PR is waiting for the author to address requested changes label Aug 1, 2026
@github-actions github-actions Bot removed the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 2, 2026
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 2, 2026
Base automatically changed from feat/dcg-binary-service to main August 5, 2026 01:50
@navedmerchant
navedmerchant dismissed edelauna’s stale review August 5, 2026 01:50

The base branch was changed.

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Aug 5, 2026
@github-actions github-actions Bot removed the awaiting-author PR is waiting for the author to address requested changes label Aug 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2f2205 and 70a20c9.

📒 Files selected for processing (47)
  • packages/types/src/__tests__/global-settings.test.ts
  • packages/types/src/global-settings.ts
  • packages/types/src/vscode-extension-host.ts
  • src/core/webview/ClineProvider.ts
  • src/core/webview/__tests__/ClineProvider.spec.ts
  • src/core/webview/__tests__/webviewMessageHandler.spec.ts
  • src/core/webview/webviewMessageHandler.ts
  • src/i18n/locales/ca/common.json
  • src/i18n/locales/de/common.json
  • src/i18n/locales/en/common.json
  • src/i18n/locales/es/common.json
  • src/i18n/locales/fr/common.json
  • src/i18n/locales/hi/common.json
  • src/i18n/locales/id/common.json
  • src/i18n/locales/it/common.json
  • src/i18n/locales/ja/common.json
  • src/i18n/locales/ko/common.json
  • src/i18n/locales/nl/common.json
  • src/i18n/locales/pl/common.json
  • src/i18n/locales/pt-BR/common.json
  • src/i18n/locales/ru/common.json
  • src/i18n/locales/tr/common.json
  • src/i18n/locales/vi/common.json
  • src/i18n/locales/zh-CN/common.json
  • src/i18n/locales/zh-TW/common.json
  • src/services/destructive-command-guard/index.ts
  • webview-ui/src/components/settings/AutoApproveSettings.tsx
  • webview-ui/src/components/settings/SettingsView.tsx
  • webview-ui/src/components/settings/__tests__/AutoApproveSettings.spec.tsx
  • webview-ui/src/i18n/locales/ca/settings.json
  • webview-ui/src/i18n/locales/de/settings.json
  • webview-ui/src/i18n/locales/en/settings.json
  • webview-ui/src/i18n/locales/es/settings.json
  • webview-ui/src/i18n/locales/fr/settings.json
  • webview-ui/src/i18n/locales/hi/settings.json
  • webview-ui/src/i18n/locales/id/settings.json
  • webview-ui/src/i18n/locales/it/settings.json
  • webview-ui/src/i18n/locales/ja/settings.json
  • webview-ui/src/i18n/locales/ko/settings.json
  • webview-ui/src/i18n/locales/nl/settings.json
  • webview-ui/src/i18n/locales/pl/settings.json
  • webview-ui/src/i18n/locales/pt-BR/settings.json
  • webview-ui/src/i18n/locales/ru/settings.json
  • webview-ui/src/i18n/locales/tr/settings.json
  • webview-ui/src/i18n/locales/vi/settings.json
  • webview-ui/src/i18n/locales/zh-CN/settings.json
  • webview-ui/src/i18n/locales/zh-TW/settings.json

Comment on lines +684 to +700
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),
}),
)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

Comment on lines +356 to +359
"destructiveCommandGuard": {
"label": "啟用破壞性命令防護",
"description": "下載並使用適用於此平台的 Destructive Command Guard(DCG)。DCG 允許的命令會自動執行。被 DCG 阻擋的命令需要你核准後才能執行。啟用後,Zoo 的命令清單將停用。關閉此選項時,已下載的執行檔會保留。"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

@edelauna
edelauna added this pull request to the merge queue Aug 5, 2026
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Aug 5, 2026
Merged via the queue into main with commit 0ae9217 Aug 5, 2026
18 checks passed
@edelauna
edelauna deleted the feat/dcg-setting branch August 5, 2026 02:33
myk1yt pushed a commit to myk1yt/Zoo-Code that referenced this pull request Aug 6, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a persisted opt-in setting for Destructive Command Guard

2 participants