shared-context-ai 0.1.31 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discovery.d.ts +42 -0
- package/dist/discovery.js +9 -0
- package/dist/index.js +56 -56
- package/package.json +9 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
interface DiscoveredResource {
|
|
2
|
+
importPath: string;
|
|
3
|
+
resourceType: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string | null;
|
|
6
|
+
body: string;
|
|
7
|
+
bodyHash: string;
|
|
8
|
+
metadata: {
|
|
9
|
+
skillClass?: string | null;
|
|
10
|
+
service?: string | null;
|
|
11
|
+
requires?: string[];
|
|
12
|
+
tools?: string[];
|
|
13
|
+
fields?: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
manifestMetadata?: {
|
|
16
|
+
author?: {
|
|
17
|
+
name: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
};
|
|
20
|
+
homepage?: string;
|
|
21
|
+
license?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface CollectionMembership {
|
|
25
|
+
collectionImportPath: string;
|
|
26
|
+
memberImportPaths: string[];
|
|
27
|
+
}
|
|
28
|
+
interface DiscoveryResult {
|
|
29
|
+
resources: DiscoveredResource[];
|
|
30
|
+
collectionMemberships: CollectionMembership[];
|
|
31
|
+
pluginName?: string;
|
|
32
|
+
formatLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
interface DiscoveryOptions {
|
|
35
|
+
/** Path to platform settings.json — scanned for _sc-tagged hook entries */
|
|
36
|
+
settingsPath?: string;
|
|
37
|
+
/** Path to platform MCP config (e.g., ~/.claude.json) — scanned for MCP server entries */
|
|
38
|
+
mcpConfigPath?: string;
|
|
39
|
+
}
|
|
40
|
+
declare function discoverResources(rootPath: string, options?: DiscoveryOptions): DiscoveryResult;
|
|
41
|
+
|
|
42
|
+
export { type CollectionMembership, type DiscoveredResource, type DiscoveryOptions, type DiscoveryResult, discoverResources };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";var G=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var a in t)G(e,a,{get:t[a],enumerable:!0})},ne=(e,t,a,$)=>{if(t&&typeof t=="object"||typeof t=="function")for(let C of te(t))!se.call(e,C)&&C!==a&&G(e,C,{get:()=>t[C],enumerable:!($=ee(t,C))||$.enumerable});return e};var ie=e=>ne(G({},"__esModule",{value:!0}),e);var ue={};re(ue,{discoverResources:()=>le});module.exports=ie(ue);var f=require("fs"),h=require("path"),Z=require("crypto");var U=".context-collection",Y="manifest.json";function V(e,t){return{version:1,name:e.name||"Untitled Plugin",description:e.description||void 0,resources:t.map(a=>a.resourceRef),...e.author?{author:typeof e.author=="string"?{name:e.author}:{name:e.author.name||"",url:e.author.url}}:{},...e.homepage?{homepage:e.homepage}:{},...e.license?{license:e.license}:{}}}function oe(e,t){return{version:1,name:e.name||"Untitled Extension",description:e.description||void 0,resources:t.map(a=>a.resourceRef),...e.author?{author:typeof e.author=="string"?{name:e.author}:{name:e.author.name||"",url:e.author.url}}:{},...e.homepage?{homepage:e.homepage}:{},...e.license?{license:e.license}:{}}}function ce(e,t){return{version:1,name:e.name||"Untitled Plugin",description:e.description||void 0,resources:t.map(a=>a.resourceRef),...e.author?{author:typeof e.author=="string"?{name:e.author}:{name:e.author.name||"",url:e.author.url}}:{},...e.homepage?{homepage:e.homepage}:{},...e.license?{license:e.license}:{}}}var K=[{path:`${U}/${Y}`,converter:()=>{throw new Error("Use parseCollectionManifest for native format")},formatLabel:"Shared Context"},{path:".claude-plugin/plugin.json",converter:V,formatLabel:"Claude Plugin"},{path:".claude/plugin.json",converter:V,formatLabel:"Claude Plugin"},{path:"gemini-extension.json",converter:oe,formatLabel:"Gemini Extension"},{path:".cursor-plugin/plugin.json",converter:ce,formatLabel:"Cursor Plugin"}];var Q=[{folder:"skills",mainFile:"SKILL.md",resourceType:"skill",canHaveChildren:!0},{folder:"commands",mainFile:null,resourceType:"skill",canHaveChildren:!0},{folder:"hooks",mainFile:"hook.json",resourceType:"hook",canHaveChildren:!1},{folder:"agents",mainFile:null,resourceType:"agent",canHaveChildren:!0},{folder:"mcps",mainFile:"mcp.json",resourceType:"mcp",canHaveChildren:!0},{folder:"collections",mainFile:"README.md",resourceType:"collection",canHaveChildren:!1}],X=`${U}/${Y}`;function O(e){let t={name:"",description:"",body:e};if(!e.startsWith(`---
|
|
3
|
+
`)&&!e.startsWith(`---\r
|
|
4
|
+
`))return t;let a=e.indexOf(`
|
|
5
|
+
---`,3);if(a===-1)return t;let $=e.slice(4,a),C=e.slice(a+4);t.body=C.replace(/^\r?\n/,"").replace(/^\r?\n/,"");let j={},L={},W=new Set(["requires","tools"]),I={},M=$.split(`
|
|
6
|
+
`),A=null,x=!1;for(let E=0;E<M.length;E++){let o=M[E];if(A&&/^\s+-\s/.test(o)){let c=o.replace(/^\s+-\s/,"").trim();if(c){let l=w(c);x?I[A].push(l):L[A].push(l)}continue}A=null,x=!1;let g=o.indexOf(":");if(g===-1)continue;let s=o.slice(0,g).trim(),u=o.slice(g+1).trim();if(!u&&s&&E+1<M.length&&/^\s+-\s/.test(M[E+1])){A=s,W.has(s)?(x=!0,I[s]=[]):(x=!1,L[s]=[]);continue}let r=s?u.match(/^([|>])([+-]?)\s*$/):null;if(r){let c=r[1],l=r[2],n=E+1;for(;n<M.length&&M[n].trim()==="";)n++;let d="";if(n<M.length){let v=M[n].match(/^(\s+)/);if(v){let b=v[1].length,i=[];for(;n<M.length;){let p=M[n];if(p.trim()===""){i.push(""),n++;continue}let m=p.match(/^(\s*)/);if(!m||m[1].length<b)break;i.push(p.slice(b)),n++}if(l!=="+")for(;i.length>0&&i[i.length-1]==="";)i.pop();if(c==="|")d=i.join(`
|
|
7
|
+
`);else for(let p=0;p<i.length;p++)p>0&&(d+=i[p]===""||i[p-1]===""?`
|
|
8
|
+
`:" "),d+=i[p]}}s==="name"||s==="title"?t.name=d:s==="description"?t.description=d:s==="skill_class"?t.skillClass=d:s==="service"?t.service=d:d&&(j[s]=d),E=n-1;continue}s==="name"||s==="title"?t.name=w(u):s==="description"?t.description=w(u):s==="skill_class"?t.skillClass=w(u):s==="service"?t.service=w(u):s&&u&&(j[s]=w(u))}return I.requires?.length&&(t.requires=I.requires),I.tools?.length&&(t.tools=I.tools),Object.keys(j).length&&(t.fields=j),Object.keys(L).length&&(t.arrayFields=L),t}function w(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")){let a=t.slice(1,-1);return t.startsWith('"')?a.replace(/\\"/g,'"').replace(/\\\\/g,"\\"):a.replace(/''/g,"'")}return t}function ae(e){let{body:t}=O(e);return t.replace(/\r\n/g,`
|
|
9
|
+
`).replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function D(e){let t=ae(e);return`sha256:${(0,Z.createHash)("sha256").update(t,"utf8").digest("hex")}`}function T(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function q(e){try{return(0,f.statSync)(e).isDirectory()}catch{return!1}}function B(e){try{return(0,f.readdirSync)(e).filter(t=>!t.startsWith(".")&&q((0,h.join)(e,t)))}catch{return[]}}function z(e){try{return(0,f.readdirSync)(e).filter(t=>!t.startsWith(".")&&!q((0,h.join)(e,t)))}catch{return[]}}function le(e,t){let a=[],$=[],C,j;function L(o,g){let s=[],u=[];for(let r of Q){let c=(0,h.join)(o,r.folder);if(!(0,f.existsSync)(c)||!q(c))continue;let l=g?`${g}/${r.folder}`:r.folder;if(r.folder==="files"){for(let n of z(c)){if(!n.endsWith(".md"))continue;let d=(0,h.join)(c,n),v=(0,f.readFileSync)(d,"utf-8"),b=O(v),i=b.name||(0,h.basename)(n,".md"),p=`${l}/${(0,h.basename)(n,".md")}`;s.push({importPath:p,resourceType:"file",title:i,description:b.description||null,body:b.body,bodyHash:D(v),metadata:{}})}continue}if(r.mainFile===null)for(let n of z(c)){if(!n.endsWith(".md"))continue;let d=(0,h.basename)(n,".md"),v=`${l}/${d}`;if(q((0,h.join)(c,d)))continue;let b=(0,f.readFileSync)((0,h.join)(c,n),"utf-8"),i=O(b),p=i.name||T(d),m={};i.skillClass&&(m.skillClass=i.skillClass),i.service&&(m.service=i.service),i.requires?.length&&(m.requires=i.requires),i.tools?.length&&(m.tools=i.tools),i.fields&&Object.keys(i.fields).length&&(m.fields=i.fields),r.folder==="commands"&&(m.fields||(m.fields={}),m.fields["user-invocable"]="true"),s.push({importPath:v,resourceType:r.resourceType,title:p,description:i.description||null,body:i.body,bodyHash:D(b),metadata:m})}for(let n of B(c)){let d=r.mainFile||`${n}.md`,v=(0,h.join)(c,n,d);if(!(0,f.existsSync)(v)){if(r.mainFile===null)for(let F of B((0,h.join)(c,n))){let S=`${F}.md`,k=(0,h.join)(c,n,F,S);if(!(0,f.existsSync)(k))continue;let N=(0,f.readFileSync)(k,"utf-8"),R=O(N),J=R.name||T(F),_={};R.skillClass&&(_.skillClass=R.skillClass),R.service&&(_.service=R.service),R.requires?.length&&(_.requires=R.requires),R.tools?.length&&(_.tools=R.tools),R.fields&&Object.keys(R.fields).length&&(_.fields=R.fields),s.push({importPath:`${l}/${F}`,resourceType:r.resourceType,title:J,description:R.description||null,body:R.body,bodyHash:D(N),metadata:_})}continue}let b=(0,f.readFileSync)(v,"utf-8"),i=`${l}/${n}`,p,m,H,P={},y=null;if(r.resourceType==="hook"||r.resourceType==="mcp"){try{let F=JSON.parse(b);p=F.name||T(n),m=F.description||null}catch{p=T(n),m=null}H=b}else if(r.resourceType==="collection"){let F=(0,h.join)(c,n,U,Y);if((0,f.existsSync)(F))try{let S=JSON.parse((0,f.readFileSync)(F,"utf-8"));p=S.name||T(n),m=S.description||null,H=b,S.resources&&Array.isArray(S.resources)&&u.push({collectionImportPath:i,memberImportPaths:S.resources.map(k=>{let N=k.split("/");return N.length>=3?`${N[0]}/${N[N.length-1]}`:k})})}catch{p=T(n),m=null,H=b}else y=O(b),p=y.name||T(n),m=y.description||null,H=y.body,y.arrayFields?.resources&&u.push({collectionImportPath:i,memberImportPaths:y.arrayFields.resources.map(S=>{let k=S.split("/");return k.length>=3?`${k[0]}/${k[k.length-1]}`:S})})}else y=O(b),p=y.name||T(n),m=y.description||null,H=y.body,y.skillClass&&(P.skillClass=y.skillClass),y.service&&(P.service=y.service),y.requires?.length&&(P.requires=y.requires),y.tools?.length&&(P.tools=y.tools),y.fields&&Object.keys(y.fields).length&&(P.fields=y.fields);r.folder==="commands"&&(P.fields||(P.fields={}),P.fields["user-invocable"]="true"),s.push({importPath:i,resourceType:r.resourceType,title:p,description:m,body:H,bodyHash:D(b),metadata:P})}}return{resources:s,memberships:u}}let W=L(e,"");a.push(...W.resources),$.push(...W.memberships);let I=new Set;t?.mcpConfigPath&&I.add(t.mcpConfigPath);let M=(0,h.join)(e,".mcp.json");(0,f.existsSync)(M)&&I.add(M);for(let o of I)if((0,f.existsSync)(o))try{let g=JSON.parse((0,f.readFileSync)(o,"utf-8"));if(g.mcpServers&&typeof g.mcpServers=="object")for(let[s,u]of Object.entries(g.mcpServers)){let r=`mcps/${s}`;if(a.some(n=>n.importPath===r))continue;let c=T(s),l=JSON.stringify({name:c,description:`MCP server: ${s}`,mcpServers:{[s]:u}},null,2);a.push({importPath:r,resourceType:"mcp",title:c,description:`MCP server: ${s}`,body:l,bodyHash:D(l),metadata:{}})}}catch{}if(t?.settingsPath&&(0,f.existsSync)(t.settingsPath))try{let o=JSON.parse((0,f.readFileSync)(t.settingsPath,"utf-8"));if(o.hooks&&typeof o.hooks=="object"&&!Array.isArray(o.hooks)){let g={};for(let[s,u]of Object.entries(o.hooks))if(Array.isArray(u))for(let r of u){if(!r||typeof r!="object")continue;let c=r,l=c._sc;if(!l)continue;g[l]||(g[l]={}),g[l][s]||(g[l][s]=[]);let{_sc:n,...d}=c;g[l][s].push(d)}for(let[s,u]of Object.entries(g)){let r=s;if(a.some(d=>d.importPath===r))continue;let c=s.split("/").pop()||s,l=T(c),n=JSON.stringify({name:l,description:`Hook: ${l}`,hooks:u},null,2);a.push({importPath:r,resourceType:"hook",title:l,description:`Hook: ${l}`,body:n,bodyHash:D(n),metadata:{}})}}}catch{}for(let o of K){if(o.path===X)continue;let g=(0,h.join)(e,o.path);if((0,f.existsSync)(g)){try{let s=JSON.parse((0,f.readFileSync)(g,"utf-8"));if(C=C||s.name||void 0,j=o.formatLabel,!a.some(u=>u.resourceType==="collection")){let u=a.filter(d=>d.resourceType!=="collection").map(d=>({resourceRef:d.importPath})),r=o.converter(s,u),c=(0,h.join)(e,"README.md"),l=(0,f.existsSync)(c)?(0,f.readFileSync)(c,"utf-8"):"",n="collections/_root";a.push({importPath:n,resourceType:"collection",title:T(r.name),description:r.description||null,body:l,bodyHash:D(l),metadata:{},manifestMetadata:{...r.author?{author:r.author}:{},...r.homepage?{homepage:r.homepage}:{},...r.license?{license:r.license}:{}}}),r.resources.length>0&&$.push({collectionImportPath:n,memberImportPaths:r.resources})}}catch{}break}}{let u=function(r,c,l){if(!(l>4))for(let n of B(r)){if(s.has(n))continue;let d=(0,h.join)(r,n),v=c?`${c}/${n}`:n;for(let b of K){if(b.path===X)continue;let i=(0,h.join)(d,b.path);if((0,f.existsSync)(i)){if(o.has(v))break;o.add(v);try{let p=JSON.parse((0,f.readFileSync)(i,"utf-8")),m=L(d,v);if(m.resources.length===0)break;a.push(...m.resources),$.push(...m.memberships);let H=m.resources.filter(k=>k.resourceType!=="collection").map(k=>({resourceRef:k.importPath})),P=b.converter(p,H),y=(0,h.join)(d,"README.md"),F=(0,f.existsSync)(y)?(0,f.readFileSync)(y,"utf-8"):"",S=`${v}/_collection`;a.push({importPath:S,resourceType:"collection",title:T(P.name),description:P.description||null,body:F,bodyHash:D(F),metadata:{},manifestMetadata:{...P.author?{author:P.author}:{},...P.homepage?{homepage:P.homepage}:{},...P.license?{license:P.license}:{}}}),$.push({collectionImportPath:S,memberImportPaths:m.resources.map(k=>k.importPath)}),C||(C=p.name||void 0),j||(j=b.formatLabel)}catch{}break}}u(d,v,l+1)}};var E=u;let o=new Set,g=new Set(Q.map(r=>r.folder)),s=new Set([...g,"worktrees","plugins","node_modules","todos"]);u(e,"",0)}let A=(0,h.join)(e,"files");if((0,f.existsSync)(A)&&q(A)&&!a.some(o=>o.resourceType==="file"))for(let o of z(A)){if(!o.endsWith(".md"))continue;let g=(0,h.join)(A,o),s=(0,f.readFileSync)(g,"utf-8"),u=O(s),r=u.name||(0,h.basename)(o,".md"),c=`files/${(0,h.basename)(o,".md")}`;a.some(l=>l.importPath===c)||a.push({importPath:c,resourceType:"file",title:r,description:u.description||null,body:u.body,bodyHash:D(s),metadata:{}})}return{resources:[...a.filter(o=>o.resourceType!=="collection"),...a.filter(o=>o.resourceType==="collection")],collectionMemberships:$,pluginName:C,formatLabel:j}}0&&(module.exports={discoverResources});
|