-
Notifications
You must be signed in to change notification settings - Fork 0
WebMCP: publish skill registry tools #51
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
8 commits
Select commit
Hold shift + click to select a range
e6654b8
feat(webmcp): add canonical skill registry collector
erinepshovel-code fa719a5
feat(webmcp): add read-only skill registry adapter
erinepshovel-code bd53c47
feat(webmcp): register browser-native skill registry tools
erinepshovel-code 8ad1fa9
feat(webmcp): add public provider and status page
erinepshovel-code 96f548b
feat(webmcp): load provider only on declared routes
erinepshovel-code 7b80ffe
fix(webmcp): publish registry through existing asset passthrough
erinepshovel-code 50c1d69
build(webmcp): refresh registry and include contract tests
erinepshovel-code ab56166
test(webmcp): verify registry and provider contracts
erinepshovel-code 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { createHash } from 'node:crypto'; | ||
| import { mkdir, readFile, writeFile } from 'node:fs/promises'; | ||
|
|
||
| // === MODULE_BUILD === | ||
| // id: skill_registry_collector | ||
| // purpose: Publish a commit-pinned projection of skill-lib/skills.json for the website-owned WebMCP surface without transferring skill authority to the website. | ||
| // entrypoint: npm run refresh:skills | ||
| // tests: tests/webmcp.test.mjs | ||
| // === END MODULE_BUILD === | ||
| // === BOUNDARIES === | ||
| // id: skill_registry_source_boundary | ||
| // network: reads only commit-pinned raw.githubusercontent.com/The-Interdependency/skill-lib/<commit>/skills.json | ||
| // storage: writes generated, public asset, and last-known-good JSON snapshots only | ||
| // authority: The-Interdependency/skill-lib remains canonical; this website publishes a derived registry projection for browser tools | ||
| // failure: a network or parse failure falls back only to a previously verified snapshot; absence of both fails closed | ||
| // === END BOUNDARIES === | ||
| // === CONTRACTS === | ||
| // id: skill_registry_exact_input_identity | ||
| // given: skill-lib skills.json is projected into the website | ||
| // then: repository, exact head commit, source path, and SHA-256 remain attached to the projection | ||
| // class: evidence | ||
| // | ||
| // id: skill_registry_dependency_integrity | ||
| // given: a skill declares depends_on entries | ||
| // then: every dependency names another skill in the same registry | ||
| // class: correctness | ||
| // === END CONTRACTS === | ||
| // Usage: run `npm run refresh:skills` after `npm run refresh:github`; WebMCP consumes `/assets/data/skill-registry.json`. Use `OFFLINE=1` only after at least one verified online refresh has created the last-known-good snapshot. | ||
|
|
||
| const ORGANIZATION = 'The-Interdependency'; | ||
| const REPOSITORY = 'skill-lib'; | ||
| const SOURCE_PATH = 'skills.json'; | ||
| const RAW_GITHUB_ORIGIN = 'https://raw.githubusercontent.com'; | ||
| const GENERATED_REPOS = 'src/_data/generated/repos.json'; | ||
| const GENERATED_OUT = 'src/_data/generated/skillRegistry.json'; | ||
| const PUBLIC_OUT = 'src/assets/data/skill-registry.json'; | ||
| const SNAPSHOT_OUT = 'src/_data/snapshots/skill-registry.last-known-good.json'; | ||
|
|
||
| function sha256(value) { | ||
| return createHash('sha256').update(value).digest('hex'); | ||
| } | ||
|
|
||
| function stableJson(value) { | ||
| return `${JSON.stringify(value, null, 2)}\n`; | ||
| } | ||
|
|
||
| function rawGithubUrl(commit) { | ||
| return new URL(`/${ORGANIZATION}/${REPOSITORY}/${commit}/${SOURCE_PATH}`, RAW_GITHUB_ORIGIN); | ||
| } | ||
|
|
||
| function getText(target) { | ||
| const url = target instanceof URL ? target : new URL(target); | ||
| if (url.protocol !== 'https:' || url.origin !== RAW_GITHUB_ORIGIN) { | ||
| throw new Error(`refusing non-raw-GitHub target: ${url.origin}`); | ||
| } | ||
| return execFileSync( | ||
| 'curl', | ||
| ['-fsSL', '--retry', '2', '--max-time', '20', url.href], | ||
| { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] } | ||
| ); | ||
| } | ||
|
|
||
| export function normalizeRegistry(sourceText, commit) { | ||
| const parsed = JSON.parse(String(sourceText)); | ||
| if (parsed?.repo !== `${ORGANIZATION}/${REPOSITORY}`) { | ||
| throw new Error(`unexpected registry repo: ${parsed?.repo || 'missing'}`); | ||
| } | ||
| if (!Array.isArray(parsed.skills) || parsed.skills.length === 0) { | ||
| throw new Error('skill registry has no skills'); | ||
| } | ||
|
|
||
| const skills = parsed.skills.map(skill => ({ | ||
| name: String(skill.name || '').trim(), | ||
| path: String(skill.path || '').trim(), | ||
| kind: String(skill.kind || '').trim(), | ||
| depends_on: Array.isArray(skill.depends_on) ? skill.depends_on.map(String) : [], | ||
| description: String(skill.description || '').trim() | ||
| })); | ||
|
|
||
| const names = new Set(skills.map(skill => skill.name)); | ||
| if (names.size !== skills.length || skills.some(skill => !skill.name || !skill.path || !skill.description)) { | ||
| throw new Error('skill registry contains duplicate or incomplete skill records'); | ||
| } | ||
| for (const skill of skills) { | ||
| for (const dependency of skill.depends_on) { | ||
| if (!names.has(dependency)) throw new Error(`unresolved skill dependency: ${skill.name} -> ${dependency}`); | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| version: parsed.version, | ||
| source: { | ||
| repository: `${ORGANIZATION}/${REPOSITORY}`, | ||
| commit, | ||
| path: SOURCE_PATH, | ||
| sha256: sha256(sourceText) | ||
| }, | ||
| install_path: parsed.install_path, | ||
| superseded_skills: Array.isArray(parsed.superseded_skills) ? parsed.superseded_skills : [], | ||
| skills | ||
| }; | ||
| } | ||
|
|
||
| async function readFallback() { | ||
| const text = await readFile(SNAPSHOT_OUT, 'utf8'); | ||
| const parsed = JSON.parse(text); | ||
| if (!parsed?.source?.commit || !Array.isArray(parsed.skills) || parsed.skills.length === 0) { | ||
| throw new Error('last-known-good skill registry snapshot is invalid'); | ||
| } | ||
| return parsed; | ||
| } | ||
|
|
||
| async function writeProjection(registry, fallback, hmmm = []) { | ||
| await Promise.all([ | ||
| mkdir('src/_data/generated', { recursive: true }), | ||
| mkdir('src/assets/data', { recursive: true }) | ||
| ]); | ||
| const serialized = stableJson({ ...registry, fallback, hmmm }); | ||
| await Promise.all([ | ||
| writeFile(GENERATED_OUT, serialized), | ||
| writeFile(PUBLIC_OUT, serialized) | ||
| ]); | ||
| } | ||
|
|
||
| async function main() { | ||
| if (process.env.OFFLINE === '1') { | ||
| const snapshot = await readFallback(); | ||
| await writeProjection(snapshot, true, ['offline build: using last-known-good skill registry snapshot']); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const repoIndex = JSON.parse(await readFile(GENERATED_REPOS, 'utf8')); | ||
| const skillLib = (repoIndex.repositories || []).find(repo => repo.name === REPOSITORY); | ||
| if (!skillLib?.head_sha) throw new Error('skill-lib head_sha missing from generated repository index'); | ||
|
|
||
| const sourceText = getText(rawGithubUrl(skillLib.head_sha)); | ||
| const registry = normalizeRegistry(sourceText, skillLib.head_sha); | ||
| await mkdir('src/_data/snapshots', { recursive: true }); | ||
| await writeFile(SNAPSHOT_OUT, stableJson(registry)); | ||
| await writeProjection(registry, false); | ||
| } catch (error) { | ||
| try { | ||
| const snapshot = await readFallback(); | ||
| await writeProjection(snapshot, true, [`registry refresh failed: ${error.message}`]); | ||
| } catch (fallbackError) { | ||
| throw new Error(`skill registry refresh failed and no valid snapshot exists: ${error.message}; fallback: ${fallbackError.message}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||
| await main(); | ||
| } | ||
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,120 @@ | ||
| // === MODULE_BUILD === | ||
| // id: webmcp_skill_registry_adapter | ||
| // purpose: Provide deterministic, read-only operations over the website's commit-pinned skill-lib registry projection. | ||
| // entrypoint: imported by /assets/js/webmcp.js and tests/webmcp.test.mjs | ||
| // tests: tests/webmcp.test.mjs | ||
| // === END MODULE_BUILD === | ||
| // === BOUNDARIES === | ||
| // id: webmcp_skill_registry_read_boundary | ||
| // network: none | ||
| // storage: none | ||
| // user_data: none | ||
| // operational_effects: none; all exported operations are read-only transformations over supplied registry data | ||
| // === END BOUNDARIES === | ||
| // === CONTRACTS === | ||
| // id: webmcp_registry_smallest_dependency_closure | ||
| // given: a registered skill name | ||
| // then: resolveSkillClosure returns that skill plus every transitive depends_on prerequisite exactly once in dependency-first order | ||
| // class: correctness | ||
| // === END CONTRACTS === | ||
| // Usage: `const registry = createSkillRegistry(data); registry.findSkills({ query: 'repository audit' })`. Consumers must pass the generated `/assets/data/skill-registry.json` projection, never invent skill records locally. | ||
|
|
||
| function normalizeText(value) { | ||
| return String(value || '').trim().toLowerCase(); | ||
| } | ||
|
|
||
| function publicSkill(skill, source) { | ||
| return { | ||
| name: skill.name, | ||
| kind: skill.kind, | ||
| depends_on: [...skill.depends_on], | ||
| description: skill.description, | ||
| canonical_path: skill.path, | ||
| canonical_url: `https://github.com/${source.repository}/blob/${source.commit}/${skill.path}` | ||
| }; | ||
| } | ||
|
|
||
| export function createSkillRegistry(registryData) { | ||
| if (!registryData?.source?.repository || !registryData?.source?.commit || !Array.isArray(registryData.skills)) { | ||
| throw new Error('invalid skill registry projection'); | ||
| } | ||
|
|
||
| const source = registryData.source; | ||
| const byName = new Map(registryData.skills.map(skill => [skill.name, skill])); | ||
|
|
||
| function requireSkill(name) { | ||
| const skill = byName.get(String(name || '').trim()); | ||
| if (!skill) throw new Error(`unknown skill: ${name}`); | ||
| return skill; | ||
| } | ||
|
|
||
| function listSkills({ kind = '' } = {}) { | ||
| const normalizedKind = normalizeText(kind); | ||
| return registryData.skills | ||
| .filter(skill => !normalizedKind || normalizeText(skill.kind) === normalizedKind) | ||
| .map(skill => publicSkill(skill, source)); | ||
| } | ||
|
|
||
| function findSkills({ query, kind = '', limit = 8 } = {}) { | ||
| const terms = normalizeText(query).split(/\s+/).filter(Boolean); | ||
| const normalizedKind = normalizeText(kind); | ||
| const boundedLimit = Math.max(1, Math.min(Number(limit) || 8, 20)); | ||
| if (terms.length === 0) return listSkills({ kind }).slice(0, boundedLimit); | ||
|
|
||
| return registryData.skills | ||
| .filter(skill => !normalizedKind || normalizeText(skill.kind) === normalizedKind) | ||
| .map(skill => { | ||
| const name = normalizeText(skill.name); | ||
| const description = normalizeText(skill.description); | ||
| const path = normalizeText(skill.path); | ||
| let score = 0; | ||
| for (const term of terms) { | ||
| if (name === term) score += 8; | ||
| if (name.includes(term)) score += 5; | ||
| if (path.includes(term)) score += 3; | ||
| if (description.includes(term)) score += 2; | ||
| } | ||
| return { skill, score }; | ||
| }) | ||
| .filter(item => item.score > 0) | ||
| .sort((a, b) => b.score - a.score || a.skill.name.localeCompare(b.skill.name)) | ||
| .slice(0, boundedLimit) | ||
| .map(item => publicSkill(item.skill, source)); | ||
| } | ||
|
|
||
| function inspectSkill({ name } = {}) { | ||
| return publicSkill(requireSkill(name), source); | ||
| } | ||
|
|
||
| function resolveSkillClosure({ name } = {}) { | ||
| const ordered = []; | ||
| const visiting = new Set(); | ||
| const visited = new Set(); | ||
|
|
||
| function visit(skillName) { | ||
| if (visited.has(skillName)) return; | ||
| if (visiting.has(skillName)) throw new Error(`skill dependency cycle at ${skillName}`); | ||
| visiting.add(skillName); | ||
| const skill = requireSkill(skillName); | ||
| for (const dependency of skill.depends_on) visit(dependency); | ||
| visiting.delete(skillName); | ||
| visited.add(skillName); | ||
| ordered.push(publicSkill(skill, source)); | ||
| } | ||
|
|
||
| visit(String(name || '').trim()); | ||
| return ordered; | ||
| } | ||
|
|
||
| function getRegistryStatus() { | ||
| return { | ||
| registry_version: registryData.version, | ||
| skill_count: registryData.skills.length, | ||
| source: { ...source }, | ||
| fallback: Boolean(registryData.fallback), | ||
| hmmm: Array.isArray(registryData.hmmm) ? [...registryData.hmmm] : [] | ||
| }; | ||
| } | ||
|
|
||
| return { listSkills, findSkills, inspectSkill, resolveSkillClosure, getRegistryStatus }; | ||
| } |
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.