Skip to content

feat(kit): add skill storage providers#367

Open
gene9831 wants to merge 4 commits into
opentiny:developfrom
gene9831:codex/skill-storage-foundation
Open

feat(kit): add skill storage providers#367
gene9831 wants to merge 4 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 options for in-memory, filesystem, and browser/IndexedDB use.
    • Expanded the public API to include skill storage import, listing, deletion, and retrieval support.
  • Bug Fixes

    • Improved handling of stored skill resources so text and binary content are preserved correctly.
    • Added cancelable import behavior for long-running skill imports.
  • Tests

    • Added coverage for memory, filesystem, and IndexedDB storage flows, including import, overwrite, delete, and lazy-loading behavior.

@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

Walkthrough

Adds a complete skills/storage subsystem to packages/kit with shared TypeScript types, a generic createImportSkill factory, and three backend implementations: in-memory, IndexedDB-backed, and filesystem-backed. Platform-specific entry points wire these into browser and Node exports. Vitest test suites cover all three backends.

Changes

Skill Storage Subsystem

Layer / File(s) Summary
Storage types and import factory
packages/kit/src/skills/storage/types.ts, packages/kit/src/skills/storage/importSkill.ts
Defines SkillSummary, SkillStorage<TImportOptions>, SkillImportResult, SkillImportJob, and SkillImporter types. Adds createImportSkill factory that wraps a loadSkill function into a cancellable SkillImportJob.
In-memory storage backend
packages/kit/src/skills/storage/memory.ts
Implements MemorySkillStorage with a Map-backed store, deep-clone helpers at read/write boundaries, CRUD operations, sorted list(), and import wiring with cancel passthrough.
IndexedDB storage backend
packages/kit/src/skills/storage/indexedDB.ts, packages/kit/package.json, packages/kit/src/skills/test/indexedDBStorage.test.ts
Defines the IndexedDB schema (object stores and skillName index), implements IndexedDBSkillStorage with lazy database init, add/get/has/delete/list/import operations, and resource serialization/deserialization helpers. Adds fake-indexeddb dev dependency and integration tests.
Filesystem storage backend
packages/kit/src/skills/storage/fs.ts, packages/kit/src/skills/test/fsStorage.test.ts
Implements FsSkillStorage using a directory-per-skill layout with SKILL.md (YAML frontmatter + instructions), recursive resource file reads/writes, ENOENT-safe get, readonly guard, and lazy readText/readBinary on retrieved resources.
Platform entry points and wiring
packages/kit/src/skills/storage/index.ts, packages/kit/src/skills/storage/node.ts, packages/kit/src/index.ts, packages/kit/src/node.ts, packages/kit/src/skills/test/memoryStorage.test.ts
Exports SkillImportOptions, SkillStorage, importSkill, and createMemorySkillStorage for browser (index.ts) and Node (node.ts) consumers. Adds MemorySkillStorage tests covering CRUD, browser/multi-file import, and import cancellation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • opentiny/tiny-robot#366: This PR's importSkill and SkillImportOptions are built directly on top of loadSkillWithDetails and SkillLoadOptions from the skill loader foundation added in that PR, and both modify packages/kit/src/node.ts exports.

Poem

🐇 Hop hop, a storage burrow dug with care,
Three backends built—memory, disk, and IndexedDB lair,
SKILL.md files tucked in directories neat,
Lazy readers waiting till data you need to meet,
Cancel jobs, clone skills, list them sorted by name—
This rabbit's skill vault will never be the same! 🗄️

🚥 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 clearly matches the main change: adding skill storage providers in the kit package.
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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


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

1 participant