Skip to content

feat(div-anthropic): 技能正文 body-defer 懒加载 (CC 2.1.234 对齐, item 9) #77

Closed

Description

@dahai80

背景

对齐 Claude Code 2.1.234 "技能按需文档加载" (item 9, enhance-0819.md Tier-1)。

现状审计

  • token 目标已达成: system prompt / skill-listing 已 frontmatter-only + 1% context budget cap (attachments.ts, SkillTool/prompt.ts)。bundled + MCP skill 已惰性。
  • 剩余 gap: directory/plugin skill 的 SKILL.md 正文在 registry build 时 eager fs.readFile 全文, 作为 markdownContent: string 常驻 Command 闭包 (loadSkillsDir.ts:303/:351)。loadSkillsDir.ts:97-99 注释 claim "only loaded on invocation" 但代码矛盾 — 过时注释。

方案

Registry build 时只保留 frontmatter + 文件路径 (不常驻 body 串)。getPromptForCommand 首次调用 ??= lazy fs.readFile 全文 + memoize (镜像 bundledSkills.ts:65-73 Promise-memo 模式)。接受 build+invoke 1 次重读换 RAM 不常驻 (skill invoke 低频)。

改动点

  • src/skills/loadSkillsDir.ts createSkillCommand: markdownContent → skillFilePath?: string + markdownContent?: string 双可选 (向后兼容 MCP/inline dead path, 优先 skillFilePath lazy)。getPromptForCommand 闭包 ??= lazy read。contentLength → markdownContent?.length ?? 0 (零 reader 无害)。修过时注释 :97-99。
  • src/utils/plugins/loadPluginCommands.ts createPluginCommand own closure: 4 file-backed 站点 lazy, 1 inline 站点保持 retain。
  • 测试: tests/utils/skillLazyLoad.test.ts — 首次 invoke 读盘, 二次命中 cache。

验证

  • typecheck 0, 444+ tests pass, build + build:dev:full pass

关联

Co-Authored-By: Claude Fable 5 [email protected]

Activity

  1. added a commit that references this issue on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions