This document serves as a self-contained, step-by-step guide for an AI agent to execute the migration from the flat, database-backed skill system to the new "Skills as Folders" (Lazy-Loading) architecture.
Prerequisites to check before starting:
/app/ai-hub/app/api/)./app/frontend/src/features/skills/)./app/db/models.py).Objective: Evolve the Skill model to support a Virtual File System (VFS) instead of monolithic text fields.
Step 1.1: Create the SkillFile SQLAlchemy Model
/app/ai-hub/app/db/models.pySkillFile model with:
id (Integer, Primary Key)skill_id (Integer, Foreign Key to skills.id)file_path (String, e.g., SKILL.md, scripts/run.py, artifacts/data.json)content (Text or LargeBinary, to hold file data)created_at / updated_at (DateTime)files = relationship("SkillFile", back_populates="skill", cascade="all, delete-orphan") to the main Skill model. Step 1.2: Deprecate Legacy Fields in the Skill Model
/app/ai-hub/app/db/models.pysystem_prompt, preview_markdown, and config as nullable/deprecated. The core logic should now expect a SKILL.md file in the SkillFile table to replace system_prompt and preview_markdown.Step 1.3: Generate & Run Alembic Migration
SkillFile table and apply it to the database.Objective: Expose endpoints for standard IDE operations (CRUD for files/folders).
Step 2.1: Implement File Tree API
/app/ai-hub/app/api/routes/skills.pyGET /skills/{skill_id}/files.file_path strings).Step 2.2: Implement File Content CRUD Operations
/app/ai-hub/app/api/routes/skills.pyGET /skills/{skill_id}/files/{path:path} to read a specific file's text/binary content.POST /skills/{skill_id}/files/{path:path} to create or update file contents.DELETE /skills/{skill_id}/files/{path:path} to remove a file.Step 2.3: Modify Skill Creation Logic
/app/ai-hub/app/api/routes/skills.py (POST /skills/)SkillFile database with a default SKILL.md file containing basic boilerplate instructions.Objective: Teach the AI agent how to interact with this new folder structure instead of relying on the giant system_prompt.
Step 3.1: Create the read_skill_artifact Tool
/app/ai-hub/app/core/agent/tools.py or similar).skill_name and file_path to read content dynamically during a session.Step 3.2: Update Agent Initialization Context
sessions.py or agent orchestrator).SKILL.md into the initial system prompt. Provide the agent with the read_skill_artifact tool to discover and read anything in the /scripts/ or /artifacts/ folders when necessary.Objective: Replace the basic textarea forms with a true workspace IDE UI.
Step 4.1: Abstract File APIs in Frontend Service
/app/frontend/src/services/apiService.jsgetSkillFiles(id), getSkillFileContent(id, path), saveSkillFile(id, path, content), deleteSkillFile(id, path).Step 4.2: Build the File Tree Sidebar Component
/app/frontend/src/features/skills/components/SkillFileTree.js (New Component)Step 4.3: Implement the Code Editor Component
/app/frontend/src/features/skills/components/SkillEditor.js (New Component)saveSkillFile API. Step 4.4: Refactor SkillsPageContent.js
/app/frontend/src/features/skills/components/SkillsPageContent.jsformData.system_prompt, formData.preview_markdown, formData.config).SkillFileTree (Left) and SkillEditor (Right).SKILL.md is automatically created.scripts/test.py via the Frontend UI.SKILL.md by default, but executing a tool to read scripts/test.py only when requested.