[PR #463] fix: skills middleware discovery for scoped directories - Fixes #387 #485

Open
opened 2026-06-05 17:23:21 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/463
Author: @thushanthbengre22-dev
Created: 4/14/2026
Status: 🔄 Open

Base: mainHead: fix/skills-middleware-scoped-directories


📝 Commits (3)

  • 5b95933 fix: skills middleware discovery for scoped directories - Fixes #387
  • 70fc563 chore: add changeset and apply formatting
  • 11cd650 Merge branch 'main' into fix/skills-middleware-scoped-directories

📊 Changes

3 files changed (+85 additions, -0 deletions)

View changed files

.changeset/clean-onions-reply.md (+5 -0)
📝 libs/deepagents/src/middleware/skills.test.ts (+34 -0)
📝 libs/deepagents/src/middleware/skills.ts (+46 -0)

📄 Description

Description

Fixes skills middleware skipping SKILL.md discovery when explicitly scoped skill directories are provided.

Issue

Closes #387

Problem

When skills is configured with a specific skill directory path like "skills/domainA/", the listSkillsFromBackend function fails to discover SKILL.md at that location.

Root cause:
The function calls ls("skills/domainA/"), which returns the contents of that directory (files like SKILL.md). The existing loop only processes subdirectories and skips files, so SKILL.md is never discovered.

Result:

  • skills_locations shows "skills/domainA/" in the system prompt
  • skills_list shows "none"
  • Internally inconsistent state (noted at line 715)

Solution

Before the subdirectory iteration loop, check if SKILL.md exists as a direct child of the source directory. If found:

  1. Parse the skill metadata directly
  2. Add to skills list
  3. Return early

This enables scoped skill directories while maintaining backward compatibility with the existing parent directory behavior.

Changes

Modified: libs/deepagents/src/middleware/skills.ts

  • Added check for SKILL.md as direct child before subdirectory loop
  • Reads and parses skill if found at source path
  • Returns early to avoid unnecessary processing

Modified: libs/deepagents/src/middleware/skills.test.ts

  • Added regression test reproducing the bug scenario
  • Verifies SKILL.md is discovered when source is explicit skill directory

Testing

New test case:

sources: ["/skills/domainA/"]
// With SKILL.md at /skills/domainA/SKILL.md

Before fix: skillsMetadata was empty
After fix: skillsMetadata contains the discovered skill

Backward compatibility verified:

  • Parent directories still work: sources: ["skills/"]
  • Multiple scoped directories: sources: ["skills/domainA/", "skills/domainB/"]
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Added test coverage for the fix
  • All tests pass locally
  • Backward compatible - no breaking changes

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/463 **Author:** [@thushanthbengre22-dev](https://github.com/thushanthbengre22-dev) **Created:** 4/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/skills-middleware-scoped-directories` --- ### 📝 Commits (3) - [`5b95933`](https://github.com/langchain-ai/deepagentsjs/commit/5b95933c4a4a86a13d4122dc0fe7b4a721e8bfd5) fix: skills middleware discovery for scoped directories - Fixes #387 - [`70fc563`](https://github.com/langchain-ai/deepagentsjs/commit/70fc5635298b6e1f937e5c8694ffeda7c9144b22) chore: add changeset and apply formatting - [`11cd650`](https://github.com/langchain-ai/deepagentsjs/commit/11cd650ef54b747f3e00e86f9f50422e8e5adb70) Merge branch 'main' into fix/skills-middleware-scoped-directories ### 📊 Changes **3 files changed** (+85 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/clean-onions-reply.md` (+5 -0) 📝 `libs/deepagents/src/middleware/skills.test.ts` (+34 -0) 📝 `libs/deepagents/src/middleware/skills.ts` (+46 -0) </details> ### 📄 Description ## Description Fixes skills middleware skipping `SKILL.md` discovery when explicitly scoped skill directories are provided. ## Issue Closes #387 ## Problem When `skills` is configured with a specific skill directory path like `"skills/domainA/"`, the `listSkillsFromBackend` function fails to discover `SKILL.md` at that location. **Root cause:** The function calls `ls("skills/domainA/")`, which returns the **contents** of that directory (files like `SKILL.md`). The existing loop only processes subdirectories and skips files, so `SKILL.md` is never discovered. **Result:** - `skills_locations` shows `"skills/domainA/"` in the system prompt - `skills_list` shows `"none"` - Internally inconsistent state (noted at line 715) ## Solution Before the subdirectory iteration loop, check if `SKILL.md` exists as a direct child of the source directory. If found: 1. Parse the skill metadata directly 2. Add to skills list 3. Return early This enables scoped skill directories while maintaining backward compatibility with the existing parent directory behavior. ## Changes **Modified:** `libs/deepagents/src/middleware/skills.ts` - Added check for `SKILL.md` as direct child before subdirectory loop - Reads and parses skill if found at source path - Returns early to avoid unnecessary processing **Modified:** `libs/deepagents/src/middleware/skills.test.ts` - Added regression test reproducing the bug scenario - Verifies `SKILL.md` is discovered when source is explicit skill directory ## Testing **New test case:** ```javascript sources: ["/skills/domainA/"] // With SKILL.md at /skills/domainA/SKILL.md ``` **Before fix:** `skillsMetadata` was empty ❌ **After fix:** `skillsMetadata` contains the discovered skill ✅ **Backward compatibility verified:** - ✅ Parent directories still work: `sources: ["skills/"]` - ✅ Multiple scoped directories: `sources: ["skills/domainA/", "skills/domainB/"]` - ✅ All existing tests pass ## Checklist - [x] Code follows project style guidelines - [x] Added test coverage for the fix - [x] All tests pass locally - [x] Backward compatible - no breaking changes --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:23:21 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#485