Skip to content

feat(agent): support inquiry agent mode when notepad created - #10

Closed
emikeliu wants to merge 4 commits into
NERDSORG:mainfrom
emikeliu:agent-mode-inquiry
Closed

feat(agent): support inquiry agent mode when notepad created#10
emikeliu wants to merge 4 commits into
NERDSORG:mainfrom
emikeliu:agent-mode-inquiry

Conversation

@emikeliu

@emikeliu emikeliu commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fixed issue #9.

实现了 registerModeDisplayCommand, modeDisplay 以在 notebook 已被创建时查询当前的 agent mode
请注意该 pull request 包含 #8 所提到的本地化功能

Summary by Sourcery

在整个扩展中引入本地化支持,并新增一个命令,用于在已有笔记本中显示当前代理模式,同时使代理类型系统在配置变更时可重新加载。

新功能:

  • 在笔记本工具栏和侧边栏命令入口中新增命令,用于显示现有 Mutsumi 笔记本的当前代理模式。
  • 引入一个封装 VS Code 本地化功能的 i18n 辅助工具,并将其接入用户可见的 UI 字符串(消息、标签、工具提示),覆盖命令、侧边栏和控制器。

增强:

  • 使代理类型和工具集注册表可以安全地重新初始化,并在 mutsumi.agentConfig 设置变更时自动重新加载。
  • 将代理类型系统的初始化集中到一个共享函数中,以便在扩展激活和配置变更时复用。
  • 优化桌面通知和错误消息的措辞,同时保持现有行为一致。
  • 通过 package.json 占位符和特定语言的 nls 文件实现扩展元数据和配置描述的本地化。

构建:

  • 通过添加 l10n bundle 文件并在扩展清单中接入这些文件,配置 VS Code 本地化资源。
Original summary in English

Summary by Sourcery

Introduce localization support across the extension and add a command to display the current agent mode in existing notebooks, while making the agent type system re-loadable on configuration changes.

New Features:

  • Add a notebook toolbar command and sidebar command entry to display the current agent mode for an existing Mutsumi notebook.
  • Introduce an i18n helper wrapping VS Code localization and wire it through user-facing UI strings (messages, labels, tooltips) across commands, sidebars, and controllers.

Enhancements:

  • Make the agent type and tool set registries safely re-initializable and automatically reload them when the mutsumi.agentConfig setting changes.
  • Centralize agent type system initialization into a shared function for use on activation and configuration change.
  • Improve desktop notifications and error messaging wording while keeping behavior consistent.
  • Localize extension metadata and configuration descriptions via package.json placeholders and language-specific nls files.

Build:

  • Configure VS Code localization assets by adding l10n bundle files and wiring the extension manifest to use them.

@sourcery-ai

sourcery-ai Bot commented Aug 2, 2026

Copy link
Copy Markdown

审阅者指南

在整个扩展中增加了本地化的 i18n 层,引入了新的 mutsumi.displayMode 命令和工具栏项,用于在已创建的笔记本中查询当前代理模式,并在 mutsumi.agentConfig 发生变化时,使代理类型/工具集注册表可以重新加载。

用于展示当前代理模式的 mutsumi.displayMode 命令时序图

sequenceDiagram
    actor User
    participant VSCode as VSCode
    participant Extension as MutsumiExtension
    participant Notebook as mutsumi-notebook

    User->>VSCode: executeCommand(mutsumi.displayMode)
    VSCode->>Extension: registerModeDisplayCommand handler

    alt [no active notebook editor]
        Extension->>vscode.window: showWarningMessage(t(notebook.noEditor))
    else [notebookType != mutsumi-notebook]
        Extension->>vscode.window: showWarningMessage(t(notebook.onlyMutsumi))
    else [valid mutsumi-notebook]
        Extension->>Notebook: read notebook.metadata.contextItems
        Extension->>vscode.window: showInformationMessage(t(modeDisplay.currentMode, mode))
    end
Loading

文件级变更

变更 详情 文件
将 VS Code 本地化功能接入扩展/包元数据和面向用户的字符串,并添加语言包。
  • 将 package.json 中的静态字符串(显示名称、视图标题、命令标题、配置描述)替换为 %key% 标记,并声明 l10n 路径。
  • 引入 package.nls*.jsonl10n/bundle*.json 来存放可本地化字符串。
  • 添加对 vscode.l10n.tsrc/i18n.ts 封装,并重构命令、通知、日志记录器和 UI 元素,使用 t(...) 替代硬编码的英文文本。
package.json
package.nls.json
package.nls.zh-cn.json
l10n/bundle.l10n.json
l10n/bundle.l10n.zh-cn.json
src/i18n.ts
src/extension.ts
src/notebook/commands/selectModel.ts
src/sidebar/contextTreeItem.ts
src/sidebar/shellTaskTreeItem.ts
src/notebook/commands/compressConversation.ts
src/sidebar/approvalTreeItem.ts
src/notebook/commands/renameSession.ts
src/controller.ts
src/notebook/commands/testRagSearch.ts
src/notebook/commands/toggleAutoApprove.ts
src/notebook/commands/debugContext.ts
src/notebook/completionProvider.ts
src/sidebar/agentTreeItem.ts
src/notebook/commands/pruneGhostBlocks.ts
src/tools.d/permission.ts
src/agent/agentRunner.ts
src/notebook/serializer.ts
src/notifications.ts
src/debugLogger.ts
src/tools.d/edit_file.ts
src/tools.d/toolsLogger.ts
使 ToolSetRegistry 和 AgentTypeRegistry 可重新初始化,并将其与 mutsumi.agentConfig 的配置变更关联起来。
  • 在 extension.ts 中将代理类型系统的初始化提取为 initializeAgentTypeSystem(),并在扩展激活和 onDidChangeConfiguration 时调用。
  • 更新 ToolSetRegistry 和 AgentTypeRegistry,以支持多次调用 initialize():通过清理状态、使用 ready 标志,以及调整保护方法来实现。
  • 添加配置变更监听器,当 mutsumi.agentConfig 被修改时重新加载代理类型系统,并带有调试日志和错误处理。
src/extension.ts
src/registry/agentTypeRegistry.ts
src/registry/toolSetRegistry.ts
添加新的 mutsumi.displayMode 命令和笔记本工具栏按钮,用于显示已有笔记本的当前代理模式。
  • 在 package.json 中声明 mutsumi.displayMode 命令并使用本地化标题,同时将其添加到笔记本工具栏分组。
  • 实现 registerModeDisplayCommand:校验当前激活的是 Mutsumi 笔记本,从笔记本 metadata 的 contextItems 中读取模式,并通过本地化文本显示模态信息消息。
  • registerModeDisplayCommand 接入 registerToolbarCommands,以便在扩展激活期间注册该命令。
package.json
src/notebook/toolbar.ts
src/notebook/commands/modeDisplay.ts
利用新的 i18n 字符串进行小幅 UX 和行为调整(错误、警告、工具提示、标签)。
  • 将 HTTP 服务器密码流程改为使用本地化消息,并更新行为文本标签。
  • 在 AgentController 和 AgentRunner 中改进错误/复制详情提示,使用本地化按钮文本。
  • 调整 shell task 和审批工具提示,使其完全本地化并略微重构,同时通过 i18n 微调序列化器的默认代理名称。
  • 通过本地化字符串和更一致的措辞,收紧多个笔记本命令的保护性消息(无编辑器、错误的笔记本类型、缺少模型/上下文)。
src/extension.ts
src/controller.ts
src/agent/agentRunner.ts
src/sidebar/shellTaskTreeItem.ts
src/sidebar/approvalTreeItem.ts
src/notebook/serializer.ts
src/notebook/commands/selectModel.ts
src/notebook/commands/compressConversation.ts
src/notebook/commands/testRagSearch.ts
src/notebook/commands/toggleAutoApprove.ts
src/notebook/commands/debugContext.ts
src/notebook/commands/pruneGhostBlocks.ts
src/notebook/commands/renameSession.ts
src/notebook/completionProvider.ts
src/sidebar/contextTreeItem.ts
src/sidebar/agentTreeItem.ts
src/tools.d/permission.ts

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 回复 Sourcery 的某条审阅评论,要求它从该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 以在任何时候(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary,以在任何时候(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可在任何时候(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会非常有用。
  • 取消所有 Sourcery 审阅: 在 Pull Request 中评论 @sourcery-ai dismiss,即可取消所有现有的 Sourcery 审阅。尤其适用于希望从一次全新的审阅开始的情况——别忘了再评论 @sourcery-ai review 以触发新的审阅!

自定义你的使用体验

打开你的控制面板 来:

  • 启用或停用审阅功能,例如 Sourcery 生成的 Pull Request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Adds a localized i18n layer across the extension, introduces a new mutsumi.displayMode command and toolbar item to query the current agent mode in an already-created notebook, and makes the agent type/tool set registries reloadable when mutsumi.agentConfig changes.

Sequence diagram for mutsumi.displayMode command to show current agent mode

sequenceDiagram
    actor User
    participant VSCode as VSCode
    participant Extension as MutsumiExtension
    participant Notebook as mutsumi-notebook

    User->>VSCode: executeCommand(mutsumi.displayMode)
    VSCode->>Extension: registerModeDisplayCommand handler

    alt [no active notebook editor]
        Extension->>vscode.window: showWarningMessage(t(notebook.noEditor))
    else [notebookType != mutsumi-notebook]
        Extension->>vscode.window: showWarningMessage(t(notebook.onlyMutsumi))
    else [valid mutsumi-notebook]
        Extension->>Notebook: read notebook.metadata.contextItems
        Extension->>vscode.window: showInformationMessage(t(modeDisplay.currentMode, mode))
    end
Loading

File-Level Changes

Change Details Files
Wire VS Code localization into extension/package metadata and user-facing strings, and add locale bundles.
  • Replace static strings in package.json (display name, view titles, command titles, configuration descriptions) with %key% tokens and declare l10n path.
  • Introduce package.nls*.json and l10n/bundle*.json for localizable strings.
  • Add src/i18n.ts wrapper over vscode.l10n.t and refactor commands, notifications, loggers, and UI elements to use t(...) instead of hard-coded English text.
package.json
package.nls.json
package.nls.zh-cn.json
l10n/bundle.l10n.json
l10n/bundle.l10n.zh-cn.json
src/i18n.ts
src/extension.ts
src/notebook/commands/selectModel.ts
src/sidebar/contextTreeItem.ts
src/sidebar/shellTaskTreeItem.ts
src/notebook/commands/compressConversation.ts
src/sidebar/approvalTreeItem.ts
src/notebook/commands/renameSession.ts
src/controller.ts
src/notebook/commands/testRagSearch.ts
src/notebook/commands/toggleAutoApprove.ts
src/notebook/commands/debugContext.ts
src/notebook/completionProvider.ts
src/sidebar/agentTreeItem.ts
src/notebook/commands/pruneGhostBlocks.ts
src/tools.d/permission.ts
src/agent/agentRunner.ts
src/notebook/serializer.ts
src/notifications.ts
src/debugLogger.ts
src/tools.d/edit_file.ts
src/tools.d/toolsLogger.ts
Make ToolSetRegistry and AgentTypeRegistry re-initializable and hook them to configuration changes for mutsumi.agentConfig.
  • Extract agent type system init into initializeAgentTypeSystem() in extension.ts and call it both on activation and on onDidChangeConfiguration.
  • Update ToolSetRegistry and AgentTypeRegistry to support multiple initialize() calls by clearing state, using a ready flag, and adjusting guard methods.
  • Add configuration-change listener that reloads the agent type system when mutsumi.agentConfig is changed, with debug logging and error handling.
src/extension.ts
src/registry/agentTypeRegistry.ts
src/registry/toolSetRegistry.ts
Add new mutsumi.displayMode command and notebook toolbar button to display current agent mode for existing notebooks.
  • Declare mutsumi.displayMode command in package.json with localized title and add it to the notebook toolbar group.
  • Implement registerModeDisplayCommand that validates a Mutsumi notebook is active, reads mode from notebook metadata contextItems, and shows a modal information message with localized text.
  • Wire registerModeDisplayCommand into registerToolbarCommands so the command is registered during activation.
package.json
src/notebook/toolbar.ts
src/notebook/commands/modeDisplay.ts
Minor UX and behavior adjustments leveraging new i18n strings (errors, warnings, tooltips, labels).
  • Change HTTP server password flow to localized messages and update behavior text labels.
  • Improve error/copy-details prompts in AgentController and AgentRunner using localized button text.
  • Adjust shell task and approval tooltips to be fully localized and slightly restructured, and tweak serializer default agent name via i18n.
  • Tighten several notebook command guard messages (no editor, wrong notebook type, missing models/context) via localized strings and consistent phrasing.
src/extension.ts
src/controller.ts
src/agent/agentRunner.ts
src/sidebar/shellTaskTreeItem.ts
src/sidebar/approvalTreeItem.ts
src/notebook/serializer.ts
src/notebook/commands/selectModel.ts
src/notebook/commands/compressConversation.ts
src/notebook/commands/testRagSearch.ts
src/notebook/commands/toggleAutoApprove.ts
src/notebook/commands/debugContext.ts
src/notebook/commands/pruneGhostBlocks.ts
src/notebook/commands/renameSession.ts
src/notebook/completionProvider.ts
src/sidebar/contextTreeItem.ts
src/sidebar/agentTreeItem.ts
src/tools.d/permission.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - 我发现了 4 个问题,并留下了一些总体反馈:

  • 新的 mutsumi.displayMode 命令目前假设当前模式存储在 metadata.contextItems[0].content 中;建议使用一个更明确、定义良好的 metadata 字段,这样在 contextItems 结构变更时,这个逻辑仍然能保持稳定。
  • modeDisplay.ts 中,showInformationMessage 使用了 { modal: true },会阻塞 UI;如果这只是用于展示信息,建议改为非模态通知,以避免打断用户的工作流。
  • 用于调试输出通道名称的 i18n key(t('Mutsumi Debug'))是一个字面量,而不是像其他字符串那样使用命名空间的 key;建议将其与现有 key 命名约定对齐(例如 debugLogger.channelName),这样更便于管理本地化资源包。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `mutsumi.displayMode` command currently assumes the current mode is stored as `metadata.contextItems[0].content`; consider using a more explicit, well-defined metadata field so this remains stable if contextItems structure changes.
- In `modeDisplay.ts`, `showInformationMessage` is called with `{ modal: true }` which blocks the UI; if this is only informational, you may want to use a non-modal notification to avoid interrupting the workflow.
- The i18n key used for the debug output channel name (`t('Mutsumi Debug')`) is a literal rather than a namespaced key like other strings; aligning it with the key naming convention (e.g. `debugLogger.channelName`) will make localization bundles easier to manage.

## Individual Comments

### Comment 1
<location path="src/extension.ts" line_range="64-73" />
<code_context>
+ * between extension activation and the onDidChangeConfiguration handler so
+ * that behavior stays consistent.
+ */
+function initializeAgentTypeSystem(): void {
+	// 1. Load Mutsumi configuration (merged with built-in defaults + validated)
+	const mutsumiConfig = loadMutsumiConfig();
+	debugLogger.log("[Extension] Mutsumi config loaded successfully");
+
+	// 2. Initialize ToolSetRegistry with configured tool sets
+	const toolSetRegistry = ToolSetRegistry.getInstance();
+	toolSetRegistry.initialize(mutsumiConfig.toolSets);
+	debugLogger.log("[Extension] ToolSetRegistry initialized");
+
+	// 3. Initialize AgentTypeRegistry with configured agent types
+	const agentTypeRegistry = AgentTypeRegistry.getInstance();
+	agentTypeRegistry.initialize(
+		mutsumiConfig.agentTypes,
</code_context>
<issue_to_address>
**issue (bug_risk):** AgentTypeSystem reload can leave registries in an unusable state if initialization throws.

Because both registries now clear internal state before validating the new config, any exception in `loadMutsumiConfig()` or either `initialize()` (e.g. malformed `mutsumi.agentConfig`) leaves them with `ready = false` and empty data, breaking subsequent agent operations after a bad config change. Consider validating against a cloned copy of the state, then only swapping the internal maps/flags once validation fully succeeds; on failure, retain the previous configuration and surface the error instead of partially resetting the registries.
</issue_to_address>

### Comment 2
<location path="src/registry/toolSetRegistry.ts" line_range="69-71" />
<code_context>
 	 * @throws {Error} If a tool set references a non-existent tool
 	 */
 	initialize(config: ToolSetsConfig): void {
-		if (this.initialized) {
-			return;
-		}
-
-		// Clear existing tool sets
+		// Clear existing tool sets so a reload fully replaces prior state
 		this.toolSets.clear();

 		// Check if RAG is enabled (embedding endpoint configured)
</code_context>
<issue_to_address>
**issue (bug_risk):** ToolSetRegistry.initialize clears state before validation, which exacerbates reload failure risk.

With the new reload behavior, `initialize()` now clears `this.toolSets` before validation and only later sets `this.ready = true`. If any validation fails (missing tools, RAG checks, or future logic), the registry is left with an empty map and `ready` may never be set, breaking callers like `getToolSet` / `getCombinedToolSet` after an invalid config change.

Consider instead constructing and validating a new `Map<string, string[]>` locally, then assigning it to `this.toolSets` and setting `this.ready = true` only after validation fully succeeds. This preserves the previous, valid tool sets when a reload fails.
</issue_to_address>

### Comment 3
<location path="src/registry/agentTypeRegistry.ts" line_range="51-53" />
<code_context>
 	 * @throws {Error} If validation fails
 	 */
 	initialize(config: AgentTypeConfigMap, toolSetNames: string[]): void {
-		if (this.initialized) {
-			return;
-		}
-
-		// Clear existing types
+		// Clear existing types so a reload fully replaces prior state
 		this.agentTypes.clear();
 		this.toolSetNames = new Set(toolSetNames);

</code_context>
<issue_to_address>
**issue (bug_risk):** AgentTypeRegistry.initialize now fully clears types before validation, similar reload robustness concern.

Because `initialize()` clears `agentTypes` and resets `toolSetNames` before validation, any validation failure (e.g. unknown child types or tool set references) leaves the registry empty and `ready = false`, breaking consumers like `getEntryAgentTypes` and `getAgentType`. Consider validating into temporary `Map`/`Set` instances and only swapping them in and setting `ready = true` after validation succeeds, so the last-known-good configuration is preserved when `mutsumi.agentConfig` is invalid.
</issue_to_address>

### Comment 4
<location path="src/notebook/commands/modeDisplay.ts" line_range="1-3" />
<code_context>
 import { normalizeReasoningEffort } from './agent/types';
+import { t } from './i18n';

 /**
  * Controls the execution of agent notebooks.
</code_context>
<issue_to_address>
**nitpick:** Mode display command file header still references selectModel, which can confuse maintenance.

Please update the file-level JSDoc (description and `@module` tag) to reflect `mutsumi.displayMode` / `modeDisplay` so they align with the current command implementation and avoid confusion for future readers and tooling that uses these annotations.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
帮我变得更有帮助!请在每条评论上点 👍 或 👎,我会根据这些反馈改进之后的代码审查。
Original comment in English

Hey - I've found 4 issues, and left some high level feedback:

  • The new mutsumi.displayMode command currently assumes the current mode is stored as metadata.contextItems[0].content; consider using a more explicit, well-defined metadata field so this remains stable if contextItems structure changes.
  • In modeDisplay.ts, showInformationMessage is called with { modal: true } which blocks the UI; if this is only informational, you may want to use a non-modal notification to avoid interrupting the workflow.
  • The i18n key used for the debug output channel name (t('Mutsumi Debug')) is a literal rather than a namespaced key like other strings; aligning it with the key naming convention (e.g. debugLogger.channelName) will make localization bundles easier to manage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `mutsumi.displayMode` command currently assumes the current mode is stored as `metadata.contextItems[0].content`; consider using a more explicit, well-defined metadata field so this remains stable if contextItems structure changes.
- In `modeDisplay.ts`, `showInformationMessage` is called with `{ modal: true }` which blocks the UI; if this is only informational, you may want to use a non-modal notification to avoid interrupting the workflow.
- The i18n key used for the debug output channel name (`t('Mutsumi Debug')`) is a literal rather than a namespaced key like other strings; aligning it with the key naming convention (e.g. `debugLogger.channelName`) will make localization bundles easier to manage.

## Individual Comments

### Comment 1
<location path="src/extension.ts" line_range="64-73" />
<code_context>
+ * between extension activation and the onDidChangeConfiguration handler so
+ * that behavior stays consistent.
+ */
+function initializeAgentTypeSystem(): void {
+	// 1. Load Mutsumi configuration (merged with built-in defaults + validated)
+	const mutsumiConfig = loadMutsumiConfig();
+	debugLogger.log("[Extension] Mutsumi config loaded successfully");
+
+	// 2. Initialize ToolSetRegistry with configured tool sets
+	const toolSetRegistry = ToolSetRegistry.getInstance();
+	toolSetRegistry.initialize(mutsumiConfig.toolSets);
+	debugLogger.log("[Extension] ToolSetRegistry initialized");
+
+	// 3. Initialize AgentTypeRegistry with configured agent types
+	const agentTypeRegistry = AgentTypeRegistry.getInstance();
+	agentTypeRegistry.initialize(
+		mutsumiConfig.agentTypes,
</code_context>
<issue_to_address>
**issue (bug_risk):** AgentTypeSystem reload can leave registries in an unusable state if initialization throws.

Because both registries now clear internal state before validating the new config, any exception in `loadMutsumiConfig()` or either `initialize()` (e.g. malformed `mutsumi.agentConfig`) leaves them with `ready = false` and empty data, breaking subsequent agent operations after a bad config change. Consider validating against a cloned copy of the state, then only swapping the internal maps/flags once validation fully succeeds; on failure, retain the previous configuration and surface the error instead of partially resetting the registries.
</issue_to_address>

### Comment 2
<location path="src/registry/toolSetRegistry.ts" line_range="69-71" />
<code_context>
 	 * @throws {Error} If a tool set references a non-existent tool
 	 */
 	initialize(config: ToolSetsConfig): void {
-		if (this.initialized) {
-			return;
-		}
-
-		// Clear existing tool sets
+		// Clear existing tool sets so a reload fully replaces prior state
 		this.toolSets.clear();

 		// Check if RAG is enabled (embedding endpoint configured)
</code_context>
<issue_to_address>
**issue (bug_risk):** ToolSetRegistry.initialize clears state before validation, which exacerbates reload failure risk.

With the new reload behavior, `initialize()` now clears `this.toolSets` before validation and only later sets `this.ready = true`. If any validation fails (missing tools, RAG checks, or future logic), the registry is left with an empty map and `ready` may never be set, breaking callers like `getToolSet` / `getCombinedToolSet` after an invalid config change.

Consider instead constructing and validating a new `Map<string, string[]>` locally, then assigning it to `this.toolSets` and setting `this.ready = true` only after validation fully succeeds. This preserves the previous, valid tool sets when a reload fails.
</issue_to_address>

### Comment 3
<location path="src/registry/agentTypeRegistry.ts" line_range="51-53" />
<code_context>
 	 * @throws {Error} If validation fails
 	 */
 	initialize(config: AgentTypeConfigMap, toolSetNames: string[]): void {
-		if (this.initialized) {
-			return;
-		}
-
-		// Clear existing types
+		// Clear existing types so a reload fully replaces prior state
 		this.agentTypes.clear();
 		this.toolSetNames = new Set(toolSetNames);

</code_context>
<issue_to_address>
**issue (bug_risk):** AgentTypeRegistry.initialize now fully clears types before validation, similar reload robustness concern.

Because `initialize()` clears `agentTypes` and resets `toolSetNames` before validation, any validation failure (e.g. unknown child types or tool set references) leaves the registry empty and `ready = false`, breaking consumers like `getEntryAgentTypes` and `getAgentType`. Consider validating into temporary `Map`/`Set` instances and only swapping them in and setting `ready = true` after validation succeeds, so the last-known-good configuration is preserved when `mutsumi.agentConfig` is invalid.
</issue_to_address>

### Comment 4
<location path="src/notebook/commands/modeDisplay.ts" line_range="1-3" />
<code_context>
 import { normalizeReasoningEffort } from './agent/types';
+import { t } from './i18n';

 /**
  * Controls the execution of agent notebooks.
</code_context>
<issue_to_address>
**nitpick:** Mode display command file header still references selectModel, which can confuse maintenance.

Please update the file-level JSDoc (description and `@module` tag) to reflect `mutsumi.displayMode` / `modeDisplay` so they align with the current command implementation and avoid confusion for future readers and tooling that uses these annotations.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/extension.ts
Comment on lines +64 to +73
function initializeAgentTypeSystem(): void {
// 1. Load Mutsumi configuration (merged with built-in defaults + validated)
const mutsumiConfig = loadMutsumiConfig();
debugLogger.log("[Extension] Mutsumi config loaded successfully");

// 2. Initialize ToolSetRegistry with configured tool sets
const toolSetRegistry = ToolSetRegistry.getInstance();
toolSetRegistry.initialize(mutsumiConfig.toolSets);
debugLogger.log("[Extension] ToolSetRegistry initialized");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): AgentTypeSystem 的重新加载在初始化抛出异常时,可能会让多个注册表处于不可用状态。

由于这两个注册表现在会在验证新配置之前先清空内部状态,如果 loadMutsumiConfig() 或任一 initialize()(例如配置中的 mutsumi.agentConfig 格式错误)抛出异常,它们就会被置为 ready = false 且数据为空,在一次错误的配置变更之后会导致后续的 agent 操作无法正常工作。建议针对现有状态的克隆副本进行验证,并仅在验证完全成功后再替换内部的 map / 标志位;验证失败时保留之前的配置,并将错误显式暴露出来,而不是只把注册表部分重置到一个不可用的状态。

Original comment in English

issue (bug_risk): AgentTypeSystem reload can leave registries in an unusable state if initialization throws.

Because both registries now clear internal state before validating the new config, any exception in loadMutsumiConfig() or either initialize() (e.g. malformed mutsumi.agentConfig) leaves them with ready = false and empty data, breaking subsequent agent operations after a bad config change. Consider validating against a cloned copy of the state, then only swapping the internal maps/flags once validation fully succeeds; on failure, retain the previous configuration and surface the error instead of partially resetting the registries.

Comment on lines 69 to 71
initialize(config: ToolSetsConfig): void {
if (this.initialized) {
return;
}

// Clear existing tool sets
// Clear existing tool sets so a reload fully replaces prior state
this.toolSets.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): ToolSetRegistry.initialize 在验证之前清空状态,这会加剧重新加载失败时的风险。

在新的重新加载行为下,initialize() 现在会在验证之前清空 this.toolSets,并且要到后面才设置 this.ready = true。如果验证中的任何一步失败(缺少工具、RAG 检查或未来的其他逻辑),注册表会被留在一个空的 map 中,而且 ready 可能永远不会被设置,在一次无效配置变更后会使像 getToolSet / getCombinedToolSet 这样的调用方出现问题。

建议改为先在本地构造并验证一个新的 Map<string, string[]>,只在验证完全成功后,再把它赋值给 this.toolSets 并设置 this.ready = true。这样可以在重新加载失败时保留之前有效的工具集合。

Original comment in English

issue (bug_risk): ToolSetRegistry.initialize clears state before validation, which exacerbates reload failure risk.

With the new reload behavior, initialize() now clears this.toolSets before validation and only later sets this.ready = true. If any validation fails (missing tools, RAG checks, or future logic), the registry is left with an empty map and ready may never be set, breaking callers like getToolSet / getCombinedToolSet after an invalid config change.

Consider instead constructing and validating a new Map<string, string[]> locally, then assigning it to this.toolSets and setting this.ready = true only after validation fully succeeds. This preserves the previous, valid tool sets when a reload fails.

Comment on lines 51 to 53
initialize(config: AgentTypeConfigMap, toolSetNames: string[]): void {
if (this.initialized) {
return;
}

// Clear existing types
// Clear existing types so a reload fully replaces prior state
this.agentTypes.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): AgentTypeRegistry.initialize 在验证之前就完全清空已有类型,在重新加载健壮性方面存在类似的问题。

由于 initialize() 会在验证之前清空 agentTypes,并重置 toolSetNames,任何验证失败(例如未知的子类型或工具集引用)都会让注册表变为空且 ready = false,从而影响 getEntryAgentTypesgetAgentType 等使用方。建议将验证过程放在临时的 Map / Set 实例中进行,仅在验证成功之后再替换内部数据结构并设置 ready = true,这样在 mutsumi.agentConfig 无效时能够保留最近一次的有效配置。

Original comment in English

issue (bug_risk): AgentTypeRegistry.initialize now fully clears types before validation, similar reload robustness concern.

Because initialize() clears agentTypes and resets toolSetNames before validation, any validation failure (e.g. unknown child types or tool set references) leaves the registry empty and ready = false, breaking consumers like getEntryAgentTypes and getAgentType. Consider validating into temporary Map/Set instances and only swapping them in and setting ready = true after validation succeeds, so the last-known-good configuration is preserved when mutsumi.agentConfig is invalid.

Comment on lines +1 to +3
/**
* @fileoverview Model selection command for Mutsumi notebook.
* @module notebook/commands/selectModel

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick: 模式显示命令文件的头部注释仍然引用了 selectModel,可能会给后续维护带来困惑。

请更新文件级的 JSDoc(描述和 @module 标签),使其反映 mutsumi.displayMode / modeDisplay,这样它们就能与当前命令实现保持一致,也能避免给未来的读者以及依赖这些注释的工具造成混淆。

Original comment in English

nitpick: Mode display command file header still references selectModel, which can confuse maintenance.

Please update the file-level JSDoc (description and @module tag) to reflect mutsumi.displayMode / modeDisplay so they align with the current command implementation and avoid confusion for future readers and tooling that uses these annotations.

@emikeliu

emikeliu commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

采用更好的方式实现。

@emikeliu emikeliu closed this Aug 2, 2026
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