Repository navigation
feat(div-anthropic): skill body-defer 懒加载 (closes #77, CC 2.1.234, item 9) - #78
Merged
Merged
Conversation
directory/plugin skill 的 SKILL.md 正文不再在 registry build 时 eager read 全文常驻 Command 闭包。createSkillCommand 签名改双可选 (markdownContent?: string + skillFilePath?: string), file-backed skill 传 skillFilePath, 首次 getPromptForCommand 时 ??= lazy read + Promise memo (镜像 bundledSkills.ts 模式, 并发 invoke 共享 in-flight read)。 MCP/inline (无文件) 仍走 markdownContent eager, 向后兼容。 - src/skills/loadSkillsDir.ts: 2 调用点 (skills-dir/legacy) 传 skillFilePath, contentLength=0 (零 reader, 无害), 修过时注释 - src/__tests__/skills/skillLazyLoad.test.ts: 6 单测 (contentLength=0, 首次 lazy/二次 memo 命中, baseDir+$ARGUMENTS 注入, description fallback, frontmatter-only token 估算, markdownContent eager 路径) - plugin loader (loadPluginCommands.ts) 不动: PluginMarkdownFile.content 必填 + 5 站点 retain, 半转换零 RAM 收益 (见 plan 执行期调整) 验证: typecheck 0, 6/6 新测 + 122/0 src/__tests__ 全测, build + build:dev:full pass, diff +29/-7 surgical (保留原 2-space/单引号风格) Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80
added a commit
that referenced
this pull request
Aug 20, 2026
追 CC 2.1.196→2.1.234 Tier-1 特性批量落地 (13 PR): 变更自 v0.4.22: - WS1 DirectoryAdded hook + Notification agent_* 类型 (#73) - WS2 堆叠 slash-skill 调用, 最多 5 前导 (#74) - LSP+filecache 内存泄漏 cap, 对齐 CC 2.1.208 (#76) - skill body-defer 懒加载, item 9 (#78) - SessionStart source "fork" 区分 fork 与 resume (#80) - P2.1 子代理护栏 — 并发/会话/深度三限 (#82) - P1.1 大输出 tool_result tail 预览 (#84) - P4.1 --ax-screen-reader 入口点对齐 — env 别名 + settings key (#86) - item 13 WebSearch per-session 搜索次数上限 (#88) - P4.2 §6 /doctor FUSION_* vs ANTHROPIC_* 环境变量冲突检测 (#90) - P4.2 #1+#3 /doctor MLX 网关连通 + 模型加载探测 (#92) - item 4 MCP 工具自动后台化 FUSION_MCP_AUTO_BACKGROUND_MS (#94) - item 22 审计日志凭证脱敏 (#96) - package.json: version 0.4.22 → 0.4.23 Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
落地 enhance-0819.md Tier-1 item 9 — 技能正文 body-defer 懒加载, 对齐 Claude Code 2.1.234 "skill 按需加载正文" 模式。Closes #77。
背景 (审计结论)
attachments.ts,SkillTool/prompt.ts); bundled + MCP skill 已惰性 (dynamic import / remote fetch)。SKILL.md正文在 registry build 时 eagerfs.readFile全文, 作为markdownContent: string常驻 Command 闭包。loadSkillsDir.ts:97-99注释 claim "only loaded on invocation" 但代码矛盾 — 过时注释。改动
src/skills/loadSkillsDir.ts(+29/-7 surgical, 保留原 2-space/单引号风格)createSkillCommand签名改双可选:markdownContent?: string+skillFilePath?: string(向后兼容, export 类型给 MCP dead-path 不破坏)。getPromptForCommand: file-backed skill (skillFilePath有值) 首次调用??=lazyfs.readFile全文 + Promise memo (镜像bundledSkills.ts:65-73模式, 并发 invoke 共享 in-flight read); MCP/inline 走markdownContenteager。loadSkillsFromSkillsDir/loadSkillsFromCommandsDir) 传skillFilePath, build 时markdownContent局部变量函数返回 GC 回收, body 不常驻。contentLength: markdownContent?.length ?? 0(全 repo 零 reader, 无害)。estimateSkillFrontmatterTokens过时注释 — frontmatter-only 估算对全部 skill 来源成立。src/__tests__/skills/skillLazyLoad.test.ts(新增, 6 单测)contentLength=0(body 不常驻闭包)baseDir前缀 +\$ARGUMENTS替换正确注入 promptfrontmatter.description时 fallback 取正文首行estimateSkillFrontmatterTokens不含 body (frontmatter-only)markdownContent(inline/MCP) 路径仍 eager, 不走文件 read不动:
src/utils/plugins/loadPluginCommands.tsPluginMarkdownFile.content必填 + 5 站点 retain, 半转换闭包 lazy re-read 而不删 retain = 零 RAM 收益 + 多一次废读。真省需改类型 + 5 站点 + inline 虚拟路径 guard, 成本高收益低 (见 plan 执行期调整)。本 PR 内存胜利集中在 loadSkillsDir.ts (真实大文档场景)。验证
bun run typecheck— 0 errorsbun test src/__tests__/skills/skillLazyLoad.test.ts— 6/6 passbun test src/__tests__/— 122 pass / 0 fail (不回归)bun run build+bun run build:dev:full— passbunx biome check src/__tests__/skills/skillLazyLoad.test.ts— cleansrc/skills/+src/__tests__/(explicit allowlist), loadSkillsDir.ts 既存 lint findings 未变取舍
Co-Authored-By: Claude Fable 5 [email protected]