Skip to content

feat(context): 接入 session 级 skills 注入并修正 runtime 降级语义#305

Merged
phantom5099 merged 4 commits into
1024XEngineer:mainfrom
wynxing:main
Apr 15, 2026
Merged

feat(context): 接入 session 级 skills 注入并修正 runtime 降级语义#305
phantom5099 merged 4 commits into
1024XEngineer:mainfrom
wynxing:main

Conversation

@wynxing

@wynxing wynxing commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

背景

关联 issue: #258

当前仓库里 skills 已有基础 loader/registry 能力,但还没有真正进入主链路。
本次改动将 session + runtime + context + bootstrap 串起来,让 session 级 skill 激活、运行时解析以及 prompt 注入真正生效,并补齐对应测试。

主要修改

1. Session

  • 增加 ActivatedSkills []SkillActivation 持久化字段
  • 新增 ActivateSkillDeactivateSkillActiveSkillIDs
  • 保存和加载时统一做 skill id 规范化、去重、稳定排序
  • 补齐激活/取消激活、幂等、持久化兼容相关测试

2. Runtime

  • 为 runtime 注入 skills.Registry
  • 新增 ActivateSessionSkillDeactivateSessionSkillListSessionSkills
  • prepareTurnSnapshot() 在构建上下文前解析当前 session 激活的 skills,并传入 context builder
  • 新增 runtime 事件:
    • skill_activated
    • skill_deactivated
    • skill_missing

3. Context

  • BuildInput 增加 ActiveSkills []skills.Skill
  • 新增统一的 Skills prompt section
  • 对 active skills 做稳定去重和排序
  • 固定裁剪:
    • references 最多 3 条
    • tool hints 最多 3 条
    • examples 最多 2 条
  • compact 前后都会重新注入 skills,不回写消息历史

4. Bootstrap

  • 启动时从 ~/.neocode/skills 初始化本地 skills registry
  • skills root 缺失时按空 catalog 处理,不影响应用启动
  • 初次 refresh 失败时保留 registry 实例,避免 runtime 退化为 registry unavailable

5. 降级与错误语义修正

  • 仅对真正的 skills.ErrSkillNotFoundskill_missing 软降级
  • 对上下文取消、权限失败、refresh 失败、解析失败等基础设施错误直接向上返回
  • 避免把“skill 不存在”和“registry/load 故障”混淆

验证

已通过:

  • go test ./internal/skills
  • go test ./internal/runtime
  • go test ./internal/app
  • go test ./internal/session
  • go test ./internal/context
  • go test ./internal/tui/...

影响

  • skills 现在已经进入主链路,可被 session 激活并注入 runtime/context
  • 缺失 skills root 不再导致整个 skills 子系统不可用
  • registry/load 故障不再被误报为 skill_missing

wynxing and others added 4 commits April 15, 2026 10:03
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: Yumiue <188874804+Yumiue@users.noreply.github.com>
test: add coverage for skill session/runtime/context branches
@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.10695% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/runtime/skills.go 82.05% 12 Missing and 9 partials ⚠️
internal/context/source_skills.go 90.90% 5 Missing and 5 partials ⚠️
internal/session/skill_activation.go 91.66% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@fennoai fennoai 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.

整体实现和测试覆盖都比较完整,未看到阻塞合入的问题。

有一个非阻塞的性能优化建议如下。


// renderActiveSkillsSection 负责去重、排序并渲染激活 skills 的结构化提示文本。
func renderActiveSkillsSection(activeSkills []skills.Skill) string {
normalized := normalizeActiveSkills(activeSkills)

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.

renderActiveSkillsSection 会再次做去重+排序;而上游 Session.ActiveSkillIDs() 已经返回了规范化且稳定排序的 ID。当前实现是安全的,但每轮构建上下文都会额外产生一次 O(n log n) 和 map/slice 分配。若后续会引入较多激活 skills,可考虑在 runtime 侧保证有序唯一后,这里只做轻量遍历渲染。

@phantom5099 phantom5099 merged commit f60a3a6 into 1024XEngineer:main Apr 15, 2026
2 checks passed
@Cai-Tang-www

Copy link
Copy Markdown
Collaborator

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.

4 participants