@zibby/skills 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/chat-memory.js +29 -27
- package/dist/chat-notify.js +3 -3
- package/dist/github.js +3 -3
- package/dist/index.js +75 -73
- package/dist/integrations.js +1 -1
- package/dist/jira.js +2 -2
- package/dist/lark.js +1 -1
- package/dist/linear.js +14 -14
- package/dist/llm-billing.js +1 -1
- package/dist/package.json +3 -1
- package/dist/plane.js +1 -1
- package/dist/sentry.js +2 -2
- package/dist/slack.js +1 -1
- package/dist/trackers/github-adapter.js +3 -3
- package/dist/trackers/index.js +12 -12
- package/dist/trackers/jira-adapter.js +1 -1
- package/dist/trackers/linear-adapter.js +16 -16
- package/docs/apps/index.md +45 -42
- package/docs/cli-reference.md +2 -2
- package/docs/get-started/install.md +2 -0
- package/docs/get-started/your-first-workflow.md +5 -2
- package/docs/integrations/gitlab.md +43 -0
- package/docs/integrations/lark.md +41 -0
- package/docs/integrations/linear.md +43 -0
- package/docs/integrations/notion.md +33 -0
- package/docs/integrations/plane.md +46 -0
- package/docs/integrations/sentry.md +42 -0
- package/docs/integrations/slack.md +33 -0
- package/docs/intro.md +15 -11
- package/docs/packages/ui-memory.md +1 -1
- package/docs/recipes/bug-autofix.md +85 -0
- package/docs/recipes/github-ai-scout.md +61 -0
- package/docs/recipes/index.md +39 -34
- package/docs/recipes/pipeline-supervisor.md +57 -0
- package/docs/skills/chat-memory.md +39 -10
- package/docs/skills/index.md +4 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import{registerSkill as R}from"@zibby/agent-workflow";import{createRequire as
|
|
1
|
+
import{registerSkill as R}from"@zibby/agent-workflow";import{createRequire as js}from"module";import{join as Ts}from"path";var xs=js(import.meta.url);function Es(){if(process.env.MCP_BROWSER_PATH)return process.env.MCP_BROWSER_PATH;try{return xs.resolve("@zibby/mcp-browser/dist/bin/mcp-browser-zibby.js")}catch{return null}}var Cs="1280x720",Ls="1280x720";function Js({headless:r}={}){if(r===!0)return!0;if(r===!1)return!1;let t=process.env.ZIBBY_HEADLESS;return t==="1"||String(t).toLowerCase()==="true"}function Ps(r,t){let e=(r||[]).filter(s=>s!=="--headless");return t?[...e,"--headless"]:e}var tt={id:"browser",serverName:"playwright",cursorKey:"playwright-official",allowedTools:["mcp__playwright__*"],sessionEnvKey:"ZIBBY_SESSION_INFO",description:"Playwright Browser MCP Server",envKeys:[],tools:[],promptFragment:`Execute this test using the browser tools available to you. You MUST make actual browser tool calls \u2014 do not fabricate results.
|
|
2
2
|
If you DO NOT have access to browser tools \u2192 return {"success": false, "steps": [], "browserClosed": false, "notes": "No browser tools available"}.
|
|
3
|
-
DO NOT return success: true unless you ACTUALLY called browser tools.`,resolve({sessionPath:r,workspace:t,nodeName:e,headless:s}={}){let n=
|
|
3
|
+
DO NOT return success: true unless you ACTUALLY called browser tools.`,resolve({sessionPath:r,workspace:t,nodeName:e,headless:s}={}){let n=Es(),i=r&&e?Ts(r,e):null,o=i||r||t||"test-results",c=Js({headless:s}),a={};if(i&&(a.ZIBBY_NODE_SESSION_PATH=i),r&&(a.ZIBBY_SESSION_PATH=r),!n)throw new Error(`@zibby/mcp-browser is not installed.
|
|
4
4
|
Cloud: verify the Fargate image has it (packages/Dockerfile installs it globally alongside @zibby/cli).
|
|
5
5
|
Local: \`npm install @zibby/mcp-browser\` in your workflow, or use the global @zibby/cli install (which pulls it transitively).
|
|
6
|
-
Override: set MCP_BROWSER_PATH to the path of mcp-browser-zibby.js.`);return{command:"node",args:
|
|
6
|
+
Override: set MCP_BROWSER_PATH to the path of mcp-browser-zibby.js.`);return{command:"node",args:Ps([n,"--isolated",`--save-video=${Cs}`,`--viewport-size=${Ls}`,`--output-dir=${o}`],c),env:a}}};import{createRequire as Ds}from"module";import{resolveIntegrationToken as Ms,clearTokenCache as qs}from"@zibby/core/backend-client.js";var $=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",PLANE:"plane",LINEAR:"linear"}),Us=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"}});var Ks=Ds(import.meta.url);function Bs(){if(process.env.MCP_JIRA_PATH)return process.env.MCP_JIRA_PATH;try{return Ks.resolve("@zibby/mcp-jira/index.js")}catch{return null}}var Fs=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function Gs(r,t){if(!t||!t.length)return r;let e=r;for(let s of t)s.type==="strong"?e=`**${e}**`:s.type==="em"?e=`_${e}_`:s.type==="code"?e=`\`${e}\``:s.type==="strike"?e=`~~${e}~~`:s.type==="link"&&s.attrs?.href&&(e=`[${e}](${s.attrs.href})`);return e}function fe(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(Gs(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
|
|
7
7
|
`);continue}if(s.type==="rule"){e.push(`
|
|
8
8
|
---
|
|
9
|
-
`);continue}let n=s.content?
|
|
9
|
+
`);continue}let n=s.content?fe(s.content,t+1):"";if(s.type==="listItem")e.push(n);else if(s.type==="bulletList"){let i=(s.content||[]).map(o=>`- ${fe(o.content||[],t+1).trim()}`);e.push(`
|
|
10
10
|
${i.join(`
|
|
11
11
|
`)}
|
|
12
|
-
`)}else if(s.type==="orderedList"){let i=(s.content||[]).map((o,c)=>`${c+1}. ${
|
|
12
|
+
`)}else if(s.type==="orderedList"){let i=(s.content||[]).map((o,c)=>`${c+1}. ${fe(o.content||[],t+1).trim()}`);e.push(`
|
|
13
13
|
${i.join(`
|
|
14
14
|
`)}
|
|
15
15
|
`)}else if(s.type==="heading"){let i=s.attrs?.level||2;e.push(`
|
|
16
16
|
|
|
17
17
|
${"#".repeat(i)} ${n.trim()}
|
|
18
18
|
|
|
19
|
-
`)}else
|
|
19
|
+
`)}else Fs.has(s.type)?e.push(`
|
|
20
20
|
|
|
21
21
|
${n}
|
|
22
22
|
`):e.push(n)}return e.join("").replace(/\n{3,}/g,`
|
|
23
23
|
|
|
24
|
-
`)}function ee(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function
|
|
24
|
+
`)}function ee(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function $e(r){return ee(r).replace(/[a-z0-9]+/g,"")}function ye(r,t){let e=ee(r),s=ee(t);if(!e||!s)return 0;if(e===s)return 1;if(e.length===1||s.length===1)return e===s?1:0;let n=l=>{let p=new Map;for(let d=0;d<l.length-1;d++){let m=l.slice(d,d+2);p.set(m,(p.get(m)||0)+1)}return p},i=n(e),o=n(s),c=0,a=0,u=0;for(let l of i.values())a+=l;for(let l of o.values())u+=l;for(let[l,p]of i.entries()){let d=o.get(l)||0;c+=Math.min(p,d)}return 2*c/Math.max(1,a+u)}function z(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function zs(r,t=[]){let e=Array.isArray(t)?t:[];if(e.length===0)return{requested:r||null,resolved:null,strategy:"none"};let s=e.filter(c=>!c.subtask),n=s.length>0?s:e,i=z(r);if(i){let c=n.find(l=>z(l.name)===i);if(c)return{requested:r,resolved:c,strategy:"exact"};let a={task:["task","\u4EFB\u52A1","\u4E8B\u9879","to do","todo"],story:["story","\u7528\u6237\u6545\u4E8B","\u9700\u6C42"],bug:["bug","\u7F3A\u9677","\u95EE\u9898"],improvement:["improvement","\u4F18\u5316","\u6539\u8FDB"],epic:["epic","\u53F2\u8BD7"]};for(let l of Object.values(a)){if(!l.some(d=>z(d)===i))continue;let p=n.find(d=>l.some(m=>z(m)===z(d.name)));if(p)return{requested:r,resolved:p,strategy:"alias"}}let u=n.map(l=>({t:l,score:ye(r,l.name)})).sort((l,p)=>p.score-l.score);if(u[0]&&u[0].score>=.5)return{requested:r,resolved:u[0].t,strategy:"fuzzy"}}let o=["task","story","bug","improvement","epic"];for(let c of o){let a=n.find(u=>z(u.name)===c);if(a)return{requested:r||null,resolved:a,strategy:"default-preferred"}}return{requested:r||null,resolved:n[0],strategy:"default-first"}}async function st(r){let t=`projectKeys=${encodeURIComponent(r)}&expand=projects.issuetypes`,e=await O(`/rest/api/3/issue/createmeta?${t}`),s=Array.isArray(e?.projects)?e.projects:[],i=s.find(c=>String(c?.key||"").toUpperCase()===String(r||"").toUpperCase())||s[0]||null;return(Array.isArray(i?.issuetypes)?i.issuetypes:[]).map(c=>({id:c.id,name:c.name,subtask:!!c.subtask,description:c.description||null}))}async function rt(r,t){if(!r)throw new Error("projectKey is required");let e="sprint is not EMPTY";t==="active"?e="sprint in openSprints()":t==="closed"?e="sprint in closedSprints()":t==="future"&&(e="sprint in futureSprints()");let s=`project = ${r} AND ${e} ORDER BY updated DESC`,n=`jql=${encodeURIComponent(s)}&maxResults=100&fields=customfield_10020`,i=await O(`/rest/api/3/search/jql?${n}`),o=new Map;for(let c of i.issues||[])for(let a of c.fields?.customfield_10020||[])a&&!o.has(a.id)&&o.set(a.id,{id:a.id,name:a.name,state:a.state,boardId:a.boardId||null,startDate:a.startDate||null,endDate:a.endDate||null,goal:a.goal||null});return[...o.values()].sort((c,a)=>{let u={active:0,future:1,closed:2},l=(u[c.state]??3)-(u[a.state]??3);return l!==0?l:String(a.startDate||"").localeCompare(String(c.startDate||""))})}function Ws(r,{sprintId:t,sprintName:e,target:s}={}){let n=Array.isArray(r)?r:[];if(!n.length)return{sprint:null,selectedBy:"none"};if(t!=null&&String(t).trim()!=="")return{sprint:n.find(c=>String(c.id)===String(t))||null,selectedBy:"id"};if(e&&String(e).trim()){let o=String(e).trim(),c=n.find(u=>String(u.name||"").toLowerCase()===o.toLowerCase());if(c)return{sprint:c,selectedBy:"name-exact"};let a=n.map(u=>({s:u,score:ye(o,u.name||"")})).sort((u,l)=>l.score-u.score);return a[0]&&a[0].score>=.5?{sprint:a[0].s,selectedBy:"name-fuzzy"}:{sprint:null,selectedBy:"name-none"}}let i=String(s||"current").trim().toLowerCase();return i==="active"||i==="current"||i==="latest"?{sprint:n[0],selectedBy:i}:{sprint:n[0],selectedBy:"default"}}function Hs(r,t){let e=r?.fields?.customfield_10020;return Array.isArray(e)?e.some(s=>String(s?.id)===String(t)):!1}async function Ys({issueKey:r,projectKey:t,sprintId:e,attempts:s=3,delayMs:n=450}){let i=[];for(let o=0;o<s;o++){try{let c=`project = ${t} AND key = ${r} AND sprint = ${e}`,a=`jql=${encodeURIComponent(c)}&maxResults=1&fields=key,status`,u=await O(`/rest/api/3/search/jql?${a}`);if(Number(u?.total||0)>0)return i.push({attempt:o+1,jql:!0,issueField:null}),{ok:!0,method:"jql",traces:i};let p=await O(`/rest/api/3/issue/${r}?fields=customfield_10020,status`),d=Hs(p,e);if(i.push({attempt:o+1,jql:!1,issueField:d}),d)return{ok:!0,method:"issue_field",traces:i}}catch(c){i.push({attempt:o+1,error:String(c?.message||c)})}o<s-1&&await new Promise(c=>setTimeout(c,n))}return{ok:!1,method:"none",traces:i}}async function je({issueKey:r,projectKey:t,sprintId:e,sprintName:s,target:n}){if(!r)return{ok:!1,error:"issueKey is required"};let i=t;if(!i&&(i=(await O(`/rest/api/3/issue/${r}?fields=project`))?.fields?.project?.key||null,!i))return{ok:!1,error:`Could not resolve project for ${r}`};let o=await rt(i,"active");if(!o.length)return{ok:!1,error:`No assignable active sprint found for project ${i}`};let{sprint:c,selectedBy:a}=Ws(o,{sprintId:e,sprintName:s,target:n});if(!c)return{ok:!1,error:`No matching sprint found in ${i}`,requested:{sprintId:e??null,sprintName:s??null,target:n??"current"},availableSprints:o.map(p=>({id:p.id,name:p.name,state:p.state}))};await O(`/rest/api/3/issue/${r}`,{method:"PUT",body:{fields:{customfield_10020:Number(c.id)}}});let u=await Ys({issueKey:r,projectKey:i,sprintId:c.id}),l=u.ok;return{ok:l,issueKey:r,projectKey:i,sprintId:c.id,sprintName:c.name,selectedBy:a,verifiedBy:u.method,verified:l,verificationTrace:u.traces,warning:l?null:`Sprint assignment attempted but verification did not find ${r} in sprint ${c.id}`}}async function O(r,t={}){let e=async()=>{let{token:s,cloudId:n}=await Ms("jira");if(typeof s!="string"||!s)throw new Error(`Invalid jira token type: ${typeof s}`);if(!n)throw new Error("Invalid jira cloudId: missing");let i=`https://api.atlassian.com/ex/jira/${n}${r}`,o=await fetch(i,{method:t.method||"GET",headers:{Authorization:`Bearer ${s}`,Accept:"application/json",...t.body?{"Content-Type":"application/json"}:{},...t.headers},body:t.body?JSON.stringify(t.body):void 0});if(!o.ok){let a=await o.text().catch(()=>"");throw new Error(`Jira API ${o.status}: ${a.slice(0,300)}`)}let c=await o.text().catch(()=>"");if(!c||!c.trim())return{};try{return JSON.parse(c)}catch{return{raw:c}}};try{return await e()}catch(s){let n=String(s?.message||s||"").toLowerCase();if(!(n.includes("token")||n.includes("401")||n.includes("403")||n.includes("substring")))throw s;return qs("jira"),e()}}var it={id:"jira",serverName:"jira",allowedTools:["mcp__jira__*"],requiresIntegration:$.JIRA,envKeys:["ATLASSIAN_ACCESS_TOKEN","ATLASSIAN_CLOUD_ID"],description:"Zibby Jira MCP Server (OAuth Bearer)",promptFragment:`## Jira (connected)
|
|
25
25
|
You have direct access to the user's Jira. Use these tools proactively:
|
|
26
26
|
|
|
27
27
|
### Issue tools
|
|
@@ -71,7 +71,7 @@ When user asks to move/transition ticket status:
|
|
|
71
71
|
3. Pick the correct transition from returned list (match by "to" status name, not guesswork), then call jira_transition_issue with transitionId.
|
|
72
72
|
4. Call jira_get_issue(issueKey) to verify final status before claiming success.
|
|
73
73
|
5. If target wording differs (e.g. \u5DF2\u7ECF\u9A8C\u6536 vs \u5DF2\u9A8C\u6536), try toStatus first; only ask user to confirm when no reasonable match exists.
|
|
74
|
-
6. IMPORTANT: When target is clear, complete transition + verification in SAME turn. Do NOT stop after listing options.`,resolve(){let r=qs();if(!r)return null;let t={};for(let e of this.envKeys)process.env[e]&&(t[e]=process.env[e]);return process.env.ATLASSIAN_INSTANCE_URL&&(t.ATLASSIAN_INSTANCE_URL=process.env.ATLASSIAN_INSTANCE_URL),{command:"node",args:[r],env:t,description:this.description}},async handleToolCall(r,t){try{switch(r){case"jira_list_projects":{let e=await O("/rest/api/3/project"),s=(Array.isArray(e)?e:[]).map(n=>({id:n.id,key:n.key,name:n.name,style:n.style}));return JSON.stringify({count:s.length,projects:s})}case"jira_list_statuses":{let{projectKey:e}=t||{};if(e){let i=await O(`/rest/api/3/project/${encodeURIComponent(e)}/statuses`),o=Array.isArray(i)?i:[],c=new Map;for(let u of o)for(let l of u.statuses||[])l?.id&&(c.has(l.id)||c.set(l.id,{id:l.id,name:l.name,category:l.statusCategory?.name||null}));let a=[...c.values()].sort((u,l)=>String(u.name).localeCompare(String(l.name)));return JSON.stringify({scope:"project",projectKey:e,count:a.length,statuses:a})}let s=await O("/rest/api/3/status"),n=(Array.isArray(s)?s:[]).map(i=>({id:i.id,name:i.name,category:i.statusCategory?.name||null})).sort((i,o)=>String(i.name).localeCompare(String(o.name)));return JSON.stringify({scope:"global",count:n.length,statuses:n})}case"jira_list_issue_types":{let{projectKey:e}=t||{};if(!e)return JSON.stringify({error:"projectKey is required"});let s=await Xe(e);return JSON.stringify({projectKey:e,count:s.length,issueTypes:s})}case"jira_search":{let e=t.jql||"",s=t.maxResults||20;e.replace(/\s*ORDER\s+BY\s+.*/i,"").trim()||(e=`created >= -365d ${e}`.trim());let i=`jql=${encodeURIComponent(e)}&maxResults=${s}&fields=summary,status,assignee,priority,updated,issuetype,project`,c=((await O(`/rest/api/3/search/jql?${i}`)).issues||[]).map(a=>({key:a.key,project:a.fields?.project?.key,summary:a.fields?.summary,status:a.fields?.status?.name,assignee:a.fields?.assignee?.displayName||"Unassigned",priority:a.fields?.priority?.name,type:a.fields?.issuetype?.name}));return JSON.stringify({count:c.length,issues:c})}case"jira_get_issue":{let e=t.issueKey;if(!e)return JSON.stringify({error:"issueKey is required"});let s=await O(`/rest/api/3/issue/${e}`);return JSON.stringify({key:s.key,project:s.fields?.project?.key,summary:s.fields?.summary,description:s.fields?.description,status:s.fields?.status?.name,assignee:s.fields?.assignee?.displayName||"Unassigned",priority:s.fields?.priority?.name,type:s.fields?.issuetype?.name,labels:s.fields?.labels,created:s.fields?.created,updated:s.fields?.updated})}case"jira_create_issue":{let{projectKey:e,summary:s,issueType:n,description:i,priority:o,labels:c,assigneeId:a,moveToSprint:u,moveToActiveSprint:l,sprintId:p,sprintName:d,target:m}=t;if(!e||!s)return JSON.stringify({error:"projectKey and summary are required"});let f={requested:n||null,resolved:null,strategy:"none"},h=[];try{h=await Xe(e),f=Gs(n,h)}catch{}let _={project:{key:e},summary:s,issuetype:f?.resolved?.id?{id:f.resolved.id}:{name:n||"Task"}};i&&(_.description={type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:i}]}]}),o&&(_.priority={name:o}),c?.length&&(_.labels=c),a&&(_.assignee={id:a});let g=await O("/rest/api/3/issue",{method:"POST",body:{fields:_}}),b={ok:!0,key:g.key,id:g.id,self:g.self};return f?.resolved&&(b.issueType=f.resolved.name,b.issueTypeResolution=f.strategy,f.strategy!=="exact"&&f.requested&&z(f.requested)!==z(f.resolved.name)&&(b.issueTypeWarning=`Requested "${f.requested}" is not available in ${e}; used "${f.resolved.name}" instead.`)),h.length>0&&(b.availableIssueTypes=h.map(y=>y.name)),(u||l)&&(b.sprintMove=await Oe({issueKey:g.key,projectKey:e,sprintId:p,sprintName:d,target:m})),JSON.stringify(b)}case"jira_list_sprints":{let{projectKey:e,state:s}=t,n=await et(e,s);return JSON.stringify({count:n.length,sprints:n})}case"jira_move_to_active_sprint":{let{issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o}=t||{},c=await Oe({issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o||"current"});return JSON.stringify(c)}case"jira_move_issue_to_sprint":{let{issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o}=t||{},c=await Oe({issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o});return JSON.stringify(c)}case"jira_get_sprint_issues":{let{sprintName:e,sprintId:s,projectKey:n,status:i,maxResults:o}=t;if(!e&&!s)return JSON.stringify({error:"sprintName or sprintId is required"});let c=o||50,a=s?`sprint = ${s}`:`sprint = "${e}"`,u=n?`project = ${n} AND `:"",l=i?` AND status = "${i}"`:"",p=`${u}${a}${l} ORDER BY status ASC, priority DESC`,d=`jql=${encodeURIComponent(p)}&maxResults=${c}&fields=summary,status,assignee,priority,issuetype,project`,m=await O(`/rest/api/3/search/jql?${d}`),f=(m.issues||[]).map(_=>({key:_.key,project:_.fields?.project?.key,summary:_.fields?.summary,status:_.fields?.status?.name,assignee:_.fields?.assignee?.displayName||"Unassigned",priority:_.fields?.priority?.name,type:_.fields?.issuetype?.name})),h={};for(let _ of f)h[_.status]=(h[_.status]||0)+1;return JSON.stringify({count:f.length,total:m.total||f.length,statusCounts:h,issues:f})}case"jira_get_comments":{let{issueKey:e,maxResults:s}=t;if(!e)return JSON.stringify({error:"issueKey is required"});let i=await O(`/rest/api/3/issue/${e}/comment?maxResults=${s||50}&orderBy=-created`),o=(i.comments||[]).map(c=>{let a="";return c.body?.content&&(a=de(c.body.content)),{id:c.id,author:c.author?.displayName||"Unknown",body:a,created:c.created,updated:c.updated}});return JSON.stringify({count:o.length,total:i.total||o.length,comments:o})}case"jira_add_comment":{let{issueKey:e,body:s}=t;return!e||!s?JSON.stringify({error:"issueKey and body are required"}):(await O(`/rest/api/3/issue/${e}/comment`,{method:"POST",body:{body:{type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:s}]}]}}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_edit_issue":{let{issueKey:e,fields:s}=t;return!e||!s?JSON.stringify({error:"issueKey and fields are required"}):(await O(`/rest/api/3/issue/${e}`,{method:"PUT",body:{fields:s}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_transition_issue":{let{issueKey:e,transitionId:s,toStatus:n,statusName:i,status:o}=t;if(!e)return JSON.stringify({error:"issueKey is required"});let c=String(n||i||o||"").trim();if(!s&&!c){let p=((await O(`/rest/api/3/issue/${e}/transitions`)).transitions||[]).map(d=>({id:d.id,name:d.name,to:d.to?.name}));return JSON.stringify({ok:!1,error:"transitionId or toStatus is required",issueKey:e,availableTransitions:p})}let a=s;if(!a){let p=(await O(`/rest/api/3/issue/${e}/transitions`)).transitions||[],d=ee(c),m=p.find(f=>ee(f?.name||"")===d||ee(f?.to?.name||"")===d);if(!m){let f=Ie(c);f.length>=2&&(m=p.find(h=>{let _=Ie(h?.name||""),g=Ie(h?.to?.name||""),b=_.length>=2&&(_.includes(f)||f.includes(_)),y=g.length>=2&&(g.includes(f)||f.includes(g));return b||y}))}if(!m){let f=p.map(b=>{let y=me(c,b?.name||""),v=me(c,b?.to?.name||"");return{t:b,score:Math.max(y,v)}}).sort((b,y)=>y.score-b.score),h=f[0],_=f[1];h&&h.score>=.45&&(!_||h.score-_.score>=.12)&&(m=h.t)}if(!m?.id)return JSON.stringify({ok:!1,error:`No transition matches target status: "${c}"`,issueKey:e,availableTransitions:p.map(f=>({id:f.id,name:f.name,to:f.to?.name}))});a=m.id}await O(`/rest/api/3/issue/${e}/transitions`,{method:"POST",body:{transition:{id:a}}});let u=await O(`/rest/api/3/issue/${e}?fields=status`);return JSON.stringify({ok:!0,issueKey:e,transitionId:a,statusAfter:u?.fields?.status?.name||null})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"jira_list_projects",description:"List all Jira projects accessible to the user",input_schema:{type:"object",properties:{}}},{name:"jira_list_statuses",description:"List Jira statuses. Use projectKey to get statuses applicable in that project workflow.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Optional project key (e.g. PROJ). If omitted, returns global status catalog."}}}},{name:"jira_list_issue_types",description:"List issue types allowed for issue creation in the given project.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"}},required:["projectKey"]}},{name:"jira_search",description:"Search Jira issues using JQL",input_schema:{type:"object",properties:{jql:{type:"string",description:'JQL query string, e.g. "project = PROJ AND status = Open"'},maxResults:{type:"number",description:"Max results to return (default 20)"}},required:["jql"]}},{name:"jira_get_issue",description:"Get details of a specific Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"}},required:["issueKey"]}},{name:"jira_create_issue",description:"Create a new Jira issue",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},summary:{type:"string",description:"Issue title/summary"},issueType:{type:"string",description:"Issue type (default: Task). Common: Task, Bug, Story, Epic"},description:{type:"string",description:"Issue description (plain text)"},priority:{type:"string",description:"Priority name, e.g. High, Medium, Low"},labels:{type:"array",items:{type:"string"},description:"Array of label strings"},assigneeId:{type:"string",description:"Atlassian account ID to assign to"},moveToSprint:{type:"boolean",description:"If true, move created issue to a sprint and verify."},moveToActiveSprint:{type:"boolean",description:"Backward-compatible alias for moveToSprint."},sprintId:{type:"number",description:"Optional sprint id for placement."},sprintName:{type:"string",description:"Optional sprint name for placement."},target:{type:"string",description:"Placement target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["projectKey","summary"]}},{name:"jira_list_sprints",description:"List sprints for a Jira project (returns sprint names, IDs, states, dates)",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},state:{type:"string",description:"Filter: active, closed, future. Omit for all."}},required:["projectKey"]}},{name:"jira_get_sprint_issues",description:"Get all issues in a sprint, optionally filtered by status column name",input_schema:{type:"object",properties:{sprintName:{type:"string",description:"Sprint name (from jira_list_sprints). Use this OR sprintId."},sprintId:{type:"number",description:"Sprint ID (from jira_list_sprints). Use this OR sprintName."},projectKey:{type:"string",description:"Project key to scope the search (optional)"},status:{type:"string",description:'Filter by status name (e.g. "\u8FDB\u884C\u4E2D", "\u6D4B\u8BD5", "Done")'},maxResults:{type:"number",description:"Max issues to return (default 50)"}}}},{name:"jira_move_to_active_sprint",description:"Backward-compatible alias: move issue to sprint target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_move_issue_to_sprint",description:"Move an issue to a sprint by id/name/target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_get_comments",description:"Get comments on a Jira issue (newest first)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},maxResults:{type:"number",description:"Max comments to return (default 50)"}},required:["issueKey"]}},{name:"jira_add_comment",description:"Add a comment to a Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},body:{type:"string",description:"Comment text (plain text)"}},required:["issueKey","body"]}},{name:"jira_edit_issue",description:"Update fields on a Jira issue (summary, story points, labels, priority)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},fields:{type:"object",description:"Object of field names to values",additionalProperties:!0}},required:["issueKey","fields"]}},{name:"jira_transition_issue",description:"Move a Jira issue to a different status. Always pass toStatus when user gave a target; only pass issueKey alone when you explicitly need to list transitions.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},transitionId:{type:"string",description:"Transition ID to perform (optional if toStatus is provided)"},toStatus:{type:"string",description:'Target status/column name (e.g. "\u5DF2\u7ECF\u9A8C\u6536", "Done", "In Progress"). If provided, tool resolves matching transition automatically.'}},required:["issueKey"]}}]};import{resolveIntegrationToken as st}from"@zibby/core/backend-client.js";async function S(r,t={}){let{token:e}=await st("github"),s=r.startsWith("https://")?r:`https://api.github.com${r}`,n={Authorization:`Bearer ${e}`,Accept:t.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...t.body?{"Content-Type":"application/json"}:{}},i=await fetch(s,{method:t.method||"GET",headers:n,body:t.body?JSON.stringify(t.body):void 0});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`GitHub API ${i.status}: ${o.slice(0,300)}`)}return t.raw?i.text():i.json()}var rt={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:j.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
|
|
74
|
+
6. IMPORTANT: When target is clear, complete transition + verification in SAME turn. Do NOT stop after listing options.`,resolve(){let r=Bs();if(!r)return null;let t={};for(let e of this.envKeys)process.env[e]&&(t[e]=process.env[e]);return process.env.ATLASSIAN_INSTANCE_URL&&(t.ATLASSIAN_INSTANCE_URL=process.env.ATLASSIAN_INSTANCE_URL),{command:"node",args:[r],env:t,description:this.description}},async handleToolCall(r,t){try{switch(r){case"jira_list_projects":{let e=await O("/rest/api/3/project"),s=(Array.isArray(e)?e:[]).map(n=>({id:n.id,key:n.key,name:n.name,style:n.style}));return JSON.stringify({count:s.length,projects:s})}case"jira_list_statuses":{let{projectKey:e}=t||{};if(e){let i=await O(`/rest/api/3/project/${encodeURIComponent(e)}/statuses`),o=Array.isArray(i)?i:[],c=new Map;for(let u of o)for(let l of u.statuses||[])l?.id&&(c.has(l.id)||c.set(l.id,{id:l.id,name:l.name,category:l.statusCategory?.name||null}));let a=[...c.values()].sort((u,l)=>String(u.name).localeCompare(String(l.name)));return JSON.stringify({scope:"project",projectKey:e,count:a.length,statuses:a})}let s=await O("/rest/api/3/status"),n=(Array.isArray(s)?s:[]).map(i=>({id:i.id,name:i.name,category:i.statusCategory?.name||null})).sort((i,o)=>String(i.name).localeCompare(String(o.name)));return JSON.stringify({scope:"global",count:n.length,statuses:n})}case"jira_list_issue_types":{let{projectKey:e}=t||{};if(!e)return JSON.stringify({error:"projectKey is required"});let s=await st(e);return JSON.stringify({projectKey:e,count:s.length,issueTypes:s})}case"jira_search":{let e=t.jql||"",s=t.maxResults||20;e.replace(/\s*ORDER\s+BY\s+.*/i,"").trim()||(e=`created >= -365d ${e}`.trim());let i=`jql=${encodeURIComponent(e)}&maxResults=${s}&fields=summary,status,assignee,priority,updated,issuetype,project`,c=((await O(`/rest/api/3/search/jql?${i}`)).issues||[]).map(a=>({key:a.key,project:a.fields?.project?.key,summary:a.fields?.summary,status:a.fields?.status?.name,assignee:a.fields?.assignee?.displayName||"Unassigned",priority:a.fields?.priority?.name,type:a.fields?.issuetype?.name}));return JSON.stringify({count:c.length,issues:c})}case"jira_get_issue":{let e=t.issueKey;if(!e)return JSON.stringify({error:"issueKey is required"});let s=await O(`/rest/api/3/issue/${e}`);return JSON.stringify({key:s.key,project:s.fields?.project?.key,summary:s.fields?.summary,description:s.fields?.description,status:s.fields?.status?.name,assignee:s.fields?.assignee?.displayName||"Unassigned",priority:s.fields?.priority?.name,type:s.fields?.issuetype?.name,labels:s.fields?.labels,created:s.fields?.created,updated:s.fields?.updated})}case"jira_create_issue":{let{projectKey:e,summary:s,issueType:n,description:i,priority:o,labels:c,assigneeId:a,moveToSprint:u,moveToActiveSprint:l,sprintId:p,sprintName:d,target:m}=t;if(!e||!s)return JSON.stringify({error:"projectKey and summary are required"});let f={requested:n||null,resolved:null,strategy:"none"},h=[];try{h=await st(e),f=zs(n,h)}catch{}let _={project:{key:e},summary:s,issuetype:f?.resolved?.id?{id:f.resolved.id}:{name:n||"Task"}};i&&(_.description={type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:i}]}]}),o&&(_.priority={name:o}),c?.length&&(_.labels=c),a&&(_.assignee={id:a});let g=await O("/rest/api/3/issue",{method:"POST",body:{fields:_}}),b={ok:!0,key:g.key,id:g.id,self:g.self};return f?.resolved&&(b.issueType=f.resolved.name,b.issueTypeResolution=f.strategy,f.strategy!=="exact"&&f.requested&&z(f.requested)!==z(f.resolved.name)&&(b.issueTypeWarning=`Requested "${f.requested}" is not available in ${e}; used "${f.resolved.name}" instead.`)),h.length>0&&(b.availableIssueTypes=h.map(y=>y.name)),(u||l)&&(b.sprintMove=await je({issueKey:g.key,projectKey:e,sprintId:p,sprintName:d,target:m})),JSON.stringify(b)}case"jira_list_sprints":{let{projectKey:e,state:s}=t,n=await rt(e,s);return JSON.stringify({count:n.length,sprints:n})}case"jira_move_to_active_sprint":{let{issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o}=t||{},c=await je({issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o||"current"});return JSON.stringify(c)}case"jira_move_issue_to_sprint":{let{issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o}=t||{},c=await je({issueKey:e,projectKey:s,sprintId:n,sprintName:i,target:o});return JSON.stringify(c)}case"jira_get_sprint_issues":{let{sprintName:e,sprintId:s,projectKey:n,status:i,maxResults:o}=t;if(!e&&!s)return JSON.stringify({error:"sprintName or sprintId is required"});let c=o||50,a=s?`sprint = ${s}`:`sprint = "${e}"`,u=n?`project = ${n} AND `:"",l=i?` AND status = "${i}"`:"",p=`${u}${a}${l} ORDER BY status ASC, priority DESC`,d=`jql=${encodeURIComponent(p)}&maxResults=${c}&fields=summary,status,assignee,priority,issuetype,project`,m=await O(`/rest/api/3/search/jql?${d}`),f=(m.issues||[]).map(_=>({key:_.key,project:_.fields?.project?.key,summary:_.fields?.summary,status:_.fields?.status?.name,assignee:_.fields?.assignee?.displayName||"Unassigned",priority:_.fields?.priority?.name,type:_.fields?.issuetype?.name})),h={};for(let _ of f)h[_.status]=(h[_.status]||0)+1;return JSON.stringify({count:f.length,total:m.total||f.length,statusCounts:h,issues:f})}case"jira_get_comments":{let{issueKey:e,maxResults:s}=t;if(!e)return JSON.stringify({error:"issueKey is required"});let i=await O(`/rest/api/3/issue/${e}/comment?maxResults=${s||50}&orderBy=-created`),o=(i.comments||[]).map(c=>{let a="";return c.body?.content&&(a=fe(c.body.content)),{id:c.id,author:c.author?.displayName||"Unknown",body:a,created:c.created,updated:c.updated}});return JSON.stringify({count:o.length,total:i.total||o.length,comments:o})}case"jira_add_comment":{let{issueKey:e,body:s}=t;return!e||!s?JSON.stringify({error:"issueKey and body are required"}):(await O(`/rest/api/3/issue/${e}/comment`,{method:"POST",body:{body:{type:"doc",version:1,content:[{type:"paragraph",content:[{type:"text",text:s}]}]}}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_edit_issue":{let{issueKey:e,fields:s}=t;return!e||!s?JSON.stringify({error:"issueKey and fields are required"}):(await O(`/rest/api/3/issue/${e}`,{method:"PUT",body:{fields:s}}),JSON.stringify({ok:!0,issueKey:e}))}case"jira_transition_issue":{let{issueKey:e,transitionId:s,toStatus:n,statusName:i,status:o}=t;if(!e)return JSON.stringify({error:"issueKey is required"});let c=String(n||i||o||"").trim();if(!s&&!c){let p=((await O(`/rest/api/3/issue/${e}/transitions`)).transitions||[]).map(d=>({id:d.id,name:d.name,to:d.to?.name}));return JSON.stringify({ok:!1,error:"transitionId or toStatus is required",issueKey:e,availableTransitions:p})}let a=s;if(!a){let p=(await O(`/rest/api/3/issue/${e}/transitions`)).transitions||[],d=ee(c),m=p.find(f=>ee(f?.name||"")===d||ee(f?.to?.name||"")===d);if(!m){let f=$e(c);f.length>=2&&(m=p.find(h=>{let _=$e(h?.name||""),g=$e(h?.to?.name||""),b=_.length>=2&&(_.includes(f)||f.includes(_)),y=g.length>=2&&(g.includes(f)||f.includes(g));return b||y}))}if(!m){let f=p.map(b=>{let y=ye(c,b?.name||""),v=ye(c,b?.to?.name||"");return{t:b,score:Math.max(y,v)}}).sort((b,y)=>y.score-b.score),h=f[0],_=f[1];h&&h.score>=.45&&(!_||h.score-_.score>=.12)&&(m=h.t)}if(!m?.id)return JSON.stringify({ok:!1,error:`No transition matches target status: "${c}"`,issueKey:e,availableTransitions:p.map(f=>({id:f.id,name:f.name,to:f.to?.name}))});a=m.id}await O(`/rest/api/3/issue/${e}/transitions`,{method:"POST",body:{transition:{id:a}}});let u=await O(`/rest/api/3/issue/${e}?fields=status`);return JSON.stringify({ok:!0,issueKey:e,transitionId:a,statusAfter:u?.fields?.status?.name||null})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"jira_list_projects",description:"List all Jira projects accessible to the user",input_schema:{type:"object",properties:{}}},{name:"jira_list_statuses",description:"List Jira statuses. Use projectKey to get statuses applicable in that project workflow.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Optional project key (e.g. PROJ). If omitted, returns global status catalog."}}}},{name:"jira_list_issue_types",description:"List issue types allowed for issue creation in the given project.",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"}},required:["projectKey"]}},{name:"jira_search",description:"Search Jira issues using JQL",input_schema:{type:"object",properties:{jql:{type:"string",description:'JQL query string, e.g. "project = PROJ AND status = Open"'},maxResults:{type:"number",description:"Max results to return (default 20)"}},required:["jql"]}},{name:"jira_get_issue",description:"Get details of a specific Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"}},required:["issueKey"]}},{name:"jira_create_issue",description:"Create a new Jira issue",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},summary:{type:"string",description:"Issue title/summary"},issueType:{type:"string",description:"Issue type (default: Task). Common: Task, Bug, Story, Epic"},description:{type:"string",description:"Issue description (plain text)"},priority:{type:"string",description:"Priority name, e.g. High, Medium, Low"},labels:{type:"array",items:{type:"string"},description:"Array of label strings"},assigneeId:{type:"string",description:"Atlassian account ID to assign to"},moveToSprint:{type:"boolean",description:"If true, move created issue to a sprint and verify."},moveToActiveSprint:{type:"boolean",description:"Backward-compatible alias for moveToSprint."},sprintId:{type:"number",description:"Optional sprint id for placement."},sprintName:{type:"string",description:"Optional sprint name for placement."},target:{type:"string",description:"Placement target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["projectKey","summary"]}},{name:"jira_list_sprints",description:"List sprints for a Jira project (returns sprint names, IDs, states, dates)",input_schema:{type:"object",properties:{projectKey:{type:"string",description:"Project key, e.g. PROJ"},state:{type:"string",description:"Filter: active, closed, future. Omit for all."}},required:["projectKey"]}},{name:"jira_get_sprint_issues",description:"Get all issues in a sprint, optionally filtered by status column name",input_schema:{type:"object",properties:{sprintName:{type:"string",description:"Sprint name (from jira_list_sprints). Use this OR sprintId."},sprintId:{type:"number",description:"Sprint ID (from jira_list_sprints). Use this OR sprintName."},projectKey:{type:"string",description:"Project key to scope the search (optional)"},status:{type:"string",description:'Filter by status name (e.g. "\u8FDB\u884C\u4E2D", "\u6D4B\u8BD5", "Done")'},maxResults:{type:"number",description:"Max issues to return (default 50)"}}}},{name:"jira_move_to_active_sprint",description:"Backward-compatible alias: move issue to sprint target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_move_issue_to_sprint",description:"Move an issue to a sprint by id/name/target and verify membership.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},projectKey:{type:"string",description:"Optional project key. If omitted, inferred from issue."},sprintId:{type:"number",description:"Optional sprint id."},sprintName:{type:"string",description:"Optional sprint name."},target:{type:"string",description:"Target when sprintId/sprintName omitted: current|active|latest (default: current)."}},required:["issueKey"]}},{name:"jira_get_comments",description:"Get comments on a Jira issue (newest first)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},maxResults:{type:"number",description:"Max comments to return (default 50)"}},required:["issueKey"]}},{name:"jira_add_comment",description:"Add a comment to a Jira issue",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},body:{type:"string",description:"Comment text (plain text)"}},required:["issueKey","body"]}},{name:"jira_edit_issue",description:"Update fields on a Jira issue (summary, story points, labels, priority)",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},fields:{type:"object",description:"Object of field names to values",additionalProperties:!0}},required:["issueKey","fields"]}},{name:"jira_transition_issue",description:"Move a Jira issue to a different status. Always pass toStatus when user gave a target; only pass issueKey alone when you explicitly need to list transitions.",input_schema:{type:"object",properties:{issueKey:{type:"string",description:"Issue key, e.g. PROJ-123"},transitionId:{type:"string",description:"Transition ID to perform (optional if toStatus is provided)"},toStatus:{type:"string",description:'Target status/column name (e.g. "\u5DF2\u7ECF\u9A8C\u6536", "Done", "In Progress"). If provided, tool resolves matching transition automatically.'}},required:["issueKey"]}}]};import{resolveIntegrationToken as nt}from"@zibby/core/backend-client.js";async function S(r,t={}){let{token:e}=await nt("github"),s=r.startsWith("https://")?r:`https://api.github.com${r}`,n={Authorization:`Bearer ${e}`,Accept:t.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...t.body?{"Content-Type":"application/json"}:{}},i=await fetch(s,{method:t.method||"GET",headers:n,body:t.body?JSON.stringify(t.body):void 0});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`GitHub API ${i.status}: ${o.slice(0,300)}`)}return t.raw?i.text():i.json()}var ot={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:$.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
|
|
75
75
|
You have access to the user's GitHub repositories. Available tools:
|
|
76
76
|
|
|
77
77
|
### Discovery
|
|
@@ -108,9 +108,9 @@ When user says "check out repo-name" or "clone repo-name":
|
|
|
108
108
|
3. STOP. Do not offer to inspect files or ask what to do next.
|
|
109
109
|
|
|
110
110
|
When user just wants to "look at" or "read" files (not clone):
|
|
111
|
-
- Use github_get_file to read individual files via API`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{command:"npx",args:["-y","@modelcontextprotocol/server-github@latest"],env:r}},async handleToolCall(r,t){try{switch(r){case"github_search_issues":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=await S(`/search/issues?q=${encodeURIComponent(e)}&per_page=${t.limit||20}`),n=(s.items||[]).map(i=>({number:i.number,title:i.title,state:i.state,repo:i.repository_url?.split("/").slice(-2).join("/"),url:i.html_url,user:i.user?.login,isPR:!!i.pull_request,labels:(i.labels||[]).map(o=>o.name),createdAt:i.created_at}));return JSON.stringify({total:s.total_count,items:n})}case"github_search_code":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=t.repo?`+repo:${t.repo}`:"",n=t.language?`+language:${t.language}`:"",i=await S(`/search/code?q=${encodeURIComponent(e)}${s}${n}&per_page=${t.limit||15}`),o=(i.items||[]).map(c=>({name:c.name,path:c.path,repo:c.repository?.full_name,url:c.html_url,score:c.score}));return JSON.stringify({total:i.total_count,items:o})}case"github_get_pr":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}`);return JSON.stringify({number:i.number,title:i.title,state:i.state,merged:i.merged,body:i.body?.slice(0,5e3),user:i.user?.login,branch:i.head?.ref,base:i.base?.ref,changedFiles:i.changed_files,additions:i.additions,deletions:i.deletions,createdAt:i.created_at,mergedAt:i.merged_at,url:i.html_url,labels:(i.labels||[]).map(o=>o.name)})}case"github_get_pr_diff":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),o=i.length>15e3;return JSON.stringify({number:n,diff:o?i.slice(0,15e3):i,truncated:o,totalLength:i.length})}case"github_list_pr_files":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:i.length,files:i.map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}/comments?per_page=50`),o=await S(`/repos/${e}/${s}/issues/${n}/comments?per_page=50`),c=[...i.map(a=>({type:"review",user:a.user?.login,body:a.body?.slice(0,1e3),path:a.path,line:a.line,createdAt:a.created_at})),...o.map(a=>({type:"issue",user:a.user?.login,body:a.body?.slice(0,1e3),createdAt:a.created_at}))].sort((a,u)=>new Date(a.createdAt)-new Date(u.createdAt));return JSON.stringify({total:c.length,comments:c})}case"github_list_commits":{let{owner:e,repo:s,branch:n,path:i,limit:o}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let c=`/repos/${e}/${s}/commits?per_page=${o||20}`;n&&(c+=`&sha=${encodeURIComponent(n)}`),i&&(c+=`&path=${encodeURIComponent(i)}`);let a=await S(c);return JSON.stringify({total:a.length,commits:a.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:e,repo:s,sha:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await S(`/repos/${e}/${s}/commits/${n}`);return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:e,repo:s,path:n,ref:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${s}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let c=await S(o);if(c.type!=="file")return Array.isArray(c)?JSON.stringify({type:"directory",path:n,entries:c.map(l=>({name:l.name,type:l.type,size:l.size,path:l.path}))}):JSON.stringify({error:`Not a file: ${c.type}`});let a=Buffer.from(c.content||"","base64").toString("utf-8"),u=a.length>2e4;return JSON.stringify({path:c.path,size:c.size,sha:c.sha?.slice(0,8),content:u?a.slice(0,2e4):a,truncated:u})}case"github_get_user":try{let e=await S("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let s=e.repositories[0],n=s.owner.login,i=s.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,c=await S(o);return JSON.stringify({login:c.login,name:c.name||c.login,avatar:c.avatar_url,bio:c.bio||c.description,type:i,isOrg:i==="Organization",publicRepos:c.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(e){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${e.message})`})}case"github_list_orgs":try{let s=(await S("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of s)o.owner.type==="Organization"&&(n.has(o.owner.login)||n.set(o.owner.login,{login:o.owner.login,description:null,url:o.owner.url}));let i=Array.from(n.values());return JSON.stringify({count:i.length,orgs:i,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(e){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${e.message}`})}case"github_clone":{let f=function(g){let b=g.replace(/^~(?=$|\/|\\)/,m);return c(b)},{owner:e,repo:s,destination:n}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let{execSync:i}=await import("child_process"),{join:o,resolve:c}=await import("path"),{existsSync:a,mkdirSync:u}=await import("fs"),{homedir:l,platform:p}=await import("os"),{token:d}=await
|
|
111
|
+
- Use github_get_file to read individual files via API`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{command:"npx",args:["-y","@modelcontextprotocol/server-github@latest"],env:r}},async handleToolCall(r,t){try{switch(r){case"github_search_issues":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=await S(`/search/issues?q=${encodeURIComponent(e)}&per_page=${t.limit||20}`),n=(s.items||[]).map(i=>({number:i.number,title:i.title,state:i.state,repo:i.repository_url?.split("/").slice(-2).join("/"),url:i.html_url,user:i.user?.login,isPR:!!i.pull_request,labels:(i.labels||[]).map(o=>o.name),createdAt:i.created_at}));return JSON.stringify({total:s.total_count,items:n})}case"github_search_code":{let e=t.query;if(!e)return JSON.stringify({error:"query is required"});let s=t.repo?`+repo:${t.repo}`:"",n=t.language?`+language:${t.language}`:"",i=await S(`/search/code?q=${encodeURIComponent(e)}${s}${n}&per_page=${t.limit||15}`),o=(i.items||[]).map(c=>({name:c.name,path:c.path,repo:c.repository?.full_name,url:c.html_url,score:c.score}));return JSON.stringify({total:i.total_count,items:o})}case"github_get_pr":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}`);return JSON.stringify({number:i.number,title:i.title,state:i.state,merged:i.merged,body:i.body?.slice(0,5e3),user:i.user?.login,branch:i.head?.ref,base:i.base?.ref,changedFiles:i.changed_files,additions:i.additions,deletions:i.deletions,createdAt:i.created_at,mergedAt:i.merged_at,url:i.html_url,labels:(i.labels||[]).map(o=>o.name)})}case"github_get_pr_diff":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}`,{accept:"application/vnd.github.v3.diff",raw:!0}),o=i.length>15e3;return JSON.stringify({number:n,diff:o?i.slice(0,15e3):i,truncated:o,totalLength:i.length})}case"github_list_pr_files":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}/files?per_page=100`);return JSON.stringify({total:i.length,files:i.map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:e,repo:s,number:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/pulls/${n}/comments?per_page=50`),o=await S(`/repos/${e}/${s}/issues/${n}/comments?per_page=50`),c=[...i.map(a=>({type:"review",user:a.user?.login,body:a.body?.slice(0,1e3),path:a.path,line:a.line,createdAt:a.created_at})),...o.map(a=>({type:"issue",user:a.user?.login,body:a.body?.slice(0,1e3),createdAt:a.created_at}))].sort((a,u)=>new Date(a.createdAt)-new Date(u.createdAt));return JSON.stringify({total:c.length,comments:c})}case"github_list_commits":{let{owner:e,repo:s,branch:n,path:i,limit:o}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let c=`/repos/${e}/${s}/commits?per_page=${o||20}`;n&&(c+=`&sha=${encodeURIComponent(n)}`),i&&(c+=`&path=${encodeURIComponent(i)}`);let a=await S(c);return JSON.stringify({total:a.length,commits:a.map(u=>({sha:u.sha?.slice(0,8),fullSha:u.sha,message:u.commit?.message?.slice(0,300),author:u.commit?.author?.name,date:u.commit?.author?.date,url:u.html_url}))})}case"github_get_commit":{let{owner:e,repo:s,sha:n}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and sha are required"});let i=await S(`/repos/${e}/${s}/commits/${n}`);return JSON.stringify({sha:i.sha?.slice(0,8),message:i.commit?.message,author:i.commit?.author?.name,date:i.commit?.author?.date,stats:i.stats,files:(i.files||[]).map(o=>({filename:o.filename,status:o.status,additions:o.additions,deletions:o.deletions,patch:o.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:e,repo:s,path:n,ref:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and path are required"});let o=`/repos/${e}/${s}/contents/${encodeURIComponent(n)}`;i&&(o+=`?ref=${encodeURIComponent(i)}`);let c=await S(o);if(c.type!=="file")return Array.isArray(c)?JSON.stringify({type:"directory",path:n,entries:c.map(l=>({name:l.name,type:l.type,size:l.size,path:l.path}))}):JSON.stringify({error:`Not a file: ${c.type}`});let a=Buffer.from(c.content||"","base64").toString("utf-8"),u=a.length>2e4;return JSON.stringify({path:c.path,size:c.size,sha:c.sha?.slice(0,8),content:u?a.slice(0,2e4):a,truncated:u})}case"github_get_user":try{let e=await S("/installation/repositories?per_page=1");if(e.repositories&&e.repositories.length>0){let s=e.repositories[0],n=s.owner.login,i=s.owner.type,o=i==="Organization"?`/orgs/${n}`:`/users/${n}`,c=await S(o);return JSON.stringify({login:c.login,name:c.name||c.login,avatar:c.avatar_url,bio:c.bio||c.description,type:i,isOrg:i==="Organization",publicRepos:c.public_repos,message:"Showing GitHub App installation owner (GitHub Apps cannot access /user endpoint)"})}return JSON.stringify({error:"No repositories accessible to this GitHub App installation"})}catch(e){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${e.message})`})}case"github_list_orgs":try{let s=(await S("/installation/repositories?per_page=100")).repositories||[],n=new Map;for(let o of s)o.owner.type==="Organization"&&(n.has(o.owner.login)||n.set(o.owner.login,{login:o.owner.login,description:null,url:o.owner.url}));let i=Array.from(n.values());return JSON.stringify({count:i.length,orgs:i,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(e){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${e.message}`})}case"github_clone":{let f=function(g){let b=g.replace(/^~(?=$|\/|\\)/,m);return c(b)},{owner:e,repo:s,destination:n}=t;if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let{execSync:i}=await import("child_process"),{join:o,resolve:c}=await import("path"),{existsSync:a,mkdirSync:u}=await import("fs"),{homedir:l,platform:p}=await import("os"),{token:d}=await nt("github"),m=l(),h=n?f(n):o(m,"zibby-repos"),_=o(h,s);if(u(h,{recursive:!0}),a(_))return JSON.stringify({error:`Directory ${_} already exists. Remove it first or use a different destination.`,existingPath:_});try{let g=`https://x-access-token:${d}@github.com/${e}/${s}.git`;i(`git clone ${g} "${_}"`,{stdio:"pipe"});let b=p()==="win32",y;return b?y=i(`dir "${_}"`,{encoding:"utf-8",shell:"cmd.exe"}):y=i(`ls -la "${_}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:_,message:`Cloned ${e}/${s} to ${_}`,contents:y.split(`
|
|
112
112
|
`).slice(0,30).join(`
|
|
113
|
-
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){return JSON.stringify({error:`Clone failed: ${g.message}`})}}case"github_search_repos":{let{query:e,limit:s}=t;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),c=i.repos.filter(a=>a.name.toLowerCase().includes(o)||a.fullName.toLowerCase().includes(o)||a.description&&a.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:c.length,repos:c.slice(0,s||20)})}case"github_list_repos":{let{owner:e,type:s,sort:n,direction:i,limit:o}=t,c=100,a=o||200,u=[];if(!e){let f=1,h=!0;for(;h&&u.length<a;){let y=`/installation/repositories?per_page=${c}&page=${f}`,T=(await S(y)).repositories||[];if(T.length===0)break;u=u.concat(T),h=T.length===c,f++}let _=u.slice(0,a).map(y=>({name:y.name,fullName:y.full_name,private:y.private,description:y.description,language:y.language,defaultBranch:y.default_branch,updatedAt:y.updated_at,stars:y.stargazers_count,url:y.html_url})),g=_.filter(y=>y.private).length,b=_.filter(y=>!y.private).length;return JSON.stringify({count:_.length,repos:_,privateCount:g,publicCount:b,message:`Found ${g} private and ${b} public repos`})}let l=await S(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,d=!0;for(;d&&u.length<a;){let f;l?f=`/orgs/${e}/repos?per_page=${c}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:f=`/users/${e}/repos?per_page=${c}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let h=await S(f),_=Array.isArray(h)?h:[];if(_.length===0)break;u=u.concat(_),d=_.length===c,p++}let m=u.slice(0,a).map(f=>({name:f.name,fullName:f.full_name,private:f.private,description:f.description,language:f.language,defaultBranch:f.default_branch,updatedAt:f.updated_at,stars:f.stargazers_count,url:f.html_url}));return JSON.stringify({count:m.length,repos:m})}case"github_create_issue":{let{owner:e,repo:s,title:n,body:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await S(`/repos/${e}/${s}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}case"github_list_issues":{let{owner:e,repo:s,state:n,labels:i,since:o,assignee:c,sort:a,direction:u,limit:l}=t||{};if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let p=new URLSearchParams;p.set("state",n||"open"),p.set("per_page",String(l||30)),p.set("sort",a||"updated"),p.set("direction",u||"desc"),i&&p.set("labels",Array.isArray(i)?i.join(","):i),o&&p.set("since",o),c&&p.set("assignee",c);let d=await S(`/repos/${e}/${s}/issues?${p.toString()}`),m=(Array.isArray(d)?d:[]).filter(f=>!f.pull_request).map(f=>({number:f.number,title:f.title,state:f.state,labels:(f.labels||[]).map(h=>typeof h=="string"?h:h.name),assignee:f.assignee?.login||null,assignees:(f.assignees||[]).map(h=>h.login),user:f.user?.login,comments:f.comments,url:f.html_url,createdAt:f.created_at,updatedAt:f.updated_at}));return JSON.stringify({count:m.length,issues:m})}case"github_get_issue":{let{owner:e,repo:s,number:n}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/issues/${n}`);return i.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:i.number,title:i.title,body:i.body||"",state:i.state,stateReason:i.state_reason||null,labels:(i.labels||[]).map(o=>typeof o=="string"?o:o.name),assignee:i.assignee?.login||null,assignees:(i.assignees||[]).map(o=>o.login),user:i.user?.login,milestone:i.milestone?.title||null,comments:i.comments,url:i.html_url,createdAt:i.created_at,updatedAt:i.updated_at,closedAt:i.closed_at})}case"github_get_issue_comments":{let{owner:e,repo:s,number:n,limit:i}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=await S(`/repos/${e}/${s}/issues/${n}/comments?per_page=${i||100}`),c=(Array.isArray(o)?o:[]).map(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:c.length,comments:c})}case"github_add_issue_comment":{let{owner:e,repo:s,number:n,body:i}=t||{};if(!e||!s||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await S(`/repos/${e}/${s}/issues/${n}/comments`,{method:"POST",body:{body:i}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_close_issue":{let{owner:e,repo:s,number:n,stateReason:i}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o={state:"closed"};i&&(o.state_reason=i);let c=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:o});return JSON.stringify({ok:!0,number:c.number,state:c.state,stateReason:c.state_reason||null,url:c.html_url})}case"github_reopen_issue":{let{owner:e,repo:s,number:n}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:i.number,state:i.state,url:i.html_url})}case"github_label_issue":{let{owner:e,repo:s,number:n,labels:i,mode:o}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=Array.isArray(i)?i:i?[i]:[];if(!c.length)return JSON.stringify({error:"labels (string or array) is required"});let a=o||"add";if(a==="set"){let l=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:{labels:c}});return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(p=>typeof p=="string"?p:p.name)})}if(a==="remove"){for(let p of c)await S(`/repos/${e}/${s}/issues/${n}/labels/${encodeURIComponent(p)}`,{method:"DELETE"});let l=await S(`/repos/${e}/${s}/issues/${n}`);return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(p=>typeof p=="string"?p:p.name)})}let u=await S(`/repos/${e}/${s}/issues/${n}/labels`,{method:"POST",body:{labels:c}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(u)?u:[]).map(l=>typeof l=="string"?l:l.name)})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var Hs=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function Ys(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let r=process.env.LINEAR_API_KEY;if(!r)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return r}async function P(r,t={}){let e=await fetch(Hs,{method:"POST",headers:{Authorization:Ys(),"Content-Type":"application/json"},body:JSON.stringify({query:r,variables:t})});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`Linear API ${e.status}: ${n.slice(0,300)}`)}let s=await e.json().catch(()=>null);if(!s)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(s.errors)&&s.errors.length){let n=s.errors.map(i=>i?.message||String(i)).join("; ");throw new Error(`Linear GraphQL error: ${n.slice(0,300)}`)}return s.data}function ne(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function Zs(r,t){let e=ne(r),s=ne(t);if(!e||!s)return 0;if(e===s)return 1;if(e.length===1||s.length===1)return e===s?1:0;let n=l=>{let p=new Map;for(let d=0;d<l.length-1;d++){let m=l.slice(d,d+2);p.set(m,(p.get(m)||0)+1)}return p},i=n(e),o=n(s),c=0,a=0,u=0;for(let l of i.values())a+=l;for(let l of o.values())u+=l;for(let[l,p]of i.entries())c+=Math.min(p,o.get(l)||0);return 2*c/Math.max(1,a+u)}function Vs(r,t){let e=Array.isArray(r)?r:[];if(!e.length)return{state:null,strategy:"no-states"};let s=ne(t);if(!s)return{state:null,strategy:"no-target"};let n=e.find(c=>ne(c.name)===s);if(n)return{state:n,strategy:"exact"};let i={backlog:["backlog"],unstarted:["todo","unstarted","open"],started:["inprogress","started","doing","wip"],completed:["done","completed","closed","resolved","fixed"],canceled:["canceled","cancelled","wontfix","won'tfix"],triage:["triage"]};for(let[c,a]of Object.entries(i)){if(!a.some(l=>ne(l)===s))continue;let u=e.find(l=>l.type===c);if(u)return{state:u,strategy:"type-alias"}}let o=e.map(c=>({s:c,score:Zs(t,c.name)})).sort((c,a)=>a.score-c.score);return o[0]&&o[0].score>=.5?{state:o[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var Qs=`
|
|
113
|
+
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(g){return JSON.stringify({error:`Clone failed: ${g.message}`})}}case"github_search_repos":{let{query:e,limit:s}=t;if(!e)return JSON.stringify({error:"query is required"});let n=await this.handleToolCall("github_list_repos",{limit:200},{}),i=JSON.parse(n);if(i.error)return JSON.stringify(i);let o=e.toLowerCase(),c=i.repos.filter(a=>a.name.toLowerCase().includes(o)||a.fullName.toLowerCase().includes(o)||a.description&&a.description.toLowerCase().includes(o));return JSON.stringify({query:e,count:c.length,repos:c.slice(0,s||20)})}case"github_list_repos":{let{owner:e,type:s,sort:n,direction:i,limit:o}=t,c=100,a=o||200,u=[];if(!e){let f=1,h=!0;for(;h&&u.length<a;){let y=`/installation/repositories?per_page=${c}&page=${f}`,T=(await S(y)).repositories||[];if(T.length===0)break;u=u.concat(T),h=T.length===c,f++}let _=u.slice(0,a).map(y=>({name:y.name,fullName:y.full_name,private:y.private,description:y.description,language:y.language,defaultBranch:y.default_branch,updatedAt:y.updated_at,stars:y.stargazers_count,url:y.html_url})),g=_.filter(y=>y.private).length,b=_.filter(y=>!y.private).length;return JSON.stringify({count:_.length,repos:_,privateCount:g,publicCount:b,message:`Found ${g} private and ${b} public repos`})}let l=await S(`/orgs/${e}`).then(()=>!0).catch(()=>!1),p=1,d=!0;for(;d&&u.length<a;){let f;l?f=`/orgs/${e}/repos?per_page=${c}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`:f=`/users/${e}/repos?per_page=${c}&page=${p}&type=${s||"all"}&sort=${n||"updated"}&direction=${i||"desc"}`;let h=await S(f),_=Array.isArray(h)?h:[];if(_.length===0)break;u=u.concat(_),d=_.length===c,p++}let m=u.slice(0,a).map(f=>({name:f.name,fullName:f.full_name,private:f.private,description:f.description,language:f.language,defaultBranch:f.default_branch,updatedAt:f.updated_at,stars:f.stargazers_count,url:f.html_url}));return JSON.stringify({count:m.length,repos:m})}case"github_create_issue":{let{owner:e,repo:s,title:n,body:i}=t;if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and title are required"});let o=await S(`/repos/${e}/${s}/issues`,{method:"POST",body:{title:n,body:i||""}});return JSON.stringify({number:o.number,url:o.html_url,title:o.title})}case"github_list_issues":{let{owner:e,repo:s,state:n,labels:i,since:o,assignee:c,sort:a,direction:u,limit:l}=t||{};if(!e||!s)return JSON.stringify({error:"owner and repo are required"});let p=new URLSearchParams;p.set("state",n||"open"),p.set("per_page",String(l||30)),p.set("sort",a||"updated"),p.set("direction",u||"desc"),i&&p.set("labels",Array.isArray(i)?i.join(","):i),o&&p.set("since",o),c&&p.set("assignee",c);let d=await S(`/repos/${e}/${s}/issues?${p.toString()}`),m=(Array.isArray(d)?d:[]).filter(f=>!f.pull_request).map(f=>({number:f.number,title:f.title,state:f.state,labels:(f.labels||[]).map(h=>typeof h=="string"?h:h.name),assignee:f.assignee?.login||null,assignees:(f.assignees||[]).map(h=>h.login),user:f.user?.login,comments:f.comments,url:f.html_url,createdAt:f.created_at,updatedAt:f.updated_at}));return JSON.stringify({count:m.length,issues:m})}case"github_get_issue":{let{owner:e,repo:s,number:n}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/issues/${n}`);return i.pull_request?JSON.stringify({error:`#${n} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:i.number,title:i.title,body:i.body||"",state:i.state,stateReason:i.state_reason||null,labels:(i.labels||[]).map(o=>typeof o=="string"?o:o.name),assignee:i.assignee?.login||null,assignees:(i.assignees||[]).map(o=>o.login),user:i.user?.login,milestone:i.milestone?.title||null,comments:i.comments,url:i.html_url,createdAt:i.created_at,updatedAt:i.updated_at,closedAt:i.closed_at})}case"github_get_issue_comments":{let{owner:e,repo:s,number:n,limit:i}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o=await S(`/repos/${e}/${s}/issues/${n}/comments?per_page=${i||100}`),c=(Array.isArray(o)?o:[]).map(a=>({id:a.id,user:a.user?.login,body:a.body||"",createdAt:a.created_at,updatedAt:a.updated_at,url:a.html_url}));return JSON.stringify({count:c.length,comments:c})}case"github_add_issue_comment":{let{owner:e,repo:s,number:n,body:i}=t||{};if(!e||!s||!n||!i)return JSON.stringify({error:"owner, repo, number, and body are required"});let o=await S(`/repos/${e}/${s}/issues/${n}/comments`,{method:"POST",body:{body:i}});return JSON.stringify({ok:!0,id:o.id,url:o.html_url})}case"github_close_issue":{let{owner:e,repo:s,number:n,stateReason:i}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let o={state:"closed"};i&&(o.state_reason=i);let c=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:o});return JSON.stringify({ok:!0,number:c.number,state:c.state,stateReason:c.state_reason||null,url:c.html_url})}case"github_reopen_issue":{let{owner:e,repo:s,number:n}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let i=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:i.number,state:i.state,url:i.html_url})}case"github_label_issue":{let{owner:e,repo:s,number:n,labels:i,mode:o}=t||{};if(!e||!s||!n)return JSON.stringify({error:"owner, repo, and number are required"});let c=Array.isArray(i)?i:i?[i]:[];if(!c.length)return JSON.stringify({error:"labels (string or array) is required"});let a=o||"add";if(a==="set"){let l=await S(`/repos/${e}/${s}/issues/${n}`,{method:"PATCH",body:{labels:c}});return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(p=>typeof p=="string"?p:p.name)})}if(a==="remove"){for(let p of c)await S(`/repos/${e}/${s}/issues/${n}/labels/${encodeURIComponent(p)}`,{method:"DELETE"});let l=await S(`/repos/${e}/${s}/issues/${n}`);return JSON.stringify({ok:!0,number:l.number,labels:(l.labels||[]).map(p=>typeof p=="string"?p:p.name)})}let u=await S(`/repos/${e}/${s}/issues/${n}/labels`,{method:"POST",body:{labels:c}});return JSON.stringify({ok:!0,number:n,labels:(Array.isArray(u)?u:[]).map(l=>typeof l=="string"?l:l.name)})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"github_get_user",description:"Get the authenticated GitHub user profile and their organizations",input_schema:{type:"object",properties:{}}},{name:"github_list_orgs",description:"List GitHub organizations the authenticated user belongs to",input_schema:{type:"object",properties:{}}},{name:"github_list_repos",description:"List repositories for a user or org. If no owner given, lists the authenticated user's repos.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Org or user login. Omit to list your own repos."},type:{type:"string",enum:["all","public","private","forks","sources","member"],description:"Filter by type (default: all)"},sort:{type:"string",enum:["created","updated","pushed","full_name"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max repos to return (default: 30)"}}}},{name:"github_clone",description:'Clone a GitHub repository to the local filesystem. Use when user says "check out" or "clone" a repo.',input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner (user or org name)"},repo:{type:"string",description:"Repository name"},destination:{type:"string",description:"Destination directory. Accepts absolute paths, ~-prefixed paths, or relative names. Defaults to ~/zibby-repos/<repo>."}},required:["owner","repo"]}},{name:"github_search_repos",description:"Search accessible repositories by name or description. Use this when the user asks to find a specific repo.",input_schema:{type:"object",properties:{query:{type:"string",description:'Search term to match against repo name or description (e.g., "electron", "my-app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_issues",description:"Search GitHub issues and pull requests",input_schema:{type:"object",properties:{query:{type:"string",description:'GitHub search query (e.g. "SCRUM-123", "login bug repo:org/app")'},limit:{type:"number",description:"Max results (default: 20)"}},required:["query"]}},{name:"github_search_code",description:"Search code across GitHub repositories by keyword",input_schema:{type:"object",properties:{query:{type:"string",description:'Code search query (e.g. "handleLogin", "class AuthService")'},repo:{type:"string",description:'Scope to a specific repo (e.g. "org/app"). Optional.'},language:{type:"string",description:'Filter by language (e.g. "javascript", "python"). Optional.'},limit:{type:"number",description:"Max results (default: 15)"}},required:["query"]}},{name:"github_get_pr",description:"Get details of a pull request \u2014 title, description, branch, stats",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_get_pr_diff",description:"Get the unified diff of a pull request \u2014 the actual code changes",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_files",description:"List files changed in a PR with per-file patches",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_pr_comments",description:"Get all review and issue comments on a PR",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"}},required:["owner","repo","number"]}},{name:"github_list_commits",description:"List recent commits on a branch, optionally filtered by file path",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},branch:{type:"string",description:"Branch name (default: repo default branch)"},path:{type:"string",description:"Filter commits touching this file path"},limit:{type:"number",description:"Max commits (default: 20)"}},required:["owner","repo"]}},{name:"github_get_commit",description:"Get details of a specific commit \u2014 message, stats, file diffs",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},sha:{type:"string",description:"Commit SHA (full or short)"}},required:["owner","repo","sha"]}},{name:"github_get_file",description:"Read a file (or list a directory) from a GitHub repo. Works on any branch/ref.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},path:{type:"string",description:'File or directory path (e.g. "src/auth/login.ts")'},ref:{type:"string",description:"Branch, tag, or commit SHA (default: repo default branch)"}},required:["owner","repo","path"]}},{name:"github_create_issue",description:"Create a GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},title:{type:"string",description:"Issue title"},body:{type:"string",description:"Issue body (markdown)"}},required:["owner","repo","title"]}},{name:"github_list_issues",description:"List issues in a repo (excludes pull requests). Filter by state, labels, and an updated-since cursor for polling.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},state:{type:"string",enum:["open","closed","all"],description:"Filter by state (default: open)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},since:{type:"string",description:"ISO-8601 timestamp; only issues updated at/after this (polling cursor)"},assignee:{type:"string",description:'Filter by assignee login, "none", or "*"'},sort:{type:"string",enum:["created","updated","comments"],description:"Sort field (default: updated)"},direction:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30, max 100 per page)"}},required:["owner","repo"]}},{name:"github_get_issue",description:"Get a single GitHub issue with full detail (title, body, state, labels, assignee, url)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_get_issue_comments",description:"Get the comment thread on a GitHub issue (chronological)",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},limit:{type:"number",description:"Max comments (default: 100)"}},required:["owner","repo","number"]}},{name:"github_add_issue_comment",description:"Add a comment to a GitHub issue. Also the way to record a PR link on an issue (post a markdown link).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},body:{type:"string",description:"Comment body (markdown)"}},required:["owner","repo","number","body"]}},{name:"github_close_issue",description:"Close a GitHub issue. Optionally set the close reason (completed or not_planned).",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},stateReason:{type:"string",enum:["completed","not_planned"],description:"Why the issue was closed (optional)"}},required:["owner","repo","number"]}},{name:"github_reopen_issue",description:"Reopen a closed GitHub issue",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"}},required:["owner","repo","number"]}},{name:"github_label_issue",description:"Add, set (replace all), or remove labels on a GitHub issue. Labels back state-like transitions on GitHub.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"Issue number"},labels:{type:"array",items:{type:"string"},description:"Label name(s)"},mode:{type:"string",enum:["add","set","remove"],description:"add appends, set replaces all, remove deletes (default: add)"}},required:["owner","repo","number","labels"]}}]};var Zs=process.env.LINEAR_API_URL||"https://api.linear.app/graphql";function Vs(){if(process.env.LINEAR_OAUTH_TOKEN)return`Bearer ${process.env.LINEAR_OAUTH_TOKEN}`;let r=process.env.LINEAR_API_KEY;if(!r)throw new Error("Linear is not connected: set LINEAR_API_KEY (personal API key) or LINEAR_OAUTH_TOKEN.");return r}async function P(r,t={}){let e=await fetch(Zs,{method:"POST",headers:{Authorization:Vs(),"Content-Type":"application/json"},body:JSON.stringify({query:r,variables:t})});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`Linear API ${e.status}: ${n.slice(0,300)}`)}let s=await e.json().catch(()=>null);if(!s)throw new Error("Linear API returned a non-JSON body");if(Array.isArray(s.errors)&&s.errors.length){let n=s.errors.map(i=>i?.message||String(i)).join("; ");throw new Error(`Linear GraphQL error: ${n.slice(0,300)}`)}return s.data}function oe(r){return String(r||"").toLowerCase().replace(/\s+/g,"").replace(/[()\-_::"'`]/g,"")}function Qs(r,t){let e=oe(r),s=oe(t);if(!e||!s)return 0;if(e===s)return 1;if(e.length===1||s.length===1)return e===s?1:0;let n=l=>{let p=new Map;for(let d=0;d<l.length-1;d++){let m=l.slice(d,d+2);p.set(m,(p.get(m)||0)+1)}return p},i=n(e),o=n(s),c=0,a=0,u=0;for(let l of i.values())a+=l;for(let l of o.values())u+=l;for(let[l,p]of i.entries())c+=Math.min(p,o.get(l)||0);return 2*c/Math.max(1,a+u)}function Xs(r,t){let e=Array.isArray(r)?r:[];if(!e.length)return{state:null,strategy:"no-states"};let s=oe(t);if(!s)return{state:null,strategy:"no-target"};let n=e.find(c=>oe(c.name)===s);if(n)return{state:n,strategy:"exact"};let i={backlog:["backlog"],unstarted:["todo","unstarted","open"],started:["inprogress","started","doing","wip"],completed:["done","completed","closed","resolved","fixed"],canceled:["canceled","cancelled","wontfix","won'tfix"],triage:["triage"]};for(let[c,a]of Object.entries(i)){if(!a.some(l=>oe(l)===s))continue;let u=e.find(l=>l.type===c);if(u)return{state:u,strategy:"type-alias"}}let o=e.map(c=>({s:c,score:Qs(t,c.name)})).sort((c,a)=>a.score-c.score);return o[0]&&o[0].score>=.5?{state:o[0].s,strategy:"fuzzy"}:{state:null,strategy:"no-match"}}var er=`
|
|
114
114
|
id
|
|
115
115
|
identifier
|
|
116
116
|
number
|
|
@@ -124,7 +124,7 @@ When user just wants to "look at" or "read" files (not clone):
|
|
|
124
124
|
assignee { id name displayName email }
|
|
125
125
|
labels { nodes { id name color } }
|
|
126
126
|
team { id key name }
|
|
127
|
-
`,
|
|
127
|
+
`,ct={id:"linear",serverName:"linear",allowedTools:["mcp__linear__*"],requiresIntegration:$.LINEAR,envKeys:["LINEAR_API_KEY","LINEAR_OAUTH_TOKEN"],description:"Linear \u2014 issues, comments, workflow states (GraphQL API key)",promptFragment:`## Linear (connected)
|
|
128
128
|
You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
129
129
|
|
|
130
130
|
### Discovery
|
|
@@ -148,7 +148,7 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
|
148
148
|
nodes { id key name description }
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
`,{first:t?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:s.length,teams:s})}case"linear_list_states":{let{teamId:e,teamKey:s}=t||{},n=e;if(!n&&s&&(n=await
|
|
151
|
+
`,{first:t?.limit||50}))?.teams?.nodes||[];return JSON.stringify({count:s.length,teams:s})}case"linear_list_states":{let{teamId:e,teamKey:s}=t||{},n=e;if(!n&&s&&(n=await at(s)),n){let a=(await P(`
|
|
152
152
|
query States($teamId: String!) {
|
|
153
153
|
team(id: $teamId) {
|
|
154
154
|
id key name
|
|
@@ -167,7 +167,7 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
|
167
167
|
nodes { id name color team { id key } }
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
`,{first:t?.limit||100,filter:e?{team:{id:{eq:e}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:n.length,labels:n})}case"linear_list_issues":{let{teamId:e,teamKey:s,stateId:n,stateName:i,label:o,assigneeId:c,updatedAfter:a,limit:u}=t||{},l={},p=e;!p&&s&&(p=await
|
|
170
|
+
`,{first:t?.limit||100,filter:e?{team:{id:{eq:e}}}:void 0}))?.issueLabels?.nodes||[];return JSON.stringify({count:n.length,labels:n})}case"linear_list_issues":{let{teamId:e,teamKey:s,stateId:n,stateName:i,label:o,assigneeId:c,updatedAfter:a,limit:u}=t||{},l={},p=e;!p&&s&&(p=await at(s)),p&&(l.team={id:{eq:p}}),n?l.state={id:{eq:n}}:i&&(l.state={name:{eqIgnoreCase:i}}),o&&(l.labels={name:{eqIgnoreCase:o}}),c&&(l.assignee={id:{eq:c}}),a&&(l.updatedAt={gt:a});let m=((await P(`
|
|
171
171
|
query Issues($first: Int, $filter: IssueFilter, $orderBy: PaginationOrderBy) {
|
|
172
172
|
issues(first: $first, filter: $filter, orderBy: $orderBy) {
|
|
173
173
|
nodes {
|
|
@@ -179,41 +179,41 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
`,{first:u||30,filter:Object.keys(l).length?l:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(f=>({id:f.id,identifier:f.identifier,number:f.number,title:f.title,url:f.url,priority:f.priority,state:f.state?.name,stateType:f.state?.type,assignee:f.assignee?.displayName||null,labels:(f.labels?.nodes||[]).map(h=>h.name),team:f.team?.key,createdAt:f.createdAt,updatedAt:f.updatedAt}));return JSON.stringify({count:m.length,issues:m})}case"linear_get_issue":{let e=t?.issueId||t?.identifier||t?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let s=await
|
|
182
|
+
`,{first:u||30,filter:Object.keys(l).length?l:void 0,orderBy:"updatedAt"}))?.issues?.nodes||[]).map(f=>({id:f.id,identifier:f.identifier,number:f.number,title:f.title,url:f.url,priority:f.priority,state:f.state?.name,stateType:f.state?.type,assignee:f.assignee?.displayName||null,labels:(f.labels?.nodes||[]).map(h=>h.name),team:f.team?.key,createdAt:f.createdAt,updatedAt:f.updatedAt}));return JSON.stringify({count:m.length,issues:m})}case"linear_get_issue":{let e=t?.issueId||t?.identifier||t?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let s=await ne(e);return JSON.stringify(s?{id:s.id,identifier:s.identifier,number:s.number,title:s.title,description:s.description||"",url:s.url,priority:s.priority,state:s.state?.name,stateId:s.state?.id,stateType:s.state?.type,assignee:s.assignee?.displayName||s.assignee?.name||null,assigneeId:s.assignee?.id||null,labels:(s.labels?.nodes||[]).map(n=>n.name),team:s.team?{id:s.team.id,key:s.team.key,name:s.team.name}:null,createdAt:s.createdAt,updatedAt:s.updatedAt}:{error:`Issue not found: ${e}`})}case"linear_get_comments":{let e=t?.issueId||t?.identifier||t?.issueKey;if(!e)return JSON.stringify({error:"issueId or identifier is required"});let s=await ne(e,`
|
|
183
183
|
id identifier
|
|
184
184
|
comments(first: ${Number(t?.limit)||50}) {
|
|
185
185
|
nodes { id body createdAt updatedAt user { id name displayName } }
|
|
186
186
|
}
|
|
187
|
-
`);if(!s)return JSON.stringify({error:`Issue not found: ${e}`});let n=(s.comments?.nodes||[]).map(i=>({id:i.id,author:i.user?.displayName||i.user?.name||"Unknown",body:i.body||"",createdAt:i.createdAt,updatedAt:i.updatedAt})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)));return JSON.stringify({count:n.length,issue:s.identifier,comments:n})}case"linear_add_comment":{let e=t?.issueId||t?.identifier||t?.issueKey,s=t?.body;if(!e||!s)return JSON.stringify({error:"issueId/identifier and body are required"});let n=await
|
|
187
|
+
`);if(!s)return JSON.stringify({error:`Issue not found: ${e}`});let n=(s.comments?.nodes||[]).map(i=>({id:i.id,author:i.user?.displayName||i.user?.name||"Unknown",body:i.body||"",createdAt:i.createdAt,updatedAt:i.updatedAt})).sort((i,o)=>String(o.createdAt).localeCompare(String(i.createdAt)));return JSON.stringify({count:n.length,issue:s.identifier,comments:n})}case"linear_add_comment":{let e=t?.issueId||t?.identifier||t?.issueKey,s=t?.body;if(!e||!s)return JSON.stringify({error:"issueId/identifier and body are required"});let n=await ne(e,"id identifier");if(!n)return JSON.stringify({error:`Issue not found: ${e}`});let o=(await P(`
|
|
188
188
|
mutation AddComment($input: CommentCreateInput!) {
|
|
189
189
|
commentCreate(input: $input) {
|
|
190
190
|
success
|
|
191
191
|
comment { id url createdAt }
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
`,{input:{issueId:n.id,body:s}}))?.commentCreate;return JSON.stringify({ok:!!o?.success,commentId:o?.comment?.id,url:o?.comment?.url})}case"linear_update_state":{let e=t?.issueId||t?.identifier||t?.issueKey,{stateId:s,stateName:n,toStatus:i,status:o}=t||{};if(!e)return JSON.stringify({error:"issueId or identifier is required"});let c=await
|
|
194
|
+
`,{input:{issueId:n.id,body:s}}))?.commentCreate;return JSON.stringify({ok:!!o?.success,commentId:o?.comment?.id,url:o?.comment?.url})}case"linear_update_state":{let e=t?.issueId||t?.identifier||t?.issueKey,{stateId:s,stateName:n,toStatus:i,status:o}=t||{};if(!e)return JSON.stringify({error:"issueId or identifier is required"});let c=await ne(e,`
|
|
195
195
|
id identifier
|
|
196
196
|
state { id name type }
|
|
197
197
|
team { id key states { nodes { id name type position } } }
|
|
198
|
-
`);if(!c)return JSON.stringify({error:`Issue not found: ${e}`});let a=s,u=s?{strategy:"explicit-id"}:null;if(!a){let d=String(n||i||o||"").trim(),m=(c.team?.states?.nodes||[]).slice().sort((h,_)=>(h.position||0)-(_.position||0));if(!d)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:c.identifier,availableStates:m.map(h=>({id:h.id,name:h.name,type:h.type}))});let f=
|
|
198
|
+
`);if(!c)return JSON.stringify({error:`Issue not found: ${e}`});let a=s,u=s?{strategy:"explicit-id"}:null;if(!a){let d=String(n||i||o||"").trim(),m=(c.team?.states?.nodes||[]).slice().sort((h,_)=>(h.position||0)-(_.position||0));if(!d)return JSON.stringify({ok:!1,error:"stateId or stateName/toStatus is required",issue:c.identifier,availableStates:m.map(h=>({id:h.id,name:h.name,type:h.type}))});let f=Xs(m,d);if(!f.state)return JSON.stringify({ok:!1,error:`No workflow state matches "${d}" in team ${c.team?.key}`,issue:c.identifier,availableStates:m.map(h=>({id:h.id,name:h.name,type:h.type}))});a=f.state.id,u={strategy:f.strategy,matchedName:f.state.name}}let p=(await P(`
|
|
199
199
|
mutation MoveIssue($id: String!, $input: IssueUpdateInput!) {
|
|
200
200
|
issueUpdate(id: $id, input: $input) {
|
|
201
201
|
success
|
|
202
202
|
issue { id identifier state { id name type } }
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
`,{id:c.id,input:{stateId:a}}))?.issueUpdate;return JSON.stringify({ok:!!p?.success,issue:p?.issue?.identifier||c.identifier,stateAfter:p?.issue?.state?.name||null,stateTypeAfter:p?.issue?.state?.type||null,resolution:u})}case"linear_link_attachment":{let e=t?.issueId||t?.identifier||t?.issueKey,{url:s,title:n,subtitle:i}=t||{};if(!e||!s)return JSON.stringify({error:"issueId/identifier and url are required"});let o=await
|
|
205
|
+
`,{id:c.id,input:{stateId:a}}))?.issueUpdate;return JSON.stringify({ok:!!p?.success,issue:p?.issue?.identifier||c.identifier,stateAfter:p?.issue?.state?.name||null,stateTypeAfter:p?.issue?.state?.type||null,resolution:u})}case"linear_link_attachment":{let e=t?.issueId||t?.identifier||t?.issueKey,{url:s,title:n,subtitle:i}=t||{};if(!e||!s)return JSON.stringify({error:"issueId/identifier and url are required"});let o=await ne(e,"id identifier");if(!o)return JSON.stringify({error:`Issue not found: ${e}`});let a=(await P(`
|
|
206
206
|
mutation LinkAttachment($input: AttachmentCreateInput!) {
|
|
207
207
|
attachmentCreate(input: $input) {
|
|
208
208
|
success
|
|
209
209
|
attachment { id url title }
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
`,{input:{issueId:o.id,url:s,title:n||s,subtitle:i||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!a?.success,attachmentId:a?.attachment?.id,url:a?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"linear_list_teams",description:"List Linear teams (id, key, name). Needed to scope workflow states and issue queries.",input_schema:{type:"object",properties:{limit:{type:"number",description:"Max teams (default: 50)"}}}},{name:"linear_list_states",description:"List a team's workflow states (id, name, type: backlog|unstarted|started|completed|canceled|triage). Linear states are PER-TEAM. Omit team to list all states across the workspace.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved to an id if teamId omitted"},limit:{type:"number",description:"Max states when listing workspace-wide (default: 200)"}}}},{name:"linear_list_labels",description:"List issue labels, optionally scoped to a team.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Optional team uuid to scope labels"},limit:{type:"number",description:"Max labels (default: 100)"}}}},{name:"linear_list_issues",description:"List/poll Linear issues filtered by team, state, label, assignee, and an updatedAfter cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved if teamId omitted"},stateId:{type:"string",description:"Filter by workflow state uuid"},stateName:{type:"string",description:"Filter by state name (case-insensitive)"},label:{type:"string",description:"Filter by label name (case-insensitive)"},assigneeId:{type:"string",description:"Filter by assignee uuid"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},limit:{type:"number",description:"Max issues (default: 30)"}}}},{name:"linear_get_issue",description:"Get a single Linear issue by identifier (e.g. ENG-123) or internal uuid \u2014 title, description, state, labels, assignee, url.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"}}}},{name:"linear_get_comments",description:"Get comments on a Linear issue (newest first).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},limit:{type:"number",description:"Max comments (default: 50)"}}}},{name:"linear_add_comment",description:"Add a comment to a Linear issue (markdown supported).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},body:{type:"string",description:"Comment body (markdown)"}},required:["body"]}},{name:"linear_update_state",description:"Move a Linear issue to a different workflow state. Pass a state NAME (toStatus/stateName) and the tool resolves it to the issue's team's matching state id (exact -> type-alias -> fuzzy), or pass stateId directly. Linear has no transitions \u2014 this sets the state.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},stateId:{type:"string",description:"Target workflow state uuid (skips name resolution)"},stateName:{type:"string",description:'Target state name (e.g. "In Progress", "Done")'},toStatus:{type:"string",description:"Alias for stateName"}}}},{name:"linear_link_attachment",description:"Attach a URL (e.g. a GitHub PR) to a Linear issue via native attachments. Use this for PR links; fall back to linear_add_comment if it fails.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},url:{type:"string",description:"The URL to attach (e.g. a PR link)"},title:{type:"string",description:"Attachment title (defaults to the URL)"},subtitle:{type:"string",description:"Optional attachment subtitle"}},required:["url"]}}]};async function
|
|
212
|
+
`,{input:{issueId:o.id,url:s,title:n||s,subtitle:i||void 0}}))?.attachmentCreate;return JSON.stringify({ok:!!a?.success,attachmentId:a?.attachment?.id,url:a?.attachment?.url})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"linear_list_teams",description:"List Linear teams (id, key, name). Needed to scope workflow states and issue queries.",input_schema:{type:"object",properties:{limit:{type:"number",description:"Max teams (default: 50)"}}}},{name:"linear_list_states",description:"List a team's workflow states (id, name, type: backlog|unstarted|started|completed|canceled|triage). Linear states are PER-TEAM. Omit team to list all states across the workspace.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved to an id if teamId omitted"},limit:{type:"number",description:"Max states when listing workspace-wide (default: 200)"}}}},{name:"linear_list_labels",description:"List issue labels, optionally scoped to a team.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Optional team uuid to scope labels"},limit:{type:"number",description:"Max labels (default: 100)"}}}},{name:"linear_list_issues",description:"List/poll Linear issues filtered by team, state, label, assignee, and an updatedAfter cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{teamId:{type:"string",description:"Team uuid"},teamKey:{type:"string",description:"Team key (e.g. ENG); resolved if teamId omitted"},stateId:{type:"string",description:"Filter by workflow state uuid"},stateName:{type:"string",description:"Filter by state name (case-insensitive)"},label:{type:"string",description:"Filter by label name (case-insensitive)"},assigneeId:{type:"string",description:"Filter by assignee uuid"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},limit:{type:"number",description:"Max issues (default: 30)"}}}},{name:"linear_get_issue",description:"Get a single Linear issue by identifier (e.g. ENG-123) or internal uuid \u2014 title, description, state, labels, assignee, url.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"}}}},{name:"linear_get_comments",description:"Get comments on a Linear issue (newest first).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},limit:{type:"number",description:"Max comments (default: 50)"}}}},{name:"linear_add_comment",description:"Add a comment to a Linear issue (markdown supported).",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},body:{type:"string",description:"Comment body (markdown)"}},required:["body"]}},{name:"linear_update_state",description:"Move a Linear issue to a different workflow state. Pass a state NAME (toStatus/stateName) and the tool resolves it to the issue's team's matching state id (exact -> type-alias -> fuzzy), or pass stateId directly. Linear has no transitions \u2014 this sets the state.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},stateId:{type:"string",description:"Target workflow state uuid (skips name resolution)"},stateName:{type:"string",description:'Target state name (e.g. "In Progress", "Done")'},toStatus:{type:"string",description:"Alias for stateName"}}}},{name:"linear_link_attachment",description:"Attach a URL (e.g. a GitHub PR) to a Linear issue via native attachments. Use this for PR links; fall back to linear_add_comment if it fails.",input_schema:{type:"object",properties:{identifier:{type:"string",description:"Issue identifier, e.g. ENG-123"},issueId:{type:"string",description:"Internal issue uuid (alternative to identifier)"},url:{type:"string",description:"The URL to attach (e.g. a PR link)"},title:{type:"string",description:"Attachment title (defaults to the URL)"},subtitle:{type:"string",description:"Optional attachment subtitle"}},required:["url"]}}]};async function at(r){return(await P(`
|
|
213
213
|
query TeamByKey($filter: TeamFilter) {
|
|
214
214
|
teams(first: 1, filter: $filter) { nodes { id key } }
|
|
215
215
|
}
|
|
216
|
-
`,{filter:{key:{eq:r}}}))?.teams?.nodes?.[0]?.id||null}async function
|
|
216
|
+
`,{filter:{key:{eq:r}}}))?.teams?.nodes?.[0]?.id||null}async function ne(r,t=er){let e=String(r).trim(),s=/^([A-Za-z][A-Za-z0-9]*)-(\d+)$/.exec(e);if(s){let i=s[1].toUpperCase(),o=Number(s[2]);return(await P(`
|
|
217
217
|
query IssueByIdentifier($filter: IssueFilter) {
|
|
218
218
|
issues(first: 1, filter: $filter) {
|
|
219
219
|
nodes { ${t} }
|
|
@@ -223,30 +223,30 @@ You have direct access to the user's Linear workspace (GraphQL API). Tools:
|
|
|
223
223
|
query IssueById($id: String!) {
|
|
224
224
|
issue(id: $id) { ${t} }
|
|
225
225
|
}
|
|
226
|
-
`,{id:e}))?.issue||null}var
|
|
226
|
+
`,{id:e}))?.issue||null}var lt={id:"plane",serverName:"plane",allowedTools:["mcp__plane__*"],requiresIntegration:$.PLANE,envKeys:["PLANE_API_KEY","PLANE_WORKSPACE_SLUG","PLANE_BASE_URL"],description:"Plane \u2014 projects, work items, cycles, modules, epics, comments (official MCP, API key)",tools:[],promptFragment:`## Plane (connected)
|
|
227
227
|
You have direct access to the user's Plane workspace via the official Plane MCP server. All Plane tools are available under the mcp__plane__* namespace \u2014 use them proactively to read and write projects, work items (issues), cycles, modules, epics, sub-issues, comments, labels, states, pages, and workspace data.
|
|
228
228
|
|
|
229
229
|
- List/get projects and work items, then create/update/delete or search work items as needed.
|
|
230
230
|
- For status changes, read the project's available states first, then set the work item's state.
|
|
231
231
|
- Cycles and modules group work items \u2014 list them to scope queries before drilling into items.
|
|
232
|
-
- Always operate within the connected workspace; the workspace slug and base URL are pre-configured (Plane Cloud, self-hosted, or Zibby-hosted all work transparently).`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{type:"stdio",command:"uvx",args:["plane-mcp-server","stdio"],env:r,description:this.description}}};import{existsSync as
|
|
232
|
+
- Always operate within the connected workspace; the workspace slug and base URL are pre-configured (Plane Cloud, self-hosted, or Zibby-hosted all work transparently).`,resolve(){let r={};for(let t of this.envKeys)process.env[t]&&(r[t]=process.env[t]);return{type:"stdio",command:"uvx",args:["plane-mcp-server","stdio"],env:r,description:this.description}}};import{existsSync as tr}from"fs";import{fileURLToPath as sr}from"url";import{dirname as rr,resolve as ir}from"path";import{resolveIntegrationToken as nr}from"@zibby/core/backend-client.js";function or(){if(process.env.MCP_SLACK_PATH)return process.env.MCP_SLACK_PATH;let r=rr(sr(import.meta.url)),t=ir(r,"..","bin","mcp-slack.mjs");return tr(t)?t:null}async function J(r,t={}){let{token:e}=await nr("slack"),s=["conversations.list","users.list","users.profile.get","users.lookupByEmail","usergroups.list","usergroups.users.list","conversations.history","conversations.replies"].includes(r),n=`https://slack.com/api/${r}`,i={Authorization:`Bearer ${e}`},o;if(s){let u=new URLSearchParams(t).toString();u&&(n+=`?${u}`)}else i["Content-Type"]="application/json; charset=utf-8",o=JSON.stringify(t);let a=await(await fetch(n,{method:s?"GET":"POST",headers:i,body:o})).json();if(!a.ok)throw new Error(`Slack API error: ${a.error}`);return a}var U={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],requiresIntegration:$.SLACK,envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack (connected)
|
|
233
233
|
You have access to the user's Slack workspace. Use these tools:
|
|
234
234
|
- slack_list_channels, slack_post_message, slack_reply_to_thread
|
|
235
235
|
- slack_add_reaction, slack_get_channel_history, slack_get_thread_replies
|
|
236
236
|
- slack_get_users, slack_get_user_profile
|
|
237
237
|
- slack_lookup_user_by_email (precise email\u2192user_id, prefer this over scanning slack_get_users)
|
|
238
|
-
- slack_list_usergroups, slack_get_usergroup_members (workspace-defined teams like @oncall, @platform)`,resolve(){let r=ir();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_USER_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);for(let e of this.envKeys)process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},async handleToolCall(r,t){try{switch(r){case"slack_list_channels":{let e=await J("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(e.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!t.channel||!t.text)return JSON.stringify({error:"channel and text are required"});let e=await J("chat.postMessage",{channel:t.channel,text:t.text,...t.blocks?{blocks:t.blocks}:{}});return JSON.stringify({ok:!0,ts:e.ts,channel:e.channel})}case"slack_reply_to_thread":{if(!t.channel||!t.thread_ts||!t.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let e=await J("chat.postMessage",{channel:t.channel,thread_ts:t.thread_ts,text:t.text});return JSON.stringify({ok:!0,ts:e.ts})}case"slack_add_reaction":return!t.channel||!t.timestamp||!t.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await J("reactions.add",{channel:t.channel,timestamp:t.timestamp,name:t.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!t.channel)return JSON.stringify({error:"channel is required"});let e=await J("conversations.history",{channel:t.channel,limit:t.limit||20});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!t.channel||!t.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let e=await J("conversations.replies",{channel:t.channel,ts:t.thread_ts});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let e=await J("users.list",{limit:100});return JSON.stringify({users:(e.members||[]).filter(s=>!s.is_bot&&!s.deleted).map(s=>({id:s.id,name:s.real_name||s.name}))})}case"slack_get_user_profile":{if(!t.user_id)return JSON.stringify({error:"user_id is required"});let e=await J("users.profile.get",{user:t.user_id});return JSON.stringify({profile:e.profile})}case"slack_lookup_user_by_email":{if(!t.email)return JSON.stringify({error:"email is required"});try{let e=await J("users.lookupByEmail",{email:t.email});return JSON.stringify({ok:!0,user:{id:e.user?.id,name:e.user?.real_name||e.user?.name,email:e.user?.profile?.email||t.email}})}catch(e){if(/users_not_found/.test(e.message))return JSON.stringify({ok:!1,reason:"users_not_found"});throw e}}case"slack_list_usergroups":{let e=await J("usergroups.list",{});return JSON.stringify({usergroups:(e.usergroups||[]).map(s=>({id:s.id,handle:s.handle,name:s.name,description:s.description||"",user_count:Number(s.user_count||0)}))})}case"slack_get_usergroup_members":{if(!t.usergroup)return JSON.stringify({error:"usergroup id is required"});let e=await J("usergroups.users.list",{usergroup:t.usergroup});return JSON.stringify({users:e.users||[]})}case"slack_search_users":{if(!t.query||typeof t.query!="string")return JSON.stringify({error:"query is required"});let e=t.query.trim().toLowerCase();if(!e)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(t.limit)||5,25)),n=[],i,o=5;for(let a=0;a<o;a+=1){let u={limit:200};i&&(u.cursor=i);let l=await J("users.list",u);for(let p of l.members||[])p.deleted||p.is_bot||n.push(p);if(i=l.response_metadata?.next_cursor,!i)break}let c=[];for(let a of n){let u=(a.real_name||"").toLowerCase(),l=(a.profile?.display_name||"").toLowerCase(),p=(a.name||"").toLowerCase(),d=0;u.includes(e)&&(d+=100-Math.abs(u.length-e.length)),l.includes(e)&&(d+=60-Math.abs(l.length-e.length)),p.includes(e)&&(d+=30-Math.abs(p.length-e.length)),(u===e||l===e)&&(d+=200),d>0&&c.push({id:a.id,name:a.real_name||a.profile?.display_name||a.name,email:a.profile?.email||void 0,_score:d})}return c.sort((a,u)=>u._score-a._score),JSON.stringify({ok:!0,matches:c.slice(0,s).map(({_score:a,...u})=>u),scanned:n.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"slack_list_channels",description:"List public channels in the workspace",input_schema:{type:"object",properties:{}}},{name:"slack_post_message",description:"Post a message to a Slack channel or DM. Pass `blocks` (Block Kit) for a rich card; `text` is the required notification fallback.",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID or name"},text:{type:"string",description:"Notification/fallback text (required)"},blocks:{type:"array",description:"Block Kit blocks for rich formatting (optional). Each block is a Slack Block Kit object (header/section/divider/context). section blocks may carry a button accessory with a url."}},required:["channel","text"]}},{name:"slack_reply_to_thread",description:"Reply to a specific message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"},text:{type:"string",description:"Reply text"}},required:["channel","thread_ts","text"]}},{name:"slack_add_reaction",description:"Add an emoji reaction to a message",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},timestamp:{type:"string",description:"Message timestamp"},reaction:{type:"string",description:"Emoji name without colons"}},required:["channel","timestamp","reaction"]}},{name:"slack_get_channel_history",description:"Get recent messages from a channel",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},limit:{type:"number",description:"Number of messages"}},required:["channel"]}},{name:"slack_get_thread_replies",description:"Get all replies in a message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"}},required:["channel","thread_ts"]}},{name:"slack_get_users",description:"List workspace users with basic profiles",input_schema:{type:"object",properties:{}}},{name:"slack_get_user_profile",description:"Get detailed profile for a specific user",input_schema:{type:"object",properties:{user_id:{type:"string",description:"Slack user ID"}},required:["user_id"]}},{name:"slack_lookup_user_by_email",description:"Find a Slack user by email. Returns { ok:true, user:{id,name,email} } on hit, { ok:false } when no user has that email. Prefer this over slack_get_users for email-based routing \u2014 single API call, exact match.",input_schema:{type:"object",properties:{email:{type:"string",description:"Email address to look up"}},required:["email"]}},{name:"slack_list_usergroups",description:"List workspace-defined user groups (e.g. @oncall, @platform). Each item has { id, handle, name, description, user_count }. Use the id with slack_get_usergroup_members to expand the membership.",input_schema:{type:"object",properties:{}}},{name:"slack_get_usergroup_members",description:"List user IDs that belong to a Slack usergroup. Pair with slack_post_message to DM each member, or use the group id directly in a channel message as <!subteam^ID> to @-mention.",input_schema:{type:"object",properties:{usergroup:{type:"string",description:"Usergroup id, e.g. S012ABC"}},required:["usergroup"]}},{name:"slack_search_users",description:'Fuzzy-search workspace users by display name or real name. Use when the user said something like "send to Sam" without an email. Returns up to `limit` ranked matches { id, name, email }. Slack has no native name-search API \u2014 this scans paginated users.list + does substring scoring (real_name > display_name > name). For large workspaces consider higher limit + ask the user to confirm if multiple hit.',input_schema:{type:"object",properties:{query:{type:"string",description:"Substring to match against names (case-insensitive)"},limit:{type:"number",description:"Max matches to return (default 5, max 25)"}},required:["query"]}}]};import{existsSync as nr}from"fs";import{fileURLToPath as or}from"url";import{dirname as ar,resolve as cr}from"path";import{resolveIntegrationToken as lr}from"@zibby/core/backend-client.js";function ur(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let r=ar(or(import.meta.url)),t=cr(r,"..","bin","mcp-lark.mjs");return nr(t)?t:null}var pr=6e3*1e3,oe=null;async function dr(){let{appId:r,appSecret:t,host:e}=await lr("lark");if(oe&&oe.appId===r&&oe.expiresAt>Date.now())return{token:oe.token,host:e};let n=await(await fetch(`${e}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return oe={token:n.tenant_access_token,expiresAt:Date.now()+pr,appId:r},{token:n.tenant_access_token,host:e}}async function Z(r,t,e={}){let{token:s,host:n}=await dr(),i=`${n}${t}`,o={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(o.body=JSON.stringify(e));let a=await(await fetch(i,o)).json();if(a.code!==0)throw new Error(`Lark API ${t} error: ${a.msg||a.code}`);return a.data||{}}function at(r){return JSON.stringify({text:r})}function mr(r){return!r||typeof r!="string"||r.startsWith("oc_")?"chat_id":r.startsWith("ou_")?"open_id":r.startsWith("on_")?"union_id":r.startsWith("cli_")?"app_id":r.includes("@")?"email":"chat_id"}var M={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:j.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
|
|
238
|
+
- slack_list_usergroups, slack_get_usergroup_members (workspace-defined teams like @oncall, @platform)`,resolve(){let r=or();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_USER_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);for(let e of this.envKeys)process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},async handleToolCall(r,t){try{switch(r){case"slack_list_channels":{let e=await J("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(e.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!t.channel||!t.text)return JSON.stringify({error:"channel and text are required"});let e=await J("chat.postMessage",{channel:t.channel,text:t.text,...t.blocks?{blocks:t.blocks}:{}});return JSON.stringify({ok:!0,ts:e.ts,channel:e.channel})}case"slack_reply_to_thread":{if(!t.channel||!t.thread_ts||!t.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let e=await J("chat.postMessage",{channel:t.channel,thread_ts:t.thread_ts,text:t.text});return JSON.stringify({ok:!0,ts:e.ts})}case"slack_add_reaction":return!t.channel||!t.timestamp||!t.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await J("reactions.add",{channel:t.channel,timestamp:t.timestamp,name:t.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!t.channel)return JSON.stringify({error:"channel is required"});let e=await J("conversations.history",{channel:t.channel,limit:t.limit||20});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!t.channel||!t.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let e=await J("conversations.replies",{channel:t.channel,ts:t.thread_ts});return JSON.stringify({messages:(e.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let e=await J("users.list",{limit:100});return JSON.stringify({users:(e.members||[]).filter(s=>!s.is_bot&&!s.deleted).map(s=>({id:s.id,name:s.real_name||s.name}))})}case"slack_get_user_profile":{if(!t.user_id)return JSON.stringify({error:"user_id is required"});let e=await J("users.profile.get",{user:t.user_id});return JSON.stringify({profile:e.profile})}case"slack_lookup_user_by_email":{if(!t.email)return JSON.stringify({error:"email is required"});try{let e=await J("users.lookupByEmail",{email:t.email});return JSON.stringify({ok:!0,user:{id:e.user?.id,name:e.user?.real_name||e.user?.name,email:e.user?.profile?.email||t.email}})}catch(e){if(/users_not_found/.test(e.message))return JSON.stringify({ok:!1,reason:"users_not_found"});throw e}}case"slack_list_usergroups":{let e=await J("usergroups.list",{});return JSON.stringify({usergroups:(e.usergroups||[]).map(s=>({id:s.id,handle:s.handle,name:s.name,description:s.description||"",user_count:Number(s.user_count||0)}))})}case"slack_get_usergroup_members":{if(!t.usergroup)return JSON.stringify({error:"usergroup id is required"});let e=await J("usergroups.users.list",{usergroup:t.usergroup});return JSON.stringify({users:e.users||[]})}case"slack_search_users":{if(!t.query||typeof t.query!="string")return JSON.stringify({error:"query is required"});let e=t.query.trim().toLowerCase();if(!e)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(t.limit)||5,25)),n=[],i,o=5;for(let a=0;a<o;a+=1){let u={limit:200};i&&(u.cursor=i);let l=await J("users.list",u);for(let p of l.members||[])p.deleted||p.is_bot||n.push(p);if(i=l.response_metadata?.next_cursor,!i)break}let c=[];for(let a of n){let u=(a.real_name||"").toLowerCase(),l=(a.profile?.display_name||"").toLowerCase(),p=(a.name||"").toLowerCase(),d=0;u.includes(e)&&(d+=100-Math.abs(u.length-e.length)),l.includes(e)&&(d+=60-Math.abs(l.length-e.length)),p.includes(e)&&(d+=30-Math.abs(p.length-e.length)),(u===e||l===e)&&(d+=200),d>0&&c.push({id:a.id,name:a.real_name||a.profile?.display_name||a.name,email:a.profile?.email||void 0,_score:d})}return c.sort((a,u)=>u._score-a._score),JSON.stringify({ok:!0,matches:c.slice(0,s).map(({_score:a,...u})=>u),scanned:n.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"slack_list_channels",description:"List public channels in the workspace",input_schema:{type:"object",properties:{}}},{name:"slack_post_message",description:"Post a message to a Slack channel or DM. Pass `blocks` (Block Kit) for a rich card; `text` is the required notification fallback.",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID or name"},text:{type:"string",description:"Notification/fallback text (required)"},blocks:{type:"array",description:"Block Kit blocks for rich formatting (optional). Each block is a Slack Block Kit object (header/section/divider/context). section blocks may carry a button accessory with a url."}},required:["channel","text"]}},{name:"slack_reply_to_thread",description:"Reply to a specific message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"},text:{type:"string",description:"Reply text"}},required:["channel","thread_ts","text"]}},{name:"slack_add_reaction",description:"Add an emoji reaction to a message",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},timestamp:{type:"string",description:"Message timestamp"},reaction:{type:"string",description:"Emoji name without colons"}},required:["channel","timestamp","reaction"]}},{name:"slack_get_channel_history",description:"Get recent messages from a channel",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},limit:{type:"number",description:"Number of messages"}},required:["channel"]}},{name:"slack_get_thread_replies",description:"Get all replies in a message thread",input_schema:{type:"object",properties:{channel:{type:"string",description:"Channel ID"},thread_ts:{type:"string",description:"Thread timestamp"}},required:["channel","thread_ts"]}},{name:"slack_get_users",description:"List workspace users with basic profiles",input_schema:{type:"object",properties:{}}},{name:"slack_get_user_profile",description:"Get detailed profile for a specific user",input_schema:{type:"object",properties:{user_id:{type:"string",description:"Slack user ID"}},required:["user_id"]}},{name:"slack_lookup_user_by_email",description:"Find a Slack user by email. Returns { ok:true, user:{id,name,email} } on hit, { ok:false } when no user has that email. Prefer this over slack_get_users for email-based routing \u2014 single API call, exact match.",input_schema:{type:"object",properties:{email:{type:"string",description:"Email address to look up"}},required:["email"]}},{name:"slack_list_usergroups",description:"List workspace-defined user groups (e.g. @oncall, @platform). Each item has { id, handle, name, description, user_count }. Use the id with slack_get_usergroup_members to expand the membership.",input_schema:{type:"object",properties:{}}},{name:"slack_get_usergroup_members",description:"List user IDs that belong to a Slack usergroup. Pair with slack_post_message to DM each member, or use the group id directly in a channel message as <!subteam^ID> to @-mention.",input_schema:{type:"object",properties:{usergroup:{type:"string",description:"Usergroup id, e.g. S012ABC"}},required:["usergroup"]}},{name:"slack_search_users",description:'Fuzzy-search workspace users by display name or real name. Use when the user said something like "send to Sam" without an email. Returns up to `limit` ranked matches { id, name, email }. Slack has no native name-search API \u2014 this scans paginated users.list + does substring scoring (real_name > display_name > name). For large workspaces consider higher limit + ask the user to confirm if multiple hit.',input_schema:{type:"object",properties:{query:{type:"string",description:"Substring to match against names (case-insensitive)"},limit:{type:"number",description:"Max matches to return (default 5, max 25)"}},required:["query"]}}]};import{existsSync as ar}from"fs";import{fileURLToPath as cr}from"url";import{dirname as lr,resolve as ur}from"path";import{resolveIntegrationToken as pr}from"@zibby/core/backend-client.js";function dr(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let r=lr(cr(import.meta.url)),t=ur(r,"..","bin","mcp-lark.mjs");return ar(t)?t:null}var mr=6e3*1e3,ae=null;async function fr(){let{appId:r,appSecret:t,host:e}=await pr("lark");if(ae&&ae.appId===r&&ae.expiresAt>Date.now())return{token:ae.token,host:e};let n=await(await fetch(`${e}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:t})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return ae={token:n.tenant_access_token,expiresAt:Date.now()+mr,appId:r},{token:n.tenant_access_token,host:e}}async function Z(r,t,e={}){let{token:s,host:n}=await fr(),i=`${n}${t}`,o={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(o.body=JSON.stringify(e));let a=await(await fetch(i,o)).json();if(a.code!==0)throw new Error(`Lark API ${t} error: ${a.msg||a.code}`);return a.data||{}}function ut(r){return JSON.stringify({text:r})}function yr(r){return!r||typeof r!="string"||r.startsWith("oc_")?"chat_id":r.startsWith("ou_")?"open_id":r.startsWith("on_")?"union_id":r.startsWith("cli_")?"app_id":r.includes("@")?"email":"chat_id"}var M={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:$.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
|
|
239
239
|
You can send messages and replies on Lark. Use:
|
|
240
240
|
- lark_send_message: post a message to a chat, user, or DM
|
|
241
241
|
- lark_reply: reply to an existing message (threaded)
|
|
242
242
|
- lark_list_chats: list chats the bot is a member of
|
|
243
243
|
- lark_get_chat_history: fetch recent messages in a chat
|
|
244
244
|
- lark_lookup_user_by_email: resolve an email \u2192 open_id for direct DM (prefer this over emailing through lark_send_message when the agent has a user_id already)
|
|
245
|
-
When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=
|
|
245
|
+
When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=dr();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_USER_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},tools:[{name:"lark_send_message",description:"Send a text message to a Lark chat, user, or DM. receive_id can be a chat_id (oc_*), open_id (ou_*), union_id (on_*), or email.",input_schema:{type:"object",properties:{receive_id:{type:"string",description:"Target id: chat_id (oc_*), open_id (ou_*), union_id (on_*), or email"},text:{type:"string",description:"Message text"}},required:["receive_id","text"]}},{name:"lark_reply",description:"Reply to an existing Lark message (creates a thread). Use the message_id from the inbound event.",input_schema:{type:"object",properties:{message_id:{type:"string",description:"Lark message id (om_*) to reply to"},text:{type:"string",description:"Reply text"}},required:["message_id","text"]}},{name:"lark_list_chats",description:"List chats (groups + DMs) the bot is a member of.",input_schema:{type:"object",properties:{page_size:{type:"number",description:"Max results (default 50)"}}}},{name:"lark_get_chat_history",description:"Fetch recent messages in a chat.",input_schema:{type:"object",properties:{chat_id:{type:"string",description:"Chat id (oc_*)"},page_size:{type:"number",description:"Max messages (default 20)"}},required:["chat_id"]}},{name:"lark_lookup_user_by_email",description:"Resolve an email address to a Lark user id (open_id). Returns { ok:true, user:{open_id,email,name} } on hit, { ok:false } if no Lark user has that email. Use the open_id as `receive_id` in lark_send_message to DM.",input_schema:{type:"object",properties:{email:{type:"string",description:"Email address to look up"}},required:["email"]}},{name:"lark_search_users",description:'Fuzzy-search users by name across chats the bot is a member of. Lark has no public org-wide user search API for bots \u2014 this walks the bot\'s chat memberships and matches names client-side. Best for "send to Sam" style routing where you have a name but no email. Returns up to `limit` ranked matches { open_id, name }.',input_schema:{type:"object",properties:{query:{type:"string",description:"Substring to match against user names (case-insensitive)"},limit:{type:"number",description:"Max matches to return (default 5, max 25)"}},required:["query"]}}],async handleToolCall(r,t){try{switch(r){case"lark_send_message":{if(!t.receive_id||!t.text)return JSON.stringify({error:"receive_id and text are required"});let e=yr(t.receive_id),s=await Z("POST",`/open-apis/im/v1/messages?receive_id_type=${e}`,{receive_id:t.receive_id,msg_type:"text",content:ut(t.text)});return JSON.stringify({ok:!0,message_id:s.message_id})}case"lark_reply":{if(!t.message_id||!t.text)return JSON.stringify({error:"message_id and text are required"});let e=await Z("POST",`/open-apis/im/v1/messages/${encodeURIComponent(t.message_id)}/reply`,{msg_type:"text",content:ut(t.text)});return JSON.stringify({ok:!0,message_id:e.message_id})}case"lark_list_chats":{let e=t.page_size||50,n=((await Z("GET",`/open-apis/im/v1/chats?page_size=${e}`)).items||[]).map(i=>({chat_id:i.chat_id,name:i.name,description:i.description,owner_id:i.owner_id,chat_mode:i.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!t.chat_id)return JSON.stringify({error:"chat_id is required"});let e=t.page_size||20,n=((await Z("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(t.chat_id)}&page_size=${e}&sort_type=ByCreateTimeDesc`)).items||[]).map(i=>({message_id:i.message_id,sender_id:i.sender?.id,sender_type:i.sender?.sender_type,msg_type:i.msg_type,content:i.body?.content,create_time:i.create_time}));return JSON.stringify({messages:n})}case"lark_lookup_user_by_email":{if(!t.email)return JSON.stringify({error:"email is required"});let s=((await Z("POST","/open-apis/contact/v3/users/batch_get_id?user_id_type=open_id",{emails:[t.email]})).user_list||[]).find(n=>n.email===t.email&&n.user_id);return JSON.stringify(s?{ok:!0,user:{open_id:s.user_id,email:s.email,name:s.name||void 0}}:{ok:!1,reason:"no_lark_user_for_email"})}case"lark_search_users":{if(!t.query||typeof t.query!="string")return JSON.stringify({error:"query is required"});let e=t.query.trim().toLowerCase();if(!e)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(t.limit)||5,25)),n=200,o=((await Z("GET","/open-apis/im/v1/chats?page_size=100")).items||[]).map(l=>l.chat_id),c=new Set,a=[];for(let l of o){if(a.length>=n)break;try{let p=await Z("GET",`/open-apis/im/v1/chats/${encodeURIComponent(l)}/members?member_id_type=open_id&page_size=100`);for(let d of p.items||[])if(!(!d.member_id||c.has(d.member_id))&&(c.add(d.member_id),a.push({open_id:d.member_id,name:d.name||""}),a.length>=n))break}catch(p){console.warn(`[lark] member scan failed for ${l}: ${p.message}`)}}let u=[];for(let l of a){let p=(l.name||"").toLowerCase();if(!p)continue;let d=0;p.includes(e)&&(d+=100-Math.abs(p.length-e.length)),p===e&&(d+=200),d>0&&u.push({open_id:l.open_id,name:l.name,_score:d})}return u.sort((l,p)=>p._score-l._score),JSON.stringify({ok:!0,matches:u.slice(0,s).map(({_score:l,...p})=>p),scanned:a.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}}};var pt={id:"chat_notify",description:"Chat notification meta-skill \u2014 routes to whichever messaging integration (Slack OR Lark) the user has configured for this project.",envKeys:[...U.envKeys||[],...M.envKeys||[]],get serverName(){if(process.env.SLACK_CHANNEL)return U.serverName;if(process.env.LARK_RECEIVE_ID)return M.serverName},get allowedTools(){return process.env.SLACK_CHANNEL?U.allowedTools||[]:process.env.LARK_RECEIVE_ID?M.allowedTools||[]:[]},promptFragment:`## Chat notifications (Slack OR Lark \u2014 at least one connected)
|
|
246
246
|
You can post chat messages via either:
|
|
247
247
|
- slack_post_message (channel, text) \u2014 Slack, when SLACK_CHANNEL is set
|
|
248
248
|
- lark_send_message (receive_id, text) \u2014 Lark, when LARK_RECEIVE_ID is set
|
|
249
|
-
Use whichever the user has configured.`,resolve(r){return process.env.SLACK_CHANNEL&&typeof U.resolve=="function"?U.resolve(r):process.env.LARK_RECEIVE_ID&&typeof M.resolve=="function"?M.resolve(r):null},async handleToolCall(r,t,e){return typeof r=="string"&&r.startsWith("slack_")?U.handleToolCall(r,t,e):typeof r=="string"&&r.startsWith("lark_")?M.handleToolCall(r,t,e):JSON.stringify({error:`chat_notify: unknown tool "${r}". Expected slack_* or lark_*.`})},get tools(){return[...U.tools||[],...M.tools||[]]}};import{createRequire as
|
|
249
|
+
Use whichever the user has configured.`,resolve(r){return process.env.SLACK_CHANNEL&&typeof U.resolve=="function"?U.resolve(r):process.env.LARK_RECEIVE_ID&&typeof M.resolve=="function"?M.resolve(r):null},async handleToolCall(r,t,e){return typeof r=="string"&&r.startsWith("slack_")?U.handleToolCall(r,t,e):typeof r=="string"&&r.startsWith("lark_")?M.handleToolCall(r,t,e):JSON.stringify({error:`chat_notify: unknown tool "${r}". Expected slack_* or lark_*.`})},get tools(){return[...U.tools||[],...M.tools||[]]}};import{createRequire as hr}from"module";import{execFileSync as gr}from"child_process";import{join as dt}from"path";import{existsSync as _r}from"fs";var br=hr(import.meta.url);function kr(){if(process.env.MCP_MEMORY_PATH)return process.env.MCP_MEMORY_PATH;try{return br.resolve("@zibby/ui-memory/mcp-server")}catch{return null}}var mt={id:"memory",serverName:"memory",allowedTools:["mcp__memory__*"],envKeys:[],description:"Zibby Memory MCP Server (test history, selectors, page model)",async middleware(){try{let{createMemoryMiddleware:r}=await import("@zibby/ui-memory");return r()}catch{return null}},promptFragment:`BEFORE executing browser actions:
|
|
250
250
|
- Review any test memory/history above. Prefer selectors proven to work.
|
|
251
251
|
- If a previous run failed, avoid the same approach.
|
|
252
252
|
- After setup/login completes, navigate directly to the target page instead of clicking through menus.
|
|
@@ -258,18 +258,18 @@ DURING execution \u2014 when a selector fails and you switch to a fallback:
|
|
|
258
258
|
AFTER completing the test, you MUST call memory_save_insight at least once:
|
|
259
259
|
- Save any useful finding: reliable selectors, timing quirks, navigation patterns, workarounds.
|
|
260
260
|
- Category: selector_tip | timing | navigation | workaround | flaky | general
|
|
261
|
-
- Be specific \u2014 future runs will read your insights.`,resolve(){let r=
|
|
261
|
+
- Be specific \u2014 future runs will read your insights.`,resolve(){let r=kr();if(!r)throw new Error(`\u274C Memory MCP server not found
|
|
262
262
|
|
|
263
263
|
Install @zibby/ui-memory:
|
|
264
|
-
npm install @zibby/ui-memory`);let t=
|
|
264
|
+
npm install @zibby/ui-memory`);let t=dt(process.cwd(),".zibby","memory");if(!_r(dt(t,".dolt")))throw new Error(`\u274C Memory database not initialized
|
|
265
265
|
|
|
266
266
|
Run:
|
|
267
|
-
zibby init --mem`);try{let e=
|
|
267
|
+
zibby init --mem`);try{let e=gr("dolt",["sql","-q","SELECT COUNT(*) AS cnt FROM test_runs","-r","json"],{cwd:t,encoding:"utf-8",timeout:5e3}),s=JSON.parse(e.trim()).rows||[];if(!s[0]||s[0].cnt===0)return console.log("[memory] Database empty \u2014 memory tools activate after first completed run"),null}catch(e){throw new Error(`\u274C Dolt not found or memory database error
|
|
268
268
|
|
|
269
269
|
Install Dolt:
|
|
270
270
|
https://docs.dolthub.com/introduction/installation
|
|
271
271
|
|
|
272
|
-
Error: ${e.message}`,{cause:e})}return{command:"node",args:[r,"--db-path",t],description:this.description}},tools:[{name:"memory_get_test_history",description:"Query recent test runs with pass/fail results and timing",input_schema:{type:"object",properties:{specPath:{type:"string",description:"Filter by spec path (substring match)"},limit:{type:"number",description:"Max results (default 10)"}}}},{name:"memory_get_selectors",description:"Query known selectors for a page with stability metrics",input_schema:{type:"object",properties:{pageUrl:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_page_model",description:"Query page structure \u2014 elements, roles, selectors",input_schema:{type:"object",properties:{url:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_navigation",description:"Query known page-to-page transitions",input_schema:{type:"object",properties:{fromUrl:{type:"string",description:"Filter by source URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_save_insight",description:"Save a useful observation for future runs (selector tips, timing, workarounds)",input_schema:{type:"object",properties:{category:{type:"string",enum:["selector_tip","timing","navigation","workaround","flaky","general"],description:"Type of insight"},content:{type:"string",description:"The insight text \u2014 be specific and actionable"},specPath:{type:"string",description:"Related spec path"},sessionId:{type:"string",description:"Current session ID"}},required:["category","content"]}}]};import{existsSync as
|
|
272
|
+
Error: ${e.message}`,{cause:e})}return{command:"node",args:[r,"--db-path",t],description:this.description}},tools:[{name:"memory_get_test_history",description:"Query recent test runs with pass/fail results and timing",input_schema:{type:"object",properties:{specPath:{type:"string",description:"Filter by spec path (substring match)"},limit:{type:"number",description:"Max results (default 10)"}}}},{name:"memory_get_selectors",description:"Query known selectors for a page with stability metrics",input_schema:{type:"object",properties:{pageUrl:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_page_model",description:"Query page structure \u2014 elements, roles, selectors",input_schema:{type:"object",properties:{url:{type:"string",description:"Filter by page URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_get_navigation",description:"Query known page-to-page transitions",input_schema:{type:"object",properties:{fromUrl:{type:"string",description:"Filter by source URL (substring match)"},limit:{type:"number",description:"Max results (default 20)"}}}},{name:"memory_save_insight",description:"Save a useful observation for future runs (selector tips, timing, workarounds)",input_schema:{type:"object",properties:{category:{type:"string",enum:["selector_tip","timing","navigation","workaround","flaky","general"],description:"Type of insight"},content:{type:"string",description:"The insight text \u2014 be specific and actionable"},specPath:{type:"string",description:"Related spec path"},sessionId:{type:"string",description:"Current session ID"}},required:["category","content"]}}]};import{existsSync as wr,readFileSync as Sr}from"fs";import{homedir as vr}from"os";import{join as Nr}from"path";import{spawn as Ir}from"child_process";var V={jira:{description:"Jira issue search, details, comments, transitions",integrationProvider:"jira",envKeys:[],setupInstructions:`To connect Jira:
|
|
273
273
|
1. Go to Settings \u2192 Integrations (https://studio.zibby.dev/integrations)
|
|
274
274
|
2. Click "Connect Jira" and authorize via Atlassian OAuth
|
|
275
275
|
3. After OAuth completes, ask me to install Jira again`},github:{description:"GitHub issues, PRs, repository management",integrationProvider:"github",envKeys:[],setupInstructions:`To connect GitHub:
|
|
@@ -281,15 +281,15 @@ AFTER completing the test, you MUST call memory_save_insight at least once:
|
|
|
281
281
|
3. After OAuth completes, ask me to install Slack again`},sentry:{description:"Sentry error tracking \u2014 projects, issues, events",integrationProvider:"sentry",envKeys:[],setupInstructions:`To connect Sentry:
|
|
282
282
|
1. Go to Settings \u2192 Integrations (https://studio.zibby.dev/integrations)
|
|
283
283
|
2. Click "Connect Sentry" and authorize
|
|
284
|
-
3. After OAuth completes, ask me to install Sentry again`},runner:{description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],setupInstructions:"Ready to use. Runs zibby test workflows as background processes \u2014 each with its own browser and session."},browser:{description:"Playwright browser automation (navigate, click, fill, screenshot)",envKeys:[],setupInstructions:"Ready to use. Starts a Playwright browser for web automation."},memory:{description:"Test memory database (Dolt) \u2014 history, selectors, insights",envKeys:[],setupInstructions:"Ready to use. Requires Dolt (https://docs.dolthub.com/introduction/installation) and a memory DB via `zibby init --mem`."},"chat-memory":{description:"Persistent chat memory \u2014 remembers facts, decisions, and task history across sessions (Dolt-backed)",envKeys:[],setupInstructions:'Ready to use. Requires Dolt installed. Tables auto-create on first use. Install with: "add chat memory" or "install chat-memory".'},git:{description:"Clone and explore git repositories locally for codebase analysis",envKeys:[],setupInstructions:"Ready to use. Clone repos with git_checkout, explore with git_explore. Auto-authenticates with GitHub/GitLab tokens."}};function
|
|
285
|
-
`)}function
|
|
286
|
-
`)}function
|
|
284
|
+
3. After OAuth completes, ask me to install Sentry again`},runner:{description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],setupInstructions:"Ready to use. Runs zibby test workflows as background processes \u2014 each with its own browser and session."},browser:{description:"Playwright browser automation (navigate, click, fill, screenshot)",envKeys:[],setupInstructions:"Ready to use. Starts a Playwright browser for web automation."},memory:{description:"Test memory database (Dolt) \u2014 history, selectors, insights",envKeys:[],setupInstructions:"Ready to use. Requires Dolt (https://docs.dolthub.com/introduction/installation) and a memory DB via `zibby init --mem`."},"chat-memory":{description:"Persistent chat memory \u2014 remembers facts, decisions, and task history across sessions (Dolt-backed)",envKeys:[],setupInstructions:'Ready to use. Requires Dolt installed. Tables auto-create on first use. Install with: "add chat memory" or "install chat-memory".'},git:{description:"Clone and explore git repositories locally for codebase analysis",envKeys:[],setupInstructions:"Ready to use. Clone repos with git_checkout, explore with git_explore. Auto-authenticates with GitHub/GitLab tokens."}};function Or(){let r=["## Available Skills"];for(let[t,e]of Object.entries(V)){let s=e.integrationProvider?`integration: ${e.integrationProvider}`:"ready";r.push(`- ${t}: ${e.description} [${s}]`)}return r.push(""),r.push("Use the install_skill / uninstall_skill / list_available_skills tools to manage skills."),r.push(`Zibby third party Integration settings page: ${Te()}`),r.push(""),r.push("## Tool-First Policy (mandatory)"),r.push("CRITICAL RULES \u2014 follow these strictly:"),r.push("1. When user asks to do something and a matching skill is available but not installed, IMMEDIATELY call install_skill. Never ask for credentials or confirmation first."),r.push(`2. If install_skill succeeds, the skill's tools are now available. Use them RIGHT AWAY in the same turn \u2014 don't just say "it's connected", actually call the tools.`),r.push("3. If install_skill reports needsIntegration, tell the user to connect via the integration URL and try again after."),r.push("4. When the relevant skill is already installed, use its tools directly \u2014 don't ask for IDs or keys. Each skill's own instructions explain the workflow."),r.push("5. If a task needs multiple skills (e.g. data from one + execution from another), install all of them, then follow each skill's workflow instructions."),r.join(`
|
|
285
|
+
`)}function Rr(){if(process.env.ZIBBY_USER_TOKEN)return process.env.ZIBBY_USER_TOKEN;try{let r=Nr(vr(),".zibby","config.json");return wr(r)&&JSON.parse(Sr(r,"utf-8")).sessionToken||null}catch{return null}}function Ar(){return(process.env.ZIBBY_API_URL||process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app").replace(/\/$/,"")}function Te(){return`${(process.env.ZIBBY_FRONTEND_URL||process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev").replace(/\/$/,"")}/integrations`}function $r(r){try{let t=process.platform;return Ir(t==="darwin"?"open":t==="win32"?"cmd":"xdg-open",t==="win32"?["/c","start","",r]:[r],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}async function jr(){let r=Rr();if(!r)return{checked:!1,statuses:null,reason:"no-session-token"};try{let t=await fetch(`${Ar()}/integrations/status`,{method:"GET",headers:{Authorization:`Bearer ${r}`}});return t.ok?{checked:!0,statuses:await t.json()||{},reason:null}:{checked:!1,statuses:null,reason:`status-${t.status}`}}catch{return{checked:!1,statuses:null,reason:"network-error"}}}function ft(r,t){if(!t||!r)return{connected:null};let e=r[t];return!e||typeof e.connected!="boolean"?{connected:null,details:e||null}:{connected:e.connected,details:e}}var yt={id:"skill-installer",description:"Live skill installation for chat sessions",envKeys:[],catalog:V,promptFragment:Or,tools:[{name:"install_skill",description:"Install a skill into the current chat session so its tools become available",input_schema:{type:"object",properties:{skillId:{type:"string",description:'Skill identifier to install (e.g. "jira", "github", "browser", "memory")'}},required:["skillId"]}},{name:"uninstall_skill",description:"Remove a skill from the current chat session",input_schema:{type:"object",properties:{skillId:{type:"string",description:"Skill identifier to remove"}},required:["skillId"]}},{name:"list_available_skills",description:"List all skills that can be installed, with their env-var readiness status",input_schema:{type:"object",properties:{}}}],async handleToolCall(r,t,e){let{activeSkills:s}=e,n=await jr();if(r==="list_available_skills"){let i=Object.entries(V).map(([o,c])=>{let a=s.includes(o),u=ft(n.statuses,c.integrationProvider);return{id:o,description:c.description,installed:a,integrationProvider:c.integrationProvider||void 0,integrationConnected:u.connected,setupInstructions:u.connected===!1?c.setupInstructions:void 0}});return JSON.stringify({skills:i})}if(r==="install_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(s.includes(i)){let l=V[i],{getSkill:p}=await import("@zibby/agent-workflow"),m=(p(i)?.tools||[]).map(f=>f.name);return JSON.stringify({ok:!0,alreadyInstalled:!0,skillId:i,description:l?.description,availableTools:m,integrationUrl:l?.integrationProvider?Te():void 0,hint:`${i} is already active. Tools available: ${m.join(", ")}. Use them directly.`})}if(!V[i])return JSON.stringify({ok:!1,error:`Unknown skill "${i}". Available: ${Object.keys(V).join(", ")}`});let o=V[i];if(o.integrationProvider){let l=ft(n.statuses,o.integrationProvider),p=Te();if(n.checked&&l.connected===!1){let d=$r(p);return JSON.stringify({ok:!1,error:`${o.integrationProvider} is not connected for this Zibby account yet`,needsIntegration:!0,integrationUrl:p,openedBrowser:d,setupInstructions:`Please connect ${o.integrationProvider} first at ${p}. After you finish OAuth, ask me to install ${i} again.`})}}s.push(i);let{getSkill:c}=await import("@zibby/agent-workflow"),u=(c(i)?.tools||[]).map(l=>l.name);return JSON.stringify({ok:!0,installed:i,description:o.description,availableTools:u,hint:`${i} is now active. You now have these tools: ${u.join(", ")}. Use them immediately to help the user \u2014 don't just confirm installation.`})}if(r==="uninstall_skill"){let{skillId:i}=t;if(!i)return JSON.stringify({ok:!1,error:"skillId is required"});if(i==="skill-installer")return JSON.stringify({ok:!1,error:"Cannot uninstall the skill installer"});let o=s.indexOf(i);return o===-1?JSON.stringify({ok:!1,error:`${i} is not installed`}):(s.splice(o,1),JSON.stringify({ok:!0,uninstalled:i}))}return JSON.stringify({error:`Unknown tool: ${r}`})},resolve(){return null}};import{readFileSync as Tr,readdirSync as xr,statSync as gt,writeFileSync as Er,mkdirSync as Cr}from"fs";import{join as _t,resolve as Lr,relative as Jr}from"path";import{execSync as bt}from"child_process";var ht=256*1024,Pr=64*1024,kt={id:"core-tools",description:"File read/write, directory listing, shell commands, open URLs, wait for async operations",envKeys:[],tools:[{name:"read_file",description:"Read the contents of a file. Returns the text content.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"}},required:["path"]}},{name:"write_file",description:"Write content to a file. Creates parent directories if needed.",input_schema:{type:"object",properties:{path:{type:"string",description:"File path (relative to cwd or absolute)"},content:{type:"string",description:"Content to write"}},required:["path","content"]}},{name:"list_directory",description:"List files and directories in a path. Returns names with type indicators (/ for dirs).",input_schema:{type:"object",properties:{path:{type:"string",description:"Directory path (relative to cwd or absolute). Defaults to cwd."}}}},{name:"run_command",description:"Run a shell command and return its output. Use for grep, git, npm, etc.",input_schema:{type:"object",properties:{command:{type:"string",description:"Shell command to execute"},cwd:{type:"string",description:"Working directory (optional, defaults to project root)"}},required:["command"]}},{name:"open_url",description:"Open a URL in the user's default browser. Use for OAuth flows, documentation, integration setup pages.",input_schema:{type:"object",properties:{url:{type:"string",description:"URL to open"}},required:["url"]}},{name:"wait",description:"Wait for N seconds. Use this for async operations (tests, builds, deploys) \u2014 wait, then check status again.",input_schema:{type:"object",properties:{seconds:{type:"number",description:"Seconds to wait (default: 5, max: 300)"},reason:{type:"string",description:"Why waiting (for logging/clarity)"}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"read_file":return Ur(t,s);case"write_file":return Dr(t,s);case"list_directory":return Mr(t,s);case"run_command":return qr(t,s);case"open_url":return Kr(t);case"wait":return await Br(t,e?.options?.signal);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};function he(r,t){return Lr(t,r)}function Ur(r,t){let e=he(r.path,t),s=gt(e);return s.size>ht?JSON.stringify({error:`File too large (${(s.size/1024).toFixed(0)}KB). Max: ${ht/1024}KB`}):Tr(e,"utf-8")}function Dr(r,t){let e=he(r.path,t),s=_t(e,"..");return Cr(s,{recursive:!0}),Er(e,r.content,"utf-8"),JSON.stringify({ok:!0,path:Jr(t,e)})}function Mr(r,t){let e=he(r.path||".",t);return xr(e).map(n=>{try{return gt(_t(e,n)).isDirectory()?`${n}/`:n}catch{return n}}).join(`
|
|
286
|
+
`)}function qr(r,t){let e=r.cwd?he(r.cwd,t):t;return bt(r.command,{cwd:e,encoding:"utf-8",timeout:3e4,maxBuffer:Pr,stdio:["pipe","pipe","pipe"]})||"(no output)"}function Kr(r){let{url:t}=r;if(!t||!t.startsWith("http://")&&!t.startsWith("https://"))return JSON.stringify({error:"Invalid URL \u2014 must start with http:// or https://"});let e=process.platform,s=e==="darwin"?"open":e==="win32"?"start":"xdg-open";try{return bt(`${s} "${t}"`,{stdio:"ignore",timeout:5e3}),JSON.stringify({ok:!0,opened:t})}catch{return JSON.stringify({ok:!1,error:`Could not open browser. Please visit: ${t}`})}}async function Br(r,t){let e=Math.min(Math.max(r.seconds||5,1),300),s=r.reason||"async operation",n=500,i=Date.now()+e*1e3;for(;Date.now()<i;){if(t?.aborted)return JSON.stringify({ok:!0,waited:Math.round((e*1e3-(i-Date.now()))/1e3),reason:s,interrupted:!0});await new Promise(o=>setTimeout(o,Math.min(n,i-Date.now())))}return JSON.stringify({ok:!0,waited:e,reason:s})}import{existsSync as Fr}from"fs";import{fileURLToPath as Gr}from"url";import{dirname as zr,resolve as Wr}from"path";import{resolveIntegrationToken as wt}from"@zibby/core/backend-client.js";function Hr(){if(process.env.MCP_SENTRY_PATH)return process.env.MCP_SENTRY_PATH;let r=zr(Gr(import.meta.url)),t=Wr(r,"..","bin","mcp-sentry.mjs");return Fr(t)?t:null}async function St(r,t={}){let{token:e,organizationSlug:s}=await wt("sentry"),n=`https://sentry.io/api/0/organizations/${s}${r}`,i=await fetch(n,{method:t.method||"GET",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok){let o=await i.text().catch(()=>"");throw new Error(`Sentry API ${i.status}: ${o.slice(0,300)}`)}return i.json()}async function Yr(){return St("/projects/?per_page=50")}async function Zr({query:r="is:unresolved",sort:t="date",project:e,limit:s=25}={}){let n=`/issues/?query=${encodeURIComponent(r)}&sort=${t}&per_page=${s}`;return e&&(n+=`&project=${encodeURIComponent(e)}`),St(n)}async function Vr(r){if(!r)throw new Error("sentryGetIssue: issueId is required");let{token:t}=await wt("sentry"),e=await fetch(`https://sentry.io/api/0/issues/${r}/`,{headers:{Authorization:`Bearer ${t}`}});if(!e.ok){let s=await e.text().catch(()=>"");throw new Error(`Sentry API ${e.status}: ${s.slice(0,300)}`)}return e.json()}var ge={id:"sentry",serverName:"sentry",allowedTools:["mcp__sentry__*"],requiresIntegration:$.SENTRY,description:"Sentry error tracking \u2014 projects, issues, events",envKeys:[],tools:[],promptFragment:`## Sentry (connected)
|
|
287
287
|
You have access to the user's Sentry. Use these tools:
|
|
288
288
|
- sentry_list_projects: List projects in the organization
|
|
289
289
|
- sentry_list_issues: List errors/issues (supports Sentry search query, project filter, sort)
|
|
290
|
-
- sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let r=
|
|
290
|
+
- sentry_get_issue: Get detailed info about a specific issue (requires issueId)`,resolve(){let r=Hr();if(!r)return null;let t={};for(let e of["PROJECT_API_TOKEN","ZIBBY_USER_TOKEN","ZIBBY_ACCOUNT_API_URL","ZIBBY_ENV","ZIBBY_PROD_ACCOUNT_API_URL","PROGRESS_API_URL","EXECUTION_ID","PROJECT_ID","STAGE"])process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r],env:t,alwaysLoad:!0}},async handleToolCall(r,t={}){try{switch(r){case"sentry_list_projects":{let e=await Yr();return JSON.stringify({projects:e.map(s=>({slug:s.slug,name:s.name,platform:s.platform}))})}case"sentry_list_issues":{let e=await Zr({query:t.query,sort:t.sort,project:t.project,limit:t.limit});return JSON.stringify({issues:e.map(s=>({id:s.id,title:s.title,culprit:s.culprit,count:s.count,firstSeen:s.firstSeen,lastSeen:s.lastSeen,level:s.level,status:s.status}))})}case"sentry_get_issue":{let e=await Vr(t.issueId);return JSON.stringify({id:e.id,title:e.title,culprit:e.culprit,metadata:e.metadata,count:e.count,userCount:e.userCount,firstSeen:e.firstSeen,lastSeen:e.lastSeen,level:e.level,status:e.status,project:{slug:e.project?.slug,name:e.project?.name}})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},toolsForAssistant:[{name:"sentry_list_projects",description:"List Sentry projects",input_schema:{type:"object",properties:{}}},{name:"sentry_list_issues",description:"List Sentry issues (errors)",input_schema:{type:"object",properties:{project:{type:"string",description:"Project slug (optional)"},query:{type:"string",description:"Sentry search query (default: is:unresolved)"},sort:{type:"string",description:"Sort order: date, new, priority, freq, user (default: date)"},limit:{type:"number",description:"Max issues to return (default 25)"}}}},{name:"sentry_get_issue",description:"Get details of a specific Sentry issue",input_schema:{type:"object",properties:{issueId:{type:"string",description:"Sentry issue ID"}},required:["issueId"]}}]};ge.tools=ge.toolsForAssistant;import{spawn as xt}from"child_process";import{writeFileSync as Qr,mkdirSync as vt,existsSync as q,readdirSync as we,readFileSync as ke,unlinkSync as Xr,createWriteStream as ei,statSync as ti}from"fs";import{resolve as Q,join as D}from"path";import{resolveMaxParallelRuns as Et}from"@zibby/core/utils/parallel-config.js";import{zibbyScratchSpecsDir as si}from"@zibby/core/constants/zibby-scratch.js";var Ce="sessions",Le=".zibby/output",_e=process.env.ZIBBY_RUNNER_NODE_PROGRESS==="1",ri=process.env.ZIBBY_RUNNER_STATUS_STREAM==="1",Ct=process.env.ZIBBY_RUNNER_SPAWN_LOGS==="1",E=new Map,W=[],ii=0,xe=0,Nt=3e3;function Lt(){return`run_${++ii}_${Date.now().toString(36)}`}function It(r){let t=Math.floor(r/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Jt(r){return r.replace(/\x1b\[[0-9;]*[a-zA-Z]/g,"")}function x(r,t,e){if(!ri)return;let s=`
|
|
291
291
|
${t} [${r}] ${e}
|
|
292
|
-
`;try{process.stderr.write(s)}catch{}}function
|
|
292
|
+
`;try{process.stderr.write(s)}catch{}}function Je(){W.length=0;for(let[,r]of E)if(r.status==="queued"&&(r.status="cancelled"),r.status==="running"&&r._child)try{r._child.kill("SIGTERM")}catch{}}process.on("exit",Je);process.on("SIGINT",()=>{Je(),process.exit(0)});process.on("SIGTERM",()=>{Je(),process.exit(0)});var Pt={id:"runner",description:"Run zibby test workflows from chat (parallel supported)",envKeys:[],promptFragment:`## Test Runner
|
|
293
293
|
You can run zibby test workflows directly from chat:
|
|
294
294
|
|
|
295
295
|
**CRITICAL: When user asks to test a ticket:**
|
|
@@ -426,35 +426,35 @@ Each run generates:
|
|
|
426
426
|
- events.json: All browser events
|
|
427
427
|
- raw_stream_output.txt: Agent log
|
|
428
428
|
|
|
429
|
-
Use run_artifacts({ runId, type }) and run_diagnose({ runId }) to inspect and explain failures.`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"run_generate":return await
|
|
430
|
-
`)){let v=
|
|
429
|
+
Use run_artifacts({ runId, type }) and run_diagnose({ runId }) to inspect and explain failures.`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"run_generate":return await ni(t,s);case"run_test":return await pi(t,s,e);case"run_status":return di(t);case"run_cancel":return mi(t);case"run_artifacts":return hi(t,s);case"run_diagnose":return gi(t,s);case"list_specs":return _i(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},tools:[{name:"run_generate",description:"Generate specs from codebase. CRITICAL: DO NOT USE if ticket has test steps in comments. Only use when: (1) NO steps in ticket AND (2) local codebase exists (not external URLs). For tickets with steps, use run_test with inline format.",input_schema:{type:"object",properties:{ticket:{type:"string",description:"Jira ticket key (e.g. SCRUM-123). Auto-fetches ticket details."},description:{type:"string",description:"Ticket description text (use if no Jira key available)"},input:{type:"string",description:"Path to a file containing ticket/requirements text"},repo:{type:"string",description:"Path to the codebase (default: current directory)"},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},output:{type:"string",description:"Output directory for spec files (default: test-specs)"}}}},{name:"run_test",description:"Start a test (async, returns runId). spec = file path, or inline:+steps, or a Jira-shaped issue key (e.g. PROJ-123): when Jira is connected, the runner loads that issue's description+comments into an inline spec. After starting, tell the user and let them ask for progress via run_status.",input_schema:{type:"object",properties:{spec:{type:"string",description:"Workspace file path; or inline:+steps; or Jira issue key (KEY-123) to auto-fetch from Jira when the jira skill is active."},ticketKey:{type:"string",description:"Optional label (e.g. SCRUM-123). If spec is an issue key, this defaults to that key."},agent:{type:"string",description:"Optional agent override (cursor, gemini, claude, codex, assistant). Omit to use configured agent."},headless:{type:"boolean",description:"Run browser headless (default false)"},workflow:{type:"string",description:"Workflow override (e.g. quick-smoke)"}},required:["spec"]}},{name:"run_status",description:'Instant progress check \u2014 returns immediately. Use this whenever user asks about test progress. ALWAYS use runId="all".',input_schema:{type:"object",properties:{runId:{type:"string",description:'Use "all" to see all runs in this session (recommended). Or a specific run ID if known.'}},required:["runId"]}},{name:"run_cancel",description:'Cancel/kill a running test. ONLY use when the USER explicitly asks to cancel or stop a run. NEVER auto-cancel \u2014 tests take 1-5 minutes and "running" is normal. Use runId="all" to cancel all active runs.',input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID to cancel, or "all" to cancel all active runs'}},required:["runId"]}},{name:"run_artifacts",description:"Read artifacts from a test run session. Can list files, read results/events/logs, or search across all sessions.",input_schema:{type:"object",properties:{runId:{type:"string",description:"Run ID from run_test. Omit to search across all sessions."},type:{type:"string",enum:["list","result","events","log","search"],description:'What to retrieve: "list" = all files in session, "result" = result.json, "events" = events.json, "log" = raw output tail, "search" = search text across sessions'},node:{type:"string",description:'Node name to read from (e.g. "execute_live", "generate_script"). Default: "execute_live"'},query:{type:"string",description:'Search text (only for type="search"). Searches across all session logs/events.'},tail:{type:"number",description:"Number of characters from end of log to return (default: 3000)"}},required:["type"]}},{name:"run_diagnose",description:"Diagnose one or all runs, especially failed ones. Uses run logs + known error patterns and returns likely root cause with suggested next action.",input_schema:{type:"object",properties:{runId:{type:"string",description:'Run ID from run_test, or "all" (default) to diagnose all known runs'},tail:{type:"number",description:"Characters of run log tail to inspect (default: 2000)"}}}},{name:"list_specs",description:"List available test spec files in the project",input_schema:{type:"object",properties:{directory:{type:"string",description:'Directory to scan (default: "test-specs")'}}}}]};function Ee(){let r=0;for(let[,t]of E)t.status==="running"&&r++;return r}function Ot(){for(;W.length>0;){let r=Et(W[0]?.context?.options?.config);if(Ee()>=r)break;let{args:t,cwd:e,context:s}=W.shift();Ut(t,e,s)}}async function ni(r,t){let{ticket:e,description:s,input:n,repo:i,agent:o,output:c}=r,a=["generate"];e&&a.push("--ticket",e),s&&a.push("--description",s),n&&a.push("--input",n),i&&a.push("--repo",i),c&&a.push("--output",c);let u=["assistant","cursor","claude","codex","gemini"],l=o||process.env.AGENT_TYPE,p=l&&u.includes(l)?l:null;p&&a.push("--agent",p);let d=e||"generate";return x(d,"\u{1F9EA}","Starting test spec generation (real agent with codebase access)..."),new Promise(m=>{Ct&&console.error(`[zibby:spawn] skill=run_generate parentPid=${process.pid} \u2192 child zibby ${a.map(g=>/\s/.test(g)?JSON.stringify(g):g).join(" ")} cwd=${t}`);let f=xt("zibby",a,{cwd:t,env:{...process.env},stdio:["ignore","pipe","pipe"],detached:!1}),h="",_="";f.stdout.on("data",g=>{let b=g.toString();h+=b;for(let y of b.split(`
|
|
430
|
+
`)){let v=Jt(y).trim();v.startsWith("\u2705")?x(d,"\u2705",v.slice(2).trim()):v.startsWith("\u2713")&&x(d,"\u2714",v.slice(2).trim())}}),f.stderr.on("data",g=>{_+=g.toString()}),f.on("close",g=>{if(g!==0){x(d,"\u274C",`Generation failed (exit ${g})`),m(JSON.stringify({error:`zibby generate failed with exit code ${g}`,stderr:_.slice(-1e3)}));return}let b=Q(t,c||"test-specs"),y=[];try{let v=e?e.toLowerCase().replace(/[^a-z0-9]+/g,"-"):"";y=we(b).filter(T=>T.endsWith(".txt")&&(!v||T.startsWith(v))).map(T=>D(b,T))}catch{}x(d,"\u2705",`Generated ${y.length} test spec files`),m(JSON.stringify({success:!0,ticketKey:e||null,specFiles:y.map(v=>v.replace(`${t}/`,"")),total:y.length,message:`Generated ${y.length} specs. Now call run_test for each file.`}))}),f.on("error",g=>{x(d,"\u274C",`Spawn error: ${g.message}`),m(JSON.stringify({error:g.message}))})})}var Rt=1e5,At=/^[A-Z][A-Z0-9]+-\d+$/,oi=new Set(["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","rule","table","tableRow","tableCell","tableHeader","mediaSingle","panel"]);function ai(r,t){if(!t||!t.length)return r;let e=r;for(let s of t)s.type==="strong"?e=`**${e}**`:s.type==="em"?e=`_${e}_`:s.type==="code"?e=`\`${e}\``:s.type==="strike"?e=`~~${e}~~`:s.type==="link"&&s.attrs?.href&&(e=`[${e}](${s.attrs.href})`);return e}function be(r,t=0){if(!Array.isArray(r))return"";let e=[];for(let s of r){if(s.type==="text"){e.push(ai(s.text||"",s.marks));continue}if(s.type==="hardBreak"){e.push(`
|
|
431
431
|
`);continue}if(s.type==="rule"){e.push(`
|
|
432
432
|
---
|
|
433
|
-
`);continue}let n=s.content?
|
|
433
|
+
`);continue}let n=s.content?be(s.content,t+1):"";if(s.type==="listItem")e.push(n);else if(s.type==="bulletList"){let i=(s.content||[]).map(o=>`- ${be(o.content||[],t+1).trim()}`);e.push(`
|
|
434
434
|
${i.join(`
|
|
435
435
|
`)}
|
|
436
|
-
`)}else if(s.type==="orderedList"){let i=(s.content||[]).map((o,c)=>`${c+1}. ${
|
|
436
|
+
`)}else if(s.type==="orderedList"){let i=(s.content||[]).map((o,c)=>`${c+1}. ${be(o.content||[],t+1).trim()}`);e.push(`
|
|
437
437
|
${i.join(`
|
|
438
438
|
`)}
|
|
439
439
|
`)}else if(s.type==="heading"){let i=s.attrs?.level||2;e.push(`
|
|
440
440
|
|
|
441
441
|
${"#".repeat(i)} ${n.trim()}
|
|
442
442
|
|
|
443
|
-
`)}else
|
|
443
|
+
`)}else oi.has(s.type)?e.push(`
|
|
444
444
|
|
|
445
445
|
${n}
|
|
446
446
|
`):e.push(n)}return e.join("").replace(/\n{3,}/g,`
|
|
447
447
|
|
|
448
|
-
`)}function
|
|
448
|
+
`)}function ci(r){return r==null||r===""?"":typeof r=="string"?r.trim():typeof r=="object"&&Array.isArray(r.content)?be(r.content).trim():""}async function li(r){let{getSkill:t}=await import("@zibby/agent-workflow"),e=t("jira");if(!e||typeof e.handleToolCall!="function")return null;try{let s=await e.handleToolCall("jira_get_issue",{issueKey:r}),n=JSON.parse(s);if(n?.error)return null;let i=await e.handleToolCall("jira_get_comments",{issueKey:r,maxResults:50}),o=JSON.parse(i);if(o?.error)return null;let c=ci(n.description),a=[];c&&a.push(c);let u=Array.isArray(o.comments)?o.comments:[];if(u.length>0){let p=u.map(d=>String(d.body||"").trim()).filter(Boolean).join(`
|
|
449
449
|
|
|
450
450
|
`);p&&a.push(p)}let l=a.join(`
|
|
451
451
|
|
|
452
|
-
`).trim();return l?(l.length>
|
|
452
|
+
`).trim();return l?(l.length>Rt&&(l=`${l.slice(0,Rt)}
|
|
453
453
|
|
|
454
|
-
...[truncated]`),{inlineSpec:`inline:${l}`,issueKey:r}):null}catch{return null}}function
|
|
455
|
-
`);T=
|
|
456
|
-
Spawn error: ${A.message}`,x(v,"\u274C",`Spawn error: ${A.message}`),f.end(),
|
|
457
|
-
${e||""}`.toLowerCase(),i={runId:r?.runId||null,status:r?.status||null,exitCode:r?.exitCode??null,likelyCause:"Unknown failure",confidence:"low",nextStep:'Call run_artifacts({ runId, type: "log" }) with larger tail and inspect full logs.'};return r?.status==="running"||r?.status==="queued"?{...i,likelyCause:"Run is still active; no terminal failure to diagnose yet.",confidence:"high",nextStep:'Call run_status({ runId: "all" }) to check progress.'}:n.includes("test spec not found")?{...i,likelyCause:"Invalid spec input: run_test received a non-existent spec path.",confidence:"high",nextStep:"Use spec as inline:... or a real file path from list_specs. For ticket keys, fetch steps first via Jira then build inline spec."}:n.includes("unknown command")&&n.includes("'run'")?{...i,likelyCause:"CLI command mismatch (`zibby run` unsupported in current CLI).",confidence:"high",nextStep:"Use `zibby test ...` spawn path (runner should already do this)."}:n.includes("missing openai_api_key")||n.includes("didn't provide an api key")||n.includes("401")?{...i,likelyCause:"Provider authentication/config issue (API key/proxy auth missing or rejected).",confidence:"medium",nextStep:"Verify proxy/token env and auth mode, then retry once configuration is valid."}:n.includes("spawn error")||n.includes("enoent")?{...i,likelyCause:"Failed to spawn CLI process (binary/path/environment issue).",confidence:"medium",nextStep:"Confirm `zibby` is installed and available in PATH for the chat process."}:n.includes("security command failed")||n.includes("security process exited with code: 45")||n.includes("password not found for account")?{...i,likelyCause:"Cursor agent keychain/auth failed during preflight (often transient, more common under parallel starts).",confidence:"high",nextStep:'Retry failed ticket sequentially (not parallel), or run with a different agent via run_test({ ..., agent: "codex" }).'}:i}function
|
|
454
|
+
...[truncated]`),{inlineSpec:`inline:${l}`,issueKey:r}):null}catch{return null}}function ui(r,t){try{let e=JSON.parse(r);return JSON.stringify({...e,...t})}catch{return r}}async function pi(r,t,e){let s={...r},n=String(s.spec??"").trim();if(!n)return JSON.stringify({error:"spec is required"});let i=null;if(At.test(n)&&!n.startsWith("inline:")){let l=await li(n);l&&(n=l.inlineSpec,s.spec=n,String(s.ticketKey||"").trim()||(s.ticketKey=l.issueKey),i=l.issueKey)}let o=String(s.ticketKey||"").trim();if(o){for(let[l,p]of E.entries())if(p?.ticketKey===o&&!(p?.status!=="running"&&p?.status!=="queued"))return JSON.stringify({runId:l,ticketKey:o,status:p.status,reused:!0,message:`A run for ${o} is already ${p.status}. Reusing existing run instead of starting a duplicate.`})}if(!n.startsWith("inline:")){let l=Q(t,n);if(!q(l))return At.test(n)?JSON.stringify({error:`Invalid run_test spec: "${n}" is an issue id, not a spec.`,reason:"Jira auto-load was attempted but did not return usable text, or Jira is not configured.",doNext:["Confirm the jira skill is active and authenticated.",'Or call tracker tools yourself, then run_test with spec: "inline:" + steps.'],validExample:{spec:"inline:1. Open https://example.com \u2026 2. Verify \u2026",ticketKey:n},invalidExample:{spec:n,ticketKey:n}}):JSON.stringify({error:`Test spec not found: ${n}`,hint:'If this should be issue steps, load the issue with your tracker tools first, then run_test with spec: "inline:" + steps. Otherwise use a real file path.'})}let c=Et(e?.options?.config);if(Ee()>=c){let l=Lt(),p=s.ticketKey||l,d={runId:l,spec:s.ticketKey?`${s.ticketKey}: ${s.spec}`:s.spec,ticketKey:s.ticketKey||null,status:"queued",startTime:Date.now(),exitCode:null,output:"",error:""};E.set(l,d),W.push({args:{...s,_queuedRunId:l},cwd:t,context:e}),x(p,"\u23F3",`Queued (${Ee()}/${c} running, ${W.length} queued)`);let m={runId:l,spec:d.spec,ticketKey:d.ticketKey,status:"queued",message:`Queued \u2014 will start when a slot opens (max ${c} concurrent).`};return i&&(m.resolvedFromJiraIssue=i,m.message+=` (spec built from Jira ${i})`),JSON.stringify(m)}let a=Date.now()-xe;a<Nt&&xe>0&&await new Promise(l=>setTimeout(l,Nt-a)),xe=Date.now();let u=Ut(s,t,e);return i?ui(u,{resolvedFromJiraIssue:i,message:`Spec was loaded from Jira issue ${i} (description + comments).`}):u}function Ut(r,t,e){let{spec:s,ticketKey:n,agent:i,headless:o,workflow:c,_queuedRunId:a}=r,u=a||Lt(),l=s,p=!1;if(s.startsWith("inline:")){p=!0;let A=si(t);vt(A,{recursive:!0}),l=D(A,`${u}.txt`),Qr(l,s.slice(7).trim(),"utf-8")}let d=Q(t,".zibby","output","runs");vt(d,{recursive:!0});let m=D(d,`${u}.log`),f=ei(m,{flags:"a"}),_=i&&["assistant","cursor","claude","codex","gemini"].includes(i)?i:null,g=["test",l];_&&g.push("--agent",_),o&&g.push("--headless"),c&&g.push("--workflow",c),Ct&&console.error(`[zibby:spawn] skill=run_test parentPid=${process.pid} \u2192 child zibby ${g.map(A=>/\s/.test(A)?JSON.stringify(A):A).join(" ")} cwd=${t}`);let b=xt("zibby",g,{cwd:t,env:{...process.env,ZIBBY_WORKFLOW_GRAPH_LOG_MARKERS:"1"},stdio:["ignore","pipe","pipe"],detached:!1}),y={runId:u,spec:n?`${n}: ${s}`:s,ticketKey:n||null,specPath:l,logPath:m,isInline:p,pid:b.pid,status:"running",output:"",error:"",startTime:Date.now(),exitCode:null,currentNode:null,completedNodes:[]},v=n||u,T="";function et(A){let I=Jt(A).trim();if(!I)return;if(I.startsWith("__WORKFLOW_GRAPH_LOG__")){try{let j=JSON.parse(I.slice(22));j.phase==="node_begin"?y.currentNode=j.node:j.phase==="node_end"&&(j.node&&!y.completedNodes.includes(j.node)&&y.completedNodes.push(j.node),y.currentNode===j.node&&(y.currentNode=null))}catch{}return}let ie=I.match(/Session\s+(\S+)/);if(ie&&!y.sessionId&&(y.sessionId=ie[1],y.sessionPath=Q(t,Le,Ce,y.sessionId)),I.startsWith("\u250C ")||I.startsWith("\u250C ")){let j=I.slice(2).trim();y.currentNode=j,_e&&x(v,"\u25B6",`${j}`)}else if(I.startsWith("\u2514 ")||I.startsWith("\u2514 ")){let j=I.slice(2).trim();j.startsWith("done")?(y.currentNode&&!y.completedNodes.includes(y.currentNode)&&y.completedNodes.push(y.currentNode),_e&&x(v,"\u2714",`${y.currentNode||"node"} done ${j.replace("done","").trim()}`),y.currentNode=null):j.startsWith("failed")&&(_e&&x(v,"\u2718",`${y.currentNode||"node"} failed ${j.replace("failed","").trim()}`),y.currentNode=null)}else I.includes("Workflow completed")&&(y.currentNode=null,_e&&x(v,"\u2714",`Workflow completed (${It(Date.now()-y.startTime)})`))}function $s(A){let I=A.toString();y.output+=I,f.write(I),y.output.length>5e4&&(y.output=y.output.slice(-3e4)),T+=I;let ie=T.split(`
|
|
455
|
+
`);T=ie.pop();for(let j of ie)et(j)}return b.stdout.on("data",$s),b.stderr.on("data",A=>{let I=A.toString();y.error+=I,f.write(I),y.error.length>2e4&&(y.error=y.error.slice(-1e4))}),b.on("close",A=>{y.status=A===0?"passed":"failed",y.exitCode=A,y.endTime=Date.now(),T&&et(T),f.end();let I=It(Date.now()-y.startTime);if(A===0?x(v,"\u2705",`Passed (${I})`):x(v,"\u274C",`Failed (${I})`),y.isInline)try{Xr(y.specPath)}catch{}Ot()}),b.on("error",A=>{y.status="error",y.error+=`
|
|
456
|
+
Spawn error: ${A.message}`,x(v,"\u274C",`Spawn error: ${A.message}`),f.end(),Ot()}),y._child=b,E.set(u,y),JSON.stringify({runId:u,spec:y.spec,ticketKey:y.ticketKey,status:"running",pid:b.pid,logFile:m})}function $t(r){let t=Math.round(((r.endTime||Date.now())-r.startTime)/1e3),e=r.completedNodes||[],s=r.currentNode||null;if(r.status!=="running")return{elapsed:t,stage:r.status,completedNodes:e,currentNode:null};let n;return s?(n=`Actively executing node "${s}"`,e.length&&(n+=` (completed: ${e.join(", ")})`)):e.length?n=`Between nodes (completed: ${e.join(", ")})`:n="Starting up (initializing workflow)",n+=`. Elapsed: ${t}s. This is normal progress \u2014 do not cancel.`,{elapsed:t,stage:"running",currentNode:s,completedNodes:e,progress:n}}function di(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let i=[...E.entries()].map(([l,p])=>{let d=$t(p),m={runId:l,spec:p.spec,ticketKey:p.ticketKey,status:p.status,elapsed:d.elapsed,exitCode:p.exitCode,sessionId:p.sessionId||null};return p.status==="running"?(m.currentNode=d.currentNode,m.completedNodes=d.completedNodes,m.progress=d.progress):m.outputTail=p.output.slice(-500),m}),o=i.filter(l=>l.status==="running").length,c=i.filter(l=>l.status==="passed").length,a=i.filter(l=>l.status==="failed").length,u={total:i.length,running:o,passed:c,failed:a,runs:i};return o>0&&(u._hint="All running tests are progressing normally through their workflow nodes. Do NOT cancel, diagnose, or interpret as stuck. Just tell the user they are still running."),JSON.stringify(u)}let e=E.get(t);if(!e)return JSON.stringify({error:`Run not found: ${t}`});let s=$t(e),n={runId:t,spec:e.spec,ticketKey:e.ticketKey,status:e.status,elapsed:s.elapsed,exitCode:e.exitCode,sessionId:e.sessionId||null};return e.status==="running"?(n.currentNode=s.currentNode,n.completedNodes=s.completedNodes,n.progress=s.progress):(n.outputTail=e.output.slice(-1e3),n.errorTail=e.error.slice(-500)),e.status==="running"&&(n._hint="This run is actively progressing. Do NOT cancel, diagnose, or assume stuck. Just tell the user it is still running."),JSON.stringify(n)}function jt(r,t){if(t.status==="queued"){let e=W.findIndex(s=>s.args._queuedRunId===r);return e>=0&&W.splice(e,1),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}if(t.status!=="running")return{ok:!1,runId:r,error:`Run is not active (status: ${t.status})`};try{return t._child.kill("SIGTERM"),t.status="cancelled",t.endTime=Date.now(),{ok:!0,runId:r,status:"cancelled"}}catch(e){return{ok:!1,runId:r,error:`Failed to cancel: ${e.message}`}}}function mi(r){let{runId:t}=r;if(!t)return JSON.stringify({error:"runId is required"});if(t==="all"){let s=[];for(let[n,i]of E.entries())(i.status==="running"||i.status==="queued")&&s.push(jt(n,i));return s.length===0?JSON.stringify({ok:!0,message:"No active runs to cancel"}):JSON.stringify({ok:!0,cancelled:s.length,results:s})}let e=E.get(t);return JSON.stringify(e?jt(t,e):{error:`Run not found: ${t}`})}function fi(r,t){let e=E.get(r);if(e?.sessionPath&&q(e.sessionPath))return e.sessionPath;if(e?.sessionId){let s=Q(t,Le,Ce,e.sessionId);if(q(s))return s}return null}function Dt(r,t=""){let e=[];if(!q(r))return e;for(let s of we(r,{withFileTypes:!0})){let n=t?`${t}/${s.name}`:s.name;if(s.isDirectory())e.push(...Dt(D(r,s.name),n));else{let i=ti(D(r,s.name));e.push({path:n,size:i.size})}}return e}function Tt(r){if(!q(r))return null;try{return JSON.parse(ke(r,"utf-8"))}catch{return null}}function Mt(r,t=2e3){if(!r||!q(r))return"";try{return ke(r,"utf-8").slice(-Math.max(200,Number(t)||2e3))}catch{return""}}function yi({run:r,logTail:t,errorTail:e}){let n=`${t||""}
|
|
457
|
+
${e||""}`.toLowerCase(),i={runId:r?.runId||null,status:r?.status||null,exitCode:r?.exitCode??null,likelyCause:"Unknown failure",confidence:"low",nextStep:'Call run_artifacts({ runId, type: "log" }) with larger tail and inspect full logs.'};return r?.status==="running"||r?.status==="queued"?{...i,likelyCause:"Run is still active; no terminal failure to diagnose yet.",confidence:"high",nextStep:'Call run_status({ runId: "all" }) to check progress.'}:n.includes("test spec not found")?{...i,likelyCause:"Invalid spec input: run_test received a non-existent spec path.",confidence:"high",nextStep:"Use spec as inline:... or a real file path from list_specs. For ticket keys, fetch steps first via Jira then build inline spec."}:n.includes("unknown command")&&n.includes("'run'")?{...i,likelyCause:"CLI command mismatch (`zibby run` unsupported in current CLI).",confidence:"high",nextStep:"Use `zibby test ...` spawn path (runner should already do this)."}:n.includes("missing openai_api_key")||n.includes("didn't provide an api key")||n.includes("401")?{...i,likelyCause:"Provider authentication/config issue (API key/proxy auth missing or rejected).",confidence:"medium",nextStep:"Verify proxy/token env and auth mode, then retry once configuration is valid."}:n.includes("spawn error")||n.includes("enoent")?{...i,likelyCause:"Failed to spawn CLI process (binary/path/environment issue).",confidence:"medium",nextStep:"Confirm `zibby` is installed and available in PATH for the chat process."}:n.includes("security command failed")||n.includes("security process exited with code: 45")||n.includes("password not found for account")?{...i,likelyCause:"Cursor agent keychain/auth failed during preflight (often transient, more common under parallel starts).",confidence:"high",nextStep:'Retry failed ticket sequentially (not parallel), or run with a different agent via run_test({ ..., agent: "codex" }).'}:i}function hi(r,t){let{runId:e,type:s,node:n="execute_live",query:i,tail:o=3e3}=r;if(s==="search"){if(!i)return JSON.stringify({error:'query is required for type="search"'});let a=Q(t,Le,Ce);if(!q(a))return JSON.stringify({matches:[],message:"No sessions found"});let u=[],l=i.toLowerCase();for(let p of we(a,{withFileTypes:!0})){if(!p.isDirectory())continue;let d=D(a,p.name),m=[{file:"execute_live/result.json",label:"result"},{file:"execute_live/events.json",label:"events"},{file:"execute_live/raw_stream_output.txt",label:"log"},{file:"generate_script/raw_stream_output.txt",label:"script_log"},{file:"title.txt",label:"title"}];for(let{file:f,label:h}of m){let _=D(d,f);if(q(_))try{let g=ke(_,"utf-8");if(g.toLowerCase().includes(l)){let b=g.toLowerCase().indexOf(l),y=Math.max(0,b-100),v=Math.min(g.length,b+i.length+100);u.push({sessionId:p.name,artifact:h,snippet:g.slice(y,v)})}}catch{}}if(u.length>=20)break}return JSON.stringify({query:i,matches:u,total:u.length})}if(!e)return JSON.stringify({error:"runId is required for this type"});if(s==="log"){let a=E.get(e),u=Mt(a?.logPath,o);if(u)return JSON.stringify({runId:e,source:"run-log",totalLength:u.length,tail:u})}let c=fi(e,t);if(!c)return JSON.stringify({error:`No session found for run ${e}. The run may still be starting.`});switch(s){case"list":{let a=Dt(c);return JSON.stringify({sessionId:c.split("/").pop(),files:a,total:a.length})}case"result":{let a=Tt(D(c,n,"result.json"));return JSON.stringify(a?{sessionId:c.split("/").pop(),node:n,result:a}:{error:`No result.json found in ${n}`})}case"events":{let a=Tt(D(c,n,"events.json"));if(!a)return JSON.stringify({error:`No events.json found in ${n}`});let u=Array.isArray(a)?a:a.events||[];return JSON.stringify({sessionId:c.split("/").pop(),node:n,totalEvents:u.length,events:u.slice(-50)})}case"log":{let a=D(c,n,"raw_stream_output.txt");if(!q(a))return JSON.stringify({error:`No log found in ${n}`});let u=ke(a,"utf-8");return JSON.stringify({sessionId:c.split("/").pop(),node:n,totalLength:u.length,tail:u.slice(-o)})}default:return JSON.stringify({error:`Unknown artifact type: ${s}. Use: list, result, events, log, search`})}}function gi(r,t){let e=String(r?.runId||"all"),s=Number(r?.tail||2e3),n=e==="all"?[...E.keys()]:[e];if(n.length===0)return JSON.stringify({error:"No runs available to diagnose. Call run_test first."});let i=n.map(a=>{let u=E.get(a);if(!u)return{runId:a,error:`Run not found: ${a}`};let l=Mt(u.logPath,s),p=String(u.error||"").slice(-Math.max(200,s));return{...yi({run:u,logTail:l,errorTail:p}),ticketKey:u.ticketKey||null,spec:u.spec,logTail:l,errorTail:p}}),o=i.filter(a=>a.status==="failed"||a.status==="error"),c=i.filter(a=>a.status==="running"||a.status==="queued");return JSON.stringify({total:i.length,failed:o.length,active:c.length,diagnoses:i})}function _i(r,t){let e=r?.directory||"test-specs",s=Q(t,e);if(!q(s))return JSON.stringify({specs:[],directory:e,message:`Directory not found: ${e}`});try{let i=function(o,c){for(let a of we(o,{withFileTypes:!0})){let u=c?`${c}/${a.name}`:a.name;a.isDirectory()?i(D(o,a.name),u):(a.name.endsWith(".txt")||a.name.endsWith(".md"))&&n.push(u)}},n=[];return i(s,""),JSON.stringify({specs:n.map(o=>`${e}/${o}`),total:n.length,directory:e})}catch(n){return JSON.stringify({error:n.message})}}import{spawn as bi}from"child_process";import{existsSync as K,mkdirSync as ki,readdirSync as qt,statSync as wi,readFileSync as Si}from"fs";import{resolve as Pe,join as B,basename as vi}from"path";var Ue=".zibby/repos";function Se(r,t,e={}){return new Promise((s,n)=>{let i=bi(r,{cwd:t,shell:!0,env:{...process.env,GIT_TERMINAL_PROMPT:"0",...e}}),o="",c="";i.stdout.on("data",a=>{o+=a.toString()}),i.stderr.on("data",a=>{c+=a.toString()}),i.on("close",a=>{a!==0?n(new Error(`Exit ${a}: ${c.trim()||o.trim()}`)):s(o.trim())}),i.on("error",a=>n(a))})}var Kt={id:"git",description:"Clone and manage git repositories for codebase analysis",envKeys:["GITHUB_TOKEN","GITLAB_TOKEN"],promptFragment:`## Git Repositories
|
|
458
458
|
You can clone and explore git repositories locally for codebase analysis:
|
|
459
459
|
- git_checkout: Clone a repo (or pull if already cloned). Supports GitHub and GitLab with auto-auth.
|
|
460
460
|
- git_list_repos: List locally cloned repos
|
|
@@ -465,7 +465,7 @@ When a test ticket lacks context, use this workflow:
|
|
|
465
465
|
2. Use git_explore to understand the project structure
|
|
466
466
|
3. Use shell commands (grep, cat) to read specific files for deeper understanding
|
|
467
467
|
4. Use GitHub/GitLab skills to read related PRs and commits
|
|
468
|
-
5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"git_checkout":return await
|
|
468
|
+
5. Build well-informed test specs and save them to files before running tests`,resolve(){return null},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"git_checkout":return await Ni(t,s);case"git_list_repos":return Ii(t,s);case"git_explore":return Oi(t,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.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.",input_schema:{type:"object",properties:{url:{type:"string",description:'Repository URL (e.g. "https://github.com/org/repo" or "org/repo" shorthand for GitHub)'},branch:{type:"string",description:"Branch to checkout (default: repo default branch)"},shallow:{type:"boolean",description:"Shallow clone with depth 1 (default: true, faster)"},name:{type:"string",description:"Local directory name override (default: repo name from URL)"}},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 Ni(r,t){let{url:e,branch:s,shallow:n=!0,name:i}=r;!e.includes("://")&&!e.startsWith("git@")&&(e=`https://github.com/${e}`);let o=i||vi(e.replace(/\.git$/,"")),c=Pe(t,Ue);ki(c,{recursive:!0});let a=B(c,o),u=e,l=process.env.GITHUB_TOKEN,p=process.env.GITLAB_TOKEN,d=process.env.GITLAB_URL;if(e.includes("github.com")&&l)u=e.replace("https://github.com",`https://x-access-token:${l}@github.com`);else if(p&&d)try{let h=new URL(d).host;e.includes(h)&&(u=e.replace(`https://${h}`,`https://oauth2:${p}@${h}`))}catch{}if(K(B(a,".git"))){let h=s?`git -C "${a}" fetch origin ${s} && git -C "${a}" checkout ${s} && git -C "${a}" pull origin ${s}`:`git -C "${a}" pull`;await Se(h,t);let _=await Se(`git -C "${a}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"updated",repo:o,path:a,branch:s||"default",head:_})}let m=["git","clone"];n&&m.push("--depth","1"),s&&m.push("--branch",s),m.push(`"${u}"`,`"${a}"`),await Se(m.join(" "),t);let f=await Se(`git -C "${a}" log -1 --format="%h %s"`,t);return JSON.stringify({action:"cloned",repo:o,path:a,branch:s||"default",shallow:n,head:f})}function Ii(r,t){let e=Pe(t,Ue);if(!K(e))return JSON.stringify({repos:[],message:"No repos cloned yet"});let s=[];for(let n of qt(e,{withFileTypes:!0})){if(!n.isDirectory())continue;let i=B(e,n.name);if(!K(B(i,".git")))continue;let o=wi(i);s.push({name:n.name,path:i,lastModified:o.mtime.toISOString()})}return JSON.stringify({repos:s,total:s.length,directory:e})}function Oi(r,t){let{repo:e,depth:s=2}=r,n=Pe(t,Ue,e);if(!K(n))return JSON.stringify({error:`Repo not found: ${e}. Run git_checkout first.`});let i={repo:e,path:n},o=B(n,"package.json");if(K(o))try{let m=JSON.parse(Si(o,"utf-8"));i.packageJson={name:m.name,version:m.version,scripts:m.scripts?Object.keys(m.scripts):[],dependencies:m.dependencies?Object.keys(m.dependencies).slice(0,30):[],devDependencies:m.devDependencies?Object.keys(m.devDependencies).slice(0,20):[]},m.dependencies?.react?i.framework="React":m.dependencies?.next?i.framework="Next.js":m.dependencies?.vue?i.framework="Vue":m.dependencies?.angular?i.framework="Angular":m.dependencies?.express?i.framework="Express":m.dependencies?.fastify&&(i.framework="Fastify")}catch{}let c=B(n,"pyproject.toml");K(c)&&(i.language="Python");let a=B(n,"go.mod");K(a)&&(i.language="Go");let u=B(n,"Cargo.toml");K(u)&&(i.language="Rust"),K(o)&&(i.language=i.language||"JavaScript/TypeScript");let l=[];function p(m,f,h){if(h>s)return;let _;try{_=qt(m,{withFileTypes:!0})}catch{return}let g=_.filter(b=>!b.name.startsWith(".")&&b.name!=="node_modules"&&b.name!=="__pycache__"&&b.name!=="dist"&&b.name!=="build"&&b.name!==".git").sort((b,y)=>b.isDirectory()!==y.isDirectory()?b.isDirectory()?-1:1:b.name.localeCompare(y.name));for(let b of g){let y=b.isDirectory();l.push(`${f}${y?"\u{1F4C1}":"\u{1F4C4}"} ${b.name}`),y&&h<s&&p(B(m,b.name),`${f} `,h+1)}}p(n,"",1),i.tree=l.slice(0,80),l.length>80&&(i.treeTruncated=!0);let d=["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 i.keyFilesFound=d.filter(m=>K(B(n,m))),JSON.stringify(i)}import{execFileSync as Wt}from"child_process";import{existsSync as Fe,mkdirSync as Ht}from"fs";import{join as F,basename as Ri}from"path";import{randomBytes as Ai}from"crypto";import{pathToFileURL as le}from"url";import{createRequire as Yt}from"module";var qe=".zibby/memory",Zt="dolt",Vt={encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:15e3},Ke="mem0",De=new Map,ve=new Map,Ne=!1,$i=Yt(import.meta.url),Ae=()=>Ai(8).toString("hex"),X=()=>new Date().toISOString(),ji=[`CREATE TABLE IF NOT EXISTS chat_memory (
|
|
469
469
|
id VARCHAR(64) PRIMARY KEY,
|
|
470
470
|
memory_key VARCHAR(160),
|
|
471
471
|
category VARCHAR(32) NOT NULL,
|
|
@@ -496,10 +496,10 @@ When a test ticket lacks context, use this workflow:
|
|
|
496
496
|
tasks_failed INT DEFAULT 0,
|
|
497
497
|
key_facts TEXT,
|
|
498
498
|
created_at VARCHAR(32) NOT NULL
|
|
499
|
-
)`],
|
|
500
|
-
`)};`;L(r,t);try{L(r,"ALTER TABLE chat_memory ADD COLUMN tier VARCHAR(16) DEFAULT 'mid'")}catch{}try{L(r,"ALTER TABLE chat_memory ADD COLUMN memory_key VARCHAR(160)")}catch{}return
|
|
499
|
+
)`],Bt=new Set;function C(r,t){return Wt(Zt,t,{...Vt,cwd:r})}function H(r,t){try{let e=C(r,["sql","-q",t,"-r","json"]);return JSON.parse(e.trim()).rows||[]}catch{return[]}}function L(r,t){C(r,["sql","-q",t])}function Ie(r){if(Bt.has(r))return!0;if(!Fe(F(r,".dolt"))){if(!Ti())return!1;Ht(r,{recursive:!0}),C(r,["init","--name","Zibby Chat Memory","--email","chat@zibby.app"])}let t=`${ji.join(`;
|
|
500
|
+
`)};`;L(r,t);try{L(r,"ALTER TABLE chat_memory ADD COLUMN tier VARCHAR(16) DEFAULT 'mid'")}catch{}try{L(r,"ALTER TABLE chat_memory ADD COLUMN memory_key VARCHAR(160)")}catch{}return Bt.add(r),!0}function Ti(){try{return Wt(Zt,["version"],{...Vt,timeout:5e3}),!0}catch{return!1}}function w(r){return r==null?"NULL":`'${String(r).replace(/'/g,"''")}'`}function Be(r){return String(r||"").toLowerCase().replace(/[“”]/g,'"').replace(/[‘’]/g,"'").replace(/[\s_-]+/g," ").replace(/[^\w\s"']/g,"").replace(/\s+/g," ").trim()}function te(r){return r==="long"?3:r==="mid"?2:r==="short"?1:0}function Ge(r,t){let e=["short","mid","long"].includes(r)?r:"mid";return new Set(["fact","decision","preference","credential","url","workaround"]).has(String(t||"").toLowerCase())&&e==="short"?"mid":e}function Qt(r){let t=new Map;for(let e of r||[]){let s=Be(e.content),n=e.memory_key?`key:${e.memory_key}`:s?`norm:${s}`:"";if(!n)continue;let i=t.get(n);if(!i){t.set(n,e);continue}let o=te(i.tier),c=te(e.tier);if(c>o){t.set(n,e);continue}c===o&&Number(e.relevance||0)>Number(i.relevance||0)&&t.set(n,e)}return[...t.values()]}function Re(r,t){let e=String(r??"");return e.length<=t?e:t<=1?e.slice(0,t):`${e.slice(0,t-1)}\u2026`}function ce(r,t){let e={recentSessions:Array.isArray(r?.recentSessions)?r.recentSessions:[],topMemories:Array.isArray(r?.topMemories)?r.topMemories:[],taskStats:Array.isArray(r?.taskStats)?r.taskStats:[],ticketFilter:r?.ticketFilter||null,backend:t||String(r?.backend||Ke),error:r?.error||null};return e.backend==="mem0"?{...e,recentSessions:[],taskStats:[]}:e}function Ft(r){let t=[];if(r.recentSessions?.length>0){t.push("Recent sessions:");for(let e of r.recentSessions.slice(0,3))e?.summary?.trim()&&t.push(`- ${Re(e.summary,150)}${e.tickets?` [${e.tickets}]`:""}`)}if(r.topMemories?.length>0){t.push("Known facts:");for(let e of r.topMemories.slice(0,10)){let s=e.tier==="long"?"\u2605":"\xB7";t.push(`${s} [${e.category}] ${Re(e.content,120)}`)}}return t.length===0?"":`## Memory Context
|
|
501
501
|
${t.join(`
|
|
502
|
-
`)}`}function
|
|
502
|
+
`)}`}function Oe(r){return{backend:r.backend,recentSessions:r.recentSessions.slice(0,3).map(t=>({summary:Re(String(t?.summary||""),160),tickets:t?.tickets||null,created_at:t?.created_at||null})),topMemories:r.topMemories.slice(0,8).map(t=>({category:t?.category||null,tier:t?.tier||null,content:Re(String(t?.content||""),140),source:t?.source||null})),taskStats:r.taskStats,error:r.error||null}}async function xi(r,t){let e=String(process.env.ZIBBY_MEMORY_BACKEND||"").trim().toLowerCase();if(e==="mem0"||e==="dolt")return e;let s=String(t?.options?.memoryBackend||t?.options?.config?.memory?.backend||"").trim().toLowerCase();if(s==="mem0"||s==="dolt")return s;if(ve.has(r))return ve.get(r);try{let n=F(r,".zibby.config.mjs");if(Fe(n)){let i=await import(le(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return ve.set(r,o),o}}catch{}return ve.set(r,Ke),Ke}function Xt(r){let t=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return t||`workspace:${Ri(r||process.cwd())}`}var Ei="mem0";function es(r){let t=F(r,qe,Ei);return{dir:t,vectorDbPath:F(t,"vectors.db"),historyDbPath:F(t,"history.db")}}function Ci(r){let t=String(process.env.ZIBBY_MEM0_OPENAI_BASE_URL||"").trim();if(!t)return null;let e=String(process.env.ZIBBY_MEM0_API_KEY||process.env.ZIBBY_USER_TOKEN||process.env.OPENAI_API_KEY||"").trim(),s=String(process.env.ZIBBY_MEM0_LLM_MODEL||"gpt-4.1-mini").trim(),n=String(process.env.ZIBBY_MEM0_EMBEDDER_MODEL||"text-embedding-3-small").trim(),i=Number(process.env.ZIBBY_MEM0_EMBEDDING_DIMS||1536),{vectorDbPath:o,historyDbPath:c}=es(r||process.cwd());return{llm:{provider:"openai",config:{model:s,baseURL:t,...e?{apiKey:e}:{}}},embedder:{provider:"openai",config:{model:n,embeddingDims:i,baseURL:t,...e?{apiKey:e}:{}}},vectorStore:{provider:"memory",config:{dimension:i,dbPath:o}},historyDbPath:c}}async function ts(r){let t=r||process.cwd();if(De.has(t))return De.get(t);let e;try{let c=Yt(le(F(t,"package.json")).href).resolve("mem0ai/oss");e=await import(le(c).href)}catch{try{let o=$i.resolve("mem0ai/oss");e=await import(le(o).href)}catch(o){throw new Error(`Cannot find package 'mem0ai' for workspace "${t}". Install in that project: npm install mem0ai. (${o.message})`,{cause:o})}}let s=e?.Memory;if(!s)throw new Error("mem0ai/oss does not export Memory");let n=Ci(t);if(n)try{Ht(es(t).dir,{recursive:!0})}catch{}let i=n?new s(n):new s;return De.set(t,i),i}function Gt(r,t="mid"){return(Array.isArray(r)?r:Array.isArray(r?.results)?r.results:[]).map(s=>({id:s?.id||Ae(),memory_key:s?.metadata?.memoryKey||s?.metadata?.memory_key||null,category:s?.metadata?.category||"fact",content:s?.memory||s?.content||"",source:s?.metadata?.source||"mem0",ticket_key:s?.metadata?.ticketKey||s?.metadata?.ticket_key||null,tier:Ge(s?.metadata?.tier||t,s?.metadata?.category||"fact"),relevance:Number(s?.score??s?.metadata?.relevance??.8),created_at:s?.created_at||s?.metadata?.created_at||X()})).filter(s=>String(s.content||"").trim().length>0)}var se={id:"dolt",store:(r,t)=>rs(r,t),recall:(r,t)=>Mi(r,t),brief:(r,t)=>qi(r,t),endSession:(r,t)=>ns(r,t),logTask:(r,t)=>os(r,t),taskHistory:(r,t)=>as(r,t)},Li={id:"mem0",store:(r,t,e)=>Di(r,t,e),recall:(r,t,e)=>is(r,t,e),brief:(r,t,e)=>Ki(r,t,e),endSession:(r,t)=>ns(r,t),logTask:(r,t)=>os(r,t),taskHistory:(r,t)=>as(r,t)},Ji={dolt:se,mem0:Li};async function zt(r,t){let e=await xi(r,t);return Ji[e]||se}var ss={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
|
|
503
503
|
You have persistent memory across sessions. Use it to avoid losing context:
|
|
504
504
|
- **memory_store**: Save important facts, decisions, or context. Anything worth remembering.
|
|
505
505
|
- **memory_recall**: Search your memory by keyword or category. Use this at the START of conversations to recall relevant context.
|
|
@@ -515,7 +515,9 @@ You have persistent memory across sessions. Use it to avoid losing context:
|
|
|
515
515
|
- When the user's request is complete: call memory_end_session
|
|
516
516
|
|
|
517
517
|
### Categories for memory_store
|
|
518
|
-
fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=
|
|
518
|
+
fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(r,t={}){let e=r?.options?.workspace||process.cwd(),s=F(e,qe),n=await zt(e,r),i=n.id;if(i==="dolt"&&!Ie(s)){let o="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:i,brief:ce({backend:i,error:o},i),promptContext:"",debugPreview:Oe(ce({backend:i,error:o},i)),error:o}}try{let o=await n.brief(t,s,e),c=JSON.parse(o||"{}"),a=ce({...c,backend:i},i);return{backend:i,brief:a,promptContext:Ft(a),debugPreview:Oe(a),error:a.error||null}}catch(o){if(i==="mem0"&&n!==se&&Ie(s)){if(!Ne){Ne=!0;try{process.stderr.write(`[chat-memory] mem0 backend unavailable (${o?.message||o}); degrading to dolt for this run
|
|
519
|
+
`)}catch{}}try{let u=await se.brief(t,s,e),l=JSON.parse(u||"{}"),p=ce({...l,backend:"dolt"},"dolt");return{backend:"dolt",brief:p,promptContext:Ft(p),debugPreview:Oe(p),error:p.error||null,degradedFrom:"mem0"}}catch{}}let c=String(o?.message||o),a=ce({backend:i,error:c},i);return{backend:i,brief:a,promptContext:"",debugPreview:Oe(a),error:c}}},async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd(),n=F(s,qe),i=await zt(s,e),o=i.id;if((o==="dolt"||["memory_end_session","task_log","task_history"].includes(r))&&!Ie(n))return JSON.stringify({error:"Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation"});let a=u=>{switch(r){case"memory_store":return u.store(t,n,s);case"memory_recall":return u.recall(t,n,s);case"memory_brief":return u.brief(t,n,s);case"memory_end_session":return u.endSession(t,n,s);case"task_log":return u.logTask(t,n,s);case"task_history":return u.taskHistory(t,n,s);default:return JSON.stringify({error:`Unknown tool: ${r}`})}};try{return await a(i)}catch(u){if(o==="mem0"&&i!==se){if(Ie(n)){if(!Ne){Ne=!0;try{process.stderr.write(`[chat-memory] mem0 backend unavailable (${u.message}); degrading to dolt for this run
|
|
520
|
+
`)}catch{}}try{return await a(se)}catch(l){return JSON.stringify({error:l.message,backend:"dolt",degradedFrom:"mem0"})}}return JSON.stringify({error:`mem0 unavailable (${u.message}); dolt fallback also unavailable`,backend:"mem0"})}return JSON.stringify({error:u.message})}},tools:[{name:"memory_store",description:"Save a fact, decision, or context to persistent memory. Survives across sessions.",input_schema:{type:"object",properties:{memoryKey:{type:"string",description:"Stable semantic identity key (e.g. user.jira.default_board)"},content:{type:"string",description:"The information to remember"},category:{type:"string",enum:["fact","decision","context","insight","preference","credential","url","error","workaround"],description:"Category of memory"},tier:{type:"string",enum:["short","mid","long"],description:"Memory tier: short (session/24h), mid (days/weeks), long (permanent)"},source:{type:"string",description:'Where this info came from (e.g. "jira", "github", "user", "test_run")'},ticketKey:{type:"string",description:"Related ticket key (optional)"},infer:{type:"boolean",description:"true = LLM distills/dedupes facts (costs tokens); false = store raw, embed-only, free",default:!1}},required:["content","category"]}},{name:"memory_recall",description:"Search persistent memory by keyword, category, ticket, or tier. Returns matching facts and context.",input_schema:{type:"object",properties:{query:{type:"string",description:"Search text (matches content)"},category:{type:"string",description:"Filter by category"},ticketKey:{type:"string",description:"Filter by ticket key"},tier:{type:"string",enum:["short","mid","long"],description:"Filter by memory tier"},limit:{type:"number",description:"Max results (default: 20)"}}}},{name:"memory_brief",description:"Get a compact briefing: recent session summaries + top relevant facts. Call at the start of a conversation.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Focus briefing on a specific ticket (optional)"}}}},{name:"memory_end_session",description:"End the current session and save a summary for future recall. Call when a task is complete.",input_schema:{type:"object",properties:{summary:{type:"string",description:"What happened in this session (1-3 sentences)"},tickets:{type:"string",description:"Comma-separated ticket keys covered"},tasksRun:{type:"number",description:"Number of tasks/tests run"},tasksPassed:{type:"number",description:"Number passed"},tasksFailed:{type:"number",description:"Number failed"},keyFacts:{type:"string",description:"Key facts worth remembering from this session (semicolon-separated)"}},required:["summary"]}},{name:"task_log",description:"Record a completed task (test run, analysis, generation) to persistent history.",input_schema:{type:"object",properties:{title:{type:"string",description:"Task description"},type:{type:"string",enum:["test_run","generate","analysis","research","other"],description:"Task type"},status:{type:"string",enum:["passed","failed","cancelled","error"],description:"Outcome"},ticketKey:{type:"string",description:"Related ticket key"},specPath:{type:"string",description:"Spec file path (if test run)"},resultSummary:{type:"string",description:"Brief result description"}},required:["title","type","status"]}},{name:"task_history",description:"Query past tasks by ticket, status, or type. See what was done before.",input_schema:{type:"object",properties:{ticketKey:{type:"string",description:"Filter by ticket key"},type:{type:"string",description:"Filter by task type"},status:{type:"string",description:"Filter by status"},limit:{type:"number",description:"Max results (default: 20)"}}}}]};function rs(r,t){let{content:e,category:s,source:n,ticketKey:i,tier:o,memoryKey:c}=r;if(!e||!s)return JSON.stringify({error:"content and category are required"});let a=Be(e);if(!a)return JSON.stringify({error:"content is empty after normalization"});let u=Ge(o,s),l=u==="long"?1:u==="mid"?.8:.5,p=String(c||"").trim().slice(0,160);if(p){let g=H(t,`SELECT id, tier, relevance
|
|
519
521
|
FROM chat_memory
|
|
520
522
|
WHERE memory_key = ${w(p)}
|
|
521
523
|
ORDER BY created_at DESC
|
|
@@ -531,22 +533,22 @@ fact, decision, context, insight, credential, url, error, workaround`,resolve(){
|
|
|
531
533
|
FROM chat_memory
|
|
532
534
|
WHERE category = ${w(s)}
|
|
533
535
|
ORDER BY created_at DESC
|
|
534
|
-
LIMIT 200`).find(_=>
|
|
536
|
+
LIMIT 200`).find(_=>Be(_.content)===a);if(m){let _=String(m.tier||"mid"),g=Number(m.relevance||0),b=te(u)>te(_),y=l>g;if(b||y){L(t,`UPDATE chat_memory
|
|
535
537
|
SET tier = ${w(b?u:_)},
|
|
536
538
|
relevance = ${Math.max(l,g)}
|
|
537
|
-
WHERE id = ${w(m.id)}`);try{C(t,["add","."]),C(t,["commit","-m",`memory promote: ${s} \u2014 ${String(e).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:m.id,category:s,tier:b?u:_,deduped:!0,promoted:!0})}return JSON.stringify({ok:!0,id:m.id,category:s,tier:_,deduped:!0,promoted:!1})}let f=
|
|
538
|
-
VALUES (${w(f)}, ${w(p||null)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(i)}, ${w(h)}, ${w(u)}, ${l}, ${w(X())})`);try{C(t,["add","."]),C(t,["commit","-m",`memory: ${s} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:f,category:s,tier:u,memoryKey:p||null,stored:e.slice(0,100)})}function
|
|
539
|
+
WHERE id = ${w(m.id)}`);try{C(t,["add","."]),C(t,["commit","-m",`memory promote: ${s} \u2014 ${String(e).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:m.id,category:s,tier:b?u:_,deduped:!0,promoted:!0})}return JSON.stringify({ok:!0,id:m.id,category:s,tier:_,deduped:!0,promoted:!1})}let f=Ae(),h=process.env.ZIBBY_CHAT_SESSION_ID||null;L(t,`INSERT INTO chat_memory (id, memory_key, category, content, source, ticket_key, session_id, tier, relevance, created_at)
|
|
540
|
+
VALUES (${w(f)}, ${w(p||null)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(i)}, ${w(h)}, ${w(u)}, ${l}, ${w(X())})`);try{C(t,["add","."]),C(t,["commit","-m",`memory: ${s} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:f,category:s,tier:u,memoryKey:p||null,stored:e.slice(0,100)})}function Pi(r){let t=String(r||"").trim().toLowerCase();return t==="1"||t==="true"||t==="yes"||t==="on"}var Me=new Map;async function Ui(r,t){if(typeof r=="boolean")return r;if(process.env.ZIBBY_MEM0_INFER!=null&&String(process.env.ZIBBY_MEM0_INFER).trim()!=="")return Pi(process.env.ZIBBY_MEM0_INFER);let e=t||process.cwd();if(Me.has(e))return Me.get(e);let s=!1;try{let n=F(e,".zibby.config.mjs");Fe(n)&&(s=(await import(le(n).href))?.default?.memory?.infer===!0)}catch{}return Me.set(e,s),s}async function Di(r,t,e){let{content:s,category:n,source:i,ticketKey:o,tier:c,memoryKey:a,infer:u}=r;if(!s||!n)return JSON.stringify({error:"content and category are required"});try{let l=await ts(e),p=Xt(e),d=Ge(c,n),m=await Ui(u,e);return await l.add([{role:"user",content:String(s)}],{userId:p,infer:m,metadata:{memoryKey:a||null,category:n,tier:d,source:i||"zibby-chat",ticketKey:o||null,created_at:X()}}),JSON.stringify({ok:!0,backend:"mem0",userId:p,category:n,tier:d,infer:m,memoryKey:a||null,stored:String(s).slice(0,100)})}catch(l){throw new Error(`mem0 store failed: ${l.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:l})}}function Mi(r,t){let{query:e,category:s,ticketKey:n,tier:i,limit:o=20}=r,c=[];e&&c.push(`content LIKE ${w(`%${e}%`)}`),s&&c.push(`category = ${w(s)}`),n&&c.push(`ticket_key = ${w(n)}`),i&&c.push(`tier = ${w(i)}`);let u=`SELECT id, memory_key, category, content, source, ticket_key, tier, relevance, created_at
|
|
539
541
|
FROM chat_memory ${c.length>0?`WHERE ${c.join(" AND ")}`:""}
|
|
540
542
|
ORDER BY relevance DESC, created_at DESC
|
|
541
|
-
LIMIT ${o}`,l=H(t,u);return JSON.stringify({total:l.length,memories:l})}async function
|
|
543
|
+
LIMIT ${o}`,l=H(t,u);return JSON.stringify({total:l.length,memories:l})}async function is(r,t,e){let{query:s,category:n,ticketKey:i,tier:o,limit:c=20}=r;try{let a=await ts(e),u=Xt(e),l=[];if(s&&String(s).trim()){let p=await a.search(String(s),{filters:{user_id:u},topK:c});l=Gt(p)}else{let p=await a.getAll({filters:{user_id:u},topK:Math.max(c,50)});l=Gt(p)}return n&&(l=l.filter(p=>p.category===n)),i&&(l=l.filter(p=>p.ticket_key===i)),o&&(l=l.filter(p=>p.tier===o)),l=l.slice(0,c),JSON.stringify({total:l.length,memories:l,backend:"mem0"})}catch(a){throw new Error(`mem0 recall failed: ${a.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:a})}}function qi(r,t){let{ticketKey:e}=r;Fi(t);let n=H(t,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
|
|
542
544
|
FROM chat_sessions ORDER BY created_at DESC LIMIT 5`),i=e?`AND ticket_key = ${w(e)}`:"",o=H(t,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
|
|
543
545
|
WHERE tier = 'long' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 10`),c=H(t,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
|
|
544
546
|
WHERE tier = 'mid' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 8`),u=H(t,`SELECT type, status, COUNT(*) as cnt FROM chat_tasks
|
|
545
|
-
GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),l=
|
|
546
|
-
VALUES (${w(a)}, ${w(e)}, ${w(s)}, ${n}, ${i}, ${o}, ${w(c)}, ${w(X())})`),c)for(let u of c.split(";").map(l=>l.trim()).filter(Boolean))
|
|
547
|
-
VALUES (${w(a)}, ${w(i)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(o)}, ${w(u)}, ${w(c)}, ${w(X())}, ${w(X())})`);try{C(t,["add","."]),C(t,["commit","-m",`task: ${n} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:a,title:e,type:s,status:n})}function
|
|
547
|
+
GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),l=Qt([...o,...c]);return JSON.stringify({recentSessions:n,topMemories:l,taskStats:u,ticketFilter:e||null})}async function Ki(r,t,e){let{ticketKey:s}=r,n=await is({limit:80},t,e),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(d=>d.ticket_key===s));let c=d=>{let m=Date.parse(String(d?.created_at||""))||0;return Number(d?.relevance||0)*1e12+m},a=(d,m)=>c(m)-c(d),u=o.filter(d=>d.tier==="long").sort(a).slice(0,10),l=o.filter(d=>d.tier==="mid").sort(a).slice(0,8),p=Qt([...u,...l]);return JSON.stringify({recentSessions:[],topMemories:p,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function ns(r,t){let{summary:e,tickets:s,tasksRun:n=0,tasksPassed:i=0,tasksFailed:o=0,keyFacts:c}=r;if(!e)return JSON.stringify({error:"summary is required"});let a=process.env.ZIBBY_CHAT_SESSION_ID||`session_${Ae()}`;if(L(t,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
|
|
548
|
+
VALUES (${w(a)}, ${w(e)}, ${w(s)}, ${n}, ${i}, ${o}, ${w(c)}, ${w(X())})`),c)for(let u of c.split(";").map(l=>l.trim()).filter(Boolean))rs({content:u,category:"fact",source:"session_summary",tier:"mid"},t);Bi(t);try{C(t,["add","."]),C(t,["commit","-m",`session end: ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,sessionId:a,summary:e.slice(0,200)})}function os(r,t){let{title:e,type:s,status:n,ticketKey:i,specPath:o,resultSummary:c}=r;if(!e||!s||!n)return JSON.stringify({error:"title, type, and status are required"});let a=Ae(),u=process.env.ZIBBY_CHAT_SESSION_ID||null;L(t,`INSERT INTO chat_tasks (id, ticket_key, type, title, status, spec_path, session_id, result_summary, created_at, finished_at)
|
|
549
|
+
VALUES (${w(a)}, ${w(i)}, ${w(s)}, ${w(e)}, ${w(n)}, ${w(o)}, ${w(u)}, ${w(c)}, ${w(X())}, ${w(X())})`);try{C(t,["add","."]),C(t,["commit","-m",`task: ${n} \u2014 ${e.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:a,title:e,type:s,status:n})}function as(r,t){let{ticketKey:e,type:s,status:n,limit:i=20}=r,o=[];e&&o.push(`ticket_key = ${w(e)}`),s&&o.push(`type = ${w(s)}`),n&&o.push(`status = ${w(n)}`);let a=`SELECT id, ticket_key, type, title, status, spec_path, result_summary, created_at, finished_at
|
|
548
550
|
FROM chat_tasks ${o.length>0?`WHERE ${o.join(" AND ")}`:""}
|
|
549
|
-
ORDER BY created_at DESC LIMIT ${i}`,u=H(t,a);return JSON.stringify({total:u.length,tasks:u})}function
|
|
551
|
+
ORDER BY created_at DESC LIMIT ${i}`,u=H(t,a);return JSON.stringify({total:u.length,tasks:u})}function Bi(r){try{L(r,"UPDATE chat_memory SET relevance = relevance * 0.98 WHERE tier = 'long' AND relevance > 0.5"),L(r,"UPDATE chat_memory SET relevance = relevance * 0.90 WHERE tier = 'mid' AND relevance > 0.1"),L(r,"UPDATE chat_memory SET relevance = relevance * 0.70 WHERE tier = 'short' AND relevance > 0.05"),L(r,"DELETE FROM chat_memory WHERE relevance < 0.05")}catch{}}function Fi(r){try{let t=new Date(Date.now()-864e5).toISOString();L(r,`DELETE FROM chat_memory WHERE tier = 'short' AND created_at < ${w(t)}`)}catch{}}import{existsSync as G,readFileSync as pe,readdirSync as ze,mkdirSync as Gi,writeFileSync as re,statSync as us}from"fs";import{join as N,resolve as We,relative as ps,dirname as ds}from"path";import{fileURLToPath as zi}from"url";import{createRequire as Wi}from"module";var Hi=Wi(import.meta.url),Yi=`## Workflow Builder
|
|
550
552
|
|
|
551
553
|
You can help users build custom AI workflows using the Zibby workflow framework.
|
|
552
554
|
|
|
@@ -656,9 +658,9 @@ Call with no arguments to see all available topics.
|
|
|
656
658
|
- Workflow names must be kebab-case (e.g., ticket-triage, pr-review).
|
|
657
659
|
- State flows through: each node's validated output is stored under its name in state (e.g., state.classify_ticket).
|
|
658
660
|
- Downstream nodes reference upstream outputs in their prompt function (e.g., \\\`\\\${JSON.stringify(state.classify_ticket, null, 2)}\\\`).
|
|
659
|
-
- Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,
|
|
661
|
+
- Nodes can declare skills to get MCP tool access \u2014 the framework handles server lifecycle automatically.`,ms=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function fs(r){return`${r.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}Workflow`}function ue(r){return`${r.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}Node`}function Zi(r){let t=r?.agent;return t?t.provider?t.provider:t.gemini?"gemini":t.codex?"codex":t.claude?"claude":t.cursor?"cursor":process.env.AGENT_TYPE||"cursor":process.env.AGENT_TYPE||"cursor"}async function Vi(r){let t=We(r,".zibby.config.mjs");if(!G(t))return{};try{return(await import(t)).default||{}}catch{return{}}}function Qi(){try{let r=ds(Hi.resolve("@zibby/core/package.json")),t=N(r,"templates","browser-test-automation"),e=pe(N(t,"nodes","preflight.mjs"),"utf-8"),s=pe(N(t,"graph.mjs"),"utf-8");return{preflight:e,graph:s}}catch{return null}}var cs=ds(zi(import.meta.url));function ys(){let r=We(cs,"..","..","..","docsite","docs");if(G(r))return r;let t=We(cs,"..","docs");return G(t)?t:null}function ls(){let r=ys();if(!r)return[];try{let t=(e,s="")=>{let n=[];for(let i of ze(e)){let o=N(e,i);try{if(us(o).isDirectory())n=n.concat(t(o,`${s}${i}/`));else if(i.endsWith(".md")){let c=`${s}${i.replace(/\.md$/,"")}`;n.push(c)}}catch{}}return n};return t(r)}catch{return[]}}function hs(r){let t=ys();if(!t)return null;let e=N(t,`${r}.md`);if(!G(e))return null;try{return pe(e,"utf-8")}catch{return null}}function Xi(r){let t=r.nodes.map(o=>{let c=o.inputFields?.length?`Input fields: ${o.inputFields.join(", ")}`:"Input: receives full state",a=o.outputFields?.length?`Output fields: ${o.outputFields.join(", ")}`:"Output: determined by task",u=o.skills?.length?`Skills: ${o.skills.join(", ")}`:"";return`- ${o.name}: ${o.description}. ${c}. ${a}.${u?` ${u}`:""}`}).join(`
|
|
660
662
|
`),e=r.edges.map(o=>o.condition?`- ${o.from} \u2192 ${o.to} (conditional: ${o.condition})`:`- ${o.from} \u2192 ${o.to}`).join(`
|
|
661
|
-
`),s=
|
|
663
|
+
`),s=Qi(),n=hs("custom-workflows"),i="";return s&&(i+=`
|
|
662
664
|
## Real working examples from the Zibby framework
|
|
663
665
|
|
|
664
666
|
### Example node (preflight.mjs) \u2014 a prompt-only node with Zod schema and onComplete hook:
|
|
@@ -735,7 +737,7 @@ Return a JSON object with this exact structure:
|
|
|
735
737
|
}
|
|
736
738
|
}
|
|
737
739
|
|
|
738
|
-
IMPORTANT: Return ONLY valid JSON. No markdown fences, no explanation outside the JSON.`}async function
|
|
740
|
+
IMPORTANT: Return ONLY valid JSON. No markdown fences, no explanation outside the JSON.`}async function gs(r,t){let e=await Vi(t),s=Zi(e);try{let{invokeAgent:n}=await import("@zibby/core"),i=Xi(r),o=await n(i,{state:{agentType:s,config:e,cwd:t,workspace:t}},{model:e?.agent?.[s]?.model||"auto",workspace:t,config:e,timeout:12e4}),a=(typeof o=="string"?o:o?.raw||JSON.stringify(o?.structured||o)).match(/\{[\s\S]*\}/);if(!a)throw new Error("Agent did not return valid JSON");return JSON.parse(a[0])}catch(n){return console.warn(`Agent code generation failed (${n.message}), using templates`),en(r)}}function en(r){let t={};for(let e of r.nodes){let s=ue(e.name),n=`${e.name.split("_").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join("")}OutputSchema`,i=e.outputFields?.length?e.outputFields.map(a=>` ${a}: z.string().describe('${a}'),`).join(`
|
|
739
741
|
`):` summary: z.string().describe('Summary of the result'),
|
|
740
742
|
status: z.enum(['ok', 'warn', 'error']).describe('Overall status'),`,o=r.edges.filter(a=>a.to===e.name&&a.from!=="START").map(a=>`Previous step (${a.from}): \${JSON.stringify(state.${a.from} || {}, null, 2)}`).join(`
|
|
741
743
|
`),c=o?`${e.description}
|
|
@@ -757,9 +759,9 @@ export const ${s} = {
|
|
|
757
759
|
prompt: (state) => \`${c}\`,
|
|
758
760
|
outputSchema: ${n},
|
|
759
761
|
};
|
|
760
|
-
`}}return{nodes:t}}function
|
|
762
|
+
`}}return{nodes:t}}function tn(r,t,e,s){let n=t.toLowerCase(),i=fs(n),o=N(r,".zibby","workflows",n),c=N(o,"nodes");Gi(c,{recursive:!0});let a=e.nodes.map(g=>g.name);for(let g of e.nodes){let b=s.nodes?.[g.name]?.code;b&&re(N(c,`${g.name.replace(/_/g,"-")}.mjs`),b,"utf-8")}let u=a.map(g=>{let b=ue(g),y=g.replace(/_/g,"-");return`export { ${b} } from './${y}.mjs';`});re(N(c,"index.mjs"),`${u.join(`
|
|
761
763
|
`)}
|
|
762
|
-
`,"utf-8");let l=a[0],p=a.map(g=>
|
|
764
|
+
`,"utf-8");let l=a[0],p=a.map(g=>ue(g)).join(", "),d=a.map(g=>` graph.addNode('${g}', ${ue(g)});`).join(`
|
|
763
765
|
`),m=e.edges.map(g=>g.condition?` graph.addConditionalEdges('${g.from}', (state) => {
|
|
764
766
|
${g.condition}
|
|
765
767
|
});`:` graph.addEdge('${g.from}', '${g.to}');`).join(`
|
|
@@ -782,16 +784,16 @@ ${m}
|
|
|
782
784
|
console.log(\`[${n}] workflow complete \u2014 success: \${result.success !== false}\`);
|
|
783
785
|
}
|
|
784
786
|
}
|
|
785
|
-
`;
|
|
786
|
-
`,"utf-8");let _=["graph.mjs","workflow.json","nodes/index.mjs",...a.map(g=>`nodes/${g.replace(/_/g,"-")}.mjs`)];return{workflowDir:
|
|
787
|
-
`,b=F(h)?le(h,"utf-8"):"";return b.includes(_)||se(h,b+g,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${f}`,exportName:_,message:`Node "${a}" added. Update graph.mjs to wire it into the graph.`})}async function nn(r,t){let{name:e,projectId:s}=r,n=(e||"").toLowerCase();if(!n)return JSON.stringify({error:"Workflow name is required."});if(!s)return JSON.stringify({error:"projectId is required."});let i=N(t,".zibby","workflows",n);if(!F(i))return JSON.stringify({error:`Workflow "${n}" not found at .zibby/workflows/${n}/`});try{let{execSync:o}=await import("child_process"),c=o(`node "${N(t,"packages/cli/bin/zibby.js")}" deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:c.trim()})}catch{try{let{execSync:c}=await import("child_process"),a=c(`npx zibby deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:a.trim()})}catch(c){return JSON.stringify({error:`Deploy failed: ${c.message}`})}}}function on(r){let t=N(r,".zibby","workflows");if(!F(t))return JSON.stringify({workflows:[],message:"No workflows found. Use build_workflow to create one."});let s=Be(t).filter(n=>{try{return cs(N(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=N(t,n,"workflow.json"),o={};try{o=JSON.parse(le(i,"utf-8"))}catch{}let c=N(t,n,"nodes"),a=0;try{a=Be(c).filter(u=>u.endsWith(".mjs")&&u!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:a,path:ls(r,N(t,n))}});return JSON.stringify({workflows:s})}var hs={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Hi,tools:[{name:"design_workflow",description:"Design a workflow spec (nodes, edges, descriptions) for the user to review before building. Call this after understanding requirements.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name in kebab-case (e.g., ticket-triage)"},description:{type:"string",description:"What the workflow does"},nodes:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Node name in snake_case (e.g., classify_ticket)"},description:{type:"string",description:"What this node does \u2014 be specific about input/output"},inputFields:{type:"array",items:{type:"string"},description:"Key fields this node reads from state"},outputFields:{type:"array",items:{type:"string"},description:"Key fields this node produces"}},required:["name","description"]},description:"Workflow nodes (processing steps)"},edges:{type:"array",items:{type:"object",properties:{from:{type:"string",description:"Source node name"},to:{type:"string",description:'Target node name (or "END")'},condition:{type:"string",description:"JS expression for conditional routing (optional)"}},required:["from","to"]},description:"Edges connecting nodes. If omitted, nodes are wired linearly."}},required:["name","description","nodes"]}},{name:"build_workflow",description:"Generate real workflow code on disk from a design spec. Uses the configured AI agent for high-quality code generation.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name (from design_workflow)"},spec:{type:"object",description:"The full spec object returned by design_workflow",properties:{name:{type:"string"},description:{type:"string"},nodes:{type:"array",items:{type:"object"}},edges:{type:"array",items:{type:"object"}}}}},required:["name","spec"]}},{name:"add_node",description:"Add a new node to an existing workflow. Generates the node file and updates the barrel export.",input_schema:{type:"object",properties:{workflowName:{type:"string",description:"Existing workflow name (kebab-case)"},nodeName:{type:"string",description:"New node name (snake_case)"},description:{type:"string",description:"What this node does"},inputFields:{type:"array",items:{type:"string"},description:"Fields read from state"},outputFields:{type:"array",items:{type:"string"},description:"Fields produced"}},required:["workflowName","nodeName","description"]}},{name:"deploy_workflow",description:"Deploy a workflow to Zibby Cloud. Returns the trigger URL.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name to deploy"},projectId:{type:"string",description:"Target project ID"}},required:["name","projectId"]}},{name:"list_workflows",description:"List all local workflows in .zibby/workflows/.",input_schema:{type:"object",properties:{}}},{name:"explore_framework_docs",description:"Read Zibby framework documentation on demand. Call this before building complex workflows or when you need details on advanced patterns (middleware, conditional routing, skills, deployment, CLI commands).",input_schema:{type:"object",properties:{topic:{type:"string",description:'Doc topic to read (e.g., "workflow", "custom-workflows", "cli-reference", "packages/core", "packages/skills", "integrations/jira"). Call with no topic to list all available docs.'}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"design_workflow":return await tn(t);case"build_workflow":return await sn(t,s);case"add_node":return await rn(t,s);case"deploy_workflow":return await nn(t,s);case"list_workflows":return on(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=as();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=fs(n);if(!i){let o=as();return JSON.stringify({error:`Doc "${n}" not found.`,available:o})}return JSON.stringify({topic:n,content:i})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};import{resolveIntegrationToken as an}from"@zibby/core/backend-client.js";var ze=Object.freeze({id:"openai_billing",requiresIntegration:j.OPENAI_BILLING,description:"OpenAI organization billing/usage admin API (paste sk-admin-... key)"}),We=Object.freeze({id:"anthropic_billing",requiresIntegration:j.ANTHROPIC_BILLING,description:"Anthropic organization cost/usage admin API (paste sk-ant-admin-... key)"}),He=Object.freeze({id:"cursor_admin",requiresIntegration:j.CURSOR_ADMIN,description:"Cursor Team/Enterprise admin API (paste admin key)"});function gs(r){return Math.floor(r/1e3)}function Fe(r){return new Date(r).toISOString().slice(0,10)}function _s(r){return new Date(r).toISOString()}async function ue(r){let t=await an(r);if(!t?.token)throw new Error(`${r} token resolver returned no token`);return t.token}async function bs({startMs:r,endMs:t,groupBy:e=["project_id","line_item"]}){let s=await ue("openai_billing"),n=[],i=0,o=e.map(a=>`group_by[]=${encodeURIComponent(a)}`).join("&"),c=null;for(let a=0;a<50;a++){let l=`https://api.openai.com/v1/organization/costs?${[`start_time=${gs(r)}`,`end_time=${gs(t)}`,"bucket_width=1d","limit=180",o,c?`page=${encodeURIComponent(c)}`:""].filter(Boolean).join("&")}`,p=await fetch(l,{headers:{Authorization:`Bearer ${s}`}});if(!p.ok){let m=await p.text().catch(()=>"");throw new Error(`OpenAI costs API ${p.status}: ${m.slice(0,200)}`)}let d=await p.json();for(let m of d.data||[]){i+=1;let f=Fe((m.start_time||0)*1e3);for(let h of m.results||[])n.push({provider:"openai",day:f,costUsd:Number(h.amount?.value??0),projectId:h.project_id||void 0,apiKeyId:h.api_key_id||void 0,model:h.line_item||void 0})}if(!d.has_more||!d.next_page)break;c=d.next_page}return{ok:!0,items:n,rawBuckets:i}}async function cn(){let r=await ue("openai_billing"),e=await fetch("https://api.openai.com/v1/organization/projects?limit=100",{headers:{Authorization:`Bearer ${r}`}});if(!e.ok){let i=await e.text().catch(()=>"");throw new Error(`OpenAI projects API ${e.status}: ${i.slice(0,200)}`)}let s=await e.json(),n=new Map;for(let i of s.data||[])n.set(i.id,i.name);return n}async function ks({startMs:r,endMs:t,groupBy:e=["workspace_id"]}){let s=await ue("anthropic_billing"),n=[],i=0,o=e.map(a=>`group_by[]=${encodeURIComponent(a)}`).join("&"),c=null;for(let a=0;a<50;a++){let l=`https://api.anthropic.com/v1/organizations/cost_report?${[`starting_at=${encodeURIComponent(_s(r))}`,`ending_at=${encodeURIComponent(_s(t))}`,"bucket=1d","limit=100",o,c?`page=${encodeURIComponent(c)}`:""].filter(Boolean).join("&")}`,p=await fetch(l,{headers:{"x-api-key":s,"anthropic-version":"2023-06-01"}});if(!p.ok){let m=await p.text().catch(()=>"");throw new Error(`Anthropic cost_report ${p.status}: ${m.slice(0,200)}`)}let d=await p.json();for(let m of d.data||[]){i+=1;let f=(m.starting_at||"").slice(0,10);for(let h of m.results||[])n.push({provider:"anthropic",day:f,costUsd:Number(h.amount??h.cost??0),workspaceId:h.workspace_id||void 0,apiKeyId:h.api_key_id||void 0,model:h.model||void 0,tokensIn:h.uncached_input_tokens!=null?Number(h.uncached_input_tokens):void 0,tokensOut:h.output_tokens!=null?Number(h.output_tokens):void 0,cachedTokens:h.cached_input_tokens!=null?Number(h.cached_input_tokens):void 0})}if(!d.has_more||!d.next_page)break;c=d.next_page}return{ok:!0,items:n,rawBuckets:i}}async function ln(){let r=await ue("anthropic_billing"),e=await fetch("https://api.anthropic.com/v1/organizations/workspaces?limit=100",{headers:{"x-api-key":r,"anthropic-version":"2023-06-01"}});if(!e.ok){let i=await e.text().catch(()=>"");throw new Error(`Anthropic workspaces ${e.status}: ${i.slice(0,200)}`)}let s=await e.json(),n=new Map;for(let i of s.data||[])n.set(i.id,i.name);return n}async function ws({startMs:r,endMs:t}){let e=await ue("cursor_admin"),s=Fe(r),n=Fe(t),i=`https://api.cursor.com/teams/daily-usage-data?startDate=${s}&endDate=${n}`,o=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(!o.ok){let l=await o.text().catch(()=>"");throw new Error(`Cursor daily-usage ${o.status}: ${l.slice(0,200)}`)}let c=await o.json(),a=[],u=0;for(let l of c.data||[]){u+=1;let p=l.date;for(let d of l.userMetrics||[]){for(let m of d.modelUsage||[]){let f=Number(m.acceptedLines??0),h=Number(m.suggestedLines??0);a.push({provider:"cursor",day:p,costUsd:Number(m.totalCents??0)/100,userEmail:d.email,model:m.model,requestCount:Number(m.requestCount??0),acceptanceRate:h>0?f/h:void 0})}(!d.modelUsage||d.modelUsage.length===0)&&a.push({provider:"cursor",day:p,costUsd:Number(d.totalCents??0)/100,userEmail:d.email})}}return{ok:!0,items:a,rawBuckets:u}}async function un({startMs:r,endMs:t}){let[e,s,n]=await Promise.allSettled([bs({startMs:r,endMs:t}),ks({startMs:r,endMs:t}),ws({startMs:r,endMs:t})]),i=l=>l.status==="fulfilled"?l.value:{ok:!1,error:l.reason?.message||String(l.reason),items:[]},o=i(e),c=i(s),a=i(n),u=[{provider:"openai",totalUsd:o.items.reduce((l,p)=>l+(p.costUsd||0),0)},{provider:"anthropic",totalUsd:c.items.reduce((l,p)=>l+(p.costUsd||0),0)},{provider:"cursor",totalUsd:a.items.reduce((l,p)=>l+(p.costUsd||0),0)}];return{openai:o,anthropic:c,cursor:a,totals:u}}function pn(r,t){let e=new Map;for(let s of r){let n=t(s);if(!n)continue;let i=e.get(n)||{key:n,totalUsd:0,count:0};i.totalUsd+=s.costUsd||0,i.count+=1,e.set(n,i)}return[...e.values()].sort((s,n)=>n.totalUsd-s.totalUsd)}function dn(r){if(!r.length)return{mean:0,stddev:0};let t=r.reduce((s,n)=>s+n,0)/r.length,e=r.reduce((s,n)=>s+(n-t)**2,0)/r.length;return{mean:t,stddev:Math.sqrt(e)}}import{z as k}from"zod";var pe=["ok","info","warn","critical"],mn=k.object({primary:k.string().min(1).max(200).describe('Headline number or phrase (e.g. "$8,240"). Rendered in large/bold.'),delta:k.object({value:k.string().max(40).describe('Delta vs baseline (e.g. "+12% wow"). Free-form string.'),direction:k.enum(["up","down","flat"]).optional(),severity:k.enum(pe).optional().describe("Color severity for the delta (warn/critical highlights regressions).")}).optional().describe("Optional comparison vs baseline. Renders inline next to primary."),summary:k.string().max(800).optional().describe('One-sentence narrative ("why this number"). Plain prose.')}),fn=k.object({kind:k.literal("trend"),title:k.string().max(120).optional(),labels:k.array(k.string().max(60)).min(2).max(20).describe('Bucket labels (e.g. ["Week-3", "Week-2", "Week-1", "This wk"]).'),values:k.array(k.number()).min(2).max(20).describe("Numeric values, one per label. Must match labels.length."),highlight:k.enum(["last","max","min","none"]).default("last").optional().describe("Which bucket to visually highlight in the rendered card."),severity:k.enum(pe).optional()}).refine(r=>r.labels.length===r.values.length,{message:"labels.length must equal values.length"}),yn=k.object({kind:k.literal("table"),title:k.string().max(120).optional(),headers:k.array(k.string().max(40)).min(1).max(8),rows:k.array(k.array(k.union([k.string().max(200),k.number()])).min(1).max(8)).max(40).describe("2D matrix. Each inner array must have headers.length entries.")}).refine(r=>r.rows.every(t=>t.length===r.headers.length),{message:"every row must have headers.length entries"}),hn=k.object({kind:k.literal("callouts"),title:k.string().max(120).optional(),tone:k.enum(pe).default("info").optional(),items:k.array(k.string().min(1).max(600)).min(1).max(10).describe("Each item renders as a bullet with a severity emoji.")}),gn=k.object({kind:k.literal("breakdown"),title:k.string().max(120).optional(),rows:k.array(k.object({label:k.string().min(1).max(80),value:k.string().min(1).max(80),sub:k.string().max(120).optional(),severity:k.enum(pe).optional()})).min(1).max(20)}),_n=k.object({kind:k.literal("paragraph"),title:k.string().max(120).optional(),text:k.string().min(1).max(3e3)}),bn=k.discriminatedUnion("kind",[fn,yn,hn,gn,_n]),Ye=k.object({title:k.string().min(1).max(200).describe('Card title (e.g. "Weekly AI Spend Report").'),subtitle:k.string().max(200).optional().describe('Date range or smaller header (e.g. "May 13 \u2014 May 20").'),headline:mn,sections:k.array(bn).max(20).default([]),footer:k.object({viewUrl:k.string().url().optional().describe('Optional "View in Zibby" button URL.'),rerunUrl:k.string().url().optional().describe('Optional "Run again" button URL.')}).optional()}),Y=Object.freeze({ok:"\u{1F7E2}",info:"\u{1F535}",warn:"\u{1F7E0}",critical:"\u{1F534}"}),Ss=Object.freeze({up:"\u2191",down:"\u2193",flat:"\u2192"}),kn=Object.freeze({ok:"green",info:"blue",warn:"orange",critical:"red"});function vs(r,t,e=12){if(!Number.isFinite(r)||!Number.isFinite(t)||t<=0)return"";let s=Math.max(0,Math.min(1,r/t)),n=Math.round(s*e);return"\u2593".repeat(n)+"\u2591".repeat(e-n)}function Ze(r,t){let e=String(r);return e.length>=t?e:e+" ".repeat(t-e.length)}function Ns(r,t){let e=String(r);return e.length>=t?e:" ".repeat(t-e.length)+e}function Is({headers:r,rows:t}){let e=r.map((o,c)=>{let a=Math.max(String(o).length,...t.map(u=>String(u[c]??"").length));return Math.min(a,32)}),s=o=>o.map((c,a)=>Ze(c,e[a])).join(" "),n=e.map(o=>"\u2500".repeat(o)).join(" ");return"```\n"+[s(r),n,...t.map(o=>s(o))].join(`
|
|
788
|
-
`)+"\n```"}function
|
|
789
|
-
`+t.headline.summary),e.push({type:"section",text:{type:"mrkdwn",text:n}});for(let i of t.sections)switch(e.push({type:"divider"}),i.title&&e.push({type:"section",text:{type:"mrkdwn",text:`*${i.title}*`}}),i.kind){case"trend":{let o=Math.max(...i.values),c=i.labels.map((a,u)=>{let l=i.values[u],p=
|
|
790
|
-
`)+"\n```"}});break}case"table":{e.push({type:"section",text:{type:"mrkdwn",text:
|
|
787
|
+
`;re(N(o,"graph.mjs"),f,"utf-8");let h={name:n,description:e.description||`${i} workflow`,entryClass:i,triggers:{api:!0}};re(N(o,"workflow.json"),`${JSON.stringify(h,null,2)}
|
|
788
|
+
`,"utf-8");let _=["graph.mjs","workflow.json","nodes/index.mjs",...a.map(g=>`nodes/${g.replace(/_/g,"-")}.mjs`)];return{workflowDir:ps(r,o),files:_,className:i,slug:n}}async function sn(r){let{name:t,description:e,nodes:s,edges:n}=r;if(!t||!ms.test(t.toLowerCase()))return JSON.stringify({error:`Invalid workflow name "${t}". Must be kebab-case, 2-64 chars, lowercase letters/numbers/hyphens.`});if(!s||s.length===0)return JSON.stringify({error:"At least one node is required."});let i={name:t.toLowerCase(),description:e||`${fs(t.toLowerCase())} workflow`,nodes:s.map(o=>({name:o.name.replace(/-/g,"_"),description:o.description||`Process ${o.name}`,inputFields:o.inputFields||[],outputFields:o.outputFields||[]})),edges:n||[]};if(i.edges.length===0&&i.nodes.length>0){for(let o=0;o<i.nodes.length-1;o++)i.edges.push({from:i.nodes[o].name,to:i.nodes[o+1].name});i.edges.push({from:i.nodes[i.nodes.length-1].name,to:"END"})}return JSON.stringify({ok:!0,spec:i,message:`Workflow "${i.name}" designed with ${i.nodes.length} node(s). Call build_workflow to generate the code.`,preview:{nodes:i.nodes.map(o=>o.name),flow:i.edges.map(o=>o.condition?`${o.from} \u2192(if ${o.condition})\u2192 ${o.to}`:`${o.from} \u2192 ${o.to}`)}})}async function rn(r,t){let{name:e,spec:s}=r,n=(e||s?.name||"").toLowerCase();if(!n||!ms.test(n))return JSON.stringify({error:`Invalid workflow name "${n}".`});if(!s||!s.nodes||s.nodes.length===0)return JSON.stringify({error:"spec with nodes is required. Call design_workflow first."});let i=N(t,".zibby","workflows",n);if(G(i))return JSON.stringify({error:`Workflow "${n}" already exists at .zibby/workflows/${n}/. Delete it first or choose a different name.`});let o=await gs(s,t),c=tn(t,n,s,o);return JSON.stringify({ok:!0,...c,message:`Workflow "${n}" created at ${c.workflowDir}/`,nextSteps:[`Test locally: zibby start ${n}`,`Deploy to cloud: zibby deploy ${n} --project <project-id>`,`Tail logs: zibby logs --workflow ${n} --project <project-id>`]})}async function nn(r,t){let{workflowName:e,nodeName:s,description:n,inputFields:i,outputFields:o}=r,c=(e||"").toLowerCase(),a=(s||"").replace(/-/g,"_"),u=N(t,".zibby","workflows",c);if(!G(u))return JSON.stringify({error:`Workflow "${c}" not found. Create it first with build_workflow.`});let l={name:c,description:"",nodes:[{name:a,description:n||`Process ${a}`,inputFields:i||[],outputFields:o||[]}],edges:[]},d=(await gs(l,t)).nodes?.[a]?.code;if(!d)return JSON.stringify({error:"Failed to generate node code."});let m=N(u,"nodes"),f=`${a.replace(/_/g,"-")}.mjs`;re(N(m,f),d,"utf-8");let h=N(m,"index.mjs"),_=ue(a),g=`export { ${_} } from './${a.replace(/_/g,"-")}.mjs';
|
|
789
|
+
`,b=G(h)?pe(h,"utf-8"):"";return b.includes(_)||re(h,b+g,"utf-8"),JSON.stringify({ok:!0,file:`nodes/${f}`,exportName:_,message:`Node "${a}" added. Update graph.mjs to wire it into the graph.`})}async function on(r,t){let{name:e,projectId:s}=r,n=(e||"").toLowerCase();if(!n)return JSON.stringify({error:"Workflow name is required."});if(!s)return JSON.stringify({error:"projectId is required."});let i=N(t,".zibby","workflows",n);if(!G(i))return JSON.stringify({error:`Workflow "${n}" not found at .zibby/workflows/${n}/`});try{let{execSync:o}=await import("child_process"),c=o(`node "${N(t,"packages/cli/bin/zibby.js")}" deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:c.trim()})}catch{try{let{execSync:c}=await import("child_process"),a=c(`npx zibby deploy ${n} --project ${s}`,{cwd:t,encoding:"utf-8",timeout:3e4,stdio:["pipe","pipe","pipe"]});return JSON.stringify({ok:!0,output:a.trim()})}catch(c){return JSON.stringify({error:`Deploy failed: ${c.message}`})}}}function an(r){let t=N(r,".zibby","workflows");if(!G(t))return JSON.stringify({workflows:[],message:"No workflows found. Use build_workflow to create one."});let s=ze(t).filter(n=>{try{return us(N(t,n)).isDirectory()}catch{return!1}}).map(n=>{let i=N(t,n,"workflow.json"),o={};try{o=JSON.parse(pe(i,"utf-8"))}catch{}let c=N(t,n,"nodes"),a=0;try{a=ze(c).filter(u=>u.endsWith(".mjs")&&u!=="index.mjs").length}catch{}return{name:n,description:o.description||"",nodeCount:a,path:ps(r,N(t,n))}});return JSON.stringify({workflows:s})}var _s={id:"workflow-builder",description:"Build, scaffold, and deploy custom AI workflows via conversation",envKeys:[],promptFragment:Yi,tools:[{name:"design_workflow",description:"Design a workflow spec (nodes, edges, descriptions) for the user to review before building. Call this after understanding requirements.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name in kebab-case (e.g., ticket-triage)"},description:{type:"string",description:"What the workflow does"},nodes:{type:"array",items:{type:"object",properties:{name:{type:"string",description:"Node name in snake_case (e.g., classify_ticket)"},description:{type:"string",description:"What this node does \u2014 be specific about input/output"},inputFields:{type:"array",items:{type:"string"},description:"Key fields this node reads from state"},outputFields:{type:"array",items:{type:"string"},description:"Key fields this node produces"}},required:["name","description"]},description:"Workflow nodes (processing steps)"},edges:{type:"array",items:{type:"object",properties:{from:{type:"string",description:"Source node name"},to:{type:"string",description:'Target node name (or "END")'},condition:{type:"string",description:"JS expression for conditional routing (optional)"}},required:["from","to"]},description:"Edges connecting nodes. If omitted, nodes are wired linearly."}},required:["name","description","nodes"]}},{name:"build_workflow",description:"Generate real workflow code on disk from a design spec. Uses the configured AI agent for high-quality code generation.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name (from design_workflow)"},spec:{type:"object",description:"The full spec object returned by design_workflow",properties:{name:{type:"string"},description:{type:"string"},nodes:{type:"array",items:{type:"object"}},edges:{type:"array",items:{type:"object"}}}}},required:["name","spec"]}},{name:"add_node",description:"Add a new node to an existing workflow. Generates the node file and updates the barrel export.",input_schema:{type:"object",properties:{workflowName:{type:"string",description:"Existing workflow name (kebab-case)"},nodeName:{type:"string",description:"New node name (snake_case)"},description:{type:"string",description:"What this node does"},inputFields:{type:"array",items:{type:"string"},description:"Fields read from state"},outputFields:{type:"array",items:{type:"string"},description:"Fields produced"}},required:["workflowName","nodeName","description"]}},{name:"deploy_workflow",description:"Deploy a workflow to Zibby Cloud. Returns the trigger URL.",input_schema:{type:"object",properties:{name:{type:"string",description:"Workflow name to deploy"},projectId:{type:"string",description:"Target project ID"}},required:["name","projectId"]}},{name:"list_workflows",description:"List all local workflows in .zibby/workflows/.",input_schema:{type:"object",properties:{}}},{name:"explore_framework_docs",description:"Read Zibby framework documentation on demand. Call this before building complex workflows or when you need details on advanced patterns (middleware, conditional routing, skills, deployment, CLI commands).",input_schema:{type:"object",properties:{topic:{type:"string",description:'Doc topic to read (e.g., "workflow", "custom-workflows", "cli-reference", "packages/core", "packages/skills", "integrations/jira"). Call with no topic to list all available docs.'}}}}],async handleToolCall(r,t,e){let s=e?.options?.workspace||process.cwd();try{switch(r){case"design_workflow":return await sn(t);case"build_workflow":return await rn(t,s);case"add_node":return await nn(t,s);case"deploy_workflow":return await on(t,s);case"list_workflows":return an(s);case"explore_framework_docs":{let n=(t.topic||"").trim();if(!n){let o=ls();return JSON.stringify({available:o,hint:"Call again with a topic to read its content."})}let i=hs(n);if(!i){let o=ls();return JSON.stringify({error:`Doc "${n}" not found.`,available:o})}return JSON.stringify({topic:n,content:i})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(n){return JSON.stringify({error:n.message})}},resolve(){return null}};import{resolveIntegrationToken as cn}from"@zibby/core/backend-client.js";var Ye=Object.freeze({id:"openai_billing",requiresIntegration:$.OPENAI_BILLING,description:"OpenAI organization billing/usage admin API (paste sk-admin-... key)"}),Ze=Object.freeze({id:"anthropic_billing",requiresIntegration:$.ANTHROPIC_BILLING,description:"Anthropic organization cost/usage admin API (paste sk-ant-admin-... key)"}),Ve=Object.freeze({id:"cursor_admin",requiresIntegration:$.CURSOR_ADMIN,description:"Cursor Team/Enterprise admin API (paste admin key)"});function bs(r){return Math.floor(r/1e3)}function He(r){return new Date(r).toISOString().slice(0,10)}function ks(r){return new Date(r).toISOString()}async function de(r){let t=await cn(r);if(!t?.token)throw new Error(`${r} token resolver returned no token`);return t.token}async function ws({startMs:r,endMs:t,groupBy:e=["project_id","line_item"]}){let s=await de("openai_billing"),n=[],i=0,o=e.map(a=>`group_by[]=${encodeURIComponent(a)}`).join("&"),c=null;for(let a=0;a<50;a++){let l=`https://api.openai.com/v1/organization/costs?${[`start_time=${bs(r)}`,`end_time=${bs(t)}`,"bucket_width=1d","limit=180",o,c?`page=${encodeURIComponent(c)}`:""].filter(Boolean).join("&")}`,p=await fetch(l,{headers:{Authorization:`Bearer ${s}`}});if(!p.ok){let m=await p.text().catch(()=>"");throw new Error(`OpenAI costs API ${p.status}: ${m.slice(0,200)}`)}let d=await p.json();for(let m of d.data||[]){i+=1;let f=He((m.start_time||0)*1e3);for(let h of m.results||[])n.push({provider:"openai",day:f,costUsd:Number(h.amount?.value??0),projectId:h.project_id||void 0,apiKeyId:h.api_key_id||void 0,model:h.line_item||void 0})}if(!d.has_more||!d.next_page)break;c=d.next_page}return{ok:!0,items:n,rawBuckets:i}}async function ln(){let r=await de("openai_billing"),e=await fetch("https://api.openai.com/v1/organization/projects?limit=100",{headers:{Authorization:`Bearer ${r}`}});if(!e.ok){let i=await e.text().catch(()=>"");throw new Error(`OpenAI projects API ${e.status}: ${i.slice(0,200)}`)}let s=await e.json(),n=new Map;for(let i of s.data||[])n.set(i.id,i.name);return n}async function Ss({startMs:r,endMs:t,groupBy:e=["workspace_id"]}){let s=await de("anthropic_billing"),n=[],i=0,o=e.map(a=>`group_by[]=${encodeURIComponent(a)}`).join("&"),c=null;for(let a=0;a<50;a++){let l=`https://api.anthropic.com/v1/organizations/cost_report?${[`starting_at=${encodeURIComponent(ks(r))}`,`ending_at=${encodeURIComponent(ks(t))}`,"bucket=1d","limit=100",o,c?`page=${encodeURIComponent(c)}`:""].filter(Boolean).join("&")}`,p=await fetch(l,{headers:{"x-api-key":s,"anthropic-version":"2023-06-01"}});if(!p.ok){let m=await p.text().catch(()=>"");throw new Error(`Anthropic cost_report ${p.status}: ${m.slice(0,200)}`)}let d=await p.json();for(let m of d.data||[]){i+=1;let f=(m.starting_at||"").slice(0,10);for(let h of m.results||[])n.push({provider:"anthropic",day:f,costUsd:Number(h.amount??h.cost??0),workspaceId:h.workspace_id||void 0,apiKeyId:h.api_key_id||void 0,model:h.model||void 0,tokensIn:h.uncached_input_tokens!=null?Number(h.uncached_input_tokens):void 0,tokensOut:h.output_tokens!=null?Number(h.output_tokens):void 0,cachedTokens:h.cached_input_tokens!=null?Number(h.cached_input_tokens):void 0})}if(!d.has_more||!d.next_page)break;c=d.next_page}return{ok:!0,items:n,rawBuckets:i}}async function un(){let r=await de("anthropic_billing"),e=await fetch("https://api.anthropic.com/v1/organizations/workspaces?limit=100",{headers:{"x-api-key":r,"anthropic-version":"2023-06-01"}});if(!e.ok){let i=await e.text().catch(()=>"");throw new Error(`Anthropic workspaces ${e.status}: ${i.slice(0,200)}`)}let s=await e.json(),n=new Map;for(let i of s.data||[])n.set(i.id,i.name);return n}async function vs({startMs:r,endMs:t}){let e=await de("cursor_admin"),s=He(r),n=He(t),i=`https://api.cursor.com/teams/daily-usage-data?startDate=${s}&endDate=${n}`,o=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(!o.ok){let l=await o.text().catch(()=>"");throw new Error(`Cursor daily-usage ${o.status}: ${l.slice(0,200)}`)}let c=await o.json(),a=[],u=0;for(let l of c.data||[]){u+=1;let p=l.date;for(let d of l.userMetrics||[]){for(let m of d.modelUsage||[]){let f=Number(m.acceptedLines??0),h=Number(m.suggestedLines??0);a.push({provider:"cursor",day:p,costUsd:Number(m.totalCents??0)/100,userEmail:d.email,model:m.model,requestCount:Number(m.requestCount??0),acceptanceRate:h>0?f/h:void 0})}(!d.modelUsage||d.modelUsage.length===0)&&a.push({provider:"cursor",day:p,costUsd:Number(d.totalCents??0)/100,userEmail:d.email})}}return{ok:!0,items:a,rawBuckets:u}}async function pn({startMs:r,endMs:t}){let[e,s,n]=await Promise.allSettled([ws({startMs:r,endMs:t}),Ss({startMs:r,endMs:t}),vs({startMs:r,endMs:t})]),i=l=>l.status==="fulfilled"?l.value:{ok:!1,error:l.reason?.message||String(l.reason),items:[]},o=i(e),c=i(s),a=i(n),u=[{provider:"openai",totalUsd:o.items.reduce((l,p)=>l+(p.costUsd||0),0)},{provider:"anthropic",totalUsd:c.items.reduce((l,p)=>l+(p.costUsd||0),0)},{provider:"cursor",totalUsd:a.items.reduce((l,p)=>l+(p.costUsd||0),0)}];return{openai:o,anthropic:c,cursor:a,totals:u}}function dn(r,t){let e=new Map;for(let s of r){let n=t(s);if(!n)continue;let i=e.get(n)||{key:n,totalUsd:0,count:0};i.totalUsd+=s.costUsd||0,i.count+=1,e.set(n,i)}return[...e.values()].sort((s,n)=>n.totalUsd-s.totalUsd)}function mn(r){if(!r.length)return{mean:0,stddev:0};let t=r.reduce((s,n)=>s+n,0)/r.length,e=r.reduce((s,n)=>s+(n-t)**2,0)/r.length;return{mean:t,stddev:Math.sqrt(e)}}import{z as k}from"zod";var me=["ok","info","warn","critical"],fn=k.object({primary:k.string().min(1).max(200).describe('Headline number or phrase (e.g. "$8,240"). Rendered in large/bold.'),delta:k.object({value:k.string().max(40).describe('Delta vs baseline (e.g. "+12% wow"). Free-form string.'),direction:k.enum(["up","down","flat"]).optional(),severity:k.enum(me).optional().describe("Color severity for the delta (warn/critical highlights regressions).")}).optional().describe("Optional comparison vs baseline. Renders inline next to primary."),summary:k.string().max(800).optional().describe('One-sentence narrative ("why this number"). Plain prose.')}),yn=k.object({kind:k.literal("trend"),title:k.string().max(120).optional(),labels:k.array(k.string().max(60)).min(2).max(20).describe('Bucket labels (e.g. ["Week-3", "Week-2", "Week-1", "This wk"]).'),values:k.array(k.number()).min(2).max(20).describe("Numeric values, one per label. Must match labels.length."),highlight:k.enum(["last","max","min","none"]).default("last").optional().describe("Which bucket to visually highlight in the rendered card."),severity:k.enum(me).optional()}).refine(r=>r.labels.length===r.values.length,{message:"labels.length must equal values.length"}),hn=k.object({kind:k.literal("table"),title:k.string().max(120).optional(),headers:k.array(k.string().max(40)).min(1).max(8),rows:k.array(k.array(k.union([k.string().max(200),k.number()])).min(1).max(8)).max(40).describe("2D matrix. Each inner array must have headers.length entries.")}).refine(r=>r.rows.every(t=>t.length===r.headers.length),{message:"every row must have headers.length entries"}),gn=k.object({kind:k.literal("callouts"),title:k.string().max(120).optional(),tone:k.enum(me).default("info").optional(),items:k.array(k.string().min(1).max(600)).min(1).max(10).describe("Each item renders as a bullet with a severity emoji.")}),_n=k.object({kind:k.literal("breakdown"),title:k.string().max(120).optional(),rows:k.array(k.object({label:k.string().min(1).max(80),value:k.string().min(1).max(80),sub:k.string().max(120).optional(),severity:k.enum(me).optional()})).min(1).max(20)}),bn=k.object({kind:k.literal("paragraph"),title:k.string().max(120).optional(),text:k.string().min(1).max(3e3)}),kn=k.discriminatedUnion("kind",[yn,hn,gn,_n,bn]),Qe=k.object({title:k.string().min(1).max(200).describe('Card title (e.g. "Weekly AI Spend Report").'),subtitle:k.string().max(200).optional().describe('Date range or smaller header (e.g. "May 13 \u2014 May 20").'),headline:fn,sections:k.array(kn).max(20).default([]),footer:k.object({viewUrl:k.string().url().optional().describe('Optional "View in Zibby" button URL.'),rerunUrl:k.string().url().optional().describe('Optional "Run again" button URL.')}).optional()}),Y=Object.freeze({ok:"\u{1F7E2}",info:"\u{1F535}",warn:"\u{1F7E0}",critical:"\u{1F534}"}),Ns=Object.freeze({up:"\u2191",down:"\u2193",flat:"\u2192"}),wn=Object.freeze({ok:"green",info:"blue",warn:"orange",critical:"red"});function Is(r,t,e=12){if(!Number.isFinite(r)||!Number.isFinite(t)||t<=0)return"";let s=Math.max(0,Math.min(1,r/t)),n=Math.round(s*e);return"\u2593".repeat(n)+"\u2591".repeat(e-n)}function Xe(r,t){let e=String(r);return e.length>=t?e:e+" ".repeat(t-e.length)}function Os(r,t){let e=String(r);return e.length>=t?e:" ".repeat(t-e.length)+e}function Rs({headers:r,rows:t}){let e=r.map((o,c)=>{let a=Math.max(String(o).length,...t.map(u=>String(u[c]??"").length));return Math.min(a,32)}),s=o=>o.map((c,a)=>Xe(c,e[a])).join(" "),n=e.map(o=>"\u2500".repeat(o)).join(" ");return"```\n"+[s(r),n,...t.map(o=>s(o))].join(`
|
|
790
|
+
`)+"\n```"}function Sn(r){let t=Qe.parse(r),e=[];e.push({type:"header",text:{type:"plain_text",text:t.title.slice(0,150),emoji:!0}}),t.subtitle&&e.push({type:"context",elements:[{type:"mrkdwn",text:t.subtitle}]});let s=[`*${t.headline.primary}*`];if(t.headline.delta){let i=Ns[t.headline.delta.direction]||"",o=t.headline.delta.severity?Y[t.headline.delta.severity]:"";s.push(`${i} ${t.headline.delta.value} ${o}`.trim())}let n=s.join(" ");t.headline.summary&&(n+=`
|
|
791
|
+
`+t.headline.summary),e.push({type:"section",text:{type:"mrkdwn",text:n}});for(let i of t.sections)switch(e.push({type:"divider"}),i.title&&e.push({type:"section",text:{type:"mrkdwn",text:`*${i.title}*`}}),i.kind){case"trend":{let o=Math.max(...i.values),c=i.labels.map((a,u)=>{let l=i.values[u],p=Is(l,o),m=(i.highlight==="last"&&u===i.labels.length-1||i.highlight==="max"&&l===o||i.highlight==="min"&&l===Math.min(...i.values))&&i.severity?` ${Y[i.severity]}`:"";return`${Xe(a,10)} ${Os(l.toLocaleString(),8)} ${p}${m}`});e.push({type:"section",text:{type:"mrkdwn",text:"```\n"+c.join(`
|
|
792
|
+
`)+"\n```"}});break}case"table":{e.push({type:"section",text:{type:"mrkdwn",text:Rs(i)}});break}case"callouts":{let o=Y[i.tone||"info"];e.push({type:"section",text:{type:"mrkdwn",text:i.items.map(c=>`${o} ${c}`).join(`
|
|
791
793
|
`)}});break}case"breakdown":{let o=i.rows.map(c=>({type:"mrkdwn",text:`*${c.label}*
|
|
792
794
|
${c.value}${c.sub?`
|
|
793
|
-
_${c.sub}_`:""}${c.severity?` ${Y[c.severity]}`:""}`}));for(let c=0;c<o.length;c+=10)e.push({type:"section",fields:o.slice(c,c+10)});break}case"paragraph":{e.push({type:"section",text:{type:"mrkdwn",text:i.text}});break}}if(t.footer&&(t.footer.viewUrl||t.footer.rerunUrl)){let i=[];t.footer.viewUrl&&i.push({type:"button",text:{type:"plain_text",text:"View in Zibby"},url:t.footer.viewUrl,style:"primary"}),t.footer.rerunUrl&&i.push({type:"button",text:{type:"plain_text",text:"Run again"},url:t.footer.rerunUrl}),e.push({type:"divider"}),e.push({type:"actions",elements:i})}return e}function
|
|
794
|
-
`+t.headline.summary),e.push({tag:"div",text:{tag:"lark_md",content:n}});for(let o of t.sections)switch(e.push({tag:"hr"}),o.title&&e.push({tag:"div",text:{tag:"lark_md",content:`**${o.title}**`}}),o.kind){case"trend":{let c=Math.max(...o.values),a=o.labels.map((u,l)=>{let p=o.values[l],d=
|
|
795
|
-
`)+"\n```"}});break}case"table":{e.push({tag:"div",text:{tag:"lark_md",content:
|
|
795
|
+
_${c.sub}_`:""}${c.severity?` ${Y[c.severity]}`:""}`}));for(let c=0;c<o.length;c+=10)e.push({type:"section",fields:o.slice(c,c+10)});break}case"paragraph":{e.push({type:"section",text:{type:"mrkdwn",text:i.text}});break}}if(t.footer&&(t.footer.viewUrl||t.footer.rerunUrl)){let i=[];t.footer.viewUrl&&i.push({type:"button",text:{type:"plain_text",text:"View in Zibby"},url:t.footer.viewUrl,style:"primary"}),t.footer.rerunUrl&&i.push({type:"button",text:{type:"plain_text",text:"Run again"},url:t.footer.rerunUrl}),e.push({type:"divider"}),e.push({type:"actions",elements:i})}return e}function vn(r){let t=Qe.parse(r),e=[],s=[`**${t.headline.primary}**`];if(t.headline.delta){let o=Ns[t.headline.delta.direction]||"",c=t.headline.delta.severity?Y[t.headline.delta.severity]:"";s.push(`${o} ${t.headline.delta.value} ${c}`.trim())}let n=s.join(" ");t.headline.summary&&(n+=`
|
|
796
|
+
`+t.headline.summary),e.push({tag:"div",text:{tag:"lark_md",content:n}});for(let o of t.sections)switch(e.push({tag:"hr"}),o.title&&e.push({tag:"div",text:{tag:"lark_md",content:`**${o.title}**`}}),o.kind){case"trend":{let c=Math.max(...o.values),a=o.labels.map((u,l)=>{let p=o.values[l],d=Is(p,c),f=(o.highlight==="last"&&l===o.labels.length-1||o.highlight==="max"&&p===c||o.highlight==="min"&&p===Math.min(...o.values))&&o.severity?` ${Y[o.severity]}`:"";return`${Xe(u,10)} ${Os(p.toLocaleString(),8)} ${d}${f}`});e.push({tag:"div",text:{tag:"lark_md",content:"```\n"+a.join(`
|
|
797
|
+
`)+"\n```"}});break}case"table":{e.push({tag:"div",text:{tag:"lark_md",content:Rs(o)}});break}case"callouts":{let c=Y[o.tone||"info"];e.push({tag:"div",text:{tag:"lark_md",content:o.items.map(a=>`${c} ${a}`).join(`
|
|
796
798
|
`)}});break}case"breakdown":{let c=o.rows.map(a=>{let u=a.severity?` ${Y[a.severity]}`:"",l=a.sub?` *${a.sub}*`:"";return`**${a.label}** ${a.value}${l}${u}`});e.push({tag:"div",text:{tag:"lark_md",content:c.join(`
|
|
797
|
-
`)}});break}case"paragraph":{e.push({tag:"div",text:{tag:"lark_md",content:o.text}});break}}if(t.footer&&(t.footer.viewUrl||t.footer.rerunUrl)){let o=[];t.footer.viewUrl&&o.push({tag:"button",text:{tag:"plain_text",content:"View in Zibby"},url:t.footer.viewUrl,type:"primary"}),t.footer.rerunUrl&&o.push({tag:"button",text:{tag:"plain_text",content:"Run again"},url:t.footer.rerunUrl,type:"default"}),e.push({tag:"hr"}),e.push({tag:"action",actions:o})}let i="blue";return t.headline.delta?.severity&&(i=
|
|
799
|
+
`)}});break}case"paragraph":{e.push({tag:"div",text:{tag:"lark_md",content:o.text}});break}}if(t.footer&&(t.footer.viewUrl||t.footer.rerunUrl)){let o=[];t.footer.viewUrl&&o.push({tag:"button",text:{tag:"plain_text",content:"View in Zibby"},url:t.footer.viewUrl,type:"primary"}),t.footer.rerunUrl&&o.push({tag:"button",text:{tag:"plain_text",content:"Run again"},url:t.footer.rerunUrl,type:"default"}),e.push({tag:"hr"}),e.push({tag:"action",actions:o})}let i="blue";return t.headline.delta?.severity&&(i=wn[t.headline.delta.severity]||"blue"),{config:{wide_screen_mode:!0},header:{title:{tag:"plain_text",content:t.title.slice(0,200)},subtitle:t.subtitle?{tag:"plain_text",content:t.subtitle.slice(0,200)}:void 0,template:i},elements:e}}var na=Object.freeze({ok:"green_background",info:"blue_background",warn:"orange_background",critical:"red_background"}),oa=Object.freeze({ok:"\u{1F7E2}",info:"\u2139\uFE0F",warn:"\u26A0\uFE0F",critical:"\u{1F6A8}"});import{createRequire as Nn}from"module";import{fileURLToPath as In}from"url";import{registerHandlers as On}from"@zibby/core/function-skill-registry.js";import{registerSkill as Rn}from"@zibby/agent-workflow";var An=Nn(import.meta.url);function $n(){try{return An.resolve("@zibby/core/function-bridge.js")}catch{return null}}var jn=import.meta.url;function Tn(){let r=Error.prepareStackTrace;try{Error.prepareStackTrace=(s,n)=>n;let e=new Error().stack;for(let s=2;s<e.length;s++){let n=e[s].getFileName();if(n&&n!==jn&&!n.startsWith("node:"))return n.startsWith("file://")?In(n):n}return null}finally{Error.prepareStackTrace=r}}function xn(r){if(!r||typeof r!="object")return{type:"object",properties:{},required:[]};let t={},e=[];for(let[s,n]of Object.entries(r))if(typeof n=="string")t[s]={type:n},e.push(s);else{let{required:i,...o}=n;t[s]=o,i!==!1&&e.push(s)}return{type:"object",properties:t,required:e}}function En(r,t,e){if(typeof e.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s={[r]:e.handler},n=[{name:r,description:e.description||"",input_schema:xn(e.input)}];return On(r,s,n),{id:r,type:"function",serverName:r,allowedTools:[`mcp__${r}__*`],description:e.description||`Function skill: ${r}`,envKeys:[],tools:n,resolve(){let i=$n();return i?{command:"node",args:[i,t,r]}:null}}}function Cn(r,t){return{id:r,type:"mcp",serverName:t.serverName||r,allowedTools:t.allowedTools||[`mcp__${t.serverName||r}__*`],description:t.description||`MCP skill: ${r}`,envKeys:t.envKeys||[],tools:t.tools||[],resolve:t.resolve,...t.cursorKey&&{cursorKey:t.cursorKey},...t.sessionEnvKey&&{sessionEnvKey:t.sessionEnvKey}}}function As(r,t){let e;if("handler"in t){if(typeof t.handler!="function")throw new Error(`Skill "${r}" must have a handler function`);let s=Tn();if(!s)throw new Error(`Could not resolve caller file for skill "${r}".`);e=En(r,s,t)}else if(typeof t.resolve=="function")e=Cn(r,t);else throw new Error(`Skill "${r}" must have either a handler (function skill) or resolve (MCP skill).`);return Rn(e),e}var Ln=As;import{registerSkill as Pa,getSkill as Ua,hasSkill as Da,getAllSkills as Ma,listSkillIds as qa}from"@zibby/agent-workflow";R(tt);R(it);R(ot);R(ct);R(lt);R(U);R(M);R(pt);R(ge);R(mt);R(Pt);R(Kt);R(yt);R(kt);R(ss);R(_s);R(Ye);R(Ze);R(Ve);R({...U,id:"slack_notify"});var Ta={BROWSER:"browser",JIRA:"jira",GITHUB:"github",LINEAR:"linear",PLANE:"plane",GIT:"git",SLACK:"slack",LARK:"lark",CHAT_NOTIFY:"chat_notify",SENTRY:"sentry",MEMORY:"memory",RUNNER:"runner",SKILL_INSTALLER:"skill-installer",CORE_TOOLS:"core-tools",CHAT_MEMORY:"chat-memory",WORKFLOW_BUILDER:"workflow-builder",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin"};export{$ as INTEGRATIONS,Us as INTEGRATION_REGISTRY,me as REPORT_SEVERITIES,Ta as SKILLS,Ze as anthropicBillingSkill,tt as browserSkill,ss as chatMemorySkill,pt as chatNotifySkill,kt as coreToolsSkill,Ve as cursorAdminSkill,pn as fetchAllProviders,Ss as fetchAnthropicCosts,un as fetchAnthropicWorkspaces,vs as fetchCursorSpend,ws as fetchOpenAICosts,ln as fetchOpenAIProjects,Ln as functionSkill,Ma as getAllSkills,Ua as getSkill,Kt as gitSkill,ot as githubSkill,dn as groupByKey,Da as hasSkill,it as jiraSkill,M as larkSkill,ct as linearSkill,qa as listSkillIds,mn as meanStddev,mt as memorySkill,Ye as openaiBillingSkill,lt as planeSkill,Pa as registerSkill,Qe as reportObjectSchema,Sn as reportToBlockKit,vn as reportToLarkCard,Pt as runnerSkill,ge as sentrySkill,As as skill,yt as skillInstallerSkill,U as slackSkill,Pt as testRunnerSkill,_s as workflowBuilderSkill};
|