@zibby/skills 0.1.32 → 0.1.34
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 +4 -3
- package/dist/gitlab.js +19 -0
- package/dist/index.js +141 -120
- 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 +4 -3
- package/dist/trackers/index.js +13 -12
- package/dist/trackers/jira-adapter.js +1 -1
- package/dist/trackers/linear-adapter.js +16 -16
- package/docs/apps/agent-ops.md +6 -6
- package/docs/apps/deploy.md +1 -1
- package/docs/apps/index.md +45 -42
- package/docs/apps/managing.md +1 -1
- package/docs/cli-reference.md +67 -67
- package/docs/cloning-repositories.md +9 -9
- package/docs/cloud/bundles.md +8 -8
- package/docs/cloud/dedicated-egress.md +6 -6
- package/docs/cloud/env-vars.md +29 -29
- package/docs/cloud/limits.md +11 -11
- package/docs/cloud/triggering.md +16 -16
- package/docs/concepts/agents.md +4 -4
- package/docs/concepts/sessions.md +7 -7
- package/docs/concepts/state.md +1 -1
- package/docs/concepts/sub-graphs.md +9 -9
- package/docs/get-started/deploy.md +14 -14
- package/docs/get-started/install.md +5 -3
- package/docs/get-started/run-locally.md +12 -12
- package/docs/get-started/trigger-and-logs.md +14 -14
- package/docs/get-started/use-from-agents.md +17 -17
- package/docs/get-started/your-first-workflow.md +10 -7
- 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 +16 -12
- package/docs/legacy/test-automation.md +2 -2
- package/docs/packages/cli.md +11 -11
- package/docs/packages/core.md +2 -2
- package/docs/packages/mcp-cli.md +18 -18
- package/docs/packages/skills.md +2 -2
- package/docs/packages/ui-memory.md +2 -2
- 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/recipes/sentry-triage.md +7 -7
- package/docs/recipes/test.md +6 -6
- package/docs/skills/browser.md +2 -2
- package/docs/skills/chat-memory.md +40 -11
- package/docs/skills/core-tools.md +1 -1
- package/docs/skills/function-skill.md +1 -1
- package/docs/skills/github.md +2 -2
- package/docs/skills/index.md +4 -0
- package/docs/skills/jira.md +1 -1
- package/docs/skills/lark.md +1 -1
- package/docs/skills/memory.md +2 -2
- package/docs/skills/sentry.md +1 -1
- package/docs/skills/slack.md +2 -2
- package/package.json +3 -1
package/dist/chat-memory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{execFileSync as
|
|
1
|
+
import{execFileSync as Z}from"child_process";import{existsSync as Y,mkdirSync as P}from"fs";import{join as _,basename as ue}from"path";import{randomBytes as de}from"crypto";import{pathToFileURL as M}from"url";import{createRequire as z}from"module";var F=".zibby/memory",X="dolt",G={encoding:"utf-8",stdio:["pipe","pipe","pipe"],timeout:15e3},U="mem0",L=new Map,b=new Map,w=!1,ye=z(import.meta.url),I=()=>de(8).toString("hex"),E=()=>new Date().toISOString(),pe=[`CREATE TABLE IF NOT EXISTS chat_memory (
|
|
2
2
|
id VARCHAR(64) PRIMARY KEY,
|
|
3
3
|
memory_key VARCHAR(160),
|
|
4
4
|
category VARCHAR(32) NOT NULL,
|
|
@@ -29,10 +29,10 @@ import{execFileSync as J}from"child_process";import{existsSync as H,mkdirSync as
|
|
|
29
29
|
tasks_failed INT DEFAULT 0,
|
|
30
30
|
key_facts TEXT,
|
|
31
31
|
created_at VARCHAR(32) NOT NULL
|
|
32
|
-
)`],
|
|
33
|
-
`)};`;
|
|
32
|
+
)`],H=new Set;function f(t,e){return Z(X,e,{...G,cwd:t})}function h(t,e){try{let r=f(t,["sql","-q",e,"-r","json"]);return JSON.parse(r.trim()).rows||[]}catch{return[]}}function g(t,e){f(t,["sql","-q",e])}function N(t){if(H.has(t))return!0;if(!Y(_(t,".dolt"))){if(!fe())return!1;P(t,{recursive:!0}),f(t,["init","--name","Zibby Chat Memory","--email","chat@zibby.app"])}let e=`${pe.join(`;
|
|
33
|
+
`)};`;g(t,e);try{g(t,"ALTER TABLE chat_memory ADD COLUMN tier VARCHAR(16) DEFAULT 'mid'")}catch{}try{g(t,"ALTER TABLE chat_memory ADD COLUMN memory_key VARCHAR(160)")}catch{}return H.add(t),!0}function Oe(){H.clear()}function De(t){return J(t)}function Le(t){return te(t)}function Be(t,e){return x(t,e)}function Fe(t,e){return ne(t,e)}function fe(){try{return Z(X,["version"],{...G,timeout:5e3}),!0}catch{return!1}}function c(t){return t==null?"NULL":`'${String(t).replace(/'/g,"''")}'`}function K(t){return String(t||"").toLowerCase().replace(/[“”]/g,'"').replace(/[‘’]/g,"'").replace(/[\s_-]+/g," ").replace(/[^\w\s"']/g,"").replace(/\s+/g," ").trim()}function A(t){return t==="long"?3:t==="mid"?2:t==="short"?1:0}function q(t,e){let r=["short","mid","long"].includes(t)?t:"mid";return new Set(["fact","decision","preference","credential","url","workaround"]).has(String(e||"").toLowerCase())&&r==="short"?"mid":r}function Q(t){let e=new Map;for(let r of t||[]){let s=K(r.content),n=r.memory_key?`key:${r.memory_key}`:s?`norm:${s}`:"";if(!n)continue;let i=e.get(n);if(!i){e.set(n,r);continue}let o=A(i.tier),m=A(r.tier);if(m>o){e.set(n,r);continue}m===o&&Number(r.relevance||0)>Number(i.relevance||0)&&e.set(n,r)}return[...e.values()]}function C(t,e){let r=String(t??"");return r.length<=e?r:e<=1?r.slice(0,e):`${r.slice(0,e-1)}\u2026`}function v(t,e){let r={recentSessions:Array.isArray(t?.recentSessions)?t.recentSessions:[],topMemories:Array.isArray(t?.topMemories)?t.topMemories:[],taskStats:Array.isArray(t?.taskStats)?t.taskStats:[],ticketFilter:t?.ticketFilter||null,backend:e||String(t?.backend||U),error:t?.error||null};return r.backend==="mem0"?{...r,recentSessions:[],taskStats:[]}:r}function W(t){let e=[];if(t.recentSessions?.length>0){e.push("Recent sessions:");for(let r of t.recentSessions.slice(0,3))r?.summary?.trim()&&e.push(`- ${C(r.summary,150)}${r.tickets?` [${r.tickets}]`:""}`)}if(t.topMemories?.length>0){e.push("Known facts:");for(let r of t.topMemories.slice(0,10)){let s=r.tier==="long"?"\u2605":"\xB7";e.push(`${s} [${r.category}] ${C(r.content,120)}`)}}return e.length===0?"":`## Memory Context
|
|
34
34
|
${e.join(`
|
|
35
|
-
`)}`}function
|
|
35
|
+
`)}`}function $(t){return{backend:t.backend,recentSessions:t.recentSessions.slice(0,3).map(e=>({summary:C(String(e?.summary||""),160),tickets:e?.tickets||null,created_at:e?.created_at||null})),topMemories:t.topMemories.slice(0,8).map(e=>({category:e?.category||null,tier:e?.tier||null,content:C(String(e?.content||""),140),source:e?.source||null})),taskStats:t.taskStats,error:t.error||null}}async function ge(t,e){let r=String(process.env.ZIBBY_MEMORY_BACKEND||"").trim().toLowerCase();if(r==="mem0"||r==="dolt")return r;let s=String(e?.options?.memoryBackend||e?.options?.config?.memory?.backend||"").trim().toLowerCase();if(s==="mem0"||s==="dolt")return s;if(b.has(t))return b.get(t);try{let n=_(t,".zibby.config.mjs");if(Y(n)){let i=await import(M(n).href),o=String(i?.default?.memory?.backend||"").trim().toLowerCase();if(o==="mem0"||o==="dolt")return b.set(t,o),o}}catch{}return b.set(t,U),U}function ee(t){let e=String(process.env.ZIBBY_MEMORY_USER_ID||"").trim();return e||`workspace:${ue(t||process.cwd())}`}var _e="mem0";function J(t){let e=_(t,F,_e);return{dir:e,vectorDbPath:_(e,"vectors.db"),historyDbPath:_(e,"history.db")}}function te(t){let e=String(process.env.ZIBBY_MEM0_OPENAI_BASE_URL||"").trim();if(!e)return null;let r=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:m}=J(t||process.cwd());return{llm:{provider:"openai",config:{model:s,baseURL:e,...r?{apiKey:r}:{}}},embedder:{provider:"openai",config:{model:n,embeddingDims:i,baseURL:e,...r?{apiKey:r}:{}}},vectorStore:{provider:"memory",config:{dimension:i,dbPath:o}},historyDbPath:m}}async function re(t){let e=t||process.cwd();if(L.has(e))return L.get(e);let r;try{let m=z(M(_(e,"package.json")).href).resolve("mem0ai/oss");r=await import(M(m).href)}catch{try{let o=ye.resolve("mem0ai/oss");r=await import(M(o).href)}catch(o){throw new Error(`Cannot find package 'mem0ai' for workspace "${e}". Install in that project: npm install mem0ai. (${o.message})`,{cause:o})}}let s=r?.Memory;if(!s)throw new Error("mem0ai/oss does not export Memory");let n=te(e);if(n)try{P(J(e).dir,{recursive:!0})}catch{}let i=n?new s(n):new s;return L.set(e,i),i}function j(t,e="mid"){return(Array.isArray(t)?t:Array.isArray(t?.results)?t.results:[]).map(s=>({id:s?.id||I(),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:q(s?.metadata?.tier||e,s?.metadata?.category||"fact"),relevance:Number(s?.score??s?.metadata?.relevance??.8),created_at:s?.created_at||s?.metadata?.created_at||E()})).filter(s=>String(s.content||"").trim().length>0)}var T={id:"dolt",store:(t,e)=>se(t,e),recall:(t,e)=>Re(t,e),brief:(t,e)=>Ae(t,e),endSession:(t,e)=>ie(t,e),logTask:(t,e)=>ce(t,e),taskHistory:(t,e)=>ae(t,e)},ke={id:"mem0",store:(t,e,r)=>Ee(t,e,r),recall:(t,e,r)=>oe(t,e,r),brief:(t,e,r)=>Te(t,e,r),endSession:(t,e)=>ie(t,e),logTask:(t,e)=>ce(t,e),taskHistory:(t,e)=>ae(t,e)},he={dolt:T,mem0:ke};async function x(t,e){let r=await ge(t,e);return he[r]||T}var Ue={id:"chat-memory",description:"Persistent chat memory and task history (Dolt-backed)",envKeys:[],promptFragment:`## Chat Memory (persistent)
|
|
36
36
|
You have persistent memory across sessions. Use it to avoid losing context:
|
|
37
37
|
- **memory_store**: Save important facts, decisions, or context. Anything worth remembering.
|
|
38
38
|
- **memory_recall**: Search your memory by keyword or category. Use this at the START of conversations to recall relevant context.
|
|
@@ -48,35 +48,37 @@ You have persistent memory across sessions. Use it to avoid losing context:
|
|
|
48
48
|
- When the user's request is complete: call memory_end_session
|
|
49
49
|
|
|
50
50
|
### Categories for memory_store
|
|
51
|
-
fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(t,e={}){let r=t?.options?.workspace||process.cwd(),s=
|
|
51
|
+
fact, decision, context, insight, credential, url, error, workaround`,resolve(){return null},async buildPromptContext(t,e={}){let r=t?.options?.workspace||process.cwd(),s=_(r,F),n=await x(r,t),i=n.id;if(i==="dolt"&&!N(s)){let o="Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation";return{backend:i,brief:v({backend:i,error:o},i),promptContext:"",debugPreview:$(v({backend:i,error:o},i)),error:o}}try{let o=await n.brief(e,s,r),m=JSON.parse(o||"{}"),l=v({...m,backend:i},i);return{backend:i,brief:l,promptContext:W(l),debugPreview:$(l),error:l.error||null}}catch(o){if(i==="mem0"&&n!==T&&N(s)){if(!w){w=!0;try{process.stderr.write(`[chat-memory] mem0 backend unavailable (${o?.message||o}); degrading to dolt for this run
|
|
52
|
+
`)}catch{}}try{let a=await T.brief(e,s,r),u=JSON.parse(a||"{}"),d=v({...u,backend:"dolt"},"dolt");return{backend:"dolt",brief:d,promptContext:W(d),debugPreview:$(d),error:d.error||null,degradedFrom:"mem0"}}catch{}}let m=String(o?.message||o),l=v({backend:i,error:m},i);return{backend:i,brief:l,promptContext:"",debugPreview:$(l),error:m}}},async handleToolCall(t,e,r){let s=r?.options?.workspace||process.cwd(),n=_(s,F),i=await x(s,r),o=i.id;if((o==="dolt"||["memory_end_session","task_log","task_history"].includes(t))&&!N(n))return JSON.stringify({error:"Dolt not available. Install: brew install dolt (macOS) or see https://docs.dolthub.com/introduction/installation"});let l=a=>{switch(t){case"memory_store":return a.store(e,n,s);case"memory_recall":return a.recall(e,n,s);case"memory_brief":return a.brief(e,n,s);case"memory_end_session":return a.endSession(e,n,s);case"task_log":return a.logTask(e,n,s);case"task_history":return a.taskHistory(e,n,s);default:return JSON.stringify({error:`Unknown tool: ${t}`})}};try{return await l(i)}catch(a){if(o==="mem0"&&i!==T){if(N(n)){if(!w){w=!0;try{process.stderr.write(`[chat-memory] mem0 backend unavailable (${a.message}); degrading to dolt for this run
|
|
53
|
+
`)}catch{}}try{return await l(T)}catch(u){return JSON.stringify({error:u.message,backend:"dolt",degradedFrom:"mem0"})}}return JSON.stringify({error:`mem0 unavailable (${a.message}); dolt fallback also unavailable`,backend:"mem0"})}return JSON.stringify({error:a.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 se(t,e){let{content:r,category:s,source:n,ticketKey:i,tier:o,memoryKey:m}=t;if(!r||!s)return JSON.stringify({error:"content and category are required"});let l=K(r);if(!l)return JSON.stringify({error:"content is empty after normalization"});let a=q(o,s),u=a==="long"?1:a==="mid"?.8:.5,d=String(m||"").trim().slice(0,160);if(d){let k=h(e,`SELECT id, tier, relevance
|
|
52
54
|
FROM chat_memory
|
|
53
|
-
WHERE memory_key = ${c(
|
|
55
|
+
WHERE memory_key = ${c(d)}
|
|
54
56
|
ORDER BY created_at DESC
|
|
55
|
-
LIMIT 1`)[0];if(k){let R=String(k.tier||"mid"),
|
|
57
|
+
LIMIT 1`)[0];if(k){let R=String(k.tier||"mid"),D=Number(k.relevance||0),V=A(a)>A(R)?a:R,le=Math.max(u,D);g(e,`UPDATE chat_memory
|
|
56
58
|
SET content = ${c(r)},
|
|
57
59
|
category = ${c(s)},
|
|
58
60
|
source = ${c(n)},
|
|
59
|
-
ticket_key = ${c(
|
|
60
|
-
tier = ${c(
|
|
61
|
-
relevance = ${
|
|
62
|
-
created_at = ${c(
|
|
63
|
-
WHERE id = ${c(k.id)}`);try{f(e,["add","."]),f(e,["commit","-m",`memory upsert: ${s} \u2014 ${String(r).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:k.id,category:s,tier:
|
|
61
|
+
ticket_key = ${c(i)},
|
|
62
|
+
tier = ${c(V)},
|
|
63
|
+
relevance = ${le},
|
|
64
|
+
created_at = ${c(E())}
|
|
65
|
+
WHERE id = ${c(k.id)}`);try{f(e,["add","."]),f(e,["commit","-m",`memory upsert: ${s} \u2014 ${String(r).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:k.id,category:s,tier:V,memoryKey:d,upserted:!0})}}let p=h(e,`SELECT id, content, tier, relevance
|
|
64
66
|
FROM chat_memory
|
|
65
67
|
WHERE category = ${c(s)}
|
|
66
68
|
ORDER BY created_at DESC
|
|
67
|
-
LIMIT 200`).find(
|
|
68
|
-
SET tier = ${c(R?
|
|
69
|
-
relevance = ${Math.max(
|
|
70
|
-
WHERE id = ${c(p.id)}`);try{f(e,["add","."]),f(e,["commit","-m",`memory promote: ${s} \u2014 ${String(r).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:p.id,category:s,tier:R?
|
|
71
|
-
VALUES (${c(
|
|
72
|
-
FROM chat_memory ${
|
|
69
|
+
LIMIT 200`).find(S=>K(S.content)===l);if(p){let S=String(p.tier||"mid"),k=Number(p.relevance||0),R=A(a)>A(S),D=u>k;if(R||D){g(e,`UPDATE chat_memory
|
|
70
|
+
SET tier = ${c(R?a:S)},
|
|
71
|
+
relevance = ${Math.max(u,k)}
|
|
72
|
+
WHERE id = ${c(p.id)}`);try{f(e,["add","."]),f(e,["commit","-m",`memory promote: ${s} \u2014 ${String(r).slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:p.id,category:s,tier:R?a:S,deduped:!0,promoted:!0})}return JSON.stringify({ok:!0,id:p.id,category:s,tier:S,deduped:!0,promoted:!1})}let O=I(),me=process.env.ZIBBY_CHAT_SESSION_ID||null;g(e,`INSERT INTO chat_memory (id, memory_key, category, content, source, ticket_key, session_id, tier, relevance, created_at)
|
|
73
|
+
VALUES (${c(O)}, ${c(d||null)}, ${c(s)}, ${c(r)}, ${c(n)}, ${c(i)}, ${c(me)}, ${c(a)}, ${u}, ${c(E())})`);try{f(e,["add","."]),f(e,["commit","-m",`memory: ${s} \u2014 ${r.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:O,category:s,tier:a,memoryKey:d||null,stored:r.slice(0,100)})}function Se(t){let e=String(t||"").trim().toLowerCase();return e==="1"||e==="true"||e==="yes"||e==="on"}var B=new Map;async function ne(t,e){if(typeof t=="boolean")return t;if(process.env.ZIBBY_MEM0_INFER!=null&&String(process.env.ZIBBY_MEM0_INFER).trim()!=="")return Se(process.env.ZIBBY_MEM0_INFER);let r=e||process.cwd();if(B.has(r))return B.get(r);let s=!1;try{let n=_(r,".zibby.config.mjs");Y(n)&&(s=(await import(M(n).href))?.default?.memory?.infer===!0)}catch{}return B.set(r,s),s}async function Ee(t,e,r){let{content:s,category:n,source:i,ticketKey:o,tier:m,memoryKey:l,infer:a}=t;if(!s||!n)return JSON.stringify({error:"content and category are required"});try{let u=await re(r),d=ee(r),y=q(m,n),p=await ne(a,r);return await u.add([{role:"user",content:String(s)}],{userId:d,infer:p,metadata:{memoryKey:l||null,category:n,tier:y,source:i||"zibby-chat",ticketKey:o||null,created_at:E()}}),JSON.stringify({ok:!0,backend:"mem0",userId:d,category:n,tier:y,infer:p,memoryKey:l||null,stored:String(s).slice(0,100)})}catch(u){throw new Error(`mem0 store failed: ${u.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:u})}}function Re(t,e){let{query:r,category:s,ticketKey:n,tier:i,limit:o=20}=t,m=[];r&&m.push(`content LIKE ${c(`%${r}%`)}`),s&&m.push(`category = ${c(s)}`),n&&m.push(`ticket_key = ${c(n)}`),i&&m.push(`tier = ${c(i)}`);let a=`SELECT id, memory_key, category, content, source, ticket_key, tier, relevance, created_at
|
|
74
|
+
FROM chat_memory ${m.length>0?`WHERE ${m.join(" AND ")}`:""}
|
|
73
75
|
ORDER BY relevance DESC, created_at DESC
|
|
74
|
-
LIMIT ${
|
|
75
|
-
FROM chat_sessions ORDER BY created_at DESC LIMIT 5`),
|
|
76
|
-
WHERE tier = 'long' ${
|
|
77
|
-
WHERE tier = 'mid' ${
|
|
78
|
-
GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),
|
|
79
|
-
VALUES (${c(
|
|
80
|
-
VALUES (${c(
|
|
81
|
-
FROM chat_tasks ${
|
|
82
|
-
ORDER BY created_at DESC LIMIT ${
|
|
76
|
+
LIMIT ${o}`,u=h(e,a);return JSON.stringify({total:u.length,memories:u})}async function oe(t,e,r){let{query:s,category:n,ticketKey:i,tier:o,limit:m=20}=t;try{let l=await re(r),a=ee(r),u=[];if(s&&String(s).trim()){let d=await l.search(String(s),{filters:{user_id:a},topK:m});u=j(d)}else{let d=await l.getAll({filters:{user_id:a},topK:Math.max(m,50)});u=j(d)}return n&&(u=u.filter(d=>d.category===n)),i&&(u=u.filter(d=>d.ticket_key===i)),o&&(u=u.filter(d=>d.tier===o)),u=u.slice(0,m),JSON.stringify({total:u.length,memories:u,backend:"mem0"})}catch(l){throw new Error(`mem0 recall failed: ${l.message}. If mem0 is not installed, run: npm install mem0ai`,{cause:l})}}function Ae(t,e){let{ticketKey:r}=t;Me(e);let n=h(e,`SELECT session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, created_at
|
|
77
|
+
FROM chat_sessions ORDER BY created_at DESC LIMIT 5`),i=r?`AND ticket_key = ${c(r)}`:"",o=h(e,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
|
|
78
|
+
WHERE tier = 'long' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 10`),m=h(e,`SELECT memory_key, category, content, source, tier, relevance, created_at FROM chat_memory
|
|
79
|
+
WHERE tier = 'mid' ${i} ORDER BY relevance DESC, created_at DESC LIMIT 8`),a=h(e,`SELECT type, status, COUNT(*) as cnt FROM chat_tasks
|
|
80
|
+
GROUP BY type, status ORDER BY cnt DESC LIMIT 10`),u=Q([...o,...m]);return JSON.stringify({recentSessions:n,topMemories:u,taskStats:a,ticketFilter:r||null})}async function Te(t,e,r){let{ticketKey:s}=t,n=await oe({limit:80},e,r),i=JSON.parse(n||"{}"),o=Array.isArray(i.memories)?i.memories:[];s&&(o=o.filter(y=>y.ticket_key===s));let m=y=>{let p=Date.parse(String(y?.created_at||""))||0;return Number(y?.relevance||0)*1e12+p},l=(y,p)=>m(p)-m(y),a=o.filter(y=>y.tier==="long").sort(l).slice(0,10),u=o.filter(y=>y.tier==="mid").sort(l).slice(0,8),d=Q([...a,...u]);return JSON.stringify({recentSessions:[],topMemories:d,taskStats:[],ticketFilter:s||null,backend:"mem0"})}function ie(t,e){let{summary:r,tickets:s,tasksRun:n=0,tasksPassed:i=0,tasksFailed:o=0,keyFacts:m}=t;if(!r)return JSON.stringify({error:"summary is required"});let l=process.env.ZIBBY_CHAT_SESSION_ID||`session_${I()}`;if(g(e,`INSERT INTO chat_sessions (session_id, summary, tickets, tasks_run, tasks_passed, tasks_failed, key_facts, created_at)
|
|
81
|
+
VALUES (${c(l)}, ${c(r)}, ${c(s)}, ${n}, ${i}, ${o}, ${c(m)}, ${c(E())})`),m)for(let a of m.split(";").map(u=>u.trim()).filter(Boolean))se({content:a,category:"fact",source:"session_summary",tier:"mid"},e);ve(e);try{f(e,["add","."]),f(e,["commit","-m",`session end: ${r.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,sessionId:l,summary:r.slice(0,200)})}function ce(t,e){let{title:r,type:s,status:n,ticketKey:i,specPath:o,resultSummary:m}=t;if(!r||!s||!n)return JSON.stringify({error:"title, type, and status are required"});let l=I(),a=process.env.ZIBBY_CHAT_SESSION_ID||null;g(e,`INSERT INTO chat_tasks (id, ticket_key, type, title, status, spec_path, session_id, result_summary, created_at, finished_at)
|
|
82
|
+
VALUES (${c(l)}, ${c(i)}, ${c(s)}, ${c(r)}, ${c(n)}, ${c(o)}, ${c(a)}, ${c(m)}, ${c(E())}, ${c(E())})`);try{f(e,["add","."]),f(e,["commit","-m",`task: ${n} \u2014 ${r.slice(0,60)}`])}catch{}return JSON.stringify({ok:!0,id:l,title:r,type:s,status:n})}function ae(t,e){let{ticketKey:r,type:s,status:n,limit:i=20}=t,o=[];r&&o.push(`ticket_key = ${c(r)}`),s&&o.push(`type = ${c(s)}`),n&&o.push(`status = ${c(n)}`);let l=`SELECT id, ticket_key, type, title, status, spec_path, result_summary, created_at, finished_at
|
|
83
|
+
FROM chat_tasks ${o.length>0?`WHERE ${o.join(" AND ")}`:""}
|
|
84
|
+
ORDER BY created_at DESC LIMIT ${i}`,a=h(e,l);return JSON.stringify({total:a.length,tasks:a})}function ve(t){try{g(t,"UPDATE chat_memory SET relevance = relevance * 0.98 WHERE tier = 'long' AND relevance > 0.5"),g(t,"UPDATE chat_memory SET relevance = relevance * 0.90 WHERE tier = 'mid' AND relevance > 0.1"),g(t,"UPDATE chat_memory SET relevance = relevance * 0.70 WHERE tier = 'short' AND relevance > 0.05"),g(t,"DELETE FROM chat_memory WHERE relevance < 0.05")}catch{}}function Me(t){try{let e=new Date(Date.now()-864e5).toISOString();g(t,`DELETE FROM chat_memory WHERE tier = 'short' AND created_at < ${c(e)}`)}catch{}}export{De as _mem0DbPaths,Oe as _resetInitCache,Le as _resolveMem0Config,Fe as _resolveMem0Infer,Be as _resolveMemoryAdapter,Ue as chatMemorySkill};
|
package/dist/chat-notify.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{existsSync as b}from"fs";import{fileURLToPath as S}from"url";import{dirname as v,resolve as N}from"path";import{resolveIntegrationToken as O}from"@zibby/core/backend-client.js";var y=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"}),J=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"}});function w(){if(process.env.MCP_SLACK_PATH)return process.env.MCP_SLACK_PATH;let r=v(S(import.meta.url)),e=N(r,"..","bin","mcp-slack.mjs");return b(e)?e:null}async function _(r,e={}){let{token:t}=await O("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}`,a={Authorization:`Bearer ${t}`},d;if(s){let l=new URLSearchParams(e).toString();l&&(n+=`?${l}`)}else a["Content-Type"]="application/json; charset=utf-8",d=JSON.stringify(e);let i=await(await fetch(n,{method:s?"GET":"POST",headers:a,body:d})).json();if(!i.ok)throw new Error(`Slack API error: ${i.error}`);return i}var m={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],requiresIntegration:y.SLACK,envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack (connected)
|
|
1
|
+
import{existsSync as b}from"fs";import{fileURLToPath as S}from"url";import{dirname as v,resolve as N}from"path";import{resolveIntegrationToken as O}from"@zibby/core/backend-client.js";var y=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"}),J=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"}});function w(){if(process.env.MCP_SLACK_PATH)return process.env.MCP_SLACK_PATH;let r=v(S(import.meta.url)),e=N(r,"..","bin","mcp-slack.mjs");return b(e)?e:null}async function _(r,e={}){let{token:t}=await O("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}`,a={Authorization:`Bearer ${t}`},d;if(s){let l=new URLSearchParams(e).toString();l&&(n+=`?${l}`)}else a["Content-Type"]="application/json; charset=utf-8",d=JSON.stringify(e);let i=await(await fetch(n,{method:s?"GET":"POST",headers:a,body:d})).json();if(!i.ok)throw new Error(`Slack API error: ${i.error}`);return i}var m={id:"slack",serverName:"slack",allowedTools:["mcp__slack__*"],requiresIntegration:y.SLACK,envKeys:["SLACK_BOT_TOKEN","SLACK_TEAM_ID"],description:"Slack MCP Server",promptFragment:`## Slack (connected)
|
|
2
2
|
You have access to the user's Slack workspace. Use these tools:
|
|
3
3
|
- slack_list_channels, slack_post_message, slack_reply_to_thread
|
|
4
4
|
- slack_add_reaction, slack_get_channel_history, slack_get_thread_replies
|
|
5
5
|
- slack_get_users, slack_get_user_profile
|
|
6
6
|
- slack_lookup_user_by_email (precise email\u2192user_id, prefer this over scanning slack_get_users)
|
|
7
|
-
- slack_list_usergroups, slack_get_usergroup_members (workspace-defined teams like @oncall, @platform)`,resolve(){let r=w();if(!r)return null;let e={};for(let t 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[t]&&(e[t]=process.env[t]);for(let t of this.envKeys)process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r],env:e,alwaysLoad:!0}},async handleToolCall(r,e){try{switch(r){case"slack_list_channels":{let t=await _("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(t.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!e.channel||!e.text)return JSON.stringify({error:"channel and text are required"});let t=await _("chat.postMessage",{channel:e.channel,text:e.text,...e.blocks?{blocks:e.blocks}:{}});return JSON.stringify({ok:!0,ts:t.ts,channel:t.channel})}case"slack_reply_to_thread":{if(!e.channel||!e.thread_ts||!e.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let t=await _("chat.postMessage",{channel:e.channel,thread_ts:e.thread_ts,text:e.text});return JSON.stringify({ok:!0,ts:t.ts})}case"slack_add_reaction":return!e.channel||!e.timestamp||!e.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await _("reactions.add",{channel:e.channel,timestamp:e.timestamp,name:e.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!e.channel)return JSON.stringify({error:"channel is required"});let t=await _("conversations.history",{channel:e.channel,limit:e.limit||20});return JSON.stringify({messages:(t.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!e.channel||!e.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let t=await _("conversations.replies",{channel:e.channel,ts:e.thread_ts});return JSON.stringify({messages:(t.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let t=await _("users.list",{limit:100});return JSON.stringify({users:(t.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(!e.user_id)return JSON.stringify({error:"user_id is required"});let t=await _("users.profile.get",{user:e.user_id});return JSON.stringify({profile:t.profile})}case"slack_lookup_user_by_email":{if(!e.email)return JSON.stringify({error:"email is required"});try{let t=await _("users.lookupByEmail",{email:e.email});return JSON.stringify({ok:!0,user:{id:t.user?.id,name:t.user?.real_name||t.user?.name,email:t.user?.profile?.email||e.email}})}catch(t){if(/users_not_found/.test(t.message))return JSON.stringify({ok:!1,reason:"users_not_found"});throw t}}case"slack_list_usergroups":{let t=await _("usergroups.list",{});return JSON.stringify({usergroups:(t.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(!e.usergroup)return JSON.stringify({error:"usergroup id is required"});let t=await _("usergroups.users.list",{usergroup:e.usergroup});return JSON.stringify({users:t.users||[]})}case"slack_search_users":{if(!e.query||typeof e.query!="string")return JSON.stringify({error:"query is required"});let t=e.query.trim().toLowerCase();if(!t)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(e.limit)||5,25)),n=[],a,d=5;for(let i=0;i<d;i+=1){let l={limit:200};a&&(l.cursor=a);let c=await _("users.list",l);for(let o of c.members||[])o.deleted||o.is_bot||n.push(o);if(a=c.response_metadata?.next_cursor,!a)break}let u=[];for(let i of n){let l=(i.real_name||"").toLowerCase(),c=(i.profile?.display_name||"").toLowerCase(),o=(i.name||"").toLowerCase(),p=0;l.includes(t)&&(p+=100-Math.abs(l.length-t.length)),c.includes(t)&&(p+=60-Math.abs(c.length-t.length)),o.includes(t)&&(p+=30-Math.abs(o.length-t.length)),(l===t||c===t)&&(p+=200),p>0&&u.push({id:i.id,name:i.real_name||i.profile?.display_name||i.name,email:i.profile?.email||void 0,_score:p})}return u.sort((i,l)=>l._score-i._score),JSON.stringify({ok:!0,matches:u.slice(0,s).map(({_score:i,...l})=>l),scanned:n.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.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 I}from"fs";import{fileURLToPath as T}from"url";import{dirname as A,resolve as C}from"path";import{resolveIntegrationToken as L}from"@zibby/core/backend-client.js";function E(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let r=A(T(import.meta.url)),e=C(r,"..","bin","mcp-lark.mjs");return I(e)?e:null}var R=6e3*1e3,g=null;async function x(){let{appId:r,appSecret:e,host:t}=await L("lark");if(g&&g.appId===r&&g.expiresAt>Date.now())return{token:g.token,host:t};let n=await(await fetch(`${t}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:e})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return g={token:n.tenant_access_token,expiresAt:Date.now()+R,appId:r},{token:n.tenant_access_token,host:t}}async function f(r,e,t={}){let{token:s,host:n}=await x(),a=`${n}${e}`,d={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(d.body=JSON.stringify(t));let i=await(await fetch(a,d)).json();if(i.code!==0)throw new Error(`Lark API ${e} error: ${i.msg||i.code}`);return i.data||{}}function k(r){return JSON.stringify({text:r})}function P(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 h={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:y.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
|
|
7
|
+
- slack_list_usergroups, slack_get_usergroup_members (workspace-defined teams like @oncall, @platform)`,resolve(){let r=w();if(!r)return null;let e={};for(let t 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[t]&&(e[t]=process.env[t]);for(let t of this.envKeys)process.env[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r],env:e,alwaysLoad:!0}},async handleToolCall(r,e){try{switch(r){case"slack_list_channels":{let t=await _("conversations.list",{types:"public_channel",limit:100});return JSON.stringify({channels:(t.channels||[]).map(s=>({id:s.id,name:s.name,topic:s.topic?.value}))})}case"slack_post_message":{if(!e.channel||!e.text)return JSON.stringify({error:"channel and text are required"});let t=await _("chat.postMessage",{channel:e.channel,text:e.text,...e.blocks?{blocks:e.blocks}:{}});return JSON.stringify({ok:!0,ts:t.ts,channel:t.channel})}case"slack_reply_to_thread":{if(!e.channel||!e.thread_ts||!e.text)return JSON.stringify({error:"channel, thread_ts, and text are required"});let t=await _("chat.postMessage",{channel:e.channel,thread_ts:e.thread_ts,text:e.text});return JSON.stringify({ok:!0,ts:t.ts})}case"slack_add_reaction":return!e.channel||!e.timestamp||!e.reaction?JSON.stringify({error:"channel, timestamp, and reaction are required"}):(await _("reactions.add",{channel:e.channel,timestamp:e.timestamp,name:e.reaction}),JSON.stringify({ok:!0}));case"slack_get_channel_history":{if(!e.channel)return JSON.stringify({error:"channel is required"});let t=await _("conversations.history",{channel:e.channel,limit:e.limit||20});return JSON.stringify({messages:(t.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_thread_replies":{if(!e.channel||!e.thread_ts)return JSON.stringify({error:"channel and thread_ts are required"});let t=await _("conversations.replies",{channel:e.channel,ts:e.thread_ts});return JSON.stringify({messages:(t.messages||[]).map(s=>({user:s.user,text:s.text,ts:s.ts}))})}case"slack_get_users":{let t=await _("users.list",{limit:100});return JSON.stringify({users:(t.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(!e.user_id)return JSON.stringify({error:"user_id is required"});let t=await _("users.profile.get",{user:e.user_id});return JSON.stringify({profile:t.profile})}case"slack_lookup_user_by_email":{if(!e.email)return JSON.stringify({error:"email is required"});try{let t=await _("users.lookupByEmail",{email:e.email});return JSON.stringify({ok:!0,user:{id:t.user?.id,name:t.user?.real_name||t.user?.name,email:t.user?.profile?.email||e.email}})}catch(t){if(/users_not_found/.test(t.message))return JSON.stringify({ok:!1,reason:"users_not_found"});throw t}}case"slack_list_usergroups":{let t=await _("usergroups.list",{});return JSON.stringify({usergroups:(t.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(!e.usergroup)return JSON.stringify({error:"usergroup id is required"});let t=await _("usergroups.users.list",{usergroup:e.usergroup});return JSON.stringify({users:t.users||[]})}case"slack_search_users":{if(!e.query||typeof e.query!="string")return JSON.stringify({error:"query is required"});let t=e.query.trim().toLowerCase();if(!t)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(e.limit)||5,25)),n=[],a,d=5;for(let i=0;i<d;i+=1){let l={limit:200};a&&(l.cursor=a);let c=await _("users.list",l);for(let o of c.members||[])o.deleted||o.is_bot||n.push(o);if(a=c.response_metadata?.next_cursor,!a)break}let u=[];for(let i of n){let l=(i.real_name||"").toLowerCase(),c=(i.profile?.display_name||"").toLowerCase(),o=(i.name||"").toLowerCase(),p=0;l.includes(t)&&(p+=100-Math.abs(l.length-t.length)),c.includes(t)&&(p+=60-Math.abs(c.length-t.length)),o.includes(t)&&(p+=30-Math.abs(o.length-t.length)),(l===t||c===t)&&(p+=200),p>0&&u.push({id:i.id,name:i.real_name||i.profile?.display_name||i.name,email:i.profile?.email||void 0,_score:p})}return u.sort((i,l)=>l._score-i._score),JSON.stringify({ok:!0,matches:u.slice(0,s).map(({_score:i,...l})=>l),scanned:n.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.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 I}from"fs";import{fileURLToPath as T}from"url";import{dirname as A,resolve as L}from"path";import{resolveIntegrationToken as C}from"@zibby/core/backend-client.js";function E(){if(process.env.MCP_LARK_PATH)return process.env.MCP_LARK_PATH;let r=A(T(import.meta.url)),e=L(r,"..","bin","mcp-lark.mjs");return I(e)?e:null}var R=6e3*1e3,g=null;async function P(){let{appId:r,appSecret:e,host:t}=await C("lark");if(g&&g.appId===r&&g.expiresAt>Date.now())return{token:g.token,host:t};let n=await(await fetch(`${t}/open-apis/auth/v3/tenant_access_token/internal`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({app_id:r,app_secret:e})})).json();if(n.code!==0)throw new Error(`Lark tenant_access_token failed: ${n.msg||n.code}`);return g={token:n.tenant_access_token,expiresAt:Date.now()+R,appId:r},{token:n.tenant_access_token,host:t}}async function f(r,e,t={}){let{token:s,host:n}=await P(),a=`${n}${e}`,d={method:r,headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json; charset=utf-8"}};r!=="GET"&&(d.body=JSON.stringify(t));let i=await(await fetch(a,d)).json();if(i.code!==0)throw new Error(`Lark API ${e} error: ${i.msg||i.code}`);return i.data||{}}function k(r){return JSON.stringify({text:r})}function x(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 h={id:"lark",serverName:"lark",allowedTools:["mcp__lark__*"],requiresIntegration:y.LARK,description:"Lark / Feishu messaging \u2014 send messages and reply in threads.",envKeys:[],promptFragment:`## Lark (connected)
|
|
8
8
|
You can send messages and replies on Lark. Use:
|
|
9
9
|
- lark_send_message: post a message to a chat, user, or DM
|
|
10
10
|
- lark_reply: reply to an existing message (threaded)
|
|
11
11
|
- lark_list_chats: list chats the bot is a member of
|
|
12
12
|
- lark_get_chat_history: fetch recent messages in a chat
|
|
13
13
|
- 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)
|
|
14
|
-
When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=E();if(!r)return null;let e={};for(let t 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[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r],env:e,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,e){try{switch(r){case"lark_send_message":{if(!e.receive_id||!e.text)return JSON.stringify({error:"receive_id and text are required"});let t=
|
|
14
|
+
When responding to an incoming event, prefer lark_reply with the source message_id so the response threads cleanly.`,resolve(){let r=E();if(!r)return null;let e={};for(let t 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[t]&&(e[t]=process.env[t]);return{type:"stdio",command:"node",args:[r],env:e,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,e){try{switch(r){case"lark_send_message":{if(!e.receive_id||!e.text)return JSON.stringify({error:"receive_id and text are required"});let t=x(e.receive_id),s=await f("POST",`/open-apis/im/v1/messages?receive_id_type=${t}`,{receive_id:e.receive_id,msg_type:"text",content:k(e.text)});return JSON.stringify({ok:!0,message_id:s.message_id})}case"lark_reply":{if(!e.message_id||!e.text)return JSON.stringify({error:"message_id and text are required"});let t=await f("POST",`/open-apis/im/v1/messages/${encodeURIComponent(e.message_id)}/reply`,{msg_type:"text",content:k(e.text)});return JSON.stringify({ok:!0,message_id:t.message_id})}case"lark_list_chats":{let t=e.page_size||50,n=((await f("GET",`/open-apis/im/v1/chats?page_size=${t}`)).items||[]).map(a=>({chat_id:a.chat_id,name:a.name,description:a.description,owner_id:a.owner_id,chat_mode:a.chat_mode}));return JSON.stringify({chats:n})}case"lark_get_chat_history":{if(!e.chat_id)return JSON.stringify({error:"chat_id is required"});let t=e.page_size||20,n=((await f("GET",`/open-apis/im/v1/messages?container_id_type=chat&container_id=${encodeURIComponent(e.chat_id)}&page_size=${t}&sort_type=ByCreateTimeDesc`)).items||[]).map(a=>({message_id:a.message_id,sender_id:a.sender?.id,sender_type:a.sender?.sender_type,msg_type:a.msg_type,content:a.body?.content,create_time:a.create_time}));return JSON.stringify({messages:n})}case"lark_lookup_user_by_email":{if(!e.email)return JSON.stringify({error:"email is required"});let s=((await f("POST","/open-apis/contact/v3/users/batch_get_id?user_id_type=open_id",{emails:[e.email]})).user_list||[]).find(n=>n.email===e.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(!e.query||typeof e.query!="string")return JSON.stringify({error:"query is required"});let t=e.query.trim().toLowerCase();if(!t)return JSON.stringify({ok:!0,matches:[]});let s=Math.max(1,Math.min(Number(e.limit)||5,25)),n=200,d=((await f("GET","/open-apis/im/v1/chats?page_size=100")).items||[]).map(c=>c.chat_id),u=new Set,i=[];for(let c of d){if(i.length>=n)break;try{let o=await f("GET",`/open-apis/im/v1/chats/${encodeURIComponent(c)}/members?member_id_type=open_id&page_size=100`);for(let p of o.items||[])if(!(!p.member_id||u.has(p.member_id))&&(u.add(p.member_id),i.push({open_id:p.member_id,name:p.name||""}),i.length>=n))break}catch(o){console.warn(`[lark] member scan failed for ${c}: ${o.message}`)}}let l=[];for(let c of i){let o=(c.name||"").toLowerCase();if(!o)continue;let p=0;o.includes(t)&&(p+=100-Math.abs(o.length-t.length)),o===t&&(p+=200),p>0&&l.push({open_id:c.open_id,name:c.name,_score:p})}return l.sort((c,o)=>o._score-c._score),JSON.stringify({ok:!0,matches:l.slice(0,s).map(({_score:c,...o})=>o),scanned:i.length})}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(t){return JSON.stringify({error:t.message})}}};var V={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:[...m.envKeys||[],...h.envKeys||[]],get serverName(){if(process.env.SLACK_CHANNEL)return m.serverName;if(process.env.LARK_RECEIVE_ID)return h.serverName},get allowedTools(){return process.env.SLACK_CHANNEL?m.allowedTools||[]:process.env.LARK_RECEIVE_ID?h.allowedTools||[]:[]},promptFragment:`## Chat notifications (Slack OR Lark \u2014 at least one connected)
|
|
15
15
|
You can post chat messages via either:
|
|
16
16
|
- slack_post_message (channel, text) \u2014 Slack, when SLACK_CHANNEL is set
|
|
17
17
|
- lark_send_message (receive_id, text) \u2014 Lark, when LARK_RECEIVE_ID is set
|
package/dist/github.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{resolveIntegrationToken as
|
|
1
|
+
import{resolveIntegrationToken as $}from"@zibby/core/backend-client.js";var R=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"}),N=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"}});async function l(f,a={}){let{token:t}=await $("github"),i=f.startsWith("https://")?f:`https://api.github.com${f}`,r={Authorization:`Bearer ${t}`,Accept:a.accept||"application/vnd.github.v3+json","User-Agent":"Zibby-App",...a.body?{"Content-Type":"application/json"}:{}},e=await fetch(i,{method:a.method||"GET",headers:r,body:a.body?JSON.stringify(a.body):void 0});if(!e.ok){let s=await e.text().catch(()=>"");throw new Error(`GitHub API ${e.status}: ${s.slice(0,300)}`)}return a.raw?e.text():e.json()}var P={id:"github",serverName:"github",allowedTools:["mcp__github__*"],requiresIntegration:R.GITHUB,envKeys:["GITHUB_TOKEN"],description:"GitHub \u2014 issues, PRs, commits, code search, file reading",promptFragment:`## GitHub (connected)
|
|
2
2
|
You have access to the user's GitHub repositories. Available tools:
|
|
3
3
|
|
|
4
4
|
### Discovery
|
|
@@ -20,6 +20,7 @@ You have access to the user's GitHub repositories. Available tools:
|
|
|
20
20
|
- github_get_pr_diff: Get PR diff
|
|
21
21
|
- github_list_pr_files: List PR changed files
|
|
22
22
|
- github_list_pr_comments: Get PR comments
|
|
23
|
+
- github_create_review: Post a review on a PR \u2014 a summary body plus optional inline comments on specific file/line positions, with an event (COMMENT, APPROVE, or REQUEST_CHANGES)
|
|
23
24
|
- github_create_issue: Create new issue
|
|
24
25
|
- github_list_issues: List issues in a repo (filter by state/labels/since cursor) \u2014 excludes PRs
|
|
25
26
|
- github_get_issue: Get a single issue's full detail (title, body, state, labels, assignee, url)
|
|
@@ -35,6 +36,6 @@ When user says "check out repo-name" or "clone repo-name":
|
|
|
35
36
|
3. STOP. Do not offer to inspect files or ask what to do next.
|
|
36
37
|
|
|
37
38
|
When user just wants to "look at" or "read" files (not clone):
|
|
38
|
-
- Use github_get_file to read individual files via API`,resolve(){let
|
|
39
|
+
- Use github_get_file to read individual files via API`,resolve(){let f={};for(let a of this.envKeys)process.env[a]&&(f[a]=process.env[a]);return{command:"npx",args:["-y","@modelcontextprotocol/server-github@latest"],env:f}},async handleToolCall(f,a){try{switch(f){case"github_search_issues":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=await l(`/search/issues?q=${encodeURIComponent(t)}&per_page=${a.limit||20}`),r=(i.items||[]).map(e=>({number:e.number,title:e.title,state:e.state,repo:e.repository_url?.split("/").slice(-2).join("/"),url:e.html_url,user:e.user?.login,isPR:!!e.pull_request,labels:(e.labels||[]).map(s=>s.name),createdAt:e.created_at}));return JSON.stringify({total:i.total_count,items:r})}case"github_search_code":{let t=a.query;if(!t)return JSON.stringify({error:"query is required"});let i=a.repo?`+repo:${a.repo}`:"",r=a.language?`+language:${a.language}`:"",e=await l(`/search/code?q=${encodeURIComponent(t)}${i}${r}&per_page=${a.limit||15}`),s=(e.items||[]).map(n=>({name:n.name,path:n.path,repo:n.repository?.full_name,url:n.html_url,score:n.score}));return JSON.stringify({total:e.total_count,items:s})}case"github_get_pr":{let{owner:t,repo:i,number:r}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${r}`);return JSON.stringify({number:e.number,title:e.title,state:e.state,merged:e.merged,body:e.body?.slice(0,5e3),user:e.user?.login,branch:e.head?.ref,base:e.base?.ref,changedFiles:e.changed_files,additions:e.additions,deletions:e.deletions,createdAt:e.created_at,mergedAt:e.merged_at,url:e.html_url,labels:(e.labels||[]).map(s=>s.name)})}case"github_get_pr_diff":{let{owner:t,repo:i,number:r}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${r}`,{accept:"application/vnd.github.v3.diff",raw:!0}),s=e.length>15e3;return JSON.stringify({number:r,diff:s?e.slice(0,15e3):e,truncated:s,totalLength:e.length})}case"github_list_pr_files":{let{owner:t,repo:i,number:r}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${r}/files?per_page=100`);return JSON.stringify({total:e.length,files:e.map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)}))})}case"github_list_pr_comments":{let{owner:t,repo:i,number:r}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/pulls/${r}/comments?per_page=50`),s=await l(`/repos/${t}/${i}/issues/${r}/comments?per_page=50`),n=[...e.map(o=>({type:"review",user:o.user?.login,body:o.body?.slice(0,1e3),path:o.path,line:o.line,createdAt:o.created_at})),...s.map(o=>({type:"issue",user:o.user?.login,body:o.body?.slice(0,1e3),createdAt:o.created_at}))].sort((o,p)=>new Date(o.createdAt)-new Date(p.createdAt));return JSON.stringify({total:n.length,comments:n})}case"github_create_review":{let{owner:t,repo:i,number:r,body:e,event:s,comments:n}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let o=(s||"COMMENT").toUpperCase();if(!["COMMENT","APPROVE","REQUEST_CHANGES"].includes(o))return JSON.stringify({error:`event must be COMMENT, APPROVE, or REQUEST_CHANGES (got ${s})`});let p=Array.isArray(n)?n.filter(m=>m&&m.path&&m.body&&(m.line!=null||m.position!=null)).map(m=>{let y={path:m.path,body:String(m.body)};return m.line!=null?(y.line=Number(m.line),y.side=m.side==="LEFT"?"LEFT":"RIGHT"):y.position=Number(m.position),y}):[];if(o!=="APPROVE"&&!e&&p.length===0)return JSON.stringify({error:"a COMMENT or REQUEST_CHANGES review needs a body and/or inline comments"});let d={event:o};e&&(d.body=String(e)),p.length>0&&(d.comments=p);let c=await l(`/repos/${t}/${i}/pulls/${r}/reviews`,{method:"POST",body:d});return JSON.stringify({ok:!0,id:c.id,state:c.state,event:o,commentsPosted:p.length,url:c.html_url})}case"github_list_commits":{let{owner:t,repo:i,branch:r,path:e,limit:s}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let n=`/repos/${t}/${i}/commits?per_page=${s||20}`;r&&(n+=`&sha=${encodeURIComponent(r)}`),e&&(n+=`&path=${encodeURIComponent(e)}`);let o=await l(n);return JSON.stringify({total:o.length,commits:o.map(p=>({sha:p.sha?.slice(0,8),fullSha:p.sha,message:p.commit?.message?.slice(0,300),author:p.commit?.author?.name,date:p.commit?.author?.date,url:p.html_url}))})}case"github_get_commit":{let{owner:t,repo:i,sha:r}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and sha are required"});let e=await l(`/repos/${t}/${i}/commits/${r}`);return JSON.stringify({sha:e.sha?.slice(0,8),message:e.commit?.message,author:e.commit?.author?.name,date:e.commit?.author?.date,stats:e.stats,files:(e.files||[]).map(s=>({filename:s.filename,status:s.status,additions:s.additions,deletions:s.deletions,patch:s.patch?.slice(0,3e3)}))})}case"github_get_file":{let{owner:t,repo:i,path:r,ref:e}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and path are required"});let s=`/repos/${t}/${i}/contents/${encodeURIComponent(r)}`;e&&(s+=`?ref=${encodeURIComponent(e)}`);let n=await l(s);if(n.type!=="file")return Array.isArray(n)?JSON.stringify({type:"directory",path:r,entries:n.map(d=>({name:d.name,type:d.type,size:d.size,path:d.path}))}):JSON.stringify({error:`Not a file: ${n.type}`});let o=Buffer.from(n.content||"","base64").toString("utf-8"),p=o.length>2e4;return JSON.stringify({path:n.path,size:n.size,sha:n.sha?.slice(0,8),content:p?o.slice(0,2e4):o,truncated:p})}case"github_get_user":try{let t=await l("/installation/repositories?per_page=1");if(t.repositories&&t.repositories.length>0){let i=t.repositories[0],r=i.owner.login,e=i.owner.type,s=e==="Organization"?`/orgs/${r}`:`/users/${r}`,n=await l(s);return JSON.stringify({login:n.login,name:n.name||n.login,avatar:n.avatar_url,bio:n.bio||n.description,type:e,isOrg:e==="Organization",publicRepos:n.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(t){return JSON.stringify({error:`GitHub App cannot access /user endpoint. Use github_list_repos instead. (${t.message})`})}case"github_list_orgs":try{let i=(await l("/installation/repositories?per_page=100")).repositories||[],r=new Map;for(let s of i)s.owner.type==="Organization"&&(r.has(s.owner.login)||r.set(s.owner.login,{login:s.owner.login,description:null,url:s.owner.url}));let e=Array.from(r.values());return JSON.stringify({count:e.length,orgs:e,message:"Extracted from accessible repositories (GitHub Apps cannot access /user/orgs directly)"})}catch(t){return JSON.stringify({error:`GitHub App cannot list orgs via /user/orgs. Error: ${t.message}`})}case"github_clone":{let u=function(_){let w=_.replace(/^~(?=$|\/|\\)/,y);return n(w)},{owner:t,repo:i,destination:r}=a;if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let{execSync:e}=await import("child_process"),{join:s,resolve:n}=await import("path"),{existsSync:o,mkdirSync:p}=await import("fs"),{homedir:d,platform:c}=await import("os"),{token:m}=await $("github"),y=d(),b=r?u(r):s(y,"zibby-repos"),h=s(b,i);if(p(b,{recursive:!0}),o(h))return JSON.stringify({error:`Directory ${h} already exists. Remove it first or use a different destination.`,existingPath:h});try{let _=`https://x-access-token:${m}@github.com/${t}/${i}.git`;e(`git clone ${_} "${h}"`,{stdio:"pipe"});let w=c()==="win32",g;return w?g=e(`dir "${h}"`,{encoding:"utf-8",shell:"cmd.exe"}):g=e(`ls -la "${h}"`,{encoding:"utf-8"}),JSON.stringify({success:!0,path:h,message:`Cloned ${t}/${i} to ${h}`,contents:g.split(`
|
|
39
40
|
`).slice(0,30).join(`
|
|
40
|
-
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(f){return JSON.stringify({error:`Clone failed: ${f.message}`})}}case"github_search_repos":{let{query:t,limit:i}=a;if(!t)return JSON.stringify({error:"query is required"});let r=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(r);if(e.error)return JSON.stringify(e);let s=t.toLowerCase(),n=e.repos.filter(o=>o.name.toLowerCase().includes(s)||o.fullName.toLowerCase().includes(s)||o.description&&o.description.toLowerCase().includes(s));return JSON.stringify({query:t,count:n.length,repos:n.slice(0,i||20)})}case"github_list_repos":{let{owner:t,type:i,sort:r,direction:e,limit:s}=a,n=100,o=s||200,u=[];if(!t){let p=1,b=!0;for(;b&&u.length<o;){let m=`/installation/repositories?per_page=${n}&page=${p}`,$=(await c(m)).repositories||[];if($.length===0)break;u=u.concat($),b=$.length===n,p++}let g=u.slice(0,o).map(m=>({name:m.name,fullName:m.full_name,private:m.private,description:m.description,language:m.language,defaultBranch:m.default_branch,updatedAt:m.updated_at,stars:m.stargazers_count,url:m.html_url})),f=g.filter(m=>m.private).length,w=g.filter(m=>!m.private).length;return JSON.stringify({count:g.length,repos:g,privateCount:f,publicCount:w,message:`Found ${f} private and ${w} public repos`})}let d=await c(`/orgs/${t}`).then(()=>!0).catch(()=>!1),l=1,_=!0;for(;_&&u.length<o;){let p;d?p=`/orgs/${t}/repos?per_page=${n}&page=${l}&type=${i||"all"}&sort=${r||"updated"}&direction=${e||"desc"}`:p=`/users/${t}/repos?per_page=${n}&page=${l}&type=${i||"all"}&sort=${r||"updated"}&direction=${e||"desc"}`;let b=await c(p),g=Array.isArray(b)?b:[];if(g.length===0)break;u=u.concat(g),_=g.length===n,l++}let y=u.slice(0,o).map(p=>({name:p.name,fullName:p.full_name,private:p.private,description:p.description,language:p.language,defaultBranch:p.default_branch,updatedAt:p.updated_at,stars:p.stargazers_count,url:p.html_url}));return JSON.stringify({count:y.length,repos:y})}case"github_create_issue":{let{owner:t,repo:i,title:r,body:e}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and title are required"});let s=await c(`/repos/${t}/${i}/issues`,{method:"POST",body:{title:r,body:e||""}});return JSON.stringify({number:s.number,url:s.html_url,title:s.title})}case"github_list_issues":{let{owner:t,repo:i,state:r,labels:e,since:s,assignee:n,sort:o,direction:u,limit:d}=a||{};if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let l=new URLSearchParams;l.set("state",r||"open"),l.set("per_page",String(d||30)),l.set("sort",o||"updated"),l.set("direction",u||"desc"),e&&l.set("labels",Array.isArray(e)?e.join(","):e),s&&l.set("since",s),n&&l.set("assignee",n);let _=await c(`/repos/${t}/${i}/issues?${l.toString()}`),y=(Array.isArray(_)?_:[]).filter(p=>!p.pull_request).map(p=>({number:p.number,title:p.title,state:p.state,labels:(p.labels||[]).map(b=>typeof b=="string"?b:b.name),assignee:p.assignee?.login||null,assignees:(p.assignees||[]).map(b=>b.login),user:p.user?.login,comments:p.comments,url:p.html_url,createdAt:p.created_at,updatedAt:p.updated_at}));return JSON.stringify({count:y.length,issues:y})}case"github_get_issue":{let{owner:t,repo:i,number:r}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await c(`/repos/${t}/${i}/issues/${r}`);return e.pull_request?JSON.stringify({error:`#${r} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(s=>typeof s=="string"?s:s.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(s=>s.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:i,number:r,limit:e}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let s=await c(`/repos/${t}/${i}/issues/${r}/comments?per_page=${e||100}`),n=(Array.isArray(s)?s:[]).map(o=>({id:o.id,user:o.user?.login,body:o.body||"",createdAt:o.created_at,updatedAt:o.updated_at,url:o.html_url}));return JSON.stringify({count:n.length,comments:n})}case"github_add_issue_comment":{let{owner:t,repo:i,number:r,body:e}=a||{};if(!t||!i||!r||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let s=await c(`/repos/${t}/${i}/issues/${r}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:s.id,url:s.html_url})}case"github_close_issue":{let{owner:t,repo:i,number:r,stateReason:e}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let s={state:"closed"};e&&(s.state_reason=e);let n=await c(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:s});return JSON.stringify({ok:!0,number:n.number,state:n.state,stateReason:n.state_reason||null,url:n.html_url})}case"github_reopen_issue":{let{owner:t,repo:i,number:r}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await c(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:i,number:r,labels:e,mode:s}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let n=Array.isArray(e)?e:e?[e]:[];if(!n.length)return JSON.stringify({error:"labels (string or array) is required"});let o=s||"add";if(o==="set"){let d=await c(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:{labels:n}});return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}if(o==="remove"){for(let l of n)await c(`/repos/${t}/${i}/issues/${r}/labels/${encodeURIComponent(l)}`,{method:"DELETE"});let d=await c(`/repos/${t}/${i}/issues/${r}`);return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(l=>typeof l=="string"?l:l.name)})}let u=await c(`/repos/${t}/${i}/issues/${r}/labels`,{method:"POST",body:{labels:n}});return JSON.stringify({ok:!0,number:r,labels:(Array.isArray(u)?u:[]).map(d=>typeof d=="string"?d:d.name)})}default:return JSON.stringify({error:`Unknown tool: ${h}`})}}catch(t){return JSON.stringify({error:t.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"]}}]};export{v as githubSkill};
|
|
41
|
+
`),instructions:"IMPORTANT: Show the contents field to the user - it contains the directory listing."})}catch(_){return JSON.stringify({error:`Clone failed: ${_.message}`})}}case"github_search_repos":{let{query:t,limit:i}=a;if(!t)return JSON.stringify({error:"query is required"});let r=await this.handleToolCall("github_list_repos",{limit:200},{}),e=JSON.parse(r);if(e.error)return JSON.stringify(e);let s=t.toLowerCase(),n=e.repos.filter(o=>o.name.toLowerCase().includes(s)||o.fullName.toLowerCase().includes(s)||o.description&&o.description.toLowerCase().includes(s));return JSON.stringify({query:t,count:n.length,repos:n.slice(0,i||20)})}case"github_list_repos":{let{owner:t,type:i,sort:r,direction:e,limit:s}=a,n=100,o=s||200,p=[];if(!t){let u=1,b=!0;for(;b&&p.length<o;){let g=`/installation/repositories?per_page=${n}&page=${u}`,S=(await l(g)).repositories||[];if(S.length===0)break;p=p.concat(S),b=S.length===n,u++}let h=p.slice(0,o).map(g=>({name:g.name,fullName:g.full_name,private:g.private,description:g.description,language:g.language,defaultBranch:g.default_branch,updatedAt:g.updated_at,stars:g.stargazers_count,url:g.html_url})),_=h.filter(g=>g.private).length,w=h.filter(g=>!g.private).length;return JSON.stringify({count:h.length,repos:h,privateCount:_,publicCount:w,message:`Found ${_} private and ${w} public repos`})}let d=await l(`/orgs/${t}`).then(()=>!0).catch(()=>!1),c=1,m=!0;for(;m&&p.length<o;){let u;d?u=`/orgs/${t}/repos?per_page=${n}&page=${c}&type=${i||"all"}&sort=${r||"updated"}&direction=${e||"desc"}`:u=`/users/${t}/repos?per_page=${n}&page=${c}&type=${i||"all"}&sort=${r||"updated"}&direction=${e||"desc"}`;let b=await l(u),h=Array.isArray(b)?b:[];if(h.length===0)break;p=p.concat(h),m=h.length===n,c++}let y=p.slice(0,o).map(u=>({name:u.name,fullName:u.full_name,private:u.private,description:u.description,language:u.language,defaultBranch:u.default_branch,updatedAt:u.updated_at,stars:u.stargazers_count,url:u.html_url}));return JSON.stringify({count:y.length,repos:y})}case"github_create_issue":{let{owner:t,repo:i,title:r,body:e}=a;if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and title are required"});let s=await l(`/repos/${t}/${i}/issues`,{method:"POST",body:{title:r,body:e||""}});return JSON.stringify({number:s.number,url:s.html_url,title:s.title})}case"github_list_issues":{let{owner:t,repo:i,state:r,labels:e,since:s,assignee:n,sort:o,direction:p,limit:d}=a||{};if(!t||!i)return JSON.stringify({error:"owner and repo are required"});let c=new URLSearchParams;c.set("state",r||"open"),c.set("per_page",String(d||30)),c.set("sort",o||"updated"),c.set("direction",p||"desc"),e&&c.set("labels",Array.isArray(e)?e.join(","):e),s&&c.set("since",s),n&&c.set("assignee",n);let m=await l(`/repos/${t}/${i}/issues?${c.toString()}`),y=(Array.isArray(m)?m:[]).filter(u=>!u.pull_request).map(u=>({number:u.number,title:u.title,state:u.state,labels:(u.labels||[]).map(b=>typeof b=="string"?b:b.name),assignee:u.assignee?.login||null,assignees:(u.assignees||[]).map(b=>b.login),user:u.user?.login,comments:u.comments,url:u.html_url,createdAt:u.created_at,updatedAt:u.updated_at}));return JSON.stringify({count:y.length,issues:y})}case"github_get_issue":{let{owner:t,repo:i,number:r}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${r}`);return e.pull_request?JSON.stringify({error:`#${r} is a pull request, not an issue`,isPR:!0}):JSON.stringify({number:e.number,title:e.title,body:e.body||"",state:e.state,stateReason:e.state_reason||null,labels:(e.labels||[]).map(s=>typeof s=="string"?s:s.name),assignee:e.assignee?.login||null,assignees:(e.assignees||[]).map(s=>s.login),user:e.user?.login,milestone:e.milestone?.title||null,comments:e.comments,url:e.html_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"github_get_issue_comments":{let{owner:t,repo:i,number:r,limit:e}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let s=await l(`/repos/${t}/${i}/issues/${r}/comments?per_page=${e||100}`),n=(Array.isArray(s)?s:[]).map(o=>({id:o.id,user:o.user?.login,body:o.body||"",createdAt:o.created_at,updatedAt:o.updated_at,url:o.html_url}));return JSON.stringify({count:n.length,comments:n})}case"github_add_issue_comment":{let{owner:t,repo:i,number:r,body:e}=a||{};if(!t||!i||!r||!e)return JSON.stringify({error:"owner, repo, number, and body are required"});let s=await l(`/repos/${t}/${i}/issues/${r}/comments`,{method:"POST",body:{body:e}});return JSON.stringify({ok:!0,id:s.id,url:s.html_url})}case"github_close_issue":{let{owner:t,repo:i,number:r,stateReason:e}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let s={state:"closed"};e&&(s.state_reason=e);let n=await l(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:s});return JSON.stringify({ok:!0,number:n.number,state:n.state,stateReason:n.state_reason||null,url:n.html_url})}case"github_reopen_issue":{let{owner:t,repo:i,number:r}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let e=await l(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:{state:"open"}});return JSON.stringify({ok:!0,number:e.number,state:e.state,url:e.html_url})}case"github_label_issue":{let{owner:t,repo:i,number:r,labels:e,mode:s}=a||{};if(!t||!i||!r)return JSON.stringify({error:"owner, repo, and number are required"});let n=Array.isArray(e)?e:e?[e]:[];if(!n.length)return JSON.stringify({error:"labels (string or array) is required"});let o=s||"add";if(o==="set"){let d=await l(`/repos/${t}/${i}/issues/${r}`,{method:"PATCH",body:{labels:n}});return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(c=>typeof c=="string"?c:c.name)})}if(o==="remove"){for(let c of n)await l(`/repos/${t}/${i}/issues/${r}/labels/${encodeURIComponent(c)}`,{method:"DELETE"});let d=await l(`/repos/${t}/${i}/issues/${r}`);return JSON.stringify({ok:!0,number:d.number,labels:(d.labels||[]).map(c=>typeof c=="string"?c:c.name)})}let p=await l(`/repos/${t}/${i}/issues/${r}/labels`,{method:"POST",body:{labels:n}});return JSON.stringify({ok:!0,number:r,labels:(Array.isArray(p)?p:[]).map(d=>typeof d=="string"?d:d.name)})}default:return JSON.stringify({error:`Unknown tool: ${f}`})}}catch(t){return JSON.stringify({error:t.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_create_review",description:"Post a review on a pull request: a summary body plus optional inline comments anchored to file/line, with an event (COMMENT, APPROVE, or REQUEST_CHANGES). Use this to deliver a code review back to the PR.",input_schema:{type:"object",properties:{owner:{type:"string",description:"Repository owner"},repo:{type:"string",description:"Repository name"},number:{type:"number",description:"PR number"},body:{type:"string",description:"The review summary (markdown). Shown as the top-level review comment."},event:{type:"string",enum:["COMMENT","APPROVE","REQUEST_CHANGES"],description:"Review verdict. Default COMMENT (no approval state). Use REQUEST_CHANGES for blocking issues."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line.",items:{type:"object",properties:{path:{type:"string",description:"File path as it appears in the diff"},line:{type:"number",description:"Line number in the file's NEW version (the right side of the diff)"},side:{type:"string",enum:["LEFT","RIGHT"],description:"RIGHT (new) or LEFT (old). Default RIGHT."},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","line","body"]}}},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"]}}]};export{P as githubSkill};
|
package/dist/gitlab.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var b=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"}),I=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"}});function j(){let d=process.env.GITLAB_API_URL;if(d)return d.replace(/\/+$/,"");let s=(process.env.GITLAB_URL||process.env.GITLAB_INSTANCE_URL||"https://gitlab.com").trim().replace(/\/+$/,"");return/\/api\/v\d+$/.test(s)?s:`${s}/api/v4`}function A(){if(process.env.GITLAB_OAUTH_TOKEN)return{Authorization:`Bearer ${process.env.GITLAB_OAUTH_TOKEN}`};let d=process.env.GITLAB_TOKEN;if(!d)throw new Error("GitLab is not connected: set GITLAB_TOKEN (personal/project access token, api scope) or GITLAB_OAUTH_TOKEN.");return{"PRIVATE-TOKEN":d}}async function u(d,s={}){let r=/^https?:\/\//.test(d)?d:`${j()}${d}`,i={Accept:"application/json","User-Agent":"Zibby-App",...A(),...s.body?{"Content-Type":"application/json"}:{}},e=await fetch(r,{method:s.method||"GET",headers:i,body:s.body?JSON.stringify(s.body):void 0});if(!e.ok){let n=await e.text().catch(()=>"");throw new Error(`GitLab API ${e.status}: ${n.slice(0,300)}`)}return s.raw?e.text():e.json()}function h(d){let s=String(d);return/^\d+$/.test(s)?s:encodeURIComponent(s)}var O={id:"gitlab",serverName:"gitlab",allowedTools:["mcp__gitlab__*"],requiresIntegration:b.GITLAB,envKeys:["GITLAB_TOKEN","GITLAB_OAUTH_TOKEN","GITLAB_INSTANCE_URL","GITLAB_API_URL"],description:"GitLab \u2014 merge requests, diffs, MR reviews/discussions, issues",promptFragment:`## GitLab (connected)
|
|
2
|
+
You have access to the user's GitLab projects via the REST API (cloud gitlab.com OR self-hosted). A "merge request" (MR) is GitLab's pull request. An MR is addressed by a PROJECT (numeric id OR full path like "group/repo") and an \`iid\` (the per-project MR number shown in the URL). For projects, prefer the full path form ("group/subgroup/repo") \u2014 it's what users have. Available tools:
|
|
3
|
+
|
|
4
|
+
### Merge requests
|
|
5
|
+
- gitlab_get_mr: Get an MR's details (title, description, author, source/target branch, state, web url, diff_refs)
|
|
6
|
+
- gitlab_get_mr_changes: Get the MR's changed files with per-file diffs \u2014 THIS is the code to review
|
|
7
|
+
- gitlab_list_mrs: List a project's merge requests (filter by state: opened|closed|merged|all)
|
|
8
|
+
- gitlab_list_mr_notes: Get the discussion/notes thread on an MR
|
|
9
|
+
- gitlab_post_mr_note: Post a general (non-inline) comment on an MR
|
|
10
|
+
- gitlab_post_mr_discussion: Post an INLINE review comment anchored to a file + line in the MR diff. Needs diff_refs (pass them from gitlab_get_mr / gitlab_get_mr_changes, or omit and the tool fetches them). Provide newLine for added/changed lines (or oldLine for removed/context lines).
|
|
11
|
+
|
|
12
|
+
### Issues
|
|
13
|
+
- gitlab_get_issue: Get a single issue (by project + issue iid) \u2014 title, description, state, labels, assignee, web url
|
|
14
|
+
- gitlab_list_issues: List a project's issues (filter by state: opened|closed|all, labels, updatedAfter cursor)
|
|
15
|
+
- gitlab_add_issue_comment: Add a comment to an issue (also the way to record an MR link on a ticket)
|
|
16
|
+
|
|
17
|
+
### Notes
|
|
18
|
+
- A code-review flow is: gitlab_get_mr (context + diff_refs) \u2192 gitlab_get_mr_changes (the diff) \u2192 gitlab_post_mr_discussion per inline finding \u2192 gitlab_post_mr_note for the summary.
|
|
19
|
+
- If an inline position is rejected by GitLab (bad line anchor), fall back to gitlab_post_mr_note with the file/line in the text.`,resolve(){let d={};for(let s of this.envKeys)process.env[s]&&(d[s]=process.env[s]);return{command:null,args:[],env:d,description:this.description}},async handleToolCall(d,s){try{switch(d){case"gitlab_get_mr":{let{projectId:r,iid:i}=s||{};if(!r||!i)return JSON.stringify({error:"projectId and iid are required"});let e=await u(`/projects/${h(r)}/merge_requests/${i}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,author:e.author?.username,sourceBranch:e.source_branch,targetBranch:e.target_branch,draft:e.draft??e.work_in_progress??!1,mergeStatus:e.merge_status,changesCount:e.changes_count,labels:Array.isArray(e.labels)?e.labels:[],webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,mergedAt:e.merged_at,diffRefs:e.diff_refs||null})}case"gitlab_get_mr_changes":{let{projectId:r,iid:i}=s||{};if(!r||!i)return JSON.stringify({error:"projectId and iid are required"});let e=await u(`/projects/${h(r)}/merge_requests/${i}/changes`),n=Array.isArray(e.changes)?e.changes:[];return JSON.stringify({iid:e.iid,total:n.length,diffRefs:e.diff_refs||null,files:n.map(a=>({oldPath:a.old_path,newPath:a.new_path,newFile:!!a.new_file,deletedFile:!!a.deleted_file,renamedFile:!!a.renamed_file,diff:typeof a.diff=="string"?a.diff.slice(0,3e3):""}))})}case"gitlab_list_mrs":{let{projectId:r,state:i,targetBranch:e,sourceBranch:n,authorUsername:a,labels:c,search:l,sort:f,orderBy:p,limit:m}=s||{};if(!r)return JSON.stringify({error:"projectId is required"});let t=new URLSearchParams;t.set("state",i||"opened"),t.set("per_page",String(m||20)),t.set("order_by",p||"updated_at"),t.set("sort",f||"desc"),e&&t.set("target_branch",e),n&&t.set("source_branch",n),a&&t.set("author_username",a),c&&t.set("labels",Array.isArray(c)?c.join(","):c),l&&t.set("search",l);let g=await u(`/projects/${h(r)}/merge_requests?${t.toString()}`),_=(Array.isArray(g)?g:[]).map(o=>({iid:o.iid,title:o.title,state:o.state,author:o.author?.username,sourceBranch:o.source_branch,targetBranch:o.target_branch,draft:o.draft??o.work_in_progress??!1,labels:Array.isArray(o.labels)?o.labels:[],webUrl:o.web_url,createdAt:o.created_at,updatedAt:o.updated_at}));return JSON.stringify({count:_.length,mergeRequests:_})}case"gitlab_list_mr_notes":{let{projectId:r,iid:i,limit:e}=s||{};if(!r||!i)return JSON.stringify({error:"projectId and iid are required"});let n=await u(`/projects/${h(r)}/merge_requests/${i}/notes?per_page=${e||50}&sort=asc&order_by=created_at`);return JSON.stringify({total:Array.isArray(n)?n.length:0,notes:(Array.isArray(n)?n:[]).map(a=>({id:a.id,author:a.author?.username,body:(a.body||"").slice(0,1e3),system:!!a.system,createdAt:a.created_at}))})}case"gitlab_post_mr_note":{let{projectId:r,iid:i,body:e}=s||{};if(!r||!i||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await u(`/projects/${h(r)}/merge_requests/${i}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}case"gitlab_post_mr_discussion":{let{projectId:r,iid:i,path:e,oldPath:n,newLine:a,oldLine:c,body:l}=s||{};if(!r||!i||!e||!l)return JSON.stringify({error:"projectId, iid, path, and body are required"});if(a==null&&c==null)return JSON.stringify({error:"newLine (added/changed line) or oldLine (removed/context line) is required to anchor an inline comment"});let f=h(r),p=s.diffRefs||null;if(p||(p=(await u(`/projects/${f}/merge_requests/${i}`)).diff_refs||null),!p||!p.head_sha)return JSON.stringify({error:"could not resolve diff_refs for this MR \u2014 cannot anchor an inline comment. Use gitlab_post_mr_note instead."});let m={base_sha:p.base_sha,start_sha:p.start_sha,head_sha:p.head_sha,position_type:"text",new_path:e,old_path:n||e};a!=null&&(m.new_line=Number(a)),c!=null&&(m.old_line=Number(c));try{let t=await u(`/projects/${f}/merge_requests/${i}/discussions`,{method:"POST",body:{body:String(l),position:m}});return JSON.stringify({ok:!0,discussionId:t.id})}catch(t){return JSON.stringify({ok:!1,error:`inline anchor rejected (${t.message}). The line must be part of the MR diff. Fall back to gitlab_post_mr_note with the file/line in the text.`})}}case"gitlab_create_mr_review":{let{projectId:r,iid:i,body:e,comments:n}=s||{};if(!r||!i)return JSON.stringify({error:"projectId and iid are required"});let a=h(r),c=Array.isArray(n)?n.filter(t=>t&&t.path&&t.body&&(t.newLine!=null||t.oldLine!=null)):[];if(!e&&c.length===0)return JSON.stringify({error:"a review needs a body and/or inline comments"});let l=s.diffRefs||null;c.length>0&&!l&&(l=(await u(`/projects/${a}/merge_requests/${i}`)).diff_refs||null);let f=!1;e&&(await u(`/projects/${a}/merge_requests/${i}/notes`,{method:"POST",body:{body:String(e)}}),f=!0);let p=0,m=[];if(c.length>0&&l)for(let t of c){let g={base_sha:l.base_sha,start_sha:l.start_sha,head_sha:l.head_sha,position_type:"text",new_path:t.path,old_path:t.oldPath||t.path};t.newLine!=null&&(g.new_line=Number(t.newLine)),t.oldLine!=null&&(g.old_line=Number(t.oldLine));try{await u(`/projects/${a}/merge_requests/${i}/discussions`,{method:"POST",body:{body:String(t.body),position:g}}),p+=1}catch(_){m.push(`${t.path}:${t.newLine??t.oldLine} \u2014 ${_.message}`)}}else c.length>0&&!l&&m.push("no diff_refs available \u2014 inline comments skipped (pass diffRefs from gitlab_get_mr)");return JSON.stringify({ok:!0,notePosted:f,inlinePosted:p,inlineErrors:m.length?m:void 0})}case"gitlab_list_issues":{let{projectId:r,state:i,labels:e,assigneeUsername:n,authorUsername:a,updatedAfter:c,search:l,sort:f,orderBy:p,limit:m}=s||{};if(!r)return JSON.stringify({error:"projectId is required"});let t=new URLSearchParams;t.set("state",i||"opened"),t.set("per_page",String(m||30)),t.set("order_by",p||"updated_at"),t.set("sort",f||"desc"),e&&t.set("labels",Array.isArray(e)?e.join(","):e),n&&t.set("assignee_username",n),a&&t.set("author_username",a),c&&t.set("updated_after",c),l&&t.set("search",l);let g=await u(`/projects/${h(r)}/issues?${t.toString()}`),_=(Array.isArray(g)?g:[]).map(o=>({iid:o.iid,title:o.title,state:o.state,labels:Array.isArray(o.labels)?o.labels:[],author:o.author?.username,assignees:(o.assignees||[]).map(y=>y.username),userNotesCount:o.user_notes_count,webUrl:o.web_url,createdAt:o.created_at,updatedAt:o.updated_at}));return JSON.stringify({count:_.length,issues:_})}case"gitlab_get_issue":{let{projectId:r,iid:i}=s||{};if(!r||!i)return JSON.stringify({error:"projectId and iid are required"});let e=await u(`/projects/${h(r)}/issues/${i}`);return JSON.stringify({iid:e.iid,projectId:e.project_id,title:e.title,description:(e.description||"").slice(0,5e3),state:e.state,labels:Array.isArray(e.labels)?e.labels:[],author:e.author?.username,assignees:(e.assignees||[]).map(n=>n.username),milestone:e.milestone?.title||null,webUrl:e.web_url,createdAt:e.created_at,updatedAt:e.updated_at,closedAt:e.closed_at})}case"gitlab_add_issue_comment":{let{projectId:r,iid:i,body:e}=s||{};if(!r||!i||!e)return JSON.stringify({error:"projectId, iid, and body are required"});let n=await u(`/projects/${h(r)}/issues/${i}/notes`,{method:"POST",body:{body:String(e)}});return JSON.stringify({ok:!0,id:n.id,createdAt:n.created_at})}default:return JSON.stringify({error:`Unknown tool: ${d}`})}}catch(r){return JSON.stringify({error:r.message})}},tools:[{name:"gitlab_get_mr",description:"Get a GitLab merge request \u2014 title, description, branches, state, author, web url, and diff_refs (needed to anchor inline review comments).",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid (the per-project MR number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_get_mr_changes",description:"Get the changed files of a GitLab merge request with per-file diffs \u2014 the actual code changes to review. Also returns diff_refs for inline comments.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},iid:{type:"number",description:"Merge request iid"}},required:["projectId","iid"]}},{name:"gitlab_list_mrs",description:"List a GitLab project's merge requests, filtered by state and other criteria. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","merged","locked","all"],description:"Filter by state (default: opened)"},targetBranch:{type:"string",description:"Filter by target branch"},sourceBranch:{type:"string",description:"Filter by source branch"},authorUsername:{type:"string",description:"Filter by author username"},labels:{type:"array",items:{type:"string"},description:"Only MRs carrying ALL of these labels"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at","title"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max MRs (default: 20)"}},required:["projectId"]}},{name:"gitlab_list_mr_notes",description:"List the discussion notes on a GitLab merge request (chronological).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},limit:{type:"number",description:"Max notes (default 50)"}},required:["projectId","iid"]}},{name:"gitlab_post_mr_note",description:"Post a general (non-inline) comment on a GitLab merge request. Use for a review summary or a top-level remark.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}},{name:"gitlab_post_mr_discussion",description:"Post an INLINE review comment anchored to a file + line in a GitLab merge request diff. Provide newLine (added/changed line) or oldLine (removed/context line). Pass diffRefs from gitlab_get_mr/gitlab_get_mr_changes, or omit to have the tool fetch them. If the line anchor is rejected, fall back to gitlab_post_mr_note.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr. Omit and the tool fetches them."}},required:["projectId","iid","path","body"]}},{name:"gitlab_create_mr_review",description:"Post a full review on a GitLab merge request in one call: a summary note plus optional inline comments anchored to file/line in the diff. Convenience wrapper over gitlab_post_mr_note + gitlab_post_mr_discussion.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Merge request iid"},body:{type:"string",description:"The review summary (markdown). Posted as a top-level MR note."},diffRefs:{type:"object",description:"The MR diff_refs ({ base_sha, start_sha, head_sha }) from gitlab_get_mr \u2014 required to anchor inline comments. Omit and the tool fetches them."},comments:{type:"array",description:"Optional inline comments, each anchored to a changed line in a file.",items:{type:"object",properties:{path:{type:"string",description:"New file path as it appears in the diff"},oldPath:{type:"string",description:"Old file path (defaults to path)"},newLine:{type:"number",description:"Line number in the NEW version of the file (for added/changed lines)"},oldLine:{type:"number",description:"Line number in the OLD version (for removed/context lines)"},body:{type:"string",description:"The inline comment text (markdown)"}},required:["path","body"]}}},required:["projectId","iid"]}},{name:"gitlab_list_issues",description:"List a GitLab project's issues, filtered by state, labels, and an updatedAfter polling cursor. Returns newest-updated first.",input_schema:{type:"object",properties:{projectId:{type:"string",description:'Project numeric id OR full path (e.g. "group/repo")'},state:{type:"string",enum:["opened","closed","all"],description:"Filter by state (default: opened)"},labels:{type:"array",items:{type:"string"},description:"Only issues carrying ALL of these labels"},assigneeUsername:{type:"string",description:"Filter by assignee username"},authorUsername:{type:"string",description:"Filter by author username"},updatedAfter:{type:"string",description:"ISO-8601 timestamp; only issues updated after this (polling cursor)"},search:{type:"string",description:"Search title and description"},orderBy:{type:"string",enum:["created_at","updated_at"],description:"Sort field (default: updated_at)"},sort:{type:"string",enum:["asc","desc"],description:"Sort direction (default: desc)"},limit:{type:"number",description:"Max issues (default: 30)"}},required:["projectId"]}},{name:"gitlab_get_issue",description:"Get a single GitLab issue with full detail (title, description, state, labels, assignees, web url).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid (the per-project issue number in the URL)"}},required:["projectId","iid"]}},{name:"gitlab_add_issue_comment",description:"Add a comment to a GitLab issue. Also the way to record an MR link on a ticket (post a markdown link).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"Project numeric id OR full path"},iid:{type:"number",description:"Issue iid"},body:{type:"string",description:"Comment body (markdown)"}},required:["projectId","iid","body"]}}]};export{O as gitlabSkill,u as glFetch};
|