Skip to content

feat(#1894): recursively discover skills in nested subdirectories#2146

Open
netwmr01 wants to merge 1 commit into
MoonshotAI:mainfrom
netwmr01:recursive_skills_loading
Open

feat(#1894): recursively discover skills in nested subdirectories#2146
netwmr01 wants to merge 1 commit into
MoonshotAI:mainfrom
netwmr01:recursive_skills_loading

Conversation

@netwmr01
Copy link
Copy Markdown

@netwmr01 netwmr01 commented May 2, 2026

Previously, discover_skills() only scanned the immediate children of a skills root. This meant nested layouts like
.agents/skills/cloudlive/skills/cloudlive-project-layout/SKILL.md were invisible to Kimi CLI, even though Codex supports them.

Changes:

  • Add _discover_subdir_skills() helper that recursively walks subdirectories looking for SKILL.md.
  • A directory containing SKILL.md is treated as a skill leaf; no further recursion happens inside it.
  • Flat .md skills remain top-level-only (Pass 2 is unchanged).

Related Issue

Resolve #1894

Description

  • Add _discover_subdir_skills() helper that recursively walks subdirectories looking for SKILL.md.
  • A directory containing SKILL.md is treated as a skill leaf; no further recursion happens inside it.
  • Flat .md skills remain top-level-only (Pass 2 is unchanged).

Checklist

  • [y ] I have read the CONTRIBUTING document.
  • [y ] I have linked the related issue, if any.
  • [y ] I have added tests that prove my fix is effective or that my feature works.
  • [y ] I have run make gen-changelog to update the changelog.
  • [y ] I have run make gen-docs to update the user documentation.

Open in Devin Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3de5b7ceb6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/skill/__init__.py Outdated
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@netwmr01 netwmr01 force-pushed the recursive_skills_loading branch 2 times, most recently from 8824f6f to 0246866 Compare May 2, 2026 15:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 024686675f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/skill/__init__.py Outdated
@netwmr01 netwmr01 force-pushed the recursive_skills_loading branch from 0246866 to 7b5da9f Compare May 3, 2026 00:34
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b5da9f0aa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/skill/__init__.py Outdated
devin-ai-integration[bot]

This comment was marked as resolved.

@netwmr01 netwmr01 force-pushed the recursive_skills_loading branch from b03ecbd to 55ec432 Compare May 3, 2026 02:50
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@netwmr01 netwmr01 force-pushed the recursive_skills_loading branch from 55ec432 to 403bf13 Compare May 3, 2026 04:30
…irectories for safety

Previously discover_skills() only scanned immediate children of a skills root,
missing nested layouts like .agents/skills/cloudlive/skills/.../SKILL.md.
Now recursively traverse subdirectories to find SKILL.md at any depth.
(Full issue: MoonshotAI#1894)

Symlink cycle protection:
- Detect symlinks via stat(follow_symlinks=False) + S_ISLNK on all backends.
- Never traverse into a symlinked intermediate directory. This prevents
  undetectable symlink cycles on remote backends (SSH/SFTP) where kaos lacks
  readlink() and resolve(). Symlinked skill directories (those containing
  SKILL.md directly) are still discovered.
- On local backends, additionally deduplicate real directories using a visited
  set keyed by Path.resolve().

Additional safeguards:
- emits a `logger.warning` a warning if recursive scanning takes longer than
  3 seconds to help detect symlink issues, huge directories, or slow network mounts.

Testing:
- Added comprehensive tests covering many edge cases
  - Symlink cycle scenarios (self‑referential, mutual)
  - Deeply nested valid skill directories
  - Mixed symlink and real directory structures
  - Non‑local backend simulation
- All existing tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant