skillset 0.0.1
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/hook.js +14 -0
- package/dist/index.js +110 -0
- package/dist/types/cache/index.d.ts +9 -0
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config/index.d.ts +29 -0
- package/dist/types/doctor.d.ts +12 -0
- package/dist/types/format/index.d.ts +3 -0
- package/dist/types/hook.d.ts +1 -0
- package/dist/types/hooks/hook-runner.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/indexer/index.d.ts +6 -0
- package/dist/types/logger/index.d.ts +2 -0
- package/dist/types/resolver/index.d.ts +3 -0
- package/dist/types/tokenizer/index.d.ts +2 -0
- package/dist/types/tree/index.d.ts +24 -0
- package/dist/types/tree/markdown.d.ts +18 -0
- package/dist/types/types.d.ts +43 -0
- package/package.json +53 -0
package/dist/hook.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var T=Object.create;var{getPrototypeOf:N,defineProperty:d,getOwnPropertyNames:G}=Object;var F=Object.prototype.hasOwnProperty;var In=(n,t,i)=>{i=n!=null?T(N(n)):{};let s=t||!n||!n.__esModule?d(i,"default",{value:n,enumerable:!0}):i;for(let o of G(n))if(!F.call(s,o))d(s,o,{get:()=>n[o],enumerable:!0});return s};var Cn=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var H=(n,t)=>{for(var i in t)d(n,i,{get:t[i],enumerable:!0,configurable:!0,set:(s)=>t[i]=()=>s})};var E=(n,t)=>()=>(n&&(t=n(n=0)),t);var Pn=import.meta.require;var Rn={};H(Rn,{writeConfig:()=>fn,setConfigValue:()=>kn,readConfigByScope:()=>mn,modeLabel:()=>an,loadConfig:()=>k,getConfigValue:()=>pn,getConfigPath:()=>hn,ensureConfigFiles:()=>un,CONFIG_PATHS:()=>a});import{existsSync as $,mkdirSync as Q,readFileSync as cn,writeFileSync as Y}from"fs";import{homedir as en}from"os";import{join as j}from"path";function w(n){if(!$(n))return null;try{let t=cn(n,"utf8");return JSON.parse(t)}catch(t){return console.warn(`wskill: failed to read config ${n}:`,t),null}}function Z(n,t){let i={...n};for(let[s,o]of Object.entries(t)){let l=s;if(o&&typeof o==="object"&&!Array.isArray(o))i[l]=Z(i[l]??{},o);else if(o!==void 0)i[l]=o}return i}function k(){return[L,w(a.project)??{},w(a.projectLocal)??{},w(a.user)??{}].reduce((i,s)=>Z(i,s),L)}function un(){for(let n of[a.project,a.projectLocal,a.user]){let t=n.split("/").slice(0,-1).join("/");if(!$(t))Q(t,{recursive:!0});if(!$(n))Y(n,JSON.stringify(L,null,2))}}function an(n){return n==="strict"?"strict":"warn"}function fn(n,t){let i=n==="local"?a.projectLocal:n==="user"?a.user:a.project,s=i.split("/").slice(0,-1).join("/");if(!$(s))Q(s,{recursive:!0});Y(i,`${JSON.stringify(t,null,2)}
|
|
3
|
+
`)}function mn(n){let t=n==="local"?a.projectLocal:n==="user"?a.user:a.project;return w(t)??{}}function hn(n){return n==="local"?a.projectLocal:n==="user"?a.user:a.project}function pn(n,t){let i=t.split("."),s=n;for(let o of i){if(typeof s!=="object"||s===null)return;s=s[o]}return s}function kn(n,t,i){let s=t.split("."),o=JSON.parse(JSON.stringify(n)),l=o;for(let e=0;e<s.length-1;e++){let u=s[e];if(!u)continue;if(!(u in l)||typeof l[u]!=="object")l[u]={};l=l[u]}let r=s[s.length-1];if(r)l[r]=i;return o}var L,a;var b=E(()=>{L={version:1,mode:"warn",showStructure:!1,maxLines:500,mappings:{},namespaceAliases:{}},a={project:j(process.cwd(),".claude","wskill","config.json"),projectLocal:j(process.cwd(),".claude","wskill","config.local.json"),user:j(en(),".claude","wskill","config.json")}});import{existsSync as q,mkdirSync as A,readFileSync as _,renameSync as nn,writeFileSync as tn}from"fs";import{homedir as sn}from"os";import{dirname as on,join as M}from"path";var R={version:1,structureTTL:3600,skills:{}},S={project:M(process.cwd(),".claude","wskill","cache.json"),user:M(sn(),".claude","wskill","cache.json")};function W(n){if(!q(n))return null;try{let t=_(n,"utf8");return JSON.parse(t)}catch(t){return console.warn(`wskill: failed to read cache ${n}:`,t),null}}function p(){let n=W(S.project)??R,t=W(S.user)??R;return{...R,skills:{...t.skills,...n.skills},structureTTL:n.structureTTL??t.structureTTL??R.structureTTL,version:1}}function ln(n){let t=on(n);if(!q(t))A(t,{recursive:!0})}function rn(n,t){ln(n);let i=`${n}.tmp`;tn(i,JSON.stringify(t,null,2)),nn(i,n)}function x(n,t){let i=S[n],s=W(i)??R,o=t(s);rn(i,o)}b();import{readFileSync as gn}from"fs";function wn(){return"## wskill: Resolved Skills\n\nThe user invoked skills explicitly via `w/alias`. These are loaded below. Ignore the literal `w/...` tokens in the prompt.\n\n---"}function $n(n,t){let i=n.skill,s=[];if(s.push(`### ${n.invocation.raw}`),s.push(""),s.push(`- **Path:** ${i.path}`),s.push(`- **Name:** ${i.name}`),i.description)s.push(`- **Description:** ${i.description}`);if(t.showStructure&&i.structure)s.push("- **Structure:**"),s.push("```"),s.push(i.structure.trim()),s.push("```");let o=vn(i,t.maxLines);if(s.push(`
|
|
4
|
+
\`\`\`markdown skill:${n.invocation.alias}`),s.push(o.block),s.push("```\n"),o.truncated){let l=t.maxLines+1;s.push(`**Truncated:** Lines 1-${t.maxLines} of ${i.lineCount??"?"}`),s.push(`Continue: sed -n '${l},${i.lineCount??""}p' ${i.path}`)}return s.join(`
|
|
5
|
+
`)}function vn(n,t){try{let s=gn(n.path,"utf8").split(/\r?\n/),o=s.length>t,l=o?s.slice(0,t):s;return{block:dn(l.join(`
|
|
6
|
+
`)),truncated:o}}catch{return{block:"(failed to read skill content)",truncated:!1}}}function dn(n){if(!n.startsWith(`---
|
|
7
|
+
`))return n;let t=n.indexOf(`
|
|
8
|
+
---`,4);if(t===-1)return n;return n.slice(t+4).trimStart()}function Sn(n){let t=[];for(let i of n){if(i.skill)continue;if(i.reason==="ambiguous"&&i.candidates?.length){let s=i.candidates.map((o)=>o.skillRef).join(", ");t.push(`- **Ambiguous:** ${i.invocation.raw} \u2192 ${s}`)}else if(i.reason==="unmatched")t.push(`- **Unmatched:** ${i.invocation.raw}`);else if(i.reason)t.push(`- **${i.reason}:** ${i.invocation.raw}`)}if(!t.length)return null;return["---","","## wskill: Warnings","",...t].join(`
|
|
9
|
+
`)}function z(n,t){let i=[wn()];for(let o of n){if(!o.skill)continue;i.push("",$n(o,t))}let s=Sn(n);if(s)i.push("",s);return{resolved:n,warnings:s?[s]:[],context:i.join(`
|
|
10
|
+
`)}}import{readFileSync as Wn,readdirSync as B}from"fs";import{homedir as J}from"os";import{join as m,relative as y,sep as h}from"path";var jn="SKILL.md";function V(n){let t=[];try{let i=B(n,{withFileTypes:!0});for(let s of i){let o=m(n,s.name);if(s.isDirectory())t.push(...V(o));else if(s.isFile()&&s.name===jn)t.push(o)}}catch{}return t}function Ln(n,t){let i=J();if(n.startsWith(m(t,".claude","skills")))return`project:${y(m(t,".claude","skills"),n).split(h)[0]}`;if(n.startsWith(m(i,".claude","skills")))return`user:${y(m(i,".claude","skills"),n).split(h)[0]}`;let s=m(i,".claude","plugins");if(n.startsWith(s)){let o=y(s,n).split(h),l=o[0],r=o.slice(2)[0]??o[0];return`plugin:${l}/${r}`}return`skill:${n.split(h).slice(-2,-1)[0]}`}function bn(n,t){let s=Wn(n,"utf8").split(/\r?\n/),o=s.find((c)=>c.startsWith("#")),l=n.split(h).slice(-2,-1)[0]??"unknown",r=o?o.replace(/^#+\s*/,"").trim():l,e=s.find((c)=>c.trim().length>0&&!c.startsWith("#"))?.trim();return{skillRef:Ln(n,t),path:n,name:r,description:e,structure:void 0,lineCount:s.length,cachedAt:new Date().toISOString()}}function yn(n){let t=n.split(h);t.pop();let s=[{path:t.join(h),depth:0}],o=[];while(s.length){let l=s.pop();if(!l)break;let{path:r,depth:e}=l,u=B(r,{withFileTypes:!0}).sort((c,f)=>c.name.localeCompare(f.name));for(let c=u.length-1;c>=0;c-=1){let f=u[c];if(!f)continue;let v=`${" ".repeat(e)}${f.isDirectory()?"\u251C\u2500\u2500":"\u251C\u2500\u2500"}`;if(o.push(`${v} ${f.name}`),f.isDirectory())s.push({path:m(r,f.name),depth:e+1})}}return o.join(`
|
|
11
|
+
`)}function D(n={}){let t=n.projectRoot??process.cwd(),i={},o=[m(t,".claude","skills"),m(J(),".claude","skills"),m(J(),".claude")].flatMap((r)=>V(r));for(let r of o){let e=bn(r,t);i[e.skillRef]={...e,structure:yn(r)}}let l={version:1,structureTTL:3600,skills:i};return x("project",()=>l),l}import{appendFileSync as Jn,existsSync as Mn,mkdirSync as qn}from"fs";import{homedir as xn}from"os";import{dirname as Qn,join as K}from"path";var Yn=K(process.cwd(),".claude","wskill","logs","events.jsonl"),Zn=K(xn(),".claude","wskill","logs","events.jsonl");function zn(n){let t=Qn(n);if(!Mn(t))qn(t,{recursive:!0})}function U(n){let t=new Date().toISOString();for(let i of n){if(i.skill&&!i.reason)continue;let s={timestamp:t,invocation:i.invocation.raw,alias:i.invocation.alias,namespace:i.invocation.namespace,reason:i.reason,candidates:i.candidates?.map((l)=>l.skillRef)},o=`${JSON.stringify(s)}
|
|
12
|
+
`;for(let l of[Yn,Zn])zn(l),Jn(l,o)}}b();function Bn(n,t){return n.skills[t]}function Vn(n,t){let i=t.toLowerCase();return Object.values(n.skills).filter((s)=>{let o=s.skillRef.toLowerCase(),l=s.name.toLowerCase()===i||s.name.toLowerCase().includes(i),r=o.endsWith(`/${i}`)||o.endsWith(`:${i}`)||o===i,e=s.path.toLowerCase().includes(i);return l||r||e})}function Dn(n,t){if(!n)return;return t.namespaceAliases[n]??n}function Kn(n,t,i){let s=t??k(),o=i??p(),l=Dn(n.namespace,s),r=s.mappings[n.alias];if(r){let c=Bn(o,r.skillRef);if(c)return{invocation:n,skill:c};return{invocation:n,reason:`mapping points to missing skillRef ${r.skillRef}`}}let e=Vn(o,n.alias);if(l)e=e.filter((c)=>c.skillRef.startsWith(`${l}:`)||c.skillRef.startsWith(`${l}/`)||c.skillRef.startsWith(`${l}`));if(e.length===0)return{invocation:n,reason:"unmatched"};let u=e[0];if(e.length===1&&u)return{invocation:n,skill:u};return{invocation:n,reason:"ambiguous",candidates:e}}function X(n,t,i){let s=t??k(),o=i??p();return n.map((l)=>Kn(l,s,o))}var g=/\bw\/([a-zA-Z0-9_-]+(?::[a-zA-Z0-9_-]+)?)/g;function O(n){return n===void 0||/[\s\[{(<"'`.,;:!?)]/.test(n)}function C(n){let t=[],i=Un(n);for(let s of i){g.lastIndex=0;let o=g.exec(s.text);while(o!==null){let l=o.index,r=l+o[0].length,e=s.text[l-1],u=s.text[r];if(!O(e)||!O(u)){o=g.exec(s.text);continue}let c=o[1];if(!c){o=g.exec(s.text);continue}let[f,v]=c.includes(":")?c.split(":"):[void 0,c];t.push({raw:o[0],alias:v??c,namespace:f}),o=g.exec(s.text)}}return t}function Un(n){let t=n.split(/\r?\n/),i=[],s=!1,o="```",l=[];for(let r of t){let u=r.trim().match(/^(?:```+|~~~+)/);if(u){let c=u[0];if(s){i.push({text:l.join(`
|
|
13
|
+
`)}),l=[],s=!1;let f=r.slice(r.indexOf(c)+c.length);if(f.trim().length)l.push(I(f))}else s=!0,o=c;continue}if(s)continue;l.push(I(r))}if(l.length)i.push({text:l.join(`
|
|
14
|
+
`)});return i}function I(n){let t="",i=!1;for(let s=0;s<n.length;s+=1){let o=n[s];if(o==="`"){i=!i,t+=" ";continue}t+=i?" ":o}return t}async function P(n){let t=Xn(n),i=typeof t?.prompt==="string"?t.prompt:typeof t?.inputText==="string"?t.inputText:n,s=p();if(Object.keys(s.skills).length===0)D(),s=p();let o=C(i);if(o.length===0)return JSON.stringify({hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:""}});let l=k(),r=X(o,l,s);U(r);let e=z(r,l);return JSON.stringify({hookSpecificOutput:{hookEventName:"UserPromptSubmit",additionalContext:e.context}})}function Xn(n){try{return JSON.parse(n)}catch{return null}}async function On(){let n=await Bun.stdin.text(),t=await P(n);console.log(t)}On();
|