-
Notifications
You must be signed in to change notification settings - Fork 106
fix(skills): namespace ClawHub skill slugs #263
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
2 commits
Select commit
Hold shift + click to select a range
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,79 @@ | ||
| #!/usr/bin/env node | ||
| import { existsSync, readFileSync } from "node:fs"; | ||
| import path from "node:path"; | ||
| import { collectDeclaredPlatforms, PLATFORM_KEYS } from "./skill_platforms.mjs"; | ||
|
|
||
| const EXPLICIT_SLUGS = new Map([ | ||
| ["openclaw-traffic-guardian", "clawsec-openclaw-traffic-guardian"], | ||
| ["openclaw-audit-watchdog", "clawsec-openclaw-audit-watchdog"], | ||
| ["soul-guardian", "clawsec-openclaw-soul-guardian"], | ||
| ["hermes-attestation-guardian", "clawsec-hermes-attestation-guardian"], | ||
| ["hermes-traffic-guardian", "clawsec-hermes-traffic-guardian"], | ||
| ["nanoclaw-traffic-guardian", "clawsec-nanoclaw-traffic-guardian"], | ||
| ["picoclaw-security-guardian", "clawsec-picoclaw-security-guardian"], | ||
| ["picoclaw-self-pen-testing", "clawsec-picoclaw-self-pen-testing"], | ||
| ["picoclaw-traffic-guardian", "clawsec-picoclaw-traffic-guardian"], | ||
| ["clawtributor", "clawsec-clawtributor"], | ||
| ]); | ||
|
|
||
| function usage() { | ||
| return [ | ||
| "Usage: node scripts/ci/resolve_clawhub_slug.mjs <skill-dir-or-name>", | ||
| "", | ||
| "Prints the ClawHub slug for a skill without changing the GitHub release tag or skill package name.", | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| function loadSkill(input) { | ||
| const skillJsonPath = existsSync(path.join(input, "skill.json")) ? path.join(input, "skill.json") : null; | ||
| if (!skillJsonPath) { | ||
| return { name: input, platforms: [] }; | ||
| } | ||
|
|
||
| const skill = JSON.parse(readFileSync(skillJsonPath, "utf8")); | ||
| if (!skill.name || typeof skill.name !== "string") { | ||
| throw new Error(`${skillJsonPath} missing string field: name`); | ||
| } | ||
|
|
||
| return { name: skill.name, platforms: collectDeclaredPlatforms(skill) }; | ||
| } | ||
|
|
||
| export function resolveClawHubSlug({ name, platforms = [] }) { | ||
| if (!/^[a-z0-9-]+$/.test(name)) { | ||
| throw new Error(`Invalid skill name for ClawHub slug mapping: ${name}`); | ||
| } | ||
|
|
||
| if (name.startsWith("clawsec-")) { | ||
| return name; | ||
| } | ||
|
|
||
| if (EXPLICIT_SLUGS.has(name)) { | ||
| return EXPLICIT_SLUGS.get(name); | ||
| } | ||
|
|
||
| if (PLATFORM_KEYS.some((platform) => name.startsWith(`${platform}-`))) { | ||
| return `clawsec-${name}`; | ||
| } | ||
|
|
||
| const declaredPlatforms = collectDeclaredPlatforms({ platforms }); | ||
| if (declaredPlatforms.length === 1 && PLATFORM_KEYS.includes(declaredPlatforms[0])) { | ||
| return `clawsec-${declaredPlatforms[0]}-${name}`; | ||
| } | ||
|
|
||
| return `clawsec-${name}`; | ||
| } | ||
|
|
||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||
| const input = process.argv[2]; | ||
| if (!input || input === "--help" || input === "-h") { | ||
| console.log(usage()); | ||
| process.exit(input ? 0 : 1); | ||
| } | ||
|
|
||
| try { | ||
| console.log(resolveClawHubSlug(loadSkill(input))); | ||
| } catch (error) { | ||
| console.error(error instanceof Error ? error.message : String(error)); | ||
| process.exit(1); | ||
| } | ||
| } | ||
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,52 @@ | ||
| export const PLATFORM_KEYS = Object.freeze(["openclaw", "nanoclaw", "hermes", "picoclaw"]); | ||
|
|
||
| const PLATFORM_AGENT_ALIASES = new Map([["hermes", "hermes-agent"]]); | ||
|
|
||
| function asStringArray(value) { | ||
| if (Array.isArray(value)) { | ||
| return value.filter((item) => typeof item === "string" && item.trim()).map((item) => item.trim()); | ||
| } | ||
| if (typeof value === "string" && value.trim()) { | ||
| return [value.trim()]; | ||
| } | ||
| return []; | ||
| } | ||
|
|
||
| export function collectDeclaredPlatforms(skill) { | ||
| const platforms = new Set([ | ||
| ...asStringArray(skill.platform), | ||
| ...asStringArray(skill.platforms), | ||
| ]); | ||
|
|
||
| for (const key of PLATFORM_KEYS) { | ||
| if (skill[key] && typeof skill[key] === "object") { | ||
| platforms.add(key); | ||
| } | ||
| } | ||
|
|
||
| return [...platforms]; | ||
| } | ||
|
|
||
| export function installAgentForSkill(skill, agentTypes, fallback = "openclaw") { | ||
| const platforms = collectDeclaredPlatforms(skill); | ||
| if (platforms.length === 0) { | ||
| return fallback; | ||
| } | ||
|
|
||
| const matchedAgents = new Set(); | ||
| let allPlatformsMatched = true; | ||
| for (const platform of platforms) { | ||
| const candidate = PLATFORM_AGENT_ALIASES.get(platform) || platform; | ||
| if (agentTypes.has(candidate)) { | ||
| matchedAgents.add(candidate); | ||
| } else { | ||
| allPlatformsMatched = false; | ||
| } | ||
| } | ||
|
|
||
| if (allPlatformsMatched && matchedAgents.size === 1) { | ||
| return [...matchedAgents][0]; | ||
| } | ||
|
|
||
| return fallback; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.