-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(cli): add nemoclaw <sandbox> skill install command (#1844) #1845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
424e923
feat(cli): add nemoclaw <sandbox> skill install command (#1844)
senthilr-nv 60be7e7
Merge remote-tracking branch 'upstream/main' into feat/skill-install
senthilr-nv a77e421
fix: address CodeRabbit review feedback on skill install
senthilr-nv 91a84d4
fix(cli): reject unexpected trailing args for skill install
senthilr-nv 8ece2ac
Merge branch 'main' into feat/skill-install
ericksoa 5737a1e
fix(cli): recover stale registry for skill install dispatch
senthilr-nv f015059
feat(hermes): add nemoclaw_reload_skills tool for skill hot-reload
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, it, expect } from "vitest"; | ||
| import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { tmpdir } from "node:os"; | ||
| // Import from compiled dist/ so coverage is attributed correctly. | ||
| import { | ||
| parseFrontmatter, | ||
| resolveSkillPaths, | ||
| collectFiles, | ||
| validateRelativePath, | ||
| shellQuote, | ||
| } from "../../dist/lib/skill-install"; | ||
|
|
||
| describe("parseFrontmatter", () => { | ||
| it("extracts name from valid frontmatter", () => { | ||
| const result = parseFrontmatter("---\nname: my-skill\ndescription: test\n---\n# Body"); | ||
| expect(result).toEqual({ name: "my-skill" }); | ||
| }); | ||
|
|
||
| it("handles quoted name values", () => { | ||
| expect(parseFrontmatter('---\nname: "my-tool"\n---\n').name).toBe("my-tool"); | ||
| expect(parseFrontmatter("---\nname: 'demo.tool'\n---\n").name).toBe("demo.tool"); | ||
| }); | ||
|
|
||
| it("handles name with dots, hyphens, and underscores", () => { | ||
| expect(parseFrontmatter("---\nname: my_skill.v2-beta\n---\n").name).toBe("my_skill.v2-beta"); | ||
| }); | ||
|
|
||
| it("parses complex YAML metadata beyond name", () => { | ||
| const fm = parseFrontmatter( | ||
| '---\nname: rich-skill\ndescription: "A skill"\nmetadata: { "openclaw": { "emoji": "🔧" } }\n---\n', | ||
| ); | ||
| expect(fm.name).toBe("rich-skill"); | ||
| }); | ||
|
|
||
| it("rejects malformed YAML", () => { | ||
| expect(() => | ||
| parseFrontmatter("---\nname: ok\ndescription: [broken\n---\n"), | ||
| ).toThrow("not valid YAML"); | ||
| }); | ||
|
|
||
| it("rejects non-mapping frontmatter", () => { | ||
| expect(() => parseFrontmatter("---\n- just\n- a list\n---\n")).toThrow("must be a YAML mapping"); | ||
| }); | ||
|
|
||
| it("throws when frontmatter is missing entirely", () => { | ||
| expect(() => parseFrontmatter("# Just markdown\nNo frontmatter")).toThrow( | ||
| "missing YAML frontmatter", | ||
| ); | ||
| }); | ||
|
|
||
| it("throws when closing delimiter is missing", () => { | ||
| expect(() => parseFrontmatter("---\nname: broken\n# No closing")).toThrow( | ||
| "missing closing --- frontmatter delimiter", | ||
| ); | ||
| }); | ||
|
|
||
| it("throws when name field is absent", () => { | ||
| expect(() => parseFrontmatter("---\ndescription: no name here\n---\n")).toThrow( | ||
| "missing required 'name' field", | ||
| ); | ||
| }); | ||
|
|
||
| it("throws when name field is empty or null", () => { | ||
| expect(() => parseFrontmatter("---\nname:\n---\n")).toThrow("missing required 'name' field"); | ||
| expect(() => parseFrontmatter('---\nname: ""\n---\n')).toThrow("missing required 'name' field"); | ||
| }); | ||
|
|
||
| it("rejects names with invalid characters", () => { | ||
| expect(() => parseFrontmatter("---\nname: my skill\n---\n")).toThrow("invalid characters"); | ||
| expect(() => parseFrontmatter("---\nname: ../escape\n---\n")).toThrow("invalid characters"); | ||
| expect(() => parseFrontmatter("---\nname: a/b\n---\n")).toThrow("invalid characters"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("validateRelativePath", () => { | ||
| it("accepts safe paths", () => { | ||
| expect(validateRelativePath("SKILL.md")).toBe(true); | ||
| expect(validateRelativePath("scripts/helper.js")).toBe(true); | ||
| expect(validateRelativePath("data/config-v2.yaml")).toBe(true); | ||
| }); | ||
|
|
||
| it("rejects shell metacharacters", () => { | ||
| expect(validateRelativePath("$(touch /tmp/pwn).js")).toBe(false); | ||
| expect(validateRelativePath("a'b.txt")).toBe(false); | ||
| expect(validateRelativePath('a"b.txt')).toBe(false); | ||
| expect(validateRelativePath("a`b`.txt")).toBe(false); | ||
| expect(validateRelativePath("file name.txt")).toBe(false); | ||
| expect(validateRelativePath("a;rm -rf.txt")).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects directory traversal", () => { | ||
| expect(validateRelativePath("../escape")).toBe(false); | ||
| expect(validateRelativePath("foo/../../etc/passwd")).toBe(false); | ||
| expect(validateRelativePath("./current")).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects empty and degenerate paths", () => { | ||
| expect(validateRelativePath("")).toBe(false); | ||
| expect(validateRelativePath("/absolute")).toBe(false); | ||
| expect(validateRelativePath("foo//bar")).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("shellQuote", () => { | ||
| it("wraps simple strings in single quotes", () => { | ||
| expect(shellQuote("hello")).toBe("'hello'"); | ||
| }); | ||
|
|
||
| it("escapes embedded single quotes", () => { | ||
| expect(shellQuote("it's")).toBe("'it'\\''s'"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("collectFiles", () => { | ||
| let tmpDir: string; | ||
|
|
||
| function setup(files: Record<string, string>) { | ||
| tmpDir = mkdtempSync(join(tmpdir(), "skill-test-")); | ||
| for (const [rel, content] of Object.entries(files)) { | ||
| const full = join(tmpDir, rel); | ||
| mkdirSync(join(full, ".."), { recursive: true }); | ||
| writeFileSync(full, content); | ||
| } | ||
| } | ||
|
|
||
| function cleanup() { | ||
| if (tmpDir) rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| it("collects a single SKILL.md", () => { | ||
| setup({ "SKILL.md": "---\nname: solo\n---\n" }); | ||
| try { | ||
| const { files, skippedDotfiles, unsafePaths } = collectFiles(tmpDir); | ||
| expect(files).toEqual(["SKILL.md"]); | ||
| expect(skippedDotfiles).toEqual([]); | ||
| expect(unsafePaths).toEqual([]); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
|
|
||
| it("collects SKILL.md plus nested scripts, skips dotfiles", () => { | ||
| setup({ | ||
| "SKILL.md": "---\nname: rich\n---\n", | ||
| "scripts/helper.js": "console.log('hi')", | ||
| ".env": "KEY=val", | ||
| }); | ||
| try { | ||
| const { files, skippedDotfiles } = collectFiles(tmpDir); | ||
| expect(files.sort()).toEqual(["SKILL.md", "scripts/helper.js"]); | ||
| expect(skippedDotfiles).toEqual([".env"]); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
|
|
||
| it("flags files with unsafe characters", () => { | ||
| setup({ | ||
| "SKILL.md": "---\nname: bad\n---\n", | ||
| "has space.txt": "content", | ||
| }); | ||
| try { | ||
| const { files, unsafePaths } = collectFiles(tmpDir); | ||
| expect(files).toEqual(["SKILL.md"]); | ||
| expect(unsafePaths).toEqual(["has space.txt"]); | ||
| } finally { | ||
| cleanup(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveSkillPaths", () => { | ||
| it("returns OpenClaw defaults when agent is null", () => { | ||
| const paths = resolveSkillPaths(null, "weather"); | ||
| expect(paths.uploadDir).toBe("/sandbox/.openclaw/skills/weather"); | ||
| expect(paths.mirrorDir).toBe("$HOME/.openclaw/skills/weather"); | ||
| expect(paths.sessionFile).toBe( | ||
| "/sandbox/.openclaw-data/agents/main/sessions/sessions.json", | ||
| ); | ||
| expect(paths.isOpenClaw).toBe(true); | ||
| }); | ||
|
|
||
| it("returns OpenClaw paths when agent.name is 'openclaw'", () => { | ||
| const agent = { | ||
| name: "openclaw", | ||
| configPaths: { | ||
| immutableDir: "/sandbox/.openclaw", | ||
| writableDir: "/sandbox/.openclaw-data", | ||
| }, | ||
| }; | ||
| const paths = resolveSkillPaths(agent, "my-skill"); | ||
| expect(paths.uploadDir).toBe("/sandbox/.openclaw/skills/my-skill"); | ||
| expect(paths.mirrorDir).toBe("$HOME/.openclaw/skills/my-skill"); | ||
| expect(paths.sessionFile).toBe( | ||
| "/sandbox/.openclaw-data/agents/main/sessions/sessions.json", | ||
| ); | ||
| expect(paths.isOpenClaw).toBe(true); | ||
| }); | ||
|
|
||
| it("returns Hermes paths without mirror or session refresh", () => { | ||
| const agent = { | ||
| name: "hermes", | ||
| configPaths: { | ||
| immutableDir: "/sandbox/.hermes", | ||
| writableDir: "/sandbox/.hermes-data", | ||
| }, | ||
| }; | ||
| const paths = resolveSkillPaths(agent, "demo-skill"); | ||
| expect(paths.uploadDir).toBe("/sandbox/.hermes/skills/demo-skill"); | ||
| expect(paths.mirrorDir).toBeNull(); | ||
| expect(paths.sessionFile).toBeNull(); | ||
| expect(paths.isOpenClaw).toBe(false); | ||
| }); | ||
|
|
||
| it("returns generic paths for a hypothetical future agent", () => { | ||
| const agent = { | ||
| name: "future-agent", | ||
| configPaths: { | ||
| immutableDir: "/sandbox/.future", | ||
| writableDir: "/sandbox/.future-data", | ||
| }, | ||
| }; | ||
| const paths = resolveSkillPaths(agent, "test-skill"); | ||
| expect(paths.uploadDir).toBe("/sandbox/.future/skills/test-skill"); | ||
| expect(paths.mirrorDir).toBeNull(); | ||
| expect(paths.sessionFile).toBeNull(); | ||
| expect(paths.isOpenClaw).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 41
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 765
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 91
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 436
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 41
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 41
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 92
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 893
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 41
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 133
🏁 Script executed:
Repository: NVIDIA/NemoClaw
Length of output: 1082
Harden reload error handling and private-cache access.
Line 128 directly accesses the private
sc._skill_commandsattribute without checking if it exists or is a dict. Line 132 swallows all exceptions, making hot-reload failures silent and hard to diagnose. Even thoughagent.skill_commandsis an optional external dependency, once imported, the code should not assume a specific API shape without defensive checks.Proposed fix
def _reload_skills(): """Clear the Hermes skill slash-command cache and re-scan skill directories. Hermes's ``agent.skill_commands`` module caches discovered skills in a module-global dict (``_skill_commands``). ``get_skill_commands()`` only scans on first call, so skills installed after gateway startup are invisible. We clear the dict and call ``scan_skill_commands()`` to force a fresh scan. Returns the dict of discovered skills, or None on failure. """ try: import agent.skill_commands as sc - sc._skill_commands.clear() + cache = getattr(sc, "_skill_commands", None) + if isinstance(cache, dict): + cache.clear() return sc.scan_skill_commands() except ImportError: return None - except Exception: + except (AttributeError, TypeError): + return None + except Exception as exc: + # Preserve debuggability while keeping current API behavior. + print(f"_reload_skills: unexpected reload failure: {exc}") return None📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.15.9)
[warning] 132-132: Do not catch blind exception:
Exception(BLE001)
🤖 Prompt for AI Agents