Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Aaaaash
Copy link
Member

@Aaaaash Aaaaash commented May 8, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

image

image

image

Changelog

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能
    • 增加了“终端命令自动执行策略”设置,支持“关闭”、“自动”和“总是”三种模式,允许用户自定义 AI 终端命令的自动执行行为。
    • 终端工具界面新增自动执行策略提示及设置跳转,用户可根据策略和工具参数决定是否需要手动批准命令执行。
    • 优化了终端工具的运行状态显示与用户交互逻辑,提升操作体验。
  • 样式
    • 为自动执行策略相关 UI 元素添加了新的样式,提升界面可读性和交互体验。
  • 文档
    • 补充了中英文自动执行策略的相关本地化描述和提示信息,完善用户指引。

@opensumi opensumi bot added the 🎨 feature feature required label May 8, 2025
Copy link
Contributor

coderabbitai bot commented May 8, 2025

"""

Walkthrough

本次更改为 AI 原生终端工具引入了终端命令自动执行策略的用户偏好设置,包括在设置界面增加新选项、支持多语言本地化、前端组件根据用户偏好与工具参数动态渲染自动执行审批 UI,并提供跳转设置的命令。

Changes

文件/路径分组 变更摘要
packages/ai-native/src/browser/ai-core.contribution.ts 在 MCP 服务器设置组下注册了新的终端自动执行策略偏好项。
packages/core-common/src/settings/ai-native.ts AINativeSettingSectionsId 枚举新增 TerminalAutoRun 成员。
packages/ai-native/src/browser/preferences/schema.ts 新增 ETerminalAutoExecutionPolicy 枚举和对应的偏好项 schema,支持三种策略,并调整本地化方式。
packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx 组件引入偏好服务和命令服务,根据用户偏好和工具参数动态决定是否需要审批,新增自动执行策略提示 UI。
packages/ai-native/src/browser/mcp/tools/components/index.module.less 新增自动执行策略相关的样式类,优化 UI 展示。
packages/i18n/src/common/en-US.lang.ts
packages/i18n/src/common/zh-CN.lang.ts
新增终端自动执行策略相关的多语言本地化字符串。
packages/ai-native/src/browser/mcp/tools/handlers/RunCommand.ts 新增注入偏好服务,重构审批逻辑以结合用户偏好,新增私有方法封装审批判断。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TerminalToolComponent
    participant PreferenceService
    participant CommandService

    User->>TerminalToolComponent: 打开终端工具
    TerminalToolComponent->>PreferenceService: 读取 TerminalAutoRun 偏好
    TerminalToolComponent->>TerminalToolComponent: 结合工具参数判断 needApproval
    alt 需要审批
        TerminalToolComponent->>User: 展示自动执行被拒绝提示及跳转设置入口
        User->>TerminalToolComponent: 点击跳转设置
        TerminalToolComponent->>CommandService: 执行跳转到设置命令
    else 不需要审批
        TerminalToolComponent->>User: 正常显示命令执行结果
    end
Loading

Possibly related PRs

Suggested labels

🎨 feature

Suggested reviewers

  • erha19
  • ensorrow
    """

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.

yarn install v1.22.22
[1/4] Resolving packages...
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9aef7c3 and f279d11.

📒 Files selected for processing (1)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/i18n/src/common/en-US.lang.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
packages/core-common/src/settings/ai-native.ts (1)

45-46: 新增枚举成员命名规范检查

TerminalAutoRun = 'ai.native.terminal.autorun' 与其他 AINativeSettingSectionsId 中的命名和格式保持一致。建议在枚举成员上方添加简要的 JSDoc 注释,以提高可读性和维护性。

packages/i18n/src/common/en-US.lang.ts (1)

1606-1614: 优化描述文本并保持一致性

  1. autorun.description 字符串中,去除多余空格并统一小写:将 "off means...""auto means...""Always means..." 中的大小写统一为小写,保证风格一致。
  2. 确认是否已在 zh-CN.lang.ts 中同步添加对应的本地化条目。
- 'ai.native.terminal.autorun.description':
-   'The auto-execution policy for Agent terminal commands.   off means never auto-execute, auto means the model will decide whether to auto-execute based on the command (only available on premium models), Always means always auto-execute.',
+ 'ai.native.terminal.autorun.description':
+   'The auto-execution policy for Agent terminal commands. off means never auto-execute, auto means the model will decide whether to auto-execute based on the command (only available on premium models), always means always auto-execute.',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26ad68b and a728f8b.

📒 Files selected for processing (7)
  • packages/ai-native/src/browser/ai-core.contribution.ts (1 hunks)
  • packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx (3 hunks)
  • packages/ai-native/src/browser/mcp/tools/components/index.module.less (1 hunks)
  • packages/ai-native/src/browser/preferences/schema.ts (3 hunks)
  • packages/core-common/src/settings/ai-native.ts (1 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: build-windows
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build (ubuntu-latest, 20.x)
🔇 Additional comments (10)
packages/i18n/src/common/zh-CN.lang.ts (1)

1369-1377: 很好的本地化字符串添加!

这些新增的本地化条目清晰地描述了终端命令自动执行策略的三种模式,并提供了相关的UI提示信息。

建议考虑在 ai.native.terminal.autorun.description 中加入一些安全建议,例如对于包含敏感操作的命令推荐使用哪种模式。

packages/ai-native/src/browser/preferences/schema.ts (3)

10-14: 枚举定义清晰明确

这个枚举很好地定义了终端自动执行策略的三个级别。


22-24: 从直接调用 localize 改为使用占位符模式是个好的改进

将之前直接调用 localize 函数改为使用 %...% 占位符格式,使代码更加整洁,也便于本地化维护。

Also applies to: 72-73, 78-161


166-171: 终端自动执行策略配置项定义正确

新增的终端自动执行策略配置项定义完整,包括类型、可选值、默认值和描述。默认值设置为 auto 是合理的,既保证了用户体验又兼顾了安全性。

packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx (6)

3-8: 适当更新了导入

正确导入了需要的服务和类型定义,包括配置服务、命令服务和新的自动执行策略枚举。


43-50: 服务注入和状态管理

正确注入了配置服务和命令服务,并添加了用于跟踪策略显示状态的状态变量,以及读取用户终端自动执行策略的配置。


51-61: 逻辑清晰的审批决策过程

needApproval 函数逻辑清晰,根据用户配置的终端执行策略和工具参数综合判断是否需要用户审批。


63-65: 打开设置的命令处理

提供了打开特定设置页面的回调函数,方便用户直接调整终端自动执行策略。


101-120: 用户友好的自动执行策略UI

这段代码添加了清晰的用户界面,用于显示当前自动执行策略状态并提供调整选项。UI 设计包括:

  1. 可展开的解释信息
  2. 关于自动运行的问题提示
  3. 用于直接跳转到设置页面的链接

建议考虑添加简单的视觉反馈(如图标颜色),以更直观地表明当前策略状态。


128-128: 条件渲染逻辑更新

更新了条件渲染逻辑,将 needApproval 变量集成到控制 UI 显示的条件中,确保只在需要用户审批的情况下显示相关界面。

Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 6.25000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 52.88%. Comparing base (fb82396) to head (f279d11).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ative/src/browser/mcp/tools/handlers/RunCommand.ts 0.00% 9 Missing and 2 partials ⚠️
...ckages/ai-native/src/browser/preferences/schema.ts 0.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4529      +/-   ##
==========================================
- Coverage   52.89%   52.88%   -0.02%     
==========================================
  Files        1677     1677              
  Lines      103326   103339      +13     
  Branches    22387    22391       +4     
==========================================
- Hits        54659    54653       -6     
- Misses      40488    40504      +16     
- Partials     8179     8182       +3     
Flag Coverage Δ
jsdom 48.39% <6.25%> (-0.02%) ⬇️
node 12.06% <6.25%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Aaaaash
Copy link
Member Author

Aaaaash commented May 9, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented May 9, 2025

🎉 PR Next publish successful!

3.8.3-next-1746753590.0

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/ai-native/src/browser/mcp/tools/handlers/RunCommand.ts (2)

55-65: 方法命名可以更加明确

方法名称 isAlwaysApproval 与实际功能有些混淆。该方法判断是否需要用户批准,而不是判断是否"总是"需要批准。

建议重命名为更清晰的名称,例如 isApprovalRequired

-  private isAlwaysApproval(requireApproval: boolean) {
+  private isApprovalRequired(requireApproval: boolean) {
     const terminalAutoExecution = this.preferenceService.get(AINativeSettingSectionsId.TerminalAutoRun);
     if (
       terminalAutoExecution === ETerminalAutoExecutionPolicy.off ||
       (terminalAutoExecution === ETerminalAutoExecutionPolicy.auto && requireApproval)
     ) {
       return true;
     }

     return false;
   }

69-69: 请更新方法调用以匹配重命名

如果您接受上面的方法重命名建议,请确保在此处也更新方法调用。

-    if (this.isAlwaysApproval(args.require_user_approval)) {
+    if (this.isApprovalRequired(args.require_user_approval)) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a728f8b and 9aef7c3.

📒 Files selected for processing (5)
  • packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx (3 hunks)
  • packages/ai-native/src/browser/mcp/tools/components/index.module.less (3 hunks)
  • packages/ai-native/src/browser/mcp/tools/handlers/RunCommand.ts (3 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ai-native/src/browser/mcp/tools/components/index.module.less
  • packages/i18n/src/common/en-US.lang.ts
  • packages/i18n/src/common/zh-CN.lang.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ai-native/src/browser/mcp/tools/handlers/RunCommand.ts (1)
packages/ai-native/src/browser/types.ts (1)
  • MCPLogger (355-357)
🪛 Biome (1.9.4)
packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx

[error] 132-132: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (7)
packages/ai-native/src/browser/mcp/tools/handlers/RunCommand.ts (1)

40-42: 实现良好的用户偏好集成

成功引入 PreferenceService 以支持终端自动执行策略功能。这符合 PR 的目标,允许用户根据自己的偏好设置终端命令的执行政策。

packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx (6)

60-74: 用户偏好逻辑实现良好

成功实现了根据用户偏好设置确定是否需要命令批准的逻辑。这与 RunCommand.ts 中的服务器端逻辑保持一致,确保了 UI 和后端行为的一致性。


42-50: 良好的本地化实践

使用映射对象和辅助函数来处理策略标签的本地化是一个很好的做法。这使代码更加清晰,并且支持未来可能添加的新策略选项。


84-86: 很好的用户体验改进

添加了打开设置的功能,使用户可以轻松访问和修改终端自动执行策略。这是一个很好的用户体验改进。


105-144: UI 增强有效改善用户体验

UI 更新提供了更好的用户反馈,包括:

  1. 显示运行状态的加载指示器
  2. 当前自动执行策略的可视化表示
  3. 能够快速导航到相关设置
  4. 更清晰的命令输出显示

这些改进有效地增强了用户体验。

🧰 Tools
🪛 Biome (1.9.4)

[error] 132-132: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)


146-151: 运行状态指示器改进

添加了运行状态指示器,使用户可以清楚地了解命令的执行状态。这是一个很好的用户体验改进。


132-132:

✅ Verification successful

安全风险:使用 dangerouslySetInnerHTML

使用 dangerouslySetInnerHTML 可能会使用户面临跨站脚本攻击(XSS)风险,特别是在渲染用户输入或外部数据时。

建议检查 computeAnsiLogString 函数是否正确地对内容进行了安全处理。如果没有,请考虑使用专门的安全库来处理终端输出的 ANSI 转义序列,如 ansi-to-html 并结合 DOMPurify 进行额外的安全处理:

- <code dangerouslySetInnerHTML={{ __html: computeAnsiLogString(output.text || '') }} />
+ <code dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(computeAnsiLogString(output.text || '')) }} />

或者考虑使用更安全的替代方案,比如专门的终端渲染库。


🌐 Web query:

Does React have a secure alternative to dangerouslySetInnerHTML for rendering HTML content?

💡 Result:

React's dangerouslySetInnerHTML is the standard way to render raw HTML content inside a component, but as its name implies, it comes with security risks—primarily cross-site scripting (XSS) vulnerabilities if the HTML content is not properly sanitized.

React itself does not provide a built-in secure alternative that directly replaces dangerouslySetInnerHTML. Instead, best practice is to sanitize the HTML content before rendering it. This means using a third-party library to clean the HTML and remove any malicious scripts or dangerous elements.

Popular libraries for sanitizing HTML content include:

  • DOMPurify: A widely used, robust sanitizer that cleans HTML and prevents XSS attacks.
  • sanitize-html: Another configurable sanitizer that allows fine-grained control over allowed tags and attributes.

The typical workflow is:

  1. Sanitize your HTML string with one of these libraries.
  2. Pass the sanitized HTML to dangerouslySetInnerHTML safely.

Example using DOMPurify:

import DOMPurify from 'dompurify';

function SafeHtmlRenderer({ html }) {
  const cleanHtml = DOMPurify.sanitize(html);
  return <div dangerouslySetInnerHTML={{ __html: cleanHtml }} />;
}

Summary: There is no direct built-in React alternative to dangerouslySetInnerHTML that is inherently safe. The secure approach is to sanitize the HTML string thoroughly before using dangerouslySetInnerHTML to render it.


🏁 Script executed:

#!/bin/bash
# Locate the definition of computeAnsiLogString to verify its sanitization
rg "computeAnsiLogString" -R .

Length of output: 435


🏁 Script executed:

#!/bin/bash
# Search for computeAnsiLogString definition across the repo
rg "function computeAnsiLogString" -n .
rg "const computeAnsiLogString" -n .
rg "export .*computeAnsiLogString" -n .
rg "computeAnsiLogString" -n .

Length of output: 1052


🏁 Script executed:

#!/bin/bash
# 查看 computeAnsiLogString 函数实现,确认是否包含 HTML 转义或安全处理
sed -n '1,200p' packages/ai-native/src/browser/mcp/tools/components/computeAnsiLogString.ts

Length of output: 825


🌐 Web query:

What is the default value of htmlEscapeInput in ansi_up library? Does ansi_up.ansi_to_html escape HTML input by default to prevent XSS?

💡 Result:

Based on the search results, I can provide information about the HTML escaping behavior in the ansi_up library:

The ansi_up library does perform HTML escaping by default to prevent XSS vulnerabilities. According to the documentation, the ansi_to_html method "safely escapes any unsafe HTML characters"[1]. This is an important security feature that helps protect applications from cross-site scripting attacks.

The default value for HTML escaping functionality in ansi_up is controlled by a property called escape_for_html, which is set to true by default[3][2]. This means that HTML characters are automatically escaped when using the ansi_to_html method unless you explicitly disable this feature.

If you want to disable HTML escaping, you would need to set this property to false:

let converter = new AnsiUp()
converter.escape_for_html = false

As shown in one of the code examples[3], some developers intentionally disable this feature when they have other mechanisms for handling HTML escaping or when they specifically need to preserve HTML in the output.

For security best practices, it's generally recommended to keep the default HTML escaping enabled, especially when dealing with user-generated content or data from untrusted sources, as this helps prevent XSS vulnerabilities that could otherwise be exploited.

Citations:


无需额外处理:ANSI 转 HTML 已默认做了安全转义

computeAnsiLogString 源于 ansi_up,且默认配置(escape_for_html = true)会对所有输入中的 HTML 特殊字符进行转义,生成的 <span> 标签仅用于展示 ANSI 颜色,不会执行任何脚本。因此,以下代码虽然使用了 dangerouslySetInnerHTML,但渲染内容已经安全转义,无需额外引入 DOMPurify 或其他库。

  • 位置:packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx
  • 代码:
    <code dangerouslySetInnerHTML={{ __html: computeAnsiLogString(output.text || '') }} />
🧰 Tools
🪛 Biome (1.9.4)

[error] 132-132: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

@Aaaaash Aaaaash merged commit 03bd40c into main May 12, 2025
12 checks passed
@Aaaaash Aaaaash deleted the feat/support-terminal-auto-run-configuration branch May 12, 2025 07:40
@erha19 erha19 mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants