Skip to content

[Fix] normalize agent skill lookup and tool filtering#832

Merged
dingyi222666 merged 1 commit intov1-devfrom
fix/agent-system
Apr 16, 2026
Merged

[Fix] normalize agent skill lookup and tool filtering#832
dingyi222666 merged 1 commit intov1-devfrom
fix/agent-system

Conversation

@dingyi222666
Copy link
Copy Markdown
Member

description: |-

This pr fixes extension-agent skill materialization, case-insensitive skill and sub-agent resolution, and delegated tool filtering so agent reloads and handoffs stay consistent.

New Features

None.

Bug fixes

  • reset the remote skill materialization directory before rewriting skill resources so stale files do not leak across reloads
  • make skill name matching case-insensitive in permission checks, activation, rendering, and active-skill lookups
  • make sub-agent lookup fall back to case-insensitive name matching when the exact name differs only by casing
  • stop relying on a prebuilt tool mask for sub-agent tool exposure and instead filter tools through the current permission rules
  • clear cached materialized skills when the skill catalog is disposed or reloaded so later runs do not reuse stale state

Other Changes

  • remove the automatic disabled-skill config insertion during skill import
  • normalize visible skill indexing to lowercase for consistent lookups across the agent services
  • keep fallback sub-agent context compatible by using the incoming tool mask when present and a permissive default otherwise

Reset remote skill materialization state between reloads and make skill and sub-agent matching case-insensitive. This also aligns sub-agent tool exposure with permission checks so imported skills and delegated tools stay consistent.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

总体信息

Walkthrough

该PR围绕技能匹配、权限管理和远程技能物化进行优化。具体包括:引入技能物化器清理机制、实现远程技能目录重置逻辑、移除技能导入时的自动映射、将技能名称匹配改为不区分大小写,以及调整子代理工具掩码的权限处理流程。

Changes

Cohort / File(s) Summary
Remote Skill Materialization
packages/extension-agent/src/computer/materialize.ts
新增 SkillMaterializer.clear() 方法重置物化状态;引入 resetRemoteSkillDir() 函数在物化前远程清理目录,包括递归移除现有目录或强制移除非目录路径。
Skill Import Simplification
packages/extension-agent/src/service/index.ts
移除 ChatLunaAgentService.importSkills() 中遍历导入技能名称并插入 skills.items 映射的代码;简化配置持久化逻辑。
Case-Insensitive Permission Matching
packages/extension-agent/src/service/permissions.ts
新增 matchRuleIgnoreCase() 辅助函数,将技能名称过滤和技能启用决策改为不区分大小写的匹配;工具和MCP检查保持原有区分大小写逻辑。
Skill Visibility & Lifecycle
packages/extension-agent/src/service/skills.ts
_visibleByName 映射改为小写键存储实现不区分大小写查询;强化技能子代理可用性检查使用不区分大小写比较;在 stop()reload() 方法中新增物化器清理逻辑。
Sub-agent Tool Authorization
packages/extension-agent/src/service/sub_agent.ts, packages/extension-agent/src/sub-agent/run.ts
移除子代理创建时的工具掩码计算;改为通过权限检查动态过滤工具;从 CreateSubAgentOptions 接口移除 mask 属性;调整工具选择为权限驱动的列表过滤方式。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Poem

🐰 技能匹配不分大小,远程目录焕然一新,
权限检查更显通透,工具筛选更加灵活,
物化清理保持整洁,代理协作更添顺畅~

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确地反映了该拉取请求的主要目的——规范化代理技能查找和工具过滤。
Description check ✅ Passed 描述详细说明了修复内容,包括技能物理化、不区分大小写的解析和工具过滤的改进。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/agent-system

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 and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces case-insensitive matching for skills and sub-agents, refactors sub-agent tool management to use permission checks instead of explicit masks, and adds a mechanism to reset remote skill directories. A review comment suggests simplifying the shell command for directory cleanup by removing redundant existence checks, as rm -rf is idempotent.

Comment thread packages/extension-agent/src/computer/materialize.ts
Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/extension-agent/src/service/skills.ts (1)

123-130: ⚠️ Potential issue | 🟠 Major

把物化缓存清理提前到 reload() 开头。

现在 materializer.clear() 只会在 scanSkills() / buildSkillCatalog() 成功后执行。只要 reload 因坏 skill 或 I/O 错误中途抛错,旧的远端物化映射就会继续保留,后续仍可能复用陈旧状态,这和本次修复目标相反。

💡 建议修改
 async reload() {
+    this.ctx.chatluna_agent?.computer.materializer.clear()
     await syncBundledSkills(this.ctx)
     const local = await scanSkills(this.ctx, this.config)
     const scanned = local
     this._skills = new Map(scanned.map((s) => [s.id, s]))
     this._catalog = buildSkillCatalog(scanned, this.config.skills.items)
-    this.ctx.chatluna_agent?.computer.materializer.clear()
     this._visibleByName = new Map(
         this._catalog
             .filter((s) => s.visible)
             .map((s) => [s.name.toLowerCase(), this._skills.get(s.id)!])
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/extension-agent/src/service/skills.ts` around lines 123 - 130, The
materializer.clear() call should happen at the start of reload() so cached
remote materializations are cleared even if
syncBundledSkills/scanSkills/buildSkillCatalog fail; move the
this.ctx.chatluna_agent?.computer.materializer.clear() invocation to the top of
reload() (before awaiting syncBundledSkills/scanSkills) and keep the existing
optional chaining to avoid null deref; ensure reload() still proceeds to call
syncBundledSkills, scanSkills, buildSkillCatalog and then sets
this._skills/_catalog as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/extension-agent/src/service/skills.ts`:
- Around line 123-130: The materializer.clear() call should happen at the start
of reload() so cached remote materializations are cleared even if
syncBundledSkills/scanSkills/buildSkillCatalog fail; move the
this.ctx.chatluna_agent?.computer.materializer.clear() invocation to the top of
reload() (before awaiting syncBundledSkills/scanSkills) and keep the existing
optional chaining to avoid null deref; ensure reload() still proceeds to call
syncBundledSkills, scanSkills, buildSkillCatalog and then sets
this._skills/_catalog as before.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9697354d-fa01-406d-b51d-f6e8b501f204

📥 Commits

Reviewing files that changed from the base of the PR and between 3303710 and 14c699c.

📒 Files selected for processing (6)
  • packages/extension-agent/src/computer/materialize.ts
  • packages/extension-agent/src/service/index.ts
  • packages/extension-agent/src/service/permissions.ts
  • packages/extension-agent/src/service/skills.ts
  • packages/extension-agent/src/service/sub_agent.ts
  • packages/extension-agent/src/sub-agent/run.ts

@dingyi222666 dingyi222666 merged commit 2fbe1fc into v1-dev Apr 16, 2026
2 of 5 checks passed
@dingyi222666 dingyi222666 deleted the fix/agent-system branch April 16, 2026 12:09
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