fix(agent): merge config defaults via deepAssign on agentcli sync#868
Conversation
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
走查总览该 PR 调整代理配置的读取与同步流程:在 变更内容配置合并与重加载参数调整
估算代码审查工作量🎯 2 (简单) | ⏱️ ~8 分钟 诗歌
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Code Review
This pull request introduces merging logic for computer and subAgent configurations and ensures a default trigger configuration is applied. It also refactors the agent reload call in the CLI sync utility. Feedback focuses on addressing a shallow merge issue in the subAgent.defaults configuration that could result in lost settings and suggests using Object.entries to simplify the builtin sub-agent merging logic.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/extension-agent/src/service/index.ts (1)
725-725: 💤 Low value指出
trigger和computer/subAgent在防御性赋值上的不一致。
createDefaultTriggerConfig()的签名和返回类型验证无误。但存在一个值得关注的不一致之处:在AgentConfig接口中,trigger、computer和subAgent都是必需属性(非可选),然而在_setConfig方法中,只有trigger获得了后备逻辑(cfg.trigger ?? createDefaultTriggerConfig()),而computer和subAgent则直接赋值(cfg.computer和cfg.subAgent)。若
readConfig的深度合并已确保trigger总是被定义,则这个后备逻辑可能多余;否则,为了保持一致性和防御性,应该对computer和subAgent也应用相同的保护策略,或将这些属性标记为可选。🤖 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 `@packages/extension-agent/src/service/index.ts` at line 725, The assignment in _setConfig is inconsistent: this.trigger.config uses a fallback (cfg.trigger ?? createDefaultTriggerConfig()) while cfg.computer and cfg.subAgent are assigned directly; update _setConfig to defendively apply the same fallback behavior for computer and subAgent (e.g., use cfg.computer ?? createDefaultComputerConfig() and cfg.subAgent ?? createDefaultSubAgentConfig() or equivalent defaults), or alternatively update the AgentConfig interface to mark computer and subAgent as optional; locate references to AgentConfig, _setConfig, this.trigger.config, cfg.trigger, cfg.computer, and cfg.subAgent to implement the chosen fix so the code is consistent and type-safe.
🤖 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.
Nitpick comments:
In `@packages/extension-agent/src/service/index.ts`:
- Line 725: The assignment in _setConfig is inconsistent: this.trigger.config
uses a fallback (cfg.trigger ?? createDefaultTriggerConfig()) while cfg.computer
and cfg.subAgent are assigned directly; update _setConfig to defendively apply
the same fallback behavior for computer and subAgent (e.g., use cfg.computer ??
createDefaultComputerConfig() and cfg.subAgent ?? createDefaultSubAgentConfig()
or equivalent defaults), or alternatively update the AgentConfig interface to
mark computer and subAgent as optional; locate references to AgentConfig,
_setConfig, this.trigger.config, cfg.trigger, cfg.computer, and cfg.subAgent to
implement the chosen fix so the code is consistent and type-safe.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c9fc96b6-9df1-46fa-b2f4-f410e4089bc1
📒 Files selected for processing (3)
packages/extension-agent/src/config/read.tspackages/extension-agent/src/service/index.tspackages/extension-agent/src/utils/agentcli_sync.ts
There was a problem hiding this comment.
Code Review
This pull request enhances the configuration handling by explicitly merging computer and subAgent settings with their defaults in readConfig, and ensures a default trigger configuration is applied during service updates. Additionally, the agent reload logic in the CLI sync utility was simplified. Review feedback indicates that the mcp section and subAgent.defaults also need more robust merging strategies to prevent partial user configurations from accidentally overwriting nested default values, such as MCP tools or sub-agent permission rules.
Route syncAgentcliConfig through agent.reload() so the partial config
written from agentcli passes through readConfig and gets merged with
defaults. readConfig now uses deepAssign for trigger/computer/subAgent
so partial saved sections (e.g. `computer: {}` or missing trigger) no
longer override nested defaults and crash isProviderEnabled / buildStatus.
0762863 to
87559b3
Compare
Summary
syncAgentcliConfignow callsagent.reload()without arguments, so the partial config written to disk passes throughreadConfigand gets merged with defaults instead of being assigned rawreadConfigusesdeepAssign(fromkoishi-plugin-chatluna/utils/object) to deep-mergetrigger,computer, andsubAgentagainst defaults, so partial saved sections (e.g.computer: {}or missingtrigger) no longer wipe out nested defaultsProblem
When the agentcli sandbox writes a partial
config.json(e.g. onlymcpchanges, with"computer": {}or missingtrigger), and the user runschatluna.agent sync:syncAgentcliConfigpreviously passed the raw JSON directly toagent.reload(next)reloadskippedreadConfigbecausecfgwas already provided_setConfigassigned the incomplete config —this.trigger.config = cfg.triggerbecameundefinedTypeError: Cannot read properties of undefined (reading 'providers')inisProviderEnabledcomputer.local.enabledinbuildStatuswhencomputer: {}The root cause is that the sync path bypassed
readConfigentirely. Routing it back throughreadConfig(and makingreadConfigitself deep-merge defaults forcomputer/subAgent, not justtrigger) fixes both the sync flow and any independent path that may have written a partial config to disk.Test plan
config.jsonwith only{ "mcp": { "mcpServers": {} } }(missing computer, trigger, subAgent details)chatluna.agent sync— should load without errors