@chatpanel/bridge 0.24.1 → 0.29.4

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/src/skills.js CHANGED
@@ -1 +1 @@
1
- import{readFile as v,readdir as H,stat as A,realpath as _}from"node:fs/promises";import{createHash as q}from"node:crypto";import w from"node:os";import{delimiter as T,isAbsolute as L,join as g,resolve as k,sep as O}from"node:path";import{isSafeSkillPath as j,normalizeSkill as W,SKILL_FILE_KINDS as I}from"./events/skill-manifest.js";import{scanSkill as X,admits as B}from"./events/skill-scan.js";const G=512*1024,N=4*1024*1024,C=500,P=3,Z=new Set([".git",".svn",".hg",".cache",".DS_Store","node_modules"]),R=Object.freeze([{source:"local",label:"ChatPanel",segments:[".chatpanel","skills"],writable:!0},{source:"agents-dir",label:"Shared (~/.agents)",segments:[".agents","skills"]},{source:"claude",label:"Claude Code",segments:[".claude","skills"]},{source:"codex",label:"Codex",segments:[".codex","skills"]},{source:"copilot",label:"GitHub Copilot",segments:[".copilot","skills"],projectSegments:[".github","skills"]},{source:"gemini",label:"Antigravity / Gemini",segments:[".gemini","skills"]},{source:"opencode",label:"OpenCode",segments:[".opencode","skills"]},{source:"kiro",label:"Kiro",segments:[".kiro","skills"]},{source:"pi",label:"Pi",segments:[".pi","skills"]},{source:"hermes",label:"Hermes",segments:[".hermes","skills"]}]);function $(t){return(Array.isArray(t)?t:[]).map(e=>String(e||"").trim()).filter(Boolean).filter(e=>L(e)).slice(0,16)}function z(t){const e=String(t||"").trim();if(!e||!L(e))return[];const n=k(e);return R.map(r=>({dir:g(n,...r.projectSegments||r.segments),source:r.source,label:r.label,writable:!1,project:n}))}function D(t=process.env,e=w.homedir(),n=[],r=""){const s=String(t.CHATPANEL_SKILL_DIRS||"").split(/\r?\n/).flatMap(o=>o.split(T)).map(o=>o.trim()).filter(Boolean),i=[...new Set([...s,...$(n)])];return[...z(r),...R.map(o=>({dir:g(e,...o.segments),source:o.source,label:o.label,writable:!!o.writable})),...i.map(o=>({dir:k(o),source:"external",label:"Custom folder",writable:!1}))]}function J(t){const e=/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(String(t||""));if(!e)return{meta:{},body:String(t||"")};const n={},r=[{indent:-1,obj:n}];for(const s of e[1].split(/\r?\n/)){if(!s.trim()||s.trim().startsWith("#"))continue;const i=s.length-s.trimStart().length,o=s.trim(),l=/^([A-Za-z_][\w.-]*)\s*:\s*(.*)$/.exec(o);if(!l)continue;for(;r.length>1&&i<=r[r.length-1].indent;)r.pop();const c=r[r.length-1].obj,[,a,u]=l;if(u===""){const p={};c[a]=p,r.push({indent:i,obj:p});continue}c[a]=Q(u)}return{meta:n,body:String(t).slice(e[0].length)}}function Q(t){const e=t.trim().replace(/\s+#.*$/,"").trim();return/^\[.*\]$/.test(e)?e.slice(1,-1).split(",").map(n=>F(n.trim())).filter(Boolean):e==="true"?!0:e==="false"?!1:F(e)}const F=t=>/^(['"]).*\1$/.test(t)?t.slice(1,-1):t,K=/^[a-z0-9][a-z0-9_-]*$/;function U({meta:t,body:e,dirName:n,relPath:r,source:s,files:i,hash:o}){const l=typeof t.name=="string"&&t.name.trim()?t.name.trim():n,c=K.test(String(l))?String(l):n,a={};for(const u of I){const p=i.filter(m=>m.startsWith(`${u}/`)).map(m=>m.slice(u.length+1));p.length&&(a[u]=p)}return W({id:c,name:String(l),command:K.test(c)?c:"",description:typeof t.description=="string"?t.description:"",prompt:e.trim(),...typeof t.version=="string"?{version:t.version}:{},...Array.isArray(t.platforms)?{platforms:t.platforms}:{},...Object.keys(a).length?{files:a}:{},origin:{source:s,id:r,hash:o}})}function V(t,e=process.platform){const n=t?.platforms;if(!Array.isArray(n)||!n.length)return!0;const r=e==="darwin"?"macos":e==="win32"?"windows":"linux";return n.includes(r)}async function M(t){try{return await H(t,{withFileTypes:!0})}catch{return[]}}async function Y(t){const e=[];for(const n of I)for(const r of await M(g(t,n))){if(!r.isFile())continue;const s=`${n}/${r.name}`;if(j(s)&&e.push(s),e.length>=200)return e}return e}async function tt(t,e,n){let r;try{const p=await A(g(t,"SKILL.md"));if(!p.isFile()||p.size>G)return null;r=await v(g(t,"SKILL.md"),"utf8")}catch{return null}const{meta:s,body:i}=J(r),o=`sha256-${q("sha256").update(r).digest("hex").slice(0,32)}`,l=e.split("/").pop(),c=await Y(t),a=U({meta:s,body:i,dirName:l,relPath:e,source:n,files:c,hash:o}),u=X({name:a.name,prompt:a.prompt,files:c||[]});return a.origin={...a.origin,scanned:{verdict:u.verdict,scanner:u.scanner,findings:u.findings.length}},{skill:a,dir:t,scan:u}}async function et({roots:t,extraDirs:e=[],workdir:n="",platform:r=process.platform}={}){t=t||D(process.env,w.homedir(),e,n);const s=new Map,i=[],o=[];for(const{dir:l,source:c,project:a}of t){const u=async(p,m,b)=>{if(!(s.size>=C||b>P))for(const d of await M(p)){if(s.size>=C)return;if(!d.isDirectory()||Z.has(d.name))continue;const S=m?`${m}/${d.name}`:d.name,y=g(p,d.name),f=d.name.startsWith(".")?null:await tt(y,S,c).catch(x=>(i.push({path:S,reason:String(x?.message||x)}),null));f?B(f.scan?.verdict)?!s.has(f.skill.id)&&V(f.skill,r)&&(a&&(f.skill.origin={...f.skill.origin,project:a}),s.set(f.skill.id,{...f,root:l,source:c})):o.push({id:f.skill.id,path:S,verdict:f.scan.verdict,findings:f.scan.findings}):await u(y,S,b+1)}};await u(l,"",1)}return{index:s,problems:i,quarantined:o}}function ct(t){return[...t.values()].map(({skill:e})=>{const{prompt:n,...r}=e;return{...r,promptChars:(n||"").length}})}function ut(t,e){const n=t.get(String(e||""));return n?n.skill:null}async function pt(t,e,n){const r=t.get(String(e||""));if(!r)return{error:"unknown skill"};if(!j(n))return{error:"unsafe path"};if(String(n).split("/")[0]==="scripts")return{error:"scripts are not readable as text"};const s=k(r.dir,n);let i;try{i=await _(s)}catch{return{error:"not found"}}const o=await _(r.dir).catch(()=>r.dir);if(i!==o&&!i.startsWith(o+O))return{error:"outside package"};const l=await A(i).catch(()=>null);return l?.isFile()?l.size>N?{error:"file too large"}:{path:n,text:await v(i,"utf8")}:{error:"not found"}}const nt=5e3;let h=null;async function E({force:t=!1,now:e=Date.now,extraDirs:n=[],workdir:r=""}={}){const s=e(),o=[z(r)[0]?.project||"",...$(n).map(c=>k(c)).sort()].join("|");if(!t&&h&&h.key===o&&s-h.at<nt)return h.value;const l=await et({extraDirs:n,workdir:r});return h={at:s,key:o,value:l},l}function ft(){h=null}async function mt(t=[]){const{index:e,problems:n,quarantined:r}=await E({extraDirs:t}),s=new Set([...e.values()].map(i=>i.root));return{count:e.size,roots:D(process.env,w.homedir(),t).filter(i=>s.has(i.dir)).map(i=>i.dir),sources:[...new Set([...e.values()].map(i=>i.source))].sort(),...n.length?{problems:n.length}:{},...r?.length?{quarantined:r.length}:{}}}async function dt(t=[],e=""){const{quarantined:n}=await E({extraDirs:t,workdir:e});return n||[]}export{R as AGENT_SKILL_DIRS,ft as clearSkillCache,ct as listRecords,J as parseFrontmatter,V as platformOk,z as projectSkillRoots,dt as quarantinedSkills,pt as readPackageFile,ut as readRecord,et as scanSkills,E as skillIndex,U as skillRecord,D as skillRoots,mt as skillsHealth};
1
+ import{readFile as v,readdir as E,stat as L,realpath as _}from"node:fs/promises";import{createHash as H}from"node:crypto";import S from"node:os";import{delimiter as $,isAbsolute as A,join as f,resolve as k,sep as q}from"node:path";import{isSafeSkillPath as I,SKILL_FILE_KINDS as T}from"./events/skill-manifest.js";import{skillFromPackage as N}from"./events/skill-package.js";import{parseFrontmatter as C}from"./events/frontmatter.js";import{scanSkill as P,admits as X}from"./events/skill-scan.js";const G=512*1024,O=4*1024*1024,j=500,B=3,W=new Set([".git",".svn",".hg",".cache",".DS_Store","node_modules"]),F=Object.freeze([{source:"local",label:"ChatPanel",segments:[".chatpanel","skills"],writable:!0},{source:"agents-dir",label:"Shared (~/.agents)",segments:[".agents","skills"]},{source:"claude",label:"Claude Code",segments:[".claude","skills"]},{source:"codex",label:"Codex",segments:[".codex","skills"]},{source:"copilot",label:"GitHub Copilot",segments:[".copilot","skills"],projectSegments:[".github","skills"]},{source:"gemini",label:"Antigravity / Gemini",segments:[".gemini","skills"]},{source:"opencode",label:"OpenCode",segments:[".opencode","skills"]},{source:"kiro",label:"Kiro",segments:[".kiro","skills"]},{source:"pi",label:"Pi",segments:[".pi","skills"]},{source:"hermes",label:"Hermes",segments:[".hermes","skills"]}]);function R(t){return(Array.isArray(t)?t:[]).map(e=>String(e||"").trim()).filter(Boolean).filter(e=>A(e)).slice(0,16)}function D(t){const e=String(t||"").trim();if(!e||!A(e))return[];const r=k(e);return F.map(n=>({dir:f(r,...n.projectSegments||n.segments),source:n.source,label:n.label,writable:!1,project:r}))}function K(t=process.env,e=S.homedir(),r=[],n=""){const o=String(t.CHATPANEL_SKILL_DIRS||"").split(/\r?\n/).flatMap(i=>i.split($)).map(i=>i.trim()).filter(Boolean),s=[...new Set([...o,...R(r)])];return[...D(n),...F.map(i=>({dir:f(e,...i.segments),source:i.source,label:i.label,writable:!!i.writable})),...s.map(i=>({dir:k(i),source:"external",label:"Custom folder",writable:!1}))]}const ce=/^[a-z0-9][a-z0-9_-]*$/,J=N;function Q(t,e=process.platform){const r=t?.platforms;if(!Array.isArray(r)||!r.length)return!0;const n=e==="darwin"?"macos":e==="win32"?"windows":"linux";return r.includes(n)}async function z(t){try{return await E(t,{withFileTypes:!0})}catch{return[]}}async function U(t){const e=[];for(const r of T)for(const n of await z(f(t,r))){if(!n.isFile())continue;const o=`${r}/${n.name}`;if(I(o)&&e.push(o),e.length>=200)return e}return e}async function V(t,e,r){let n;try{const g=await L(f(t,"SKILL.md"));if(!g.isFile()||g.size>G)return null;n=await v(f(t,"SKILL.md"),"utf8")}catch{return null}const{meta:o,body:s}=C(n),i=`sha256-${H("sha256").update(n).digest("hex").slice(0,32)}`,l=e.split("/").pop(),u=await U(t),c=J({meta:o,body:s,dirName:l,relPath:e,source:r,files:u,hash:i}),p=P({name:c.name,prompt:c.prompt,files:u||[]});return c.origin={...c.origin,scanned:{verdict:p.verdict,scanner:p.scanner,findings:p.findings.length}},{skill:c,dir:t,scan:p}}async function Y({roots:t,extraDirs:e=[],workdir:r="",platform:n=process.platform}={}){t=t||K(process.env,S.homedir(),e,r);const o=new Map,s=[],i=[];for(const{dir:l,source:u,project:c}of t){const p=async(g,w,b)=>{if(!(o.size>=j||b>B))for(const m of await z(g)){if(o.size>=j)return;if(!m.isDirectory()||W.has(m.name))continue;const h=w?`${w}/${m.name}`:m.name,x=f(g,m.name),a=m.name.startsWith(".")?null:await V(x,h,u).catch(y=>(s.push({path:h,reason:String(y?.message||y)}),null));a?X(a.scan?.verdict)?!o.has(a.skill.id)&&Q(a.skill,n)&&(c&&(a.skill.origin={...a.skill.origin,project:c}),o.set(a.skill.id,{...a,root:l,source:u})):i.push({id:a.skill.id,path:h,verdict:a.scan.verdict,findings:a.scan.findings}):await p(x,h,b+1)}};await p(l,"",1)}return{index:o,problems:s,quarantined:i}}function ue(t){return[...t.values()].map(({skill:e})=>{const{prompt:r,...n}=e;return{...n,promptChars:(r||"").length}})}function pe(t,e){const r=t.get(String(e||""));return r?r.skill:null}async function me(t,e,r){const n=t.get(String(e||""));if(!n)return{error:"unknown skill"};if(!I(r))return{error:"unsafe path"};if(String(r).split("/")[0]==="scripts")return{error:"scripts are not readable as text"};const o=k(n.dir,r);let s;try{s=await _(o)}catch{return{error:"not found"}}const i=await _(n.dir).catch(()=>n.dir);if(s!==i&&!s.startsWith(i+q))return{error:"outside package"};const l=await L(s).catch(()=>null);return l?.isFile()?l.size>O?{error:"file too large"}:{path:r,text:await v(s,"utf8")}:{error:"not found"}}const Z=5e3;let d=null;async function M({force:t=!1,now:e=Date.now,extraDirs:r=[],workdir:n=""}={}){const o=e(),i=[D(n)[0]?.project||"",...R(r).map(u=>k(u)).sort()].join("|");if(!t&&d&&d.key===i&&o-d.at<Z)return d.value;const l=await Y({extraDirs:r,workdir:n});return d={at:o,key:i,value:l},l}function fe(){d=null}async function de(t=[]){const{index:e,problems:r,quarantined:n}=await M({extraDirs:t}),o=new Set([...e.values()].map(s=>s.root));return{count:e.size,roots:K(process.env,S.homedir(),t).filter(s=>o.has(s.dir)).map(s=>s.dir),sources:[...new Set([...e.values()].map(s=>s.source))].sort(),...r.length?{problems:r.length}:{},...n?.length?{quarantined:n.length}:{}}}async function ge(t=[],e=""){const{quarantined:r}=await M({extraDirs:t,workdir:e});return r||[]}export{F as AGENT_SKILL_DIRS,fe as clearSkillCache,ue as listRecords,C as parseFrontmatter,Q as platformOk,D as projectSkillRoots,ge as quarantinedSkills,me as readPackageFile,pe as readRecord,Y as scanSkills,M as skillIndex,J as skillRecord,K as skillRoots,de as skillsHealth};
package/src/workdir.js CHANGED
@@ -1 +1 @@
1
- import{mkdirSync as s}from"node:fs";import u from"node:os";import n from"node:path";const c=n.join(u.homedir(),".chatpanel","workspace");function p(t){const r=t&&String(t).trim()?n.resolve(String(t).trim()):c;try{s(r,{recursive:!0})}catch{}return r}function l(t){return!(t&&String(t).trim())}function m(t,r,e=n){const o=String(t||"");if(!o)return"";if(!r||!e.isAbsolute(o))return o;const i=e.relative(r,o);return i?i.startsWith("..")||e.isAbsolute(i)?o:i:"."}function h(t,r,e){return t!=="codex"||r==="bypassPermissions"?"":r!=="acceptEdits"?"Codex is read-only in this mode — set Permissions to “auto-edit files” to let it write.":`Codex may only create or edit files inside ${e}. To work on another project, set this agent’s Working directory to it.`}export{c as DEFAULT_WORKSPACE,m as displayPath,l as isDefaultWorkdir,p as resolveWorkdir,h as writeScopeNote};
1
+ import{mkdirSync as s}from"node:fs";import a from"node:os";import n from"node:path";const u=n.join(a.homedir(),".chatpanel","workspace");function h(t){const r=t&&String(t).trim()?n.resolve(String(t).trim()):u;try{s(r,{recursive:!0})}catch{}return r}function p(t){return!(t&&String(t).trim())}function m(t,r,i=n){const e=String(t||"");if(!e)return"";if(!r||!i.isAbsolute(e))return e;const o=i.relative(r,e);return o?o.startsWith("..")||i.isAbsolute(o)?e:o:"."}function y(t,r,i,e=[]){if(t!=="codex"||r==="bypassPermissions")return"";if(r!=="acceptEdits")return"Codex is read-only in this mode — set Permissions to “auto-edit files” to let it write.";const o=Array.isArray(e)?e.filter(Boolean):[];return`Codex may only create or edit files inside ${o.length?`${i}, ${o.join(", ")}`:String(i)}. To work on another project, set this agent’s Working directory to it${o.length?"":", or allow the folder in Settings › Runtime"}.`}export{u as DEFAULT_WORKSPACE,m as displayPath,p as isDefaultWorkdir,h as resolveWorkdir,y as writeScopeNote};