Skip to content

feat(kit): add skill storage providers#367

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

feat(kit): add skill storage providers#367
gene9831 wants to merge 5 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 skill storage implementations for in-memory, filesystem, and browser IndexedDB, with CRUD operations and list summaries.
    • Expanded the public API with cancelable skill importing, plus new storage entrypoints and exports.
  • Bug Fixes
    • Improved persistence and overwrite behavior for skill resources, including correct lazy loading of text/binary content.
  • Tests
    • Added Vitest coverage for memory, filesystem (atomic install), and IndexedDB flows, including import, overwrite, delete, and lazy-loading semantics.
  • Chores
    • Updated test setup to support IndexedDB simulation and tightened TypeScript ambient 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6f65e0f2-2ed0-4eaf-b2d2-f2dbe3d5a701

📥 Commits

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

📒 Files selected for processing (3)
  • packages/kit/src/skills/storage/fs.ts
  • packages/kit/src/skills/test/fsStorage.test.ts
  • packages/kit/tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/kit/src/skills/storage/fs.ts

Walkthrough

Adds a complete skills/storage subsystem to packages/kit with shared TypeScript types, a cancellable import factory, memory, IndexedDB, and filesystem backends, platform exports, Node type 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. Adds createImportSkill to wrap skill loading.
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 corresponding 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 IndexedDB persistence, resource conversion and lazy readers, fake IndexedDB tests, the test dependency, and Node ambient type configuration.
Filesystem storage backend
packages/kit/src/skills/storage/fs.ts, packages/kit/src/skills/test/fsStorage.test.ts
Adds atomic directory-based 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 types, importers, factories, and backend implementations through browser, Node, and package entry points.

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

Possibly related PRs

  • opentiny/tiny-robot#366: Provides the skill loader APIs consumed by the storage import wiring and also updates Node exports.

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

2 participants