@counterfact-labs/cli 0.2.5 → 0.2.7

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.
Files changed (82) hide show
  1. package/README.md +20 -0
  2. package/bundle/client-release.json +1 -1
  3. package/dist/adapters/completion-lock.js +95 -0
  4. package/dist/adapters/completion.js +132 -17
  5. package/dist/adapters/entry-files.js +126 -0
  6. package/dist/adapters/entry-selection.js +45 -0
  7. package/dist/adapters/files.js +2 -1
  8. package/dist/adapters/results.js +10 -2
  9. package/dist/adapters/selection.js +104 -0
  10. package/dist/adapters/settings.js +29 -2
  11. package/dist/analysis-core/analysis/schemas.js +1 -1
  12. package/dist/analysis-core/chunks/2PZF54KH.js +10 -0
  13. package/dist/analysis-core/chunks/{OPMA32A6.js → 6RWEWBHK.js} +1 -1
  14. package/dist/analysis-core/chunks/{PECX3OXB.js → 7NEWZ74F.js} +1 -1
  15. package/dist/analysis-core/chunks/{6QY5BV5B.js → CGCJN73D.js} +1 -1
  16. package/dist/analysis-core/chunks/CWYVUGG4.js +1 -0
  17. package/dist/analysis-core/chunks/{3JWEFCTJ.js → FBTOOUPL.js} +1 -1
  18. package/dist/analysis-core/chunks/GOQVKWP3.js +32 -0
  19. package/dist/analysis-core/chunks/IHAVDX4L.js +66 -0
  20. package/dist/analysis-core/chunks/IVULXWQN.js +21 -0
  21. package/dist/analysis-core/chunks/K5FUABWW.js +1 -0
  22. package/dist/analysis-core/chunks/KGQYR62R.js +7 -0
  23. package/dist/analysis-core/chunks/PY5M22CL.js +1 -0
  24. package/dist/analysis-core/chunks/{YDBO7P4X.js → RNTMH4MU.js} +1 -1
  25. package/dist/analysis-core/chunks/RUVMFAST.js +1 -0
  26. package/dist/analysis-core/chunks/S27VIQMZ.js +1 -0
  27. package/dist/analysis-core/chunks/{5DGPLXYB.js → SLJ6CW7W.js} +1 -1
  28. package/dist/analysis-core/chunks/{STI4JE7L.js → UEORNVQB.js} +1 -1
  29. package/dist/analysis-core/chunks/{X7WZAA7S.js → WYLIV2P2.js} +1 -1
  30. package/dist/analysis-core/contracts/analysis-selection.js +1 -0
  31. package/dist/analysis-core/contracts/module-resolution.js +1 -0
  32. package/dist/analysis-core/contracts/relay-analysis.js +1 -1
  33. package/dist/analysis-core/contracts/requests.js +1 -1
  34. package/dist/analysis-core/contracts/selection-paths.js +1 -0
  35. package/dist/analysis-core/conventions/analysis-fit.js +1 -1
  36. package/dist/analysis-core/conventions/file-admission.js +1 -1
  37. package/dist/analysis-core/import/calls/modules.js +1 -0
  38. package/dist/analysis-core/import/outside-loader-sources.js +1 -1
  39. package/dist/analysis-core/index.js +3 -3
  40. package/dist/analysis-core/requests/local-plan.js +1 -1
  41. package/dist/analysis-core/requests/registry.js +1 -1
  42. package/dist/analysis-core/requests/template-version.js +1 -1
  43. package/dist/analysis-core/requests/tools.js +1 -1
  44. package/dist/analysis-core/settings.js +1 -1
  45. package/dist/analysis-core/stages/engine-entry.js +1 -1
  46. package/dist/cli/agent-folder.js +3 -3
  47. package/dist/cli/analysis-selection.js +91 -0
  48. package/dist/cli/commands/analyze.js +34 -8
  49. package/dist/cli/commands/balance.js +6 -3
  50. package/dist/cli/completion-delivery.js +63 -0
  51. package/dist/cli/completion-recovery.js +68 -14
  52. package/dist/cli/context.js +4 -1
  53. package/dist/cli/main.js +21 -9
  54. package/dist/cli/mcp-failure.js +8 -0
  55. package/dist/cli/mcp.js +130 -30
  56. package/dist/cli/prior-completion.js +35 -0
  57. package/dist/cli/relay-check.js +163 -97
  58. package/dist/cli/relay-failure.js +32 -0
  59. package/dist/cli/relay-preparation.js +24 -11
  60. package/dist/cli/results-upload.js +131 -0
  61. package/dist/cli/scope-choices.js +57 -0
  62. package/dist/cli/sign-in.js +61 -2
  63. package/dist/contract/cli-api-messages.js +2 -0
  64. package/dist/contract/cli-refusals.js +74 -1
  65. package/dist/contract/cli-version.js +1 -1
  66. package/dist/contract/console.js +7 -2
  67. package/dist/contract/email-sign-in-messages.js +4 -0
  68. package/dist/contract/scope-choice.js +78 -0
  69. package/dist/contract/selection-metadata.js +9 -0
  70. package/dist/contract/selection-offer.js +43 -0
  71. package/dist/gatekeeper/cli-api.js +16 -7
  72. package/dist/gatekeeper/connection-exchange.js +1 -0
  73. package/dist/gatekeeper/console.js +61 -36
  74. package/package.json +2 -2
  75. package/dist/analysis-core/chunks/377MLK4M.js +0 -21
  76. package/dist/analysis-core/chunks/DLPVYWHZ.js +0 -1
  77. package/dist/analysis-core/chunks/FOKDE64Y.js +0 -1
  78. package/dist/analysis-core/chunks/KTNA2KTN.js +0 -7
  79. package/dist/analysis-core/chunks/NIOS7U6C.js +0 -41
  80. package/dist/analysis-core/chunks/QFY6A3MS.js +0 -66
  81. package/dist/analysis-core/chunks/SVMEWGD3.js +0 -1
  82. package/dist/analysis-core/chunks/ZTOVBAG7.js +0 -1
@@ -1,41 +0,0 @@
1
- import{b as kn}from"./74FPPPIG.js";import{d as Co,e as vt}from"./5TATKWLG.js";import{a as vo,b as dn,c as Ao}from"./724WZMYW.js";import{c as yn,d as Sn,e as At,g as No}from"./YUY436SM.js";import{a as Fe,c as B,d as jo,e as De}from"./C6X5GDG4.js";import{d as xn}from"./6B2HILSY.js";import{f as Mo}from"./JKWTHRUR.js";import{b as $o,d as hn,e as Po}from"./SKVEBOGA.js";import{a as mn}from"./A7WJJMRY.js";import{b as gn}from"./FSLWD2PE.js";import{relative as cc,sep as uc}from"node:path";var To=/(^|\/)(?:(?:\.cursor|\.windsurf|\.claude|\.roo)\/rules\/|\.clinerules\/|\.junie\/guidelines\.md$|\.kiro\/steering\/|\.github\/instructions\/.*\.instructions\.md$)/;function Se(e){let t=e.toLowerCase(),n=t.split("/").pop();return["claude.md","agents.md","gemini.md",".cursorrules",".windsurfrules",".clinerules","copilot-instructions.md"].includes(n)||/^(claude|agents|gemini)\.(local|override)\.md$/.test(n)||To.test(t)}function Ac(e){let t=e.toLowerCase();return t.includes("/")?t===".github/copilot-instructions.md"||To.exec(t)?.index===0:Se(t)}function $c(e,t){return+(e.toLowerCase()==="agents.md")-+(t.toLowerCase()==="agents.md")||e.localeCompare(t)}var ot=["claude.md","agents.md"];function ri(e){return!Be(e)&&e.CF_CONFIGURATION_GUIDE_PROMPT!=="0"}function Be(e){return e.CF_IMPORT_GUIDES_AS_PROMPT==="1"}function Fo(e,t,n=!1){return n||Be(e)||!Se(t)}function Do(e,t){return Be(e)?ot.includes(t.toLowerCase()):Se(t)}function Bo({codeAgentsFound:e,folderAgentsFound:t=!1,otherDefinitions:n,agentConfiguration:o=!1,usage:r="import"},s){return Be(s)?t?"background":r==="scan"?n?"prompt":"background":r==="map"?e?"background":"prompt":e&&!n?"background":"prompt":ri(s)&&o&&!e&&!t?"prompt":"background"}function ne(e,t){return e.CF_IMPORT_COVERAGE==="1"&&(t===void 0||e[t]==="1")}function V(e){return ne(e,"CF_IMPORT_LAYOUTS")}var We=class{text;tokens=[];lineStarts=[0];constructor(t){this.text=t;for(let n=0;n<t.length;n++)t.charCodeAt(n)===10&&this.lineStarts.push(n+1)}push(t,n,o,r,s=!1){this.tokens.push({kind:t,text:this.text.slice(n,o),value:r??this.text.slice(n,o),start:n,end:o,line:this.lineAt(n),endLine:this.lineAt(o-1),...s?{formatted:!0}:{}})}lineAt(t){let n=0,o=this.lineStarts.length-1;for(;n<o;){let r=n+o+1>>1;this.lineStarts[r]<=t?n=r:o=r-1}return n+1}},si=/[\p{L}_$]/u,ii=/[\p{L}\p{N}_$]/u;function rt(e){return si.test(e)}function Go(e){return ii.test(e)}function le(e){return e>="0"&&e<="9"}function st(e){return e===" "||e===" "||e===`
2
- `||e==="\r"||e==="\f"||e==="\v"}function Ke(e,t){return e[t+1]==="\r"&&e[t+2]===`
3
- `?3:2}function it(e,t){let n=t+1;for(;n<e.length&&Go(e[n]);)n++;return n}function lt(e,t){let n=t+1;for(;n<e.length&&(Go(e[n])||e[n]===".");)n++;return n}function at(e,t){for(;t<e.length&&e[t]!==`
4
- `&&e[t]!=="\r";)t++;return t}var Wo={n:`
5
- `,t:" ",r:"\r",b:"\b",f:"\f",v:"\v"},Ko=/^[0-9a-fA-F]+$/;function li(e,t,n){let o=e[t+1];if(o==="\r"&&e[t+2]===`
6
- `)return["",t+3];if(o===`
7
- `||o==="\r")return["",t+2];if(o in Wo)return[Wo[o],t+2];let r=o==="x"?2:o==="u"?4:o==="U"&&n==="py"?8:0;if(r){let s=e.slice(t+2,t+2+r);if(s.length===r&&Ko.test(s)){let i=parseInt(s,16);if(i<=1114111)return[String.fromCodePoint(i),t+2+r]}}if(o==="u"&&n==="js"&&e[t+2]==="{"){let s=e.indexOf("}",t+3),i=s===-1?"":e.slice(t+3,s);if(Ko.test(i)&&parseInt(i,16)<=1114111)return[String.fromCodePoint(parseInt(i,16)),s+1]}if(n==="py"){if(o==="a")return["\x07",t+2];if(o>="0"&&o<="7"){let s=t+1;for(;s<t+4&&e[s]>="0"&&e[s]<="7";)s++;return[String.fromCharCode(parseInt(e.slice(t+1,s),8)),s]}if(o==="N"&&e[t+2]==="{"){let s=e.indexOf("}",t+3);if(s!==-1)return[e.slice(t,s+1),s+1]}}return n==="js"&&o==="0"?["\0",t+2]:[o,t+2]}function Ge(e,t){let n="",o=0;for(;o<e.length;){if(e[o]!=="\\"||o+1>=e.length){n+=e[o++];continue}let[r,s]=li(e,o,t);n+=r,o=s}return n}var ai=new Set(["return","typeof","instanceof","in","of","new","delete","void","throw","case","do","else","yield","await"]);function Uo(e,t){let n=e[t],o=t+1;for(;o<e.length;){let r=e[o];if(r==="\\")o+=Ke(e,o);else{if(r===n)return o+1;if(r===`
8
- `||r==="\r")return o;o++}}return e.length}function ci(e,t,n=!1){let o=["t"],r=[],s=-1,i,l,a=(f,u,p)=>{l=i,i={kind:f,text:e.slice(u,p),start:u,end:p}},c=t+1;for(;c<e.length;){let f=o[o.length-1],u=e[c];if(f==="t")if(u==="\\")c+=Ke(e,c);else if(u==="`"){if(n&&a("template",c,c+1),c++,o.pop(),o.length===0)return{end:c,closed:!0,interpolations:r}}else u==="$"&&e[c+1]==="{"?(i=l=void 0,o.length===1&&(s=c),o.push(1),c+=2):c++;else if(u==="'"||u==='"'){let p=Uo(e,c);n&&a("string",c,p),c=p}else if(u==="`")o.push("t"),c++;else if(u==="/"&&e[c+1]==="/")c=at(e,c);else if(u==="/"&&e[c+1]==="*")c=zo(e,c);else if(n&&u==="/"&&Xo(i,l)){let p=Jo(e,c);a("regex",c,p),c=p}else if(u==="{")n&&a("punct",c,c+1),o[o.length-1]=f+1,c++;else if(u==="}")n&&a("punct",c,c+1),c++,f===1?(o.pop(),o.length===1&&r.push([s,c])):o[o.length-1]=f-1;else if(n&&(rt(u)||le(u))){let p=le(u)?lt(e,c):it(e,c);a(le(u)?"number":"ident",c,p),c=p}else n&&!st(u)&&a("punct",c,c+1),c++}return s!==-1&&o.length>1&&r.push([s,e.length]),{end:e.length,closed:!1,interpolations:r}}function ui(e,t,n){let o=n.closed?n.end-1:n.end,r="",s=t+1;for(let[i,l]of n.interpolations)r+=Ge(e.slice(s,i),"js")+e.slice(i,Math.min(l,o)),s=l;return r+Ge(e.slice(s,o),"js")}function zo(e,t){let n=e.indexOf("*/",t+2);return n===-1?e.length:n+2}function Jo(e,t){let n=t+1,o=!1;for(;n<e.length;){let r=e[n];if(r===`
9
- `||r==="\r")return n;if(r==="\\")n+=Ke(e,n);else if(r==="[")o=!0,n++;else if(r==="]")o=!1,n++;else if(r==="/"&&!o){n++;break}else n++}for(;n<e.length&&/[a-z]/i.test(e[n]);)n++;return Math.min(n,e.length)}function fi(e,t){return e.kind==="punct"&&(e.text==="+"||e.text==="-")&&t?.text===e.text&&t.end===e.start}function Xo(e,t){if(!e)return!0;if(fi(e,t))return!1;switch(e.kind){case"ident":return ai.has(e.text);case"number":case"string":case"template":case"regex":return!1;case"punct":return e.text!==")"&&e.text!=="]"&&e.text!=="}";default:return!0}}function qo(e){let t=new We(e),n,o,r=(i,l,a,c,f=!1)=>{t.push(i,l,a,c,f),i!=="comment"&&(o=n,n=t.tokens[t.tokens.length-1])},s=0;for(;s<e.length;){let i=e[s],l=e[s+1];if(st(i)){s++;continue}let a;if(i==="/"&&l==="/")a=at(e,s),r("comment",s,a);else if(i==="/"&&l==="*")a=zo(e,s),r("comment",s,a);else if(i==="'"||i==='"')a=Uo(e,s),r("string",s,a,Ge(pi(e,s,a,i),"js"));else if(i==="`"){let c=ci(e,s);a=c.end,r("template",s,a,ui(e,s,c),c.interpolations.length>0)}else i==="/"&&Xo(n,o)?(a=Jo(e,s),r("regex",s,a)):le(i)||i==="."&&le(l??"")?(a=lt(e,s),r("number",s,a)):rt(i)?(a=it(e,s),r("ident",s,a)):(a=s+1,r("punct",s,a));s=a}return t.tokens}function pi(e,t,n,o){let r=0;for(let i=n-2;i>t&&e[i]==="\\";i--)r++;let s=n-t>1&&e[n-1]===o&&r%2===0;return e.slice(t+1,s?n-1:n)}var di=new Set(["r","b","f","u","rb","br","fr","rf"]);function Yo(e,t,n=!1,o){let r=e[t],s=e.startsWith(r.repeat(3),t),l=t+(s?3:1),a=l,c=0,f=[];for(;a<e.length;){let u=e[a];if(u==="\\")a+=Ke(e,a);else if(n&&u==="{"&&c===0&&e[a+1]==="{")a+=2;else if(n&&u==="{"){let p=f.at(-1);o&&(c===0||p?.format&&c===p.depth?f.push({start:a+1,depth:c+1,nesting:0,format:!1}):p&&!p.format&&p.nesting++),c++,a++}else if(n&&u==="}"&&c>0){let p=f.at(-1);p?.depth===c?(p.format||o?.push([p.start,a]),f.pop()):p&&!p.format&&p.nesting--,c--,a++}else if(o&&f.length&&!f.at(-1).format&&"()[]".includes(u))f.at(-1).nesting+="([".includes(u)?1:-1,a++;else if(o&&u===":"&&f.length&&!f.at(-1).format&&f.at(-1).nesting===0){let p=f.at(-1);o.push([p.start,a]),p.format=!0,a++}else if(c>0&&!f.at(-1)?.format&&(u==='"'||u==="'")&&!e.startsWith(u.repeat(3),a)&&Vo(e,a)!==-1)a=Vo(e,a);else{if(s&&e.startsWith(r.repeat(3),a))return{end:a+3,bodyStart:l,bodyEnd:a};if(!s&&u===r)return{end:a+1,bodyStart:l,bodyEnd:a};if(!s&&(u===`
10
- `||u==="\r"))return{end:a,bodyStart:l,bodyEnd:a};a++}}return{end:e.length,bodyStart:l,bodyEnd:e.length}}function Vo(e,t){let n=Yo(e,t);return n.end>n.bodyEnd?n.end:-1}function Zo(e){let t=new We(e),n=0;for(;n<e.length;){let o=e[n];if(st(o)){n++;continue}if(o==="#"){let r=at(e,n);t.push("comment",n,r),n=r}else if(o==='"'||o==="'")n=Ho(t,n,n,"");else if(le(o)||o==="."&&le(e[n+1]??"")){let r=lt(e,n);t.push("number",n,r),n=r}else if(rt(o)){let r=it(e,n),s=e.slice(n,r).toLowerCase();(e[r]==='"'||e[r]==="'")&&di.has(s)?n=Ho(t,n,r,s):(t.push("ident",n,r),n=r)}else t.push("punct",n,n+1),n++}return t.tokens}function Ho(e,t,n,o){let r=Yo(e.text,n,o.includes("f")),s=e.text.slice(r.bodyStart,r.bodyEnd);return e.push("string",t,r.end,o.includes("r")?s:Ge(s,"py"),o.includes("f")),r.end}var mi={ts:"js",tsx:"js",js:"js",jsx:"js",mjs:"js",cjs:"js",mts:"js",cts:"js",py:"py"};function W(e){let t=e.slice(e.lastIndexOf("/")+1),n=t.lastIndexOf(".");return n===-1?null:mi[t.slice(n+1).toLowerCase()]??null}function $t(e,t){return t==="py"?Zo(e):qo(e)}function U(e,t,n){let o=$t(t,n).filter(r=>r.kind!=="comment");return{path:e,text:t,lang:n,toks:o}}function d(e,t){return e?.kind==="punct"&&e.text===t}function y(e,t){return e?.kind==="ident"&&(t===void 0||e.text===t)}function K(e){return e?.kind==="string"||e?.kind==="template"}function Ue(e){let t=/^[A-Za-z]*/.exec(e.text)[0],n=e.text.slice(t.length),o=n[0]??"",r=n.startsWith(o.repeat(3))&&n.length>=6?3:1,s=n.length>=2*r&&n.endsWith(o.repeat(r));if(s){let i=0;for(let l=n.length-r-1;l>=0&&n[l]==="\\";l--)i++;s=i%2===0}return{prefix:t,width:r,inner:n.slice(r,s?n.length-r:void 0),closed:s}}function T(e,t){return d(e[t],"=")&&!d(e[t+1],"=")&&!d(e[t+1],">")}var de=["function","def","class"],me=12;function z(e,t){return t===0||e[t].line>e[t-1].endLine}function ke(e,t){return t.start-(e.lastIndexOf(`
11
- `,t.start-1)+1)}function A(e,t){let n=0;for(let o=t;o<e.length;o++)if(e[o].kind==="punct"){if("([{".includes(e[o].text))n++;else if(")]}".includes(e[o].text)&&--n===0)return o}return e.length}function C(e,t){let n=A(e,t),o=[],r=t+1,s=0;for(let i=t+1;i<n;i++){let l=e[i];l.kind==="punct"&&"([{".includes(l.text)?s++:l.kind==="punct"&&")]}".includes(l.text)?s--:s===0&&d(l,",")&&(o.push({from:r,to:i}),r=i+1)}return r<n&&o.push({from:r,to:n}),o}function Pt(e,t,n){let o=A(e,t),r=[],s=t+1,i=0,l=!1,a=0;for(let c=t+1;c<o;c++){let f=e[c];if(f.kind==="punct")if("([{".includes(f.text))i++;else if(")]}".includes(f.text))i--;else{if(i!==0)continue;f.text===","&&a===0?(r.push({from:s,to:c}),s=c+1,l=!1):f.text===":"&&!l?l=!0:l&&(n==="js"&&f.text==="<"?a++:n==="js"&&f.text===">"&&a>0&&!d(e[c-1],"=")?a--:a===0&&T(e,c)&&(l=!1))}}return s<o&&r.push({from:s,to:o}),r}var hi=100;function we(e){return e.replace(/\s+/g," ").trim().slice(0,hi)}function J(e,t={}){return e.lang==="py"?Ii(e,t.namespaceBindings===!0,t.bindingPositions===!0):Si(e,t.bindingPositions===!0)}var gi=new Set(["@anthropic-ai/sdk","anthropic","openai","ai","@anthropic-ai/claude-agent-sdk","claude_agent_sdk","@openai/agents"]);function Mt(e,t,n={},o){let r=t==="py"?e.split(".")[0]:e.startsWith("@")?e.split("/").slice(0,2).join("/"):e.split("/")[0];return r==="@openai/agents"?n.layouts===!0:t==="py"&&r==="agents"?n.layouts===!0&&(n.openaiAgents===!0||!!o&&xi(o)):gi.has(r)||r.startsWith("@ai-sdk/")||r.startsWith("@langchain/")||r.startsWith("langchain")}function xi({toks:e}){let t=(n,o=!1)=>e.some((r,s)=>y(r,n)&&!de.includes(e[s-1]?.text??"")&&(d(e[s+1],"(")||o&&d(e[s+1],".")));return t("Agent")&&t("Runner",!0)}var yi=[".","/","@/","~/"];function ae(e,t){return e.filter(n=>t==="py"||yi.some(o=>n.source.startsWith(o))).flatMap(n=>n.names.map(o=>({name:o,imported:n.renamed?.[o]??o,source:n.source,line:n.line})))}function Si(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++)if(y(n[r],"import")&&!d(n[r-1],".")){let s=d(n[r+1],"(")?ki(e,r+1):bi(e,r);s&&o.push({...s,...t?{bindingAt:r}:{}})}else y(n[r],"require")&&d(n[r+1],"(")&&K(n[r+2])&&d(n[r+3],")")&&o.push({source:n[r+2].value,line:n[r].line,...Ei(e,r),...t?{bindingAt:r}:{}});return o}function ki(e,t){let n=e.toks[t+1];return K(n)&&d(e.toks[t+2],")")?{source:n.value,line:n.line,names:[]}:null}var wi=80;function bi(e,t){let{toks:n}=e,o=Math.min(n.length,t+wi);for(let r=t+1;r<o;r++){let s=n[r];if(K(s))return r!==t+1&&!y(n[r-1],"from")?null:{source:s.value,line:n[t].line,..._i(e,t+1,r)};if(d(s,";")||y(s,"import"))return null}return null}function _i(e,t,n){let{toks:o}=e,r=[],s={},i=y(o[t],"type")&&Qo(o[t+1])?t+1:t,l=y(o[i])?o[i].text:void 0;for(let a=t;a<n;a++){let c=o[a];if(!(!y(c)||c.text==="from"))if(c.text==="as")y(o[a+1])&&(r.push(o[++a].text),y(o[a-2])&&(s[o[a].text]=o[a-2].text));else{if(y(o[a+1],"as"))continue;(c.text!=="type"||!Qo(o[a+1]))&&r.push(c.text)}}return{names:r,renamed:s,...l?{defaultName:l}:{}}}function Qo(e){return d(e,"{")||y(e)&&e?.text!=="from"}function Ei(e,t){let{toks:n}=e,o={names:[],renamed:{}};if(!d(n[t-1],"="))return o;if(y(n[t-2]))return{names:[n[t-2].text],renamed:{}};if(!d(n[t-2],"}"))return o;let r=t-2;for(;r>0&&!d(n[r],"{");)r--;let s=[],i={};for(let l=r+1;l<t-2;l++)!y(n[l])||d(n[l+1],":")||(s.push(n[l].text),d(n[l-1],":")&&y(n[l-2])&&(i[n[l].text]=n[l-2].text));return{names:s,renamed:i}}function Ii(e,t,n){let{toks:o}=e,r=[];for(let s=0;s<o.length;s++)if(z(o,s)){if(y(o[s],"import"))r.push(...Oi(e,s+1,t).map(i=>({...i,...n?{bindingAt:s}:{}})));else if(y(o[s],"from")){let i=er(e,s+1);i.next>s+1&&y(e.toks[i.next],"import")&&r.push({source:i.text,line:o[s].line,...Ri(e,i.next+1),...n?{bindingAt:s}:{}})}}return r}function er(e,t){let{toks:n}=e,o=t,r=!1;for(;;){if(d(n[o],"."))r=!1;else if(y(n[o])&&!r&&n[o].text!=="import")r=!0;else break;o++}return{text:n.slice(t,o).map(s=>s.text).join(""),next:o}}function Oi(e,t,n){let{toks:o}=e,r=[],s=t;for(;;){let i=er(e,s);if(i.next===s)break;let l=y(o[i.next],"as")?o[i.next+1]?.text:void 0,a=l??i.text.split(".")[0];if(r.push({source:i.text,line:o[t].line,names:n?[a]:[],...n?{namespaceNames:[a],...l?{renamed:{[l]:i.text}}:{}}:{}}),s=i.next,y(o[s],"as")&&(s+=2),!d(o[s],","))break;s++}return r}function Ri(e,t){let{toks:n}=e,o=d(n[t],"("),r=o?A(n,t):n.length,s=[],i={};for(let l=o?t+1:t;l<r&&!(!o&&(z(n,l)||d(n[l],";")));l++)y(n[l])&&(y(n[l+1],"as")&&y(n[l+2])?(s.push(n[l+2].text),i[n[l+2].text]=n[l].text,l+=2):s.push(n[l].text));return{names:s,renamed:i}}var jt=["eval","evals"],Li=new RegExp(`(^|/)(${[...jt,"evaluations?","bench(?:mark)?s?"].join("|")})/`,"i"),vi=/^(evals?|bench(?:mark)?s?)[_-].+|.+[._-](evals?|bench(?:mark)?s?)[._-]/i;function tr(e,t){if(Li.test(e))return!0;let n=W(e);if((n||/\.(json|ya?ml|toml)$/i.test(e))&&vi.test(e.split("/").at(-1)))return!0;if(!n||t===void 0||!/(^|\/)scripts\//i.test(e))return!1;let o=U(e,t,n),{toks:r}=o;if(r.some((p,h)=>y(p,"export")||y(p,"exports")||n==="py"&&y(p,"def")||y(p,"module")&&d(r[h+1],".")&&y(r[h+2],"exports"))||!r.some(p=>y(p)&&/^(expected|dataset|fixtures|cases)$/i.test(p.text)))return!1;let s=r.flatMap((p,h)=>y(p)&&d(r[h+1],"(")&&!["for","if","while","switch","catch"].includes(p.text)&&!["function","def","class"].includes(r[h-1]?.text)?[h]:[]),l=J(o).filter(p=>p.names.some(h=>s.some(m=>y(r[m],h)&&!d(r[m-1],".")))),a=/(^|[/._-])(scores?|scoring|graders?|grading|evals?|evaluators?|bench(?:mark)?s?)([/._-]|$)/i,c=l.filter(p=>p.source.startsWith(".")&&/(^|[/._-])(agents?|runners?)([/._-]|$)/i.test(p.source)),f=[...c,...l.filter(p=>a.test(p.source))],u=new Set(f.flatMap(p=>p.names));return s.some(p=>d(r[p-1],".")?!(y(r[p-2],"console")&&["log","table"].includes(r[p].text)):y(r[p],"require")&&r[p+2]?.kind==="string"&&f.some(h=>h.source===r[p+2].value)?!1:!u.has(r[p].text)&&!(n==="py"&&y(r[p],"print")))?!1:l.some(p=>a.test(p.source))&&c.some(p=>!a.test(p.source))}function Ct(e){return e.CF_IMPORT_CALLS==="1"}var ze={archive:{bytes:6e7,files:2e4},conventionImport:{fileBytes:5e4,totalBytes:12e4,skillBytes:6e5,skillFiles:60,extractionFiles:25},sourceFetch:{instructionBytes:6e5,codeBytes:3e5,htmlReferenceBytes:3e4,codeFileBytes:6e4,codeFiles:60},codeScan:{files:400,bytes:3e6,fileBytes:2e5},candidateFetch:{check:12e4,pointers:12e4},codeAgent:{extraBytes:4e4,importBytes:2e6,toolCodeFiles:5},survey:{fileBytes:5e6,files:60},localCheck:{uploadBytes:18e5},verification:{sourceBytes:12e4}};function Je(e){return e.CF_IMPORT_LAYOUTS==="1"}var rr=/(^|\/)(__tests__|__snapshots__)\/|\.(test|spec)\.[jt]sx?$|_test\.(go|py)$/i,wn=new Set(["test","tests","__tests__","spec","specs","testdata","test-data","test_data","test-support","mocks","fixtures","fixture","__fixtures__","__mocks__","__snapshots__"]),sr=/^(examples?|samples?)(?:[-_].+)?$|^.+[-_](examples?|samples?)$/i,ir=/\.(test|spec)\..+|^test_.*\.py$|_test\.(py|go)$|_spec\.rb$|^conftest\.py$/i,Ai=new Set([...wn].filter(e=>!["test","tests","__tests__","spec","specs"].includes(e))),$i=new Set([".github","cassettes"]),Pi=new Set,nr=new WeakMap;function lr(e){if(!ne(e))return[];let t=nr.get(e);if(t)return t;let n=[];try{let o=JSON.parse(e.CF_IMPORT_SCOPES??"[]");Array.isArray(o)&&o.every(r=>{if(!r||typeof r!="object"||!["runtime","example","evaluator"].includes(r.kind)||typeof r.path!="string")return!1;let s=r.path.endsWith("/**"),i=s?r.path.slice(0,-3):r.path;return!!i&&!/[\\\0:*?]/.test(i)&&!i.split("/").some(l=>!l||l==="."||l==="..")&&!(r.kind==="evaluator"&&s)})&&new Set(o.map(r=>r.path)).size===o.length&&(n=Object.freeze(o.map(({path:r,kind:s})=>Object.freeze({path:r,kind:s}))))}catch{}return nr.set(e,n),n}function be(e,t,n){let o=B(t,n);if(o===null)return;let r=lr(e).filter(l=>l.path.endsWith("/**")?t.startsWith(l.path.slice(0,-2)):t===l.path).sort((l,a)=>a.path.replace(/\/\*\*$/,"").length-l.path.replace(/\/\*\*$/,"").length)[0];if(!r||r.kind==="runtime")return;let s=o.split("/"),i=s.pop();if(!(s.some(l=>Ai.has(l.toLowerCase())||$i.has(l.toLowerCase()))||/^conftest\.py$/i.test(i))&&!(r.kind==="example"&&(ir.test(i)||s.some(l=>wn.has(l.toLowerCase())))))return r}function bn(e,t,n={}){return!lr(e).some(r=>r.kind!=="runtime"&&(B(r.path,n.root)!==null||r.path.endsWith("/**")&&B(`${Fe(n.root)}/`,r.path.slice(0,-3))!==null))||be(e,t,n.root)?!1:Nt(t,{root:n.root??void 0,listing:n.listing??Pi})!==null}var Mi=new Set(["example-agents","examples","example","fixtures","__fixtures__","testdata","test","tests","__tests__","demo","demos"]),ji=/^examples?[-_]/i;function ar(e,t,n){if(e.CF_IMPORT_INCLUDE_EXAMPLES==="1"||be(e,t,n))return!1;let o=ne(e),r=i=>Mi.has(i.toLowerCase())||ji.test(i)||o&&(i.toLowerCase()==="fixture"||sr.test(i));if(Fe(n).split("/").some(r))return!1;let s=B(t,n);return s!==null&&s.split("/").slice(0,-1).some(r)}var or=new WeakMap;function Ci(e){let t=or.get(e);if(t)return t;let n={exact:new Set,foldedNames:new Set};for(let o of e.keys()){let r=0;for(let s=o.indexOf("/");s!==-1;s=o.indexOf("/",r))n.exact.add(o.slice(0,s)),n.foldedNames.add(o.slice(0,r)+o.slice(r,s).toLowerCase()),r=s+1}return or.set(e,n),n}function Ni(e,t,n){let o=e.some(r=>Nt(t(r),n)===null);return r=>{if(n.settings&&be(n.settings,r,n.root))return!1;if(n.settings&&bn(n.settings,r,n))return!0;let s=Nt(r,n);return s==="test"||s==="example"&&o}}function cr(e,t,n){let o=Ni(e,t,n),r=[],s=[];for(let i of e)(o(t(i))?s:r).push(i);return{kept:r,skipped:s}}function _n(e,t){return Nt(e,t)!==null}function Nt(e,t){let n=B(e,t.root);return n?Ti(e,n,t):null}function Ti(e,t,n){let o=Ci(n.listing),r=e.endsWith("/")||o.exact.has(e),s=t.split("/").filter(Boolean),i=r?"":s.pop()??"";return ir.test(i)||s.some(a=>wn.has(a.toLowerCase()))?"test":s.some((a,c)=>{let f=a.toLowerCase();if(sr.test(f))return!0;if(f!=="before"&&f!=="after")return!1;let u=Fe(De(s.slice(0,c).join("/"),n.root)),p=u?`${u}/`:"",h=f==="before"?"after":"before";return o.foldedNames.has(p+h)})?"example":null}var Fi=new Set,ur=new WeakMap;function fr(e,t){let n={root:t.root,listing:t.listing??Fi};if(!_n(e,n))return!1;let o=t.listing;if(!o?.has(e))return!0;let r=ur.get(o);r||ur.set(o,r=new WeakMap);let s=r.get(t.settings);s||r.set(t.settings,s=new Map);let i=s.get(t.key);if(!i){let l=[...o.keys()].filter(a=>_n(a,n)||t.readable(a,"get"in o?o.get(a):void 0));i=new Set(cr(l,a=>a,n).skipped),s.set(t.key,i)}return i.has(e)}function pr(e){return e.CF_IMPORT_EXAMPLE_FILTER!=="0"}import{posix as En}from"node:path";var In=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function ce(e,t={}){let n=`(?:${ct.map(In).join("|")})`,o=`(?:${Tt.map(In).join("|")})`,s=new RegExp(`^(${t.nested?"(?:.*?/)??":""}(?:(${n}/[^/]+)/${_e}|${o})/([^/]+))/(.+)$`,t.caseSensitive?"":"i").exec(e);if(!s)return null;let i=t.caseSensitive?s[4]:s[4].toLowerCase(),l=t.caseSensitive?F.skill:F.skill.toLowerCase();return{folder:s[1],name:s[3],definition:i===l,reference:i.startsWith("references/"),...s[2]?{ownerPath:s[1].replace(/\/skills\/[^/]+$/i,".md")}:{}}}function On(e){return ce(e)?.reference??!1}function Di(e){return ne(e,"CF_DISCOVERY_SKILLS")}function Bi(e){return!/[\\:\0]/.test(e)&&e.split("/").every(t=>t&&t!=="."&&t!=="..")}function Wi(e){let t=[],n;for(let[o,r]of e.split(/\r?\n/).entries()){let s=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(r);if(n){if(s&&s[1][0]===n.marker[0]&&s[1].length>=n.marker.length&&!s[2].trim()){n=void 0;continue}if(!n.shell||!/^\s*(?:\$\s+)?(?:cat|less|more|head|tail)\s+/.test(r))continue}if(!n&&s){n={marker:s[1],shell:/^(?:sh|bash|shell|console)?$/i.test(s[2].trim())};continue}let i=/!?\[[^\]\n]*\]\(\s*(?:<([^>\n]+)>|([^\s)\n]+))(?:\s+["'][^"'\n]*["'])?\s*\)|^\s*\[[^\]]+\]:\s*(?:<([^>]+)>|(\S+))|`([^`\n]+)`|([^\s`<>"'()[\],;]+)/g;for(let l of r.matchAll(i)){let a=l.slice(1,5).some(h=>h!==void 0),c=l[1]??l[2]??l[3]??l[4]??l[5]??l[6],f=a?c:c.replace(/[.,;:]+$/,""),u=/^[^.\s][^\s]*\.(?:md|mdx|rst|txt|html?|json|ya?ml|toml|csv|ts|tsx|js|jsx|mjs|cjs|py|go|java|rb|rs|sh|prompt)(?:#.*)?$/i.test(f.split(/[/\\]/).at(-1)??""),p=l[5]!==void 0&&/[/\\]/.test(f)||/^\.{1,2}[/\\]/.test(f);f.startsWith("#")||!a&&(/\s/.test(f)||!(p||u))||t.push({target:f,span:{from:o+1,to:o+1}})}}return t}function cu(e,t){let n={references:[],cycles:[],unresolved:[]};if(!Di(e))return n;let o=[...new Set(t.paths)].filter(s=>Bi(s)&&B(s,t.root)!==null).sort(),r=new Set(o);for(let s of[...new Set(t.skillPaths)].sort()){if(!r.has(s)||!ce(s,{nested:!0})?.definition)continue;let i=new Set,l=new Set,a=c=>{if(!(i.has(c)||!Object.hasOwn(t.files,c))){i.add(c),l.add(c);for(let{target:f,span:u}of Wi(t.files[c])){let p=w=>n.unresolved.push({ownerPath:s,fromPath:c,target:f,span:u,reason:w}),h=f.split("#")[0];if(!h||/[\\:\0*?[\]$]/.test(h)||h.startsWith("/")||/[{}]/.test(h.replace(/(?:^|\/)\{lang\}(?=\/)/g,""))){p("unsupported");continue}let m=En.normalize(En.join(En.dirname(c),h));if(m===".."||m.startsWith("../")||B(m,t.root)===null){p("out-of-scope");continue}let g=new RegExp(`^${m.split("/").map(w=>w==="{lang}"?"[^/]+":In(w)).join("/")}$`),x=m.includes("{lang}")?o.filter(w=>g.test(w)):r.has(m)?[m]:[];if(!x.length){p("missing");continue}for(let w of x){let k={ownerPath:s,fromPath:c,path:w,span:u};l.has(w)?n.cycles.push(k):(n.references.push(k),a(w))}}l.delete(c)}};a(s)}return n}var Ln="readme";function gu(e){let t=e.toLowerCase();return t.startsWith(Ln)?0:t===F.agentGuide?1:t.endsWith(".md")&&e.split("/").length<=2?2:dr.test(e)?3:null}var F={systemPrompt:"system_prompt.md",hyphenatedPrompt:"system-prompt.md",unseparatedPrompt:"systemprompt.md",system:"system.md",prompt:"prompt.md",promptFallback:"CLAUDE.md",soul:"soul.md",knowledge:"knowledge.md",tools:"tools.json",toolsSource:"tools.ts",cli:".cli.json",config:"counterfact.json",skill:"SKILL.md",readme:`${Ln}.md`,agentGuide:"agents.md"},ut=[F.systemPrompt,F.hyphenatedPrompt,F.system,F.prompt],vn=F.promptFallback,Ki=[...ut,vn].map(e=>e.toLowerCase()),Ft=[".mcp.json","mcp.json"],Gi=[F.toolsSource,F.cli],Ie=".claude",ft="agents",_e="skills",ct=[`${Ie}/${ft}`,ft],xu=/^(?:\.claude\/)?(skills|commands)\//i,Tt=[_e,`${Ie}/${_e}`],Ui=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),zi=e=>e.map(Ui).join("|"),Ji=`(?:${zi(ct)})`,An=new RegExp(`^${Ji}/[^/]+\\.md$`,"i"),Xi=/^templates\/.+/i;function yu(e,t){return ce(e,t)?.definition??!1}function Ee(e){return e.CF_DISCOVERY_SKILLS!=="0"}var $n=new Map([...ut.map(e=>[e,{role:"prompt",kind:"dedicated"}]),[vn.toLowerCase(),{role:"prompt",kind:"fallback"}],[F.soul,{role:"soul"}],[F.knowledge,{role:"knowledge"}],[F.config,{role:"marker"}],[F.tools,{role:"tool file",kind:"json"}],[F.toolsSource,{role:"tool file",kind:"sdk"}],[F.cli,{role:"tool file",kind:"cli"}],...Ft.map(e=>[e,{role:"MCP config"}])]),qi=[...$n.keys()];function Rn(e){let t=$n.get(e.toLowerCase());if(t)return t;if(An.test(e))return{role:"sub-agent"};let n=ce(e),o=n?.ownerPath?{ownerPath:n.ownerPath}:{};return n?.definition?{role:"skill",name:n.name,...o}:n?.reference?{role:"reference",kind:"skill",name:n.name,...o}:Xi.test(e)?{role:"reference",kind:"template"}:null}function Vi(e){let t=Rn(e);return!!t&&t.role!=="skill"&&t.role!=="reference"}var Hi=["package.json","pyproject.toml","go.mod","cargo.toml"],Yi=[...qi.filter(e=>!Gi.includes(e)),...Hi],Zi=new RegExp(`^${Ln}[^/]*$`,"i");function Dt(e,t,n){let o=Je(e)?n?.ownerOf(t):void 0;return o?B(t,o.folder)??t:t}function Pn(e,t,n){if(Je(e)&&n?.files?.some(l=>l.path===t&&l.kind==="entry"))return!0;t=Dt(e,t,n);let o=t.split("/").pop()??"",r=ce(t),s=r?.definition&&(Ee(e)||!r.ownerPath&&!r.folder.startsWith(`${Ie}/`)),i=r?.reference&&r.ownerPath&&Ee(e);return Yi.includes(o.toLowerCase())||Zi.test(o)||Vi(t)||!!s||!!i}var Su=[...ut,vn].join(", "),ku=`${F.config}, a system prompt file, ${F.tools}, an MCP config, ${F.soul}, ${F.knowledge}, ${ft}/*.md and ${_e}/*/${F.skill}`,wu=/(agent|tool|prompt|llm|model|chain|graph|pipeline|workflow|handler|route|server|main|index|app|orchestr)/i,bu=/(^|\/)prompts?\/.*\.(md|txt|prompt)$/i;function _u(e,t,n={}){let o=t.flatMap(m=>{let g=B(m,n.root);return g===null?[]:[{path:m,relativePath:g}]}),r=o.filter(({path:m})=>Xe(e,{path:m},{purpose:"override",route:"github"}).admitted),s=new Map(r.map(m=>[m.relativePath.toLowerCase(),m.path])),i=ut.map(m=>s.get(m)).find(Boolean),l=Ft.map(m=>s.get(m)).find(Boolean),a=m=>Do(e,m),c=Bo({codeAgentsFound:n.codeAgentsFound??!1,folderAgentsFound:n.folderAgentsFound,agentConfiguration:n.agentConfiguration,otherDefinitions:r.some(({relativePath:m})=>{let g=Rn(m);return!a(m)&&!!g&&g.role!=="reference"})},e),f=n.agentConfiguration&&c==="prompt",u=f?ot.map(m=>s.get(m)).find(Boolean):void 0,p=!f&&s.has(F.soul)&&!(Be(e)?Ki:ut).some(m=>s.has(m)),h=[];for(let m of r){let g=a(m.relativePath)&&(c==="background"||f&&!ot.includes(m.relativePath.toLowerCase())),x=f&&ot.includes(m.relativePath.toLowerCase())?{role:"prompt",kind:"fallback"}:g?{role:"knowledge",kind:"background"}:Rn(m.relativePath);if(!x||n.mode==="core"&&(x.role==="skill"||x.role==="reference"))continue;let w;g?w=m.path===s.get(m.relativePath.toLowerCase()):f&&x.role==="prompt"&&x.kind==="fallback"?w=m.path===u:x.role==="prompt"&&x.kind==="dedicated"?w=m.path===i:x.role==="MCP config"?w=m.path===l:$n.has(m.relativePath.toLowerCase())&&(w=m.path===s.get(m.relativePath.toLowerCase()));let k=x.ownerPath?{ownerPath:s.get(x.ownerPath.toLowerCase())??null}:{};h.push({...m,...x,...k,...w===void 0?{}:{preferred:w}})}return{files:h,scoped:o,registry:p}}var Oe=/\.(?:md|txt|j2|hbs|mustache|prompt)$/i,mr=/(?:^|[/\\])(?:prompts?|templates?|instructions)(?=$|[/\\])/i,Qi=/prompt|instructions|system/i,el=200;function Bt(e){if(!Oe.test(e))return!1;let t=e.split("/"),n=t[t.length-1];return t.slice(0,-1).some(r=>r.toLowerCase()==="prompts")||Qi.test(n)}function hr(e,t){return!Bt(e)||Buffer.byteLength(t)<el?null:tl(e,t)}function tl(e,t){let n=Buffer.byteLength(t),o=t.split(`
12
- `).length;return{kind:"file",named:!1,prose:!1,path:e,start:0,line:1,endLine:o,span:{from:1,to:o},symbol:null,chars:n,excerpt:we(t),enclosing:null}}function Ru(e,t){let n=e.toks[t.from];return t.to!==t.from+1||n?.kind!=="string"||!Ue(n).closed?null:{kind:"named",named:!0,prose:!1,path:e.path,start:n.start,line:n.line,endLine:n.endLine,span:{from:n.line,to:n.endLine},symbol:null,chars:n.value.length,excerpt:we(n.value),enclosing:null}}function Mn(e){return/(?:^|\/)(?:pyproject\.toml|requirements\.txt)$/i.test(e)}function vu(e,t){if(!Mn(e))return!1;let n=t.split(/\r?\n/).map(s=>s.replace(/("(?:\\.|[^"\\])*"|'[^']*')|#.*/g,(i,l)=>l??""));if(/(?:^|\/)requirements\.txt$/i.test(e))return n.some(s=>/^\s*openai[-_.]agents(?:\[[^\]]*\])?(?=\s*(?:$|[<>=!~;@#]))/i.test(s));let o="",r=new Map;for(let s of n){let i=/^\s*\[([^\]]+)\]/.exec(s);i?o=i[1]:(r.has(o)||r.set(o,[]),r.get(o).push(s))}for(let[s,i]of r){let l=i.join(`
13
- `);if(/^tool\.poetry(?:\.group\.[^.]+)?\.dependencies$/.test(s)){if(/^\s*["']?openai[-_.]agents["']?\s*=/im.test(l))return!0}else if(["project","project.optional-dependencies","dependency-groups"].includes(s)){let a=/^\s*([\w."'-]+)\s*=\s*\[((?:"(?:\\.|[^"\\])*"|'[^']*'|[^\]"'])*)\]/gm;for(let c of l.matchAll(a))if(!(s==="project"&&c[1].replace(/["']/g,"")!=="dependencies")&&/["']openai[-_.]agents(?=["'[<>=!~ ;@])/i.test(c[2]))return!0}}return!1}function gr(e){return/\.json$/i.test(e)?"json":/\.ya?ml$/i.test(e)?"yaml":W(e)||/\.(cs|go|rb|java)$/i.test(e)?"code":/\.(md|markdown)$/i.test(e)?"markdown":"text"}function xr(e){return{salesforce:"Salesforce",slack:"Slack",s3:"S3",anthropic:"Anthropic","http-client":"HTTP client"}[e.toLowerCase()]??e}function yr(e){let t=new Map;for(let n of e)!n.unitKey||!n.scope||(t.has(n.scope)||t.set(n.scope,new Map),t.get(n.scope).set(n.unitKey,n.id));return e.flatMap(n=>!n.unitKey||!n.scope?[]:(n.links??[]).flatMap(o=>{let r=t.get(n.scope)?.get(o.to);return r?[{from:n.id,to:r,kind:"invokes",label:o.kind,sourceRef:o.source??null}]:[]}))}function Sr(e,t,n){let o;try{let r=JSON.parse(e),s=r?.mcpServers??r?.servers;o=s&&typeof s=="object"?Object.keys(s):[]}catch{return{servers:[],warnings:[`${t} is not valid JSON; ignored`]}}return{servers:o,warnings:!n&&o.length?[`found MCP config (servers: ${o.join(", ")}) but no ${F.tools}; tool schemas are discovered from a running server and were not extracted`]:[]}}import{z as Re}from"zod";var nl=Re.object({name:Re.string().min(1,"tool name is required"),description:Re.string().optional(),input_schema:Re.record(Re.string(),Re.unknown()).optional()}),ol=Re.array(nl);function kr(e){let t=[];if(e==null)return{tools:[],warnings:t};let n=e;if(typeof e=="string"){let r=e.trim();if(r==="")return{tools:[],warnings:t};try{n=JSON.parse(r)}catch(s){throw new Error(`tools is not valid JSON: ${s.message}`)}}let o=ol.safeParse(n);if(!o.success)throw new Error(`tools do not match the expected shape (an array of {name, description?, input_schema?}): ${o.error.issues.map(r=>`${r.path.join(".")||"(root)"}: ${r.message}`).join("; ")}`);return o.data.length===0&&t.push("no tools were provided"),{tools:o.data,warnings:t}}import{posix as jn}from"node:path";var Z=e=>`${e.path}:${e.kind}:${e.start}`;function pt(e){return e.slice(e.lastIndexOf("/")+1)}function rl(e){return e.replace(/\.(tsx?|jsx?|mjs|cjs|py)$/,"").replace(/^(\.{1,2}\/)+/,"").replace(/^[@~]?\//,"").replace(/^\.+/,"").replace(/\./g,"/")}function Wt(e,t){let n=rl(t),o=e.replace(/\.[^./]+$/,"").replace(/\/index$/,"").replace(/\/__init__$/,"");return n.length>0&&(o===n||o.endsWith(`/${n}`))}function dt(e,t){let n=t.replace(/\\/g,"/").replace(/^(\.\/)+/,""),o=e.filter(r=>r.path===n||r.path.endsWith(`/${n}`));return o.length>0?o:e.filter(r=>pt(r.path)===pt(n))}function Le(e,t,n){let o=Z(t);e.set(o,[...e.get(o)??[],n])}function qe(e,t,n){let o=n.source,r=s=>s.replace(/\.(tsx?|jsx?|mjs|cjs|py)$/,"").replace(/\/(?:index|__init__)$/,"");if(o.startsWith(".")){let s=t.path.endsWith(".py"),i=s?/^\.+/.exec(o)?.[0].length??0:0,l=s?"../".repeat(Math.max(0,i-1))+o.slice(i).replace(/\./g,"/"):o,a=r(jn.normalize(jn.join(jn.dirname(t.path),l)));return e.files.filter(c=>r(c.path)===a)}return e.files.filter(s=>Wt(s.path,o))}function ve(e,t,n,o){let r=(o.get(n)??[]).filter(c=>c.path===t.path);if(r.length)return r;let[s,i]=n.split("."),l=t.imports.find(c=>c.name===s);if(!l)return[];let a=new Set(qe(e,t,l).map(c=>c.path));return(o.get(i??l.imported)??[]).filter(c=>a.has(c.path))}import{posix as Xt}from"node:path";var Kt=/^(claude-[a-z0-9.-]+|gpt-[a-z0-9.-]+|o[1-9](-[a-z0-9-]+)?|gemini-[a-z0-9.-]+)$/,sl=/^\S+\.(?:md|txt|j2|hbs|mustache|prompt)$/i,mt=50,wr=200;function br(e){let t=[],n=[],o=[];for(let[r,s]of e.toks.entries()){if(!K(s))continue;s.kind==="string"&&Kt.test(s.value)&&t.length<mt&&t.push({value:s.value,path:e.path,line:s.line});let i=s.value.length<=wr&&sl.test(s.value),l=e.toks[r-2],a=d(e.toks[r-1],":")&&l&&/^(?:system_prompt|user_prompt|prompt|template)$/i.test(l.kind==="string"?l.value:l.text);if(i){let c={value:s.value,path:e.path,line:s.line};n.length<mt&&n.push(c),a&&o.length<mt&&o.push(c)}}return{modelIds:t,fileRefs:n,promptFileRefs:o}}function _r(e){let{toks:t}=e,n=[];for(let o=0;o<t.length&&n.length<mt;o++)if(!(!y(t[o])||!T(t,o+1)||!d(t[o+2],"{"))&&!(e.lang==="js"&&!y(t[o-1],"const")))for(let{from:r,to:s}of C(t,o+2)){let i=t[r],l=t[r+2];if(!(s!==r+3||!d(t[r+1],":")||l?.kind!=="string"||l.value.length>wr||!Kt.test(l.value))&&!(!y(i)&&i?.kind!=="string")&&(n.push({object:t[o].text,member:i.kind==="string"?i.value:i.text,value:l.value,path:e.path,line:l.line}),n.length===mt))break}return n}import{posix as Jt}from"node:path";function Er(e,t){let n=e?e.split("/"):[];for(let o of t.split("/"))if(!(o===""||o==="."))if(o===".."){if(n.pop()===void 0)return null}else n.push(o);return n.join("/")}function il(e,t=!1){let n=t?[".ts",".tsx",".js",".jsx",".mts",".cts",".mjs",".cjs"]:[".ts",".tsx",".js"],o=e.replace(t?/\.(js|jsx|mjs|cjs)$/:/\.(js|jsx|mjs)$/,""),r=t&&e.endsWith(".mjs")?[".mts"]:t&&e.endsWith(".cjs")?[".cts"]:[".ts",".tsx"];return[e,...n.map(s=>e+s),...o===e?[]:r.map(s=>o+s),...n.map(s=>`${e}/index${s}`)]}function ll(e,t,n){let o=t.length-t.replace(/^\.+/,"").length,r=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"",s="../".repeat(o-1),i=t.slice(o).split(".").join("/"),l=Er(r,s+i);return l===null?[]:i?[`${l}.py`,`${l}/__init__.py`]:[...n.map(a=>l?`${l}/${a}.py`:`${a}.py`),l?`${l}/__init__.py`:"__init__.py"]}function Cn(e,t,n,o,r=!1){if(!t.startsWith("."))return[];if(o==="py")return ll(e,t,n);let s=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"",i=Er(s,t);return i===null?[]:il(i,r)}function he(e,t,n,o,r,s=!1){return Cn(e,t,n,o,s).find(i=>r.has(i))}import{posix as gt}from"node:path";var al=new Set(["string","unknown","any","object","never","boolean","number","undefined","null","void"]),cl=new Set(["if","for","while","switch","catch","with"]),ul=24;function Ir(e){return al.has(e)}function X(e,t){let n=0;for(let o=t-1;o>=0;o--){let r=e.toks[o];if(r.kind==="punct"){if(")]}".includes(r.text))n++;else if("([{".includes(r.text)&&n--===0)return o}}return-1}function Nn(e,t){let{toks:n}=e;if(!d(n[t],"("))return!1;let o=n[t-1];if(o&&y(o)&&cl.has(o.text))return!1;let r=A(n,t),s=n[r+1];return d(s,"{")||d(s,"=")&&d(n[r+2],">")?!0:d(s,":")&&y(n[t-2],"function")}function Or(e,t){let{toks:n}=e;if(!d(n[t],"{"))return!1;for(let r=t-1;r>=0&&r>=t-ul;r--){let s=n[r];if(d(s,";")||d(s,"{")||d(s,"}"))break;if(y(s,"interface")||y(s,"type")&&y(n[r+1])&&(d(n[r+2],"=")||d(n[r+2],"<")))return!0}if(!d(n[t-1],":"))return!1;let o=X(e,t);return o>=0&&(Or(e,o)||Nn(e,o))}function Tn(e,t){let n=X(e,t);if(n<0)return!1;if(Nn(e,n)||Or(e,n))return!0;let o=d(e.toks[n],"{")?X(e,n):-1;return o>=0&&Nn(e,o)}var fl=new Set(["if","for","while","switch","catch","return","function","def","class","elif","with","await","typeof"]),Fn={js:new Set(["if","for","while","switch","catch","with"]),py:new Set(["if","elif","for","while","with","except"])},pl={js:new Set([...Fn.js,"return","yield","throw","await","typeof","void","delete","new","in","instanceof","case","else","do","default","extends"]),py:new Set([...Fn.py,"return","yield","await","not","and","or","is","in","assert","raise","else","lambda","del"])};function Q(e,t,n){if(!n)return y(e[t])&&!fl.has(e[t].text)&&d(e[t+1],"(");let o=t+1;if(!d(e[o],"("))return!1;let r=t,s=n.lang==="py"&&d(e[r],"\\");if(s&&r--,n.lang==="py"&&e[r]?.endLine<e[o].line&&!s&&X(n,o)<0)return!1;if(n.lang==="js"&&d(e[r],".")&&d(e[r-1],"?")&&(r-=2),n.lang==="js"&&d(e[r],">")){if(!/\.[cm]?tsx?$/.test(n.path))return!1;let i=0;do{if(d(e[r],";")||d(e[r],"="))return!1;d(e[r],">")?i++:d(e[r],"<")&&i--,r--}while(r>=0&&i>0);if(i!==0)return!1}for(;d(e[r],"]");)r=X(n,r)-1;if(d(e[r],")")){let i=e[X(n,r)-1];return!y(i)||!Fn[n.lang].has(i.text)}return!y(e[r])||de.some(i=>y(e[r-1],i))||n.lang==="py"&&["match","case"].includes(e[r].text)&&z(e,r)&&d(e[A(e,o)+1],":")?!1:d(e[r-1],".")||!pl[n.lang].has(e[r].text)}function q(e,t={}){let n=e.lang==="py"?El(e,!!t.includeMembers,!!t.promptFunctions):gl(e,!!t.includeMembers,!!t.typedReturns);if(!t.includeMembers)return n;for(let o=0;o<e.toks.length;o++){if(!d(e.toks[o],"["))continue;let r=e.toks[o-1];if(o===0||y(r,"return")||r?.kind==="punct"&&"=:(,[>".includes(r.text))for(let[i,l]of C(e.toks,o).entries())n.push({name:`[${i}]`,line:e.toks[l.from].line,from:l.from-1,to:l.to,params:null,kind:"index"})}return n.map(o=>({...o,kind:o.kind??(o.params===null?"value":"function")}))}function oe(e,t){return Rr(e,t).at(-1)?.name??null}function Rr(e,t){return e.filter(n=>n.from<t&&t<n.to).sort((n,o)=>n.from-o.from)}var dl="=+-*/,([{:?.&|<>!%",ml=".+-*/?:,|&)]}";function Ve(e,t,n){let{toks:o}=e,r=0;for(let s=t;s<o.length;s++){n?.(1);let i=o[s];if(i.kind==="punct"&&"([{".includes(i.text))r++;else{if(i.kind==="punct"&&")]}".includes(i.text)&&--r<0)return s;if(r===0&&d(i,";")&&e.lang==="js")return s+1}if(r===0&&s>t&&z(o,s)&&hl(e,s))return s}return o.length}function hl(e,t){if(e.lang==="py")return!0;let n=e.toks[t-1],o=e.toks[t],r=n.kind==="punct"&&dl.includes(n.text),s=o.kind==="punct"&&ml.includes(o.text);return!r&&!s}function ht(e,t,n){let{toks:o}=e,r=[];for(let{from:s,to:i}of Pt(o,t,n)){let l=s;for(;l<i&&o[l].kind==="punct"&&(o[l].text==="*"||o[l].text===".");)l++;i-s===1&&o[s].kind==="punct"&&["*","/"].includes(o[s].text)||r.push(l<i&&y(o[l])?o[l].text:null)}return n==="py"&&(r[0]==="self"||r[0]==="cls")&&r.shift(),r}function gl(e,t,n){let{toks:o}=e,r=[],s=0;for(let i=0;i<o.length;i++){let l=o[i];if(d(l,"{"))s++;else if(d(l,"}"))s--;else if(y(l,"function")&&!d(o[i-1],".")){let a=kl(e,i,n);a&&r.push(a)}else if(["const","let","var"].includes(l.text)&&l.kind==="ident"&&y(o[i+1])){let a=bl(e,i,s===0||t);a&&r.push(a)}else if(t&&y(l,"class")&&y(o[i+1])){let a=o.findIndex((c,f)=>f>i+1&&d(c,"{"));a>=0&&r.push({name:o[i+1].text,line:l.line,from:i,to:A(o,a)+1,params:null,kind:"class"})}else if(t&&y(l)){let a=Sl(e,i,r);a&&r.push(a)}}return r}var xl=["public","private","protected","static","readonly","async","get","set"],yl=["if","for","while","switch","catch","with"];function Sl(e,t,n){let{toks:o}=e,r=t;for(d(o[r-1],".")&&y(o[r-2],"this")&&(r-=2);y(o[r-1])&&xl.includes(o[r-1].text);)r--;if(!z(o,r)&&!["{","}",",",";"].some(u=>d(o[r-1],u))||yl.includes(o[t].text))return null;let s=t+1;if(d(o[s],"(")){let u=A(o,s)+1;if(d(o[u],":"))for(;u<o.length&&!d(o[u],"{")&&!d(o[u],";");)u++;return d(o[u],"{")?{name:o[t].text,line:o[t].line,from:t,to:A(o,u)+1,params:ht(e,s,"js"),kind:"method"}:null}if(!T(o,s)&&!d(o[s],":"))return null;let l=Rr(n,t).at(-1)?.kind==="class"?Lr(e,s,Ve(e,s+1)):T(o,s)?s:null,a=l===null?s+1:l+1,c=Ve(e,a),f=0;for(let u=a;u<c;u++){if(d(o[u],",")&&f===0){c=u;break}o[u].kind==="punct"&&("([{".includes(o[u].text)?f++:")]}".includes(o[u].text)&&f--)}return{name:o[t].text,line:o[t].line,from:t,to:c,params:null,kind:l===null?"property":"value"}}function kl(e,t,n){let{toks:o}=e,r=t+1;if(d(o[r],"*")&&r++,!y(o[r]))return null;let s=o[r];if(r++,d(o[r],"<")&&(r=wl(e,r)),!d(o[r],"("))return null;let i=ht(e,r,"js"),l=A(o,r)+1;n&&d(o[l],":")&&d(o[l+1],"{")&&(l=A(o,l+1)+1);for(let a=l;a<o.length&&!d(o[a],";");a++)if(d(o[a],"{"))return{name:s.text,line:o[t].line,from:t,to:A(o,a)+1,params:i};return null}function wl(e,t){let n=0;for(let o=t;o<e.toks.length;o++)if(d(e.toks[o],"<"))n++;else if(d(e.toks[o],">")&&--n===0)return o+1;return e.toks.length}function bl(e,t,n){let{toks:o}=e,r=Lr(e,t+2);if(r===null)return null;let s=Ve(e,r+1),i=_l(e,r+1,s);return!i&&!n?null:{name:o[t+1].text,line:o[t].line,from:t,to:s,params:i}}function Lr(e,t,n=e.toks.length){let o=t;if(d(e.toks[o],":")){let r=o+me;for(;o<r&&o<n&&!T(e.toks,o);)o++}return o<n&&T(e.toks,o)?o:null}function _l(e,t,n){let{toks:o}=e,r=y(o[t],"async")?t+1:t;if(y(o[r],"function"))return r++,d(o[r],"*")&&r++,y(o[r])&&r++,d(o[r],"(")?ht(e,r,"js"):null;let s=i=>d(o[i],"=")&&d(o[i+1],">");if(y(o[r])&&s(r+1))return[o[r].text];if(!d(o[r],"("))return null;for(let i=A(o,r)+1;i<n;i++)if(s(i))return ht(e,r,"js");return null}function El(e,t,n){let{toks:o,text:r}=e,s=[];for(let i=0;i<o.length;i++){let l=o[i],a=y(l,"def")&&y(o[i+1])&&d(o[i+2],"("),c=t&&y(l,"class")&&y(o[i+1]);if(a||c){let f=Ol(e,a||d(o[i+2],"(")?A(o,i+2)+1:i+2),u=(t||n)&&y(o[i-1],"async")&&o[i-1].line===l.line?o[i-1]:l,p=ke(r,u),h=f+1;for(;h<o.length&&!(z(o,h)&&ke(r,o[h])<=p);)h++;s.push({name:o[i+1].text,line:l.line,from:i,to:h,params:a?ht(e,i+2,"py"):null,...c?{kind:"class"}:{}})}else y(l)&&z(o,i)&&(t||ke(r,l)===0)&&Il(e,i+1)&&s.push({name:l.text,line:l.line,from:i,to:Ve(e,i+1),params:null})}return s}function Il(e,t){let{toks:n}=e;return T(n,t)||d(n[t],":")}function Ol(e,t){let n=t;for(;n<e.toks.length&&!d(e.toks[n],":");)n++;return n}function He(e,t){return e.filter(n=>n.from<t&&t<n.to).at(-1)??null}function Ye(e){let{toks:t}=e,n=[];for(let o=0;o<t.length;o++){if(!y(t[o])||!Q(t,o,e))continue;let r=o;for(;d(t[r-1],".")&&y(t[r-2]);)r-=2;if(d(t[r-1],".")&&d(t[r-2],")")){let a=X(e,r-2);r=n.find(f=>f.open===a)?.from??a}let s=A(t,o+1);if(s===t.length)continue;let i=d(t[o-1],".")&&d(t[o-2],")")?o:r,l=t.slice(i,o+1).map(a=>a.text).join("");n.push({from:r,to:s+1,open:o+1,callee:l,args:C(t,o+1)})}return n}function ue(e,t,n){let o=Ve(e,t,n);return d(e.toks[o-1],";")?o-1:o}function Gt(e){let{toks:t}=e,n=[];for(let o=0;o<t.length;o++){if(!y(t[o])||d(t[o-1],"."))continue;let r=o+1;if(d(t[r],":")){if(!(e.lang==="js"?["const","let","var"].includes(t[o-1]?.text):z(t,o)))continue;for(;r<o+me&&r<t.length&&!T(t,r)&&![";","{","}"].some(a=>d(t[r],a));)r++}let s=d(t[r],"+");if(s&&r++,!T(t,r))continue;let i=X(e,o);e.lang==="py"&&d(t[i],"(")||(n.push({at:o,name:t[o].text,append:s,from:r+1,to:ue(e,r+1)}),o=r)}return n}function vr(e,t,n=Ye(e)){let{toks:o}=e,{assignments:r,functions:s,owner:i,binding:l,inBlock:a,lexical:c,declarations:f}=t,u=J(e),p=q(e,{includeMembers:!0}),h=p.filter(S=>S.params!==null),m=S=>p.filter(_=>(_.params!==null||_.kind==="class")&&_.from<S&&S<_.to).sort((_,E)=>E.from-_.from)[0]??null,g=(S,_)=>{let E=m(S.from);return a(S.from,_)&&(E===null||E.from<_&&_<E.to)},x=J(e,{namespaceBindings:!0,bindingPositions:!0}).map(S=>{let _=S.bindingAt,E=S.names.map(O=>({local:O,name:S.renamed?.[O]??O,namespace:S.namespaceNames?.includes(O)===!0||e.lang==="js"&&(y(o[_],"require")&&!d(o[_-2],"}")||d(o[_+1],"*"))}));return{module:S,at:_,names:E}}),w=(S,_,E=!1)=>{if(E){if(i(_)?.params?.includes(S)||l(S,_)||s.some(L=>L.name===S))return null;let I=u.filter(L=>L.names.includes(S));return I.length===1?{module:I[0],name:I[0].renamed?.[S]??S,namespace:!1}:null}let O=m(_),R=[...O?.kind==="class"?[O]:[],...h.filter(I=>I.from<_&&_<I.to).sort((I,L)=>L.from-I.from),null];for(let I of R){let L=x.filter($=>m($.at)===I&&a($.at,_)&&$.names.some(M=>M.local===S)),v=r.filter($=>$.name===S&&m($.at)===I&&(!c(f.get($)??$)||a($.at,_))&&!L.some(M=>y(o[M.at],"require")&&$.from<=M.at&&M.at<$.to)),P=p.filter($=>$.name===S&&($.params!==null||$.kind==="class")&&m($.from)===I&&g($,_));if(I?.params?.includes(S)||v.length||P.length)return null;if(!L.length)continue;if(L.length!==1||L[0].at>=_&&!(e.lang==="js"&&y(o[L[0].at],"import")))return null;let j=L[0],N=j.names.find($=>$.local===S);return{module:j.module,name:N.name,namespace:N.namespace}}return null};return{importBinding:w,hasImport:(S,_)=>_?u.some(E=>E.names.includes(S)):x.some(E=>E.names.some(O=>O.local===S)),loaderImport:(S,_)=>{let E=S.callee.split(".")[0];if(_){let R=w(E,S.from);return R?ae([R.module],e.lang).find(I=>I.name===E)??null:null}let O=ae(u,e.lang).filter(R=>R.name===E);return O.length!==1||i(n.find(R=>R.callee===S.callee)?.open??0)?.params?.includes(E)?null:O[0]}}}function Ar(e,t,n={}){let{toks:o}=e,r=Gt(e),s=t.filter(_=>_.params!==null),i=_=>He(s,_),l=(_,E)=>{let O=i(E);return r.findLast(R=>R.at<E&&R.name===_&&i(R.at)===O)??(O?.params?.includes(_)?void 0:r.findLast(R=>R.at<E&&R.name===_&&i(R.at)===null))},a=[],c=[];for(let _=0;_<o.length;_++)a.push([...c]),d(o[_],"{")?c.push(_):d(o[_],"}")&&c.pop();let f=(_,E)=>a[_].every((O,R)=>a[E]?.[R]===O),u=_=>["const","let"].includes(o[_.at-1]?.text),p=_=>u(_)||y(o[_.at-1],"var"),h=new Map;for(let _ of r)h.set(_,p(_)?_:r.findLast(E=>E.at<_.at&&E.name===_.name&&i(E.at)===i(_.at)&&p(E)&&(!u(E)||f(E.at,_.at))));let m=(_,E,O)=>r.some(R=>R.name===_&&i(R.at)!==E&&O(R.at)&&!h.get(R)&&!i(R.at)?.params?.includes(_)),g=(_,E)=>{let O=i(E);return!m(_,O,R=>O!==null&&O.from<R&&R<O.to)},x=_=>{let E=i(_.at);if(!E?.params?.includes(_.name))return!1;let O=o.findIndex((R,I)=>E.from<I&&I<_.at&&d(R,"("));return O>=0&&_.at<A(o,O)},w=(_,E)=>{let O=i(_.from);return f(_.from,E)&&(O===null||(n.enclosingBindings?O.from<E&&E<O.to:O===i(E)))},k=_=>{for(let E=_.at-1;E>=0&&![";","{","}"].includes(o[E].text);E--){if([")","]"].includes(o[E].text)){E=X(e,E);continue}if(["if","else","for","while","case","and","or"].includes(o[E].text)||["?","&","|"].includes(o[E].text))return!0}return!1};return{assignments:r,functions:s,owner:i,legacyBinding:l,inBlock:f,lexical:u,declarations:h,parameterIsCertain:g,parameterDefault:x,functionVisible:w,bindingIsCertain:(_,E)=>_.at<E&&f(_.at,E)&&(!n.enclosingBindings||!k(_))&&!m(_.name,i(_.at),O=>f(_.at,O)&&(!n.enclosingBindings||i(_.at)===null||i(_.at).from<O&&O<i(_.at).to)),binding:(_,E)=>{let O=i(E),R=r.filter($=>{if($.name!==_)return!1;let M=h.get($);return!M||!u(M)||f(M.at,E)}),I=[...s.filter($=>$.from<E&&E<$.to).sort(($,M)=>M.from-$.from),null],L=n.enclosingBindings?I.find($=>$?.params?.includes(_)||R.some(M=>i(M.at)===$)||s.some(M=>M.name===_&&i(M.from)===$&&w(M,E))):void 0,v=R.filter($=>n.enclosingBindings?i($.at)===L:i($.at)===O||!O?.params?.includes(_)&&i($.at)===null),P=$=>{let M=h.get($);return M&&u(M)?a[M.at].length:0},j=Math.max(-1,...v.map(P)),N=v.filter($=>P($)===j);return N.findLast($=>$.at<E)??N[0]}}}function re(e,t,n={}){let{toks:o}=e,r=Ye(e),s=Ar(e,t,n),{assignments:i,functions:l,owner:a,legacyBinding:c,binding:f,bindingIsCertain:u,parameterIsCertain:p,parameterDefault:h,functionVisible:m}=s,{importBinding:g,hasImport:x,loaderImport:w}=vr(e,s,r),k=(E,O=new Set)=>o.slice(E.from,E.to).flatMap((R,I)=>{let L=c(R.text,E.from+I);return R.kind!=="ident"||!L||L.append||O.has(L.at)?[R]:k(L,new Set([...O,L.at]))}),b=E=>{let O=o[E.open-1].text;if(["readFileSync","readFile"].includes(O))return E.args[0]??null;if(!d(o[E.open-2],"."))return null;let R=E.open-3;if(O==="read_text"&&y(o[R]))return{from:E.from,to:R+1};if(!d(o[R],")"))return null;let I=X(e,R),L=r.find(v=>v.open===I);return O==="read_text"?L?.callee==="Path"?L.args[0]??null:{from:I+1,to:R}:O==="read"&&L?.callee==="open"||O==="text"&&L?.callee==="Bun.file"?L?.args[0]??null:null},S=E=>{let[O,...R]=E.callee.split("."),I=g(O,E.open,!n.enclosingBindings);if(I){let v=I.module,P=R.at(-1)??I.name;return(/^(?:node:)?fs(?:\/promises)?$/.test(v.source)?["readFile","readFileSync","readdir","readdirSync"]:/^(?:node:)?path$/.test(v.source)?["join","resolve"]:/^(?:node:)?url$/.test(v.source)?["fileURLToPath"]:v.source==="pathlib"?["Path"]:[]).includes(P)?P:null}return(n.enclosingBindings?l.some(v=>v.from<E.open&&E.open<v.to&&v.params?.includes(O)):a(E.open)?.params?.includes(O))||f(O,E.open)||l.some(v=>v.name===O)||x(O,!n.enclosingBindings)||R.length&&!["fs","path","Bun"].includes(O)?null:R.at(-1)??O},_=r.flatMap(E=>{let O=b(E)??(["readFileSync","readFile"].includes(S(E)??"")?E.args[0]:null);return O?[{sourcePath:e.path,line:o[E.open-1].line,call:E,path:O,tokens:k(O)}]:[]});return{source:e,calls:r,assignments:i,functions:l,owner:a,binding:f,bindingIsCertain:u,parameterIsCertain:p,parameterDefault:h,functionVisible:m,pathTokens:k,importBinding:g,loaderImport:w,builtin:S,operations:_}}function fe({source:{toks:e}},t){let{from:n,to:o}=t;for(y(e[n],"await")&&n++;d(e[n],"(")&&A(e,n)===o-1;)n++,o--;return{from:n,to:o}}function ee(e,t){let{from:n,to:o}=fe(e,t);return e.calls.findLast(r=>r.to===o&&(r.from===n||y(e.source.toks[n],"new")&&r.from===n+1))}function Dn(e,t){let{toks:n}=e.source,{from:o}=t,r=o+1;if(d(n[o],"(")&&(r=A(n,o)+1,o++),!y(n[o])||!d(n[r],"=")||!d(n[r+1],">"))return null;let s=r+2;return d(n[s],"{")?y(n[s+1],"return")?(s+=2,{name:n[o].text,body:{from:s,to:ue(e.source,s)}}):null:{name:n[o].text,body:{from:s,to:t.to}}}function H(e,t,n=new Map,o=new Set){let{source:{toks:r,path:s},binding:i,builtin:l}=e,a=fe(e,t),{from:c,to:f}=a;if(c>=f||!r[c])return null;let u=r.slice(c,f).map(b=>b.text).join(""),p=b=>{let S=i(b,c);return!S||e.parameterDefault(S)&&n.has(b)&&n.get(b)!==void 0?e.parameterIsCertain(b,c)?n.get(b)??null:null:e.bindingIsCertain(S,c)&&!S.append&&!o.has(S.at)?H(e,S,n,new Set([...o,S.at])):null},h=b=>H(e,b,n,o);if(f===c+1){let b=r[c];if(e.source.lang==="py"&&b.formatted&&b.value.includes("{"))return null;if(b.kind==="string"||b.kind==="template"&&!b.value.includes("${"))return/^(?:[a-z]+:|[/\\])/i.test(b.value)?null:b.value;if(b.kind==="template"){let S=!1,_=b.value.replace(/\$\{([^}]*)\}/g,(E,O)=>{if(!/^[A-Za-z_$][\w$]*$/.test(O))return S=!0,"";let R=p(O);return R==null&&(S=!0),R??""});return S||/^(?:[a-z]+:|[/\\])/i.test(_)?null:_}if(y(b,"__dirname")&&!i(b.text,c)&&!e.owner(c)?.params?.includes(b.text))return`/repository/${gt.dirname(s)}`;if(y(b))return p(b.text)}let m=[];for(let b=c;b<f;b++){if(["(","[","{"].some(S=>d(r[b],S))){b=A(r,b);continue}m.push(b)}let g=m.find(b=>d(r[b],"?")&&d(r[b+1],"?"));if(g!==void 0){let b=h({from:c,to:g});if(b!==null)return b;let S=g===c+1&&y(r[c])&&!i(r[c].text,c)?r[c].text:null;return S&&e.owner(c)?.params?.includes(S)&&e.parameterIsCertain(S,c)&&(!n.has(S)||n.get(S)===void 0)?h({from:g+2,to:f}):null}let x=m.find(b=>d(r[b],"+"));if(x!==void 0){let b=h({from:c,to:x}),S=h({from:x+1,to:f});return b===null||S===null?null:b+S}if(u==="import.meta.url")return`/repository/${s}`;let w=ee(e,a);if(!w)return null;let k=l(w);if(k==="URL"&&w.args.length===2){let b=r.slice(w.args[1].from,w.args[1].to).map(_=>_.text).join(""),S=h(w.args[0]);return b==="import.meta.url"&&S!==null&&!/^(?:[a-z]+:|[/\\])/i.test(S)?gt.join("/repository",gt.dirname(s),S):null}if(k==="fileURLToPath"||k==="Path")return w.args.length===1?h(w.args[0]):null;if(k==="join"||k==="resolve"){let b=w.args.map(h);return b.length&&b.every(S=>S!==null)&&b.every(S=>S.startsWith("/repository/")||!/^(?:[a-z]+:|[/\\])/i.test(S))?k==="resolve"?gt.resolve("/repository",...b):gt.join(...b):null}return null}function $r(e,t){let n=fe(e,t),o=e.source.toks[n.from],r=y(o,"null")||y(o,"undefined")&&!e.binding(o.text,n.from)&&!e.owner(n.from)?.params?.includes(o.text);return n.to===n.from+1&&r?void 0:H(e,n)}import{posix as Ut}from"node:path";function ge(e,t){if(e===null)return null;let n=e.startsWith("/repository/")?e.slice(12):e.startsWith(".")?Ut.join(Ut.dirname(t),e):e,o=Ut.normalize(n.replace(/\\/g,"/")).replace(/\/$/,"");return o===".."||o.startsWith("../")||/^(?:[a-z]+:|\/)/i.test(o)?null:o}function Pr(e,t){return{from:t.from,to:t.open-2}}function Bn(e,t,n,o=new Set){let r=fe(e,t),{source:{toks:s},binding:i}=e;if(r.to===r.from+1&&y(s[r.from])){let p=i(s[r.from].text,r.from);return p&&e.bindingIsCertain(p,r.from)&&!p.append&&!o.has(p.at)?Bn(e,p,n,new Set([...o,p.at])):null}let l=ee(e,r);if(!l)return null;if(["readdirSync","readdir"].includes(e.builtin(l)??"")&&l.args[0]){let p=ge(H(e,l.args[0],n),e.source.path);return p===null?null:{path:p}}if(s[l.open-1].text!=="filter"||l.args.length!==1)return null;let a=Dn(e,l.args[0]),c=a&&ee(e,a.body),f=c?.args[0]&&H(e,c.args[0]);if(!a||c?.callee!==`${a.name}.endsWith`||!f||!Oe.test(`template${f}`))return null;let u=Bn(e,Pr(e,l),n,o);return u?{...u,extension:f}:null}function Mr(e,t,n,o){let{source:{toks:r}}=e;for(let s of e.calls){if(r[s.open-1].text!=="map"||s.args.length!==1)continue;let i=Dn(e,s.args[0]);if(!i||!(i.body.from<=t.from&&t.to<=i.body.to))continue;let l=Bn(e,Pr(e,s),o);if(!l?.extension||e.owner(t.open)!==e.owner(s.open)||r.slice(i.body.from,t.from).some((u,p)=>{let h=i.body.from+p;return y(u,"function")||d(u,"=")&&d(r[h+1],">")}))continue;let c=new Map(o).set(i.name,"__template_entry__");if(ge(H(e,n,c),e.source.path)===Ut.join(l.path,"__template_entry__"))return{kind:"directory",path:l.path,extension:l.extension}}return null}function jr(e,t){let n=e.owner(t.open),o=new Set(e.assignments.filter(r=>e.owner(r.at)===n&&r.from<=t.from&&t.to<=r.to));for(let r of e.assignments)e.owner(r.at)!==n||r.from<=t.from||zt(e,r,o)&&o.add(r);return o}function zt(e,t,n){return e.source.toks.slice(t.from,t.to).some((o,r)=>{let s=t.from+r;if(d(e.source.toks[s-1],".")||d(e.source.toks[s+1],":"))return!1;let i=y(o)&&e.binding(o.text,s);return i&&n.has(i)})}function Cr(e,t,n,o){if(!t)return!1;let{toks:r}=e.source;for(let i=t.from;i<t.to;i++){if(!y(r[i],"return")||e.owner(i)!==t)continue;let l={from:i+1,to:ue(e.source,i+1)};if(l.from<=n.from&&n.to<=l.to||zt(e,l,o))return!0}let s=r.findIndex((i,l)=>t.from<l&&l<n.from&&d(i,"=")&&d(r[l+1],">"));return s>=0&&!d(r[s+2],"{")}function Wn(e,t,n,o=!1){let r=(o?n.replace(Oe,""):n).replace(/\\/g,"/"),s=c=>o?c.path.replace(Oe,""):c.path,i=Jt.dirname(t);for(;;){let c=Jt.normalize(Jt.join(i,r)),f=e.filter(u=>s(u)===c);if(f.length)return f.length===1?f:[];if(i==="."||i==="/")break;i=Jt.dirname(i)}if(r.includes("/"))return[];let l=o?e.filter(c=>s(c)===r||s(c).endsWith(`/${r}`)):dt([...e],r),a=l.length||!o?l:e.filter(c=>pt(s(c))===pt(r));return a.length===1?a:[]}function Nr(e){return e.filter(({call:t})=>{let n=t.callee.split(".").at(-1);return n==="readFile"||n==="readFileSync"||["read_text","read","text"].includes(n??"")&&t.from<t.open-1})}function Ze(e){return e.filter(t=>Oe.test(t))}function Tr(e,t,n){let{tokens:o}=e,r=o.filter(a=>a.kind==="string"||a.kind==="template").filter(a=>a.value.length<=200).map(a=>a.value),s=r.map(a=>{let c=mr.exec(a);return c?a.slice(0,c.index+c[0].length).replace(/\\/g,"/"):null}).find(a=>a!==null)??null,i=Ze(r)[0]?.match(/\.[^./\\]+$/)?.[0]??null;if(s===null&&i===null)return null;let l=t.params.findIndex(a=>a!==null&&o.some((c,f)=>y(c,a)&&!d(o[f-1],".")?!0:c.kind!=="template"&&!c.formatted?!1:(c.value.match(/\$?\{[^}]*\}/g)??[]).some(u=>{let p=$t(u.replace(/^\$?\{|\}$/g,""),n);return p.some((h,m)=>y(h,a)&&!d(p[m-1],"."))})));return l<0?null:{folder:s,ext:i,paramIndex:l}}function Rl(e,t,n,o){let r=t.loaderImport(n,V(e));if(!r)return null;let s=qe({files:o.map(i=>({path:i.source.path}))},{path:t.source.path},r).map(i=>i.path);return{binding:r,paths:s}}function xt(e,t){let n=e.builtin(t);if(["readFileSync","readFile"].includes(n??""))return!0;if(!["read_text","read","text"].includes(n??""))return!1;let o=n==="read_text"?"Path":n==="read"?"open":"file";return e.calls.some(r=>r.from===t.from&&r.to<t.to&&e.builtin(r)===o)}function Fr(e,t,n,o="anchored"){let r=Object.entries(t).flatMap(([u,p])=>{if(n?.source.path===u)return[re(n.source,n.scopes)];let h=W(u);if(!h)return[];let m=U(u,p,h);return[re(m,q(m))]});n&&!r.some(u=>u.source===n.source)&&r.push(re(n.source,n.scopes));let s=r.flatMap(u=>u.operations);if(o==="operations")return{operations:s,reads:[],dependencies:[]};let i=r.flatMap(u=>u.functions.map(p=>({syntax:u,scope:p}))),l=new Map,a=new Set,c=(u,p)=>{let h=p.callee.split(".")[0];if(u.owner(p.open)?.params?.includes(h))return[];let m=u.binding(h,p.open),g=i.filter(k=>k.syntax===u&&k.scope.name===p.callee&&u.functionVisible(k.scope,p.open));if(g.length)return g.filter(k=>!m||m.at===k.scope.from+1);if(m)return[];let x=Rl(e,u,p,r);if(!x)return[];if(!x.paths.length)for(let k of Cn(u.source.path,x.binding.source,[x.binding.imported],u.source.lang,!0))a.add(k);let w=p.callee.split(".")[1]??x.binding.imported;return i.filter(k=>x.paths.includes(k.syntax.source.path)&&k.scope.name===w&&k.syntax.owner(k.scope.from)===null)};for(let u of r)for(let p of u.calls){let h=c(u,p);for(let m of h){let g=new Map((m.scope.params??[]).flatMap((w,k)=>w===null?[]:[[w,h.length!==1?null:p.args[k]?$r(u,p.args[k]):void 0]])),x=l.get(m.scope)??[];x.push({parameters:g,...h.length===1&&m.syntax!==u?{consumer:u.source.path}:{}}),l.set(m.scope,x)}}let f=[];for(let u of r)for(let p of u.operations){if(!xt(u,p.call))continue;let h=u.owner(p.call.open),m=h?l.get(h)??[{parameters:new Map}]:[{parameters:new Map}];for(let g of m){let x=ge(H(u,p.path,g.parameters),u.source.path),w=x===null?Mr(u,p.call,p.path,g.parameters):{kind:"file",path:x};if(!w)continue;let k=jr(u,p.call),b=new Set(g.consumer&&Cr(u,h,p.call,k)?[g.consumer]:[]);for(let E of u.calls){if(u.owner(E.open)!==h||!E.args.some(R=>zt(u,R,k)))continue;let O=c(u,E);O.length===1&&O[0].syntax!==u&&b.add(O[0].syntax.source.path)}let S=f.find(E=>E.sourcePath===p.sourcePath&&E.line===p.line&&JSON.stringify(E.target)===JSON.stringify(w)),_=[...b].sort();S?S.consumerPaths=[...new Set([...S.consumerPaths,..._])].sort():f.push({sourcePath:p.sourcePath,line:p.line,target:w,consumerPaths:_})}}return{operations:s,reads:f,dependencies:[...a].sort()}}var Ll=30;function Dr(e,t){let n=(e?.modelIds??[]).filter(o=>Math.abs(o.line-t)<=Ll);return n.sort((o,r)=>Math.abs(o.line-t)-Math.abs(r.line-t)||o.line-r.line),n[0]??null}function yt(e,t,n,o){let r=Dr(e.byPath.get(t),n);return r||!o?r:Dr(e.byPath.get(o.path),o.line)}function vl(e,t,n){let o=n.model;if(o?.kind==="literal"&&Kt.test(o.text))return t.modelIds.find(p=>p.value===o.text&&p.line>=n.line)??{value:o.text,path:t.path,line:n.line};if(o?.kind!=="member")return null;let[r,s,i]=o.text.split(".");if(!s||i)return null;let l=new Map;for(let p of e.files)for(let h of p.modelMembers??[])l.set(h.object,[...l.get(h.object)??[],h]);let a=ve(e,t,r,l).filter(p=>p.member===s);if(a.length!==1)return null;let{value:c,path:f,line:u}=a[0];return{value:c,path:f,line:u}}function Al(e,t,n){if(!n.shape)return;let o=t.imports.find(s=>s.name===n.shape),r=o?qe(e,t,o):[];return{name:n.shape,path:r.length===1?r[0].path:t.path,line:o?.line??n.line}}function Kn(e,t){let n=new Map,o=new Map;for(let i of e.files){for(let l of i.loaders??[])n.set(l.name,[...n.get(l.name)??[],l]);for(let l of i.promptReturns??[])o.set(l.fn,[...o.get(l.fn)??[],l])}let r=e.files.flatMap(i=>i.sites.filter(l=>l.kind==="file")),s=(i,l,a,c=new Set)=>{let f=`${i.path}:${JSON.stringify(l)}`;if(c.has(f)||c.size>=50)return[];let u=new Set([...c,f]);if(l.kind==="site")return i.sites.filter(x=>x.start===l.siteStart).map(x=>({site:x,sdk:i.sdk}));if(l.kind==="symbol"||l.kind==="module-member"){let[x,w]=l.callee.split("."),k=x.replace(/\(\)$/,""),b=(i.promptBindings??[]).filter(I=>I.name===l.callee.replace("().","."));if(!l.importBinding&&b.length)return b.flatMap(I=>I.loads.flatMap(L=>s(i,L,a,u)));let S=l.importBinding?[l.importBinding]:i.imports.filter(I=>I.name===k);if(S.length!==1)return[];let _=S[0],E=qe(e,i,_);if(E.length!==1)return[];let O=E[0],R=l.kind==="module-member"?w:w?`${_.imported}.${w}`:_.imported;return R?s(O,{kind:"symbol",callee:R,literals:[]},a,u):[]}if(l.kind==="bound-file"||l.kind==="chainlite")return l.literals.flatMap(x=>{let w=l.kind==="bound-file"?[x]:[Xt.join(Xt.dirname(i.path),x),Xt.join(Xt.dirname(i.path),"prompts",x)],k=r.filter(b=>w.includes(b.path));return k.length===1?k.map(b=>({site:b,sdk:l.kind==="chainlite"||i.sdk})):[]});let p=l.kind==="loader"||l.kind==="return",h=p?ve(e,i,l.callee,n):[];if(h.length)return h.flatMap(x=>l.literals.flatMap(w=>{let k=x.ext&&!w.endsWith(x.ext)?w+x.ext:w,b=x.folder?`${x.folder}/${k}`:k;return Wn(r,x.path,b,!x.ext).map(_=>({site:_,sdk:e.byPath.get(x.path)?.sdk??!1}))}));let m=p&&a?ve(e,i,l.callee,o):[];return m.length?m.flatMap(x=>x.loads.flatMap(w=>s(e.byPath.get(x.path),w,!1,u))):l.kind==="read"||l.kind==="file-key"?Ze(l.literals).flatMap(x=>Wn(r,i.path,x).map(w=>({site:w,sdk:i.sdk}))):[]};for(let i of e.files){if(i.sdk||i.callSites.some(a=>a.kind==="system-arg"))for(let a of i.loadedPromptRefs??[])for(let c of r.filter(f=>f.path===a.value))Le(t,c,{kind:"L3",callPath:i.path,callLine:a.line,callExcerpt:a.value,wrapper:null,shortLabel:null,sdk:i.sdk,modelId:yt(e,i.path,a.line,null)});let l=new Map;for(let a of i.deliveries??[]){let c=`${a.callStart??a.line}:${a.callee}`;l.set(c,[...l.get(c)??[],a])}for(let a of l.values()){let c={...a[0],model:a.find(m=>m.model)?.model??null,shape:a.find(m=>m.shape)?.shape??null},f=a.flatMap(m=>m.loads.flatMap(g=>s(i,g,!0))),u=[...new Map(f.map(m=>[Z(m.site),m.site])).values()];if(!u.length)continue;let p=u.slice(1).map(m=>m.path),h=Al(e,i,c);Le(t,u[0],{kind:"L4",callPath:i.path,callLine:c.line,callExcerpt:`${c.callee}(\u2026)`,...c.callStart!==void 0?{callStart:c.callStart}:{},wrapper:null,shortLabel:null,sdk:i.sdk||f.some(m=>m.sdk),modelId:vl(e,i,c),...p.length?{alsoLoads:p}:{},...h?{shape:h}:{}})}}}function Wr(e,t,n,o){let r=e.files.filter(i=>i.path!==t.path).flatMap(i=>i.sites.filter(l=>l.symbol===n)),s=r.filter(i=>o.some(l=>Wt(i.path,l)));return s.length>0?s:r}function Kr(e,t,n){let o=t.sites.filter(s=>s.symbol===n);if(o.length>0)return o;let r=t.imports.find(s=>s.name===n);return r?Wr(e,t,r.imported,[r.source]):[]}function $l(e,t,n,o){return Wr(e,t,o,[n.source,`${n.source}.${n.imported}`])}function Pl(e,t,n){let o=(e.wrappers.get(n)??[]).filter(l=>l.path===t.path);if(o.length>0)return o;let r=t.imports.find(l=>l.name===n);if(!r)return[];let s=e.wrappers.get(r.imported)??[],i=s.filter(l=>Wt(l.path,r.source));return i.length>0?i:s}function Ml(e,t,n,o){if(n.kind!=="system-arg"||!n.value)return!1;let r=Gr(e,t,n.value);for(let s of r)Le(o,s,{kind:"L1",callPath:t.path,callLine:n.line,callExcerpt:`system prompt ${n.value.text}`,wrapper:null,shortLabel:n.shortLabel??null,sdk:t.sdk,modelId:yt(e,t.path,n.line,null)});return r.length>0}function jl(e,t){return e.args.find(n=>n.name===t.paramName)??e.args.filter(n=>n.name===null)[t.paramIndex]}function Gr(e,t,n){return n.kind==="literal"&&n.siteStart!==null?t.sites.filter(o=>o.start===n.siteStart):n.kind==="identifier"?Kr(e,t,n.text):n.kind==="member"?Cl(e,t,n.text):[]}function Cl(e,t,n){let o=/^(\w+)\.(\w+)$/.exec(n);if(!o)return[];let r=t.imports.find(s=>s.name===o[1]);return r?$l(e,t,r,o[2]):/^(?:self|cls|this|[A-Z]\w*)$/.test(o[1])?Kr(e,t,o[2]):[]}function Nl(e,t,n){for(let o of t.wrapperCalls)for(let r of Pl(e,t,o.name)){let s=jl(o,r);if(s)for(let i of Gr(e,t,s))Le(n,i,{kind:"L2",callPath:t.path,callLine:o.line,callExcerpt:`${o.name}(\u2026)`,wrapper:r,shortLabel:o.shortLiterals.length===1?o.shortLiterals[0]:null,sdk:t.sdk||(e.byPath.get(r.path)?.sdk??!1),modelId:yt(e,t.path,o.line,r)})}}function Gn(e,t=!1){return e.filter(n=>n.sdk||n.callSites.some(o=>o.kind==="system-arg")).flatMap(n=>t?n.priorFileRefs??[]:n.fileRefs)}function qf(e,t){let n=e.flatMap(o=>dt(t,o.value).map(r=>({promptPath:r.path,readerPath:o.path})));return[...new Map(n.map(o=>[JSON.stringify(o),o])).values()]}function Br(e,t){let n=e.files.flatMap(o=>o.sites.filter(r=>r.kind==="file"));if(n.length!==0)for(let o of Gn(e.files)){let r=e.byPath.get(o.path);for(let s of dt(n,o.value))Le(t,s,{kind:"L3",callPath:r.path,callLine:o.line,callExcerpt:o.value,wrapper:null,shortLabel:null,sdk:r.sdk,modelId:yt(e,r.path,o.line,null)})}}function Ur(e,t={}){let n=new Map;for(let a of e.flatMap(c=>c.wrappers))n.set(a.name,[...n.get(a.name)??[],a]);let o={byPath:new Map(e.map(a=>[a.path,a])),files:e,wrappers:n},r=new Map,s=[];for(let a of e){for(let c of a.callSites)c.kind!=="system-arg"||Ml(o,a,c,r)||c.value&&c.value.kind!=="literal"&&s.push({path:a.path,line:c.line});Nl(o,a,r)}let i;if(t.includePrior&&e.some(a=>a.priorDeliveries!==void 0)){let a=e.map(f=>f.priorDeliveries===void 0?f:{...f,deliveries:f.priorDeliveries,fileRefs:f.priorFileRefs??f.fileRefs,promptBindings:void 0,loadedPromptRefs:void 0}),c={...o,files:a,byPath:new Map(a.map(f=>[f.path,f]))};i=new Map(r),Br(c,i),Kn(c,i)}Br(o,r),Kn(o,r);let l=new Set([...r.values()].flat().filter(a=>a.kind==="L4").map(a=>`${a.callPath}:${a.callLine}`));return{links:r,...i?{priorLinks:i}:{},callsWithoutPrompt:s.filter(a=>!l.has(`${a.path}:${a.line}`))}}var St={named:3,prose:2,file:3,link:4,sdk:1},Tl=6,Fl=3,zr={L1:0,L2:1,L4:1.5,L3:2};function kt(e,t){return e<t?-1:e>t?1:0}function Dl(e){return[...e].sort((n,o)=>zr[n.kind]-zr[o.kind]||Number(o.sdk)-Number(n.sdk)||kt(n.callPath,o.callPath)||n.callLine-o.callLine)[0]??null}function Bl(e){return(e.named?St.named:0)+(e.prose?St.prose:0)+(e.kind==="file"?St.file:0)}function Un(e,t,n){let o=Dl(t),r=n||t.some(i=>i.sdk),s=Bl(e)+(o?St.link:0)+(r?St.sdk:0);return s<Fl?null:{tier:s>=Tl?"strong":"possible",score:s,prompt:e,link:o&&{kind:o.kind,callPath:o.callPath,callLine:o.callLine,callExcerpt:o.callExcerpt,...o.callStart!==void 0?{callStart:o.callStart}:{},wrapper:o.wrapper,shortLabel:o.shortLabel},sdk:r,modelId:o?.modelId??null,...o?.alsoLoads?.length?{alsoLoads:o.alsoLoads}:{},...o?.shape?{shape:o.shape}:{}}}function qt(e,t){return(t.selectionScore??t.score)-(e.selectionScore??e.score)||kt(e.prompt.path,t.prompt.path)||e.prompt.line-t.prompt.line}function Xr(e,t){let n={files:e},o=new Map(e.map(a=>[a.path,a])),r=t.flatMap(a=>{let c=a.link;if(c?.kind!=="L4")return[];let f=o.get(c.callPath),u=f?.deliveries?.find(h=>h.line===c.callLine&&`${h.callee}(\u2026)`===c.callExcerpt&&(c.callStart===void 0||h.callStart===c.callStart));if(!u)return[];let p=f?.stepCalls?.find(h=>h.callStart===u.callStart&&h.line===u.line);return[{path:c.callPath,candidate:a,delivery:u,enclosingStart:p?.enclosingStart}]}),s=new Map;for(let a of r){let c=a.delivery.enclosing;c&&s.set(c,[...s.get(c)??[],a])}let i=new Map,l=(a,c,f)=>{let u=Z(a.candidate.prompt),p=Z(c.candidate.prompt);if(u===p)return;let h=i.get(u)??[];h.some(m=>m.to===p&&m.kind===f)||h.push({to:p,kind:f}),i.set(u,h)};for(let a of e){let c=r.filter(p=>p.path===a.path),f=[...a.stepCalls??[]];for(let{delivery:p}of c)f.some(h=>Jr(h,p))||f.push({callee:p.callee,line:p.line,callStart:p.callStart,enclosing:p.enclosing,resultVar:p.resultVar,argNames:[]});f.sort((p,h)=>p.line-h.line||(p.callStart??0)-(h.callStart??0));let u=new Map;for(let p of f){let h=p.localTarget===null?[]:ve(n,a,p.callee,s).filter(w=>p.localTarget===void 0||w.enclosingStart===p.localTarget),m=c.filter(w=>w.delivery.enclosing!==null&&w.delivery.enclosing===p.enclosing&&(w.enclosingStart===void 0||p.enclosingStart===void 0||w.enclosingStart===p.enclosingStart));for(let w of m)for(let k of h)l(w,k,"calls");let g=`${p.enclosing??""}:${p.enclosingStart??""}`,x=u.get(g)??new Map;for(let w of p.argNames){let k=x.get(w);if(!(!k||p.argCalls&&Object.hasOwn(p.argCalls,w)&&p.argCalls[w]!==k.callStart))for(let b of k.steps)for(let S of h)l(b,S,"feeds")}p.resultVar&&x.set(p.resultVar,{steps:[...h,...c.filter(w=>Jr(p,w.delivery))],callStart:p.callStart}),u.set(g,x)}}return i}function Jr(e,t){return e.line===t.line&&e.callee===t.callee&&(t.callStart===void 0||e.callStart===t.callStart)}function zn(e){let{links:t,callsWithoutPrompt:n,priorLinks:o}=Ur(e,{includePrior:!0}),r=new Set([...t.values()].flatMap(f=>f.flatMap(u=>u.alsoLoads??[]))),s=[];for(let f of e)for(let u of f.sites){if(r.has(u.path)&&!(t.get(Z(u))??[]).some(h=>h.kind!=="L3"))continue;let p=Un(u,t.get(Z(u))??[],f.sdk);if(p&&o){let h=Un(u,o.get(Z(u))??[],f.sdk);h?.score!==p.score&&(p.selectionScore=h?.score??0)}p&&s.push(p)}s.sort(qt);let i=Xr(e,s);for(let f of s){let u=i.get(Z(f.prompt));u?.length&&(f.links=u)}let l=e.flatMap(f=>f.modelIds).sort((f,u)=>kt(f.path,u.path)||f.line-u.line),a=Gn(e,!0),c=e.flatMap(f=>f.snippets??[]).map(f=>{let u=zn([f.hits]),p={path:f.hits.path,span:f.span,imports:f.hits.imports,status:"unresolved"};return{...u,strong:u.strong.map(h=>({...h,documentation:p})),possible:u.possible.map(h=>({...h,documentation:p})),documentation:p}});return{...a.length?{filenameReferences:a}:{},strong:[...s.filter(f=>f.tier==="strong"),...c.flatMap(f=>f.strong)].sort(qt),possible:[...s.filter(f=>f.tier==="possible"),...c.flatMap(f=>f.possible)].sort(qt),callsWithoutPrompt:[...n,...c.flatMap(f=>f.callsWithoutPrompt)].sort((f,u)=>kt(f.path,u.path)||f.line-u.line),repoModelIds:l,...c.length?{documentedImports:c.map(f=>f.documentation)}:{},scanned:e.length}}import{posix as Et}from"node:path";var Wl=40,Kl=new Set(["const","let","var","function","class","default","async","interface","enum"]);function Gl(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++){if(!y(n[r],"export"))continue;let s=0,i=t?n.length:Math.min(n.length,r+Wl);for(let l=r+1;l<i&&(d(n[l],"{")&&s++,d(n[l],"}")&&s--,!(d(n[l],";")||(!t||s===0)&&y(n[l])&&Kl.has(n[l].text)));l++)if((!t||s===0)&&y(n[l],"from")&&K(n[l+1])){o.push(n[l+1].value);break}}return o}function Vt(e,t,n,o=!1){let r=U(e,t,n),s=J(r);return n==="js"?[...s,...Gl(r,o).map(i=>({source:i,names:[]}))]:s}function wt(e,t){let{toks:n}=e;if(d(n[t],"(")){let o=Jn(e,t+1);return o&&d(n[o.next],")")?{...o,next:o.next+1}:null}return d(n[t],"[")?zl(e,t):Jn(e,t)}function Jn(e,t){let{toks:n}=e,o=[],r=t;for(;K(n[r]);)o.push(n[r]),r++,d(n[r],"+")&&K(n[r+1])&&r++;return o.length===0?null:{start:o[0].start,line:o[0].line,endLine:o[o.length-1].endLine,text:o.map(s=>s.value).join(""),partStarts:o.map(s=>s.start),next:r,...o.some(Xn)?{filledAtRunTime:!0}:{}}}function Xn(e){return!!e.formatted&&(e.kind==="template"||Ul(e.value))}function Ul(e){for(let t=0;t<e.length;t++)if(e[t]==="{"){if(e[t+1]==="{"){t++;continue}return e.indexOf("}",t+1)>=0}return!1}function bt(e,t,n=e.toks.length){let{toks:o}=e;if(e.lang==="py")for(;t<n&&d(o[t],"(");)t++;if(e.lang==="py"&&y(o[t],"lambda")){for(let r=t+1;r<n;r++){if(d(o[r],":"))return r+1;["(","[","{"].some(s=>d(o[r],s))&&(r=A(o,r))}return null}if(e.lang!=="js")return null;for(;t<n;){let r=y(o[t],"async")?t+1:t,s=d(o[r],"(")?A(o,r):-1,i=s>=0?s+1:y(o[r])?r+1:-1;if(d(o[i],":")){let l=Math.min(n,i+me);for(;i<l&&!d(o[i],"=");)i++}if(i>=0&&i+2<n&&d(o[i],"=")&&d(o[i+1],">"))return i+2;if(s<0)return null;t=r+1,n=Math.min(n,s)}return null}function zl(e,t){let{toks:n}=e,o=t+1;if(!d(n[o],"{"))return null;let r=A(n,o),s=d(n[r+1],",")?r+2:r+1;if(!d(n[s],"]"))return null;for(let i=o+1;i<r;i++){let l=n[i];if((y(l)&&l.text==="text"||l.kind==="string"&&l.value==="text")&&d(n[i+1],":")){let c=Jn(e,i+2);return c&&{...c,next:s+1}}}return null}var qn={kind:"other",text:"",siteLine:null,siteStart:null};function te(e,t,n,o=e.toks.length,r=!1){let{toks:s}=e,i=r?bt(e,n,o):null,l=wt(e,i??n);if(i!==null&&(!l||!t.has(l.start)))return qn;if(l&&l.next<=o){let f=t.get(l.start)??null;return{kind:"literal",text:we(l.text),siteLine:f,siteStart:f===null?null:l.start}}if(!y(s[n]))return qn;let a=n+1,c=!1;for(;;){let f=d(s[a],"?")&&d(s[a+1],".")?a+1:a;if(!d(s[f],".")||!y(s[f+1]))break;a=f+2,c=!0}return a<o&&!Jl(s[a],z(s,a))?qn:{kind:c?"member":"identifier",text:e.text.slice(s[n].start,s[a-1].end),siteLine:null,siteStart:null}}function Jl(e,t){return t||e.kind==="punct"&&",)}];".includes(e.text)}var qr=new Set(["system","systemPrompt","system_prompt","instructions"]);function Vn(e,t){let n=Ae(e.toks[t-2]);if(n===null||!qr.has(n)||Vr(e,t-2)!==t)return!1;let o=X(e,t-2);if(e.lang==="py"&&e.toks[t-2].kind==="ident")return Q(e.toks,o-1,e)&&!d(e.toks[t-3],".");if(!d(e.toks[o],"{"))return!1;let r=X(e,o);if(!Q(e.toks,r-1,e))return!1;let s=o-1;return e.lang==="py"&&(d(e.toks[s],"*")&&d(e.toks[s-1],"*")||d(e.toks[s],"=")&&y(e.toks[s-1]))&&(s-=2),s===r||d(e.toks[s],",")}function xe(e,t,n,o=!1,r=!1){let s=[];return e.toks.forEach((i,l)=>{let a=Vr(e,l);if(a===null)return;let c=Xl(e,n,a,r&&Vn(e,a)),f=o?ql(e,l):null;s.push({valueAt:a,site:{kind:"system-arg",path:e.path,line:i.line,value:c,enclosing:oe(t,l),...f?{shortLabel:f}:{}}})}),s}function Xl(e,t,n,o){let{toks:r}=e,s=te(e,t,n,r.length,o);if(s.kind!=="other")return s;if(d(r[n],"[")){let l=A(r,n);for(let a=n+1;a<l;a++)if(Ae(r[a])==="text"&&d(r[a+1],":"))return te(e,t,a+2)}let i=d(r[n+1],"?")&&d(r[n+2],"?")||d(r[n+1],"|")&&d(r[n+2],"|");return y(r[n])&&i?te(e,t,n,n+1):s}var Ae=e=>e?.kind==="string"?e.value:e?.kind==="ident"?e.text:null;function ql(e,t){let{toks:n}=e,o=0;for(let r=t-1;r>=0;r--){let s=n[r];if(s.kind==="punct"){if(")]}".includes(s.text))o++;else if("([{".includes(s.text)){if(o>0){o--;continue}let i=e.lang==="js"&&d(s,"{")?r-1:r;return!d(n[i],"(")||!Vl(e,i-1)||e.lang==="js"&&i===r?null:Hl(e,r)}}}return null}function Vl(e,t){let{toks:n}=e;if(e.lang==="js"&&d(n[t],">")){let o=0;do d(n[t],">")&&!d(n[t-1],"=")?o++:d(n[t],"<")&&o--,t--;while(t>=0&&o>0)}return y(n[t],"Agent")}function Hl(e,t){let{toks:n}=e;for(let{from:o,to:r}of C(n,t).reverse()){let s=n[o],i=(y(s,"get")||y(s,"set"))&&(Ae(n[o+1])==="name"||d(n[o+1],"["));if(d(s,".")||d(s,"[")||d(s,"*")||i)return null;if(Ae(s)!=="name")continue;let l=e.lang==="py"?T(n,o+1):d(n[o+1],":"),a=n[o+2];if(!l||r!==o+3||a?.kind!=="string")return null;let{prefix:c,closed:f}=Ue(a);return f&&!/[fb]/i.test(c)&&a.value.trim()||null}return null}function Vr(e,t){let{toks:n}=e,o=n[t],r=Ae(o),s=l=>T(n,l),i=l=>d(n[l],":")||e.lang==="py"&&s(l);return r!==null&&qr.has(r)?(e.lang==="py"&&o.kind==="ident"?s(t+1):i(t+1))?e.lang==="js"&&Zl(e,t)?null:t+2:e.lang==="js"&&o.kind==="ident"&&(d(n[t-1],"{")||d(n[t-1],","))&&(d(n[t+1],",")||d(n[t+1],"}"))&&!Tn(e,t)?t:null:r==="role"&&i(t+1)&&n[t+2]?.kind==="string"&&n[t+2].value==="system"?Yl(e,t+3):(d(o,"(")||d(o,"["))&&n[t+1]?.kind==="string"&&n[t+1].value==="system"&&d(n[t+2],",")?t+3:y(o,"SystemMessage")&&d(n[t+1],"(")?Ae(n[t+2])==="content"&&i(t+3)?t+4:t+2:null}function Yl(e,t){let{toks:n}=e;if(!d(n[t],",")||Ae(n[t+1])!=="content")return null;let o=n[t+2];return d(o,":")||d(o,"=")?t+3:null}function Zl(e,t){let n=e.toks[t+2];return y(n)&&Ir(n.text)||Tn(e,t)}function Hr(e,t,n,o,r={}){let s=W(e);if(!s)return[];let i=U(e,t,s),{toks:l}=i,a=J(i),c=q(i,{includeMembers:!0}),f=_t(i,"default");f?.name==="default"&&c.push(f),c.sort((g,x)=>g.from-x.from||x.to-g.to);let u=[],p=na(i),h=ta(i,o),m=g=>c.filter(x=>x.params!==null&&x.from<g&&g<x.to).at(-1)?.name??null;for(let g of Vt(e,t,s,!0)){let x=a.find(S=>S.source===g.source&&S.names.join("\0")===g.names.join("\0")),w=x?.names.map(S=>({name:S,imported:x.defaultName===S?"default":x.renamed?.[S]??S}))??ea(i,g.source),k=x?.line??l.find(S=>S.kind==="string"&&S.value===g.source)?.line??1,b=Ql(i,k);for(let{name:S,imported:_}of w){let E=he(e,g.source,[_],s,n,!0)??null,O={from:e,to:E,symbol:S,imported:_,source:g.source,...E?{}:{reason:g.source.startsWith(".")?"missing":"external"}},R=l.some((v,P)=>P>b&&y(v,S)&&T(l,P+1))||c.some(v=>v.name===S&&v.from>b&&!c.some(P=>P.from<v.from&&v.from<P.to&&(P.params!==null||P.kind==="class")));if(R)continue;let I=Yr(i,S);for(let v of I)u.push({...O,symbol:v,kind:"import",usage:"reexport",within:null,span:{from:k,to:k}});let L=x?l.flatMap((v,P)=>!R&&y(v,S)&&P>b&&!["def","function","class"].includes(l[P-1]?.text??"")&&(!d(l[P-1],".")||d(l[P-2],".")&&d(l[P-3],"."))&&!c.some(j=>j.from<P&&P<j.to&&j.params?.includes(S))?[P]:[]):[];if(!L.length&&!I.length){let v=ne(r,"CF_IMPORT_LEXICAL_FACTS")?m(l.findIndex(P=>P.line===k)):null;u.push({...O,kind:"import",usage:v?"reference":"reexport",within:v,span:{from:k,to:k}})}for(let v of L){let P=p.find(M=>M.from<=v&&v<M.to),j=!h||h.from<=(P?.at??v)&&(P?.at??v)<h.to,N=P&&!j&&(P.kind!=="tool-registration"||h?.to===0),$=P&&(j||N)?P.kind:"import";u.push({...O,...N?{reason:"unlinked"}:{},kind:$,usage:Q(l,v,i)?"call":"reference",within:m(v),span:{from:Math.min(l[P?.at??v].line,l[v].line),to:Math.max(l[P?.at??v].endLine,l[v].endLine)}})}}if(!w.length){let S=he(e,g.source,[],s,n,!0)??null;u.push({from:e,to:S,kind:"import",symbol:"*",imported:"*",source:g.source,usage:"reexport",within:null,span:{from:k,to:k},...S?{}:{reason:g.source.startsWith(".")?"missing":"external"}})}}for(let g=0;g<l.length;g++)!y(l[g])||!["import","import_module","require"].includes(l[g].text)||!d(l[g+1],"(")||l[g+2]?.kind==="string"&&d(l[g+3],")")||u.push({from:e,to:null,kind:"import",symbol:"*",imported:"*",source:"",usage:"call",within:m(g),reason:"dynamic",span:{from:l[g].line,to:l[g].endLine}});return u.filter((g,x)=>u.findIndex(w=>JSON.stringify(w)===JSON.stringify(g))===x)}function Ql(e,t){let{toks:n}=e,o=n.findIndex(r=>r.line===t);for(let r=o;r<n.length;r++){if(e.lang==="py"&&n[r].line>t)return r-1;if(d(n[r],";")||e.lang==="js"&&n[r].kind==="string")return r}return n.length-1}function ea(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++){if(!y(n[r],"export"))continue;let s=r+1;if(!d(n[s],"{"))continue;let i=A(n,s);!y(n[i+1],"from")||n[i+2]?.value!==t||o.push(...C(n,s).flatMap(l=>y(n[l.from])?[{name:n[l.to-1].text,imported:n[l.from].text}]:[]))}return o}function Yr(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++)if(!(!y(n[r],"export")||!d(n[r+1],"{"))&&!y(n[A(n,r+1)+1],"from"))for(let s of C(n,r+1))y(n[s.from],t)&&o.push(n[s.to-1].text);return o}function _t(e,t){let n=q(e),{toks:o}=e;if(t==="default"){let s=o.findIndex((i,l)=>y(i,"default")&&y(o[l-1],"export"));if(s>=0){let i=s+1;y(o[i],"async")&&i++;let l=y(o[i],"function"),a=l?i+1:i;if(y(o[a])&&(t=o[a].text),d(o[a],"(")){let c=A(o,a),f=l?c+1:c+3;if(l||d(o[c+1],"=")&&d(o[c+2],">")){let u=d(o[f],"{")?A(o,f)+1:o.findIndex((p,h)=>h>=f&&d(p,";"));return{name:"default",line:o[i].line,from:i,to:u<0?o.length:u,params:C(o,a).map(p=>y(o[p.from])?o[p.from].text:null),kind:"function"}}}}}let r=n.find(s=>s.name===t);if(r)return r;for(let s of n)if(Yr(e,s.name).includes(t))return s;return null}function ta(e,t){if(!t||t.path!==e.path)return null;let{toks:n}=e,o=new Set([t.symbol]);for(let a of J(e))for(let c of a.names)(a.renamed?.[c]??c)===t.symbol&&o.add(c);let r=new Map;t.promptPath===e.path&&t.promptStart!==void 0&&r.set(t.promptStart,t.line??1);let s=xe(e,[],r).filter(({site:a})=>(t.line===void 0||a.line===t.line)&&(a.value?.kind==="identifier"&&o.has(a.value.text)||a.value?.siteStart!=null&&a.value.siteStart===t.promptStart)),i=s.length===1?s[0].valueAt:void 0,l=[];for(let a=0;a<n.length;a++){if(!Q(n,a,e))continue;let c=A(n,a+1);(t.callStart!==void 0?n[a].start===t.callStart:i!==void 0?a<i&&i<c:t.line!==void 0&&n[a].line<=t.line&&(n[c]?.endLine??0)>=t.line)&&l.push({from:a,to:c+1})}return i!==void 0||t.callStart!==void 0?l.at(-1)??{from:0,to:0}:l.length===1?l[0]:{from:0,to:0}}function na(e){let{toks:t}=e,n=[],o=(r,s,i)=>{if(s&&(n.push({...s,at:r,kind:i}),s.to===s.from+1&&y(t[s.from]))){let l=t.flatMap((a,c)=>y(a,t[s.from].text)&&d(t[c+1],"=")?[c+2]:[]);l.length===1&&d(t[l[0]],"[")&&n.push({from:l[0],to:A(t,l[0])+1,at:r,kind:i})}};for(let r=0;r<t.length;r++){let s=t[r].kind==="string"?t[r].value:t[r].text;if(["tools","state_schema","context_schema","config_schema","model_config","llm_config"].includes(s)&&(d(t[r+1],"=")||d(t[r+1],":"))){let l=r+2,a=d(t[l],"[")?A(t,l)+1:l+1;o(r,{from:l,to:a},s==="tools"?"tool-registration":"config")}if(!d(t[r+1],"("))continue;let i=C(t,r+1);["add_node","addNode"].includes(s)&&o(r,i[1],"graph-node"),["StateGraph"].includes(s)&&o(r,i[0],"config"),["bind_tools","bindTools","ToolNode"].includes(s)&&o(r,i[0],"tool-registration")}return n}function Cp(e){return[...e].filter(t=>Et.basename(t)==="langgraph.json")}function Qr(e,t,n,o={}){if(Et.basename(e)==="langgraph.json")return oa(e,t,n,o.root);if(W(e)!=="py")return[];let r=U(e,t,"py"),{toks:s}=r,i=q(r),l=re(r,i,{enclosingBindings:!0}),a=o.root?`${o.root}/llm_config.yaml`:"llm_config.yaml",c=[],f=new Map;for(let u of l.calls){if(u.callee.includes("."))continue;let p=l.importBinding(u.callee,u.from);p?.module.source!=="chainlite"||p.name!=="llm_generation_chain"||s.some((h,m)=>y(h,u.callee)&&h.line!==p.module.line&&!d(s[m+1],"(")&&l.importBinding(u.callee,m)?.module===p.module)||s.some((h,m)=>y(h,"import")&&d(s[m+1],"*"))||f.set(u.callee,[...f.get(u.callee)??[],u.from])}for(let[u,p]of f){let h=o.call?.path===e?o.call:void 0,m=p.filter(g=>h?.callStart!==void 0?s[g].start===h.callStart:h?.line===void 0||s[g].line===h.line);for(let g of p){let x=A(s,g+1),w=i.filter(k=>k.params!==null&&k.from<g&&g<k.to).at(-1)?.name??null;c.push({from:e,to:n.has(a)?a:null,kind:"config",symbol:u,imported:"*",source:a,usage:"call",within:w,span:{from:s[g].line,to:s[Math.min(x,s.length-1)].endLine},...n.has(a)?h&&(m.length!==1||m[0]!==g)?{reason:"unlinked"}:{}:{reason:"missing"}})}}return c}function oa(e,t,n,o){let r=()=>[{from:e,to:null,kind:"graph-node",symbol:"graphs",imported:"*",source:"",usage:"reference",within:null,span:{from:1,to:Math.max(1,t.split(`
14
- `).length)},reason:"dynamic"}],s;try{s=JSON.parse(t)}catch{return r()}if(!Zr(s)||!Zr(s.graphs))return[];let i=s.graphs,l=U(e,t,"js"),{toks:a}=l,c=C(a,0).filter(u=>a[u.from]?.value==="graphs");if(c.length!==1)return r();let f=C(a,c[0].from+2);return f.map(u=>{let p=a[u.from].value,h=i[p],m=f.filter(k=>a[k.from].value===p).length!==1,g=typeof h=="string"?/^(.+):([A-Za-z_$][\w$]*)$/.exec(h):null,x=null,w;if(m||!g)w="dynamic";else if(/^[a-z][a-z\d+.-]*:\/\//i.test(g[1])||!g[1].includes("/")&&!W(g[1]))w="external";else{let k=Et.normalize(Et.join(Et.dirname(e),g[1]));!g[1].startsWith("/")&&!g[1].includes("\\")&&!/^[A-Za-z]:/.test(g[1])&&k!==".."&&!k.startsWith("../")&&B(k,o)!==null&&W(k)&&n.has(k)?x=k:w="missing"}return{from:e,to:x,kind:"graph-node",symbol:p,imported:g?.[2]??"*",source:typeof h=="string"?h:"",usage:"reference",within:p,span:{from:a[u.from].line,to:a[u.to-1].endLine},...w?{reason:w}:{}}})}function Np(e,t,n,o,r={}){let s=W(e);if(!s)return[];let i=U(e,t,s),{toks:l}=i,a=_t(i,n);if(!a||a.params!==null)return[];let c=l.findIndex((k,b)=>b>=a.from&&b<a.to&&T(l,b));if(c<0)return[];let f=y(l[c+1])&&d(l[c+2],".")&&y(l[c+3],"compile"),u=f?l[c+1].text:n,p=f?_t(i,u):a;if(!p||!l.slice(p.from,p.to).some(k=>y(k,"StateGraph")))return[];if([n,u].some(k=>l.filter((b,S)=>y(b,k)&&T(l,S+1)).length!==1))return[];let h=q(i),m=k=>h.filter(b=>b.params!==null&&b.from<k&&k<b.to).map(b=>b.from).join(","),g=[{from:p.from,to:p.to}];for(let k=0;k<l.length;k++)y(l[k],u)&&d(l[k+1],".")&&["add_node","addNode"].includes(l[k+2]?.text)&&d(l[k+3],"(")&&m(k)===m(p.from)&&g.push({from:k,to:A(l,k+3)+1});let x=[];for(let k of g)for(let b=k.from;b<k.to;b++){if(!["add_node","addNode"].includes(l[b]?.text)||!d(l[b+1],"(")||m(b)!==m(p.from))continue;let S=C(l,b+1)[1];if(!S||S.to!==S.from+1||!y(l[S.from]))continue;let _=l[S.from].text;!es(i,_)||l.some((O,R)=>y(O,_)&&T(l,R+1))||x.push({from:e,to:e,kind:"graph-node",symbol:_,imported:_,source:_,usage:"reference",within:null,span:{from:l[b].line,to:l[S.from].endLine}})}return[...Hr(e,t,o,void 0,r).filter(k=>(k.kind==="config"||k.kind==="graph-node")&&g.some(b=>l.slice(b.from,b.to).some(S=>y(S,k.symbol)&&S.line>=k.span.from&&S.line<=k.span.to))),...x].filter((k,b,S)=>S.findIndex(_=>JSON.stringify(_)===JSON.stringify(k))===b)}function Tp(e,t,n,o){let r=W(e);if(!r||o?.path!==e)return!1;let s=U(e,t,r),i=es(s,n);if(!i)return!1;let l=(a,c)=>o.callStart!==void 0?s.toks[a].start<=o.callStart&&s.toks[c-1].end>o.callStart:o.line!==void 0&&s.toks[a].line<=o.line&&s.toks[c-1].endLine>=o.line;return l(i.from,i.to)&&(o.callStart!==void 0||q(s).filter(a=>a.params!==null&&l(a.from,a.to)).length===1)}function es(e,t){let n=_t(e,t);return n&&n.params!==null&&q(e).filter(o=>o.name===n.name).length===1?n:null}function Zr(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}var Qe=50,ra=new Set(["replace","replaceAll","format","format_messages","formatMessages"]),sa=new Set(["withStructuredOutput","with_structured_output","bind","bind_tools","bindTools"]);function ts(e,t){let n=e.source,{toks:o}=n,r=(p,h)=>{let m=e.importBinding(p,h),g=m&&ae([m.module],n.lang).find(x=>x.name===p);return g?{namespace:m.namespace,importBinding:g}:null},s=p=>[...new Map(p.map(h=>[JSON.stringify(h),h])).values()].slice(0,Qe),i=p=>{let h=C(o,p),m=h.map(x=>o[x.from]);return!h.every(x=>(y(o[x.from])||o[x.from].kind==="string")&&(d(o[x.from+1],":")||y(o[x.from])&&x.to===x.from+1))||new Set(m.map(x=>x.value||x.text)).size!==m.length?null:h},l=(p,h)=>e.functions.some(m=>m.from<h&&h<m.to&&m.params?.includes(p)),a=(p,h)=>{let m=/^([A-Za-z_$][\w$]*)(\(\))?(?:\.([A-Za-z_$][\w$]*))?$/.exec(p.trim()),g=m&&r(m[1],h);return!m||!g?[]:[{kind:g.namespace&&m[3]&&!m[2]?"module-member":"symbol",callee:`${m[1]}${m[2]&&m[3]?"()":""}${m[3]?`.${m[3]}`:""}`,literals:[],importBinding:g.importBinding}]},c=(p,h,m)=>{let g=r(p,h);if(g)return[{kind:"symbol",callee:p,literals:[],importBinding:g.importBinding}];let x=e.binding(p,h);return x&&e.bindingIsCertain(x,h)&&!x.append&&!m.has(x.at)&&(!l(p,h)||e.owner(x.at)===e.owner(h))?f(x,new Set([...m,x.at])):[]},f=(p,h=new Set)=>{let m=fe(e,p),{from:g,to:x}=m;if(g>=x||!o[g])return[];let w=t.find(b=>b.start===o[g].start);if(K(o[g])&&x===g+1){let b=w?[{kind:"site",callee:"",literals:[],siteStart:w.start}]:[];if(x===g+1&&o[g].kind==="template")for(let S of o[g].value.matchAll(/\$\{([^{}]*)\}/g))b.push(...a(S[1],g));return s(b)}if(x===g+1&&y(o[g]))return c(o[g].text,g,h);let k=ee(e,m);if(k){let b=o[k.open-1].text;if(ra.has(b)&&d(o[k.open-2],"."))return f({from:k.from,to:k.open-2},h);let S=e.operations.find(_=>_.call.from===k.from&&_.call.to===k.to);if(S&&xt(e,k)){let _=ge(H(e,S.path),n.path);return _?[{kind:"bound-file",callee:k.callee,literals:[_]}]:[]}if(!k.args.length)return a(k.callee,g)}if(d(o[g],"[")&&A(o,g)===x-1)return s(C(o,g).flatMap(b=>f(b,h)));if(d(o[g],"{")&&A(o,g)===x-1){let b=i(g);if(!b)return[];let S=O=>b.find(R=>(y(o[R.from],O)||o[R.from]?.value===O)&&d(o[R.from+1],":")),_=S("role"),E=S("content");return _&&E&&["system","user"].includes(o[_.from+2]?.value)?f({from:E.from+2,to:E.to},h):[]}if(x===g+3&&y(o[g])&&d(o[g+1],".")&&y(o[g+2]))return a(`${o[g].text}.${o[g+2].text}`,g);if(d(o[x-2],".")&&y(o[x-1])){let b=ee(e,{from:g,to:x-2});if(b&&!b.args.length)return a(`${b.callee}().${o[x-1].text}`,g)}return[]},u=(p,h=new Set)=>{let m=fe(e,p),{from:g,to:x}=m;if(x===g+1&&y(o[g])){let E=o[g].text,O=e.binding(E,g);return!!O&&e.bindingIsCertain(O,g)&&!O.append&&!h.has(O.at)&&(!l(E,g)||e.owner(O.at)===e.owner(g))&&u(O,new Set([...h,O.at]))}let w=ee(e,m);if(!w)return!1;let k=o[w.open-1].text;if(sa.has(k))return u({from:w.from,to:w.open-2},h);let b=w.callee.split(".")[0],S=e.importBinding(b,g),_=w.callee.includes(".")?w.callee.split(".").at(-1):S?.name??b;return!!S&&Mt(S.module.source,n.lang)&&/^(?:Chat(?!Prompt|Message|History)|AzureChat|BaseChat|LLM)/.test(_)};return{values:f,modelValue:u,objectFields:i,unique:s}}var ia=new Set(["invoke","ainvoke","batch","abatch","stream","astream"]);function ns(e,t,n){let o=re(e,t,{enclosingBindings:!0}),{toks:r}=e,{values:s,modelValue:i,objectFields:l,unique:a}=ts(o,n),c=o.assignments.filter(m=>o.owner(m.at)===null).filter(m=>o.assignments.filter(g=>g.name===m.name&&o.owner(g.at)===null).length===1).filter(m=>o.bindingIsCertain(m,r.length)).map(m=>({name:m.name,loads:s(m,new Set([m.at]))})).filter(m=>m.loads.length).slice(0,Qe),f=[],u=Qr(e.path,e.text,new Set),p=(m,g,x=null)=>{if(!g.length||f.length===Qe)return;let w=o.assignments.find(k=>ee(o,k)===m);f.push({path:e.path,line:r[m.from].line,callStart:r[m.from].start,callee:m.callee,key:null,loads:a(g),model:x,shape:null,enclosing:o.owner(m.from)?.name??null,resultVar:w?.name??null})};for(let m of o.calls){if(u.some(g=>g.symbol===m.callee&&g.span.from===r[m.from].line)){let g=m.args[0],x=g&&H(o,g),w=m.args.find(k=>y(r[k.from],"engine")&&d(r[k.from+1],"="));x&&p(m,[{kind:"chainlite",callee:m.callee,literals:[x]}],w?te(e,new Map,w.from+2,w.to):null);continue}ia.has(r[m.open-1].text)&&d(r[m.open-2],".")&&i({from:m.from,to:m.open-2})&&m.args[0]&&p(m,s(m.args[0]))}for(let m=0;m<r.length&&c.length<Qe;m++){let g=y(r[m],"return")?o.owner(m):null;if(!g||o.owner(g.from)!==null||o.functions.filter(w=>w.name===g.name).length!==1||o.assignments.some(w=>w.name===g.name)||r.filter((w,k)=>y(w,"return")&&o.owner(k)===g).length!==1||r.slice(g.from,m).some(w=>w.kind==="ident"&&["if","for","while","switch","try","catch"].includes(w.text)))continue;if(d(r[m+1],"{")){let w=l(m+1);if(!w)continue;for(let k of w){let b=r[k.from];if(!y(b)&&b.kind!=="string")continue;let S=d(r[k.from+1],":")?k.from+2:k.from,_=s({from:S,to:k.to});_.length&&c.length<Qe&&c.push({name:`${g.name}.${b.value||b.text}`,loads:_})}continue}let x=s({from:m+1,to:ue(e,m+1)});x.length&&c.push({name:g.name,loads:x})}let h=o.operations.flatMap(m=>{if(!xt(o,m.call))return[];let g=ge(H(o,m.path),e.path);return g?[{value:g,path:e.path,line:m.line}]:[]});return{bindings:c,deliveries:f,loadedRefs:h}}function Ht(e,t,n){let o=e.split(`
15
- `),r=Math.min(Math.max(t-1-3,0),o.length-1),s=0;for(let i=0;i<r;i++)s+=o[i].length+1;return{text:e.slice(s,s+n),fromLine:r+1}}var la=new Map([["python","py"],["py","py"],["javascript","js"],["js","js"]]);function os(e,t,n){return t.filter(o=>/\.md$/i.test(o)&&Fo(e,o)&&be(e,o,n)?.kind==="example")}function Yt(e,t){if(!/\.md$/i.test(e))return[];let n=[],o,r=0,s=t.split(`
16
- `);for(let i=0;i<s.length;i++){let l=s[i].replace(/\r$/,""),a=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(l);if(a){let c=a[1][0],f=a[1].length,u=a[2].trim();o?c===o.marker&&f>=o.width&&!u&&(o.lang&&r>o.start&&n.push({path:e,lang:o.lang,start:o.start,end:r,span:{from:o.line,to:i}}),o=void 0):(c!=="`"||!u.includes("`"))&&(o={marker:c,width:f,lang:la.get(u.split(/\s+/)[0].toLowerCase()),start:r+s[i].length+1,line:i+2})}r+=s[i].length+1}return n}function id(e,t,n){let o=new Set(os(e,Object.keys(t)));if(!o.size)return t;let r=n.nodes.flatMap(s=>s.files??[]).filter(s=>s.role==="system prompt"&&s.span);return Object.fromEntries(Object.entries(t).map(([s,i])=>{if(!o.has(s))return[s,i];let l=r.filter(c=>c.path===s).map(c=>c.span),a=Yt(s,i).filter(c=>l.some(f=>c.span.from<=f.from&&f.to<=c.span.to));return a.length?[s,i.split(`
17
- `).map((c,f)=>a.some(u=>u.span.from<=f+1&&f+1<=u.span.to)?c:"").join(`
18
- `)]:[s,i]}))}function rs(e,t,n,o,r){if(!o||!os(e,[t]).length)return null;let s=Yt(t,n).find(l=>l.span.from<=o.from&&o.to<=l.span.to);if(!s)return null;let i=Ht(n.slice(s.start,s.end),o.from-s.span.from+1,r);return{text:i.text,fromLine:s.span.from+i.fromLine-1}}function ld(e,t){return e.split("").map((n,o)=>/[\r\n]/.test(n)||t.some(r=>r.start<=o&&o<r.end)?n:" ").join("")}var ss=200,is=300,Yn=/SYSTEM|PROMPT|INSTRUCTION/i,aa=/^\s*You(?:['’]re)?(?![\w'’])/;function ls(e,t,n={}){let o=n.minChars!==void 0,r=n.promptFunctions!==!1,s=[],i=new Map,l=new Set,a=(c,f)=>{l.has(c)||(l.add(c),s.push(f),i.set(c,f.span.from))};for(let c=0;c<e.toks.length;c++){let f=ca(e,c,o||r);if(!f)continue;let u=r?bt(e,f.valueAt):null,p=wt(e,u??f.valueAt);!p||p.text.length<(n.minChars??ss)||!o&&!Yn.test(e.toks[f.nameAt].text)&&!(u!==null&&Zt(p.text,!!p.filledAtRunTime))||(a(p.start,Hn(e,p,{named:!0,prose:Zt(p.text,r&&!!p.filledAtRunTime),line:e.toks[f.nameAt].line,symbol:e.toks[f.nameAt].text,enclosing:oe(t,f.declAt)},r&&!!p.filledAtRunTime)),p.partStarts.forEach(h=>l.add(h)))}return r&&e.toks.forEach((c,f)=>{let u=y(c,"return")?t.filter(w=>w.params!==null&&w.from<f&&f<w.to).sort((w,k)=>k.from-w.from)[0]:void 0,p=Vn(e,f);if(!u&&!p)return;let h=u?f+1:f,m=p?bt(e,h):null,g=wt(e,m??h);if(!g||g.text.length<(n.minChars??ss))return;let x=Zt(g.text,!!g.filledAtRunTime);u&&!o&&!Yn.test(u.name)&&!x||(a(g.start,Hn(e,g,{named:!!u||!x,prose:x,line:u?.line??g.line,symbol:u?.name??null,enclosing:u?.name??oe(t,f)},!!g.filledAtRunTime)),g.partStarts.forEach(w=>l.add(w)))}),e.toks.forEach((c,f)=>{if(!K(c)||l.has(c.start)||c.value.length<(n.minChars??is))return;let u=r&&Xn(c),p=Zt(c.value,u);if(!o&&!p)return;let h={start:c.start,line:c.line,endLine:c.endLine,text:c.value,partStarts:[c.start],next:f+1};a(c.start,Hn(e,h,{named:!1,prose:p,line:c.line,symbol:null,enclosing:oe(t,f)},u))}),s.sort((c,f)=>c.line-f.line),{sites:s,siteLineByStart:i}}function Zt(e,t=!1){let n=t?e.replace(/^(?:\s*\$?\{[^{}]*\})+\s*/,""):e;return e.length>=is&&aa.test(n)}function Hn(e,t,n,o=!1){return{kind:n.named?"named":"prose",...n,path:e.path,endLine:t.endLine,span:{from:t.line,to:t.endLine},start:t.start,chars:t.text.length,excerpt:we(t.text),...o?{filledAtRunTime:!0}:{}}}function ca(e,t,n){let{toks:o}=e,r=e.lang==="js";if(r&&!(y(o[t])&&["const","let","var"].includes(o[t].text)))return null;let s=r?t+1:t;if(!y(o[s])||!n&&!Yn.test(o[s].text)||!r&&!(z(o,t)&&ua(e,t)))return null;let i=s+1;if(d(o[i],":")){let l=i+me;for(;i<l&&i<o.length&&!T(o,i);)i++}return T(o,i)?{declAt:t,nameAt:s,valueAt:i+1}:null}function ua(e,t){let n=ke(e.text,e.toks[t]);if(n===0)return!0;for(let o=t-1;o>=0;o--)if(!(!z(e.toks,o)||ke(e.text,e.toks[o])>=n))return y(e.toks[o],"class");return!1}var fa=20,pa=/^(?:messages\.(?:create|stream)|chat\.completions\.create|responses\.create|generateText|streamText|Runner\.run)\(/,da=/\/v1\/(?:messages|chat\/completions)$/;function Qt(e,t,n,o={}){let{toks:r}=e,s=n.filter(a=>Mt(a.source,e.lang,o,e)),i=s.length>0,l=s.map(a=>({line:a.line,at:null}));return r.forEach((a,c)=>{if(K(a)){da.test(a.value)&&l.push({line:a.line,at:c});return}if(!y(a))return;let f=r.slice(c,c+7).map(m=>m.text).join(""),u=de.includes(r[c-1]?.text??""),p=i&&a.text==="query"&&r[c+1]?.text==="("&&r[c-1]?.text!==".";(pa.test(f)&&(a.text!=="Runner"||o.layouts===!0&&i)&&!u||p&&!u)&&l.push({line:a.line,at:c})}),l.sort((a,c)=>a.line-c.line),l.slice(0,fa).map(({line:a,at:c})=>({kind:"sdk",path:e.path,line:a,value:null,enclosing:c===null?null:oe(t,c)}))}function en(e,t,n){let o=[];for(let r of t){let{params:s}=r;if(s)for(let{site:i,valueAt:l}of n){if(i.value?.kind!=="identifier"||l<=r.from||l>=r.to)continue;let a=s.indexOf(i.value.text),c=o.some(f=>f.name===r.name&&f.paramIndex===a);a>=0&&!c&&o.push({name:r.name,paramIndex:a,paramName:i.value.text,path:e.path,line:r.line})}}return o}var ma=200,ha=40;function as(e,t,n,o){let{toks:r}=e,s=[];for(let i=0;i<r.length&&s.length<ma;i++){let l=r[i];if(!Q(r,i)||d(r[i-1],".")||de.includes(r[i-1]?.text??""))continue;let a=C(r,i+1).map(f=>ga(e,n,f));a.some(f=>f.kind==="literal"&&f.siteLine!==null||f.kind==="identifier"&&o.has(f.text))&&s.push({name:l.text,path:e.path,line:l.line,args:a,shortLiterals:a.filter(f=>f.kind==="literal"&&f.siteLine===null&&f.text.length>0&&f.text.length<=ha).map(f=>f.text),enclosing:oe(t,i)})}return s}function ga(e,t,n){let{toks:o}=e,r=e.lang==="py"&&y(o[n.from])&&T(o,n.from+1),s=r?n.from+2:n.from;return{...te(e,t,s,n.to),name:r?o[n.from].text:null}}var cs=50;function tn(e,t,n,o,r,s){let{toks:i}=e,l=new Set(t.map(u=>u.name)),a=u=>He(t,u),c=new Map(n.map(u=>[u.from,u])),f=new Set(s.map(u=>u.callStart));return n.filter(u=>l.has(u.callee)||r.has(u.callee.split(".")[0])||f.has(i[u.from].start)).slice(0,cs).map(u=>{let p=a(u.from),h=[...new Set(u.args.flatMap(R=>{let{from:I,to:L}=R;for(e.lang==="py"&&y(i[I])&&T(i,I+1)&&(I+=2);d(i[I],"(")&&A(i,I)===L-1;)I++,L--;if(!y(i[I]))return[];for(let v=I+1;v<L;v+=2)if(!d(i[v],".")||!y(i[v+1]))return[];return[i[I].text]}))].slice(0,cs),m=R=>o.findLast(I=>I.name===R&&I.at<u.from&&a(I.at)===p&&!(I.from<=u.from&&u.from<I.to)),g=R=>{let I=y(i[R.from],"await")?R.from+1:R.from,L=c.get(I);return!R.append&&L?.to===R.to?L:null},x=Object.fromEntries(h.flatMap(R=>{let I=m(R);if(!I)return[];let L=g(I);return[[R,L?i[L.from].start:null]]})),w=o.find(R=>g(R)===u),k=t.filter(R=>R.from<u.from&&u.from<R.to),b=t.filter(R=>R.name===u.callee&&(!a(R.from)||k.includes(a(R.from)))).sort((R,I)=>(a(I.from)?.from??-1)-(a(R.from)?.from??-1))[0],S=u.callee.split(".")[0],_=k.findLast(R=>R.params?.includes(S)||o.some(I=>I.name===S&&I.at<u.from&&a(I.at)===R)),E=_&&(!b||(a(b.from)?.from??-1)<_.from),O=E?null:b?i[b.from].start:null;return{callee:u.callee,resultVar:w?.name??null,argNames:h,enclosing:p?.name??null,line:i[u.from].line,callStart:i[u.from].start,...p?{enclosingStart:i[p.from].start}:{},...b||E||l.has(u.callee)?{localTarget:O}:{},...Object.keys(x).length?{argCalls:x}:{}}})}var $e=50,xa=200,us=new Set(["system","systemPrompt","system_prompt","instructions","prompt","template","template_file"]),ya=new Set(["model","engine","schema","response_format","output_type","outputSchema","tools","messages","max_tokens","maxTokens"]),Sa=new Set(["schema","response_format","output_type","outputSchema"]),fs=/(?:template|template_file|prompt_file)$/;function ps(e,t){let{toks:n}=e,o=t.filter(I=>I.params!==null),r=I=>He(o,I),s=Ye(e),i=new Map(s.map(I=>[I.from,I])),l=J(e),a=new Set(ae(l,e.lang).map(I=>I.name)),c=Qt(e,t,l).length>0,f=en(e,t,xe(e,t,new Map)),u=new Map(s.flatMap(I=>{let L=ka(e,I),v=f.find(j=>j.name===I.callee),P=L.filter(j=>c||v||L.some(N=>N.object===j.object&&ya.has(N.key)));return c||v||P.length?[[I,{fields:P,wrapper:v}]]:[]})),p=Gt(e),h=new Map(p.map(I=>[I.at,I])),m=new Map(p.filter(I=>!I.append).map(I=>[y(n[I.from],"await")?I.from+1:I.from,I.name])),g=Fr({},{[e.path]:e.text},{source:e,scopes:t},"operations"),x=Nr(g.operations),w=new Map(x.map(I=>[I.call.from,I.path])),k=[];for(let I of o){for(let L of x){if(r(L.call.from)!==I)continue;let v=Tr(L,I,e.lang);if(!(!v||k.some(P=>P.name===I.name&&P.line===I.line))&&(k.push({name:I.name,paramIndex:v.paramIndex,folder:v.folder,ext:v.ext,path:e.path,line:I.line}),k.length===$e))break}if(k.length===$e)break}let b=new Set(k.map(I=>I.name)),S=new Map,_=I=>[...new Map(I.map(L=>[JSON.stringify(L),L])).values()].slice(0,$e),E=I=>n.slice(I.from,I.to).filter(K).filter(L=>L.value.length<=xa).map(L=>L.value).slice(0,$e),O=[];for(let I=0;I<2;I++){let L=new Map;O=[];let v=(P,j)=>{let{from:N,to:$}=P;for(y(n[N],"await")&&N++;d(n[N],"(")&&A(n,N)===$-1;)N++,$--;if($===N+1&&y(n[N]))return L.get(j)?.get(n[N].text)??[];let M=i.get(N);if(M&&M.to===$){let je=w.get(N);if(je){let G=E(je);return Ze(G).length>0?[{kind:"read",callee:M.callee,literals:G}]:[]}if(u.get(M)?.fields.some(G=>us.has(G.key)||G.key==="messages"))return[];let Ce=M.args[0]?E(M.args[0]):[],Ne=a.has(M.callee.split(".")[0]),D=[...S.keys()].some(G=>G.name===M.callee);if(D||(b.has(M.callee)||Ne)&&(Ce.length>0||Ne&&M.args.length===0))return[{kind:D?"return":"loader",callee:M.callee,literals:Ce}]}return[]};for(let P=0;P<n.length;P++){let j=r(P),N=h.get(P);if(N){let{name:D,append:G}=N,pe=L.get(j)??new Map;pe.set(D,_([...G?pe.get(D)??[]:[],...v(N,j)])),L.set(j,pe)}if(y(n[P],"return")&&j&&!k.some(D=>D.name===j.name&&D.line===j.line)){let D=v({from:P+1,to:ue(e,P+1)},j);D.length&&(S.has(j)||S.size<$e)&&S.set(j,{fn:j.name,loads:_([...S.get(j)?.loads??[],...D]),path:e.path,line:j.line})}let $=i.get(P);if(!$||O.length===$e)continue;let M=u.get($);if(!M)continue;let{fields:je,wrapper:Ce}=M,Ne=(D,G,pe=!1)=>{let se=v(D,j);if(!se.length&&pe){let ie=E(D);Ze(ie).length>0&&(se=[{kind:"file-key",callee:$.callee,literals:ie}])}if(!se.length||O.length===$e)return;let Te=je.filter(ie=>D.object===void 0||ie.object===D.object),ye=Te.find(ie=>ie.key==="model"||ie.key==="engine"),pn=Te.find(ie=>Sa.has(ie.key)),ti=ye?te(e,new Map,ye.from,ye.to):null,Lo=pn?te(e,new Map,pn.from,pn.to):null,ni=Lo?.kind==="identifier"?Lo.text:null,oi=m.get($.from)??null;O.push({path:e.path,line:n[$.from].line,callStart:n[$.from].start,callee:$.callee,key:G,loads:se,model:ti,shape:ni,enclosing:j?.name??null,resultVar:oi})};for(let D of je)if((us.has(D.key)||fs.test(D.key))&&Ne(D,D.key,e.lang==="py"&&fs.test(D.key)),D.key==="messages")for(let G=D.from;G<D.to;G++){if(!d(n[G],"{"))continue;let pe=Zn(e,G),se=pe.find(ye=>ye.key==="role");if(!se||n[se.from]?.kind!=="string"||!["system","user"].includes(n[se.from].value))continue;let Te=pe.find(ye=>ye.key==="content");Te&&se.from<Te.from&&Ne({...Te,object:D.object},"content"),G=A(n,G)}Ce&&$.args[Ce.paramIndex]&&!je.length&&Ne($.args[Ce.paramIndex],null)}}let R=tn(e,o,s,p,a,O);return{loaders:k,promptReturns:[...S.values()],deliveries:O,stepCalls:R}}function Zn(e,t){let{toks:n}=e;return C(n,t).flatMap(({from:o,to:r})=>{let s=y(n[o])?n[o].text:n[o]?.kind==="string"?n[o].value:null;return s?d(n[o+1],":")||e.lang==="py"&&T(n,o+1)?[{key:s,from:o+2,to:r,object:t}]:r===o+1?[{key:s,from:o,to:r,object:t}]:[]:[]})}function ka(e,t){return e.lang==="py"?Zn(e,t.open):t.args.flatMap(n=>d(e.toks[n.from],"{")?Zn(e,n.from):[])}function Qn(e){return{path:e,sites:[],callSites:[],sdk:!1,sdkLine:null,wrappers:[],wrapperCalls:[],imports:[],modelIds:[],fileRefs:[]}}function ms(e,t,n={}){try{if(n.coverageLinks===!0&&n.documented===!0&&/\.md$/i.test(e)){let o=Yt(e,t).map(r=>({span:r.span,hits:ds(e,t.slice(0,r.start).replace(/[^\r\n]/g," ")+t.slice(r.start,r.end),n,r.lang)}));return{...Qn(e),snippets:o}}return ds(e,t,n)}catch{return Qn(e)}}function ds(e,t,n,o=W(e)){if(!o){let S=hr(e,t);return{...Qn(e),sites:S?[S]:[]}}let r=U(e,t,o),s=q(r,{promptFunctions:n.promptFunctions!==!1}),i=J(r),l=ae(i,o),{sites:a,siteLineByStart:c}=ls(r,s,n),f=Qt(r,s,i,n.sdk),u=xe(r,s,c,n.sdk?.layouts===!0&&f.length>0,n.promptFunctions!==!1),p=new Set([...a.flatMap(S=>S.symbol?[S.symbol]:[]),...l.map(S=>S.name)]),h=n.promptLoaders!==!1?ps(r,s):null,m=n.coverageLinks===!0&&h?ns(r,s,a):null,g=[...h?.deliveries??[],...m?.deliveries??[]],x=m?re(r,s):null,w=x?tn(r,x.functions,x.calls,x.assignments,new Set(l.map(S=>S.name)),g):h?.stepCalls,k=br(r),b=n.promptLoaders!==!1?_r(r):[];return{path:e,sites:a,callSites:[...u.map(S=>S.site),...f].sort((S,_)=>S.line-_.line),sdk:f.length>0,sdkLine:f.length>0?f[0].line:null,wrappers:en(r,s,u),wrapperCalls:as(r,s,c,p),imports:l,modelIds:k.modelIds,fileRefs:m?k.promptFileRefs:k.fileRefs,...h?.loaders.length?{loaders:h.loaders}:{},...h?.promptReturns.length?{promptReturns:h.promptReturns}:{},...g.length?{deliveries:g}:{},...m?{priorDeliveries:h?.deliveries??[],priorFileRefs:k.fileRefs}:{},...w?.length?{stepCalls:w}:{},...m?.bindings.length?{promptBindings:m.bindings}:{},...m?.loadedRefs.length?{loadedPromptRefs:m.loadedRefs}:{},...b.length?{modelMembers:b}:{}}}var hs=e=>e.CF_CODE_PROMPT_FUNCTIONS!=="0";var wa=20;function nn(e,t){let n=new Set(t),o=new Set;for(let[r,s]of Object.entries(e)){let i=W(r);if(i)for(let l of Vt(r,s,i)){let a=he(r,l.source,l.names,i,n);a!==void 0&&o.add(a)}}return[...o].sort()}function im(e,t,n){return nn(e,t).filter(o=>!jo(o,n)).slice(0,wa)}function ba(e,t){let n=Fe(e),o=n?n.split("/"):[],r=t.split("/").slice(0,-1),s=0;for(;s<o.length&&s<r.length&&o[s]===r[s];)s++;return o.slice(0,s).join("/")}function lm(e,t,n){let o=hs(n),r=zn(Object.entries(t).map(([l,a])=>ms(l,a,{promptFunctions:o}))),s=r.strong[0]??r.possible[0];if(!s)return null;let i=s.prompt.path;return{suggestedDir:ba(e,i),file:i,symbol:s.prompt.symbol}}function am(e,t){let n=t.suggestedDir||"the repository root";return`no agent prompt in ${e}; its code imports ${t.file}, which defines ${t.symbol??"a prompt"} \u2014 import ${n} to include it`}function eo(e,t){if(!t||!d(e[t.from],"{")||A(e,t.from)!==t.to-1)return null;let n=new Map;for(let o of C(e,t.from)){let r=e[o.from];if(!(y(r)||r?.kind==="string")||!d(e[o.from+1],":"))return null;let s=r.kind==="string"?r.value:r.text;if(n.has(s))return null;n.set(s,{from:o.from+2,to:o.to})}return n}function Pe(e,t,n=0){if(!t||n>32)return;let{from:o,to:r}=t,s=e[o];if(s?.kind==="string"&&Ue(s).closed){if(r===o+1)return s.value;if(d(e[o+1],"+")){let a=Pe(e,{from:o+2,to:r},n+1);if(typeof a=="string")return s.value+a}}if(r===o+1){if(s?.kind==="number"){let a=Number(s.text.replace(/_/g,""));return Number.isFinite(a)?a:void 0}if(y(s,"true"))return!0;if(y(s,"false"))return!1;if(y(s,"null"))return null}if(d(s,"[")&&A(e,o)===r-1){let a=C(e,o).map(c=>Pe(e,c,n+1));return a.includes(void 0)?void 0:a}let i=eo(e,t);if(!i)return;let l=[...i].map(([a,c])=>[a,Pe(e,c,n+1)]);return l.some(([,a])=>a===void 0)?void 0:Object.fromEntries(l)}function gs(e,t){let n=eo(e,t);if(!n)return null;let o=Pe(e,n.get("type"));if(o==="function"&&n.has("function")&&(n=eo(e,n.get("function"))),!n)return null;let r=n.get("input_schema")??(o==="function"?n.get("parameters"):void 0);if(!r)return null;let s=Pe(e,n.get("name")),i=Pe(e,n.get("description"));if(typeof s!="string"||!s.trim()||typeof i!="string")return{tools:[],warnings:["Some tools couldn't be read from code"]};let l=Pe(e,r),a=l!==null&&typeof l=="object"&&!Array.isArray(l);return{tools:[{name:s,description:i,...a?{input_schema:l}:{}}],warnings:a?[]:[`${s}'s arguments couldn't be read from code`]}}function oo(e,t){y(e[t],"as")&&y(e[t+1],"const")&&(t+=2);let n=e[t];return n===void 0||n.kind==="punct"&&",;)}]".includes(n.text)||y(n)&&n.line>(e[t-1]?.endLine??n.line)&&!["as","satisfies"].includes(n.text)}function to(e,t,n){for(;d(e[t],".");)t++;return y(e[t])?[e[t].text]:!d(e[t],"{")&&!d(e[t],"[")?[]:C(e,t).filter(o=>o.from<o.to&&o.to<=n).flatMap(o=>{let r=o.from;return d(e[t],"{")&&d(e[r+1],":")&&(r+=2),to(e,r,o.to)})}function no(e,t){let{toks:n}=e,o=new Map,r=new Map,s=new Map,i=[];for(let l=0;l<n.length;l++){if(d(n[l],"{")?i.push(l):d(n[l],"}")&&i.pop(),!y(n[l])||!["const","let","var"].includes(n[l].text))continue;let a=i.at(-1);if(t!==void 0&&a!==void 0&&(t<a||t>A(n,a)))continue;let c=y(n[l+1])?l+2:A(n,l+1)+1,f=to(n,l+1,c).filter(p=>t===void 0||(r.get(p)??-1)<=i.length);for(let p of f)o.set(p,null),r.set(p,i.length),s.set(p,l);if(!y(n[l],"const")||!y(n[l+1])||!f.length)continue;let u=n[l+1].text;for(let p=l+2;p<Math.min(n.length,l+40)&&!d(n[p],";");p++)if(d(n[p],"=")){o.set(u,null),r.set(u,i.length),d(n[p+1],"[")&&oo(n,A(n,p+1)+1)&&(o.set(u,p+1),r.set(u,i.length));break}}if(t!==void 0)for(let l of q(e)){if(l.params===null||t<=l.from||t>=l.to)continue;let a=l.params.filter(c=>c!==null);if(l.params.includes(null)){let c=n.findIndex((f,u)=>u>l.from&&u<t&&d(f,"("));c>=0&&a.push(...Pt(n,c,"js").flatMap(({from:f,to:u})=>to(n,f,u)))}for(let c of a)(s.get(c)??-1)<=l.from&&o.set(c,null)}return o}function _a(e){let{toks:t}=e,n=new Map;for(let o=0;o<t.length;o++){if(!y(t[o],"export"))continue;let r=no(e,o);if(y(t[o+1],"const")){let s=t[o+2]?.text,i=r.get(s);i!=null&&n.set(s,i)}else if(y(t[o+1],"default")){let s=d(t[o+2],"[")?o+2:r.get(t[o+2]?.text),i=d(t[o+2],"[")?A(t,o+2)+1:o+3;s!=null&&oo(t,i)&&n.set("default",s)}else if(d(t[o+1],"{"))for(let s of C(t,o+1)){let i=r.get(t[s.from]?.text);i!=null&&n.set(t[s.to-1].text,i)}}return n}function xs(e,t,n){return n.has(e[t.from]?.start)&&d(e[t.from+1],"(")&&A(e,t.from+1)===t.to-1}function Ea(e,t){let n=t?.call;if(!n)return;let{toks:o}=e;if(n.loadedPrompt&&n.callStart!==void 0){let u=o.findIndex(p=>p.start===n.callStart);if(u<0)return;for(;d(o[u+1],".")&&y(o[u+2]);)u+=2;return Q(o,u,e)?{from:u+1,to:A(o,u+1)+1}:void 0}let r=new Set([n.symbol]),s=new Set(Object.keys(t.imports));for(let u of J(e)){let p=he(e.path,u.source,u.names,"js",s);if(!(n.promptPath&&p!==n.promptPath))for(let h of u.names)((u.renamed?.[h]??h)===n.symbol||p===n.promptPath&&h===u.defaultName)&&r.add(h)}let i=n.promptPath===e.path&&n.promptStart!==void 0?new Map([[n.promptStart,n.line??1]]):new Map,l=xe(e,[],i).filter(({site:u})=>n.line===void 0||u.line===n.line),a=(l.find(({site:u})=>u.value?.siteStart!=null&&u.value.siteStart===n.promptStart)??l.find(({site:u})=>u.value&&r.has(u.value.text))??l[0])?.valueAt;if(a===void 0)return;let c,f;for(let u=0;u<a;u++){if(!d(o[u],"(")&&!d(o[u],"{"))continue;let p=A(o,u)+1;p<=a||(d(o[u],"{")?c={from:u,to:p}:f={from:u,to:p})}return f??c}function ys(e,t,n,o){let r=U(t?.path??"tools.ts",e,"js"),{toks:s}=r,i=t?.call?.loadedPrompt?new Set(q(r).filter(S=>S.params!==null).map(S=>S.name)):new Set,l=no(r),a=new Map,c=t?.imports??{},f=new Set(Object.keys(c));for(let S of J(r)){let _=he(r.path,S.source,S.names,"js",f);if(_===void 0)continue;let E=U(_,c[_],"js"),O=o(c[_]);for(let[R,I]of _a(E))for(let L of S.names)(S.defaultName===L?"default":S.renamed?.[L]??L)===R&&a.set(L,{toks:E.toks,open:I,path:_,calls:O})}let u=new Set,p=new Set,h=[],m="Some tools couldn't be read from code",g=Ea(r,t),x=!1;for(let S=0;S<s.length;S++){if(g&&(S<g.from||S>=g.to))continue;let _=s[S];if(["input_schema","parameters"].includes(_.kind==="string"?_.value:_.text)&&d(s[S+1],":")&&d(s[S+2],"{")){S=A(s,S+2);continue}if((y(_,"tools")||_.kind==="string"&&_.value==="tools")&&d(s[S+1],":")){x=!0;let E=s[S+2],O=no(r,S),R=d(E,"[")?S+2:y(E)?O.get(E.text):void 0,I=d(E,"[")?A(s,S+2)+1:S+3;if(!oo(s,I)){h.push(m);continue}R==null?y(E)&&!O.has(E.text)&&a.has(E.text)?p.add(E.text):h.push(m):u.add(R)}}if(!x)for(let S of l.values())S!==null&&C(s,S).some(_=>gs(s,_)||xs(s,_,n))&&u.add(S);let w=[],k=new Map,b=[...u].map(S=>({toks:s,open:S,calls:n,path:null}));b.push(...[...p].map(S=>a.get(S)));for(let{toks:S,open:_,calls:E,path:O}of b){let R=L=>h.push(O?`${O}: ${L}`:L),I=A(S,_);if(!d(S[I],"]")){R(m);continue}for(let L of C(S,_)){let v=gs(S,L),P=xs(S,L,E),j=L.to===L.from+1&&y(S[L.from])?S[L.from].text:null,N=x&&O===null&&j&&i.has(j)?{name:j,description:""}:null;if(!v&&!P&&!N)R(m);else{let $=v?v.tools:N?[N]:x&&P?[E.get(S[L.from].start)]:[];for(let M of $)k.has(M.name)||k.set(M.name,O??r.path);w.push(...$),v?.warnings.forEach(R)}}}return{tools:w,warnings:h,selected:x,from:Object.fromEntries(k)}}var It=String.raw`(?:"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')`,Ia=new RegExp(String.raw`(${It}|`+"`(?:[^`\\\\]|\\\\.)*`)"+String.raw`|\/\/[^\n]*|\/\*[\s\S]*?\*\/`,"g"),Oa=/(?<![\w$])tool\s*(<[^()]*>)?\(/g,Ra=new RegExp(`^${It}$`),La=new RegExp(`^${It}(?:\\s*\\+\\s*${It})*$`),va={n:`
19
- `,t:" ",r:"\r"};function Ss(e){return e.slice(1,-1).replace(/\\(.)/g,(t,n)=>va[n]??n)}function Aa(e){return e.replace(Ia,(t,n)=>n?n[0]+"_".repeat(n.length-2)+n[n.length-1]:" ".repeat(t.length))}function ks(e,t){let n=0;for(let o=t;o<e.length;o++){let r=e[o];if("([{".includes(r))n++;else if(")]}".includes(r)){if(n===0)return o;n--}else if(r===","&&n===0)return o}return e.length}function ws(e){let t=Aa(e),n=[],o=[],r=new Map,s="a tool( call in tools.ts was skipped: its name and description are not plain text";for(let i of t.matchAll(Oa)){let l=t.slice(Math.max(0,i.index-40),i.index).trimEnd();if(l.endsWith(".")&&!l.endsWith("...")||i[1]){o.push(s);continue}let c=ks(t,i.index+i[0].length),f=c+1,u=ks(t,f),p=e.slice(i.index+i[0].length,c).trim(),h=e.slice(f,u).trim();if(t[c]!==","||!Ra.test(p)||!La.test(h)){o.push(s);continue}let m=h.match(new RegExp(It,"g")),g={name:Ss(p),description:m.map(Ss).join("")};n.push(g),r.set(i.index,g)}return{tools:n,warnings:o,readCalls:r}}function bs(e,t){let{tools:n,warnings:o}=_s(e,t);return{tools:n,warnings:o}}function _s(e,t){let{tools:n,warnings:o,readCalls:r}=ws(e),s=new Map(n.map(({name:l})=>[l,t?.path??"tools.ts"])),i=ys(e,t,r,l=>ws(l).readCalls);if(i.selected)return i;n.push(...i.tools),o.push(...i.warnings);for(let[l,a]of Object.entries(i.from))s.has(l)||s.set(l,a);return{tools:n,warnings:o,from:Object.fromEntries(s),selected:!1}}function km(e,t,n){let o=Object.fromEntries(e.filter(u=>W(u)==="js"&&t[u]!==void 0).map(u=>[u,t[u]])),r=nn(o,Object.keys(t)),s=u=>{let p=Object.fromEntries(nn({[u]:t[u]},Object.keys(t)).filter(m=>r.includes(m)).map(m=>[m,t[m]])),h=_s(t[u],{path:u,imports:p,...n?.path===u?{call:n}:{}});return{...h,warnings:h.warnings.map(m=>`${u}: ${m}`)}},i=Object.keys(o).map(s),l=i.filter((u,p)=>u.selected&&(!n||Object.keys(o)[p]===n.path)),a=l.length?l:[...i,...r.filter(u=>!o[u]).map(s)],c=new Map;return{tools:a.flatMap(u=>u.tools.filter(p=>c.has(p.name)?!1:(c.set(p.name,u.from[p.name]),!0))),from:Object.fromEntries(c),warnings:[...new Set(a.flatMap(u=>u.warnings))]}}function Es(e){let t;try{t=JSON.parse(e)}catch{return{tools:[],warnings:[".cli.json is not valid JSON; ignored"]}}let n=t?.clis;return!n||typeof n!="object"||Array.isArray(n)?{tools:[],warnings:[]}:{tools:Object.entries(n).map(([r,s])=>{let i=s?.description;return{name:r,description:typeof i=="string"?i:""}}),warnings:[]}}var $a=/\.(ts|tsx|js|jsx|mjs|cjs|py|go|rs|rb|java|kt|swift|c|cc|cpp|h|hpp|cs|php|sh|bash|zsh|ps1|sql|tf|hcl|lock|toml|gradle)$/i,Pa=/\.(md|mdx|txt|json|ya?ml)$/i,Ma=/^(licen[cs]e.*|copying|notice|authors|codeowners|readme|changelog|\.gitignore|\.gitattributes|\.editorconfig|\.gitkeep|\.nvmrc|\.python-version|\.tool-versions|\.prettierrc|\.npmignore|\.dockerignore)$/i;function ro(e){return $a.test(e.trim())}function _m(e){return!ro(e)&&Pa.test(e.trim())}function Em(e){let t=e.trim();return!Se(t)&&!Ma.test(t.split("/").at(-1))&&!/\.(md|mdx|txt|text|jsonl?|ndjson|csv|tsv|pdf|rst|adoc|ini|cfg|ya?ml|toml|lock|png|jpe?g|gif|svg|ico|webp|avif|bmp|tiff?)$/i.test(t)}var ja=["stripe","slack","postgresql","datadog","pagerduty","jira","googlecalendar"],Ca=new Set(ja);function rn(e){if(!e)return null;let t=e.trim().toLowerCase();return Ca.has(t)?t:null}function Na(e,t){let n=[...e.warnings],o=new Set(e.nodes.map(l=>l.id)),r=new Set,s=e.nodes.map(l=>{let a=[],c=new Set;for(let f of l.tools??[]){let u=f.label.trim();if(!u){n.push(`${t}: dropped a tool with no name on ${l.id}`);continue}let p=`${f.source??"tool"}:${u}`;if(c.has(p)){n.push(`${t}: ${l.id} lists ${u} twice \u2014 kept one`);continue}c.add(p);let h=rn(f.brand);f.brand&&!h&&!r.has(f.brand)&&(r.add(f.brand),n.push(`${t}: "${f.brand}" is not a provider mark we can draw \u2014 those tools render without one`)),a.push({label:u,brand:h,...f.source?{source:f.source}:{}})}return{...l,tools:a}}),i=e.edges.filter(l=>{let a=o.has(l.from)&&o.has(l.to);return a||n.push(`${t}: dropped edge ${l.from} \u2192 ${l.to} (unknown endpoint)`),a});return e.nodes.some(l=>l.kind==="agent")||n.push(`${t}: the mapping found no agent node \u2014 the graph may be incomplete`),{fragment:{...e,nodes:s,edges:i,warnings:[]},warnings:n}}var on=2e4;function Is(e){return e.trim().replace(/^(?:\.?\/)+/,"")}function Ta(e,t,n,o={}){let r=[],s=new Map;for(let c of Object.keys(t))s.set(Is(c),c);let i={},l=so(e),a=e.nodes.map(c=>{let f=[],u=[];for(let p of c.files??[]){let h=p.path.trim();if(!h)continue;let m=s.get(Is(h));if(m===void 0){r.push(`${n}: node ${c.id} lists ${h} as a definition file, which the analysis never read \u2014 dropped`);continue}let g=t[m],x=g.length>on,w=(p.role==="system prompt"?rs(o,m,g,p.span,on):null)??(x&&p.span&&p.role==="system prompt"&&ro(m)?Ht(g,p.span.from,on):null),k=w?w.text:x?g.slice(0,on):g;x&&!io(m,l)&&r.push(`${n}: node ${c.id}'s ${p.role} file (${m}) is ${g.length} characters \u2014 stored truncated at ${k.length}`),f.push({role:p.role,label:p.label??null,path:m,...p.span?{span:p.span}:{},...p.filledAtRunTime?{filledAtRunTime:!0}:{}}),u.push({...p.filledAtRunTime?{filledAtRunTime:!0}:{},role:p.role,...p.label?{label:p.label}:{},path:m,tokens:Mo(g.length),text:k,...x?{truncated:!0,storedChars:k.length}:{},...p.span?{span:p.span}:{},...w?{fromLine:w.fromLine}:{}})}return u.length&&(i[c.id]=u),{...c,files:f}});return{fragment:{...e,nodes:a},nodes:i,warnings:r}}function Fa(e){let t=[],n=[];for(let{repoKey:o,fragment:r,files:s}of e){let i=l=>`${o}#${l}`;for(let l of r.nodes){let a=s?.[l.id],c=(l.tools??[]).map(f=>({label:f.label,...f.brand?{brand:f.brand}:{},...f.source?{source:f.source}:{}}));t.push({id:i(l.id),label:l.label,kind:l.kind,desc:l.desc,meta:l.meta,...l.sourcePaths?{sourcePaths:l.sourcePaths}:{},sourceRef:l.sourceRef?{repo:o,path:l.sourceRef.path,line:l.sourceRef.line}:null,...a?.length?{files:a}:{},...c.length?{tools:c}:{}})}for(let l of r.edges)n.push({from:i(l.from),to:i(l.to),kind:l.kind,label:l.label,sourceRef:l.sourceRef?{repo:o,path:l.sourceRef.path,line:l.sourceRef.line}:null})}return{nodes:t,edges:n}}var Da={critical:0,high:1,medium:2,low:3};function lo(e){return Da[e]}function Os(e){let t=e?.trim();return t&&t.length<=280?t:null}var Ba=2,ao=4,co=120,Rs="Which should the agent do?",Wa="asked to pose a question, answered with one fix";function Ls(e){if(!kn(e.category))return{question:null,fixes:e.fixes,warnings:[]};let t=`finding "${e.title}"`;if(e.fixes.length<Ba)return{question:null,fixes:e.fixes,warnings:[`${t}: ${Wa}`]};let n=[],o=e.fixes;o.length>ao&&(n.push(`${t}: ${o.length} options proposed; keeping the first ${ao}`),o=o.slice(0,ao));let r=(e.question??"").trim();return r?r.length>co&&(n.push(`${t}: the question is longer than ${co} characters; cut`),r=`${r.slice(0,co-1).trimEnd()}\u2026`):(n.push(`${t}: no question with ${o.length} options; asking "${Rs}"`),r=Rs),{question:r,fixes:o,warnings:n}}function fo(e){let t=e.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");return[e.kind,e.siteRepo??"-",e.site?.path??"-",t].join("|")}var Me=e=>e.legacyFingerprint??e.fingerprint,et=e=>e.replace(/\s+/g," ").trim(),Ka=new Set("a an and are as at be been being but by can could do does for from has have in is it its of on or that the their them then there these they this those to until was were which while will with would".split(" ")),Ot=new Set(["before","after","instead","from","to","than"]),$s=new Set([...Ot,"no","not","never","cannot","without"]),Ga=/^(?:send(?:s|ing)?|sent|delet(?:e[sd]?|ing)|refund(?:s|ed|ing)?|grant(?:s|ed|ing)?|revok(?:e[sd]?|ing)|return(?:s|ed|ing)?|rout(?:e[sd]?|ing)|read(?:s|ing)?|writ(?:e[sd]?|ing)|charg(?:e[sd]?|ing)|block(?:s|ed|ing)?|allow(?:s|ed|ing)?|skip(?:s|ped|ping)?|select(?:s|ed|ing)?|check(?:s|ed|ing)?|request(?:s|ed|ing)?)$/,po=e=>e.split(/[.!?;,\n]+|\b(?:and|but|while)\b/);function tt(e){return Ga.test(e)?e==="sent"?"send":e.replace(/(?:ing|ped|ed|es|s)$/,"").replace(/^skipp$/,"skip").replace(/^(delet|revok|rout|writ|charg)$/,"$1e"):null}function nt(e){let t=(e.toLowerCase().replaceAll("can't","cannot").match(/[a-z0-9_]+/g)??[]).filter(n=>!Ka.has(n)||Ot.has(n)).map(n=>tt(n)??n);return t.map((n,o)=>["not","never","cannot"].includes(n)&&tt(t[o+1]??"")!==null?"skip":n)}function uo(e){return new Set(nt(e))}function Ua(e){return[...uo(e)].filter(t=>tt(t)!==null).sort()}function za(e){return po(e).filter(t=>nt(t).some(n=>Ot.has(n))).map(t=>nt(t).join(" ")).sort()}function Ja(e,t){let n=o=>o!=="refund"&&tt(o)!==null;return po(e).flatMap(o=>{let r=nt(o);return r.flatMap((s,i)=>{if(!n(s))return[];let l=r.slice(i+1),a=l.findIndex(g=>n(g)||$s.has(g)),c=l.slice(0,a<0?l.length:a).filter(g=>t.has(g)),f=["skip","no","not","never","cannot","without"].includes(r[i-1]??""),u=a<0?[]:l.slice(a),p=u.findIndex(g=>n(g)),h=u.slice(0,p<0?u.length:p),m=h.flatMap((g,x)=>{if(!Ot.has(g))return[];let w=h.slice(x+1),k=w.findIndex(b=>Ot.has(b));return[JSON.stringify([g,w.slice(0,k<0?w.length:k).filter(b=>t.has(b))])]});return c.length?[{action:s,objects:c,denied:f,relations:m}]:[]})}).sort((o,r)=>JSON.stringify(o).localeCompare(JSON.stringify(r)))}function Xa(e){let t=nt(e);return["before","after","instead"].filter(n=>t.includes(n)).concat(t.some((n,o)=>["no","not","never","cannot","without"].includes(n)||n==="skip"&&tt(t[o+1]??"")!==null)?["negative"]:[])}function sn(e){let t=et(e.cause??"").toLowerCase(),n=[...new Set(e.sites.map(s=>et(s.quote).toLowerCase()))].sort((s,i)=>i.length-s.length||s.localeCompare(i));for(let s of n)t=t.replaceAll(s,"");let o=uo(t),r=uo(e.sites.map(s=>s.quote).join(" "));return{text:t,terms:o,operators:t.match(/!==|===|!=|==|<=|>=|<|>/g)??[],actions:Ua(t),direction:Xa(t),relations:za(t),anchors:[...o].filter(s=>r.has(s)).sort(),numbers:[...o].filter(s=>/^\d+$/.test(s)).sort(),objects:po(t).map(s=>nt(s).filter(i=>r.has(i)&&tt(i)===null&&!$s.has(i)).join(" ")).filter(Boolean).sort(),bindings:Ja(t,r)}}function Ps(e,t){let[n,o]=[sn(e),sn(t)];if(Math.min(n.terms.size,o.terms.size)<3||!n.anchors.length)return!1;for(let s of["operators","actions","direction","relations","anchors","numbers","objects","bindings"])if(JSON.stringify(n[s])!==JSON.stringify(o[s]))return!1;let r=[...n.terms].filter(s=>o.terms.has(s));return n.text===o.text||r.length>=4&&r.length/Math.max(n.terms.size,o.terms.size)>=.7}function qa(e){return[...new Set(e.map(t=>JSON.stringify([t.repoKey,t.path,et(t.quote)])))].sort()}function ln(e){return e.omittedSites||!e.sites.length||e.sites.some(t=>t.verified===!1||!t.path||!et(t.quote)||!Number.isInteger(t.startLine)||t.startLine<1||!Number.isInteger(t.endLine)||t.endLine<t.startLine)?null:qa(e.sites)}function Va(e,t){if(!e.kind||e.kind!==t.kind||!e.category||e.category!==t.category||(e.agentId??null)!==(t.agentId??null))return!1;let[n,o]=[ln(e),ln(t)];return n!==null&&o!==null&&JSON.stringify(n)===JSON.stringify(o)&&Ps(e,t)}function Ha(e,t){if(e.kind!==t.kind||e.category!==t.category||(e.agentId??null)!==(t.agentId??null))return!0;let[n,o]=[ln(e),ln(t)];return n!==null&&o!==null&&JSON.stringify(n)!==JSON.stringify(o)?!0:n===null||o===null?!1:Ms(e,t)}function Ms(e,t){let[n,o]=[sn(e),sn(t)],r=(i,l)=>i.some(a=>!l.includes(a))&&l.some(a=>!i.includes(a));for(let i of["actions","anchors","numbers","operators"])if(r(n[i],o[i]))return!0;for(let i of n.actions.filter(l=>o.actions.includes(l))){let l=n.bindings.filter(c=>c.action===i),a=o.bindings.filter(c=>c.action===i);if(l.length&&a.length&&l.every(c=>a.every(f=>r(c.objects,f.objects)||c.denied!==f.denied||r(c.relations,f.relations))))return!0}for(let i of new Set(n.bindings.map(l=>JSON.stringify(l.objects)))){let l=a=>a.bindings.filter(c=>JSON.stringify(c.objects)===i).map(c=>c.action);if(r(l(n),l(o)))return!0}let s=i=>i.direction.filter(l=>l!=="negative");return!!r(s(n),s(o))}function Wm(e){for(let f of[e.previous,e.current])if(f.some(u=>!u.id||!u.fingerprint)||new Set(f.map(u=>u.id)).size!==f.length)throw new Error("Missing or duplicate finding identities.");let t=e.previous.flatMap(f=>e.current.flatMap(u=>(Me(f)===Me(u)?!e.enabled||!Ha(f,u):e.enabled&&Va(f,u))?[{previous:f,current:u}]:[])),n=[],o=new Set,r=new Set,s=(f,u)=>{for(let p of f)f.filter(h=>h.previous.id===p.previous.id).length!==1||f.filter(h=>h.current.id===p.current.id).length!==1||(n.push({previousId:p.previous.id,currentId:p.current.id,fingerprint:e.enabled?p.previous.fingerprint:Me(p.previous),reason:u}),o.add(p.previous.id),r.add(p.current.id))};s(t.filter(f=>Me(f.previous)===Me(f.current)),"legacy");let i=t.filter(f=>!o.has(f.previous.id)&&!r.has(f.current.id));e.enabled&&s(i,"meaning");let l=i.filter(f=>!o.has(f.previous.id)&&!r.has(f.current.id)),a=new Map;for(let f of l){let u=l.filter(m=>m.current.id===f.current.id).map(m=>m.previous.id).sort(),p=l.filter(m=>m.previous.id===f.previous.id).map(m=>m.current.id).sort(),h={reason:"ambiguous",previousIds:u,currentIds:p};a.set(JSON.stringify(h),h)}n.sort((f,u)=>f.previousId.localeCompare(u.previousId)||f.currentId.localeCompare(u.currentId));let c=new Map(n.map(f=>[f.currentId,f]));return{matches:n,unmatchedPrevious:e.previous.filter(f=>!o.has(f.id)),unmatchedCurrent:e.current.filter(f=>!r.has(f.id)),currentIdentities:e.current.map(f=>({currentId:f.id,legacyFingerprint:Me(f),matchedFingerprint:c.get(f.id)?.fingerprint??Me(f),matchedId:c.get(f.id)?.previousId??f.id})),diagnostics:[...a.entries()].sort(([f],[u])=>f.localeCompare(u)).map(([,f])=>f)}}var js=e=>[...e.site?[{...e.site,excerpt:e.excerpt}]:[],...e.otherSites??[]];function vs(e){let t=js(e),n=new Map;for(let o of t){let r=JSON.stringify([o.path,o.line??null]);(!n.has(r)||(o.line??0)>0&&o.excerpt?.trim())&&n.set(r,o)}return[...n.values()].sort((o,r)=>o.path.localeCompare(r.path)||(o.line??-1)-(r.line??-1))}function Km(e,t){if(e.category!==t.category)return!1;let[n,o]=[vs(e),vs(t)];return n.length===o.length&&n.every((r,s)=>r.path===o[s].path&&(r.line==null||o[s].line==null?r.line==o[s].line:Math.abs(r.line-o[s].line)<=3))}function Gm(e,t){let[n,o]=[As(e,"a"),As(t,"b")];if((n.agentId??null)!==(o.agentId??null)||Ms(n,o))return!1;let r=(f,u)=>f.omittedSites&&!!u.excerpt?.trim()||f.sites.some(p=>!!p.quote.trim()&&(!p.path||!Number.isInteger(p.startLine)||p.startLine<1||p.verified===!1));if(r(n,e)||r(o,t))return!1;let s=f=>{let u=new Map;for(let p of f.sites){if(!p.quote.trim())continue;let h=JSON.stringify([p.repoKey,p.path,p.startLine]);(!u.has(h)||u.get(h).endLine<p.endLine)&&u.set(h,p)}return[...u.values()]},[i,l]=[s(n),s(o)].sort((f,u)=>f.length-u.length);if(!i.length||e.category!==t.category&&i.length<2||i.length===1&&et(e.cause).toLowerCase()!==et(t.cause).toLowerCase()&&!Ps(n,o))return!1;let a=(f,u)=>f.repoKey===u.repoKey&&f.path===u.path&&f.startLine<=u.endLine&&u.startLine<=f.endLine,c=(f,u)=>f===i.length||l.some((p,h)=>u.has(h)||!a(i[f],p)?!1:c(f+1,new Set([...u,h])));return c(0,new Set)}function As(e,t){return{id:t,fingerprint:fo(e),kind:e.kind,title:e.title,category:e.category,cause:e.cause,agentId:e.agentId,omittedSites:+!e.site,sites:js(e).map(n=>({repoKey:n.repo??e.siteRepo??"",path:n.path,startLine:n.line??0,endLine:(n.line??0)+(n.excerpt?.split(`
20
- `).length??1)-1,quote:n.excerpt??"",...n.verified!==void 0?{verified:n.verified}:{}}))}}var Ya="users";function Cs(e){let t=$o.safeParse(e);return t.success?t.data:Ya}function Ns(e,t){if(mn(t))return Cs(e)}function Za(e){let t={users:[],team:[]};for(let n of e)t[Cs(n.audience)].push(n);return t}function Xm(e){if(!e.every(t=>t===void 0))return e.every(t=>t==="team")?"team":"users"}function mo(e,t,n,o,r){if(t===null)return null;let s=e.safeParse(t);return s.success?s.data:(r.push(`${o}: ${n} "${t}" is not one of ${Object.values(e.enum).join(", ")} \u2014 dropped`),null)}var go=12,Ts=3,ho=3;function Fs(e,t){return Object.keys(e).find(n=>e[n].has(t))}function Qa(e,t,n=go,o={}){let r=[],s=e;if(gn(o)){let c=e.filter(f=>f.category==="better_as_code");if(c.length>Ts){let f=c.sort((p,h)=>lo(p.severity)-lo(h.severity)).slice(0,Ts),u=0;s=e.flatMap(p=>p.category!=="better_as_code"?[p]:u<f.length?[f[u++]]:[])}}let i=s.slice(0,n);s.length>n&&!(gn(o)&&n>go)&&r.push(`the model proposed ${s.length} findings; keeping the first ${n}`);let l=c=>{let f=(c.otherSites??[]).flatMap(h=>{let m=xn.safeParse(h);return m.success?[m.data]:(r.push(`finding "${c.title}" listed an other site in a shape we could not read \u2014 dropped`),[])});f.length>ho&&r.push(`finding "${c.title}" quoted ${f.length} other sites; keeping the first ${ho}`);let u=f.slice(0,ho).flatMap(h=>{let m=Fs(t,h.path);return m?[{...h,repo:m}]:(r.push(`finding "${c.title}" also cited ${h.path}, which the analysis never read \u2014 that site dropped`),[])});if(!c.site)return{...c,siteRepo:null,otherSites:u};let p=Fs(t,c.site.path);return p?{...c,siteRepo:p,otherSites:u}:(r.push(`finding "${c.title}" cited ${c.site.path}, which the analysis never read \u2014 site dropped`),{...c,site:null,excerpt:c.excerpt,siteRepo:null,otherSites:u})};return{findings:i.map(c=>{let{audience:f,...u}=l(c),p=Ns(f,o),h=Ls(u);return r.push(...h.warnings),{...u,...p===void 0?{}:{audience:p},summary:Os(u.summary),fixes:h.fixes,question:h.question}}),warnings:r}}function ec(e){let t=e.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),n=[...new Set(e.targetFiles.map(o=>o.path.trim().replace(/^(\.\/)+/,"")))].sort().join(`
21
- `);return[e.kind,t,n].join("|")}function tc(e,t,n){if(!e)return{delta:null,warnings:[]};let o=[],r=[];for(let l of e.nodes){let a=mo(hn,l.change,`delta node ${l.id} change`,n,o);if(a){if(a!=="added"&&!t.has(l.id)){o.push(`${n}: dropped delta node ${l.id} (not in the architecture)`);continue}r.push({id:l.id,change:a,label:l.label})}}let s=new Set([...t,...r.map(l=>l.id)]),i=[];for(let l of e.edges){let a=`${l.from} \u2192 ${l.to}`,c=mo(hn,l.change,`delta edge ${a} change`,n,o),f=mo(Po,l.kind,`delta edge ${a} kind`,n,o);if(!(!c||!f)){if(!s.has(l.from)||!s.has(l.to)){o.push(`${n}: dropped delta edge ${a} (unknown node)`);continue}i.push({from:l.from,to:l.to,kind:f,change:c,detail:l.detail})}}return r.length===0&&i.length===0?{delta:null,warnings:o}:{delta:{nodes:r,edges:i},warnings:o}}function nc(e){return fo(e)}function oc(e){let t=e.split(`
22
- `);return t.length>1&&t[t.length-1]===""&&t.pop(),t.map((n,o)=>`${o+1} ${n}`).join(`
23
- `)}function an(e){return{label:e,brand:rn(e)}}function kh(e,t,n,o,r){let s=[],i=a=>{s.push(...a.tools.map(c=>c.name)),r.push(...a.warnings.map(c=>`${t}: ${c}`))};if(o.toolsPath)try{s.push(...kr(n[o.toolsPath]).tools.map(a=>a.name))}catch{r.push(`${t}: tools.json is not a valid tool list; ignored`)}o.toolsTsPath&&i(bs(n[o.toolsTsPath])),o.cliPath&&i(Es(n[o.cliPath]));let l=[];if(o.mcpPath){let a=Sr(n[o.mcpPath],o.mcpPath,o.toolsPath!==null);l.push(...a.servers),r.push(...a.warnings.map(c=>`${t}: ${c}`))}return[...new Set(s)].map(an).concat(l.map(a=>({...an(a),source:"mcp"})))}function Ds(e){let t=e.sourceRef?.repo?`${e.sourceRef.repo}#`:null;return e.unitKey??(t&&e.id.startsWith(t)?e.id.slice(t.length):e.id.startsWith("model:")?e.id:e.id.slice(e.id.indexOf("#")+1))}function Bs(e){return Ds(e).startsWith("model:")}function so(e){return new Set(e.nodes.filter(Bs).flatMap(t=>[...(t.files??[]).map(n=>n.path),...t.sourceRef?[t.sourceRef.path]:[]]))}function io(e,t){let n=e.trim().replace(/^(\.\/)+/,"");if(!t)return n.includes(" \u203A ")&&n.slice(n.lastIndexOf(" \u203A ")+3).includes("/");if(t.has(n))return!0;for(let o of t){let r=o.indexOf(" \u203A ");if(r>=0&&n.startsWith(o.slice(0,r+3)))return!0}return!1}async function vh(e,t,n,o,r=!1,s){if(t)return t;let i={enabled:o??e.CF_ANALYSIS_IMPORTED_AGENTS!=="0",byRepo:{}};if(!i.enabled)return i;Ct(e)&&(i.grouped=!0);let l=await n?.()??[];r&&(i.agentRows=structuredClone(s?.length?[...s]:l.map((a,c)=>({id:a.id??String(c),repoPath:a.repoPath,unitKey:a.unitKey,notFoundAt:a.notFoundAt??null}))));for(let a of l){if(!a.unitKey||!a.repoPath||!a.unitKey.startsWith("model:")&&(!r||!a.codeInputsJson))continue;let c=Co(a.repoPath);if(!c)continue;let f=a.unitKey.startsWith("model:")?i.byRepo:i.codeByRepo??={};(f[c]??=[]).push(structuredClone({unitKey:a.unitKey,name:a.name,...a.groupKey===void 0?{}:{groupKey:a.groupKey},...a.groupName===void 0?{}:{groupName:a.groupName},systemPrompt:a.systemPrompt,toolsJson:a.toolsJson,model:a.model,...a.codeInputsJson===void 0?{}:{codeInputsJson:a.codeInputsJson},...a.links===void 0?{}:{links:a.links},...a.services===void 0?{}:{services:a.services}}))}return i}function Ks(e,t){let n=e.slice(6).split("#")[0];return rc(n,t)}function rc(e,t){return t?B(e,vt(t))??e:e}function Ws(e){return`${Ks(e.unitKey)} \u203A ${e.name}`}function xo(e,t,n=""){let o=e?.enabled?e.byRepo[t]??[]:[],r=o.map(Ws),s=new Set(Object.entries(e?.enabled?e.byRepo:{}).filter(([a])=>a!==t).flatMap(([,a])=>a.map(Ws))),i=o.map((a,c)=>{let f=r.filter(x=>x===r[c]).length>1?`${r[c]} (${a.unitKey.split("#").slice(1).join("#")})`:r[c],u=s.has(r[c])?`${t} \u203A ${f}`:f,p=`${u}/system_prompt.md`,h={[p]:a.systemPrompt??n},m=[{role:"system prompt",label:null,path:p}];if(a.toolsJson?.length){let x=`${u}/tools.json`;h[x]=JSON.stringify(a.toolsJson,null,2),m.push({role:"tools",label:null,path:x})}if(a.services?.length){let x=`${u}/context.md`,w=a.services.map(({name:k,kind:b})=>`${xr(k)}${b===k?"":` (${b})`}`);h[x]=`This agent's code (not the model) reads from or writes to: ${w.join(", ")}.`,m.push({role:"reference",label:"Context",path:x})}return{node:{id:a.unitKey,label:a.name,kind:"agent",desc:"",meta:a.model,sourceRef:{path:p,line:1},files:m,tools:(a.toolsJson??[]).map(x=>an(x.name))},files:h,keys:[a.unitKey],sourcePath:Ks(a.unitKey,t),agentKey:a.unitKey.split("#").slice(1).join("#")}});if(!e?.grouped)return i.map(a=>({...a,steps:[a]}));let l=new Map;return i.forEach((a,c)=>{let f=o[c].groupKey?`group:${o[c].groupKey}`:`step:${c}`,u=l.get(f)??[];u.push(a),l.set(f,u)}),[...l.values()].map(a=>{let c=a[0],f=o.find(u=>u.unitKey===c.node.id);return{...c,steps:a,keys:a.flatMap(u=>u.keys),files:Object.assign({},...a.map(u=>u.files)),node:{...c.node,label:f.groupName??f.name,sourcePaths:[...new Set(a.map(u=>u.sourcePath))],files:a.flatMap(u=>u.node.files),tools:[...new Map(a.flatMap(u=>u.node.tools).map(u=>[u.label,u])).values()]}}})}function Gs(e,t){return xo(e,t).flatMap(({steps:n})=>n.flatMap(({files:o,sourcePath:r,agentKey:s})=>Object.entries(o).map(([i,l])=>({path:i,text:l,sourcePath:r,agentKey:s,role:i.slice(i.lastIndexOf("/")+1)}))))}function Ah(e,t,n,o=""){let r=new Set(n.nodes.filter(f=>f.kind==="agent").map(f=>f.id)),s=[],i={},l=xo(e,t,o);for(let f of l)r.has(f.node.id)||(r.add(f.node.id),s.push(f.node),Object.assign(i,f.files));let a=new Map(l.flatMap(f=>f.keys.map(u=>[u,f.node.id]))),c=yr((e?.enabled?e.byRepo[t]??[]:[]).filter(f=>r.has(a.get(f.unitKey)??f.unitKey)).map(f=>{let u=a.get(f.unitKey)??f.unitKey;return{...f,id:u,scope:t,links:f.links?.map(p=>({...p,to:a.get(p.to)??p.to})).filter(p=>!e?.grouped||p.to!==u),unitKey:u}}));return{nodes:s,files:i,edges:c}}function $h(e,t,n){return n.length?t.filter(o=>!o.startsWith(`${e}: no agent found \u2014`)&&!o.startsWith(`${e}: no agent conventions found (`)):t}function Ph(e,t,n){let o=new Set(xo(e,t).flatMap(r=>Object.keys(r.files)));return o.size?Object.fromEntries(Object.entries(n).filter(([r])=>!o.has(r))):n}import{posix as Y}from"node:path";function Us(e,t){if(t==="markdown"){let l=e.startsWith("---")?e.indexOf(`
24
- ---`,3):-1;return l<0?null:{start:3,end:l+1,bodyStart:l+4,newline:`
25
- `,raw:e.slice(3,l).split(`
26
- `)}}if(t==="outline"){let l=e.split(`
27
- `),a=l[0]==="---"?l.indexOf("---",1):-1;if(a<0)return null;let c=l.slice(0,a).join(`
28
- `).length+1;return{start:4,end:c,bodyStart:Math.min(e.length,c+4),newline:`
29
- `,raw:l.slice(1,a)}}let n=/^\uFEFF?---(\r?\n)/.exec(e);if(!n)return null;let o=e.slice(n[0].length),r=/^---(?:\r?\n|$)/m.exec(o);if(!r)return null;let s=o.slice(0,r.index),i=n[0].length+r.index;return{start:n[0].length,end:i,bodyStart:i+r[0].length,newline:n[1],raw:s?s.slice(0,-1).split(`
30
- `):[]}}function Js(e){return(e.startsWith('"')?e.match(/^"((?:\\.|[^"\\])*)"\s*(?:#.*)?$/):e.match(/^'((?:''|[^'])*)'\s*(?:#.*)?$/))?.[1]??null}function zs(e,t=!1){if(!e||e.startsWith("#"))return null;if(e.startsWith('"')||e.startsWith("'"))return Js(e);let n=e.replace(/\s+#.*$/,"");if(t&&/:\s*$/.test(n))return null;let o=t?n.trimEnd():n;return/^[[\]{}&*!?@`%|>]|^-(?:\s|$)|:\s/.test(o)||/^(?:[-+]?\d|[-+]?\.\d|[-+]?\.(?:inf|nan)$|null$|~$|true$|false$|yes$|no$|on$|off$|y$|n$)/i.test(o)?null:n}function sc(e,t=!1,n=!1){let o=[],r=new Map,s=null;return e.map(i=>{let l=i.replace(/\r$/,""),a=l.length-l.trimStart().length,c=()=>o.map(({key:g})=>g).join(".")||null;if(s&&(!l.trim()||a>s.indent))return l.trim()&&(s.contentIndent??=a),{location:c(),text:l.slice(s.contentIndent??a),keys:s.keys};if(s=null,!l.trim()||l.trimStart().startsWith("#"))return{location:c()};for(;o.length&&o.at(-1).indent>=a;)o.pop();if(n&&/^\s*-\s/.test(l)){let g=o.map(({key:k})=>k),x=JSON.stringify(g),w=r.get(x)??0;return r.set(x,w+1),{location:c(),keys:[...g,w]}}let f=l.match(/^\s*([\w.-]+):(?:\s+(.*))?$/);if(!f)return{location:c()};let u=f[2]??"",p=[...o.map(({key:g})=>g),f[1]];if(!u||u.startsWith("#"))return o.push({indent:a,key:f[1]}),{location:c(),...n?{keys:p}:{}};if(/^[|>][+-]?\s*(?:#.*)?$/.test(u))return s={indent:a,keys:p},{location:c()};let h=u.match(/^(["'])(.*)\1\s*(?:#.*)?$/),m=t?Js(u)??u.replace(/\s+#.*$/,""):h?h[2]:u.replace(/\s+#.*$/,"");return{location:c(),text:m,keys:p}})}function yo(e,t={}){let n=e.split(`
31
- `).map(i=>i.replace(/\r$/,"")),o=sc(n,!0),r={},s=[{indent:-1,value:r}];for(let i=0;i<n.length;i++){let l=n[i];if(!l.trim()||l.trimStart().startsWith("#"))continue;if(l.includes(" "))return null;let a=l.length-l.trimStart().length,c=l.match(/^\s*([\w.-]+):(?:\s+(.*))?$/),f=l.match(/^\s*-(?:\s+(.*))?$/);if(!c&&!f)return null;for(;s.at(-1).indent>=a;)s.pop();let u=s.at(-1);if(u.childIndent??=a,u.childIndent!==a||u.indent===-1&&a!==0)return null;if(f){if(!t.lists)return null;let m=zs(f[1]??"",!0);if(m===null||s.length===1)return null;if(!Array.isArray(u.value)){if(Object.keys(u.value).length)return null;u.value=[],Object.defineProperty(s.at(-2).value,u.key,{value:u.value,enumerable:!0,writable:!0})}u.value.push(m);continue}if(!c||Array.isArray(u.value)||Object.hasOwn(u.value,c[1]))return null;let p=c[2]??"";if(!p||p.startsWith("#")){let m={};Object.defineProperty(u.value,c[1],{value:m,enumerable:!0,writable:!0}),s.push({indent:a,key:c[1],value:m});continue}let h;if(/^[|>][+-]?\s*(?:#.*)?$/.test(p)){let m=i+1,g;for(;i+1<n.length;){let w=n[i+1],k=w.length-w.trimStart().length;if(w.trim()&&k<=a)break;if(w.includes(" ")||w.trim()&&(g??=k,k<g))return null;i++}let x=i;h=o.slice(m,x+1).flatMap(({text:w})=>w===void 0?[]:[w]).join(`
32
- `)}else{let m=zs(p);if(m===null)return null;h=m}Object.defineProperty(u.value,c[1],{value:h,enumerable:!0,writable:!0})}return r}function Nh(e){let t=yo(e,{lists:!0});return t?So(e,{legacyBoundaries:!0}).map(n=>({key:n.key,value:t[n.key],span:n.span})):null}function So(e,t={}){let n=e.split(`
33
- `),o=n.flatMap((r,s)=>(t.legacyBoundaries?r.trim()&&!/^\s|^#/.test(r):/^[\w.-]+:(?:\s|$)/.test(r))?[s]:[]);return o.map((r,s)=>{let i=n[r].slice(0,n[r].indexOf(":")),l=o[s+1]??n.length;for(;l>o[s]+1&&!n[l-1].trim();)l--;return{key:i,span:{from:r+1,to:l}}})}function ko(e){let t=e.split(/^---(?:\s+#.*)?\s*$/m);if(t.length>1)return[...new Set(t.flatMap(ko))];let n=e.split(`
34
- `).filter(i=>i.trim()&&!/^\s*(?:#|---\s*$|\.\.\.\s*$|%[A-Z])/.test(i)),o=n.join(`
35
- `).trimStart().replace(/^(?:(?:&[\w.-]+|!<[^>]+>|![\w:/.!-]+)\s+)+/,"");if(o.startsWith("{"))return ic(o);let r=i=>i.length-i.trimStart().length,s=n.reduce((i,l)=>Math.min(i,r(l)),1/0);return n.flatMap(i=>{let l=/^["']?([\w.-]+)["']?\s*:/.exec(i.trimStart());return r(i)===s&&l?[l[1]]:[]})}function ic(e){let t=[],n=[],o="",r=!1;for(let s=0;s<e.length;s++){let i=e[s];if(o){i==="\\"&&o==='"'?s++:i===o&&(o==="'"&&e[s+1]==="'"?s++:o="");continue}if(i==="#"&&/\s/.test(e[s-1]??" ")){for(;s<e.length&&e[s]!==`
36
- `;)s++;continue}if(r&&n.length===1&&!/\s/.test(i)&&i!=="}"&&i!=="?"){let l=/^(?:"((?:\\.|[^"\\])*)"|'((?:''|[^'])*)'|([\w.-]+))\s*:/.exec(e.slice(s));if(!l)return[];try{t.push(l[1]!==void 0?JSON.parse(`"${l[1]}"`):l[2]?.replace(/''/g,"'")??l[3])}catch{return[]}s+=l[0].length-1,r=!1;continue}if(i==='"'||i==="'")o=i;else if(i==="{"||i==="[")n.push(i),n.length===1&&(r=!0);else if(i==="}"||i==="]"){if(n.pop()!==(i==="}"?"{":"["))return[];if(!n.length)return t}else i===","&&n.length===1&&(r=!0)}return[]}function Rt(e,t){return V(e)?[...new Set(t)].filter(n=>qs(n)&&/(?:^|\/)\.claude-plugin\/(?:plugin|marketplace)\.json$/i.test(n)).sort():[]}function Wh(e,t,n={}){return Rt(e,t).flatMap(o=>{let r=/^(?:(.*)\/)?\.claude-plugin\/plugin\.json$/i.exec(o);if(r)return[{folder:r[1]??"",path:o}];let s=o.split("/").slice(0,-2).join("/");try{let i=JSON.parse(n[o]);return!i||typeof i!="object"||!("plugins"in i)||!Array.isArray(i.plugins)?[]:[...new Set(i.plugins.flatMap(l=>{if(!l||typeof l!="object"||typeof l.source!="string")return[];let a=l.source.replace(/^\.\//,"");return qs(a)?[De(a,s)]:[]}))].map(l=>({folder:l,path:o}))}catch{return[]}})}function qs(e){return!/[\\:\0?*#%]/.test(e)&&!e.split("/").some(t=>!t||t==="."||t==="..")}function Kh(e,t,n){let o=t.split("/");for(let r=0;r<o.length-2;r++)if(!(o[r].toLowerCase()!=="plugins"||!o[r+1])&&Xs(e,o.slice(r+2).join("/")))return o.slice(0,r+2).join("/");for(let r of[...n].sort((s,i)=>i.folder.length-s.folder.length)){let s=B(t,r.folder);if(s!==null&&Xs(e,s))return r.folder}return null}function Xs(e,t){return t.toLowerCase().startsWith(`${ft}/`)&&An.test(t)||!!(Ee(e)&&t.toLowerCase().startsWith(`${_e}/`)&&ce(t)?.definition)}function wo(e,t,n={}){if(!V(e))return[];let o=[...new Set(t)].filter(s=>!/[\\:\0]/.test(s)&&s.split("/").every(i=>i&&i!=="."&&i!=="..")).sort(),r=new Map;for(let s of o){let i=/^(?:(.*)\/)?environments\/[^/]+\.ya?ml$/i.exec(s),l=/^(?:(.*)\/)?agents\/[^/]+\/environment\.ya?ml$/i.exec(s),a=i?.[1]??l?.[1]??(i||l?"":null);if(a===null||r.has(a))continue;let c=p=>B(p,a),f=o.filter(p=>/^agents\/(?:[^/]+\.md|[^/]+\/agent\.md)$/i.test(c(p)??""));if(!f.length)continue;let u=o.filter(p=>/^(?:environments\/[^/]+\.ya?ml|vaults\/[^/]+\.ya?ml|policy\.ya?ml|agents\/[^/]+\/(?:environment|policy|vault)\.ya?ml|skills\/[^/]+\/SKILL\.md)$/i.test(c(p)??""));r.set(a,{folder:a,agents:f,configs:u})}for(let s of r.values())for(let i of s.agents){if(n[i]===void 0)continue;let l=lc(i,n[i],s,o);for(let a of l.configPaths)s.configs.includes(a)||s.configs.push(a);for(let a of l.relationships)a.kind==="config"&&n[a.path]!==void 0&&ac(n[a.path])&&!s.configs.includes(a.path)&&s.configs.push(a.path)}return[...r.values()].sort((s,i)=>s.folder<i.folder?-1:s.folder>i.folder?1:0)}function Yh(e,t,n){let o=wo(e,t,n).filter(s=>s.agents.some(i=>n[i]===void 0)),r=new Set(Rt(e,t));return t.filter(s=>!r.has(s)&&/\.(?:ya?ml|json|md)$/i.test(s)&&o.some(i=>B(s,i.folder)!==null&&!i.agents.includes(s)&&!i.configs.includes(s)))}function lc(e,t,n,o){let r=Us(t),s=r?.raw.join(`
37
- `)??"",i=new Map(So(s).map(x=>[x.key,s.split(`
38
- `).slice(x.span.from-1,x.span.to).join(`
39
- `)])),l=x=>i.has(x)?yo(i.get(x),{lists:!0})?.[x]:void 0,a=x=>typeof l(x)=="string"?l(x):null,c={path:e,name:a("name")??Y.basename(e,".md"),model:a("model"),description:a("description"),prompt:r?t.slice(r.bodyStart).trim():t.trim(),relationships:[],refused:[],configPaths:[]};r||c.refused.push({path:e,reason:"invalid"});let f=(x,w,k=!1)=>{if(/[\\:\0${}*]/.test(x)||x.startsWith("/")){c.refused.push({path:e,reason:"dynamic"});return}let b=Y.normalize(Y.join(Y.dirname(e),x));if(B(b,n.folder)===null||b===".."||b.startsWith("../")){c.refused.push({path:b,reason:"out-of-scope"});return}if(!o.includes(b)){c.refused.push({path:b,reason:"missing"});return}if(w==="agent"&&!n.agents.includes(b)){c.refused.push({path:b,reason:"out-of-scope"});return}c.relationships.some(S=>S.path===b&&S.kind===w)||c.relationships.push({path:b,kind:w}),k&&!c.configPaths.includes(b)&&c.configPaths.push(b)},u=(x,w)=>{let k=l(x);if(k===void 0&&!i.has(x))return;let b=typeof k=="string"?[k]:Array.isArray(k)?k:[];if(!b.length||b.some(S=>typeof S!="string")){c.refused.push({path:e,reason:"dynamic"});return}for(let S of b)f(S,w,w==="config")};for(let x of["environment","policy","vault","vault_schema"])u(x,"config");u("skills","skill");let p=l("multiagent");if(p&&typeof p=="object"&&"agents"in p&&Array.isArray(p.agents))for(let x of p.agents)typeof x=="string"?f(x,"agent"):c.refused.push({path:e,reason:"dynamic"});else i.has("multiagent")&&c.refused.push({path:e,reason:"dynamic"});let h=Y.basename(e,".md"),m=h.toLowerCase()==="agent",g=m?n.configs.filter(x=>Y.dirname(x)===Y.dirname(e)&&/\/environment\.ya?ml$/i.test(x)):n.configs.filter(x=>B(x,n.folder)?.match(/^environments\/([^/]+)\.ya?ml$/i)?.[1]===h);if(!i.has("environment")){let x=n.agents.length===1?n.configs.filter(w=>/^environments\/[^/]+\.ya?ml$/i.test(B(w,n.folder))):[];for(let w of g.length?g:x.length===1?x:[])f(Y.relative(Y.dirname(e),w),"config")}if(!i.has("policy")&&(m||n.agents.length===1))for(let x of n.configs.filter(w=>/(?:^|\/)policy\.ya?ml$/i.test(w)&&Y.dirname(w)===(m?Y.dirname(e):n.folder)))f(Y.relative(Y.dirname(e),x),"config");for(let x of c.prompt.matchAll(/(?:\]\(|[`\s])((?:\.\.?\/)[^\s`"'()]+\.(?:ya?ml|json|md))(?:[)`\s]|$)/g))f(x[1],/\/SKILL\.md$/i.test(x[1])?"skill":"config");return c}function ac(e){let t=/^(?:config|networking|filesystem_policy|network_policies|policy|permissions|auth|injection_location|secret_name)$/;return ko(e).some(n=>t.test(n))}function Rg(e){return e==="skill"?"skill":"definition"}var Eo=class extends Error{reason;constructor(t,n){super(t==="secret"?At(n):t==="secret-content"?Ao(n):`File was not read: ${t}.`),this.reason=t}},Oo=["html"],Ys=["md","json","yaml","yml",...Oo],Ro=e=>new RegExp(`\\.(?:${e.join("|")})$`,"i"),fc=Ro(Ys),pc=Ro(Oo),dc=Ro(["ts","tsx","js","jsx","py","go","rb","java","rs","toml",...Ys.filter(e=>!Oo.includes(e))]);function Zs(e,t,n){return t=Dt(e,t,n),On(t)&&pc.test(t)}function mc(e,t,n){return t=Dt(e,t,n),On(t)&&fc.test(t)&&(Ee(e)||!Zs(e,t))}function hc(e,t,n){return dc.test(t)||mc(e,t,n)||ne(e)&&Bt(t)}function gc(e,t,n=[]){if(!Je(e)||!t.toLowerCase().endsWith(".md"))return!1;let o=t.split("/");return o.some((r,s)=>r.toLowerCase()==="commands"&&s<o.length-1&&(o[s-1]?.toLowerCase()===Ie||n.includes(o.slice(0,s).join("/"))))}function Qs(e,t,n=!1){if(!Sn(t,n)||gc(e,t))return!1;let o=[Ie,...Ft.filter(s=>s.startsWith(".")),F.cli],r="";for(let s of t.toLowerCase().split("/")){let i=r?`${r}/${s}`:s,l=Rt(e,[i]).length>0,a=V(e)&&(s===".claude-plugin"||l);if(s.startsWith(".")&&!o.includes(s)&&!a||r.split("/").at(-1)===".claude-plugin"&&!l||r===Ie&&!ct.includes(`${r}/${s}`)&&!(Tt.includes(`${r}/${s}`)&&Ee(e)))return!1;r=r?`${r}/${s}`:s}return!0}var dr=/(prompt|tool|agent|config|instruction)/i,Vs=/\.(md|json|ts|js|py|yaml|yml|txt)$/i,un=/(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|poetry\.lock|Cargo\.lock|go\.sum)$|\.lock$/i,xc=/(^|\/)(node_modules|dist|build|out|vendor|target|__pycache__|coverage)\//i,fn=new RegExp(`${xc.source}|\\.min\\.|\\.(png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot|pdf|zip|gz|jar|bin|map)$`,"i"),Lt=new RegExp(`${fn.source}|${rr.source}|${un.source}|${yn.source}`,"i"),yc=/\.(ts|tsx|js|jsx|mjs|cjs|py)$/i,ei=new RegExp(`(^|/)(${jt.join("|")}|cassettes|docs|\\.github)/`,"i"),Sc=/(^|\/)([^/]*\.stories\.[^/]*|[^/]*\.d\.ts)$/i,kc=new RegExp(`(^|/)(${["test","tests","__tests__","test-support","testdata","fixtures","__fixtures__",...jt,"cassettes","mocks","__mocks__","examples","docs","\\.github"].join("|")})/`,"i"),wc=/(^|\/)([^/]*fixture[^/]*|[^/]*\.stories\.[^/]*|test_[^/]*\.py|conftest\.py|[^/]*\.d\.ts)$/i,bo=/(^|\/)\.git\//i,_o=(e,t,n)=>n==="github"?ze.conventionImport.fileBytes:void 0,cn=()=>ze.codeScan.fileBytes,bc={archive:{hidden:!1,discovery:!0,excluded:[fn,un,bo]},listing:{hidden:!0},definition:{hidden:!0,discovery:!0,limit:_o},skill:{hidden:!0,discovery:!0,limit:_o},extraction:{hidden:!0,discovery:!0,accepts:(e,t)=>Vs.test(t),limit:_o},source:{hidden:!0,discovery:!0,excluded:[Lt],empty:!0,accepts:(e,t,n)=>Pn(e,t,n)||hc(e,t,n),limit:(e,t,n,o)=>Pn(e,t,o)?void 0:Zs(e,t,o)?ze.sourceFetch.htmlReferenceBytes:ze.sourceFetch.codeFileBytes},"code-scan":{hidden:!0,discovery:!0,excluded:[Lt,ei,Sc],relativeExclusions:!0,excludeExamples:!0,accepts:(e,t)=>yc.test(t)||Bt(t)||Je(e)&&Mn(t)&&Qs(e,t),limit:cn},"code-support":{hidden:!0,excluded:[Lt],accepts:(e,t)=>W(t)!==null,limit:cn},pointer:{hidden:!1,limit:cn},proposal:{hidden:!0,excluded:[fn,un,bo],empty:!0,limit:cn},survey:{hidden:!0,discovery:!0,excluded:[Lt,bo],relativeExclusions:!0,accepts:(e,t)=>Vs.test(t)||gr(t)==="code",limit:()=>ze.survey.fileBytes},override:{hidden:!1}};function Xe(e,t,n){return Io(e,t,n,!0)}var _c=/(?:^|\/)(?:vault\.ya?ml|(?:vaults?|auth)\/(?:credentials?|values?|tokens?)(?:\.[^/]+)?)$/i;function Ec(e){let t=e.path.replace(/\\/g,"/");if(e.text===void 0||!/\.(?:ya?ml|json|md)$/i.test(t))return!1;let n=e.text,o=/(?:^|[\n{,])\s*(?:-\s*)?["']?(?:secret(?:_value)?|api[_-]?key|access[_-]?token|refresh[_-]?token|token|password|client[_-]?secret|private[_-]?key|credentials?)["']?\s*:/gim,r=/(?:^|[\n{,])\s*(?:-\s*)?["']?[A-Z][A-Z0-9_]*(?:_KEY|_TOKEN|_PASSWORD|_SECRET)["']?\s*:/gm;return[...n.matchAll(o),...n.matchAll(r)].some(i=>!/^\s*(["']?)(?:\$\{[A-Z_][A-Z0-9_]*\}|\$[A-Z_][A-Z0-9_]*)\1[^\S\n]*(?:#[^\n]*)?(?:[,}\r\n]|$)/.test(n.slice(i.index+i[0].length)))||/["']?auth["']?\s*:/.test(n)&&/(?:^|[\n{,])\s*["']?value["']?\s*:/m.test(n)||/-----BEGIN (?:[A-Z ]*PRIVATE KEY|CERTIFICATE)-----/.test(n)}function Io(e,t,n,o){let r=No(e,t,{...n,allowSelectedFile:n.purpose==="override",requireLocalTarget:n.purpose==="proposal"});if(!r.admitted)return r;let s=B(t.path,n.root);if(V(e)&&_c.test(t.path.replace(/\\/g,"/")))return{admitted:!1,reason:"secret"};if(V(e)&&Ec(t)&&(!n.listing||wo(e,[...n.listing.keys()],t.text===void 0?n.managedFiles:{...n.managedFiles,[t.path]:t.text}).some(u=>u.configs.includes(t.path)&&!/\/SKILL\.md$/i.test(t.path))))return{admitted:!1,reason:"secret"};if(n.route==="local-folder"&&n.purpose==="proposal"&&n.localTarget){let u=cc(n.localTarget.root,n.localTarget.path).split(uc).join("/"),p=Io(e,{...t,path:u},{...n,root:void 0,localTarget:void 0,gitIgnored:void 0},o);if(!p.admitted)return p}let i=bc[n.purpose];if(n.purpose==="proposal"&&Se(s))return{admitted:!1,reason:"wrong-type"};if(i.discovery&&ar(e,t.path,n.root))return{admitted:!1,reason:"excluded"};if(i.hidden&&n.route!=="github"&&!Qs(e,t.path,t.directory))return{admitted:!1,reason:"hidden"};if(i.hidden&&n.route==="local-folder"&&t.path.split("/").includes("node_modules"))return{admitted:!1,reason:"excluded"};let l=i.relativeExclusions?s:t.path,a=be(e,t.path,n.root);if(!["listing","pointer","override"].includes(n.purpose)&&bn(e,t.path,n))return{admitted:!1,reason:"excluded"};if(i.excluded?.some(u=>a&&u===ei?!1:a&&u===Lt?fn.test(l)||un.test(l):u.test(l)))return{admitted:!1,reason:"excluded"};if(n.purpose==="archive"&&Ct(e)&&tr(s,t.text)&&!a)return{admitted:!1,reason:"excluded"};if(i.excludeExamples&&!a){if(pr(e)){if(o&&fr(t.path,{root:n.root??void 0,listing:n.listing,settings:e,key:JSON.stringify([n.root??"",n.route,...n.exclusions?.length?[n.exclusions]:[]]),readable:(u,p)=>Io(e,{path:u,size:p},{...n,localTarget:void 0},!1).admitted}))return{admitted:!1,reason:"excluded"}}else if(kc.test(l)||wc.test(l))return{admitted:!1,reason:"excluded"}}if(i.empty&&t.size!==void 0&&t.size<=0)return{admitted:!1,reason:"empty"};if(i.accepts&&!(a?.kind==="example"&&n.purpose==="code-scan"&&/\.md$/i.test(s))&&!i.accepts(e,s,n.scopes))return{admitted:!1,reason:"wrong-type"};let c=i.limit?.(e,s,n.route,n.scopes);if(c!==void 0&&t.size!==void 0&&t.size>c)return{admitted:!1,reason:"too-large"};let f=vo(e,t.text);return f?{admitted:!1,reason:f}:{admitted:!0}}var Ic=`
40
- [The rest of this file was not read.]
41
- `;async function Oc(e,t,n,o={}){let r=Xe(e,t,{purpose:"override",route:"github",...o});if(!r.admitted)throw new Error(r.reason==="secret"?At(t.path):`File was not read: ${r.reason}.`);let s=await n(),i=Xe(e,{path:t.path,text:s},{purpose:"override",route:"github",...o});if(!i.admitted)throw new Eo(i.reason,t.path);if(t.readBytes===void 0)return s;let l=Buffer.from(s,"utf8");if(l.length<=t.readBytes)return s;let a=Math.min(t.readBytes,l.length);for(;a>0&&(l[a]&192)===128;)a--;return l.subarray(0,a).toString("utf8")+Ic}var Rc=4096;function Lc(e,t,n,o={}){let r=dn(e),s=r&&t.readBytes!==void 0?t.readBytes+Rc:void 0;return Oc(e,r?t:{path:t.path},async()=>{let i=await n(s===void 0?t:{...t,readBytes:s});if(i===null)throw new Error("File is unavailable.");return s===void 0?i:Buffer.from(i.slice(0,s),"utf8").subarray(0,s).toString("utf8")},o)}var Hs=new WeakMap;function vc(e,t){let n=Hs.get(t);if(n?.settings===e)return t;t=n?.source??t;let o=t.admission;if(!o?.exclusions?.length&&!dn(e))return t;let r,s=()=>r??=(t.listAll?t.listAll():t.list()).then(a=>new Set(a.map(c=>c.path))),i=async a=>{let c=await(a&&t.listAll?t.listAll():t.list());return o?.exclusions?.length?c.filter(f=>Xe(e,f,{purpose:"override",route:"github",...o}).admitted):c},l={repoKey:t.repoKey,root:t.root,source:t.source,admission:o,head:()=>t.head(),linkFor:(...a)=>t.linkFor(...a),list:()=>i(!1),...t.listAll?{listAll:()=>i(!0)}:{},read:async a=>Lc(e,a,c=>t.read(c),{...o,...V(e)?{listing:await s()}:{}})};return Hs.set(l,{source:t,settings:e}),l}async function Lg(e,t,n){for(let o of n){if(!o.admission?.exclusions?.length)continue;let r=t.repos?.find(c=>c.key===o.repoKey);if(!r)continue;let s=new Map(Gs(t.projectAgents,r.key).map(c=>[c.path,De(c.sourcePath,vt(r.key))])),i=[...Object.keys(r.files??{}).map(c=>s.get(c)??c),...s.values(),...(r.selected??[]).map(c=>c.path),...(r.scan?.plan??[]).map(c=>c.path)];if(!i.length)continue;let l=vc(e,o),a=new Set((await(l.listAll?l.listAll():l.list())).map(c=>c.path));for(let c of i)if(!Xe(e,{path:c},{purpose:"override",route:"github",...o.admission,listing:a}).admitted)throw new Error("Saved files conflict with the current exclusions. Start a new analysis.")}}export{Ac as a,$c as b,ot as c,ri as d,Be as e,Fo as f,Bo as g,ro as h,_m as i,Em as j,Ct as k,Je as l,ne as m,V as n,W as o,U as p,d as q,y as r,Ue as s,z as t,ke as u,A as v,C as w,J as x,Mt as y,tr as z,ze as A,lr as B,be as C,bn as D,ar as E,Ni as F,_n as G,pr as H,ce as I,Di as J,cu as K,mr as L,Bt as M,tl as N,Ru as O,Mn as P,vu as Q,Us as R,yo as S,Nh as T,So as U,Rt as V,Wh as W,Kh as X,wo as Y,Yh as Z,lc as _,ac as $,Rg as aa,Eo as ba,Ys as ca,Zs as da,mc as ea,hc as fa,gc as ga,Qs as ha,dr as ia,Vs as ja,un as ka,xc as la,fn as ma,Lt as na,yc as oa,ei as pa,bo as qa,Xe as ra,Ic as sa,Oc as ta,Lc as ua,vc as va,Lg as wa,gu as xa,F as ya,ut as za,vn as Aa,Ki as Ba,Ie as Ca,ft as Da,ct as Ea,xu as Fa,Tt as Ga,An as Ha,yu as Ia,Ee as Ja,Vi as Ka,Zi as La,Dt as Ma,Pn as Na,Su as Oa,ku as Pa,wu as Qa,bu as Ra,_u as Sa,kr as Ta,Z as Ua,he as Va,q as Wa,re as Xa,Fr as Ya,qf as Za,zn as _a,Hr as $a,_t as ab,Cp as bb,Qr as cb,Np as db,Tp as eb,os as fb,Yt as gb,id as hb,ld as ib,ms as jb,hs as kb,nn as lb,im as mb,lm as nb,am as ob,bs as pb,km as qb,Es as rb,an as sb,kh as tb,Ds as ub,Bs as vb,so as wb,io as xb,vh as yb,Ks as zb,rc as Ab,xo as Bb,Ah as Cb,$h as Db,Ph as Eb,rn as Fb,Na as Gb,Ta as Hb,Fa as Ib,fo as Jb,Wm as Kb,vs as Lb,Km as Mb,Gm as Nb,As as Ob,Za as Pb,Xm as Qb,go as Rb,Qa as Sb,ec as Tb,tc as Ub,nc as Vb,oc as Wb};