Skip to content

feat(kit): add skill storage providers#367

Merged
SonyLeo merged 8 commits into
opentiny:developfrom
gene9831:codex/skill-storage-foundation
Jul 16, 2026
Merged

feat(kit): add skill storage providers#367
SonyLeo merged 8 commits into
opentiny:developfrom
gene9831:codex/skill-storage-foundation

Conversation

@gene9831

@gene9831 gene9831 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

PR 描述

新增 skill storage 层,将 storage 作为和 loader 平级的 SkillDefinition provider,支持持久化、恢复和从 loader source 导入 skill。

主要改动:

  • 新增 SkillStorage 接口,提供 add / get / has / delete / list / import
  • 新增 storage.import(),内部复用 loader 的 loadSkillWithDetails(),导入后写入 storage。
  • 新增 memory storage,适合内存态 skill 集合管理。
  • 新增 IndexedDB storage,面向浏览器端持久化,并支持 resource 懒加载读取。
  • 新增 fs storage,保持原生 skill 目录结构,支持从已有 skill 目录读取、导入和删除。
  • node 子入口补充 storage 导出。
  • 增加 memory / IndexedDB / fs storage 关键流程测试。
  • 增加 fake-indexeddb 作为 IndexedDB storage 测试依赖。

验证:

pnpm -F @opentiny/tiny-robot-kit test -- --run src/skills/test/memoryStorage.test.ts src/skills/test/indexedDBStorage.test.ts src/skills/test/fsStorage.test.ts
pnpm build

Summary by CodeRabbit

  • New Features
    • Added new skill storage implementations: in-memory, filesystem (with optional read-only mode), and browser IndexedDB, each with add/get/has/delete plus list summaries.
    • Expanded the public skills storage API with cancelable skill importing and new storage entrypoints/exports.
  • Bug Fixes
    • Improved skill resource persistence so stored resources load lazily and correctly handle overwrites without stale data.
  • Tests
    • Added Vitest coverage for memory, filesystem (atomic install/replace), and IndexedDB (lazy-loading, import, delete, overwrite, cancel behavior).
  • Chores
    • Updated test setup for IndexedDB simulation and narrowed ambient TypeScript types to Node.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@gene9831, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 7 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f2a1945-a3cd-4683-bf99-1e702017824d

📥 Commits

Reviewing files that changed from the base of the PR and between d5dd64f and e65d881.

📒 Files selected for processing (9)
  • packages/kit/src/skills/storage/fs.ts
  • packages/kit/src/skills/storage/index.ts
  • packages/kit/src/skills/storage/indexedDB.ts
  • packages/kit/src/skills/storage/memory.ts
  • packages/kit/src/skills/storage/node.ts
  • packages/kit/src/skills/storage/types.ts
  • packages/kit/src/skills/test/fsStorage.test.ts
  • packages/kit/src/skills/test/indexedDBStorage.test.ts
  • packages/kit/src/skills/test/memoryStorage.test.ts

Walkthrough

Adds a complete skills/storage subsystem with shared contracts, cancellable imports, memory, IndexedDB, and filesystem backends, platform exports, configuration, and Vitest coverage.

Changes

Skill Storage Subsystem

Layer / File(s) Summary
Storage contracts and import factory
packages/kit/src/skills/storage/types.ts, packages/kit/src/skills/storage/importSkill.ts
Defines storage, summary, import-result, and cancellable job types, then adapts skill loading into a SkillImporter.
In-memory storage backend
packages/kit/src/skills/storage/memory.ts, packages/kit/src/skills/test/memoryStorage.test.ts
Implements clone-isolated CRUD, sorted listing, import persistence, cancellation passthrough, and tests.
IndexedDB storage backend
packages/kit/src/skills/storage/indexedDB.ts, packages/kit/src/skills/test/indexedDBStorage.test.ts, packages/kit/package.json, packages/kit/tsconfig.json
Adds transactional persistence, resource conversion, lazy readers, fake IndexedDB tests, and related configuration.
Filesystem storage backend
packages/kit/src/skills/storage/fs.ts, packages/kit/src/skills/test/fsStorage.test.ts
Adds atomic directory persistence with SKILL.md, recursive resources, lazy readers, imports, listing, deletion, readonly enforcement, rollback, and tests.
Platform entry points and exports
packages/kit/src/skills/storage/index.ts, packages/kit/src/skills/storage/node.ts, packages/kit/src/index.ts, packages/kit/src/node.ts
Exposes storage contracts, importers, factories, and implementations through package and platform entry points.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SkillImporter
  participant SkillStorage
  participant Persistence
  Caller->>SkillStorage: import(options)
  SkillStorage->>SkillImporter: load skill
  SkillImporter-->>SkillStorage: SkillImportResult
  SkillStorage->>Persistence: add(skill)
  Persistence-->>SkillStorage: stored skill
  SkillStorage-->>Caller: import result with persisted skill
Loading

Possibly related PRs

Suggested reviewers: sonyleo

Poem

🐇 Storage burrows bloom with care,
Memory, disk, and browser lair.
Skills wait softly, readers wake,
Cancelled jobs know paths to take,
A tidy vault now guards each name.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding new skill storage providers.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gene9831 gene9831 marked this pull request as ready for review June 30, 2026 07:01
@gene9831

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

1 similar comment
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@gene9831

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/kit/src/skills/storage/indexedDB.ts (1)

161-171: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Minor: import() resolves with the raw loaded skill, not the stored one.

Unlike FsSkillStorage.import() (which re-reads via add() and returns the persisted skill with lazy readers), here the resolved result.skill is the loader's skill while add()'s return value is discarded. Consumers awaiting the job get eager content rather than the storage-backed lazy descriptors, which is an inconsistency across backends.

♻️ Align with fs backend
   import(options: TImportOptions): SkillImportJob {
     const task = this.importer(options)

     return Object.assign(
       task.then(async (result) => {
-        await this.add(result.skill)
-        return result
+        const skill = await this.add(result.skill)
+        return { ...result, name: skill.name, skill }
       }),
       { cancel: task.cancel },
     )
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/kit/src/skills/storage/indexedDB.ts` around lines 161 - 171, The
IndexedDBStorage import() flow returns the loader’s raw skill instead of the
stored version, unlike FsSkillStorage.import(). Update IndexedDBStorage.import()
so it awaits add(result.skill) and returns the persisted skill from add() (or
otherwise rehydrates the stored record) before resolving the job, while keeping
the cancel passthrough from importer() intact.
packages/kit/src/skills/storage/fs.ts (1)

96-121: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

list() performs a full per-skill read to produce summaries.

Each summary requires get(), which reads SKILL.md and recursively walks/stats every resource file. For roots with many skills this is significantly more I/O than the IndexedDB backend (which reads inline metadata). Also note that if any skill's SKILL.md has empty instructions, readSkillDirectory throws (Line 147) and that error escapes get() (only ENOENT is swallowed), breaking the entire list().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/kit/src/skills/storage/fs.ts` around lines 96 - 121, The fs-backed
skill listing in list() is doing expensive full skill reads via get() for every
directory, and any parsing failure from readSkillDirectory can abort the whole
list. Update list() to build summaries without loading each full
SKILL.md/resource tree, using only lightweight metadata or directory inspection
where possible, and make get()/readSkillDirectory failures for a single skill
non-fatal so one bad skill does not break the entire listing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/kit/src/skills/test/fsStorage.test.ts`:
- Around line 66-105: The fsStorage test relies on fixture skill directories
under the test .cache path, but the referenced weather and vue-best-practices
SKILL.md fixtures are missing from the repo. Add those committed fixture
directories/files so createTempRoot(), storage.list(), and storage.import() in
fsStorage.test.ts can copy and validate real skill data during the test.

---

Nitpick comments:
In `@packages/kit/src/skills/storage/fs.ts`:
- Around line 96-121: The fs-backed skill listing in list() is doing expensive
full skill reads via get() for every directory, and any parsing failure from
readSkillDirectory can abort the whole list. Update list() to build summaries
without loading each full SKILL.md/resource tree, using only lightweight
metadata or directory inspection where possible, and make
get()/readSkillDirectory failures for a single skill non-fatal so one bad skill
does not break the entire listing.

In `@packages/kit/src/skills/storage/indexedDB.ts`:
- Around line 161-171: The IndexedDBStorage import() flow returns the loader’s
raw skill instead of the stored version, unlike FsSkillStorage.import(). Update
IndexedDBStorage.import() so it awaits add(result.skill) and returns the
persisted skill from add() (or otherwise rehydrates the stored record) before
resolving the job, while keeping the cancel passthrough from importer() intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7db29771-794a-48ea-b87e-8863b9a8686c

📥 Commits

Reviewing files that changed from the base of the PR and between 79556a0 and 50df777.

📒 Files selected for processing (13)
  • packages/kit/package.json
  • packages/kit/src/index.ts
  • packages/kit/src/node.ts
  • packages/kit/src/skills/storage/fs.ts
  • packages/kit/src/skills/storage/importSkill.ts
  • packages/kit/src/skills/storage/index.ts
  • packages/kit/src/skills/storage/indexedDB.ts
  • packages/kit/src/skills/storage/memory.ts
  • packages/kit/src/skills/storage/node.ts
  • packages/kit/src/skills/storage/types.ts
  • packages/kit/src/skills/test/fsStorage.test.ts
  • packages/kit/src/skills/test/indexedDBStorage.test.ts
  • packages/kit/src/skills/test/memoryStorage.test.ts

Comment thread packages/kit/src/skills/test/fsStorage.test.ts
Comment thread packages/kit/src/skills/storage/fs.ts Outdated
SonyLeo
SonyLeo previously approved these changes Jul 14, 2026
Comment thread packages/kit/src/skills/storage/fs.ts Outdated
Comment thread packages/kit/src/skills/storage/fs.ts
Comment thread packages/kit/src/skills/storage/fs.ts Outdated
Comment thread packages/kit/src/skills/storage/fs.ts Outdated
Comment thread packages/kit/src/skills/storage/fs.ts
Comment thread packages/kit/src/skills/storage/fs.ts Outdated
Comment thread packages/kit/src/skills/storage/fs.ts
Comment thread packages/kit/src/skills/test/fsStorage.test.ts
Comment thread packages/kit/src/skills/storage/index.ts Outdated
Comment thread packages/kit/src/skills/storage/memory.ts
@SonyLeo SonyLeo merged commit adf92b6 into opentiny:develop Jul 16, 2026
4 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🧹 Preview Cleaned Up

The preview deployment has been removed.

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