@counterfact-labs/cli 0.2.7 → 0.2.10

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 (142) hide show
  1. package/bundle/client-release.json +1 -1
  2. package/dist/adapters/analysis-results.js +87 -0
  3. package/dist/adapters/combined-results.js +27 -0
  4. package/dist/adapters/entry-files.js +5 -2
  5. package/dist/adapters/entry-packing.js +161 -0
  6. package/dist/adapters/entry-selection.js +13 -1
  7. package/dist/adapters/files.js +110 -5
  8. package/dist/adapters/git.js +10 -1
  9. package/dist/adapters/release.js +4 -1
  10. package/dist/adapters/results.js +9 -2
  11. package/dist/adapters/selection.js +19 -9
  12. package/dist/adapters/settings.js +37 -6
  13. package/dist/analysis-core/analysis/code-agents/skipped-files.js +1 -1
  14. package/dist/analysis-core/analysis/file-analysis-plan.js +1 -0
  15. package/dist/analysis-core/analysis/file-dependencies.js +1 -0
  16. package/dist/analysis-core/analysis/finding-activity-switch.js +1 -0
  17. package/dist/analysis-core/analysis/finding-identity.js +1 -0
  18. package/dist/analysis-core/analysis/finding-quality/policy.js +1 -0
  19. package/dist/analysis-core/analysis/folder-analysis-plan.js +1 -0
  20. package/dist/analysis-core/analysis/passes/full-file-passes.js +1 -0
  21. package/dist/analysis-core/analysis/project-architecture.js +1 -0
  22. package/dist/analysis-core/analysis/schemas.js +1 -1
  23. package/dist/analysis-core/chunks/2CWULBP2.js +1 -0
  24. package/dist/analysis-core/chunks/2M55DR2J.js +35 -0
  25. package/dist/analysis-core/chunks/34NVU26H.js +1 -0
  26. package/dist/analysis-core/chunks/{RNTMH4MU.js → 5BTATES5.js} +1 -1
  27. package/dist/analysis-core/chunks/5UWDUYHF.js +1 -0
  28. package/dist/analysis-core/chunks/{6RWEWBHK.js → 5VQ4VYIP.js} +1 -1
  29. package/dist/analysis-core/chunks/66JRJPJC.js +1 -0
  30. package/dist/analysis-core/chunks/6JTHFDH3.js +1 -0
  31. package/dist/analysis-core/chunks/6VHZNBII.js +19 -0
  32. package/dist/analysis-core/chunks/6YCABS5T.js +1 -0
  33. package/dist/analysis-core/chunks/C77LGCKF.js +1 -0
  34. package/dist/analysis-core/chunks/CNQZLSAP.js +1 -0
  35. package/dist/analysis-core/chunks/DHVEGIU6.js +1 -0
  36. package/dist/analysis-core/chunks/HCPO6QPU.js +1 -0
  37. package/dist/analysis-core/chunks/I4F56VMG.js +1 -0
  38. package/dist/analysis-core/chunks/INVTU73D.js +1 -0
  39. package/dist/analysis-core/chunks/{6B2HILSY.js → JAPVLU4Z.js} +1 -1
  40. package/dist/analysis-core/chunks/KBTM5MBC.js +14 -0
  41. package/dist/analysis-core/chunks/LFJQ4YLP.js +3 -0
  42. package/dist/analysis-core/chunks/M5YWJY7P.js +1 -0
  43. package/dist/analysis-core/chunks/MKYLK6DB.js +1 -0
  44. package/dist/analysis-core/chunks/N2L4JMJE.js +1 -0
  45. package/dist/analysis-core/chunks/NCW5LJ5O.js +6 -0
  46. package/dist/analysis-core/chunks/P253B344.js +7 -0
  47. package/dist/analysis-core/chunks/PBHHWFR6.js +1 -0
  48. package/dist/analysis-core/chunks/Q5WR6B2H.js +2 -0
  49. package/dist/analysis-core/chunks/QPIBHTON.js +67 -0
  50. package/dist/analysis-core/chunks/QVXARKP7.js +1 -0
  51. package/dist/analysis-core/chunks/SJESFYBA.js +10 -0
  52. package/dist/analysis-core/chunks/SP6XFHNH.js +1 -0
  53. package/dist/analysis-core/chunks/TA2NIQAY.js +1 -0
  54. package/dist/analysis-core/chunks/UKX3A6AX.js +1 -0
  55. package/dist/analysis-core/chunks/VC3PYT2B.js +1 -0
  56. package/dist/analysis-core/chunks/VDUFPTDD.js +1 -0
  57. package/dist/analysis-core/chunks/VWRFSVLI.js +1 -0
  58. package/dist/analysis-core/chunks/VX6LYNXV.js +1 -0
  59. package/dist/analysis-core/chunks/W73WF226.js +1 -0
  60. package/dist/analysis-core/chunks/{FBTOOUPL.js → XVGLY4EO.js} +1 -1
  61. package/dist/analysis-core/chunks/YWL52FVW.js +2 -0
  62. package/dist/analysis-core/contracts/analysis-selection.js +1 -1
  63. package/dist/analysis-core/contracts/analysis-size.js +1 -0
  64. package/dist/analysis-core/contracts/execution-request.js +1 -0
  65. package/dist/analysis-core/contracts/intake-finding.js +1 -0
  66. package/dist/analysis-core/contracts/model-call-identity.js +1 -0
  67. package/dist/analysis-core/contracts/relay-analysis.js +1 -1
  68. package/dist/analysis-core/contracts/requests.js +1 -1
  69. package/dist/analysis-core/conventions/analysis-fit.js +1 -1
  70. package/dist/analysis-core/conventions/file-admission.js +1 -1
  71. package/dist/analysis-core/conventions/read-limits.js +1 -0
  72. package/dist/analysis-core/import/calls/modules.js +1 -1
  73. package/dist/analysis-core/import/entry-selection.js +1 -0
  74. package/dist/analysis-core/import/outside-loader-sources.js +1 -1
  75. package/dist/analysis-core/index.js +3 -3
  76. package/dist/analysis-core/requests/answer-formats.js +1 -1
  77. package/dist/analysis-core/requests/local-plan.js +1 -1
  78. package/dist/analysis-core/requests/planned-limits.js +1 -0
  79. package/dist/analysis-core/requests/registry.js +1 -1
  80. package/dist/analysis-core/requests/template-version.js +1 -1
  81. package/dist/analysis-core/requests/tools.js +1 -1
  82. package/dist/analysis-core/settings.js +1 -1
  83. package/dist/analysis-core/stages/engine-entry.js +1 -1
  84. package/dist/bundle/seal/engine.js +1 -1
  85. package/dist/cli/analysis-selection.js +47 -5
  86. package/dist/cli/api.js +1 -1
  87. package/dist/cli/commands/analyze.js +55 -15
  88. package/dist/cli/commands/skipped.js +65 -0
  89. package/dist/cli/context.js +2 -1
  90. package/dist/cli/finding-display.js +102 -7
  91. package/dist/cli/finding-settings.js +3 -1
  92. package/dist/cli/intake-payload.js +25 -2
  93. package/dist/cli/main.js +21 -7
  94. package/dist/cli/mcp-failure.js +6 -5
  95. package/dist/cli/mcp.js +134 -28
  96. package/dist/cli/relay-check.js +103 -23
  97. package/dist/cli/relay-failure.js +4 -4
  98. package/dist/cli/relay-preparation.js +47 -9
  99. package/dist/cli/result-check.js +31 -12
  100. package/dist/cli/saved-results.js +10 -0
  101. package/dist/cli/scope-choices.js +3 -3
  102. package/dist/cli/sign-in.js +2 -2
  103. package/dist/cli/skipped-files.js +22 -0
  104. package/dist/cli/summary.js +15 -1
  105. package/dist/contract/agent-choice.js +25 -2
  106. package/dist/contract/cli-api-messages.js +3 -0
  107. package/dist/contract/cli-refusals.js +31 -5
  108. package/dist/contract/cli-version.js +1 -1
  109. package/dist/contract/console-url.js +3 -0
  110. package/dist/contract/console.js +17 -38
  111. package/dist/contract/engine.js +1 -1
  112. package/dist/contract/messages.js +4 -3
  113. package/dist/contract/project-architecture.js +1 -0
  114. package/dist/contract/scope-choice.js +31 -11
  115. package/dist/contract/selection-offer.js +5 -8
  116. package/dist/gatekeeper/cli-api.js +70 -4
  117. package/dist/gatekeeper/console.js +8 -3
  118. package/dist/gatekeeper/model.js +5 -23
  119. package/dist/gatekeeper/trust/policy.js +2 -1
  120. package/package.json +4 -2
  121. package/dist/analysis-core/analysis/source-notes/types.js +0 -1
  122. package/dist/analysis-core/chunks/2PSNOSJ2.js +0 -1
  123. package/dist/analysis-core/chunks/2PZF54KH.js +0 -10
  124. package/dist/analysis-core/chunks/6U2IR4XB.js +0 -1
  125. package/dist/analysis-core/chunks/7NEWZ74F.js +0 -1
  126. package/dist/analysis-core/chunks/CGCJN73D.js +0 -14
  127. package/dist/analysis-core/chunks/CWYVUGG4.js +0 -1
  128. package/dist/analysis-core/chunks/FSLWD2PE.js +0 -1
  129. package/dist/analysis-core/chunks/GOQVKWP3.js +0 -32
  130. package/dist/analysis-core/chunks/IHAVDX4L.js +0 -66
  131. package/dist/analysis-core/chunks/IVULXWQN.js +0 -21
  132. package/dist/analysis-core/chunks/K2GNDX3W.js +0 -1
  133. package/dist/analysis-core/chunks/K5FUABWW.js +0 -1
  134. package/dist/analysis-core/chunks/KGQYR62R.js +0 -7
  135. package/dist/analysis-core/chunks/KWECQJ6X.js +0 -1
  136. package/dist/analysis-core/chunks/PY5M22CL.js +0 -1
  137. package/dist/analysis-core/chunks/PYKAERZZ.js +0 -1
  138. package/dist/analysis-core/chunks/SLJ6CW7W.js +0 -1
  139. package/dist/analysis-core/chunks/UEORNVQB.js +0 -1
  140. package/dist/analysis-core/chunks/WYLIV2P2.js +0 -1
  141. package/dist/analysis-core/data/finding-types.js +0 -1
  142. /package/dist/analysis-core/chunks/{SKVEBOGA.js → 33EUZF25.js} +0 -0
@@ -0,0 +1,19 @@
1
+ import{J as ct,K as pt,d as rt,h as at,j as lt,k as it,m as ft,r as re}from"./LFJQ4YLP.js";import{b as st}from"./2CWULBP2.js";import{e as te,g as Ce}from"./VC3PYT2B.js";import{a as W,b as he,c as Qe,e as He,f as Ze,g as et,h as tt,i as ge,j as ot,k as nt,n as V}from"./P253B344.js";import{Fb as _,K as Ie,X,a as Me,aa as ze,b as je,ba as ue,ca as Ge,d as de,db as Q,e as K,f as Ae,fb as se,g as Ee,h as oe,i as I,k as _e,ka as Ke,kb as De,l as Ne,la as qe,lb as Ue,mb as Ye,n as Te,na as Je,nb as Ve,r as Le,u as ne,wb as Xe,za as J}from"./2M55DR2J.js";import{b as G,c as L}from"./C6X5GDG4.js";import{a as Re,b as R,c as B,k as z,l as q,v as Be}from"./YWL52FVW.js";import{a as Fe,f as We}from"./SJESFYBA.js";function ye(e,t,n){if(!oe(e)||!t.filenameReferences?.length)return n;let f=n.agents.flatMap(l=>l.prompt.kind==="dedicated"?[{path:l.prompt.path}]:[]),i=Ge(t.filenameReferences,f);return{...n,agents:n.agents.map(l=>{if(l.prompt.kind!=="dedicated")return l;let m=l.prompt.path,p=i.filter(d=>d.promptPath===m&&!l.files.some(y=>y.path===d.readerPath)&&_(e,{path:d.readerPath},{purpose:"override",route:"github",root:t.root}).admitted);return p.length?{...l,files:[...l.files,...p.map(d=>({path:d.readerPath,role:"reference",label:"prompt filename reference"}))]}:l})}}function D(e,t,n){return e.filter(f=>t.some(i=>i.includes(n(f))))}function mt(e,t,n){if(!e.length||n&&!I(n.settings))return;let f;if(n&&!K(n.settings)){let i=Object.keys(n.files).filter(p=>L(p,n.root)!==null&&_(n.settings,{path:p},{purpose:"override",route:"github",root:n.root}).admitted),l=i.filter(p=>Me(L(p,n.root))).sort((p,d)=>je(L(p,n.root),L(d,n.root)));if(!l.length)return;let m=D(i.filter(p=>!l.includes(p)&&J(p)).sort(),l.map(p=>n.files[p]),p=>L(p,n.root));f=[...l.map(p=>({path:p,role:"reference",label:"developer guidance"})),...m.map(p=>({path:p,role:"reference",label:null}))]}else{if(!t||t.prompt.kind!=="fallback")return;let i=t.prompt.path;if(e.some(l=>l.files.some(m=>m.path===i)))return;f=t.files.map(l=>({...l,role:"reference",label:l.role==="system prompt"?"developer guidance":l.label}))}f=f.filter(i=>!e.some(l=>l.files.some(m=>m.path===i.path))),f.length&&(e[0]={...e[0],files:[...e[0].files,...f],sharedReferencePaths:[...e[0].sharedReferencePaths??[],...f.map(i=>i.path)]})}function ke(e,t){return["[","{"].some(n=>R(e.source.toks[t.from],n))&&z(e.source.toks,t.from)===t.to?{...t,to:t.to+1}:e.calls.find(n=>n.from===t.from&&n.to===t.to+1&&R(e.source.toks[t.to],")"))??t}function N(e,t,n=new Set){let{toks:f}=e.source;if(t.to!==t.from+1||!B(f[t.from])||["True","False","None"].includes(f[t.from].text))return t;let i=e.binding(f[t.from].text,t.from);return!i||i.append||!e.bindingIsCertain(i,t.from)||n.has(i.at)||e.functions.some(l=>l.from<t.from&&t.from<l.to&&l.params?.includes(i.name))?null:N(e,ke(e,i),new Set([...n,i.at]))}import{posix as dt}from"node:path";function ut(e,t,n,f,i){let{source:{path:l,toks:m}}=e,p=[],d=[],y=[],a=[],k=(u,o)=>a.push({path:u,reason:o}),c=(u,o,b,S=null)=>({path:o,role:u,label:S,...b?{span:b}:{}}),r=(u,o)=>{let b=e.importBinding(u,o),S=t.filter(g=>g.name===u&&g.from<o&&(g.params!==null||g.kind==="class")&&(!e.owner(g.from)||e.owner(g.from)===e.owner(o)));if(!b)return S.length===1?{path:l,span:{from:m[S[0].from].line,to:m[S[0].to-1].endLine}}:null;let x=b.module.source,O=i.length===1?dt.dirname(dt.dirname(i[0])):"",s=We(x.startsWith(".")?l:`${O?`${O}/`:""}__root__.py`,x.startsWith(".")?x:`.${x}`,[b.name],"py",f);return s?{path:s}:null},h=n&&N(e,n);if(h&&R(m[h.from],"[")&&z(m,h.from)===h.to-1)for(let u of q(m,h.from)){let o=u.to===u.from+1&&B(m[u.from])&&!e.binding(m[u.from].text,u.from)?u:N(e,u);if(!o||!B(m[o.from])){k(l,"dynamic");continue}let b=m[o.from].text;if(!(o.to===o.from+1||R(m[o.from+1],"(")&&z(m,o.from+1)===o.to-1)){k(l,"dynamic");continue}if(e.functions.some(O=>O.from<o.from&&o.from<O.to&&O.params?.includes(b))){k(l,"dynamic");continue}if(!e.importBinding(b,o.from)&&!t.some(O=>O.name===b&&(O.params!==null||O.kind==="class")&&O.from<o.from)){k(l,"dynamic");continue}p.push(b);let x=r(b,o.from);x&&(y.push(c("tools",x.path,x.span,b)),d.push(x.path))}else n&&k(l,"dynamic");return{names:p,files:y,proofPaths:d,refused:a}}function ht(e,t,n,f,i,l){let m=t.source,{path:p,toks:d}=m,{files:y,paths:a,frameworks:k,defaultsByPath:c}=l,r={prompt:{kind:"none"},files:[]},h=[],u,o=(s,g)=>h.push({path:s,reason:g}),b=(s,g,P,w=null)=>({path:g,role:s,label:w,...P?{span:P}:{}});c.has(p)||c.set(p,ge(p,m.text,a));let S=c.get(p),x=s=>{r.layoutProof??={kind:"outside-loader",paths:[]},r.layoutProof.paths.push(s);let g=y[s];if(g===void 0){r.files.push(b("template",s)),o(s,"missing");return}let P=tt(g,e);if(P.unresolved.length||!P.fields.some(w=>w.key==="system_prompt"&&w.value!==null)){o(s,"invalid");return}for(let w of P.fields.filter(v=>v.value!==null))r.files.push(b(w.key==="system_prompt"?"system prompt":"template",s,w.span,w.key)),w.key==="system_prompt"&&(r.prompt={kind:"entry",path:s,span:w.span,text:w.value})},O=n.get("prompt_templates")??n.get("system_prompt");if(O){let s=N(t,O),g=s&&X(m,s);if(g&&n.has("system_prompt"))r.prompt={kind:"entry",path:p,span:g.span,text:d[s.from].value},u={path:p,start:g.start},r.files.push(b("system prompt",p,g.span));else if(s&&R(d[s.from],"{")&&z(d,s.from)===s.to-1){let P=!1,w=(v,C="")=>{let $=new Set;for(let j of q(d,v.from)){let M=d[j.from]?.kind==="string"?d[j.from].value:null;if(!M||$.has(M)||!R(d[j.from+1],":")){o(p,"invalid"),P=!0;return}$.add(M);let A=N(t,{from:j.from+2,to:j.to}),T=A&&X(m,A);T?(r.files.push(b(M==="system_prompt"?"system prompt":"template",p,T.span,C+M)),M==="system_prompt"&&!C&&(r.prompt={kind:"entry",path:p,span:T.span,text:d[A.from].value},u={path:p,start:T.start})):A&&R(d[A.from],"{")?w(A,`${C}${M}.`):o(p,"dynamic")}};w(s),P&&(r.prompt={kind:"none"},r.files=[])}else{let P=s&&S.find(w=>w.start===d[s.from].start&&w.end===d[s.to-1].end);P?.path&&!P.reason?x(P.path):o(p,"dynamic")}}else if(f.args.some(s=>!B(d[s.from])||!R(d[s.from+1],"=")))o(p,"dynamic");else if(k.length===1){let s=k[0],g=y[s];if(g===void 0)r.files.push(b("config",s)),r.layoutProof={kind:"outside-loader",paths:[s]};else{c.has(s)||c.set(s,ge(s,g,a));let P=c.get(s).filter(M=>M.className===i&&M.binding==="prompt_templates"&&M.forwarded),w=n.get("use_structured_outputs_internally"),v=w?N(t,w):null,C=v&&v.to===v.from+1&&["True","False"].includes(d[v.from].text)?d[v.from].text==="True":null,$=P.filter(M=>M.when?.every(A=>A.parameter==="use_structured_outputs_internally"&&A.value===(w?C:A.defaultValue))),j=$.length===1?$[0]:null;j?.path&&(!j.reason||j.reason==="missing")?x(j.path):o(s,"dynamic")}}else o(p,k.length>1?"dynamic":"missing");return{...r,promptSite:u,refused:h}}function gt(e,t,n=t.files){let f={agents:[],refused:[]};if(!I(e))return f;let i={...n,...t.files},l=new Set([...Object.keys(i),...t.listedPaths??[]]),m=new Set(Ke(e,[...l],t.root)),p=[...l].filter(a=>/(?:^|\/)smolagents\/agents\.py$/.test(a)),d=new Map,y=(a,k)=>f.refused.push({path:a,reason:k});for(let[a,k]of Object.entries(t.files)){if(!k.includes("smolagents")||Le(a,{listing:l,root:t.root})&&!Te(e,a,t.root)||!/\.py$/i.test(a)&&!m.has(a)||!_(e,{path:a,size:Buffer.byteLength(k)},{purpose:"code-scan",route:"github",root:t.root,listing:l}).admitted)continue;let c=m.has(a)?qe(a,k).filter(s=>s.lang==="py"):null,r=c?Je(k,c):k,h=Re(a,r,"py"),u=Be(h,{includeMembers:!0}),o=ze(h,u,{enclosingBindings:!0}),{toks:b}=h,S=[],x=s=>{let g=s&&N(o,s);return g&&X(h,g)?b[g.from].value:null},O=(s,g,P,w=null)=>({path:g,role:s,label:w,...P?{span:P}:{}});for(let s of o.calls){let g=o.importBinding(s.callee,s.from);if(!g||!["smolagents","smolagents.agents"].includes(g.module.source)||!["CodeAgent","ToolCallingAgent"].includes(g.name))continue;let P=new Map(s.args.flatMap(E=>B(b[E.from])&&R(b[E.from+1],"=")?[[b[E.from].text,{from:E.from+2,to:E.to}]]:[])),w=c?.find(E=>E.span.from<=b[s.from].line&&b[s.from].line<=E.span.to);if(w&&(g.module.line<w.span.from||w.span.to<g.module.line)){let E=P.get("managed_agents"),Y=E&&N(o,E);if(!(Y&&R(b[Y.from],"[")&&q(b,Y.from).some(me=>{let $e=N(o,me);return $e&&S.some(Bt=>Bt.at===$e.from)})))continue}let C=o.assignments.find(E=>E.from===s.from&&ke(o,E).to===s.to)?.name??`line-${b[s.from].line}`,$=`smolagents:${JSON.stringify([a,b[s.from].start])}`,j={from:b[s.from].line,to:b[s.to-1].endLine},M={key:$,name:x(P.get("name"))??C,model:null,description:x(P.get("description")),prompt:{kind:"none"},files:[],skills:[],tools:[],subagents:[],layoutCall:{path:a,callStart:b[s.from].start,line:j.from,loadedPrompt:!0}},A=ht(e,o,P,s,g.name,{files:i,paths:l,frameworks:p,defaultsByPath:d});M.prompt=A.prompt,M.files.push(...A.files),A.layoutProof&&(M.layoutProof=A.layoutProof),A.promptSite&&(M.layoutCall.promptPath=A.promptSite.path,M.layoutCall.promptStart=A.promptSite.start),f.refused.push(...A.refused),M.files.push(O(c?"system prompt":"config",a,j));let T=ut(o,u,P.get("tools"),l,p);M.tools=T.names,M.files.push(...T.files),T.proofPaths.length&&(M.layoutProof??={kind:"outside-loader",paths:[]},M.layoutProof.paths.push(...T.proofPaths)),f.refused.push(...T.refused),f.agents.push(M),S.push({agent:M,name:C,at:s.from,children:P.get("managed_agents")})}for(let s of S){if(!s.children)continue;let g=N(o,s.children);if(!g||!R(b[g.from],"[")||z(b,g.from)!==g.to-1){y(a,"dynamic");continue}for(let P of q(b,g.from)){let w=N(o,P),v=w&&S.find($=>$.at===w.from&&w.to===o.calls.find(j=>j.from===$.at)?.to);if(!v||v===s){y(a,"dynamic");continue}let C=v.agent.prompt;s.agent.subagents.push({key:v.agent.key,path:C.kind==="none"?a:C.path,name:v.agent.name,description:v.agent.description,prompt:C.kind==="entry"?C.text:"",tools:v.agent.tools,skillPaths:[],files:v.agent.files})}}}return f}import{basename as Dt}from"node:path";import{basename as Kt}from"node:path";var kt=/^[\w.*:/()-]+$/,bt=/^(?:true|false|null|~|[-+]?(?:\d[\d_.eExXoObB+-]*|\.\d[\d_eE+-]*|\.inf|\.nan)|\d{4}-\d{1,2}-\d{1,2}(?:[Tt].*)?)$/i,le=e=>kt.test(e)&&!e.startsWith("*")&&!bt.test(e);function ae(e){if(e.startsWith('"'))try{return JSON.parse(e)}catch{return e}return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/''/g,"'"):e}function Z(e,t=!1,n=!1){let f=[],i="",l=0,m=-1,p=0,d=()=>{m>=0&&f.push([m,p]),m=-1};for(let y=0;y<e.length;y++){let a=e[y];if(i){i==='"'&&a==="\\"?y++:a===i&&(i==="'"&&e[y+1]==="'"?y++:i=""),p=y+1;continue}if(!n&&a==="#"&&(y===0||/\s/.test(e[y-1]))){if(!t)return d(),{spans:f,end:y,comment:e.slice(y)};let k=e.indexOf(`
2
+ `,y);y=k<0?e.length:k;continue}if(t&&a==="]"&&l===0)return d(),{spans:f,end:y,comment:""};if(a===","&&l===0){d();continue}/\s/.test(a)||(m<0&&(m=y),(a==='"'||a==="'")&&(m===y||l>0)?i=a:a==="("?l++:a===")"&&l>0&&l--,p=y+1)}if(t)throw new Error("Unclosed frontmatter tool list");return d(),{spans:f,end:e.length,comment:""}}function yt(e,t){let n=e.startsWith("["),f=Z(n?e.slice(1):e,n),i=(n?e.slice(1,f.end+1):e.slice(0,f.end)).trimEnd(),l=!n&&f.spans.length===1&&/^["']/.test(i)&&ae(i)!==i?i[0]:"",m=l?ae(i):n?e.slice(1,f.end+1):e.slice(0,f.end).trimEnd(),p=n?f.spans:Z(m,!1,!!l).spans,d=0,y=p.flatMap(([k,c],r)=>{let h=m.slice(k,c),u=ae(h),o=m.slice(d,k).replace(/[^\S\n]*#[^\n]*/g,""),b=n?m.slice(c,p[r+1]?.[0]??m.length):"",S=b.match(/[^\S\n]*#[^\n]*/g)?.join(`
3
+ `)??"";return d=c,u?[{name:u,raw:h,before:o,note:S,noteAfterComma:/^[^\S\n]*,/.test(b)}]:[]}),a=n?e.slice(f.end+2).split(`
4
+ `)[0]:e.slice(i.length);return{style:n?"flow":"comma",outerQuote:l,quote:y.find(k=>/^["']/.test(k.raw))?.raw[0]??"",prefix:"",suffix:a,head:(y[0]?.before??m).replace(/,/g,""),tail:y.length?m.slice(d).replace(/[^\S\n]*#[^\n]*/g,""):"",separator:y[1]?.before.replace(/#[^\n]*/g,"")??(m.includes(`
5
+ `)?`,
6
+ ${m.match(/\n([^\S\n]*)/)[1]}`:", "),entries:y,first:t,last:t+e.slice(0,n?f.end+2:e.length).split(`
7
+ `).length-1,indent:" - ",blockComments:[]}}function zt(e){let t=Q(e),n=t?.raw.map(p=>p.replace(/\r$/,""))??null,f=[],i=[],l={},m=[];if(n)for(let p=0;p<n.length;p++){let d=/^([A-Za-z_][\w-]*\s*:[^\S\n]*)(.*)$/.exec(n[p]);if(!d||!/^tools\s*:/i.test(d[1]))continue;let y=Z(d[2]),a;d[2].startsWith("[")?a=yt(n.slice(p).join(`
8
+ `).slice(d[1].length),p):a=yt(d[2],p),a.prefix=d[1];let k=a.style==="flow"?Z(a.suffix).comment:y.comment;if(k&&(l[a.style==="flow"?a.last:p]=k),a.style==="flow")for(let c of a.entries)c.note&&m.push({tool:c.name,comment:c.note.trim()});if(!d[2].slice(0,y.end).trim()){a.style="block",a.suffix=d[2];for(let c=p+1;c<n.length;c++){if(!n[c].trim()||/^\s*#/.test(n[c])){/^\s+#/.test(n[c])&&a.blockComments.push(c);continue}let r=/^(\s*-\s+)(.*)$/.exec(n[c]);if(!r)break;let h=Z(r[2]),u=r[2].slice(0,h.end).trimEnd(),o=ae(u);a.indent=r[1],o&&a.entries.push({name:o,raw:u,before:"",note:"",noteAfterComma:!1,row:n[c]}),h.comment&&o&&m.push({tool:o,comment:h.comment}),i.push(c),a.last=c}a.quote=a.entries.map(c=>c.raw).find(c=>/^["']/.test(c))?.[0]??""}for(let c=p;c<=(a.style==="block"?p:a.last);c++)i.push(c);f.push(a),p=a.last}return{header:t,lists:f,tools:f.length?f.flatMap(p=>p.entries.map(d=>d.name)):null,lines:n,toolLines:i,toolComments:l,itemComments:m}}function Pt(e){try{return zt(e)}catch{let t=Q(e);return{header:t,lists:[],tools:[],lines:t.raw.map(n=>n.replace(/\r$/,"")),toolLines:[],toolComments:{},itemComments:[],error:"Unclosed frontmatter tool list"}}}function Gt(e){let{tools:t,lines:n,toolLines:f,toolComments:i,itemComments:l,error:m}=Pt(e);return{tools:t,lines:n,toolLines:f,toolComments:i,itemComments:l,...m?{error:m}:{}}}function wt(e){let t=Gt(e);if(t.error)throw new Error(t.error);let{tools:n,lines:f,toolLines:i,toolComments:l,itemComments:m}=t;return{tools:n,lines:f,toolLines:i,toolComments:l,itemComments:m}}function ie(e){return e.every(t=>kt.test(t)&&!t.startsWith("*"))&&(e.length!==1||le(e[0]))?e.join(", "):`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}function H(e,t){return t==="'"&&!/[\r\n]/.test(e)?`'${e.replace(/'/g,"''")}'`:t==='"'||!le(e)?JSON.stringify(e):e}function Bo(e,t){let n=Pt(e);if(n.error)return e;let f=n.tools??[],i=t([...f]);if(i.length===f.length&&i.every((h,u)=>h===f[u]))return e;if(!n.header){let h=e.startsWith("\uFEFF")?"\uFEFF":"";return`${h}---
9
+ tools: ${ie(i)}
10
+ ---
11
+ ${e.slice(h.length)}`}let{header:l,lists:m,toolLines:p,toolComments:d}=n,y=new Map,a=m[0];if(a){let h=m.flatMap(b=>b.entries),u=i.map(b=>{let S=h.findIndex(x=>x.name===b);return S<0?{name:b,raw:H(b,a.quote),before:a.separator,note:"",noteAfterComma:!1}:h.splice(S,1)[0]}),o=a.prefix.endsWith(" ")?a.prefix:`${a.prefix} `;if(!i.length)y.set(a.first,`${o}[]${a.style==="block"&&a.suffix?` ${a.suffix}`:a.suffix}`);else if(a.style==="block"){y.set(a.first,`${a.prefix}${a.suffix}`);let b=p.filter(S=>S>a.first&&S<=a.last).sort((S,x)=>S-x);for(let S=0;S<u.length;S++){let x=u[S],O=a.entries.includes(x)&&x.row?le(x.raw)||/^["']/.test(x.raw)?x.row:x.row.replace(x.raw,H(x.name,a.quote)):`${a.indent}${H(x.name,a.quote)}`,s=b[Math.min(S,b.length-1)]??a.first;y.set(s,`${y.has(s)?`${y.get(s)}${l.newline}`:""}${O}`)}}else{let b=a.style==="flow"||i.length===1&&bt.test(i[0])||i.some(s=>s.includes(",")||s!==s.trim()||/[\r\n]|(?:^|\s)#|:\s|^[[\]{}&*!|>'"%@`]/.test(s)),S=a.head;for(let[s,g]of u.entries()){if(s){let P=g.before||a.separator,w=u[s-1];w.note&&(w.noteAfterComma?(P=P.replace(/,[^\S\n]*/,`,${w.note}`),P.includes(`
12
+ `)||(P+=`
13
+ `)):P=`${w.note}${/^[^\S\n]*\n/.test(P)?"":`
14
+ `}${P}`),S+=P}S+=b?/^["']/.test(g.raw)||le(g.raw)?g.raw:H(g.name,a.quote):g.name}let x=u[u.length-1];x.note?(S+=x.noteAfterComma&&!a.tail.includes(",")?",":"",S+=x.noteAfterComma&&a.tail.includes(",")?a.tail.replace(",",`,${x.note}`):`${x.note}${a.tail}`,a.tail.includes(`
15
+ `)||(S+=`
16
+ `)):S+=a.tail;let O=b?`[${S}]`:a.outerQuote?H(S,a.outerQuote):S;y.set(a.first,`${a.prefix}${O}${a.suffix}`.replace(/\n/g,l.newline))}}let k=new Set(p),c=l.raw.map((h,u)=>y.has(u)?`${y.get(u)}${l.newline}`:k.has(u)?d[u]&&u>a.last?`${d[u]}${l.newline}`:"":`${!i.length&&m.some(b=>b.blockComments.includes(u))?h.trimStart():h}
17
+ `).join(""),r=a?"":`tools: ${ie(i)}${l.newline}`;return`${e.slice(0,l.start)}${c}${r}${e.slice(l.end)}`}function be(e){return e.CF_LEGACY_TOOL_LISTS!=="1"}function Ko(e,t){return be(e)?ie(t):t.join(", ")}var qt=/^\s*(name|description|tools|model)\s*:\s*(.+?)\s*$/i;function Jt(e){if(e.startsWith('"')&&e.endsWith('"'))try{return JSON.parse(e)}catch{}return e.replace(/^["']|["']$/g,"")}function ee(e,t,n,f){let i=be(e),l=Kt(t).replace(/\.md$/i,""),m,p,d=[],y=!1,a=n,k=[],c=Q(n,i?void 0:"markdown");if(c){a=n.slice(c.bodyStart).trim();let h=i?c.raw.map(u=>u.replace(/\r$/,"")):c.raw;for(let u=0;u<h.length;u++){let b=h[u].match(qt);if(!b)continue;let S=b[1].toLowerCase(),x=Jt(b[2]);if(S==="name")l=x;else if(S==="description")if(/^[>|][+-]?$/.test(b[2])){let O=[];for(;u+1<h.length&&(/^\s+\S/.test(h[u+1])||h[u+1].trim()==="");)O.push(h[++u].trim());m=O.join(x[0]===">"?" ":`
18
+ `).trim()}else m=x;else S==="model"?p=x:S==="tools"&&!i&&(y=!0,d=x.replace(/^\[|\]$/g,"").split(",").map(O=>O.trim()).filter(Boolean))}}if(i)try{let h=wt(n);d=h.tools??[],y=h.tools!==null}catch{y=!0,k.push("tools could not be read; check the tool list")}let r=a.trim();return{name:l,...m!==void 0?{description:m}:{},...r?{prompt:r}:{},...!f?.preserveToolAbsence||y?{tools:d}:{},...p!==void 0?{model:p}:{},...k.length?{warnings:k}:{}}}function St(e,t,n){let f=t.managed,i=[],l=new Set([...f.agents,...f.configs,...Object.keys(n.files),...n.listedPaths??[]]),m=new Set(Ue(e,[...l],n.files)),p=Object.fromEntries(Object.entries(n.files).filter(([c,r])=>{if(m.has(c))return!1;let h=_(e,{path:c,text:r},{purpose:"override",route:"github",root:t.folder,listing:l,managedFiles:n.files});return!h.admitted&&h.reason==="secret"&&i.push({path:c,reason:"secret"}),h.admitted})),d=new Map;for(let c of f.agents){if(p[c]===void 0){i.some(h=>h.path===c)||i.push({path:c,reason:"missing"});continue}let r=Ye(c,p[c],f,n.listedPaths??Object.keys(n.files));i.push(...r.refused),d.set(c,r)}let y=new Set([...d.values()].flatMap(c=>c.relationships.filter(r=>r.kind==="agent").map(r=>r.path))),a=[...d.values()].filter(c=>!y.has(c.path));return!a.length&&d.size&&a.push(d.values().next().value),{agents:a.map(c=>{let r=[{path:c.path,role:"system prompt",label:null}],h=[],u=[],o=(b,S,x)=>{for(let O of b.relationships){if(p[O.path]===void 0){i.some(s=>s.path===O.path)||i.push({path:O.path,reason:"missing"});continue}if(O.kind==="agent"){if(S.has(O.path)){i.push({path:O.path,reason:"cycle"});continue}let s=d.get(O.path);if(!s||u.some(P=>P.path===s.path))continue;let g=[];u.push({path:s.path,name:s.name,description:s.description,prompt:s.prompt,...s.model?{model:s.model}:{},tools:[],skillPaths:[],files:g}),o(s,new Set([...S,s.path]),g)}else if(O.kind==="skill"&&n.skills&&Ie(e)||O.kind==="config"&&Ve(p[O.path])){if(x.some(s=>s.path===O.path))continue;if(x.push({path:O.path,role:O.kind==="skill"?"skill":"config",label:null}),O.kind==="skill"&&b===c){let s=ee(e,Dt(O.path),p[O.path]);h.push({path:O.path,name:s.name,description:s.description??"",body:s.prompt??""})}}}};return o(c,new Set([c.path]),r),{key:`managed:${c.path}`,name:c.name,model:c.model,description:c.description,prompt:{kind:"dedicated",path:c.path},files:r,tools:[],skills:h,subagents:u}}),notes:[],registry:!1,refused:i}}function vt(e,t,n){let f=t.miniSwe,i=n.templateSelection?.agentPath===f.agentPath?n.templateSelection.configPaths:void 0,l=ot(e,f,n.files,i),m=l.unresolved.filter(o=>o.reason!=="runtime-variable").map(o=>({path:o.target??o.path,reason:o.reason==="duplicate"?"invalid":o.reason})),p=l.fields.find(o=>o.key==="agent.system_template"&&o.value!==null),d=l.fields.find(o=>o.key==="agent.instance_template"&&o.value!==null),y=l.unresolved.some(o=>l.selectedPaths.includes(o.path)&&o.source===o.path);if(!p||!d||y||m.some(o=>o.reason==="invalid"))return{agents:[],notes:[],registry:!1,refused:m};let a=[p,...l.fields.filter(o=>o!==p)].map(o=>({path:o.path,span:o.span,label:o.key,role:o===p?"system prompt":o.key.endsWith("_template")?"template":"config"}));a.push(...l.loaded.map(o=>({path:o.path,role:"template",label:null})));let k=[];for(let o of a){let b=k.find(S=>S.path===o.path);b?b.span&&o.span&&(b.span={from:Math.min(b.span.from,o.span.from),to:Math.max(b.span.to,o.span.to)}):k.push({...o})}let c=[...new Set(k.map(o=>o.path))],r=Object.fromEntries(c.map(o=>[o,n.files[o]])),h=new Map(c.map(o=>[o,Buffer.byteLength(r[o])])),u=ct(e,{ownPaths:c},{files:r,sizes:h,root:t.folder});return m.push(...u.refused,...u.skipped),l.fields.some(o=>!u.paths.includes(o.path))?{agents:[],notes:[],registry:!1,refused:m}:(l.loaded=l.loaded.filter(o=>u.paths.includes(o.path)),l.edges=l.edges.filter(o=>u.paths.includes(o.from)&&u.paths.includes(o.to)),{agents:[{key:t.key,name:n.fallbackName,model:l.model,description:null,prompt:{kind:"entry",path:p.path,span:p.span,text:p.value},files:k.filter(o=>u.paths.includes(o.path)),tools:[],skills:[],subagents:[],templateVariants:l}],notes:[],registry:!1,refused:m})}function Ot(e,t,n){if(!t.skills||!ne(e))return n;let f=[...new Set([...Object.keys(t.files),...t.listedPaths??[]])],i=V(e,f,t.root,{files:t.files,listedPaths:t.listedPaths,agentConfigurations:t.agentConfigurations}),l=new Set(i.files.filter(k=>k.role==="skill").map(k=>k.path)),m=k=>[...new Set([...k.skillPaths.filter(c=>l.has(c)),...k.files?.filter(c=>c.role==="skill").map(c=>c.path)??[]])],p=n.agents.flatMap(k=>[...k.skills.map(c=>c.path),...k.subagents.flatMap(m)]),d=re(e,{skillPaths:p,paths:f,files:t.files,root:t.root});for(let k of d)k.files=k.files.filter(c=>Object.hasOwn(t.files,c.path));let y=new Map(d.map(k=>[k.ownerPath,k])),a=(k,c)=>{let r=new Set(c.flatMap(u=>u.refused.map(o=>o.path))),h=k.filter(u=>u.role!=="reference"||!r.has(u.path));for(let u of c)for(let o of u.files)h.some(b=>b.path===o.path)||h.push({path:o.path,role:"reference",label:null});return h};return{...n,agents:n.agents.map(k=>{let c=k.skills.flatMap(r=>y.has(r.path)?[y.get(r.path)]:[]);return{...k,files:a(k.files,c),skills:k.skills.map(r=>({...r,...y.has(r.path)?{manifest:y.get(r.path)}:{}})),subagents:k.subagents.map(r=>{let h=m(r).flatMap(g=>y.has(g)?[y.get(g)]:[]);if(!h.length)return r;let u=i.ownerOf(r.path),o=W(e,f.filter(g=>i.ownerOf(g)===u),u?.folder),b=r.files??r.skillPaths.map(g=>({path:g,role:l.has(g)?"skill":"reference",label:o.skillNames[g]??o.skillRefNames[g]??null})),S=new Set([...k.files.map(g=>g.path),...o.subagentPaths,...Object.keys(o.subagentSkillOwners)]),x=o.scoped.filter(g=>!S.has(g)&&J(g)&&Object.hasOwn(t.files,g)).sort(),O=r.files?[]:D(x,[t.files[r.path],...b.filter(g=>g.role==="reference").map(g=>t.files[g.path])],o.stripRoot).map(g=>({path:g,role:"reference",label:null})),s=a([...b,...O],h);return{...r,files:s,skillPaths:[...new Set([...r.skillPaths,...m(r),...h.flatMap(g=>g.files.map(P=>P.path))])].filter(g=>s.some(P=>P.path===g)),skillManifests:h}})}})}}import{basename as Lt}from"node:path";import{createHash as Ut}from"node:crypto";var xt=25,Yt=e=>oe(e,"CF_IMPORT_AGENT_PAGES");function yn(e,t,n,f,i=xt,l){if(!Yt(e))return null;let m=f?.pageSize??i,p=f?.offset??0;if(![8,25,400].includes(m)||!Number.isSafeInteger(p)||p<0)throw new Error("invalid-agent-page");let d=[...new Map(t.map(P=>[P.id,P])).values()],y=Ut("sha256").update(JSON.stringify({version:1,context:{commit:n.commit,scope:n.scope},size:m,budgets:l,settings:Object.entries(Ce(e)).filter(([,P])=>P!==void 0).sort(([P],[w])=>P.localeCompare(w)),rows:d.map(({id:P,path:w,groupKey:v,pool:C})=>({id:P,path:w,groupKey:v,pool:C}))})).digest("hex");if(f&&(f.version!==1||f.binding!==y))throw new Error("stale-agent-page");let a=d.map((P,w)=>{let v=Ct(e,P,w);return typeof v=="string"?`group:${v}`:`agent:${P.id}`}),k=[...new Set(a)];if(p>0&&p>=k.length)throw new Error("invalid-agent-page");let c=f?.end;if(c!==void 0&&(!Number.isSafeInteger(c)||c<p||c>k.length||c>p+m||c===p&&k.length>0))throw new Error("invalid-agent-page");let r=new Set,h=new Set,u=l?{...l}:null,o=p,b=!1;for(let P of k.slice(p,c??p+m)){let w=new Map(d.filter((C,$)=>a[$]===P&&!h.has(d[$].path)).map(C=>[C.path,C])),v={strong:0,possible:0};for(let C of w.values())v[C.pool??"strong"]+=C.bytes;if(c===void 0&&u&&r.size&&(v.strong>u.strong||v.possible>u.possible)){b=!0;break}r.add(P),o++;for(let C of w.keys())h.add(C);u&&(u.strong=Math.max(0,u.strong-v.strong),u.possible=Math.max(0,u.possible-v.possible))}c!==void 0&&(b=o<k.length&&o-p<m);let S=new Set(k.slice(o)),x=d.filter((P,w)=>r.has(a[w])),O=d.filter((P,w)=>S.has(a[w])).map(P=>P.id),s={version:1,binding:y,offset:p,pageSize:m,end:o},g=new Map(x.map(P=>[P.path,P.bytes]));return{context:{...n},current:s,continuation:O.length?{version:1,binding:y,offset:o,pageSize:m}:null,detected:d.length,detectedGroups:k.length,selected:x.map(P=>P.id),remaining:O,refusals:O.map(P=>({id:P,reason:b?"prompt-over-limit":"page"})),partial:O.length>0,estimatedInputBytes:[...g.values()].reduce((P,w)=>P+w,0)}}function $t(){return xt}function Ct(e,t,n){return _e(e)&&t!==null&&typeof t=="object"&&"groupKey"in t&&typeof t.groupKey=="string"&&t.groupKey?t.groupKey:n}function Mt(e,t){let n=$t(),f=new Set,i=[],l=[];return t.forEach((m,p)=>{let d=Ct(e,m,p);f.has(d)||f.size<n?(f.add(d),i.push(m)):l.push(m)}),{kept:i,leftOut:l}}function jt(e){let t=$t();if(e.kind==="layout")return`Only ${t} agents can be added per import, so ${e.leftOut} were left out.`;if(e.kind==="scan"){let f=e.found-t;return`${f} ${f===1?"agent wasn't":"agents weren't"} read because the repository is large.`}let n=e.kind==="import"?`Not added: this import already has ${t} agents.`:`Only the ${t} strongest agents of a repository are added.`;return e.kind==="model"?`${e.name}: ${n}`:n}var fe="crew:";function Pe(e){return e.startsWith(fe)}function we(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Object.entries(e);return!t.length||t.some(([,n])=>typeof n!="string"||n.length>=2e3)?null:t.map(([n,f])=>`${n}: ${f}`).join(`
19
+ `)}function At(e,t,n={},f=Object.keys(t)){return I(n)?Vt(e,t,f):e.kind!=="crew"?{agents:[],notes:[],registry:!1}:Et(e,t)}function Et(e,t){let n=[],f=[],i=(p,d)=>f.push({code:"unreadable-crew",path:p,detail:d?`${d} could not be read; some instructions may be missing.`:"could not be read; some instructions may be missing."}),l=se(t[e.agentsPath]??""),m=e.tasksPath?se(t[e.tasksPath]??""):[];l?.length||i(e.agentsPath),m===null&&i(e.tasksPath);for(let{key:p,value:d,span:y}of l??[]){if(!U(d)){i(e.agentsPath,p);continue}let{llm:a,tools:k,...c}=d,r=we(c);if(r===null&&Object.keys(c).length){i(e.agentsPath,p);continue}let h=[{role:"system prompt",path:e.agentsPath,label:p,span:y}];for(let u of m??[])U(u.value)&&u.value.agent===p&&h.push({role:"knowledge",path:e.tasksPath,label:u.key,span:u.span});n.push({key:`${fe}${e.agentsPath}#${p}`,name:p,model:typeof a=="string"?a:null,description:typeof d.goal=="string"?d.goal:null,entry:{path:e.agentsPath,span:y,text:r},files:h,tools:Array.isArray(k)?[...new Set(k.filter(u=>typeof u=="string"&&!!u.trim()))]:[],skills:[],subagents:[]})}return{agents:n,notes:f,registry:!1}}function U(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Vt(e,t,n){let f=new Set([...n,...Object.keys(t)]),i=Object.entries(t).filter(([r])=>r.endsWith(".py")).map(([r,h])=>nt(r,h,f,e.folder)),l=i.flatMap(r=>r.agents),m=i.flatMap(r=>r.refused);if(!l.length)return e.kind==="crew"&&/\.ya?ml$/i.test(e.agentsPath)?{...Et(e,t),refused:m}:{agents:[],notes:[],refused:m,registry:!1};let p=new Map,d=r=>{if(!p.has(r)){let h=t[r]===void 0?null:se(t[r]);p.set(r,h),h===null&&m.push({path:r,reason:t[r]===void 0?"missing":"invalid"})}return p.get(r)??[]},y=i.flatMap(r=>r.tasks).flatMap(r=>{let h=r.config?.path?d(r.config.path).find(b=>b.key===r.config.key):void 0;if(r.config&&(!r.config.path||!h||!U(h.value)))return r.config.path&&m.push({path:r.config.path,reason:h?"invalid":"missing"}),[];let u=U(h?.value)?h.value:{},o=r.factory.includes(".")?r.factory.slice(0,r.factory.lastIndexOf(".")):null;return[{fact:r,path:r.config?.path??r.path,key:r.config?.key??r.factory,span:h?.span??r.span,agent:r.agent??(typeof u.agent=="string"?o?`${o}.${u.agent}`:u.agent:null),context:[...r.context,...Array.isArray(u.context)?u.context.filter(b=>typeof b=="string"):[]],tools:r.tools}]}),a=i.flatMap(r=>r.tasks).filter(r=>r.config),k=a.flatMap(r=>r.config?.path?[{path:r.config.path,source:r.path,owner:r.factory.includes(".")?r.factory.slice(0,r.factory.lastIndexOf(".")):null}]:[]);!a.length&&e.kind==="crew"&&e.tasksPath&&k.push({path:e.tasksPath,source:e.tasksPath,owner:null});for(let{path:r,source:h,owner:u}of k)for(let o of d(r)){if(y.some(S=>S.path===r&&S.key===o.key&&S.fact.path===h&&(S.fact.factory.includes(".")?S.fact.factory.slice(0,S.fact.factory.lastIndexOf(".")):null)===u)||!U(o.value))continue;let b=o.value;y.push({fact:{path:h,factory:u?`${u}.${o.key}`:o.key,span:o.span,callStart:0,agent:null,context:[],tools:[]},path:r,key:o.key,span:o.span,agent:typeof b.agent=="string"?u?`${u}.${b.agent}`:b.agent:null,context:Array.isArray(b.context)?b.context.filter(S=>typeof S=="string"):[],tools:[]})}let c=[];for(let r of l){let h=r.config?.path?d(r.config.path).find(v=>v.key===r.config.key):void 0;if(r.config&&(!r.config.path||!h||!U(h.value))){r.config.path&&m.push({path:r.config.path,reason:h?"invalid":"missing"});continue}let u=U(h?.value)?h.value:{},o={...Object.fromEntries(Object.entries(u).filter(([v,C])=>!["llm","tools"].includes(v)&&typeof C=="string")),...r.instructions},b=we(o);if(!b){m.push({path:r.path,reason:"dynamic"});continue}let S=r.config?.key??r.factory.split(".").at(-1),x=r.config?.path??r.path,O=h?.span??r.span,s=[{path:x,role:"system prompt",label:S,span:O}];x!==r.path&&s.push({path:r.path,role:"config",label:r.factory,span:r.span});let g=y.filter(v=>v.fact.path===r.path?v.agent===r.factory||v.agent===S:/\.ya?ml$/i.test(v.fact.path)&&v.agent===S&&l.filter(C=>(C.config?.key??C.factory)===S).length===1),P=new Set,w=[...r.tools];for(let v=0;v<g.length;v++){let C=g[v];if(!P.has(C)&&(P.add(C),!(C.fact.config&&!C.fact.config.path))){s.push({path:C.path,role:"knowledge",label:C.key,span:C.span}),w.push(...C.tools);for(let $ of C.context){let j=y.filter(M=>M.fact.path===C.fact.path&&M.fact.factory===$||M.path===C.path&&M.key===$);j.length===1?g.push(j[0]):m.push({path:C.path,reason:j.length?"dynamic":"missing"})}}}for(let v of w)v.path&&v.path!==r.path&&!s.some(C=>C.path===v.path)&&(t[v.path]===void 0&&m.push({path:v.path,reason:"missing"}),s.push({path:v.path,role:"tools",label:v.name}));c.push({key:`${fe}${r.path}#${r.factory}`,name:S,model:typeof u.llm=="string"?u.llm:null,description:typeof o.goal=="string"?o.goal:null,entry:{path:x,span:O,text:b},files:s,tools:[...new Set([...w.map(v=>v.name),...Array.isArray(u.tools)?u.tools.filter(v=>typeof v=="string"):[]])],skills:[],subagents:[],crewCall:{path:r.path,callStart:r.callStart}})}return{agents:c,notes:[],refused:m,registry:!1}}import{basename as Ft,posix as ce}from"node:path";function Rt(e,t,n){let f={...t.selected,codeAgentsFound:t.codeAgentsFound||t.selected.codeAgentsFound};if(!Se(e,f,n))return{kind:"none"};let i={...t.bodies,...f.files},l=W(e,Object.keys(i),G(f.root)).templatePaths,m=ve(e,{...f,files:i},l);if(!t.entries)return{kind:"search",paths:[],ownedPaths:m.ownedPaths};let p=new Set([...Object.keys(i),...t.attemptedPaths??[]]),d=new Set(m.facts.dependencies);for(let h of m.relatedReads)h.target.kind==="file"&&d.add(h.target.path);for(let h of t.entries)m.relatedReads.some(u=>u.target.kind==="directory"&&pe(u,h.path))&&d.add(h.path);let y=(h,u)=>{let o=_(e,h,{purpose:u,route:"local-folder"});return o.admitted||o.reason==="too-large"},a=[...new Set(t.entries.filter(h=>!p.has(h.path)&&(d.has(h.path)?y(h,"pointer"):L(h.path,f.root)===null&&Fe(h.path)!==null&&y(h,"code-support"))).map(h=>h.path))],k=G(f.root)??"",c=h=>ce.parse(h).name===(k?Ft(k):f.fallbackName)?0:Xe.test(Ft(h))?1:2,r=h=>ce.relative(k||".",ce.dirname(h)).split("/").filter(u=>u&&u!==".").length;return a.sort((h,u)=>Number(d.has(u))-Number(d.has(h))||c(h)-c(u)||r(h)-r(u)||(h<u?-1:h>u?1:0)),{kind:"search",paths:a,ownedPaths:m.ownedPaths}}function pe(e,t){return e.target.kind==="file"?e.target.path===t:ce.dirname(t)===e.target.path&&(!e.target.extension||t.endsWith(e.target.extension))}function Se(e,t,n){if(!te(e)||t.codeAgentsFound||t.explicitPrompt!==void 0||n.agents.length||t.listedPaths&&W(e,[...t.listedPaths],G(t.root)).configPath)return null;let f=W(e,Object.keys(t.files),G(t.root)).templatePaths;if(!f.length)return null;let i=Object.fromEntries(Object.entries(t.files).filter(([l])=>L(l,t.root)!==null&&_(e,{path:l},{purpose:"override",route:"github"}).admitted));return ue(e,i).reads.some(l=>f.some(m=>pe(l,m)))?null:f}function ve(e,t,n){let f=Object.fromEntries(Object.entries(t.files).filter(([c])=>_(e,{path:c},{purpose:"override",route:"github"}).admitted)),i=ue(e,f),l=i.reads.filter(c=>L(c.sourcePath,t.root)===null&&n.some(r=>pe(c,r))),m=n.filter(c=>l.some(r=>pe(r,c))).sort(),p=[...new Set(l.map(c=>c.sourcePath))].sort(),d=i.reads.filter(c=>p.includes(c.sourcePath)),y=d.flatMap(c=>c.target.kind==="file"&&Object.hasOwn(f,c.target.path)&&L(c.target.path,t.root)!==null&&!n.includes(c.target.path)?[c.target.path]:[]).sort(),a=l.flatMap(c=>c.consumerPaths).sort(),k=m.length?[...new Set([m[0],...n.filter(c=>c!==m[0]),...y,...p,...a])]:[];return{facts:i,relatedReads:d,provenTemplates:m,ownedPaths:k}}function cs(e,t,n={}){return de(e)&&!t.agentConfigurations&&(t={...t,agentConfigurations:Ze(e,t.listedPaths??Object.keys(t.files),t.root)}),st(e,t,Xt(e,t,n))}function Xt(e,t,n){let f=It(e,t),{answer:i,scopeProof:l}=Qt(e,t,f),m=rt(e);if(!m&&!i.agents.some(o=>o.crewCall||o.layoutCall))return ye(e,t,i);let p=[...new Set([...Object.keys(t.files),...t.listedPaths??[],...i.scopePaths??[]])],d=V(e,p,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),y=i.agents.filter(o=>m||o.crewCall||o.layoutCall).map(o=>{let b=f.agents.find($=>$.key===o.key),S=Oe(b?.files??[]),x=i.agentScopes?.find($=>$.key===o.key)?.folder,O=d.scopes.find($=>x===void 0?$.key===o.key:$.folder===x)??d.scopes[0],s=W(e,p.filter($=>d.ownerOf($)===O),O.folder),g=new Set([...o.files.filter($=>$.role!=="reference"||$.label!==null).map($=>$.path),...o.subagents.flatMap($=>[$.path,...b?.subagents.find(j=>j.path===$.path)?.skillPaths??$.skillPaths]),...i.notes.filter($=>$.code==="orphan-skill").map($=>$.path)]),P=s.scoped.filter($=>!g.has($)&&J($)).sort(),w=`convention:${JSON.stringify(o.key)}`,v=o.files.map($=>o.prompt.kind!=="none"&&o.prompt.path===$.path&&"span"in o.prompt?{...$,span:$.span??o.prompt.span}:$),C=o.subagents.map($=>{let j=b?.subagents.find(F=>F.path===$.path),M=$.files??$.skillPaths.map(F=>({path:F,role:s.skillNames[F]?"skill":"reference",label:s.skillNames[F]??s.skillRefNames[F]??null})),A=ne(e)?Oe(j?.files??[]):M.map(F=>F.path),T=$.files&&!s.subagentPaths.includes($.path)?[]:D(P,[$.path,...A].map(F=>t.files[F]??""),s.stripRoot),E=T.filter(F=>!M.some(me=>me.path===F)).map(F=>({path:F,role:"reference",label:null})),Y=i.agents.find(F=>"key"in $&&F.key===$.key);return{child:$,id:`${w}:${JSON.stringify("key"in $?$.key:$.path)}`,scopeProof:Y?.layoutProof??l,toolCall:Y?.layoutCall,independentReferences:[...Oe(j?.files??[]),...T],ownFiles:"key"in $?[...M,...E]:[{path:$.path,role:"system prompt",label:null},...M,...E]}});return{agent:o,id:w,scope:O,ownFiles:v,independentReferences:S,children:C,scopeProof:o.layoutProof??l,toolCall:o.crewCall??o.layoutCall}}),a=y.flatMap(({agent:o,id:b,scope:S,ownFiles:x,independentReferences:O,children:s,scopeProof:g,toolCall:P})=>[{id:b,scope:S,ownFiles:x,independentReferences:O,scopeProof:g,toolCall:P,sharedReferencePaths:o.sharedReferencePaths,fileProfile:o.crewCall||o.layoutCall?"layout":"convention",skillManifests:o.skills.flatMap(w=>w.manifest?[w.manifest]:[])},...s.map(({child:w,id:v,ownFiles:C,independentReferences:$,scopeProof:j,toolCall:M})=>({id:v,scope:S,ownFiles:C,independentReferences:$,scopeProof:j,toolCall:M,fileProfile:"key"in w?"layout":"convention",skillManifests:w.skillManifests}))]),k=pt(e,a,{files:t.files,sizes:n.sizes??new Map(Object.entries(t.files).map(([o,b])=>[o,Buffer.byteLength(b)])),total:n.total,root:t.root,scopes:d}),c=new Map(k.map(o=>[o.agentId,o])),{complete:r,...h}=i,u=new Map(y.map(({agent:o,id:b,children:S})=>{let x=c.get(b);return[o.key,{...o,manifest:x,files:_t(x,o.files),skills:o.skills.filter(O=>x.files.some(s=>s.path===O.path)),subagents:S.flatMap(({child:O,id:s,ownFiles:g})=>{let P=c.get(s);if(!P.files.some(C=>C.path===O.path))return[];let w=_t(P,g),v="key"in O?w:w.filter(C=>C.path!==O.path);return[{...O,files:v,skillPaths:O.skillPaths.filter(C=>v.some($=>$.path===C))}]})}]}));return ye(e,t,{...h,...r&&!k.some(o=>o.refused.length)?{complete:r}:{},scopePaths:p,manifests:k,agents:i.agents.map(o=>u.get(o.key)??o)})}function _t(e,t){return e.files.flatMap(n=>t.some(f=>f.path===n.path)?t.filter(f=>f.path===n.path):[{path:n.path,role:n.roles.includes("config")?"config":"tools",label:null,...n.spans.length===1?{span:n.spans[0]}:{}}])}function Oe(e){return e.filter(t=>t.role==="reference"&&t.label===null).map(t=>t.path)}function Qt(e,t,n){let f=Ot(e,t,n);if(!K(e)&&t.codeAgentsFound)return{answer:{...f,projection:"code"}};let i=Se(e,t,f);if(!i)return{answer:f};let l=ve(e,t,i);if(!l.provenTemplates.length)return{answer:f};let m=l.provenTemplates[0],p=new Set(f.agentScopes?.find(y=>y.key===null)?.notes),d=y=>!(y.code==="no-prompt"&&y.detail==="no-conventions"&&y.path===(G(t.root)??""));return{scopeProof:{kind:"outside-loader",paths:l.ownedPaths},answer:{...f,projection:"conventions",notes:f.notes.filter(d),...f.agentScopes?{agentScopes:f.agentScopes.map(y=>({...y,notes:y.notes.filter(d)}))}:{},...f.unassignedNotes?{unassignedNotes:f.unassignedNotes.filter(y=>!p.has(y))}:{},agents:[{key:null,name:t.fallbackName,model:null,description:null,prompt:{kind:"dedicated",path:m},files:l.ownedPaths.map(y=>({path:y,role:y===m?"system prompt":i.includes(y)?"template":"reference",label:null})),skills:[],subagents:[]}]}}}function ps(e,t){return te(e)?Rt(e,t,It(e,t.selected)):{kind:"none"}}function It(e,t){if(!Ne(e)){let{agents:s,notes:g}=xe(e,t,null);return{agents:s,notes:g}}let n=De(e,t.listedPaths??[]).flatMap(s=>[...s.agents,...s.configs]),f=[...new Set([...Object.keys(t.files),...n,...I(e)?t.listedPaths??[]:[]])],{scopes:i,ownerOf:l,ignoredPaths:m,pluginFolders:p}=V(e,f,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),d=new Set(m),y=new Map(i.map(s=>[s,{}]));for(let[s,g]of Object.entries(t.files)){if(d.has(s))continue;let P=l(s);P&&(y.get(P)[s]=g)}let a=i.map(s=>{let g=y.get(s),P={...t,files:g,root:s.folder,fallbackName:s.key===null?t.fallbackName:Lt(s.folder),explicitPrompt:s.key===null?t.explicitPrompt:void 0,...t.pointerFiles?{pointerFiles:Object.fromEntries(Object.entries(t.pointerFiles).filter(([w])=>!d.has(w)&&l(w)===s))}:{}};return{scope:s,input:P,answer:Nt(e,s,P,!1,t.files)}}),k=[],c=new Map,r=a.filter(({scope:s,input:g,answer:P})=>{let w=P.agents[0];if(!w)return!0;let v=Object.entries(g.files).map(([j,M])=>[L(j,s.folder),M]).sort(([j],[M])=>j<M?-1:j>M?1:0),C=JSON.stringify([w.name,v,...s.managed||I(e)&&(s.kind==="crew"||p.includes(s.folder))?[s.folder]:[]]),$=c.get(C);return $!==void 0?(k.push({code:"duplicate-agent",path:s.folder,detail:$}),!1):(c.set(C,s.folder),!0)}),h=r.find(({scope:s})=>s.key===null),u=h.answer.agents[0];r.some(({scope:s,answer:g})=>s.key!==null&&g.agents.length)&&(h.answer=Nt(e,h.scope,h.input,!0,t.files),h.answer.notes=h.answer.notes.filter(s=>s.detail!=="no-conventions"));for(let{scope:s,answer:g}of K(e)?[]:r)p.includes(s.folder)&&(g.agents=g.agents.map(P=>({...P,plugin:!0})));let{kept:o,leftOut:b}=Mt(e,r.flatMap(({answer:s})=>s.agents));mt(o,u,{settings:e,files:t.files,root:t.root});let S=[...k,...b.length?[{code:"agent-cap",detail:jt({kind:"layout",leftOut:b.length})}]:[]],x=new Set(o.map(s=>s.key));return{...!t.definitionsOmitted&&r.some(({scope:s})=>s.kind==="crew")&&r.every(({scope:s,answer:g})=>g.notes.length===0&&!g.refused?.length&&(s.kind==="crew"?g.agents.length>0&&g.agents.every(P=>Pe(P.key??"")):g.agents.length===0))&&(!t.listedPaths||V(e,t.listedPaths,t.root,{agentConfigurations:t.agentConfigurations}).files.every(s=>Object.hasOwn(t.files,s.path)))?{complete:!0}:{},...r.some(({scope:s,answer:g})=>s.miniSwe&&g.agents.length)&&!t.codeAgentsFound?{projection:"conventions"}:{},agents:o.map(s=>s.layoutCall?{...s,subagents:s.subagents.filter(g=>"key"in g&&x.has(g.key))}:s),notes:[...r.flatMap(({answer:s})=>s.notes),...S],...n.length?{scopePaths:f}:{},...r.some(({answer:s})=>s.refused?.length)?{refused:r.flatMap(({answer:s})=>s.refused??[])}:{},...i.length>1||i.some(s=>s.kind==="crew"||s.managed||s.miniSwe)||r.some(({answer:s})=>s.agents.some(g=>g.layoutCall))?{agentScopes:r.flatMap(({scope:s,answer:g})=>(g.agents.length?g.agents:[{key:s.key}]).map((P,w)=>({key:P.key,folder:s.folder,registry:g.registry&&!Pe(P.key??""),notes:g.notes.filter(v=>v.code!=="unreadable-crew"||w===0)}))),unassignedNotes:[...r.filter(({answer:s})=>!s.agents.some(g=>x.has(g.key))).flatMap(({answer:s})=>s.notes),...S]}:{}}}function Nt(e,t,n,f=!1,i){if(t.managed)return St(e,t,n);if(t.miniSwe&&n.explicitPrompt===void 0)return vt(e,t,n);if(t.kind!=="crew"&&!I(e))return xe(e,n,t.key,f);let l=gt(e,n,i),m=Ht(e,t,n.files,n.listedPaths),p=xe(e,n,t.key,f||t.key===null&&(m.agents.length>0||l.agents.length>0));return{agents:[...p.agents,...m.agents,...l.agents],notes:[...p.notes.filter(d=>d.detail!=="no-conventions"||t.kind!=="crew"&&m.agents.length===0&&l.agents.length===0),...m.notes],registry:p.registry,...m.refused?.length||l.refused.length?{refused:[...m.refused??[],...l.refused]}:{}}}function Ht(e,t,n,f){let i=At(t,n,e,f),{agents:l,notes:m,registry:p}=i;return{agents:l.map(({entry:d,...y})=>({...y,prompt:Wt(e,{entry:d},m)})),notes:m,registry:p,...i.refused?.length?{refused:i.refused}:{}}}function xe(e,t,n,f=!1){let{files:i,skills:l,fallbackName:m}=t,p=G(t.root),d=W(e,Object.keys(i),p,t.listedPaths),y=[],a=typeof t.explicitPrompt=="string"&&!Ae(e,t.explicitPrompt);a&&y.push({code:"explicit-guide",path:t.explicitPrompt});let k=a?null:t.explicitPrompt,c=typeof k=="string"&&Object.hasOwn(i,k)&&_(e,{path:k},{purpose:"override",route:"github"}).admitted?k:null,r={...d,skillPaths:l?d.skillPaths:[]},h=Qe(r),u=Zt(i,d.configPath,y),o=!K(e)&&!u?.prompt&&!u?.agents?.length?et(e,t):null,b=Ee({codeAgentsFound:!K(e)&&!!t.codeAgentsFound,folderAgentsFound:f,otherDefinitions:h,agentConfiguration:o!==null},e);if(o&&b==="prompt"&&(d=o),!(k===null||c!==null||He({...r,claudePath:d.claudePath},b)))return Tt(he(d),l,y),{agents:[],notes:[...y,{code:"no-prompt",path:p??"",detail:"no-conventions"}],registry:d.registry};let x=Wt(e,{files:i,c:d,guideRole:b,folderAgentsFound:f,root:p,config:u,explicitPath:k===null?null:c??void 0,pointerFiles:t.pointerFiles},y);x.kind==="none"&&(d=he(d));let O=l?d.skillPaths.map(P=>{let w=ee(e,`${d.skillNames[P]}.md`,i[P]);return y.push(...(w.warnings??[]).map(v=>({code:"frontmatter",path:P,detail:v}))),{path:P,name:w.name,description:w.description??"",body:w.prompt??""}}):[];Tt(d,l,y);let s=l?[...d.subagentSkillPaths,...d.subagentSkillRefPaths]:[],g=d.subagentPaths.map(P=>{let w=ee(e,Lt(P),i[P],{preserveToolAbsence:!0});return y.push(...(w.warnings??[]).map(v=>({code:"frontmatter",path:P,detail:v}))),{path:P,name:w.name,description:w.description??null,prompt:w.prompt??"",...w.tools!==void 0?{tools:w.tools}:{},...w.model!==void 0?{model:w.model}:{},skillPaths:s.filter(v=>d.subagentSkillOwners[v]===P)}});return{agents:[{key:n,name:u?.name??m,model:u?.model??null,description:u?.description??null,prompt:x,files:eo(e,i,d,x,l),skills:O,subagents:g}],notes:y,registry:d.registry}}function ms(e,t,n,f){let i=W(e,Object.keys(n),G(f));return Object.hasOwn(i.subagentSkillOwners,t)?!0:re(e,{skillPaths:i.subagentSkillPaths,paths:i.scoped,files:n,root:f})?.some(l=>l.files.some(m=>m.path===t))??!1}function Zt(e,t,n){if(!t)return null;let f=at(e[t]);if(f.invalid)try{JSON.parse(e[t])}catch{n.push({code:"invalid-config",path:t})}return f.config}function Wt(e,t,n){if("entry"in t)return t.entry.text?{kind:"entry",...t.entry,text:t.entry.text}:(n.push({code:"no-prompt",path:t.entry.path}),{kind:"none"});let{files:f,c:i,guideRole:l,folderAgentsFound:m,root:p,config:d,explicitPath:y,pointerFiles:a}=t;if(y===null)return{kind:"none"};if(y!==void 0)return{kind:"explicit",path:y};let k=d?lt(d)[0]?.prompt:void 0,c=d?it(e,d,p??"")[0]:void 0,r=k?ft(e,k,{repoKey:"",markerDir:p??"",files:a??f}):null,h=c!==void 0&&Object.hasOwn(f,c),u=h&&!!f[c];if(h&&(u||a!==void 0)&&Object.hasOwn(i.subagentSkillOwners,c))n.push({code:"pointer-owned-by-subagent",path:c});else if(h&&(a===void 0?u:r?.kind==="resolved")){let o=r?.kind==="resolved"?r.prompt:null;return{kind:"pointer",path:c,...o&&o.kind!=="file"?{span:{...o.span},site:{kind:o.kind,start:o.start,symbol:o.symbol}}:{}}}else k&&n.push(a!==void 0&&r?.kind==="secret"?{code:"secret-file",path:r.path}:{code:"pointer-missed",...c?{path:c}:{},detail:k});return i.promptPath?{kind:"dedicated",path:i.promptPath}:i.registry&&i.soulPath?{kind:"registry",path:i.soulPath}:i.claudePath&&l==="prompt"?(n.push({code:"claude-fallback",...de(e)?{path:i.claudePath}:{}}),{kind:"fallback",path:i.claudePath}):(n.push({code:"no-prompt",path:p??"",...m?{folderAgentsFound:!0}:{}}),{kind:"none"})}function Tt(e,t,n){if(t)for(let f of[...e.subagentSkillPaths,...e.subagentSkillRefPaths])e.subagentSkillOwners[f]||n.push({code:"orphan-skill",path:f})}function eo(e,t,n,f,i){let l=[],m=(a,k,c=null)=>({role:a,label:c,path:k});if(f.kind!=="none"&&f.kind!=="registry"&&l.push(m("system prompt",f.path)),n.soulPath&&l.push(m("soul",n.soulPath)),n.knowledgePath&&l.push(m("knowledge",n.knowledgePath)),i)for(let a of n.skillPaths)l.push(m("skill",a,n.skillNames[a]));for(let a of n.templatePaths)l.push(m("template",a));if(i)for(let a of n.skillRefPaths)l.push(m("reference",a,n.skillRefNames[a]));let p=[];n.configPath&&p.push(m("config",n.configPath));for(let a of[n.toolsPath,n.toolsTsPath,n.cliPath])a&&p.push(m("tools",a));n.mcpPath&&p.push(m("mcp",n.mcpPath));let d=new Set([...l.map(a=>a.path),...p.map(a=>a.path),...n.subagentPaths,...Object.keys(n.subagentSkillOwners),...n.skillPaths,...n.skillRefPaths]),y=n.scoped.filter(a=>!d.has(a)&&J(a)).sort();return l.push(...D(y,l.map(a=>t[a.path]),n.stripRoot).map(a=>m("reference",a)),...p),l}export{D as a,Gt as b,Bo as c,be as d,Ko as e,ee as f,Yt as g,yn as h,$t as i,Mt as j,jt as k,cs as l,ps as m,ms as n};
@@ -0,0 +1 @@
1
+ var n=Object.freeze({"benchmark-judge":"score_match","judge-code-prompt":"judge-code-prompt","derive-findings":"derive_findings","derive-findings-legacy":"derive_findings","derive-findings-no-outcome":"derive_findings","derive-findings-legacy-no-outcome":"derive_findings","derive-structure":"derive_structure","structure-recheck":"structure_recheck","derive-shape":"derive_shape","scope-items":"scope_check_structure","scope-findings":"scope_check","explain-sources":"explain_sources","finding-headlines":"finding_headlines","check-findings":"finding_check","check-findings-precision-v1":"finding_check","second-opinion":"finding_second_opinion"});function c(e){if(!Object.hasOwn(n,e))throw new Error("Unknown analysis template");return n[e]}function s(e){return Object.fromEntries(Object.entries(e).map(([i,r])=>[i,{...r,route:c(i)}]))}export{c as a,s as b};
@@ -0,0 +1 @@
1
+ import{C as T,K as A,y as F,z as L}from"./LFJQ4YLP.js";import{a as S}from"./326F4XNG.js";import{a as _,f as O}from"./SP6XFHNH.js";import{a as E,b as C,g as R}from"./VC3PYT2B.js";import{Fb as x}from"./2M55DR2J.js";import{y as q}from"./YWL52FVW.js";import{a as M,j as I}from"./SJESFYBA.js";import{a as P}from"./S27VIQMZ.js";import{createHash as G}from"node:crypto";var N=new WeakMap,j={version:"shared-modules-v1",settingsFiles:I.settingsFiles,resolve(i,s){let{paths:l,files:t,settings:f}=s,u=M(i);if(!u)return[];let c=N.get(s);return c||(c=new I({files:new Map([...l].map(d=>[d,t.get(d)??""]))},f),N.set(s,c)),q(i,t.get(i)??"",u,{allReexports:!0,completeImports:!0}).map(d=>d.dynamic?{from:i,specifier:d.source,status:"refused",provenance:null,reason:"dynamic"}:c.resolve(i,d.source,d.names))}};var B=i=>i==="too-large"?"over-limit":i==="wrong-type"||i==="empty"?"unsupported":i;function V(i,s){let l=R(i);if(!E(l))return{kind:"refused",reason:"disabled"};let t=O.safeParse(s.request);if(!t.success||t.data.kind!=="file"||t.data.entries)return{kind:"refused",reason:"invalid-selection"};let f=t.data,u=s.resolver??j,c=F(l,{profile:"entry-analysis",listing:[...s.entries],selection:f,limits:s.limits}),{entries:d}=c;return{kind:"pending",checkpoint:{version:1,settings:l,request:f,entries:d,files:{},resolutions:{},unavailable:{},targets:{},attempted:{paths:[],bytes:0},resolverVersion:u.version,...u.identity===void 0?{}:{resolverIdentity:u.identity},...s.proposal?{proposal:structuredClone(s.proposal)}:{},limits:c.limits,inventoryIncomplete:(s.inventoryIncomplete??0)+c.inventoryIncomplete}}}async function Y(i,s){let l=O.safeParse(i.request);if(i.version!==1||!l.success||l.data.kind!=="file"||l.data.entries)return{kind:"refused",reason:"invalid-selection"};let t=structuredClone(i);t.request=l.data;let{settings:f,request:u}=t,c=s.resolver??j;if(c.version!==t.resolverVersion||c.identity!==t.resolverIdentity)return{kind:"refused",reason:"stale-snapshot"};if(!E(f))return{kind:"refused",reason:"disabled"};let d=new Map(t.entries.map(e=>[e.path,e])),k=new Set(d.keys()),v=new Map(Object.entries(t.files)),p=c.settingsFiles?.(k,v,[u.entry,...Object.keys(t.files)])??[];if(p.every(e=>Object.hasOwn(t.files,e)||Object.hasOwn(t.unavailable,e))){let e=Object.keys(t.files).filter(n=>!Object.hasOwn(t.resolutions,n)),r={paths:k,files:v,settings:f},o=await S(e,4,async n=>{try{return{path:n,edges:await c.resolve(n,r)}}catch{return{path:n,reason:"unreadable"}}});for(let{path:n,edges:g,reason:b}of o)Object.defineProperty(b?t.unavailable:t.resolutions,n,{value:b??g,enumerable:!0,configurable:!0,writable:!0})}let m=A(f,{...t,settingsFiles:p,targetIdentity:G("sha256").update(JSON.stringify(Object.entries(t.targets).sort(([e],[r])=>e.localeCompare(r)))).digest("hex")});if(m.kind==="refused")return{kind:"refused",reason:m.reason};if(m.kind==="ready")return{kind:"ready",selection:m.selection,files:Object.fromEntries(m.selection.files.map(e=>[e.path,t.files[e.path]]))};for(let[e,r]of Object.entries(m.unavailable??{}))Object.defineProperty(t.unavailable,e,{value:r,enumerable:!0,configurable:!0,writable:!0});let a={...f,CF_RESPECT_GITIGNORE:"1",CF_LOCAL_SYMLINK_GUARD:"1",CF_SECRET_SCAN:"1"},y=(e,r,o)=>{if(!P.safeParse(e).success||r&&r.root!==u.launchRoot)return"out-of-scope";let n=x(a,{path:e,...o===void 0?{}:{text:o}},{purpose:"entry",route:"local-folder",...s.admission,gitIgnored:s.gitIgnored,...r?{localTarget:r}:{}});return n.admitted?null:n.reason==="out-of-scope"&&r?"symlink-escape":B(n.reason)},z=await S(m.pending.filter(e=>!Object.hasOwn(t.files,e)).slice(0,4),4,async e=>{let r=0,o=!1;try{let n=y(e);if(n)return{path:e,reason:n,bytes:r,attempted:o};let g=await s.localTarget(e);if(!g)return{path:e,reason:"unreadable",bytes:r,attempted:o};if(n=y(e,g),n)return{path:e,reason:n,bytes:r,attempted:o};let b=d.get(e);o=!0,r=b.size;let h=await s.read({path:e,size:b.size,ref:b.ref,readBytes:b.size+1});if(h!==null&&(r=Buffer.byteLength(h)),h===null)return{path:e,reason:"unreadable",bytes:r,attempted:o};let w=await s.localTarget(e);return!w||w.path!==g.path||w.root!==g.root?{path:e,reason:"symlink-escape",bytes:r,attempted:o}:(n=y(e,w,h),n?{path:e,reason:n,bytes:r,attempted:o}:r!==b.size?{path:e,reason:"over-limit",bytes:r,attempted:o}:{path:e,text:h,target:w.path,bytes:r,attempted:o})}catch{return{path:e,reason:"unreadable",bytes:r,attempted:o}}});for(let e of z){if(e.attempted){let o=m.pendingSettings.includes(e.path)?t.settingsAttempted??={paths:[],bytes:0}:t.attempted;o.paths.push(e.path),o.bytes+=e.bytes}let r=(o,n)=>Object.defineProperty(o,e.path,{value:n,enumerable:!0,configurable:!0,writable:!0});e.reason?r(t.unavailable,e.reason):e.text!==void 0&&(r(t.files,e.text),r(t.targets,e.target))}return{kind:"pending",checkpoint:t}}async function D(i,s){let l=O.safeParse(s.request);if(l.success&&l.data.kind==="file"&&l.data.entries){if(!C(i))return{kind:"refused",reason:"disabled"};let f=l.data,u=new Map,c=a=>{let y=u.get(a.path);return y||(y=Promise.resolve(s.read(a)),u.set(a.path,y)),y},d=await S(f.entries.slice(0,_.choices),4,async a=>{try{return await D(i,{...s,proposal:void 0,read:c,request:{kind:"file",launchRoot:f.launchRoot,entry:a}})}catch{return{kind:"refused",reason:"invalid-selection"}}}),k=d.find(a=>a.kind==="refused"&&a.reason!=="over-limit");if(k?.kind==="refused")return k;let v=d.filter(a=>a.kind==="ready");if(!v.length)return{kind:"refused",reason:"over-limit"};let p=L(f,v.map(a=>a.selection));if(p.kind!=="ready")return{kind:"refused",reason:p.kind==="refused"?p.reason:"invalid-selection"};let m=Object.fromEntries(v.flatMap(a=>Object.entries(a.files)));return T(s.proposal,p.selection.files)?{kind:"ready",selection:p.selection,files:Object.fromEntries(p.selection.files.map(a=>[a.path,m[a.path]]))}:{kind:"refused",reason:"invalid-scope"}}let t=V(i,s);for(;t.kind==="pending";)t=await Y(t.checkpoint,s);return t}export{V as a,Y as b,D as c};
@@ -0,0 +1 @@
1
+ import{a as h}from"./I4F56VMG.js";import{b as g,f as y,g as b}from"./33EUZF25.js";import{z as e}from"zod";var t=e.string(),n=t.nullable(),m=e.number().int().positive().safe(),T=e.enum(["ordering","reliability","coverage","cost","safety","correctness"]),B=e.enum(["low","medium","high","critical"]),q={headline:t.optional(),ifLeft:t.optional()},R=e.strictObject({nodes:e.array(e.strictObject({id:t,change:t,label:n})),edges:e.array(e.strictObject({from:t,to:t,kind:t,change:t,detail:n}))}),j=e.strictObject({sites:e.array(e.strictObject({index:e.number().int().nonnegative().safe(),role:e.enum(["Says","But also says","Unclear","Context","Requirement","What actually happens","Why it's a gap","Evidence"]),meaning:t,keyPhrase:t})),support:e.enum(["supported","partly","not_supported"]),supportNote:t,counterEvidence:e.array(e.strictObject({repo:t,path:t,line:m,excerpt:t,meaning:t}))}),x=e.strictObject({kind:T,severity:B,title:t,cause:t,summary:n,category:n,question:n,audience:g.optional(),activity:h.optional(),siteRepo:n,site:e.strictObject({path:t,line:m.nullable()}).nullable(),excerpt:n,otherSites:e.array(e.strictObject({repo:t,path:t,line:m,excerpt:t})),fixes:e.array(e.strictObject({title:t,approach:t,kind:e.enum(["code","prompt"]),targetFiles:e.array(e.strictObject({path:t,create:e.boolean().nullable()})),expectedOutcome:t,summary:n,impact:n,confidence:n,objective:n,status:n,blockedBy:n,alsoFixes:e.array(t).nullable(),delta:R.nullable()})),sourceNotes:j.nullable().optional(),...q}),a=Object.freeze({findings:2e4,textBytes:4096,quoteBytes:2e3,freeTextBytesPerFinding:16*1024}),A=a.freeTextBytesPerFinding*a.findings;function O(i){return typeof i=="string"?!i.includes("\0")&&!/[\uD800-\uDFFF]/u.test(i):i===null||typeof i!="object"||Object.values(i).every(O)}function k(i,c){return new TextEncoder().encode(i).byteLength<=(c?a.quoteBytes:a.textBytes)}var _=new Set(["excerpt","keyPhrase"]);function E(i){return _.has(String(i.at(-1)))}function S(i,c=[]){return typeof i=="string"?k(i,E(c)&&c[0]!=="activity"):i===null||typeof i!="object"||Object.entries(i).every(([p,l])=>S(l,[...c,p]))}var r=x.shape,F=t.min(1).refine(i=>i.trim().length>0),w=y.extend({nodes:e.array(y.shape.nodes.element.strict()),edges:e.array(y.shape.edges.element.strict())}).strict(),d=r.fixes.element.shape,C=e.strictObject({title:d.title.min(1),approach:d.approach.min(1),kind:d.kind,targetFiles:e.array(d.targetFiles.element.extend({path:t.min(1)})),...b.shape,delta:w.nullable(),expectedOutcome:d.expectedOutcome}),N=e.strictObject({...x.pick({kind:!0,severity:!0}).shape,title:r.title.min(1),cause:r.cause.min(1),summary:r.summary,site:r.site.unwrap().extend({path:t.min(1)}).nullable(),excerpt:r.excerpt,category:r.category,otherSites:e.array(e.strictObject({path:t.min(1),line:m,excerpt:t.trim().min(1),repo:F})),question:r.question,fixes:e.array(C).min(1),activity:r.activity,audience:r.audience,siteRepo:F.nullable(),sourceNotes:j.nullable().optional()}).refine(i=>S(i)),I=x.superRefine((i,c)=>{let p=0;function l(s,u){if(typeof s=="string"){let o=E(u);o||(p+=new TextEncoder().encode(s).byteLength),(!k(s,o)||!O(s))&&c.addIssue({code:"custom",path:u,message:"Invalid result text"})}else Array.isArray(s)?s.forEach((o,f)=>l(o,[...u,f])):s!==null&&typeof s=="object"&&Object.entries(s).forEach(([o,f])=>l(f,[...u,o]))}l(i,[]),p>a.freeTextBytesPerFinding&&c.addIssue({code:"custom",message:"Result text exceeds the finding budget"})}),K=e.array(I).max(a.findings);export{T as a,B as b,q as c,R as d,x as e,a as f,A as g,O as h,F as i,N as j,I as k,K as l};
@@ -0,0 +1 @@
1
+ import{a as c}from"./2CWULBP2.js";import{e as w}from"./2M55DR2J.js";import{posix as d}from"node:path";function _({codeAgents:t,conventions:e}){return[...new Set([...t.map(r=>r.prompt.path),...e.agents.flatMap(r=>[...c(r)?[r.prompt.path]:[],...r.subagents.map(s=>s.path)])])]}function S(t,e={}){return(t.CF_CHOOSE_AGENT??e.CF_CHOOSE_AGENT)!=="0"}function b(t,{codeAgents:e,conventions:r,root:s,selection:u}){if(u?.kind==="file"||w(t)||!S(t))return;let l=new Set(e.map(n=>n.prompt.path)),i=new Map(r.agentScopes?.map(n=>[n.key,n.folder])),o=A(e).map(({folder:n,reason:p})=>({folder:n,reason:p}));if(o.push(...r.agents.flatMap(n=>c(n)?(n.definitionPaths??[]).filter(p=>n.key===null||!l.has(p)).map(p=>({folder:P(n,p,i,s),reason:p})):[])),o.some(n=>o.every(p=>y(n.folder,p.folder))))return;let f=o.filter((n,p)=>!o.some((m,h)=>h!==p&&y(m.folder,n.folder)&&(m.folder!==n.folder||h<p)));return{kind:f.length?"choose_agent":"no_agent",candidates:f}}function y(t,e){return t==="."||e===t||e.startsWith(`${t}/`)}function k(t){let e=d.dirname(t[0]);for(let r of t.slice(1))for(;e!=="."&&r!==e&&!r.startsWith(`${e}/`);)e=d.dirname(e);return e}function A(t){let e=t.map(()=>new Set),r=new Map(t.map((i,o)=>[i.unitKey,o])),s=new Map,u=(i,o)=>{o!==void 0&&(e[i].add(o),e[o].add(i))};t.forEach((i,o)=>{u(o,s.get(i.prompt.path)),s.set(i.prompt.path,o);for(let a of i.links??[])u(o,r.get(a.to))});let l=new Set;return t.flatMap((i,o)=>{if(l.has(o))return[];let a=[o],f=[];for(;a.length;){let n=a.pop();l.has(n)||(l.add(n),f.push(t[n].prompt.path,...t[n].ownFiles.map(p=>p.path)),a.push(...e[n]))}return[{folder:k(f),reason:i.prompt.path,files:[...new Set(f)]}]})}function P(t,e,r,s){return t.key!==null?r.get(t.key)||d.dirname(e):(r.get(null)??s)||"."}export{_ as a,b,k as c,A as d};
@@ -0,0 +1 @@
1
+ import{c as f}from"./724WZMYW.js";function w(t){return t.skippedFiles??(t.notRead??[]).map(({path:e,kind:n})=>({path:e,reason:n==="prompt-too-large"?"too-large":"allowance"}))}function p(...t){let e={"secret-content":-7,secret:-6,hidden:-5,excluded:-4,"wrong-type":-3,empty:-2,"out-of-scope":-1,"too-large":0,allowance:1,"tool-limit":2,"scan-limit":3,total:4,unreadable:5,missing:6},n=new Map;for(let i of t)for(let o of i??[]){let r=n.get(o.path);(!r||e[o.reason]<e[r.reason])&&n.set(o.path,o)}return[...n.values()]}function d(t,e=0){let n=p(t),i=(...s)=>n.filter(({reason:u})=>s.includes(u)).length,o=n.filter(s=>s.reason==="secret-content").map(s=>f(s.path)),r=i("too-large"),a=i("allowance","tool-limit"),l=i("total","scan-limit"),c=i("missing","unreadable");return r&&o.push(`${r} ${r===1?"file was":"files were"} too big to read.`),a&&o.push(`${a} ${a===1?"file wasn't":"files weren't"} read because the file allowance was reached.`),l&&o.push(`${l} ${l===1?"file wasn't":"files weren't"} read because the repository is large.`),c&&o.push(`${c} ${c===1?"file couldn't":"files couldn't"} be read, so some tools may be missing.`),e>0&&o.push(`${e} more ${e===1?"file wasn't":"files weren't"} read.`),o}function h(t,e){return e?[...t.filter(i=>{let o=/^(\d+) more (?:file wasn't|files weren't) read\.$/.exec(i);return o?(e+=Number(o[1]),!1):!0}),...d([],e)]:[...t]}var $="Analyze them separately?";function m(t){return p(t).filter(e=>["too-large","total","allowance","scan-limit","tool-limit"].includes(e.reason))}function F(t){let e=m(t).length;return e?`${e} ${e===1?"file was":"files were"} too large to read, so findings in ${e===1?"it":"them"} may be missing.`:void 0}function b(t,e){return p(t,e.map(n=>({path:n,reason:"total"})))}export{w as a,p as b,d as c,h as d,$ as e,m as f,F as g,b as h};
@@ -0,0 +1 @@
1
+ import{z as t}from"zod";var i=t.strictObject({state:t.enum(["active","dead","switched_off"]),gate:t.string().nullable(),reason:t.string(),evidence:t.array(t.strictObject({path:t.string(),line:t.number(),excerpt:t.string()}))});export{i as a};
@@ -0,0 +1 @@
1
+ function i(r){return r.CF_NOT_ACTIVE_GROUP==="1"}function e(r,t){let n=typeof t=="object"&&t!==null&&"answerFormats"in t&&Array.isArray(t.answerFormats)&&t.answerFormats.includes("findings-activity");return Object.freeze({...r,CF_NOT_ACTIVE_GROUP:n&&r.CF_NOT_ACTIVE_GROUP!=="0"?"1":"0"})}export{i as a,e as b};
@@ -1 +1 @@
1
- import{a as c,c as l,d as s,e as m,g as i}from"./SKVEBOGA.js";import{c as u,d as p}from"./FSLWD2PE.js";function n(a,d={}){return JSON.stringify({bundleDescription:a,inputs:d})}import{z as e}from"zod";import{z as t}from"zod";var r=t.object({motivation:t.array(t.object({kind:t.string(),reason:t.string(),evidence:t.string()})),outcomes:t.array(t.object({improvement:t.string(),measurement:t.string()}))}),O=r.extend({motivation:r.shape.motivation.default([]),outcomes:r.shape.outcomes.default([])});var h=e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}),f=e.object({label:e.string(),source:e.literal("mcp").optional(),brand:e.string().nullable().default(()=>null)}),x=["system prompt","soul","knowledge","skill","config","tools","mcp","template","reference","code"],y=e.object({filledAtRunTime:e.boolean().optional(),role:e.enum(x),label:e.string().nullable().default(()=>null),path:e.string().min(1),span:e.object({from:e.number().int(),to:e.number().int()}).optional()}),S=e.object({id:e.string().min(1),label:e.string().min(1),kind:e.enum(["entry","agent","tool","store","exit"]),desc:e.string(),meta:e.string().nullable(),sourceRef:h.nullable(),sourcePaths:e.array(e.string()).optional(),files:e.array(y).default(()=>[]),tools:e.array(f).default(()=>[])}),j=e.object({from:e.string().min(1),to:e.string().min(1),kind:e.enum(["invokes","delegates","reads","writes","emits"]),label:e.string().nullable(),sourceRef:h.nullable()}),_=e.object({nodes:e.array(S),edges:e.array(j),warnings:e.array(e.string())}),v=e.object({...r.shape,title:e.string().min(1).describe(n("analysis-wire-schemas-1")),approach:e.string().min(1).describe(n("analysis-wire-schemas-2")),kind:e.enum(["code","prompt"]),targetFiles:e.array(e.object({path:e.string().min(1),create:e.boolean().nullable()})),...i.shape});function o(a){return e.string().describe(n("analysis-wire-schemas-3",{v0:Object.values(a.enum).join(", ")}))}var w=e.object({nodes:e.array(e.object({id:e.string().min(1),change:o(s),label:e.string().nullable()})),edges:e.array(e.object({from:e.string().min(1),to:e.string().min(1),kind:o(m),change:o(s),detail:e.string().nullable()}))}),k=v.omit({motivation:!0,outcomes:!0}).extend({expectedOutcome:e.string().describe(n("analysis-wire-schemas-4")),summary:i.shape.summary.catch(null),impact:i.shape.impact.catch(null),objective:i.shape.objective.catch(null),blockedBy:i.shape.blockedBy.catch(null),confidence:o(l).nullable().catch(null),status:o(c).nullable().catch(null),alsoFixes:e.array(e.string()).nullable().default([]).catch(()=>[]),delta:w.nullable().catch(null)}),q=e.object({path:e.string().min(1),line:e.number().int().positive(),excerpt:e.string().trim().min(1)}),F=e.object({path:e.string(),line:e.number(),excerpt:e.string()}),b=a=>e.string().describe(n("analysis-wire-schemas-5",{v0:u(a).join(", ")})).nullable().catch(null),g=e.object({kind:e.enum(["ordering","reliability","coverage","cost","safety","correctness"]),severity:e.enum(["low","medium","high","critical"]),title:e.string().min(1).describe(n("analysis-wire-schemas-6")),cause:e.string().min(1),summary:e.string().describe(n("analysis-wire-schemas-7")).catch(""),site:e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}).nullable(),excerpt:e.string().nullable(),category:b({}),otherSites:e.array(F).nullable().default([]).catch(()=>[]),question:e.string().describe(n("analysis-wire-schemas-8")).catch(""),fixes:e.array(k).min(1)}),E=e.object({findings:e.array(g)});function A(a){return p(a)?E:e.object({findings:e.array(g.extend({category:b(a)}))})}export{n as a,_ as b,k as c,q as d,g as e,E as f,A as g};
1
+ import{a as c,c as l,d as s,e as m,g as i}from"./33EUZF25.js";import{c as u,d as p}from"./VDUFPTDD.js";function n(a,d={}){return JSON.stringify({bundleDescription:a,inputs:d})}import{z as e}from"zod";import{z as t}from"zod";var r=t.object({motivation:t.array(t.object({kind:t.string(),reason:t.string(),evidence:t.string()})),outcomes:t.array(t.object({improvement:t.string(),measurement:t.string()}))}),O=r.extend({motivation:r.shape.motivation.default([]),outcomes:r.shape.outcomes.default([])});var h=e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}),f=e.object({label:e.string(),source:e.literal("mcp").optional(),brand:e.string().nullable().default(()=>null)}),x=["system prompt","soul","knowledge","skill","config","tools","mcp","template","reference","code"],y=e.object({filledAtRunTime:e.boolean().optional(),role:e.enum(x),label:e.string().nullable().default(()=>null),path:e.string().min(1),span:e.object({from:e.number().int(),to:e.number().int()}).optional()}),S=e.object({id:e.string().min(1),label:e.string().min(1),kind:e.enum(["entry","agent","tool","store","exit"]),desc:e.string(),meta:e.string().nullable(),sourceRef:h.nullable(),sourcePaths:e.array(e.string()).optional(),files:e.array(y).default(()=>[]),tools:e.array(f).default(()=>[])}),j=e.object({from:e.string().min(1),to:e.string().min(1),kind:e.enum(["invokes","delegates","reads","writes","emits"]),label:e.string().nullable(),sourceRef:h.nullable()}),_=e.object({nodes:e.array(S),edges:e.array(j),warnings:e.array(e.string())}),v=e.object({...r.shape,title:e.string().min(1).describe(n("analysis-wire-schemas-1")),approach:e.string().min(1).describe(n("analysis-wire-schemas-2")),kind:e.enum(["code","prompt"]),targetFiles:e.array(e.object({path:e.string().min(1),create:e.boolean().nullable()})),...i.shape});function o(a){return e.string().describe(n("analysis-wire-schemas-3",{v0:Object.values(a.enum).join(", ")}))}var w=e.object({nodes:e.array(e.object({id:e.string().min(1),change:o(s),label:e.string().nullable()})),edges:e.array(e.object({from:e.string().min(1),to:e.string().min(1),kind:o(m),change:o(s),detail:e.string().nullable()}))}),k=v.omit({motivation:!0,outcomes:!0}).extend({expectedOutcome:e.string().describe(n("analysis-wire-schemas-4")),summary:i.shape.summary.catch(null),impact:i.shape.impact.catch(null),objective:i.shape.objective.catch(null),blockedBy:i.shape.blockedBy.catch(null),confidence:o(l).nullable().catch(null),status:o(c).nullable().catch(null),alsoFixes:e.array(e.string()).nullable().default([]).catch(()=>[]),delta:w.nullable().catch(null)}),q=e.object({path:e.string().min(1),line:e.number().int().positive(),excerpt:e.string().trim().min(1)}),F=e.object({path:e.string(),line:e.number(),excerpt:e.string()}),b=a=>e.string().describe(n("analysis-wire-schemas-5",{v0:u(a).join(", ")})).nullable().catch(null),g=e.object({kind:e.enum(["ordering","reliability","coverage","cost","safety","correctness"]),severity:e.enum(["low","medium","high","critical"]),title:e.string().min(1).describe(n("analysis-wire-schemas-6")),cause:e.string().min(1),summary:e.string().describe(n("analysis-wire-schemas-7")).catch(""),site:e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}).nullable(),excerpt:e.string().nullable(),category:b({}),otherSites:e.array(F).nullable().default([]).catch(()=>[]),question:e.string().describe(n("analysis-wire-schemas-8")).catch(""),fixes:e.array(k).min(1)}),E=e.object({findings:e.array(g)});function A(a){return p(a)?E:e.object({findings:e.array(g.extend({category:b(a)}))})}export{n as a,y as b,S as c,j as d,_ as e,k as f,q as g,g as h,E as i,A as j};
@@ -0,0 +1,14 @@
1
+ import{a as M}from"./Y7JGSUOA.js";import{d as J}from"./3MTXB4MK.js";import{j as U}from"./6JTHFDH3.js";import{a as K}from"./HTLIRVP7.js";import{a as G}from"./QDYMR6KS.js";import{b as T}from"./E7TFIHC5.js";import{f as x}from"./VC3PYT2B.js";import{b as P}from"./6YCABS5T.js";import{a as N,b as v,c as D,d as $}from"./VWRFSVLI.js";import{a as E,b as R}from"./MJGB25S5.js";import{d as A}from"./TA2NIQAY.js";import{a as L}from"./74FPPPIG.js";import{a as w}from"./INVTU73D.js";import{c as I}from"./VDUFPTDD.js";import{z as b}from"zod";function _(t,e){if(Buffer.byteLength(t)<=e)return t;let r=0,i=Math.min(t.length,e);for(;r<i;){let a=Math.ceil((r+i)/2);Buffer.byteLength(t.slice(0,a))<=e?r=a:i=a-1}return i>0&&/[\uD800-\uDBFF]/.test(t[i-1])&&i--,t.slice(0,i)}function H(t){let{bundleText:e}=t,r=s=>Buffer.byteLength(JSON.stringify(s));function i(s){let n=[];for(let o of s){if(r([...n,""])>4e3)break;let p=0,l=Buffer.byteLength(o);for(;p<l;){let d=Math.ceil((p+l)/2);r([...n,_(o,d)])<=4e3?p=d:l=d-1}n.push(_(o,p))}return n}function a(s,n=!1){return s.map(o=>typeof o!="string"&&o.kind==="no-core"&&n?e("analysis-check-input-1"):K([o])[0])}function m(s){let n=s.citedFiles===void 0?"":',"citedFiles":'+JSON.stringify(s.citedFiles),o=a(s.diagnostics,!0),p=s.citedFiles===void 0?o:i(o),l=[{text:'{"coreFiles":'+JSON.stringify(s.coreFiles)},{text:n+',"findings":'+JSON.stringify(s.findings)+',"diagnostics":'+JSON.stringify(p)+"}"}];return R(l,E({},{template:"check-findings"}).breakpoints)}function c(s){return Buffer.byteLength(m(s).map(n=>n.text).join(""))}return{checkDiagnosticsText:a,checkPromptBlocks:m,checkPayloadBytes:c}}function O(t,e={}){return t.length?t.map(r=>{let i=e.includeFiles===!1?"":`; files ${r.files.join(", ")||"none"}`;return`${r.ref} "${r.title}" (${r.subKind}): frozen ${r.frozen.join(", ")||"none"}; declined ${r.declined.join(", ")||"none"}${i}`}).join(`
2
+ `):"none"}function F(t){let{bundleText:e}=t,r=e("analysis-scope-check-1"),i=e("analysis-split-check-scope-rule-1"),a=[e("analysis-derive-structures-1"),e("analysis-derive-structures-2"),e("analysis-derive-structures-3"),e("analysis-derive-structures-4"),e("analysis-derive-structures-5"),e("analysis-derive-structures-6"),e("analysis-derive-structures-7"),e("analysis-derive-structures-8")].join(`
3
+ `),m=e("analysis-derive-structures-10");function c(n){return n.map(o=>({unit:JSON.stringify(o.unitKey),kind:o.kind,name:JSON.stringify(o.name),location:JSON.stringify(`${o.sourcePath}:${o.sourceLine}${o.sourceEndLine?`\u2013${o.sourceEndLine}`:""}`)}))}function s(n){return e("code-finding-note",{codeSources:c(n)})}return{RULE:r,SPLIT_SCOPE_RULE:i,SUB_KIND_DEFS:a,STRUCTURE_SCOPE_RULE:m,codeSourceLabels:c,codeFindingNote:s}}import{posix as W}from"node:path";function V(t){let{bundleText:e}=t,r=.25,i=4;function a(c){let s=new Set(c.map(l=>l.name)),n=new Map(c.map(l=>[l.name,new Set(l.skills.filter(d=>d!==l.name&&s.has(d)))])),o=new Map;for(let l of n.values())for(let d of l)o.set(d,(o.get(d)??0)+1);let p=Math.max(i,(c.length-1)*r);return c.map(l=>({name:l.name,linkedFrom:o.get(l.name)??0,linksTo:n.get(l.name).size})).filter(l=>l.linkedFrom>=p||l.linksTo>=p)}function m(c){let s=a(c);if(!s.length)return null;let n=s.map(o=>e("shape-shared-skill",o));return e("analysis-split-check-shared-skills-1",{v0:n.join(`
4
+ `)})}return{sharedSkillsOf:a,sharedSkillsText:m}}function Q(t){let{bundleText:e}=t,{shapeFindingsText:r}=J(t),{sharedSkillsText:i}=V(t);function a(c){let s=new Map(c.map((n,o)=>[n.name,`s${o+1}`]));return e("shape-skills",{skills:c.map(n=>({...n,id:s.get(n.name),refs:n.references.map(o=>W.relative(W.dirname(n.path),o)).join(","),tools:n.tools.join(","),links:n.skills.map(o=>s.get(o)).join(","),hasRefs:n.references.length>0,hasTools:n.tools.length>0,hasLinks:n.skills.length>0,hasDetails:n.references.length>0||n.tools.length>0||n.skills.length>0}))})}function m(c){return e("shape-inventory",{agent:c.agent,v0:a(c.skills),shared:i(c.skills),tools:c.tools.map(s=>({...s,skills:s.skills.join(", ")})),subAgents:c.subAgents.map(s=>({...s,tools:s.tools.join(", "),skills:a(s.skills)})),prompts:c.prompts,knowledge:c.knowledge.map(s=>({...s,headings:s.sections.map(n=>`${n.startLine}-${n.endLine} ${n.heading}`).join(`
5
+ `)})),findings:r(c.findings)})}return{inventoryText:m}}function X(t){let{SPLIT_SCOPE_RULE:e}=F(t),{inventoryText:r}=Q(t);function i(a){return{scopeRule:e,open:O(a.open),inventory:r(a)}}return{shapeInputs:i,SPLIT_SCOPE_RULE:e}}function j(t){let{bundleText:e}=t,r={contradiction:{def:e("analysis-categories-1"),evidence:e("analysis-categories-2")},ambiguity:{def:e("analysis-categories-3"),evidence:e("analysis-categories-4")},bypassable_requirement:{def:e("analysis-categories-5"),evidence:e("analysis-categories-6")},stale_fact:{def:e("analysis-categories-7"),evidence:e("analysis-categories-8")},description_mismatch:{def:e("analysis-categories-9"),evidence:e("analysis-categories-10")},ungoverned_tool:{def:e("analysis-categories-11"),evidence:e("analysis-categories-12")},untrusted_instructions:{def:e("analysis-categories-13"),evidence:e("analysis-categories-14")},better_as_code:{def:e("analysis-categories-15"),evidence:e("analysis-categories-16")}},i={untrusted_instructions:{derive:"analysis-categories-17",check:"analysis-categories-18"},better_as_code:{derive:"analysis-categories-19",check:"analysis-categories-20"}};function a(s){return I(s).map(n=>{let o=r[n];return e("category-entry",{category:n,definition:o.def,evidence:o.evidence})}).join(`
6
+ `)}function m(s,n){return I(s).map(o=>{let p=i[o]?.[n];return p?`
7
+
8
+ ${e(p,{promptAgreement:x(s)})}`:""}).join("")}function c(){return[e("analysis-categories-21"),e("analysis-categories-22"),e("analysis-categories-23"),e("analysis-categories-24"),e("analysis-categories-25"),e("analysis-categories-26")].join(`
9
+ `)}return{categoryBlock:a,categoryRules:m,impactBlock:c}}function Y(t){let{checkPromptBlocks:e}=H(t),{shapeInputs:r}=X(t),{templates:i}=t,{categoryBlock:a,categoryRules:m}=j(t);function c(s,n,o,p={}){if(s==="derive-shape")return{...n,...r(n.inventoryData)};if(s.startsWith("check-findings")||s==="second-opinion"){let l=e(n.checkInput),d=a(o),f=m(o,"check"),k=x(o),h=w(o),S={...n,notActiveGroup:h,promptAgreement:k,categories:d,categoryRules:f,core:l[0].text,claims:l[1].text};if(s!=="second-opinion")return S;let g;try{if(typeof n.checkTemplate!="string")throw new Error;g=D("check",o,n.checkTemplate)}catch{throw new Error("Unknown check template")}let u=typeof g=="string"&&Object.hasOwn(p,g)?p[g]:void 0;if(u?.route!=="finding_check"||u.system===void 0)throw new Error("Unknown check template");return{...S,checkSystem:T(u.system,{notActiveGroup:h,promptAgreement:k,categories:d,categoryRules:f},i)}}return n}return{stageInputs:c}}var Z="<<<BEGIN REPOSITORY TEXT>>>",q="<<<END REPOSITORY TEXT>>>";function B(t){let e=t;for(let r="";r!==e;)r=e,e=e.replaceAll(Z,"").replaceAll(q,"");return`${Z}
10
+ ${e.replaceAll("{{","{ {")}
11
+ ${q}`}function ee(t,e){return{location:B(String(t.location)),text:B(String(t.text)),usage:B(t.usage===null?e.bundleText("code-check-no-usage"):String(t.usage))}}function te(t){let{categoryBlock:e,categoryRules:r,impactBlock:i}=j(t),{codeSourceLabels:a,codeFindingNote:m,RULE:c,SPLIT_SCOPE_RULE:s,STRUCTURE_SCOPE_RULE:n,SUB_KIND_DEFS:o}=F(t),{bundleText:p}=t;function l(d,f,k){if(d==="finding-headlines")return{data:JSON.stringify(f.evidence),choiceCategories:L.join(", ")};if(d==="judge-code-prompt")return ee(f,t);if(d.startsWith("derive-findings"))return{...f,notActiveGroup:w(k),promptAgreement:x(k),pass:f.pass??null,codeSources:a(f.codeSources??[]),categories:e(k),categoryRules:r(k,"derive"),impacts:i()};if(d==="derive-structure"){let h=f.loadModesData,S=f.openStructuresData,g=f.findingsData;return{...f,findings:(g??[]).map(u=>({...u,category:u.category??"\u2014",excerpt:u.excerpt??"",site:u.site?{...u.site,line:u.site.line??"?"}:null,otherSites:(u.otherSites??[]).map(y=>({...y,line:y.line??"?",excerpt:y.excerpt??""})),question:u.question??"",options:u.fixes.map(y=>y.title)})),subKinds:o,scopeRule:n,open:O(S,{includeFiles:!1}),loadModes:h.map(u=>{let y=u.evidenceKind?p("load-evidence-skill-frontmatter"):u.evidence;return p("analysis-derive-structures-11",{v0:u.path,v1:u.mode,v2:u.unit??"no unit",v3:u.via,v4:y?` (${y})`:""})}).join(`
12
+ `)}}if(d==="scope-items"){let h=f.scopeRuleId==="structure"?n:f.scopeRuleId==="split"?s:"";return{items:f.items??[],scopeRule:h}}if(d==="scope-findings"){let h=f.codeSources,S=f.codeFiles,g=m(h);return{...f,system:g?p("scope-system-code")+`
13
+
14
+ `+g:c,code:S.length?p("code-evidence",{files:JSON.stringify(S)}):""}}return f}return{enrichRequestInputs:l,headlineFallbackQuestion:()=>t.description("finding-headlines-fallback-question")}}function ne(t,e){if(!Object.hasOwn(e.templates,t.template))throw new Error(`Unknown template: ${t.template}`);if(!Object.hasOwn(e.answerFormats,t.answerFormat))throw new Error(`Unknown answer format: ${t.answerFormat}`);let r=e.templates[t.template],i=t.limits??{};if(i.maxTokens!==void 0&&(!Number.isSafeInteger(i.maxTokens)||i.maxTokens<=0))throw new Error("Invalid maxTokens");let a=T(r.prompt,t.inputs,e.includes),m=r.promptBlocks?.map(c=>({text:T(c.text,t.inputs,e.includes),...c.cache?{cache:!0}:{}}));if(m&&m.map(c=>c.text).join("")!==a)throw new Error("Registered blocks must match the prompt");return{route:r.route??t.template,model:t.model,...r.system===void 0?{}:{system:T(r.system,t.inputs,e.includes)},prompt:a,...m?{promptBlocks:m}:{},schema:e.answerFormats[t.answerFormat],...i.maxTokens===void 0?{}:{maxTokens:i.maxTokens},...i.effort===void 0?{}:{effort:i.effort},...i.thinking===void 0?{}:{thinking:i.thinking}}}var C=class extends Error{name="InputBudgetError"};function nt(t){let{templates:e,descriptions:r}=t,{withDescriptions:i}=M(t),a=U(i,t.description);function m(){let o={prompt:e["check-evidence"],promptBlocks:[{text:"{{core}}"},{text:"{{claims}}"}]},p=P({"benchmark-judge":{system:e["benchmark-judge"],prompt:"{{data}}"},"judge-code-prompt":{prompt:e["judge-code-prompt"]},"derive-findings":{prompt:e["derive-findings"]},"derive-findings-legacy":{prompt:e["derive-findings-legacy"]},"derive-findings-no-outcome":{prompt:e["derive-findings-no-outcome"]},"derive-findings-legacy-no-outcome":{prompt:e["derive-findings-legacy-no-outcome"]},"derive-structure":{prompt:e["derive-structure"]},"structure-recheck":{system:e["structure-recheck-system"],prompt:e["structure-recheck"]},"derive-shape":{prompt:e["derive-shape"]},"scope-items":{prompt:e["scope-items"],system:e["scope-system"]},"scope-findings":{prompt:e["scope-findings"],system:"{{system}}"},"check-findings":{...o,system:e["check-findings"]},"check-findings-precision-v1":{...o,system:e["check-findings-precision-v1"]},"second-opinion":{...o,system:e["opinion-system"]},"explain-sources":{prompt:e["source-evidence"],system:e["explain-sources"]},"finding-headlines":{system:e["finding-headlines"],prompt:"{{data}}"}});return Object.fromEntries(Object.entries(p).map(([l,d])=>[l,{...d,...d.promptBlocks?{promptBlocks:R(d.promptBlocks,E({},{template:l}).breakpoints)}:{}}]))}function c(){return{templates:m(),includes:e,answerFormats:a,descriptions:r,policy:v()}}function s(o,p={}){let l=Object.hasOwn(v(),o.template)?$(o.template,o.answerFormat,p):o.answerFormat;return re({...o,answerFormat:l},c(),p)}function n(o,p={}){let l=oe(N(o,p),c());return{...l,schema:l.schema}}return{instructionRegistry:c,analysisModelRequest:s,analysisRequest:n,buildAnalysisCall:o=>oe(o,c()),withDescriptions:i,callInputBytes:se}}function se(t){return Buffer.byteLength(t.prompt)+Buffer.byteLength(t.system??"")}function re(t,e,r){let i=e.policy??v();if(!Object.hasOwn(i,t.template)||!i[t.template].answerFormats.includes(t.answerFormat))throw new Error("Unsupported template answer format");if(!Object.hasOwn(v(),t.template))return{...t,inputs:t.inputs};let a=G({templates:e.includes??{},descriptions:e.descriptions??{}}),{stageInputs:m}=Y(a),{enrichRequestInputs:c}=te(a),s=t.answerFormat.endsWith("-activity")||(t.answerFormat==="check"||t.answerFormat==="opinion")&&t.inputs.findingActivityEnabled===!0,n={...r,CF_NOT_ACTIVE_GROUP:s?"1":"0"};return{...t,inputs:c(t.template,m(t.template,t.inputs,n,e.templates),n)}}function oe(t,e){let r=A.parse({template:t.template,inputs:t.inputs,answerFormat:t.answerFormat,model:t.model,...t.limits?{limits:t.limits}:{}}),{data:i,settings:a,maxInputBytes:m}=r.inputs,c=ne(re({...r,inputs:i},e,a),e);if(m!==void 0&&se(c)>m)throw new C("serialized evidence exceeds the priced input budget");let s=r.template==="judge-code-prompt"?b.object({path:b.string(),line:b.number()}).parse(i.at):r.template==="structure-recheck"?b.object({childId:b.string()}).parse(i):{};return{...c,...Object.hasOwn(v(),r.template)&&r.template!=="benchmark-judge"?{context:s}:{}}}export{ne as a,_ as b,H as c,F as d,V as e,Q as f,X as g,j as h,Y as i,te as j,C as k,nt as l,se as m,oe as n};
@@ -0,0 +1,3 @@
1
+ import{a as _,b as de,k as mt}from"./SP6XFHNH.js";import{b as ae}from"./HCPO6QPU.js";import{a as Be,g as Ne}from"./VC3PYT2B.js";import{C as ht,a as Pe,c as it,d as at,l as lt,m as ct,n as Oe,o as ft,u as pt,v as dt,w as ut,z as ge}from"./P253B344.js";import{Fb as B,K as Ye,W as We,Y as qe,ea as He,f as ze,fa as ve,g as je,ga as me,h as oe,ha as be,i as ke,ia as Ze,ja as Qe,l as ce,m as $e,n as Je,ob as rt,pa as et,qa as tt,ra as ot,t as fe,u as Ke,wa as nt,x as Ge,y as Ve}from"./2M55DR2J.js";import{a as C}from"./MKYLK6DB.js";import{e as st}from"./YUY436SM.js";import{a as De,c as G}from"./C6X5GDG4.js";import{a as le,b as H,c as Z,k as Te,p as _e}from"./YWL52FVW.js";import{a as X,c as pe}from"./SJESFYBA.js";import{e as Xe}from"./RUVMFAST.js";import{a as Ue}from"./S27VIQMZ.js";function Me(t){let e;try{e=JSON.parse(t)}catch{return{config:null,invalid:!0}}if(typeof e!="object"||e===null||Array.isArray(e))return{config:null,invalid:!0};let o=e,n={};for(let r of["name","model","description","prompt"]){let i=ye(o[r]);i&&(n[r]=i)}if(Array.isArray(o.agents)){let r=o.agents.flatMap(i=>{let c=Dt(i);return c?[c]:[]});r.length>0?n.agents=r:n.invalidAgents=!0}return{config:n,invalid:!1}}function gt(t){let{config:e}=Me(t);return e?Ee(e):"bare"}function Ee(t){return t.agents?.length?"agents":t.prompt?"prompt":"bare"}function yt(t){let e=Ee(t);return e==="agents"?t.agents:e==="prompt"?[{name:t.name,model:t.model,prompt:t.prompt}]:[]}function wt(t,e,o){return St(t,e,o).paths}function St(t,e,o,n={}){let r=yt(e).map(l=>l.prompt),i=[],c=[];for(let l of r){let f=Fe(l).path,y=Ie(o,f);if(y===null){c.push({path:f,reason:"out-of-scope"});continue}let k=B(t,{path:y},{purpose:"pointer",route:"github",...n});k.admitted?i.push(y):c.push({path:y,reason:k.reason})}return{paths:i,refused:c}}function _t(t,e,o){let n=Ie(o.markerDir,Fe(e).path),r=n!==null?B(t,{path:n},{purpose:"pointer",route:"github"}):null;if(r&&!r.admitted&&r.reason==="secret")return{kind:"secret",path:n};let i=$t(e,o,tt(t));return i?{kind:"resolved",prompt:i}:{kind:"missed"}}function lo(t,e,o){let n=[],r=[];e.invalidAgents&&r.push(`${o.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let i=Ee(e);for(let c of yt(e)){let l=_t(t,c.prompt,o);if(l.kind==="secret"){r.push(st(l.path));continue}if(l.kind==="missed"){r.push(`${o.repoKey}: counterfact.json points at ${c.prompt}, which was not found; ignored`);continue}n.push({name:c.name??null,model:c.model??null,description:i==="prompt"?e.description??null:null,prompt:l.prompt})}return{agents:n,warnings:r,refused:St(t,e,o.markerDir).refused}}function ye(t){return typeof t=="string"&&t.trim()?t.trim():void 0}function Dt(t){if(typeof t!="object"||t===null)return null;let e=t,o=ye(e.prompt);if(!o)return null;let n={prompt:o},r=ye(e.name),i=ye(e.model);return r&&(n.name=r),i&&(n.model=i),n}function Fe(t){let e=t.replace(/\\/g,"/"),o=e.indexOf("#");if(o>=0)return{path:e.slice(0,o),symbol:e.slice(o+1),line:null};let n=/^(.*):(\d+)$/.exec(e);return n?{path:n[1],symbol:null,line:Number(n[2])}:{path:e,symbol:null,line:null}}function Ie(t,e){let o=[];for(let n of[...t.split("/"),...e.split("/")])if(n===".."){if(o.pop()===void 0)return null}else n!=="."&&n!==""&&o.push(n);return o.join("/")}function $t(t,e,o){let{path:n,symbol:r,line:i}=Fe(t),c=Ie(e.markerDir,n);if(c===null||!Object.hasOwn(e.files,c))return null;let l=e.files[c];if(l===void 0)return null;if(r===null&&i===null)return X(c)?null:We(c,l);let{sites:f}=et(c,l,{minChars:1,promptFunctions:o});return r!==null?f.find(y=>y.symbol===r)??null:Jt(f,i)}function Jt(t,e){let o=r=>Math.min(r.line,r.span.from),n=t.filter(r=>o(r)<=e&&e<=r.span.to);return n.sort((r,i)=>r.span.to-o(r)-(i.span.to-o(i))),n[0]??null}function Kt(t){return oe(t,"CF_IMPORT_SCOPED_SCAN")}function kt(t,e,o,n="bare"){let r=e.filter(y=>Je(t,y,o)),i=Kt(t);if(!i&&!r.length)return;if(!i&&(n==="agents"||n==="prompt"))return[];let c=i?lt(t,e,o).filter(y=>!y.convention&&(!y.markerPath||y.scope.key===null&&n!=="agents"&&n!=="prompt")).flatMap(y=>y.paths):vt(t,e,o,n)?e:[];if(!c.length&&!r.length)return c;let l=De(o),f=new Set([...c,...r]);for(let y of e){let k=G(y,l);k!==null&&!k.includes("/")&&qe(y)&&f.add(y)}return[...f]}function ne(t,{paths:e,root:o,scanFlag:n,marker:r}){let i={scan:!1,markerToRead:null};if(!n)return i;let c=Pe(t,e,o);if(c.configPath&&r===null)return{scan:!1,markerToRead:c.configPath};let l=kt(t,e,o,r);return l?{scan:l.length>0,markerToRead:null,scanPaths:l}:{scan:vt(t,e,o,r),markerToRead:null}}function vt(t,e,o,n){let r=Pe(t,e,o);return je({usage:"scan",codeAgentsFound:!1,otherDefinitions:it(r)},t)!=="prompt"&&!at(t,r)&&n!=="agents"&&n!=="prompt"}function So(t,e){if(e.phase==="read"){let c=gt(e.text??"");if(e.pending.scanPaths){let l=Me(e.text??"").config,f=e.pending.markerPath.split("/").slice(0,-1).join("/"),y=new Set(l?wt(t,l,f):[]),k=c==="bare"?e.pending.scanPaths:(e.pending.scanPathsIfExplicit??[]).filter(E=>!y.has(E));return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:k.length>0,scanPaths:k}}return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:e.pending.scanIfBare&&c==="bare"}}let{paths:o,root:n,scanFlag:r}=e,i=ne(t,{paths:o,root:n,scanFlag:r,marker:null});if(!r)return{kind:"off"};if(i.markerToRead){let c=ne(t,{paths:o,root:n,scanFlag:r,marker:"bare"});return{kind:"marker",markerPath:i.markerToRead,scanIfBare:c.scan,...c.scanPaths?{scanPaths:c.scanPaths,scanPathsIfExplicit:kt(t,o,n,"agents")}:{}}}return{kind:"settled",markerPath:null,markerKind:null,scan:i.scan,...i.scanPaths?{scanPaths:i.scanPaths}:{}}}var bt=(t,e)=>{let{markerToRead:o}=ne(e.settings,{paths:t.map(({path:n})=>n),root:e.dir??void 0,scanFlag:e.flags.scan,marker:null});return o?{strength:"partial",wants:[o]}:null};function Pt(t,e,o="bare"){let{scan:n}=ne(e.settings,{paths:t.map(({path:r})=>r),root:e.dir??void 0,scanFlag:e.flags.scan,marker:o});return n?{strength:"partial",wants:[]}:null}function we(t){return oe(t,"CF_IMPORT_MANIFEST")}function xe(t,e){if(!Ke(t))return null;let o=new Set(e.paths),n=Ge(t,e),r=new Set(e.skillPaths),i=new Set(e.referencePaths),c=a=>Object.hasOwn(e.files,a)?Buffer.byteLength(e.files[a]):e.sizes?.get(a),l=e.selected??[...new Set([...e.skillPaths,...Object.keys(e.files).filter(a=>fe(a,{nested:!0})?.reference)])].filter(a=>Object.hasOwn(e.files,a)).map(a=>({path:a,size:c(a)})),f=[...new Map(l.filter(a=>!i.has(a.path)||r.has(a.path)).map(a=>[a.path,a])).values()],y=new Set(f.map(a=>a.path)),k=f.filter(a=>r.has(a.path)),E=new Set(f.filter(a=>fe(a.path,{nested:!0})?.reference).map(a=>a.path)),S=k.length,x=C.conventionImport.skillBytes-f.filter(a=>r.has(a.path)||E.has(a.path)).reduce((a,m)=>a+(c(m.path)??m.size),0),A=ce(t)?C.codeAgent.importBytes-f.reduce((a,m)=>a+(c(m.path)??m.size),0):1/0,I=new Map(k.map(a=>[a.path,null])),R=(a,m=!1)=>{if(I.has(a))return;let h=c(a),M=E.has(a),u=B(t,{path:a,size:h,text:e.files[a]},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:o,managedFiles:e.files}),P=y.has(a)?0:h,F=u.admitted?h===void 0?"missing":!M&&S>=C.conventionImport.skillFiles?"allowance":!M&&(h>x||P>A)?"total":null:u.reason;I.set(a,F),!M&&(m||!F)&&S++,!M&&!F&&(x-=h,A-=P)};for(let a of i)R(a,!0);let s=[...new Set(e.skillPaths)].sort().filter(a=>Object.hasOwn(e.files,a)).map(a=>{let m={ownerPath:a,files:[],cycles:[],unresolved:[],refused:[]},h=new Set([a]);for(let M of n.references.filter(u=>u.ownerPath===a)){if(!h.has(M.fromPath))continue;R(M.path);let u=I.get(M.path);if(u){m.refused.push({path:M.path,reason:u});continue}h.add(M.path);let P=m.files.find(F=>F.path===M.path);P||(P={path:M.path,evidence:[],sharedOwners:[]},m.files.push(P)),P.evidence.push(M)}return m.cycles=n.cycles.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.unresolved=n.unresolved.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.refused=ae(m.refused),m}),p=new Map;for(let a of s)for(let m of a.files)p.set(m.path,[...p.get(m.path)??[],a.ownerPath]);for(let a of s)for(let m of a.files)m.sharedOwners=p.get(m.path);return s}var Gt=2e3;function Ot(t,e,o,n={}){let r=e.filter(u=>G(u.path,o)!=null),i={},c=[],l=new Map,f=n.mode!=="core"&&Ye(t),y=Oe(t,r.map(u=>u.path),o,{mode:f?"all":"core",files:n.files}),k=new Set([...y.ignoredPaths,...y.ignoredImportPaths]),E=new Map(y.files.filter(u=>u.role!=="reference").map(u=>[u.path,u])),S=new Map(y.scopes.map(u=>[u.key,C.conventionImport.totalBytes])),x=C.conventionImport.skillBytes,A=ce(t)?C.codeAgent.importBytes:1/0,I=0,R=u=>G(u.path,y.ownerOf(u.path).folder)??u.path,s=(u,P)=>{l.set(u.path,{path:u.path,reason:P})},p=(u,P)=>{let F=B(t,u,{purpose:P,route:"github",root:o});return F.admitted?!0:(s(u,F.reason),!1)},a=u=>{if(i[u.path])return;let P=f&&E.get(u.path)?.role==="skill"?"skill":"core",F=y.ownerOf(u.path),N=P==="skill"?x:S.get(F.key),j=u.size??0;if(P==="skill"&&I>=C.conventionImport.skillFiles){s(u,"allowance");return}if(j>N||j>A){s(u,"total");return}i[u.path]=u.ref,c.push(u.path),A-=j,P==="skill"?(x-=j,I++):S.set(F.key,N-j)},m=r.filter(u=>E.has(u.path));for(let u of m)p(u,rt(E.get(u.path).role))&&a(u);let h=0;if(we(t))for(let u of me(new Set(r.map(P=>P.path)))){let P=r.find(F=>F.path===u);if(h>=C.conventionImport.extractionFiles){s(P,"allowance");continue}if(p(P,"source")&&p(P,"definition")){let F=c.length;a(P),c.length>F&&h++}}let M=y.needsExtraction;if(M){let u=r.flatMap(F=>{if(k.has(F.path)||i[F.path]||f&&fe(R(F)))return[];if(!p(F,"extraction"))return[];let N=Ve(R(F));return N===null?[]:[{entry:F,rank:N}]}).sort((F,N)=>F.rank-N.rank||(F.entry.size??0)-(N.entry.size??0)),P=h;for(let{entry:F}of u){if(P>=C.conventionImport.extractionFiles){s(F,"allowance");continue}let N=c.length;a(F),c.length>N&&P++}}if(f&&n.files){let u=Vt(t,{entries:e,selected:r.filter(P=>Object.hasOwn(i,P.path)),files:n.files,root:o});for(let P of u.paths)Object.hasOwn(i,P)||(c.push(P),i[P]=r.find(F=>F.path===P).ref);for(let P of u.refused)l.set(P.path,P)}return{...ce(t)&&m.some(u=>!Object.hasOwn(i,u.path))?{definitionsOmitted:!0}:{},selectedPaths:c,shaByPath:i,treeListing:r.slice(0,Gt).map(u=>u.path),needsExtraction:M,refused:[...l.values()]}}function Vt(t,e){let o=new Set(e.selected.map(i=>i.path)),n=Oe(t,e.entries.map(i=>i.path),e.root,{files:e.files}).files.filter(i=>i.role==="skill"&&o.has(i.path)).map(i=>i.path),r=xe(t,{skillPaths:n,paths:e.entries.map(i=>i.path),files:e.files,sizes:new Map(e.entries.map(i=>[i.path,i.size])),selected:e.selected,root:e.root,admission:e.admission,referencePaths:e.referencePaths});return{paths:[...new Set(r?.flatMap(i=>i.files.map(c=>c.path))??[])],refused:r?.flatMap(i=>i.refused)??[]}}var Mt=(t,e)=>{let o=Ot(e.settings,t,e.dir??void 0,{mode:e.mode});return{strength:"partial",wants:o.selectedPaths,state:{needsExtraction:o.needsExtraction,treeListing:o.treeListing,shaByPath:o.shaByPath,refused:o.refused,...o.definitionsOmitted?{definitionsOmitted:!0}:{}}}};var Et=["marker","code-scan","conventions"];var Yt={marker:bt,"code-scan":Pt,conventions:Mt};function Ae(t,e,o,n,r=Yt){let i={...o,settings:t},c={readers:[]};for(let l of Et)if(!(n&&!n.includes(l)))try{let f=r[l]?.(e,i);f&&c.readers.push({id:l,claim:f,done:!1})}catch{}return c}function Xo(t){return{readers:t.readers.map(({id:e,done:o})=>({id:e,done:o}))}}function Ft(t){let e=t.readers.find(({id:o})=>o==="conventions").claim;return{selectedPaths:e.wants,...e.state}}var Wt={files:200,bytes:C.codeAgent.importBytes,depth:32,edges:_.edges,entries:pe.inventoryEntries};function It(t={}){return Object.fromEntries(Object.entries(Wt).map(([e,o])=>{let n=t[e]??o;return[e,Number.isFinite(n)?Math.max(0,Math.min(o,Math.floor(n))):0]}))}function xt(t,e,o,n){let r=new Set(o.map(s=>G(s.path,n))),i=t.CF_READING_NOTE_AGENT_ONLY!=="0"&&ft(t),c=new Set(e.agents),l=s=>!r.has(s)&&(!i||c.has(s)),f=e.instruction.filter(l),y=e.code.filter(l),k=e.agents.filter(s=>!r.has(s)),E=new Set(dt(k)),S=[...f,...y].every(s=>E.has(s)),x=f.length,A=y.length,I=[!S&&x>0&&`${x} instruction file${x===1?"":"s"} left out by the ${Math.round(C.sourceFetch.instructionBytes/1e3)}KB instruction budget`,!S&&A>0&&`${A} analyzable file${A===1?"":"s"} left out by the ${Math.round(C.sourceFetch.codeBytes/1e3)}KB/${C.sourceFetch.codeFiles}-file code budget \u2014 the analysis reads the most agent-shaped files first`,ut(k,i)].filter(Boolean),R=o.filter(s=>s.readBytes!==void 0).map(s=>G(s.path,n));return R.length&&I.push(`${R.join(", ")}: only the first ${C.sourceFetch.codeFileBytes/1e3} KB was read`),I.length?I.map((s,p)=>p<I.length-1?String(s).replace(/\.$/,""):s).join("; "):void 0}function At(t,e,o,n={}){let{descriptions:r,priority:i,declarations:c}=ht(t,e,{root:o},n),l=[],f=r.flatMap(a=>a.admission.admitted?[{entry:a.readEntry,rel:a.rel,score:a.score,size:a.readEntry.size,pool:a.pool,...a.tier===void 0?{}:{tier:a.tier}}]:(l.push({path:a.entry.path,reason:a.admission.reason}),[])),y=f.filter(({score:a})=>a===0).sort(ge),k=f.filter(({score:a})=>a>0).sort(ge),E=[],S={instruction:0,code:0},x={instruction:[],code:[]},A=0,I=(i.enabled?[...f].sort(ge):[...y,...k]).sort((a,m)=>Number(c.has(m.entry.path))-Number(c.has(a.entry.path)));for(let{entry:a,rel:m,pool:h}of I){let M=h==="instruction"?C.sourceFetch.instructionBytes:C.sourceFetch.codeBytes;if(S[h]+a.size>M||h==="code"&&A>=C.sourceFetch.codeFiles){x[h].push(m),l.push({path:a.path,reason:S[h]+a.size>M?"total":"allowance"});continue}E.push(a),S[h]+=a.size,h==="code"&&(A+=1)}let R=pt(i,l.flatMap(a=>{let m=G(a.path,o);return m===null?[]:[{...a,path:m}]})),s={...x,agents:R},p=xt(t,s,E,o);return{selected:E,totalBytes:S.instruction+S.code,refused:l,...p?{skippedNote:p}:{},...i.enabled&&p?{readingNotes:s}:{}}}function Re(t){let e=t.CF_CODE_AGENTS!=="0";return{scan:e,model:e&&t.CF_CODE_AGENTS_MODEL!=="0"}}function Rt(t,e){if(e.profile==="entry-analysis"){let l=It(e.limits),f=e.listing.find(k=>k.path===e.selection.entry),y=[...f?[f]:[],...e.listing.filter(k=>k.path!==e.selection.entry)].slice(0,l.entries);return{profile:e.profile,request:e.selection,entries:y,limits:l,inventoryIncomplete:e.listing.length-y.length}}let o=$e(t),n=o.length?{scopeSelections:o}:{},r={dir:e.root??null,mode:e.profile==="hosted-import"?e.mode??"all":"all",flags:e.profile==="hosted-import"?e.flags??Re(t):Re(t)};if(e.profile==="hosted-import"){let l=Ae(t,e.listing,r);return{profile:e.profile,...l,...n,selection:Ft(l),...ke(t)?{mode:r.mode}:{}}}let i=e.listing.filter(l=>B(t,l,{purpose:"pointer",route:"github",root:e.root}).admitted),c=Ae(t,i,r,["marker","code-scan"]);return{profile:e.profile,...c,...n,listing:i,selection:e.selection??At(t,e.listing,e.root),context:r,...e.selection&&ke(t)?{selectionPaths:e.selection.selected.map(l=>l.path)}:{}}}import{createHash as qt}from"node:crypto";var Q=t=>qt("sha256").update(t).digest("hex");function Cn(t,e){let o=s=>({kind:"refused",reason:s,pending:[]}),n=t.entries,r=new Map;for(let s of e)for(let p of s.files){let a=r.get(p.path);if(a&&(a.hash!==p.hash||a.size!==p.size))return o("stale-snapshot");r.set(p.path,{...p,role:n.includes(p.path)?"entry":"imported-helper"})}let i=[...r.values()],c=Q(JSON.stringify([n,e.map(s=>s.snapshot)])),l=[],f=new Set,y=(s,p,a=!1)=>{p=[...new Set(p)];let m=JSON.stringify([...p].sort());f.has(m)||p.length===i.length&&n.every(h=>r.has(h))||p.filter(h=>n.includes(h)).length>de||p.length>_.scopeImports+1||l.length>=_.choices||(f.add(m),l.push({id:Q(m),scope:{snapshot:c,entry:s,entries:n,imports:p.length===1?"none":p.filter(h=>h!==s)},includes:p,omitted:i.filter(h=>!p.includes(h.path)).map(h=>h.path),...a&&p.length>1?{coverage:"entry-imports"}:{}}))};for(let s=0;s<e.length;s+=de){let p=e.slice(s,s+de);y(p[0].kind==="file"?p[0].entry:n[s],p.flatMap(a=>a.files.map(m=>m.path)),!0)}for(let s of n.filter(p=>r.has(p)))y(s,[s]);for(let s of e)y(s.kind==="file"?s.entry:n[0],s.files.map(p=>p.path),!0);for(let s of e)for(let p of s.choices)y(p.scope.entry,p.includes);let k=s=>[...new Map(s.map(p=>[JSON.stringify(p),p])).values()],E=k(e.flatMap(s=>s.refusedEdges)),S=k(e.flatMap(s=>s.edges)),x=E.slice(0,_.edges),I=n.length-e.length+E.length-x.length+Math.max(0,S.length-_.edges)+e.reduce((s,p)=>s+p.completeness.frontierCount,0),R={schemaVersion:1,kind:"file",launchRoot:t.launchRoot,entry:t.entry,entries:n,snapshot:c,resolverVersion:e[0].resolverVersion,files:i,entrySets:e.map(s=>({entry:s.kind==="file"?s.entry:n[0],includes:s.files.map(p=>p.path)})),edges:S.slice(0,_.edges),refusedEdges:x,completeness:{complete:I===0&&e.every(s=>s.completeness.complete),frontierCount:I},choices:l};if(t.scope){if(t.scope.snapshot!==c)return o("stale-snapshot");let s=t.scope,p=Xt(R,s);return p?{kind:"ready",pending:[],selection:{...R,entrySets:void 0,...Ct(R,p.includes),choices:[]}}:o("invalid-scope")}return{kind:"ready",pending:[],selection:mt.parse(R)}}function Ut(t,e){if(t.kind!=="file"||!t.entries||!t.entrySets||!e.length)return;let o=e.map(c=>t.entrySets.find(l=>l.entry===c));if(o.some(c=>!c))return;let n=new Set(o.flatMap(c=>c.includes)),r=t.files.filter(c=>n.has(c.path)).map(c=>c.path);if(t.entries.filter(c=>n.has(c)).length>de||r.length>_.scopeImports+1)return;let i=e[0];return{id:Q(JSON.stringify([...r].sort())),scope:{snapshot:t.snapshot,entry:i,entries:t.entries,imports:r.length===1?"none":r.filter(c=>c!==i)},includes:r,omitted:t.files.filter(c=>!n.has(c.path)).map(c=>c.path),...r.length>1?{coverage:"entry-imports"}:{}}}function Xt(t,e){let o=f=>JSON.stringify([f.snapshot,f.entry,f.imports==="none"?[]:Array.isArray(f.imports)?[...f.imports].sort():f.imports,f.entries]),n=t.choices.find(f=>o(f.scope)===o(e));if(n)return n;if(t.kind!=="file"||!t.entries||e.imports==="all")return;let r=new Set([e.entry,...e.imports==="none"?[]:e.imports]),i=t.entrySets?.filter(f=>f.includes.every(y=>r.has(y))).map(f=>f.entry)??[];if(!i.includes(e.entry))return;let c=[e.entry,...i.filter(f=>f!==e.entry)],l=Ut(t,c);return l&&o(l.scope)===o(e)?l:void 0}function Ct(t,e,o=!0){let n=new Set(e),r=new Set(t.files.map(f=>f.path)),i=t.edges.filter(f=>n.has(f.from)&&!n.has(f.path)&&r.has(f.path)).map(f=>({from:f.from,specifier:f.specifier,status:"refused",provenance:f.provenance,reason:"not-selected"})),c=o?[...new Map([...t.refusedEdges.filter(f=>n.has(f.from)),...i].map(f=>[JSON.stringify(f),f])).values()]:[...t.refusedEdges,...i].slice(0,_.edges).filter(f=>n.has(f.from)),l=t.completeness.frontierCount+(o?Math.max(0,c.length-_.edges):0);return{files:t.files.filter(f=>n.has(f.path)),edges:t.edges.filter(f=>n.has(f.from)&&n.has(f.path)),refusedEdges:c.slice(0,_.edges),completeness:{complete:l===0&&c.every(f=>f.reason==="external"),frontierCount:l}}}function Ht(t,e){let o=new Set(e.map(r=>r.path)),n=new Set(e.filter(r=>r.role==="entry").map(r=>r.path));return!t?.files.some(r=>!o.has(r.path)||r.role==="prompt"&&!n.has(r.path))}function Zt(t){return t.unavailable?t.unavailable:t.entry?!Number.isSafeInteger(t.entry.size)||t.entry.size<0?"over-limit":Ue.safeParse(t.path).success?t.depth>t.limits.depth||!t.spentPaths.has(t.path)&&(t.spentPaths.size>=t.limits.files||t.bytes+t.size>t.limits.bytes)?"over-limit":null:"out-of-scope":"missing"}function Lt(t,e){let o=b=>({kind:"refused",reason:b,pending:[]});if(!Be(t))return o("disabled");let{request:n,files:r,resolutions:i,unavailable:c={}}=e,l=Rt(t,{profile:"entry-analysis",listing:[...e.entries],selection:n,limits:e.limits}),{limits:f}=l,y=new Map(l.entries.map(b=>[b.path,b])),k={},E=[],S=[],x=[],A=[],I=new Set,R=new Set,s=[{path:n.entry,depth:0,settings:!1},...(e.settingsFiles??[]).map(b=>({path:b,depth:0,settings:!0}))],p=new Set,a=new Map,m=new Map,h=new Set(e.attempted?.paths),M=new Set(e.settingsAttempted?.paths),u={files:pe.settingsFiles,bytes:pe.settingsBytes,depth:f.depth},P=e.settingsAttempted?.bytes??0,F=e.attempted?.bytes??0,N=0,j=e.inventoryIncomplete??0;j+=l.inventoryIncomplete;let J=(b,v)=>{A.length<_.edges&&A.push({from:b.from,specifier:b.specifier,status:"refused",provenance:b.provenance,reason:v})};for(let b=0;b<s.length;b++){let v=s[b],T=`${v.settings}:${v.path}`;if(p.has(T))continue;p.add(T);let D=y.get(v.path),$=Object.hasOwn(r,v.path)?r[v.path]:void 0,te=$===void 0?D?.size??0:Buffer.byteLength($),ie=v.settings?M:h,z=Zt({...v,entry:D,size:te,unavailable:Object.hasOwn(c,v.path)?c[v.path]:void 0,spentPaths:ie,bytes:v.settings?P:F,limits:v.settings?u:f});if(z){if(v.path===n.entry&&!v.settings)return o(z);if(v.settings&&Object.defineProperty(k,v.path,{value:z,enumerable:!0}),!v.settings){m.set(v.path,z);for(let g of a.get(v.path)??[])J(g,z);z==="over-limit"&&j++}continue}if(ie.has(v.path)||(v.settings?P+=te:F+=te,ie.add(v.path)),$===void 0){S.push(v.path),(v.settings?I:R).add(v.path);continue}if(v.settings)continue;if(E.push(v.path),!Object.hasOwn(i,v.path)){S.push(v.path);continue}let q=i[v.path];for(let g=0;g<q.length;g++){let O=q[g];if(N++>=f.edges){J(O,"over-limit"),j+=q.length-g;break}if(!Xe.safeParse(O).success||O.from!==v.path){J({from:v.path,specifier:"?",status:"refused",provenance:null,reason:"unsupported"},"unsupported");continue}if(O.status==="refused"){J(O,O.reason);continue}x.push(O),a.set(O.path,[...a.get(O.path)??[],O]);let L=m.get(O.path);if(L){J(O,L);continue}s.push({path:O.path,depth:v.depth+1,settings:!1})}}if(S.length)return{kind:"pending",pending:[...new Set(S)],pendingSettings:[...I].filter(b=>!R.has(b)),...Object.keys(k).length?{unavailable:k}:{}};let se=E.map(b=>({path:b,role:b===n.entry?"entry":"imported-helper",hash:Q(r[b]),size:Buffer.byteLength(r[b])})),ee=Q(JSON.stringify({request:{...n,scope:void 0},files:se,inventory:[...y.values()].map(({path:b,size:v,ref:T})=>({path:b,size:v,ref:T})).sort((b,v)=>b.path.localeCompare(v.path)),metadata:(e.settingsFiles??[]).map(b=>[b,Object.hasOwn(r,b)?Q(r[b]):c[b]??"over-limit"]),edges:x,refusedEdges:A,frontierCount:j,limits:f,resolverVersion:e.resolverVersion,resolverIdentity:e.resolverIdentity,targetIdentity:e.targetIdentity,settings:Object.entries(Ne(t)).sort(([b],[v])=>b.localeCompare(v))})),w=n.scope;if(w&&w.snapshot!==ee)return o("stale-snapshot");let d=E.filter(b=>b!==n.entry);if(w&&(w.entry!==n.entry||Array.isArray(w.imports)&&w.imports.some(b=>!d.includes(b))))return o("invalid-scope");let V=new Set(!w||w.imports==="all"?E:[n.entry,...w.imports==="none"?[]:w.imports]),Y=Ct({files:se,edges:x,refusedEdges:A,completeness:{complete:!1,frontierCount:j}},[...V],!1),U=Y.files;if(!Ht(e.proposal,U))return o("invalid-scope");let re=[],ue=(b,v)=>{let T=[n.entry,...v==="none"?[]:v];T.length!==U.length&&re.push({id:b,scope:{snapshot:ee,entry:n.entry,imports:v},includes:T,omitted:U.filter(D=>!T.includes(D.path)).map(D=>D.path)})};ue("entry-only","none");for(let b of U.filter(v=>v.role==="imported-helper").slice(0,_.choices-1))ue(Q(b.path),[b.path]);let he={schemaVersion:1,kind:"file",launchRoot:n.launchRoot,entry:n.entry,snapshot:ee,resolverVersion:e.resolverVersion,...Y,choices:re};return{kind:"ready",pending:[],selection:he}}function Nn({prompt:t,link:e}){return{path:e?.callPath??t.path,...e?{line:e.callLine}:{},symbol:t.symbol,promptPath:t.path,promptStart:t.start,...e?.kind==="L4"?{loadedPrompt:!0,...e.callStart!==void 0?{callStart:e.callStart}:{}}:{}}}function Bt(t,e,o){return nt(t,e,o)}var Se=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function Qt(t,e,o,n={}){let r=new Map(t.map(i=>[Se(i),i]));return e.flatMap(i=>{let c=Object.hasOwn(o,i)?o[i]:void 0;if(c===void 0||!B(n,{path:i},{purpose:"code-support",route:"github"}).admitted)return[];let l=le(i,c,X(i)).toks;return l.flatMap((f,y)=>{if(!Z(f))return[];let k=r.get(Se(f.text));if(!k)return[];let E=!1;if(Z(l[y-1],"function")||Z(l[y-1],"def"))E=H(l[y+1],"(");else if(["const","let","var"].some(S=>Z(l[y-1],S))){for(let S=y+1;S<l.length&&S<y+80&&!H(l[S],";");S++)if(H(l[S],"=")){let x=Z(l[S+1],"async")?S+2:S+1,A=H(l[x],"(")?Te(l,x)+1:x+1;E=Z(l[x],"function")||H(l[A],"=")&&H(l[A+1],">");break}}return E?[{name:k,sourcePath:i,sourceLine:f.line}]:[]})})}function Nt(t,e,o,n,r={}){let i=new Set(t.map(Se)),c=k=>B(r,{path:k},{purpose:"code-support",route:"github"}).admitted,l=k=>Qt(t,[k],o,r).length>0,f=e.filter(k=>c(k)&&l(k)),y=n.filter(k=>c(k)&&i.has(Se(k.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(o[k]===void 0||l(k))).sort();return[...new Set([...f,...y])]}var jt="model call";function zt(t,e){let o=Bt(t.ownPaths,e,t.toolCall);return{tools:o.tools.map(n=>({tool:n,from:o.from[n.name]})),toolWarnings:o.warnings}}function Le(t=new Map,e){return{left:Math.max(0,C.codeAgent.importBytes-[...t.values()].reduce((o,n)=>o+n,0)),chosen:new Set([...t.keys()].filter(o=>!e?.has(o))),...e?{replacementBytes:e}:{}}}function eo(t,e){return t.modelId??(!t.documentation&&e.length===1?e[0]:null)}function ns(t,e,o){return to(t,eo(t,e),o)}function to(t,e,o){let{prompt:n,link:r}=t,i=[n.kind==="file"?{role:"system prompt",label:null,path:n.path}:{role:"system prompt",label:n.symbol??`line ${n.span.from}`,path:n.path,span:{from:n.span.from,to:n.span.to},...n.filledAtRunTime?{filledAtRunTime:!0}:{}}];for(let l of t.alsoLoads??[])i.push({role:"system prompt",label:"also loaded",path:l});r&&i.push({role:"code",label:jt,path:r.callPath}),r?.wrapper&&i.push({role:"code",label:"model wrapper",path:r.wrapper.path}),e&&i.push({role:"code",label:"model setting",path:e.path}),t.shape&&i.push({role:"code",label:"answer shape",path:t.shape.path});let c=new Set;return i.filter(l=>!c.has(l.path)&&!!c.add(l.path)).map(l=>ze(o,l.path,l.path===n.path&&t.promptSource==="marker")?l:{...l,role:"reference"})}function ss(t,e){let{prompt:o}=t,n=e[o.path]??"";return o.kind==="file"?n:n.split(`
2
+ `).slice(o.span.from-1,o.span.to).join(`
3
+ `)}function rs(t,e){return e?Object.fromEntries(e.files.filter(o=>t[o.path]!==void 0).map(o=>[o.path,t[o.path]])):t}function is(t,e,o){let{files:n,sizes:r,root:i,total:c=Le()}=o,l=[...new Set([...e.ownPaths,...o.guides??[]])],f=[],y=new Set(l);l=l.filter(h=>{let M=B(t,{path:h},{purpose:"override",route:"github"});return M.admitted||f.push({path:h,reason:M.reason}),M.admitted});let k=[...r.keys()].filter(h=>{let M=B(t,{path:h},{purpose:"code-support",route:"github",root:i});return!M.admitted&&!y.has(h)&&f.push({path:h,reason:M.reason}),M.admitted}),E=Object.fromEntries(l.filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),S=ot(E,k).filter(h=>!l.includes(h)),x=Object.fromEntries([...l,...S].filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),A=zt({ownPaths:l,toolCall:e.toolCall},x).tools.map(({tool:h})=>h.name),I=new Set(Nt(A,S,n,k,t)),R=Ce(t,l,{...o,total:c});for(let h of new Set([...l,...S,...I]))R.take(h,I.has(h)&&!l.includes(h));let{paths:s,skipped:p}=R,a=Object.fromEntries(s.filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),m=zt(e,a);return{paths:s,skipped:p,refused:ae(f,R.refused),...m}}function Ce(t,e,{sizes:o,total:n=Le(),pool:r},i=[]){let c=[],l=[],f=[],y=C.codeAgent.extraBytes,k=0;return{paths:c,skipped:l,refused:f,take:(S,x,A=!1)=>{if(c.includes(S))return!0;let I=o.get(S),R=S===e[0],s=i.includes(S),p=[n,...r?[r]:[]],a=u=>Math.max(0,(I??0)-(u.replacementBytes?.get(S)??0)),m=s?"override":e.includes(S)||A?"pointer":"code-support",h=B(t,{path:S,size:I},{purpose:m,route:"github"});h.admitted||f.push({path:S,reason:h.reason});let M=I===void 0?"missing":h.admitted?!s&&!R&&I>y?"allowance":!s&&p.some(u=>!u.chosen.has(S)&&(a(u)>u.left||u.wholeBytesLeft!==void 0&&I>u.wholeBytesLeft))?"total":x&&k>=C.codeAgent.toolCodeFiles?"tool-limit":null:h.reason;if(M)return l.push({path:S,reason:M}),!1;!R&&!s&&(y-=I),x&&k++;for(let u of p)u.chosen.has(S)||(u.left-=a(u),u.wholeBytesLeft!==void 0&&(u.wholeBytesLeft-=I),u.chosen.add(S));return c.push(S),!0}}}function as(t,e,o){return"request"in e?Lt(t,e):oo(t,e,o)}function oo(t,e,o){if(!we(t)&&!(oe(t)&&e.some(s=>s.fileProfile==="layout")))return null;let n=o.scopes??ct(t,[...o.sizes.keys()],o.root??void 0,{},o.agentConfigurations??{}),r=o.total??Le(),i=new Set(o.confirmationIds),c=o.selectedIds&&new Set(o.selectedIds),l=e.filter(s=>!c||c.has(s.id));for(let s of l)for(let{path:p}of s.ownFiles.filter(a=>s.fileProfile==="convention"||s.sharedReferencePaths?.includes(a.path))){let a=o.sizes.get(p),m=s.scopeProof?.paths.includes(p)?void 0:o.root;a===void 0||r.chosen.has(p)||!B(t,{path:p},{purpose:"override",route:"github",root:m}).admitted||(r.left-=Math.max(0,a-(r.replacementBytes?.get(p)??0)),r.wholeBytesLeft!==void 0&&(r.wholeBytesLeft-=a),r.chosen.add(p))}let f=(s,p)=>{for(let a of s){let m=a.ownFiles[0]?.path;if(!m)continue;let h=n.ownerOf(m);!h||h.key!==a.scope.key||h.folder!==a.scope.folder||!B(t,{path:m},{purpose:"pointer",route:"github",root:o.root}).admitted||Ce(t,[m],{...o,total:p,pool:void 0}).take(m,!1)}};f(l,r);let y,k=new Set,E=new Set(o.sizes.keys()),S=me(E).flatMap(s=>o.files[s]===void 0?[]:be(s,o.files[s],E,{root:o.root??void 0})),x=new Map(S.map(s=>[s,s.to&&o.files[s.to]!==void 0?Ze(s.to,o.files[s.to],s.imported,E,t):[]])),A=new Set(S.filter(s=>{let p=s.to&&X(s.to),a=s.to&&o.files[s.to];return p&&a!==void 0&&a!==null&&!ve(le(s.to,a,p),s.imported)})),I=e.map(s=>{let p=[...new Set(s.ownFiles.map(w=>w.path))],a=new Set(s.fileProfile==="layout"?s.ownFiles.filter(w=>w.role==="tools").map(w=>w.path):[]),m={schemaVersion:1,agentId:s.id,scope:{...s.scope},files:[],edges:[],unresolved:[],refused:[]};if(c&&!c.has(s.id))return m;i.has(s.id)&&!y&&(y={left:C.candidateFetch.check,chosen:new Set(k)},f(l.filter(w=>i.has(w.id)),y));let h=Ce(t,p,{...o,total:r,pool:i.has(s.id)?y:void 0},s.fileProfile==="convention"?p:s.sharedReferencePaths),M=new Set(s.skillManifests?.flatMap(w=>w.files.map(d=>d.path))),u=s.ownFiles.filter(w=>w.role!=="reference"||!M.has(w.path)||s.independentReferences?.includes(w.path)).map(w=>({path:w.path,symbol:null,role:w.role,evidence:null,span:w.span})),P=S.filter(w=>w.to!==null&&p.includes(w.to)),F=P.filter(w=>new Set(P.filter(d=>d.to===w.to).map(d=>d.imported)).size>1),N=S.filter(w=>!A.has(w)&&(P.includes(w)&&!s.toolCall&&!F.includes(w)||x.get(w).some(d=>{if(d.kind!=="graph-node"||!d.to||!p.includes(d.to)||!s.toolCall||s.toolCall.path!==d.to)return!1;let V=o.files[d.to];return V!==void 0&&Qe(d.to,V,d.imported,s.toolCall)})));m.unresolved.push(...P.filter(w=>!N.includes(w)).map(w=>({...w,reason:A.has(w)?"missing":"unlinked"})));for(let w of N)u.push({path:w.from,symbol:w.symbol,role:"config",evidence:w,explicit:!0});let j=new Set,J=new Map,se=new Set,ee=new Set;for(let w=0;w<u.length;w++){let d=u[w],V=JSON.stringify([d.path,d.symbol,d.role]);if(j.has(V)){let g=m.files.find(O=>O.path===d.path);g&&d.span&&!g.spans.some(O=>O.from===d.span.from&&O.to===d.span.to)&&(g.spans.push(d.span),g.evidence.push({kind:"entry",from:d.path,to:d.path,span:d.span})),g&&d.evidence?.kind==="skill-reference"&&!g.evidence.some(O=>JSON.stringify(O)===JSON.stringify(d.evidence))&&g.evidence.push(d.evidence);continue}j.add(V);let Y=n.ownerOf(d.path),U=p.includes(d.path)&&s.scopeProof?.paths.includes(d.path),re=B(t,{path:d.path},{purpose:p.includes(d.path)||d.explicit?"pointer":"code-support",route:"github",root:U?void 0:o.root}),ue=d.role==="reference"&&p.includes(d.path)&&(s.sharedReferencePaths?.includes(d.path)||s.skillManifests?.some(g=>m.files.some(O=>O.path===g.ownerPath)&&g.files.some(O=>O.path===d.path)&&!g.refused.some(O=>O.path===d.path))),he=re.admitted?!U&&(!Y||!ue&&(Y.key!==s.scope.key||Y.folder!==s.scope.folder))?"out-of-scope":!p.includes(d.path)&&e.some(g=>g.id!==s.id&&g.ownFiles.some((O,K)=>O.path===d.path&&(K===0||O.label===jt)))?"other-agent":null:re.reason;if(he){m.refused.push({path:d.path,reason:he});continue}let b=o.files[d.path],v=X(d.path),T=b!==void 0&&v?le(d.path,b,v):null,D=T&&d.symbol?ve(T,d.symbol):null,$=D?.name??d.symbol;if(b!==void 0&&!J.has(d.path)){let g=S.filter(L=>L.from===d.path),O=[...g.length?g:be(d.path,b,E,{root:s.scope.folder,call:s.toolCall}),...[...ee].filter(L=>L.to===d.path).flatMap(L=>x.get(L))];O.forEach(L=>se.add(L));let K=He(d.path,b,E,p.includes(d.path)?s.toolCall:void 0,t).flatMap(L=>O.some(W=>!W.reason&&W.kind===L.kind&&W.symbol===L.symbol&&W.span.from===L.span.from)?[]:N.some(W=>W.to===d.path)&&!p.includes(d.path)&&(L.kind==="config"||L.kind==="graph-node")&&!L.reason?[{...L,reason:"unlinked"}]:[L]);J.set(d.path,[...K,...O,...(o.links??[]).filter(L=>L.from===d.path)])}let te=J.get(d.path)??[];if(d.role==="code"&&d.evidence?.kind==="import"&&te.some(g=>g.reason==="external"&&g.usage==="call"&&(g.within===$||g.within===null)&&_e(g.source,v))){m.refused.push({path:d.path,reason:"provider-transport"});continue}let ie=a.has(d.path)||d.role==="tool"&&D?.params!=null&&!p.includes(d.path);if(!h.take(d.path,ie,d.explicit))continue;m.unresolved.push(...S.filter(g=>g.from===d.path&&(g.reason||A.has(g))).map(g=>A.has(g)?{...g,reason:"missing"}:g));let z=m.files.find(g=>g.path===d.path);z||(z={path:d.path,roles:[],spans:[],evidence:[],sharedOwners:[]},m.files.push(z)),z.roles.includes(d.role)||z.roles.push(d.role);let q=d.span??(T&&D?{from:T.toks[D.from].line,to:T.toks[D.to-1].endLine}:void 0);q&&!z.spans.some(g=>g.from===q.from&&g.to===q.to)&&z.spans.push(q),d.evidence?z.evidence.push(d.evidence):z.evidence.push({kind:"entry",from:d.path,to:d.path,...d.span?{span:d.span}:{}});for(let g of s.skillManifests??[])if(m.files.some(O=>O.path===g.ownerPath))for(let O of g.files)for(let K of O.evidence)K.fromPath===d.path&&u.push({path:O.path,symbol:null,role:"reference",explicit:!0,evidence:{kind:"skill-reference",from:K.fromPath,to:O.path,span:K.span}});if(b!==void 0)for(let g of te){let O=g.usage==="reexport"&&(g.symbol===$||g.symbol==="*"),K=g.usage==="call"&&g.within===$;if(!(g.kind!=="import"&&($===null||g.within===$)||$!==null&&(O||K)||g.reason==="dynamic"&&($===null||g.within===$)))continue;if(!g.to||g.reason){m.unresolved.push(g);continue}let W=N.includes(g);W&&(ee.add(g),J.delete(g.to)),m.edges.push(g);let Tt=g.kind==="tool-registration"?"tool":g.kind==="config"?"config":g.kind==="graph-node"?"workflow":O?d.role:"code";u.push({path:g.to,symbol:W?null:g.imported==="*"?d.symbol:g.imported,role:Tt,evidence:g,explicit:se.has(g)})}}if(m.refused.push(...ae(h.skipped,h.refused)),m.unresolved=m.unresolved.filter(w=>w.reason!=="unlinked"||!m.edges.some(d=>d.from===w.from&&d.to===w.to&&d.kind===w.kind&&d.symbol===w.symbol&&d.span.from===w.span.from)),m.unresolved=[...new Map(m.unresolved.map(w=>[JSON.stringify(w),w])).values()],m.refused=m.refused.filter((w,d,V)=>V.findIndex(Y=>Y.path===w.path&&Y.reason===w.reason)===d),!i.has(s.id))for(let w of m.files)k.add(w.path);return m}),R=new Map;for(let s of I)for(let p of s.files)R.set(p.path,[...R.get(p.path)??[],s.agentId]);for(let s of I)for(let p of s.files)p.sharedOwners=[...new Set(R.get(p.path))].sort();return I}export{Nn as a,Qt as b,Nt as c,we as d,xt as e,At as f,Re as g,Me as h,Ee as i,yt as j,wt as k,St as l,_t as m,lo as n,Kt as o,kt as p,So as q,xe as r,Ot as s,Vt as t,Ae as u,Xo as v,Ft as w,Wt as x,Rt as y,Cn as z,Ut as A,Xt as B,Ht as C,zt as D,Le as E,eo as F,ns as G,ss as H,rs as I,is as J,as as K};
@@ -0,0 +1 @@
1
+ var N=8e5,o=512,t=2e5,T=64e3;export{N as a,o as b,t as c,T as d};
@@ -0,0 +1 @@
1
+ var e={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}};export{e as a};
@@ -0,0 +1 @@
1
+ import{a as s}from"./E7TFIHC5.js";import{f as p}from"./VC3PYT2B.js";import{a}from"./INVTU73D.js";import{createHash as d}from"node:crypto";function x(e){function r(t){if(!("includes"in e)||!Object.hasOwn(e.includes,t))throw new Error(`Unknown template: ${t}`);return e.includes[t]}function m(t){return"templateText"in e?Buffer.byteLength(e.templateText(t)):r(t).expandedSize}function i(t,n={}){return{name:t,hash:"templateText"in e?d("sha256").update(s(e.templateText(t),{promptAgreement:p(n),notActiveGroup:a(n)})).digest("hex"):r(t).expandedFingerprint}}function f(t,n={}){for(let o of t)if(i(o.name,n).hash!==o.hash)throw new Error("Counterfact's instructions changed since this analysis started. Start a new analysis.")}return{templateBytes:m,promptVersion:i,assertPromptVersions:f}}export{x as a};
@@ -0,0 +1,6 @@
1
+ import{Ha as O,Ka as F,Qa as $}from"./2M55DR2J.js";import{a as R}from"./SJESFYBA.js";import{f as E,g as V}from"./VDUFPTDD.js";var z="We couldn't see this agent's code, so this may already be handled there.";function se(e){return Object.values(e).some(s=>[...s].some(t=>R(t)!==null))}function _(e,s){return e==="better_as_code"&&s===!1?z:void 0}function ie(e){return e.sawCode??e.findingQuality?.sawCode}var H="Findings could not be checked a second time; all findings were kept.";function N(e,s){let t=new Set(s),r=new Map,n=new Set,a=new Set,d=new Set;for(let o of e){if(!t.has(o.id)){a.add(o.id);continue}if(n.has(o.id)){d.add(o.id),r.delete(o.id);continue}n.add(o.id),r.set(o.id,o)}return{byId:r,unknownIds:[...a],duplicateIds:[...d]}}function J(e,s){let t=N(e,s);return t.unknownIds.length===0&&t.duplicateIds.length===0}function de(e,s,t,r={}){let n=e.map((h,w)=>`f${w+1}`),a=!J(s,n),d=a?"Verdict ids did not match; all findings were kept.":t?.failure,o=new Set(t?.sentIds??n),l=new Map(t?.skipped.map(h=>[h.id,h.reason])??[]),u=a?["verdict ids did not match"]:[],p=new Map(s.map(h=>[h.id,h])),i=[...t?.rejectedBatches??[],...a?[{ids:n,verdicts:s}]:[]],c=new Map,f=[],k=r.mode==="offline-simulation"&&r.shadow?.done?N(r.shadow.verdicts,n).byId:new Map;for(let h of i)for(let w of h.verdicts)h.ids.includes(w.id)&&c.set(w.id,w);let b=e.map((h,w)=>{let g=n[w],y=a?void 0:p.get(g),q=p.get(g)??c.get(g),C=o.has(g)||q!==void 0,M=C?"":l.get(g)??"No model call was made before the check stopped.",I="keep",m;C?d?m=d:y?y.reason.trim()?!y.evidenceAgainst?.trim()||!y.evidenceFor?.trim()||y.verdict==="drop"&&/^[\s"'“”‘’]*none found[\s."'“”‘’]*$/i.test(y.evidenceAgainst)?(m="The model supplied no usable evidence for its decision; this finding was kept.",u.push(`${g}: ${m}`)):(I=y.verdict,m=y.reason,f.push(g)):(m="The model returned an empty reason; this finding was kept.",u.push(`${g}: ${m}`)):(m="The model returned no verdict for this finding in the accepted response; it was kept.",u.push(`${g}: ${m}`)):m=M;let x=k.get(g);return!d&&f.includes(g)&&x&&r.shadow?.coverage.answeredIds.includes(g)&&(x.verdict==="drop"&&x.decisive&&x.quotes.some(U=>U.side==="against")?(I="drop",m=x.reason):x.verdict!==I&&(I="keep",m="The checks disagree without decisive contrary evidence; this finding was kept.")),{id:g,title:h.title,verdict:I,reason:m,sent:C,skipReason:M,modelVerdict:q?.verdict??"",modelReason:q?.reason??"",evidenceAgainst:q?.evidenceAgainst??"",evidenceFor:q?.evidenceFor??""}}),v=[],P=e.filter((h,w)=>{let g=b[w];return g.verdict!=="drop"?!0:(v.push({finding:h,reason:g.reason}),!1)}),Q=d?[H]:v.length?[`${v.length} ${v.length===1?"finding was":"findings were"} removed after a second read: ${v.map(({finding:h})=>h.title.replace(/\s+/g," ").trim()).join("; ")}`]:[];return{kept:d?e:P,dropped:v,warnings:Q,verdicts:b,...u.length?{diagnostics:u}:{},...i.length?{rejectedBatches:i}:{},...t?.recordAcceptance?{acceptedIds:f}:{}}}var j={critical:0,high:1,medium:2,low:3},K="No strong findings to show.",L=/^[\s"'“”‘’]*none found[\s."'“”‘’]*$/i,W=/"([^"\n]*(?:\n[^"\n]*)*)"|“([^”]+)”|`([^`]+)`|‘([^’]+)’|'([^'\n]+)'/g;function A(e,s){return N(e.map(t=>({...t,id:t.fingerprint})),s).byId}function S(e,s){return e.repo===s.repo&&e.path===s.path}function T(e,s){let t=e.repos.filter(r=>r.key===s.repo);return t.length===1?t[0].files?.[s.path]:void 0}function G(e,s,t){return e===void 0||s===null||!Number.isInteger(s)||s<1||!t?.trim()?!1:O(e.split(`
2
+ `).slice(s-1).join(`
3
+ `),t)===1}function Y(e){return[...e.site?[{repo:e.siteRepo??"",...e.site,excerpt:e.excerpt}]:[],...e.otherSites]}function B(e,s){let t=T(s,e),r=e.line>1?t.split(`
4
+ `).slice(0,e.line-1).join(`
5
+ `)+`
6
+ `:"",n=t.replace(/\s+/g," "),a=e.excerpt.replace(/\s+/g," ").trim(),d=r.replace(/\s+/g," ").length,o=n.indexOf(a,d);if(o>=0)return{from:o,to:o+a.length};let l=a.split(/\s*(?:\.{3}|…)\s*/),u=n.indexOf(l[0],d),p=u;for(let i of l){let c=n.indexOf(i,p);if(c<0)return null;p=c+i.length}return u<0?null:{from:u,to:p}}function X(e,s,t){if(!S(e,s))return!0;let r=B(e,t),n=B(s,t);return r!==null&&n!==null&&(r.to<=n.from||n.to<=r.from)}function Z(e,s,t,r){if(!V(e.category))return"The finding has no supported evidence category.";if(!e.site||!e.siteRepo)return"The finding has no fetched primary site.";if(s.length<E(e.category))return"The category's required quoted sites are missing.";if(!t)return"Evidence coverage was not recorded unambiguously.";if(t.claimTruncated)return"The claim was truncated in the check.";if(!t.coreComplete||t.missing.length||t.truncated.length)return"Required evidence was unavailable or truncated.";if(t.requested.length===0||t.requested.some(n=>!t.included.some(a=>S(n,a))||T(r,n)===void 0))return"Required files were not included in the check.";for(let n of s){if(!t.requested.some(a=>S(a,n))||!t.included.some(a=>S(a,n)))return"A cited file was not included in the check.";if(!G(T(r,n),n.line,n.excerpt))return"A cited quote could not be verified at its source line."}return E(e.category)===2&&!s.some((n,a)=>s.slice(a+1).some(d=>X(n,d,r)))?"The category needs distinct quoted sites.":null}function ee(e,s){let t=e.cause.replace(/\s+/g," ").trim();for(let a of s){let d=a.excerpt?.replace(/\s+/g," ").trim();d&&(t=t.replaceAll(d,""))}if(!t||t===e.title)return!1;let r=/\b(?:without|before|instead|different|wrong|repeatedly|twice|never|cannot|can't|unable to|fails? to|unapproved|unauthori[sz]ed)\b/i,n=/\b(?:send(?:s|ing)?|sent|delet(?:e[sd]?|ing)|appl(?:y|ies|ied|ying)|grant(?:s|ed|ing)?|revok(?:e[sd]?|ing)|return(?:s|ed|ing)?|rout(?:e[sd]?|ing)|run(?:s|ning)?|execut(?:e[sd]?|ing)|writ(?:e[sd]?|ing)|read(?:s|ing)?|retry|retries|retried|retrying|skip(?:s|ped|ping)?|omit(?:s|ted|ting)?|block(?:s|ed|ing)?|allow(?:s|ed|ing)?|charg(?:e[sd]?|ing)|pay(?:s|ing)?|paid|los(?:e[sd]?|ing)|receiv(?:e[sd]?|ing)|select(?:s|ed|ing)?|exclud(?:e[sd]?|ing)|includ(?:e[sd]?|ing)|schedul(?:e[sd]?|ing))\b/i;return r.test(t)&&n.test(t)}function te(e,s,t,r){let n=[...e.matchAll(/(?:^|[\s(`*])([^\s"'“”‘’`() *]+):(\d+)(?:-\d+)?/g)].map(o=>{let l=o[1],u=t.included.filter(i=>i.path===l||`${i.repo}:${i.path}`===l),p=[...new Map(u.map(i=>[JSON.stringify([i.repo,i.path]),i])).values()];return{from:o.index,to:o.index+o[0].length,line:Number(o[2]),ref:p.length===1?p[0]:void 0}});if(n.length===0||n.some(o=>!o.ref))return!1;let a=new Map;for(let o of e.matchAll(W)){let l=o.index,u=l+o[0].length;if(n.some(f=>f.from>=l&&f.to<=u))continue;let p=o.slice(1).find(f=>f!==void 0),i=n.flatMap((f,k)=>G(T(r,f.ref),f.line,p)?[k]:[]);if(i.length!==1)return!1;let c=i[0];a.set(c,[...a.get(c)??[],p])}let d=!1;for(let o=0;o<n.length;o++){let l=n[o],{line:u,ref:p}=l,i=a.get(o)??[];if(i.length===0)return!1;s.some(c=>S(c,p)&&c.line===u&&i.some(f=>O(f,c.excerpt??"")!==null))&&(d=!0)}return d}function D(e,s,t,r){if(!e?.accepted)return"No accepted check verdict is available.";let n=e.verdict;return!n.sent||n.verdict!=="keep"||n.modelVerdict!=="keep"||!n.reason.trim()||n.reason!==n.modelReason?"The check kept the finding without an accepted supporting decision.":te(n.evidenceFor,s,t,r)?L.test(n.evidenceAgainst)?null:"Contrary check evidence has not been resolved.":"The check supplied no verified supporting quote."}function me(e){let s=e.findings.map($),t=A(e.coverage,s),r=A(e.verdicts,s),n=new Set(e.shadowRequestedIds??(e.shadowVerdicts===void 0?[]:s)),a=A(e.shadowVerdicts??[],[...n]);return e.findings.map((d,o)=>{let l=s[o],u=Y(d),p=t.get(l),i=Z(d,u,p,e.sources),c=_(d.category,e.sawCode)??i;!c&&!ee(d,u)&&(c="The finding does not explain a concrete behavioral consequence."),c||(c=D(r.get(l),u,p,e.sources)),!c&&n.has(l)&&(c=D(a.get(l),u,p,e.sources)),!c&&d.sourceNotes&&(d.sourceNotes.support!=="supported"||d.sourceNotes.counterEvidence.length>0)&&(c="Source notes contain uncertain support or unresolved contrary evidence.");let f=c?"not sure":"sure";return{fingerprint:l,support:i?"incomplete":"complete",confidence:f,weak:f!=="sure"||d.severity==="low",reason:c??(d.severity==="low"?"Verified support, but low impact.":"Verified quotes and an accepted keep support the stated consequence.")}})}function we(e,s,t){let r=e.map(t??(i=>$(i))),n=A(s,r),{active:a,notActive:d}=F(e),o=new Set(a),l=e.flatMap((i,c)=>{if(!o.has(i))return[];let f=r[c],k=n.get(f),b=k?.confidence==="sure",v=b&&k?.support==="complete"&&!k.weak&&i.severity!=="low";return[{finding:i,fingerprint:f,sure:b,strong:v}]}).sort((i,c)=>Number(c.strong)-Number(i.strong)||j[i.finding.severity]-j[c.finding.severity]||Number(c.sure)-Number(i.sure)||(i.fingerprint<c.fingerprint?-1:i.fingerprint>c.fingerprint?1:0)),u=l.filter(i=>i.strong).slice(0,3),p=new Set(u);return{ordered:[...l.map(i=>i.finding),...d],defaultIds:u.map(i=>i.fingerprint),hiddenIds:l.filter(i=>!p.has(i)).map(i=>i.fingerprint),emptyMessage:!u.length&&l.length?K:null}}export{se as a,ie as b,H as c,N as d,J as e,de as f,me as g,we as h};
@@ -0,0 +1,7 @@
1
+ import{A as We,Aa as Xe,C as Ue,D as Be,E as Ge,Fb as $,G as ge,Gb as it,H as Ze,Hb as ye,I as ee,K as Ke,L as we,M as Ye,N as Pe,O as ke,R as Se,S as Je,T as V,a as de,aa as ce,c as Q,d as B,e as pe,eb as He,g as Fe,gb as Qe,h as Me,hb as oe,i as I,ib as et,j as Le,jb as tt,kb as ot,l as K,n as De,o as je,ob as nt,p as G,q as Te,ra as qe,s as ze,sb as st,t as J,ub as fe,ya as W,yb as rt,z as ie,za as te,zb as at}from"./2M55DR2J.js";import{a as Ne}from"./MKYLK6DB.js";import{a as z,c as v,e as Y}from"./C6X5GDG4.js";import{a as j,b as C,c as E,e as Ae,i as he,j as $e,k as T,l as Z,o as Ie,v as le}from"./YWL52FVW.js";import{f as Ve}from"./SJESFYBA.js";function q(e,t,o,c=t,r={}){let a=V(e,t.filter(s=>$(e,{path:s},{purpose:"override",route:"github"}).admitted),{root:o,...r});return be(a,e,c.some(s=>{let d=v(s,o);return d!==null&&de(d)}))}function be(e,t,o=e.scoped.some(c=>de(c.relativePath))){let c=new Map(e.scoped.map(s=>[s.path,s.relativePath])),r=(s,d,w=!1)=>e.files.find(g=>g.role===s&&g.kind!=="background"&&g.preferred!==!1&&(!d||g.kind===d)&&(!w||g.preferred))?.path??null,a=(s,d,w=!1)=>e.files.filter(g=>g.role===s&&(!d||g.kind===d)&&g.ownerPath!==void 0===w).map(g=>g.path).sort();return{scoped:e.scoped.map(s=>s.path),hasRepositoryGuide:o,developerCompanionPaths:!pe(t)&&o?e.scoped.filter(s=>Et(s.relativePath)).map(s=>s.path):[],stripRoot:s=>c.get(s)??s,configPath:r("marker"),promptPath:r("prompt","dedicated",!0),claudePath:r("prompt","fallback"),toolsPath:r("tool file","json"),toolsTsPath:r("tool file","sdk"),cliPath:r("tool file","cli"),mcpPath:r("MCP config",void 0,!0),registry:e.registry,soulPath:r("soul"),knowledgePath:r("knowledge"),subagentPaths:a("sub-agent"),skillPaths:a("skill"),skillNames:Object.fromEntries(e.files.filter(s=>s.role==="skill"&&s.name).map(s=>[s.path,s.name])),skillRefNames:Object.fromEntries(e.files.filter(s=>s.role==="reference"&&s.kind==="skill"&&s.name).map(s=>[s.path,s.name])),templatePaths:a("reference","template"),skillRefPaths:a("reference","skill"),subagentSkillPaths:a("skill",void 0,!0),subagentSkillRefPaths:a("reference","skill",!0),subagentSkillOwners:Object.fromEntries(e.files.filter(s=>s.ownerPath!==void 0).map(s=>[s.path,s.ownerPath]))}}function lt(e){let t=new Set(e.developerCompanionPaths),o=c=>!t.has(c);return{...e,mcpPath:e.mcpPath&&o(e.mcpPath)?e.mcpPath:null,subagentPaths:e.subagentPaths.filter(o),skillPaths:e.skillPaths.filter(o),subagentSkillPaths:e.subagentSkillPaths.filter(o),subagentSkillRefPaths:e.subagentSkillRefPaths.filter(o),skillRefPaths:e.skillRefPaths.filter(o)}}function ne(e){let t=lt(e);return!!(t.promptPath||t.toolsPath||t.toolsTsPath||t.cliPath||t.mcpPath||t.soulPath||t.knowledgePath||t.subagentPaths.length||t.skillPaths.length)}function Ot(e){let t=lt(e);return!!(t.promptPath||t.registry&&t.soulPath||t.subagentPaths.length)}function ct(e,t){return pe(e)?ne(t):Ot(t)}function Et(e){return e.toLowerCase()===".mcp.json"||/^\.claude\/(agents|skills)\//i.test(e)}function ft(e,t){return!!e.configPath||!!e.claudePath&&t==="prompt"||ne(e)}var Ct=/^(evals?|evaluations)\/.*\.(jsonl?|ya?ml|md|csv)$|\.eval\.(json|ya?ml)$/i;function Rt(e){return ge.exec(e)?.[1]?.toLowerCase()==="commands"&&/\.md$/i.test(e)}function Ft(e){return Ct.test(e)}function X(e,t,o={}){if(!B(e))return!1;if(o.agentConfigurations){if(o.agentConfigurations[z(o.root)]!==!0)return!1;if(o.skills!==!1)return!0}let c=t.flatMap(w=>{let g=v(w,o.root);return g===null?[]:[{path:w,relative:g}]}),r=c.filter(({path:w})=>$(e,{path:w},{purpose:"definition",route:"github",root:o.root}).admitted);if(!r.some(({relative:w})=>Q.includes(w.toLowerCase())))return!1;let a=q(e,r.map(w=>w.path),o.root,t),s=!!(a.subagentPaths.length||a.toolsPath||o.skills!==!1&&a.skillPaths.length),d=r.some(({relative:w})=>Rt(w));return!o.agentConfigurations&&c.some(({relative:w})=>{let g=ge.exec(w)?.[1]?.toLowerCase();return!(g==="skills"||(g==="commands"?s:Le(w)&&(s||d)))&&!at.test(w)&&!rt.test(w)&&w.toLowerCase()!==ie.toolsSource&&Xe(w)})?!1:s||d||r.some(({relative:w})=>Ft(w))}function se(e,t,o){let c=new Map([[z(o),[]]]);for(let r of t)v(r,o)!==null&&Q.includes(r.split("/").at(-1).toLowerCase())&&c.set(r.slice(0,Math.max(0,r.lastIndexOf("/"))),[]);for(let r of t){if(v(r,o)===null)continue;let a=r.slice(0,Math.max(0,r.lastIndexOf("/")));for(;c.get(a)?.push(r),!!a;)a=a.slice(0,Math.max(0,a.lastIndexOf("/")))}return Object.fromEntries([...c].map(([r,a])=>[r,X(e,a,{root:r})]))}function fo(e,t){let o=[...new Set([...Object.keys(t.files),...t.listedPaths??[]])],{root:c,skills:r,agentConfigurations:a}=t;if(!X(e,o,{root:c,skills:r,agentConfigurations:a}))return null;let s=q(e,Object.keys(t.files),c,t.listedPaths,{agentConfiguration:!0});return s.claudePath?s:null}import{posix as re}from"node:path";import{posix as Mt}from"node:path";function _e(e,t=1){let o=new Set,c=[],r=e.replace(/{#[\s\S]*?#}|{%[-+]?\s*raw\s*[-+]?%}[\s\S]*?(?:{%[-+]?\s*endraw\s*[-+]?%}|$)/g,a=>a.replace(/[^\n]/g," "));for(let a of r.matchAll(/{%[-+]?\s*(include|extends|import|from)\s+(.+?)\s*[-+]?%}/g)){let s=a[2].match(/^(["'])([^"']+)\1(?:\s+(?:as\s+\w+|import\s+.+|ignore missing|with context|without context))?$/),d=t+e.slice(0,a.index).split(`
2
+ `).length-1;c.push({source:s?.[2]??a[2],span:{from:d,to:d},...s?{}:{reason:"dynamic"}})}for(let a of r.matchAll(/{{[-+]?\s*([\w]+)|{%[-+]?\s*(?:if|elif|for\s+\w+\s+in|set\s+\w+\s*=)\s+([\w]+)/g)){let s=a[1]??a[2];!["true","false","none"].includes(s.toLowerCase())&&!/^\d/.test(s)&&o.add(s)}return{variables:[...o],loaders:c}}function ut(e,t={}){let o=e.split(`
3
+ `),c=[],r=[],a=(s,d,w)=>{let g=new Set;for(let P of Qe(s.join(`
4
+ `))){let k=w?`${w}.${P.key}`:P.key,l={from:d+P.span.from,to:d+P.span.to},n=s.slice(P.span.from-1,P.span.to);g.has(P.key)&&r.push({key:k,span:l,reason:"duplicate"}),g.add(P.key);let p=n[0].slice(n[0].indexOf(":")+1).trim();if(!p||p.startsWith("#")){let f=n.slice(1),u=f.find(y=>y.trim()&&!y.trimStart().startsWith("#"))?.match(/^ */)?.[0].length;if(u){a(f.map(y=>y.slice(u)),l.from,k);continue}}let h=He(n.join(`
5
+ `))?.[P.key],m=typeof h=="string"?h:null,i=k.endsWith("_template")||Me(t,"CF_IMPORT_PROMPT_FIELDS")&&k.endsWith("_prompt");(i&&m===null||/^[!&*]/.test(p))&&r.push({key:k,span:l,reason:"invalid"}),c.push({key:k,span:l,text:o.slice(l.from-1,l.to).join(`
6
+ `),value:m,...i&&m!==null?_e(m,l.from+(/^[|>]/.test(p)?1:0)):{variables:[],loaders:[]}})}};a(o,0,"");for(let s of r.filter(d=>d.reason==="duplicate"))for(let d of c.filter(w=>w.key===s.key||w.key.startsWith(`${s.key}.`)))d.value=null;return{fields:c,unresolved:r}}function At(e,t){let{toks:o}=e,c=[],r=new Map;for(let a=0;a<o.length;a++){if(!he(o,a))continue;let s=$e(e.text,o[a]),d=c.findLast(k=>k.indent===s);for(;c.length&&c.at(-1).indent>=s;)c.pop();if(r.set(o[a].line,c.some(k=>!k.guard)?null:c.map(k=>k.guard)),!["if","elif","else","for","while","try","except","with","match","case"].some(k=>E(o[a],k)))continue;let w=a+1;for(;w<o.length&&o[w].line===o[a].line;)w++;let g=C(o[w-1],":"),P=null;if(g&&E(o[a],"else")&&d?.guard&&(P={...d.guard,value:!d.guard.value}),g&&E(o[a],"if")){let k=E(o[a+1],"not"),l=a+(k?2:1),n=o.slice(l,w-1).map(m=>m.text).join(""),p=t.owner(a),h=/^[A-Za-z_]\w*$/.test(n)?n:null;if(/^self\.[A-Za-z_]\w*$/.test(n)){let i=o.flatMap((f,u)=>u<a&&he(o,u)&&t.owner(u)===p&&o.slice(u,u+3).map(y=>y.text).join("")===n?[u]:[]).at(-1);h=i!==void 0&&C(o[i+3],"=")&&E(o[i+4])&&o[i+5]?.line!==o[i].line?o[i+4].text:null}if(h&&p?.params?.includes(h)&&!t.binding(h,a)){let m=o.findIndex((y,x)=>p.from<x&&x<a&&C(y,"(")),i=m>=0&&T(o,m)<a?Z(o,m).find(y=>E(o[y.from],h)):void 0,f=i&&o.findIndex((y,x)=>i.from<x&&x<i.to&&C(y,"=")),u=f!==void 0&&f>=0&&f+2===i?.to?o[f+1].text:null;P={parameter:h,value:!k,defaultValue:u==="True"?!0:u==="False"?!1:null}}}c.push({indent:s,guard:P}),r.set(o[a].line,null)}return r}function ko(e,t,o){let c=j(e,t,"py"),r=le(c,{includeMembers:!0}),a=ce(c,r,{enclosingBindings:!0}),{toks:s}=c,d=At(c,a),w=a.assignments.map(h=>["else","try","finally"].includes(h.name)&&E(s[h.from-2])?{...h,name:s[h.from-2].text,at:h.from-2}:h),g=h=>s.slice(h.from,h.to).map(m=>m.kind==="string"?JSON.stringify(m.value):m.text).join(""),P=(h,m,i,f)=>{let u=a.importBinding(h,m);return u?f?!u.namespace&&u.module.source===i&&u.name===f:u.namespace&&u.module.source===i:!1},k=[],l=new Map,n=new Map;for(let h of a.calls.filter(m=>m.callee.endsWith("read_text"))){let m=g(h),i=/^([A-Za-z_]\w*)\.resources\.files\(("(?:[^"\\]|\\.)*")\)\.joinpath\((.*?)\)\.read_text\(\)$/.exec(m)??/^([A-Za-z_]\w*)\.files\(("(?:[^"\\]|\\.)*")\)\.joinpath\((.*?)\)\.read_text\(\)$/.exec(m);if(!i)continue;let f=a.importBinding(i[1],h.from),u=m.startsWith(`${i[1]}.resources.files(`);if(!(f&&(u?f.namespace&&f.name==="importlib"&&["importlib","importlib.resources"].includes(f.module.source):f.namespace&&f.name==="importlib.resources"&&f.module.source==="importlib.resources"||!f.namespace&&f.name==="resources"&&f.module.source==="importlib")))continue;let x=a.calls.find(b=>b.from<h.from&&h.to<b.to&&b.args.length===1&&b.args[0].from===h.from&&b.args[0].to===h.to&&(b.callee.endsWith(".safe_load")&&P(b.callee.split(".")[0],b.from,"yaml")||P(b.callee,b.from,"yaml","safe_load")));if(!x)continue;let S=JSON.parse(i[2]),_;try{_=JSON.parse(i[3])}catch{}let R=null,A;if(typeof _!="string"||!/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*$/.test(S))A="dynamic";else if(Mt.isAbsolute(_)||/[\\\0]/.test(_)||_.split("/").includes(".."))A="out-of-scope";else{let b=`${S.replaceAll(".","/")}/${_}`,N=e.indexOf(`${S.split(".")[0]}/`),L=N>=0?e.slice(0,N)+b:null,D=[...o].filter(H=>H===b||H.endsWith(`/${b}`));R=L??(D.length===1?D[0]:null),R?o.has(R)||(A="missing"):A=D.length>1?"dynamic":"missing"}let O=w.find(b=>b.from<=x.from&&x.from<b.to&&a.owner(b.at)===a.owner(x.from)),F={path:R,source:typeof _=="string"?_:i[3],span:{from:s[h.from].line,to:s[h.to-1].endLine},start:s[x.from].start,end:s[x.to-1].end,binding:O?.name??null,forwarded:!1,when:d.get(s[O?.at??h.from].line)??null,className:r.filter(b=>b.kind==="class"&&b.from<h.from&&h.from<b.to).at(-1)?.name??null,...A?{reason:A}:{}};k.push(F),O&&(l.set(F,O),n.set(O,x))}let p=new Set([...l.values()].filter(h=>{let m=n.get(h);return(E(s[h.from],h.name)&&E(s[h.from+1],"or")?h.from+2:h.from)===m.from&&(h.to===m.to||h.to+1===m.to&&C(s[h.to],")"))}));for(let h of k){let m=l.get(h);!m||!p.has(m)||a.owner(m.at)?.name!=="__init__"||(h.forwarded=a.calls.some(i=>a.owner(i.from)===a.owner(m.at)&&s[i.from].start>h.end&&E(s[i.from],"super")&&i.callee.endsWith("__init__")&&i.args.some(f=>E(s[f.from],m.name)&&C(s[f.from+1],"=")&&f.to===f.from+3&&E(s[f.from+2],m.name))&&w.filter(f=>f.name===m.name&&m.at<f.at&&f.at<i.from&&a.owner(f.at)===a.owner(m.at)).every(f=>p.has(f))&&!s.some((f,u)=>u<i.from&&f.start>=h.end&&E(f,m.name)&&a.owner(u)===a.owner(m.at)&&![...p].some(y=>y.at<=u&&u<n.get(y).to))))}return k}function mt(e,t){if(!I(e))return[];let o=new Set(t),c=[];for(let r of[...o].sort()){let a=r.match(/^((?:[^/]+\/)*?)(?:src\/)?minisweagent\/agents\/default\.py$/);if(!a)continue;let s=r.slice(0,-18),d=`${s}/config`,w=`${d}/__init__.py`,g=`${s}/run/mini.py`;if(!o.has(w)||!o.has(g))continue;let P=[...o].filter(k=>v(k,d)!==null&&/\.ya?ml$/.test(k)).sort();P.length&&c.push({folder:a[1].replace(/\/$/,""),configFolder:d,agentPath:r,loaderPath:w,runnerPath:g,configs:P,templates:[...o].filter(k=>v(k,d)!==null&&/\.(?:j2|jinja2?)$/.test(k)).sort()})}return c}function $t(e,t){let o=j(e.agentPath,t[e.agentPath]??"","py").toks,c=j(e.loaderPath,t[e.loaderPath]??"","py").toks,r=j(e.runnerPath,t[e.runnerPath]??"","py").toks;if(!["system_template","instance_template"].every(s=>o.some((d,w)=>E(d,s)&&C(o[w-1],".")))||!c.some((s,d)=>E(s,"safe_load")&&C(c[d+1],"("))||!c.some((s,d)=>E(s,"read_text")&&C(c[d+1],"("))||!r.some((s,d)=>E(s,"get_config_from_spec")&&C(r[d+1],"("))||!r.some((s,d)=>E(s,"get_agent")&&C(r[d+1],"("))||!r.some((s,d)=>E(s,"get")&&C(r[d+1],"(")&&r[d+2]?.value==="agent"))return null;let a=r.flatMap((s,d)=>{if(!E(s,"DEFAULT_CONFIG_FILE")||!C(r[d+1],"="))return[];let w=r.slice(d+2).filter(g=>g.line===s.line);return w.flatMap((g,P)=>E(g,"builtin_config_dir")&&C(w[P+1],"/")&&w[P+2]?.kind==="string"?[re.join(e.configFolder,w[P+2].value)]:[])});return a.length===1?a[0]:null}function Eo(e,t,o,c){let r={variants:[],selectedPaths:[],fields:[],model:null,loaded:[],unresolved:[],edges:[]};if(!I(e))return r;let a=$t(t,o);if(!a)return r.unresolved.push({path:t.runnerPath,source:"config",reason:"dynamic"}),r;let s=new Map,d=new Set(Object.keys(o)),w=l=>{let n=$(e,{path:l,text:o[l],size:o[l]===void 0?void 0:Buffer.byteLength(o[l])},{purpose:"pointer",route:"github",root:t.configFolder,listing:d,managedFiles:o});return n.admitted||s.set(l,n.reason),n.admitted},g=new Map([...new Set([...t.configs,...c??[]])].flatMap(l=>w(l)&&Object.hasOwn(o,l)?[[l,ut(o[l],e)]]:[]));r.variants=t.configs.map(l=>({path:l,fields:(g.get(l)?.fields??[]).map(n=>({...n,path:l}))})),r.selectedPaths=c?[...c]:[a];let P=new Map;for(let l of r.selectedPaths){if(v(l,t.configFolder)===null){r.unresolved.push({path:l,source:l,reason:"out-of-scope"});continue}let n=g.get(l);if(!n){r.unresolved.push({path:l,source:l,reason:s.get(l)??"missing"});continue}r.unresolved.push(...n.unresolved.map(p=>({path:l,source:p.key,span:p.span,reason:p.reason})));for(let p of n.fields)if(/^(?:agent|model|environment)(?:\.|$)/.test(p.key)){for(let h of P.keys())(h.startsWith(`${p.key}.`)||p.key.startsWith(`${h}.`))&&P.delete(h);P.set(p.key,{...p,path:l})}}r.fields=[...P.values()],r.model=P.get("model.model_name")?.value??null;let k=new Set;for(let l of r.fields){let n=new Set([l.path]),p=[{path:l.path,facts:{variables:l.variables,loaders:l.loaders},next:0}];for(;p.length;){let h=p.at(-1),{path:m,facts:i}=h;if(h.next===0)for(let x of i.variables)r.unresolved.push({path:m,source:x,reason:"runtime-variable"});if(h.next>=i.loaders.length){n.delete(m),p.pop();continue}let f=i.loaders[h.next++],u=re.normalize(re.join(re.dirname(m),f.source)),y=f.reason??(re.isAbsolute(f.source)||v(u,t.configFolder)===null?"out-of-scope":w(u)?n.has(u)?"cycle":Object.hasOwn(o,u)?null:"missing":s.get(u));if(y){r.unresolved.push({path:m,source:f.source,...f.reason?{}:{target:u},span:f.span,reason:y});continue}r.edges.push({from:m,to:u,span:f.span}),!k.has(u)&&(k.add(u),r.loaded.push({path:u}),n.add(u),p.push({path:u,facts:_e(o[u]),next:0}))}}return r}import{posix as ue}from"node:path";function Oe(e){return/(?:^|\/)(?:(?:[^/]+_)?(?:crew|agents|tasks))\.py$/i.test(e)}function dt(e,t,o,c=""){let r=j(e,t,"py"),{toks:a}=r,s=le(r,{includeMembers:!0}),d=Ie(r),w=ce(r,s,{enclosingBindings:!0}),g={agents:[],tasks:[],refused:[]},P=l=>s.filter(n=>n.from<=l&&l<n.to),k=l=>{if(!E(a[l])||C(a[l-1],".")||!C(a[l+1],"("))return null;let n=w.importBinding(a[l].text,l);return n?.module.source==="crewai"&&["Agent","Task"].includes(n.name)?n.name:null};for(let l=0;l<a.length;l++){let n=k(l);if(!n)continue;let p=T(a,l+1);if(p>=a.length){g.refused.push({path:e,reason:"invalid"});continue}let h=P(l),m=h.filter(O=>O.kind==="class").at(-1),i=h.filter(O=>O.params!==null).at(-1),f=h.filter(O=>O.params===null&&O.kind!=="class"&&O.kind!=="index").at(-1),u=i?.name??f?.name??`line-${a[l].line}`,y=m?`${m.name}.${u}`:u,x=h.some(O=>O.kind==="index")||g.agents.some(O=>O.factory===y)?`${y}@${a[l].start}`:y,S=new Map(Z(a,l+1).flatMap(O=>E(a[O.from])&&C(a[O.from+1],"=")?[[a[O.from].text,{from:O.from+2,to:O.to}]]:[])),_={path:e,factory:x,span:{from:a[l].line,to:a[p].endLine},callStart:a[l].start},R=S.get("config");if(R){let O=a.slice(R.from,R.to).map(b=>b.kind==="string"?JSON.stringify(b.value):b.text).join(""),F=/^(?:self\.)?(agents_config|tasks_config)\["([^"\n]+)"\]$/.exec(O);if(F){let b=s.filter(M=>M.name===F[1]&&M.params===null&&(m?m.from<M.from&&M.to<=m.to&&!s.some(U=>U.params!==null&&U.from<M.from&&M.from<U.to):!s.some(U=>U.kind==="class"&&U.from<M.from&&M.from<U.to))),N=b.length===1?pt(r,b[0]):void 0,L=m&&Lt(r,m,w),D=N?xe(r,N):b.length===0&&L?`config/${F[1]==="agents_config"?"agents":"tasks"}.yaml`:null,H=null;if(D===null||/[\\\0${}*]/.test(D))g.refused.push({path:e,reason:"dynamic"});else{let M=ue.normalize(ue.join(ue.dirname(e),D));D.startsWith("/")||M===".."||M.startsWith("../")||v(M,c)===null?g.refused.push({path:M,reason:"out-of-scope"}):o.has(M)?H=M:g.refused.push({path:M,reason:"missing"})}_.config={path:H,key:F[2]}}else _.config={path:null,key:""},g.refused.push({path:e,reason:"dynamic"})}let A=ve(r,S.get("tools"),o,s,i,m,g.refused,w);if(n==="Agent"){let O=Object.fromEntries(["role","goal","backstory"].flatMap(F=>{let b=S.get(F)&&xe(r,S.get(F));return S.has(F)&&b==null&&g.refused.push({path:e,reason:"dynamic"}),b==null?[]:[[F,b]]}));g.agents.push({..._,instructions:O,tools:A})}else{let O=L=>It(r,L,m,s,d),F=O(S.get("agent")),b=S.get("context"),N=b&&C(a[b.from],"[")&&T(a,b.from)===b.to-1?Z(a,b.from):[];b&&(!C(a[b.from],"[")||N.some(L=>!O(L)))&&g.refused.push({path:e,reason:"dynamic"}),S.has("agent")&&!F&&g.refused.push({path:e,reason:"dynamic"}),g.tasks.push({..._,agent:F,context:N.flatMap(L=>O(L)??[]),tools:A})}l=p}return g}function pt(e,t){let o=t.from+1;for(;o<t.to&&!C(e.toks[o],"=");)o++;return o<t.to?{from:o+1,to:t.to}:void 0}function xe(e,t){let{toks:o}=e;return t.to===t.from+1&&o[t.from]?.kind==="string"&&Ae(o[t.from]).closed?o[t.from].value:E(o[t.from],"dedent")&&C(o[t.from+1],"(")&&T(o,t.from+1)===t.to-1?xe(e,{from:t.from+2,to:t.to-1}):null}function It(e,t,o,c,r){if(!t)return null;let a=e.toks.slice(t.from,t.to).map(d=>d.text).join(""),s=/^(self\.)?([A-Za-z_]\w*)(?:\(\))?$/.exec(a);if(s&&!s[1]){let d=c.filter(g=>g.params!==null&&g.from<t.from&&t.from<g.to),w=g=>c.filter(P=>P.params!==null&&P.from<g&&g<P.to).at(-1);if(d.some(g=>g.params?.includes(s[2]))||c.some(g=>g.name===s[2]&&d.includes(w(g.from)))||r.some(g=>g.names.includes(s[2])&&d.includes(w(e.toks.findIndex(P=>P.line===g.line)))))return null}return s?s[1]&&o?`${o.name}.${s[2]}`:s[2]:null}function ve(e,t,o,c,r,a,s,d,w=new Set){if(!t)return[];let{toks:g}=e;if(C(g[t.from],"[")&&T(g,t.from)===t.to-1)return Z(g,t.from).flatMap(u=>ve(e,u,o,c,r,a,s,d,new Set(w)));let P=g[t.from];if(!E(P)||w.has(P.text))return s.push({path:e.path,reason:"dynamic"}),[];if(w.add(P.text),r?.params?.includes(P.text))return s.push({path:e.path,reason:"dynamic"}),[];let l=c.filter(u=>u.name===P.text&&u.params===null&&u.kind!=="class"&&u.from<t.from).filter(u=>{let y=c.filter(x=>(x.params!==null||x.kind==="class")&&x.from<u.from&&u.from<x.to).at(-1);return!y||y===r||!r&&y===a}),n=r&&l.filter(u=>r.from<u.from&&u.to<=r.to),p=n&&n.length?n:l;if(p.length===1){let u=pt(e,p[0]);if(u)return ve(e,u,o,c,r,a,s,d,w)}if(p.length>1)return s.push({path:e.path,reason:"dynamic"}),[];let h=d.importBinding(P.text,t.from),m=h?.module,i=null;if(m){let u=ue.dirname(e.path).split("/"),y=u.lastIndexOf(m.source.split(".")[0]),x=m.source.startsWith(".")?m.source:y<0?`.${m.source}`:".".repeat(u.length-y)+m.source.split(".").slice(1).join(".");i=Ve(e.path,x,[h.name],"py",o)??null,!i&&(m.source.startsWith(".")||y>=0)&&s.push({path:e.path,reason:"missing"})}else if(!c.some(u=>u.name===P.text&&(u.kind==="class"||u.params!==null)))return s.push({path:e.path,reason:"dynamic"}),[];let f=t.from+1;for(;C(g[f],".")&&E(g[f+1]);)f+=2;return f<t.to&&(!C(g[f],"(")||T(g,f)!==t.to-1)?(s.push({path:e.path,reason:"dynamic"}),[]):[{name:g.slice(t.from,f).map(u=>u.text).join(""),path:m?i:e.path}]}function Lt(e,t,o){let c=e.text.slice(0,e.toks[t.from].start).trimEnd().split(`
7
+ `);for(let r=c.length-1;r>=0;r--){let a=/^\s*@([A-Za-z_]\w*)(?:\(\))?\s*$/.exec(c[r]);if(!a)break;let s=o.importBinding(a[1],t.from);if(s?.module.source==="crewai.project"&&s.name==="CrewBase")return!0}return!1}var Nt=new Set([...We,ie.soul].map(e=>e.toLowerCase())),Dt=["templates","default_prompts","prompts/default","docs","evals","benchmarks"],jt=["tests","__tests__","fixtures","test_data","evals","benchmarks","templates","default_prompts","prompts/default","docs"];function gt(e,t=""){return e===t?null:`folder:${e}`}function Qo(e,t,o){let c=wt(e,t,o),r=z(o),a=t.filter(n=>!G(e,n,r)),s=a.filter(n=>c.ownerOf(n)?.key===null),d=q(e,s,r),w=ne(d)||!!d.configPath,g=V(e,s,{root:r}).files.filter(n=>n.role!=="reference"&&n.kind!=="background"),P=new Set(g.map(n=>n.relativePath)),k=g.flatMap(n=>n.role==="sub-agent"?[n.relativePath.slice(0,-3)]:n.role==="skill"?[n.relativePath.slice(0,n.relativePath.lastIndexOf("/"))]:[]),l=new Map(c.scopes.map(n=>[n.folder,{scope:n,paths:[]}]));for(let n of[...new Set(a)]){let p=c.ownerOf(n);if(!p)continue;let h=v(n,r),m=h.split("/");if(p.key===null&&w&&m.length>1&&!P.has(h)&&!k.some(i=>v(h,i)!==null)){let i=m.slice(0,-1).findIndex((u,y)=>![...P].some(x=>x.startsWith(`${m.slice(0,y+1).join("/")}/`))),f=Y(m.slice(0,i<0?-1:i+1).join("/"),r);l.has(f)||l.set(f,{scope:{key:gt(f,r),folder:f,kind:"folder"},paths:[]}),p=l.get(f).scope}l.get(p.folder).paths.push(n)}return[...l.values()].sort((n,p)=>n.scope.folder<p.scope.folder?-1:n.scope.folder>p.scope.folder?1:0).map(({scope:n,paths:p})=>{let h=q(e,p,n.folder),m=c.scopes.includes(n);return{scope:n,paths:p,convention:m&&(!!n.managed||!!n.miniSwe||n.kind==="crew"&&!n.agentsPath.endsWith(".py")||ct(e,h)),markerPath:m?h.configPath:null}})}function wt(e,t,o,c={},r){let a=z(o);r??=B(e)?se(e,t,o):void 0;let s=K(e),d=et(e,t,c),{scopes:w,skipped:g,pluginFolders:P}=s?Tt(e,t,a,d,r):{scopes:[{key:null,folder:a,kind:"root"}],skipped:[],pluginFolders:[]},k=m=>Pt(w,m),l=new Set(t),n=t.filter(m=>G(e,m,a)||k(m)&&(s&&fe(e,m,P)||je(e,m,{root:a,listing:l}))),p=new Set(I(e)?Object.entries(c).filter(([m])=>m.endsWith(".py")&&k(m)).flatMap(([m,i])=>dt(m,i,new Set(t),a).agents.flatMap(f=>f.tools.flatMap(u=>u.path??[]))):[]),h=s?t.filter(m=>{let i=k(m);return!p.has(m)&&i?.kind==="crew"&&v(m,i.folder)?.toLowerCase().startsWith("tools/")}):[];return{scopes:w,skipped:g,ownerOf:k,pluginFolders:P,ignoredPaths:n,ignoredImportPaths:h,...d.length?{pluginDeclarations:d.filter(m=>P.includes(m.folder))}:{}}}function Pt(e,t){return e.findLast(o=>v(t,o.folder)!==null)??null}function Tt(e,t,o,c,r){let a=[...new Set(t)].filter(l=>!fe(e,l)).sort().flatMap(l=>{let n=v(l,o);return n===null?[]:[{path:l,relativePath:n}]}),s=[],d=new Map,w=a.filter(l=>!G(e,l.path,o)).map(l=>l.path);for(let l of ot(e,w))d.set(l.folder,l.agents.map(n=>({path:n,plugin:!1,crew:!1,checkPath:`${l.folder}/`,managed:l})));for(let l of mt(e,w))d.set(l.folder,[...d.get(l.folder)??[],{path:l.agentPath,plugin:!1,crew:!1,checkPath:`${l.folder}/`,miniSwe:l}]);for(let{path:l,relativePath:n}of a){let p=n.split("/"),h=p.pop().toLowerCase(),m=Y(p.join("/"),o),i=p.length>0&&(Nt.has(h)||Q.includes(h)&&X(e,t,{root:m,agentConfigurations:r})),f=tt(e,l,c);f===o&&!G(e,l,o)&&!s.includes(o)&&s.push(o);let u=f!==null&&f!==o&&!!v(`${f}/`,o),y=n.toLowerCase()==="config/agents.yaml"||n.toLowerCase().endsWith("/config/agents.yaml"),x=I(e)&&Oe(l)&&!/(?:^|\/)(?:tasks|[^/]+_tasks)\.py$/i.test(l),S=y||x;if(!i&&!u&&!S)continue;let _=y?l.slice(0,-18).replace(/\/$/,""):x?l.slice(0,Math.max(0,l.lastIndexOf("/"))):u?f:Y(p.join("/"),o),R=d.get(_)??[];R.push({path:l,plugin:u,crew:S,checkPath:u?`${_}/`:l}),d.set(_,R)}let g=ze(e),P={settings:e,folder:o,scoped:a,candidates:d,rootPlugins:s,excludedFolders:g?Dt:jt},k=ht(P,new Set);if(g){let l=[...new Set(k.accepted.map(i=>i.folder))].filter(i=>i!==o),n=a.filter(i=>!G(e,i.path,o)&&!l.some(f=>v(i.path,f)!==null)).map(i=>i.path),p=V(e,n,{root:o,folderAgentsFound:l.length>0,agentConfiguration:X(e,t,{root:o,agentConfigurations:r})}),h=kt(e,p,l.length>0)?[{path:`${o}/`,checkPath:`${o}/`}]:[],m=Te([...k.accepted,...h],i=>i.checkPath,{root:o,listing:new Set(a.map(i=>i.path)),settings:e});if(k.accepted.some(i=>m(i.checkPath))){let i=new Set([...d.values()].flat().filter(f=>m(f.checkPath)).map(f=>f.path));k=ht(P,i)}}return k.skipped.sort((l,n)=>l.path<n.path?-1:l.path>n.path?1:0),{scopes:k.scopes,skipped:k.skipped,pluginFolders:k.pluginFolders}}function ht({settings:e,folder:t,scoped:o,candidates:c,rootPlugins:r,excludedFolders:a},s){let d=[{key:null,folder:t,kind:"root"}],w=[],g=[...r],P=[],k=new Map;for(let l of[...c.keys()].sort()){let n=c.get(l),p=Pt(d,n[0].path),h=k.get(p.folder)??zt(o.map(S=>S.path),p.folder);k.set(p.folder,h);let m=[];for(let S of n){let{path:_,checkPath:R}=S;if(fe(e,_,g))continue;let A=G(e,_,t)?"excluded-folder":l===t?null:s.has(_)?"excluded-folder":Wt(v(R,t),v(R,p.folder),h,De(e,_,t)?[]:a);A?w.push({path:_,reason:A}):(m.push(S),P.push({path:_,folder:l,checkPath:R}))}if(!m.length)continue;let i=(I(e)?m.find(S=>S.crew&&S.path.endsWith("config/agents.yaml")):void 0)??m.find(S=>S.crew),f=gt(l,t),u=i?{key:f,folder:l,kind:"crew",agentsPath:i.path,tasksPath:o.find(S=>v(S.path,l)?.toLowerCase()==="config/tasks.yaml")?.path??null}:{key:f,folder:l,kind:"folder"},y=m.find(S=>S.managed)?.managed;y&&(u.managed=y);let x=m.find(S=>S.miniSwe)?.miniSwe;x&&(u.miniSwe=x),l===t?d[0]=u:d.push(u),m.some(S=>S.plugin)&&!g.includes(l)&&g.push(l)}return{scopes:d,skipped:w,pluginFolders:g,accepted:P}}function ae(e,t,o,c={}){let r=c.agentConfigurations??(B(e)?se(e,c.listedPaths??t,o):void 0),a=wt(e,t,o,c.files,r),{scopes:s,ownerOf:d,ignoredPaths:w}=a,g=new Set(w),P=new Map(s.map(i=>[i,[]]));for(let i of t){if(g.has(i))continue;let f=d(i);f&&P.get(f).push(i)}let k=s.map(i=>V(e,P.get(i),{root:i.folder,mode:c.mode,agentConfiguration:X(e,c.listedPaths??t,{root:i.folder,agentConfigurations:r}),folderAgentsFound:i.key===null&&(s.length>1||i.kind==="crew")})),l=(i,f)=>kt(e,i,s[f].key===null&&(s.length>1||s[f].kind==="crew")),n=s.length===1?k:k.filter((i,f)=>s[f].managed||s[f].miniSwe||s[f].kind==="crew"||l(i,f)),p=!n.length||n.some(i=>{let f=k.indexOf(i);return s[f].managed||s[f].miniSwe?!1:s[f].kind==="crew"&&!l(i,f)?s[f].agentsPath.endsWith(".py"):!i.registry&&(!i.files.some(u=>u.role==="prompt")||!i.files.some(u=>u.role==="tool file"))}),h=new Set((a.pluginDeclarations??[]).map(i=>i.path));for(let i of oe(e,t))/marketplace\.json$/i.test(i)&&h.add(i);let m=k.flatMap((i,f)=>{let u=s[f],y=[...h].filter(S=>!g.has(S)&&d(S)===u).map(S=>({path:S,relativePath:v(S,u.folder),role:"marker",kind:"entry"}));if(u.miniSwe)return[...i.files,...y,...[...u.miniSwe.configs,...u.miniSwe.templates,u.miniSwe.agentPath,u.miniSwe.loaderPath,u.miniSwe.runnerPath].map(S=>({path:S,relativePath:v(S,u.folder),role:"knowledge",kind:"entry"}))];if(u.managed)return[...[...u.managed.agents,...u.managed.configs].flatMap(S=>{let _=J(v(S,u.folder))?.definition;if(_&&(c.mode==="core"||!Ke(e)))return[];let R=u.managed.agents.includes(S);return[{path:S,relativePath:v(S,u.folder),role:R?"prompt":_?"skill":"knowledge",kind:R?"entry":_?"skill":"json"}]}),...y];if(u.kind!=="crew")return[...i.files,...y];let x=[{path:u.agentsPath,relativePath:v(u.agentsPath,u.folder),role:"prompt",kind:"entry"}];if(I(e))for(let S of P.get(u)){let _=v(S,u.folder);S!==u.agentsPath&&(Oe(_)&&!_.includes("/")||/^config\/[^/]+\.ya?ml$/i.test(_))&&x.push({path:S,relativePath:_,role:"knowledge",kind:"entry"})}return u.tasksPath&&x.push({path:u.tasksPath,relativePath:v(u.tasksPath,u.folder),role:"knowledge",kind:"entry"}),[...i.files,...x,...y]});return{...a,files:m,needsExtraction:p}}function kt(e,t,o){let c=be(t,e),r=Fe({codeAgentsFound:!1,folderAgentsFound:o,otherDefinitions:ne(c),agentConfiguration:t.files.some(a=>a.role==="prompt"&&a.kind==="fallback")},e);return ft(c,r)}function zt(e,t){let o=new Set;for(let c of e){let r=v(c,t);r!==null&&ee.test(r)&&o.add(r.slice(0,-3).toLowerCase())}return o}function Wt(e,t,o,c){let r=e.toLowerCase();if(c.some(d=>`/${r}`.includes(`/${d}/`)))return"excluded-folder";let a=r.slice(0,r.lastIndexOf("/"));if(J(e,{nested:!0})||Ze.some(d=>a===d||a.endsWith(`/${d}`)))return"skill-folder";if(`/${r}`.includes(`/${Be}/${Ge}/`)||ee.test(t))return"sub-agent-folder";let s=t.toLowerCase().split("/");return s.some((d,w)=>o.has(s.slice(0,w).join("/")))?"sub-agent-folder":null}var St="Some of this agent's files weren't read, so findings may be missing.";var yt=e=>e.CF_READING_PRIORITY!=="0";var Ut=new Set(["system prompt","soul","knowledge","config","tools","mcp"]);function bt(e){let t=new Set;for(let c of e.nodes)for(let r of c.files??[])Ut.has(r.role)&&t.add(r.path);let o=new Set(e.edges.filter(c=>c.kind==="delegates").map(c=>c.to));for(let c of e.nodes)o.has(c.id)&&c.sourceRef&&t.add(c.sourceRef.path);return t}function sn(e){return new Set([...e.nodes,...e.edges].flatMap(t=>t.sourceRef?[t.sourceRef.path]:[]))}var me=6e4,Bt=e=>{if(e.length<=me)return e;let t=e.endsWith(ye)?ye:"";return(t?e.slice(0,-t.length):e).slice(0,me)+t};function rn(e,t){let o=[...e].filter(c=>t[c]!==void 0&&Bt(t[c])!==t[c]).sort();return o.length===0?null:`${o.length} core file${o.length===1?" was":"s were"} longer than ${me/1e3} KB, so only the first ${me/1e3} KB ${o.length===1?"was":"were"} read: ${o.join(", ")}`}var Ee=e=>e.split("/").slice(0,-1).join("/"),Gt=/(agent|prompt|tool|llm|model)/i,Zt=2.5;function Re(e,t){if(!yt(e))return{enabled:!1,tierOf:()=>6};if(t.repos?.some(n=>n.kind==="github"&&z(n.root)))return Kt(e,t,t.repos);let o=t.scopes??(K(e)?ae(e,t.paths,void 0,{agentConfigurations:{}}):void 0),c=t.graph?bt(t.graph):new Set,r=new Set(t.graph?.nodes.flatMap(n=>(n.files??[]).filter(p=>p.role==="code"&&W(p.path)).map(p=>p.path))??[]),a=new Set(t.graph?.nodes.flatMap(n=>(n.files??[]).filter(p=>p.role==="system prompt").map(p=>p.path))??[]),s=n=>te(n)&&(Ue.includes(n.split("/").pop().toLowerCase())||/(^|\/)system_prompt_[^/]+\.md$/i.test(n)||Je.test(n)),d=n=>{if(c.has(n))return 1;if(r.has(n))return 2;let p=Pe(e,n,o),h=J(p,{nested:!0});if(h?.reference)return 5;if(h?.definition||ee.test(p))return 4;if(h||/(^|\/)(docs?|references)\//i.test(p)||Ye.test(n.split("/").pop()))return 5;if(we(p)||ke(e,n,o)&&we(n.split("/").pop())||s(n))return 1;if(W(n)){if(Gt.test(n))return Zt;if(Se.test(n))return 3}return 6};for(let n of t.paths)d(n)===1&&s(n)&&a.add(n);let w=[...a].flatMap(n=>{let p=Ee(n);return[p,...p?[Ee(p)]:[]]}),g=n=>W(n)&&w.some(p=>Ee(n)===p),P=new Map(t.paths.map(n=>{let p=d(n);return[n,p>2&&g(n)?2:p]})),k=[...P].filter(([n,p])=>p<=2&&W(n)).map(([n])=>n),l=qe(Object.fromEntries(k.flatMap(n=>t.files?.[n]===void 0?[]:[[n,t.files[n]]])),t.paths);for(let n of l)W(n)&&!J(Pe(e,n,o),{nested:!0})&&(P.get(n)??6)>2&&P.set(n,2);return{enabled:!0,tierOf:n=>P.get(n)??d(n)}}function Kt(e,t,o){let c=new Map;for(let r of o){let a=r.kind==="github"?r.root:void 0,s=t.paths.filter(n=>r.files?.[n]!==void 0&&!c.has(n)),d=n=>v(n,a)??(r.files?.[n]!==void 0?n:null),w=n=>{let p=n?d(n.path):null;return p===null?null:{path:p}},g=t.graph&&{nodes:t.graph.nodes.map(n=>({...n,sourceRef:w(n.sourceRef),files:n.files?.flatMap(p=>{let h=d(p.path);return h===null?[]:[{...p,path:h}]})})),edges:t.graph.edges.map(n=>({...n,sourceRef:w(n.sourceRef)}))},P=s.flatMap(n=>{let p=d(n);return p===null?[]:[p]}),k=Object.fromEntries(s.flatMap(n=>{let p=d(n);return p===null||t.files?.[n]===void 0?[]:[[p,t.files[n]]]})),l=Re(e,{paths:P,files:k,graph:g});for(let n of s)c.set(n,l.tierOf(d(n)??n))}return{enabled:!0,tierOf:r=>c.get(r)??6}}function Yt(e,t){return e.enabled?t.filter(o=>["too-large","total","allowance"].includes(o.reason)&&e.tierOf(o.path)<3).map(o=>o.path):[]}function Jt(e){return e.slice(0,3)}function Vt(e,t=!1){let o=Jt(e);if(!o.length)return;let c=t?". "+St:", so some findings may be missing";return`${o.join(", ")} ${o.length===1?"was":"were"} left out${c}`}function Pn(e,t){return Vt(Yt(e,t))}function kn(e,t){return e.enabled&&e.tierOf(t)<3}function _t(e,t,o){let c=Ne.sourceFetch.codeFileBytes;return e.enabled&&e.tierOf(t)<3&&W(t)&&o>c?{size:c,readBytes:c}:{size:o}}function xt(e,t){return e.enabled&&e.tierOf(t)<3&&W(t)}function Ce(e){return e.split("/").length-1}function vt(e,t,o){return ke(e,t,o)?0:Se.test(t)?1+Math.min(Ce(t),3)/10:Ce(t)<=2?2:Ce(t)<=4?3:4}function Sn(e,t){return(e.tier??0)-(t.tier??0)||e.score-t.score||e.size-t.size}function yn(e,t,o,c){return[...e].sort((r,a)=>(c?.enabled?c.tierOf(r)-c.tierOf(a):0)||Number(o.has(a))-Number(o.has(r))||t[r].length-t[a].length||(r<a?-1:1))}function bn(e,t,o,c){return[...e].sort((r,a)=>(c?.enabled?c.tierOf(r.path)-c.tierOf(a.path):0)||Number(t.has(a.path))-Number(t.has(r.path))||Number(o.has(a.path))-Number(o.has(r.path))||r.text.length-a.text.length)}function $n(e,t,o={},c={}){let{root:r}=o,a=t.map(i=>i.path),s=B(e)?se(e,a,r):void 0,d=t.filter(i=>{let f=$(e,i,{...o,purpose:"source",route:"github"});return f.admitted||f.reason==="wrong-type"||f.reason==="too-large"}),w=K(e)?ae(e,d.map(i=>i.path),r,{files:c.files,listedPaths:a,agentConfigurations:s}):void 0,g=new Set([...w?.pluginDeclarations?.map(i=>i.path)??[],...oe(e,w?.files.map(i=>i.path)??[])]),P=w??(c.measureAnalysisSize?ae(e,d.map(i=>i.path),r,{listedPaths:a,agentConfigurations:s}):void 0),k=new Map(P?.files.map(i=>[i.path,i])),l=c.measureAnalysisSize?new Map(t.map(i=>[i.path,i.size])):void 0,n=w?{files:w.files.map(i=>({...i,path:v(i.path,r)})),ownerOf:i=>{let f=w.ownerOf(Y(i,r));return f?{...f,folder:f.key===null?"":v(f.folder,r)}:null}}:void 0,p=new Set(w?.ignoredPaths),h=Re(e,{paths:d.map(i=>v(i.path,r)),scopes:n});return{descriptions:t.flatMap(i=>{if(p.has(i.path))return[];let f=v(i.path,r),u=f===null?{size:i.size}:_t(h,f,i.size),y=$(e,{...i,size:u.size},{...o,purpose:"source",route:"github",scopes:n}),x=f===null?99:vt(e,f,n),S=f!==null&&!g.has(i.path)&&!xt(h,f)&&(te(i.path)||st(e,f,n)||x===0)?"instruction":"code",_={};if(c.measureAnalysisSize){let R=y.admitted||y.reason==="too-large",A=$(e,i,{...o,purpose:"code-scan",route:"github",listing:l}),O=k.get(i.path),F=O&&(y.admitted||["too-large","wrong-type","empty"].includes(y.reason))&&$(e,{path:i.path},{...o,purpose:nt(O.role),route:"github"}).admitted;_.countsTowardAnalysisSize=R||A.admitted||A.reason==="too-large"||!!F,c.measureAnalysisSizeLowerBound&&(_.countsTowardAnalysisSizeWithoutInventory=it(e,i,o),_.countsTowardInstructionSizeWithoutInventory=_.countsTowardAnalysisSizeWithoutInventory&&te(i.path)&&oe(e,[i.path]).length===0),_.analysisPool=O?.role==="skill"||O?.role==="reference"?"instruction":S}return[{entry:i,readEntry:{...i,...u},rel:f,score:x,pool:S,..._,admission:y,...h.enabled&&f!==null?{tier:h.tierOf(f)}:{}}]}),priority:h,declarations:g,discovery:P}}export{q as a,lt as b,ne as c,ct as d,ft as e,se as f,fo as g,ut as h,ko as i,Eo as j,dt as k,Qo as l,wt as m,ae as n,yt as o,bt as p,sn as q,Bt as r,rn as s,Re as t,Yt as u,Jt as v,Vt as w,Pn as x,kn as y,Sn as z,yn as A,bn as B,$n as C};
@@ -0,0 +1 @@
1
+ var o=["totalBytes","instructionBytes","fileCount"],i=()=>new Error("Invalid analysis size"),c=t=>typeof t=="number"&&Number.isSafeInteger(t)&&t>=0;function f(t){if(!t||typeof t!="object"||Array.isArray(t)||Reflect.ownKeys(t).length!==o.length||o.some(s=>!Object.hasOwn(t,s)||!c(Reflect.get(t,s))))throw i();let{totalBytes:e,instructionBytes:n,fileCount:r}=t;if(n>e)throw i();return{totalBytes:e,instructionBytes:n,fileCount:r}}export{f as a};
@@ -0,0 +1,2 @@
1
+ import{h as j}from"./VDUFPTDD.js";function N(e,t){let n=[...e].filter(o=>t.has(o)).length,r=e.size+t.size-n;return r?n/r:null}function D(e){let t=e.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),n=[e.kind,e.siteRepo??"-",e.site?.path??"-",t];return(j(e.category)?[...n,e.site?.line??"-",e.cause??""]:n).join("|")}var p=e=>e.legacyFingerprint??e.fingerprint,y=e=>e.replace(/\s+/g," ").trim(),T=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(" ")),S=new Set(["before","after","instead","from","to","than"]),P=new Set([...S,"no","not","never","cannot","without"]),_=/^(?: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)?)$/,k=e=>e.split(/[.!?;,\n]+|\b(?:and|but|while)\b/);function v(e){return _.test(e)?e==="sent"?"send":e.replace(/(?:ing|ped|ed|es|s)$/,"").replace(/^skipp$/,"skip").replace(/^(delet|revok|rout|writ|charg)$/,"$1e"):null}function w(e){let t=(e.toLowerCase().replaceAll("can't","cannot").match(/[a-z0-9_]+/g)??[]).filter(n=>!T.has(n)||S.has(n)).map(n=>v(n)??n);return t.map((n,r)=>["not","never","cannot"].includes(n)&&v(t[r+1]??"")!==null?"skip":n)}function L(e){return new Set(w(e))}function B(e){return[...L(e)].filter(t=>v(t)!==null).sort()}function W(e){return k(e).filter(t=>w(t).some(n=>S.has(n))).map(t=>w(t).join(" ")).sort()}function Q(e,t){let n=r=>r!=="refund"&&v(r)!==null;return k(e).flatMap(r=>{let o=w(r);return o.flatMap((a,l)=>{if(!n(a))return[];let u=o.slice(l+1),f=u.findIndex(m=>n(m)||P.has(m)),s=u.slice(0,f<0?u.length:f).filter(m=>t.has(m)),i=["skip","no","not","never","cannot","without"].includes(o[l-1]??""),c=f<0?[]:u.slice(f),d=c.findIndex(m=>n(m)),g=c.slice(0,d<0?c.length:d),h=g.flatMap((m,E)=>{if(!S.has(m))return[];let O=g.slice(E+1),M=O.findIndex(x=>S.has(x));return[JSON.stringify([m,O.slice(0,M<0?O.length:M).filter(x=>t.has(x))])]});return s.length?[{action:a,objects:s,denied:i,relations:h}]:[]})}).sort((r,o)=>JSON.stringify(r).localeCompare(JSON.stringify(o)))}function G(e){let t=w(e);return["before","after","instead"].filter(n=>t.includes(n)).concat(t.some((n,r)=>["no","not","never","cannot","without"].includes(n)||n==="skip"&&v(t[r+1]??"")!==null)?["negative"]:[])}function b(e){let t=y(e.cause??"").toLowerCase(),n=[...new Set(e.sites.map(a=>y(a.quote).toLowerCase()))].sort((a,l)=>l.length-a.length||a.localeCompare(l));for(let a of n)t=t.replaceAll(a,"");let r=L(t),o=L(e.sites.map(a=>a.quote).join(" "));return{text:t,terms:r,operators:t.match(/!==|===|!=|==|<=|>=|<|>/g)??[],actions:B(t),direction:G(t),relations:W(t),anchors:[...r].filter(a=>o.has(a)).sort(),numbers:[...r].filter(a=>/^\d+$/.test(a)).sort(),objects:k(t).map(a=>w(a).filter(l=>o.has(l)&&v(l)===null&&!P.has(l)).join(" ")).filter(Boolean).sort(),bindings:Q(t,o)}}function C(e,t){let[n,r]=[b(e),b(t)];if(Math.min(n.terms.size,r.terms.size)<3||!n.anchors.length)return!1;for(let a of["operators","actions","direction","relations","anchors","numbers","objects","bindings"])if(JSON.stringify(n[a])!==JSON.stringify(r[a]))return!1;let o=[...n.terms].filter(a=>r.terms.has(a));return n.text===r.text||o.length>=4&&o.length/Math.max(n.terms.size,r.terms.size)>=.7}function K(e){return[...new Set(e.map(t=>JSON.stringify([t.repoKey,t.path,y(t.quote)])))].sort()}function I(e){return e.omittedSites||!e.sites.length||e.sites.some(t=>t.verified===!1||!t.path||!y(t.quote)||!Number.isInteger(t.startLine)||t.startLine<1||!Number.isInteger(t.endLine)||t.endLine<t.startLine)?null:K(e.sites)}function J(e,t){return e.kind===t.kind&&e.category===t.category&&(e.agentId??null)===(t.agentId??null)}function H(e,t){if(!e.kind||!e.category||!J(e,t))return!1;let[n,r]=[I(e),I(t)];return n!==null&&r!==null&&JSON.stringify(n)===JSON.stringify(r)&&C(e,t)}function U(e,t){if(!J(e,t))return!0;let[n,r]=[I(e),I(t)];return n!==null&&r!==null&&JSON.stringify(n)!==JSON.stringify(r)?!0:n===null||r===null?!1:R(e,t)}function R(e,t){let[n,r]=[b(e),b(t)],o=(l,u)=>l.some(f=>!u.includes(f))&&u.some(f=>!l.includes(f));for(let l of["actions","anchors","numbers","operators"])if(o(n[l],r[l]))return!0;for(let l of n.actions.filter(u=>r.actions.includes(u))){let u=n.bindings.filter(s=>s.action===l),f=r.bindings.filter(s=>s.action===l);if(u.length&&f.length&&u.every(s=>f.every(i=>o(s.objects,i.objects)||s.denied!==i.denied||o(s.relations,i.relations))))return!0}for(let l of new Set(n.bindings.map(u=>JSON.stringify(u.objects)))){let u=f=>f.bindings.filter(s=>JSON.stringify(s.objects)===l).map(s=>s.action);if(o(u(n),u(r)))return!0}let a=l=>l.direction.filter(u=>u!=="negative");return!!o(a(n),a(r))}function A(e){for(let i of[e.previous,e.current])if(i.some(c=>!c.id||!c.fingerprint)||new Set(i.map(c=>c.id)).size!==i.length)throw new Error("Missing or duplicate finding identities.");let t=e.previous.flatMap(i=>e.current.flatMap(c=>(p(i)===p(c)?!e.enabled||!U(i,c):e.enabled&&H(i,c))?[{previous:i,current:c}]:[])),n=[],r=new Set,o=new Set,a=(i,c)=>{for(let d of i)i.filter(g=>g.previous.id===d.previous.id).length!==1||i.filter(g=>g.current.id===d.current.id).length!==1||(n.push({previousId:d.previous.id,currentId:d.current.id,fingerprint:e.enabled?d.previous.fingerprint:p(d.previous),reason:c}),r.add(d.previous.id),o.add(d.current.id))};a(t.filter(i=>p(i.previous)===p(i.current)),"legacy");let l=t.filter(i=>!r.has(i.previous.id)&&!o.has(i.current.id));e.enabled&&a(l,"meaning");let u=l.filter(i=>!r.has(i.previous.id)&&!o.has(i.current.id)),f=new Map;for(let i of u){let c=u.filter(h=>h.current.id===i.current.id).map(h=>h.previous.id).sort(),d=u.filter(h=>h.previous.id===i.previous.id).map(h=>h.current.id).sort(),g={reason:"ambiguous",previousIds:c,currentIds:d};f.set(JSON.stringify(g),g)}n.sort((i,c)=>i.previousId.localeCompare(c.previousId)||i.currentId.localeCompare(c.currentId));let s=new Map(n.map(i=>[i.currentId,i]));return{matches:n,unmatchedPrevious:e.previous.filter(i=>!r.has(i.id)),unmatchedCurrent:e.current.filter(i=>!o.has(i.id)),currentIdentities:e.current.map(i=>({currentId:i.id,legacyFingerprint:p(i),matchedFingerprint:s.get(i.id)?.fingerprint??p(i),matchedId:s.get(i.id)?.previousId??i.id})),diagnostics:[...f.entries()].sort(([i],[c])=>i.localeCompare(c)).map(([,i])=>i)}}function q(e,t){let n=new Map;for(let r of e.sites){let o=K([r])[0];t.includes(o)||n.set(o,JSON.stringify([r.repoKey,r.path]))}return[...n.values()].sort()}function Z(e,t){let n=A({previous:[e],current:[t],enabled:!0});if(!J(e,t))return"different";let[r,o]=[I(e),I(t)];if(r===null||o===null)return"unknown";if(n.matches.length)return"unchanged";if(!e.kind||!e.category||p(e)!==p(t))return"different";let a=y(e.cause??"").toLowerCase();if(!a||a!==y(t.cause??"").toLowerCase()&&!C(e,t))return"different";let[l,u]=[q(e,o),q(t,r)];return!l.length||new Set(l).size!==l.length||JSON.stringify(l)!==JSON.stringify(u)?"different":"quotes_changed"}function ee(e){let t=A(e),n=new Set(e.previous.map(p)),r=new Set(e.current.map(p)),o=(s,i)=>JSON.stringify([s,i]),a=new Set(t.matches.map(s=>o(s.previousId,s.currentId)));for(let s of e.reviews??[])if(!e.previous.some(i=>i.id===s.beforeId)||!e.current.some(i=>i.id===s.afterId))throw new Error("Identity review names a missing finding.");let l=new Set(e.previous.map(s=>JSON.stringify(["previous",s.id]))),u=new Map(t.matches.map(s=>[s.currentId,s.previousId])),f=new Set(e.current.map(s=>u.has(s.id)?JSON.stringify(["previous",u.get(s.id)]):JSON.stringify(["current",s.id])));return{result:t,legacyOverlap:N(n,r),matchedOverlap:N(l,f),review:{pairs:t.matches.map(s=>({beforeId:s.previousId,afterId:s.currentId,reason:s.reason})),falseJoins:e.reviews?.filter(s=>!s.sameProblem&&a.has(o(s.beforeId,s.afterId))).map(s=>o(s.beforeId,s.afterId))??null,missedJoins:e.reviews?.filter(s=>s.sameProblem&&!a.has(o(s.beforeId,s.afterId))).map(s=>o(s.beforeId,s.afterId))??null,rawNew:[...r].filter(s=>!n.has(s)).length,rawFixed:[...n].filter(s=>!r.has(s)).length,matchedNew:t.unmatchedCurrent.length,matchedFixed:t.unmatchedPrevious.length}}}var $=e=>[...e.site?[{...e.site,excerpt:e.excerpt}]:[],...e.otherSites??[]];function F(e){let t=$(e),n=new Map;for(let r of t){let o=JSON.stringify([r.path,r.line??null]);(!n.has(o)||(r.line??0)>0&&r.excerpt?.trim())&&n.set(o,r)}return[...n.values()].sort((r,o)=>r.path.localeCompare(o.path)||(r.line??-1)-(o.line??-1))}function te(e,t){if(e.category!==t.category)return!1;let[n,r]=[F(e),F(t)];return n.length===r.length&&n.every((o,a)=>o.path===r[a].path&&(o.line==null||r[a].line==null?o.line==r[a].line:Math.abs(o.line-r[a].line)<=3))}function ne(e,t){let[n,r]=[z(e,"a"),z(t,"b")];if((n.agentId??null)!==(r.agentId??null)||R(n,r))return!1;let o=(i,c)=>i.omittedSites&&!!c.excerpt?.trim()||i.sites.some(d=>!!d.quote.trim()&&(!d.path||!Number.isInteger(d.startLine)||d.startLine<1||d.verified===!1));if(o(n,e)||o(r,t))return!1;let a=i=>{let c=new Map;for(let d of i.sites){if(!d.quote.trim())continue;let g=JSON.stringify([d.repoKey,d.path,d.startLine]);(!c.has(g)||c.get(g).endLine<d.endLine)&&c.set(g,d)}return[...c.values()]},[l,u]=[a(n),a(r)].sort((i,c)=>i.length-c.length);if(!l.length||e.category!==t.category&&l.length<2||l.length===1&&y(e.cause).toLowerCase()!==y(t.cause).toLowerCase()&&!C(n,r))return!1;let f=(i,c)=>i.repoKey===c.repoKey&&i.path===c.path&&i.startLine<=c.endLine&&c.startLine<=i.endLine,s=(i,c)=>i===l.length||u.some((d,g)=>c.has(g)||!f(l[i],d)?!1:s(i+1,new Set([...c,g])));return s(0,new Set)}function z(e,t){return{id:t,fingerprint:D(e),kind:e.kind,title:e.title,category:e.category,cause:e.cause,agentId:e.agentId,omittedSites:+!e.site,sites:$(e).map(n=>({repoKey:n.repo??e.siteRepo??"",path:n.path,startLine:n.line??0,endLine:(n.line??0)+(n.excerpt?.split(`
2
+ `).length??1)-1,quote:n.excerpt??"",...n.verified!==void 0?{verified:n.verified}:{}}))}}export{D as a,p as b,K as c,A as d,Z as e,ee as f,F as g,te as h,ne as i,z as j};