@zibby/skills 0.1.15 → 0.1.17
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/git.js +2 -2
- package/dist/index.js +57 -57
- package/dist/package.json +1 -1
- package/docs/concepts/sub-graphs.md +227 -0
- package/package.json +1 -1
package/dist/git.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as C}from"child_process";import{existsSync as g,mkdirSync as T,readdirSync as O,statSync as j,readFileSync as L}from"fs";import{resolve as E,join as u,basename as A}from"path";var D="/workspace/repos",N=".zibby/repos";function $(a){return process.env.REPOS?D:E(a,N)}function R(){let a=process.env.REPOS;if(!a)return[];try{let i=JSON.parse(a);return Array.isArray(i)?i:[]}catch{return[]}}function S(a){return String(a).replace(/\//g,"-")}function x(a,i,e={}){return new Promise((r,d)=>{let s=C(a,{cwd:i,shell:!0,env:{...process.env,GIT_TERMINAL_PROMPT:"0",...e}}),t="",n="";s.stdout.on("data",c=>{t+=c.toString()}),s.stderr.on("data",c=>{n+=c.toString()}),s.on("close",c=>{c!==0?d(new Error(`Exit ${c}: ${n.trim()||t.trim()}`)):r(t.trim())}),s.on("error",c=>d(c))})}var M={id:"git",description:"Clone and manage git repositories for codebase analysis",envKeys:["GITHUB_TOKEN","GITLAB_TOKEN"],promptFragment:`## Git Repositories
|
|
2
2
|
You can clone and explore git repositories locally for codebase analysis:
|
|
3
3
|
- git_checkout: Clone a repo (or pull if already cloned). Supports GitHub and GitLab with auto-auth.
|
|
4
4
|
- git_list_repos: List locally cloned repos
|
|
@@ -9,4 +9,4 @@ When a test ticket lacks context, use this workflow:
|
|
|
9
9
|
2. Use git_explore to understand the project structure
|
|
10
10
|
3. Use shell commands (grep, cat) to read specific files for deeper understanding
|
|
11
11
|
4. Use GitHub/GitLab skills to read related PRs and commits
|
|
12
|
-
5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(
|
|
12
|
+
5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(a,i,e){let r=e?.options?.workspace||process.cwd();try{switch(a){case"git_checkout":return await U(i,r);case"git_list_repos":return G(i,r);case"git_explore":return J(i,r);default:return JSON.stringify({error:`Unknown tool: ${a}`})}}catch(d){return JSON.stringify({error:d.message})}},tools:[{name:"git_checkout",description:'Clone a git repository locally (or pull latest if already cloned). Auto-authenticates with GitHub/GitLab tokens if available. When running inside a Zibby workflow, `url` may be the name of a configured repo (e.g. "org/repo") and the platform-injected clone URL + token will be used automatically.',input_schema:{type:"object",properties:{url:{type:"string",description:'Full URL ("https://github.com/org/repo") OR a configured repo name from the project ("org/repo")'},branch:{type:"string",description:"Branch to checkout (default: repo default branch, or whatever was configured)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: derived from URL/name)"}},required:["url"]}},{name:"git_list_repos",description:"List locally cloned repositories",input_schema:{type:"object",properties:{}}},{name:"git_explore",description:"Quick structural overview of a cloned repo: key files, package.json info, directory tree (top 2 levels), detected framework/language",input_schema:{type:"object",properties:{repo:{type:"string",description:"Repo name (as listed by git_list_repos)"},depth:{type:"number",description:"Directory tree depth (default: 2)"}},required:["repo"]}}]};async function U(a,i){let{url:e,branch:r,shallow:d=!0,name:s}=a,n=R().find(f=>f.name===e),c=null;n?(e=n.cloneUrl||n.url||e,c=n.provider||"github",s||(s=S(n.name)),!r&&n.branch&&(r=n.branch)):!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let y=s||A(e.replace(/\.git$/,"")),w=$(i);T(w,{recursive:!0});let p=u(w,y),m=e,_=process.env.GITHUB_TOKEN,o=process.env.GITLAB_TOKEN,k=process.env.GITLAB_URL;if(c==="gitlab"&&o)try{let f=new URL(e).host;m=e.replace(`https://${f}`,`https://oauth2:${o}@${f}`)}catch{}else if(e.includes("github.com")&&_)m=e.replace("https://github.com",`https://x-access-token:${_}@github.com`);else if(o&&k)try{let f=new URL(k).host;e.includes(f)&&(m=e.replace(`https://${f}`,`https://oauth2:${o}@${f}`))}catch{}if(g(u(p,".git"))){let f=r?`git -C "${p}" fetch origin ${r} && git -C "${p}" checkout ${r} && git -C "${p}" pull origin ${r}`:`git -C "${p}" pull`;await x(f,i);let l=await x(`git -C "${p}" log -1 --format="%h %s"`,i);return JSON.stringify({action:"updated",repo:y,path:p,branch:r||"default",head:l})}let h=["git","clone"];d&&h.push("--depth","1"),r&&h.push("--branch",r),h.push(`"${m}"`,`"${p}"`),await x(h.join(" "),i);let v=await x(`git -C "${p}" log -1 --format="%h %s"`,i);return JSON.stringify({action:"cloned",repo:y,path:p,branch:r||"default",shallow:d,head:v})}function G(a,i){let e=$(i),r=new Map;if(g(e))for(let t of O(e,{withFileTypes:!0})){if(!t.isDirectory())continue;let n=u(e,t.name);if(!g(u(n,".git")))continue;let c=j(n);r.set(t.name,{name:t.name,path:n,lastModified:c.mtime.toISOString(),cloned:!0})}let d=R(),s=[];for(let t of d){let n=S(t.name),c=r.get(n);s.push({name:t.name,path:u(e,n),cloned:!!c,lastModified:c?.lastModified||null,configured:!0}),r.delete(n)}for(let t of r.values())s.push({...t,configured:!1});return JSON.stringify({repos:s,total:s.length,directory:e})}function J(a,i){let{repo:e,depth:r=2}=a,d=$(i),s=g(u(d,e))?u(d,e):u(d,S(e));if(!g(s))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let t={repo:e,path:s},n=u(s,"package.json");if(g(n))try{let o=JSON.parse(L(n,"utf-8"));t.packageJson={name:o.name,version:o.version,scripts:o.scripts?Object.keys(o.scripts):[],dependencies:o.dependencies?Object.keys(o.dependencies).slice(0,30):[],devDependencies:o.devDependencies?Object.keys(o.devDependencies).slice(0,20):[]},o.dependencies?.react?t.framework="React":o.dependencies?.next?t.framework="Next.js":o.dependencies?.vue?t.framework="Vue":o.dependencies?.angular?t.framework="Angular":o.dependencies?.express?t.framework="Express":o.dependencies?.fastify&&(t.framework="Fastify")}catch{}let c=u(s,"pyproject.toml");g(c)&&(t.language="Python");let y=u(s,"go.mod");g(y)&&(t.language="Go");let w=u(s,"Cargo.toml");g(w)&&(t.language="Rust"),g(n)&&(t.language=t.language||"JavaScript/TypeScript");let p=[];function m(o,k,h){if(h>r)return;let v;try{v=O(o,{withFileTypes:!0})}catch{return}let f=v.filter(l=>!l.name.startsWith(".")&&l.name!=="node_modules"&&l.name!=="__pycache__"&&l.name!=="dist"&&l.name!=="build"&&l.name!==".git").sort((l,b)=>l.isDirectory()!==b.isDirectory()?l.isDirectory()?-1:1:l.name.localeCompare(b.name));for(let l of f){let b=l.isDirectory();p.push(`${k}${b?"\u{1F4C1}":"\u{1F4C4}"} ${l.name}`),b&&h<r&&m(u(o,l.name),`${k} `,h+1)}}m(s,"",1),t.tree=p.slice(0,80),p.length>80&&(t.treeTruncated=!0);let _=["README.md","README.rst","src/App.tsx","src/App.jsx","src/App.js","src/routes.tsx","src/routes.js","app/routes.tsx","app/routes.js","src/index.tsx","src/index.ts","src/main.tsx","src/main.ts","pages/_app.tsx","pages/_app.js","app/layout.tsx","docker-compose.yml","Dockerfile",".env.example"];return t.keyFilesFound=_.filter(o=>g(u(s,o))),JSON.stringify(t)}export{M as gitSkill};
|