Skip to content

feat(desktop): SkillHub 支持导入本地 zip/SKILL.md - #1232

Merged
MagicLizi merged 3 commits into
makecindy:mainfrom
codeingforcoffee:feat/skillhub-import-local-skill
Jul 31, 2026
Merged

feat(desktop): SkillHub 支持导入本地 zip/SKILL.md#1232
MagicLizi merged 3 commits into
makecindy:mainfrom
codeingforcoffee:feat/skillhub-import-local-skill

Conversation

@codeingforcoffee

@codeingforcoffee codeingforcoffee commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

目的在于自己本地有一些skill想调试,或者不想上传到skillhub,只想本地使用的技能,希望也能导入到cindy使用,开发过程中发现卸载需要登陆cindy账号,去掉了来自本地上传路径的门禁,允许自己上传,卸载,不受云端账号管控。

record

摘要

SkillHub「技能」页支持从本地导入 zip 或 SKILL.md:校验 frontmatter(name + description)后,经安装位置选择器落盘,并在 registry 记为 origin: 'imported'(「本地」徽标、可离线卸载、可发布)。不上传云端。市场安装技能的卸载鉴权保持不变(仍要求云端账号)。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:
  • 本 PR 包含:
    • Main:inspectLocalSkill / importLocalSkill、IPC(skillhub:inspect-local / skillhub:import-local)、registry origin='imported'、本地导入与蒸馏产物允许离线卸载
    • Renderer:技能页标题右侧「导入技能」、复用并泛化 InstallTargetPicker、详情按钮矩阵与来源徽标
    • 四语 i18n、help-knowledge、相关单测
  • 明确不包含:市场技能卸载鉴权放宽;云端上传/同步导入内容
  • 用户可见变化:技能页可导入本地技能;导入项显示「本地」;未登录可卸载本地导入项
  • 是否存在 breaking change:无

UI 变化

image image image image
  • 引用的设计规范:
    • DESIGN.md §2 / §10:颜色走语义 token(按钮与页面沿用既有 SkillHub / InstallTargetPicker themed 样式),同时实现 Light / Dark
    • DESIGN.md §3 Buttons:导入入口复用现有次级/页面 header 按钮样式,不新增硬编码色
    • 入口位置:技能页标题右侧(非顶栏 headerActions)

怎么验证的

自动验证

PATH=.../node/v22.19.0/bin:$PATH pnpm test:unit
结果:全部 PASS(含 apps/desktop unit)

PATH=.../node/v22.19.0/bin:$PATH pnpm --filter desktop run typecheck
结果:通过

pnpm --filter desktop exec vitest run \
  src/main/skillhub/__tests__/importLocalSkill.pure.test.ts \
  src/main/skillhub/__tests__/installService.test.ts \
  src/renderer/features/skillhub/lib/__tests__/detailButtons.test.ts \
  src/renderer/features/skillhub/lib/__tests__/skillSource.test.ts
结果:4 files / 85 tests passed

pnpm check:i18n-glossary
结果:通过

手工验证

未做 Desktop 实机导入流程目检(Light / Dark 均未实机验证);逻辑与按钮矩阵由单测覆盖。

未执行的验证

  • Desktop 实机:选 zip / SKILL.md 导入、校验失败提示、冲突覆盖、本地卸载(未登录)、市场卸载仍要云账号
  • 双模式实机目检

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:本地导入会写入用户选择的 skills 目录并更新 SkillHub registry;imported/learned 卸载不再要求云端登录;市场 installed 卸载鉴权不变
  • 回滚 / 降级方式:回退本 PR;已导入文件与 registry 条目需用户侧手动清理(无自动 migration)

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO
  • UI 改动已在「UI 变化」注明引用的设计规范章节(不涉及 UI 则跳过)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

Made with Cursor

技能页标题旁新增「导入技能」:校验 frontmatter 后经安装位置选择器落盘,
registry 记 origin=imported(本地徽标、可离线卸载、可发布);市场安装技能的卸载鉴权不变。

Signed-off-by: codeingforcoffee <garryxia666@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@codeingforcoffee
codeingforcoffee requested a review from a team as a code owner July 31, 2026 14:20
Copilot AI review requested due to automatic review settings July 31, 2026 14:20
@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为桌面端 SkillHub 增加本地技能导入能力。

  • 支持选择、检查并导入 ZIP 或独立 SKILL.md,校验 frontmatter 后写入所选技能目录。
  • 为本地文件选择增加绑定渲染进程的一次性授权,并将导入结果登记为 origin: imported
  • 调整详情页操作、来源徽标和卸载鉴权,使本地导入与学习产物可离线卸载。
  • 补充安装位置选择、四语文案、帮助文档及相关单元测试。

Confidence Score: 4/5

此 PR 暂不适合合并,因为大 ZIP 条目的导入仍可能耗尽 Electron 主进程内存。

解压逻辑会先在 chunks 中保留单个条目的全部数据,再由 Buffer.concat 分配并复制同等大小的 Buffer;由于首个条目最多可使用完整的 500 MB 解压预算,这个修复仍保留了原线程所关注的主进程内存崩溃路径。

Files Needing Attention: apps/desktop/src/main/skillhub/importLocalSkill.ts

Important Files Changed

Filename Overview
apps/desktop/src/main/skillhub/importLocalSkill.ts 实现本地技能检查、解压、暂存替换及 registry 登记,但大条目解压仍会在主进程产生接近两倍的内存峰值。
apps/desktop/src/main/skillhub/importLocalSkill.pure.ts 提供导入源分类、元数据校验、ZIP 包根识别、安装路径约束及声明大小预算辅助逻辑。
apps/desktop/src/main/skillhub/registerIpc.ts 增加受信任渲染进程校验、主进程文件选择及与发送方绑定的一次性导入授权。
apps/desktop/src/main/skillhub/installService.ts 根据 registry 来源区分卸载鉴权,本地导入及学习产物可在无云端账号时卸载。
apps/desktop/src/renderer/features/skillhub/SkillhubHomeView.tsx 增加本地技能选择、检查、目标位置选择、冲突确认和导入结果处理流程。
apps/desktop/src/renderer/features/skillhub/components/InstallTargetPicker.tsx 泛化安装位置选择器以同时支持市场安装和本地导入。

Comments Outside Diff (1)

  1. apps/desktop/src/main/skillhub/importLocalSkill.ts, line 1492-1516 (link)

    P1 解压仍会双倍占用内存

    当导入包含单个数百 MB 解压后条目的 ZIP 时,readZipEntryLimited 会先把全部数据保存在 chunks 中,再由 Buffer.concat 分配并复制一份同等大小的连续 Buffer;首个条目最多可使用完整的 500 MB 额度,因此 Electron 主进程仍会因接近两倍的峰值内存而耗尽内存并崩溃。

    Context Used: 使用和PR描述相同的语言进行评论 (source)

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/desktop/src/main/skillhub/importLocalSkill.ts
    Line: 1492-1516
    
    Comment:
    **解压仍会双倍占用内存**
    
    当导入包含单个数百 MB 解压后条目的 ZIP 时,`readZipEntryLimited` 会先把全部数据保存在 `chunks` 中,再由 `Buffer.concat` 分配并复制一份同等大小的连续 Buffer;首个条目最多可使用完整的 500 MB 额度,因此 Electron 主进程仍会因接近两倍的峰值内存而耗尽内存并崩溃。
    
    **Context Used:** 使用和PR描述相同的语言进行评论 ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/main/skillhub/importLocalSkill.ts:1492-1516
**解压仍会双倍占用内存**

当导入包含单个数百 MB 解压后条目的 ZIP 时,`readZipEntryLimited` 会先把全部数据保存在 `chunks` 中,再由 `Buffer.concat` 分配并复制一份同等大小的连续 Buffer;首个条目最多可使用完整的 500 MB 额度,因此 Electron 主进程仍会因接近两倍的峰值内存而耗尽内存并崩溃。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (3): Last reviewed commit: "fix(desktop): 本地技能导入改为 main 侧文件授权" | Re-trigger Greptile

Comment thread apps/desktop/src/main/skillhub/importLocalSkill.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa39103362

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/desktop/src/main/skillhub/importLocalSkill.ts Outdated

Copilot AI 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.

🟡 Not ready to approve

main 侧导入逻辑目前未强制 installPath 为绝对路径(相对路径可能导致非预期落盘位置),需要先补齐防御性校验后再合入。

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

本 PR 为 Desktop 的 SkillHub「技能」页新增**从本地导入技能(zip / SKILL.md)**的能力:通过 IPC 在 main 侧进行只读 inspect 与落盘导入,并在 registry 中标记 origin: 'imported',同时在 renderer 侧复用/泛化安装位置选择器与详情页按钮矩阵逻辑;并调整卸载鉴权以允许本地导入/learn 产物离线卸载。

Changes:

  • 新增 main 侧本地导入实现(zip 解压/校验 frontmatter/落盘/写 registry),并补齐 IPC + preload + 类型声明。
  • renderer 侧在 SkillHub 首页增加「导入技能」入口,复用并泛化 InstallTargetPicker,并扩展来源/按钮状态派生以支持 origin='imported'
  • 扩展卸载逻辑与测试覆盖(origin='imported' 可离线卸载;imported/learned 不走市场更新路径),并补充 help-knowledge 文档与 i18n。
File summaries
File Description
apps/desktop/src/renderer/vite-env.d.ts 扩展 renderer 侧 ElectronAPI 类型:inspect/import 本地导入 + registry origin 新枚举值
apps/desktop/src/renderer/i18n/locales/zh-CN/common.json 新增导入入口/选择器/提示文案(zh-CN)
apps/desktop/src/renderer/i18n/locales/ko/common.json 新增导入入口/选择器/提示文案(ko)
apps/desktop/src/renderer/i18n/locales/ja/common.json 新增导入入口/选择器/提示文案(ja)
apps/desktop/src/renderer/i18n/locales/en/common.json 新增导入入口/选择器/提示文案(en)
apps/desktop/src/renderer/features/skillhub/SkillhubHomeView.tsx 技能页新增「导入技能」入口:选文件→inspect→安装位置选择器→import
apps/desktop/src/renderer/features/skillhub/SkillhubFeatureLayout.tsx reconcile 逻辑允许 origin='imported',避免被判为“需要回填/修正”
apps/desktop/src/renderer/features/skillhub/SkillhubDetailView.tsx 更新详情页卸载按钮注释语义(installed/imported)
apps/desktop/src/renderer/features/skillhub/lib/skillSource.ts origin='imported' 视为本地来源(local)
apps/desktop/src/renderer/features/skillhub/lib/detailButtons.ts 按钮派生逻辑支持 imported:可卸载、禁止市场更新、必要时引导发布新版本
apps/desktop/src/renderer/features/skillhub/lib/tests/skillSource.test.ts 覆盖 imported → local 的来源派生测试
apps/desktop/src/renderer/features/skillhub/lib/tests/detailButtons.test.ts 覆盖 imported 在按钮矩阵/更新/卸载策略上的关键分支
apps/desktop/src/renderer/features/skillhub/components/InstallTargetPicker.tsx 泛化安装位置选择器:支持 market clone 与本地导入共用(runAction + i18n key 可配置)
apps/desktop/src/preload/preload.ts 暴露 skillhub:inspect-local / skillhub:import-local 到 renderer
apps/desktop/src/main/skillhub/registry/types.ts main 侧 registry 类型扩展 origin='imported'
apps/desktop/src/main/skillhub/registerIpc.ts 新增 IPC handler:inspect-local / import-local,并在导入后刷新缓存
apps/desktop/src/main/skillhub/installService.ts 卸载鉴权调整:imported/learned 允许离线卸载;路径匹配更健壮
apps/desktop/src/main/skillhub/installLock.ts 安装锁 owner 扩展:新增 local-import
apps/desktop/src/main/skillhub/importLocalSkill.ts 新增本地导入实现:校验、解压/写入、registry 记录 origin=imported、备份与回滚
apps/desktop/src/main/skillhub/importLocalSkill.pure.ts 新增纯函数辅助:frontmatter/命名校验、zip root 定位、路径分类等
apps/desktop/src/main/skillhub/tests/installService.test.ts 更新/新增卸载鉴权相关单测(market vs imported)
apps/desktop/src/main/skillhub/tests/importLocalSkill.pure.test.ts 为纯函数辅助补齐单测覆盖
apps/desktop/help-knowledge/skills.md 补充「本地导入技能」用户文档说明
Review details
  • Files reviewed: 22/23 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread apps/desktop/help-knowledge/skills.md Outdated
Comment thread apps/desktop/src/main/skillhub/importLocalSkill.ts Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

⏸️ 白名单确认门已拦住此 PR。

触发: product(feat 类型 + UI 路径) + arch(核心路径)

此 PR 新增 SkillHub 本地导入功能,需要 roster 成员确认产品方向与架构设计。

放行方式: 直接在 PR 上 Approve;需要修改就 Request Changes,改完后重新 Approve 即放行。

讨论 issue:#1234

按 PR review:解压前校验声明大小并以流式读取限流,避免 zip bomb;
installPath 要求绝对路径且落在 .agents/.claude skills 根下;统一 SkillHub 拼写。

Signed-off-by: codeingforcoffee <garryxia666@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings July 31, 2026 14:38

Copilot AI 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.

🟡 Human review recommended

变更涉及本地文件解压落盘与卸载鉴权边界调整,尽管已有防御与单测覆盖,仍建议由人工对安全与数据路径风险做最终确认。

Review details
  • Files reviewed: 23/24 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f54d01b4d2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/desktop/src/main/skillhub/registerIpc.ts Outdated
@MagicLizi

Copy link
Copy Markdown
Contributor

@codeingforcoffee 👋 这个 PR 还有 4 条 review conversation 没 resolve(apps/desktop/src/main/skillhub/importLocalSkill.ts / apps/desktop/help-knowledge/skills.md / apps/desktop/src/main/skillhub/registerIpc.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

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

在「待确认 PR」面板确认放行。

@MagicLizi

Copy link
Copy Markdown
Contributor

@codeingforcoffee 👋 这个 PR 还有 2 条 review conversation 没 resolve(apps/desktop/src/main/skillhub/importLocalSkill.ts / apps/desktop/src/main/skillhub/registerIpc.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

避免 renderer 传入任意路径触发读取/解压,改为在 main 内选文件并签发短期票据后再导入。

Signed-off-by: codeingforcoffee <garryxia666@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@MagicLizi

Copy link
Copy Markdown
Contributor

白名单确认门已放行(product / arch,由 MagicLizi 确认),PR 恢复正常推进。

Copilot AI review requested due to automatic review settings July 31, 2026 16:14

Copilot AI 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.

🟡 Human review recommended

该 PR 引入 zip 解压落盘与卸载鉴权分支调整,涉及文件系统与安全边界变更,建议人工做一次端到端导入/卸载路径审阅与确认后再合并。

Review details
  • Files reviewed: 24/25 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1bdcb34ce

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/desktop/src/renderer/features/skillhub/SkillhubHomeView.tsx

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

审查通过,零 P0/P1。zip 导入安全防护完善:safeJoin 防 zip slip、声明 size 预检 + 流式字节上限防 zip bomb、grant token 绑定发送方身份。

@MagicLizi
MagicLizi merged commit 1e64c08 into makecindy:main Jul 31, 2026
5 checks passed
@MagicLizi

Copy link
Copy Markdown
Contributor

grant token 绑 webContents + 单次消费 + TTL 的组合拳把渲染进程的文件注入路径堵得很死,zip 解压那边 safeJoin 也没给遍历留缝。做得漂亮。

@codeingforcoffee
codeingforcoffee deleted the feat/skillhub-import-local-skill branch July 31, 2026 17:15
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.

3 participants