## 背景 对齐 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 ## 关联 - enhance-0819.md item 9 - 前序: PR #73 (WS1 hooks), PR #74 (WS2 stacked slash-skill), PR #76 (item 7 memcap) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Activity
feat(div-anthropic): skill body-defer 懒加载 (issue #77, CC 2.1.234) (#78)