@counterfact-labs/cli 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/client-release.json +1 -1
- package/dist/adapters/files.js +5 -1
- package/dist/adapters/relay-plan.js +2 -2
- package/dist/adapters/release.js +8 -3
- package/dist/adapters/settings.js +2 -1
- package/dist/analysis-core/analysis/finding-quality/config.js +1 -1
- package/dist/analysis-core/analysis/finding-quality/policy.js +1 -1
- package/dist/analysis-core/analysis/headlines/attachment.js +1 -1
- package/dist/analysis-core/analysis/headlines/input.js +1 -1
- package/dist/analysis-core/analysis/schemas.js +1 -1
- package/dist/analysis-core/chunks/3CKW5JIF.js +1 -0
- package/dist/analysis-core/chunks/3GUKUEEJ.js +1 -0
- package/dist/analysis-core/chunks/7OYIBWX3.js +1 -0
- package/dist/analysis-core/chunks/{Y5AUKKYG.js → D6AWHLRI.js} +1 -1
- package/dist/analysis-core/chunks/{G322LST6.js → DRGDIIFA.js} +1 -1
- package/dist/analysis-core/chunks/{ZMUBMYWN.js → FTODBFQW.js} +1 -1
- package/dist/analysis-core/chunks/{EQTIRIMU.js → HPIAEQHE.js} +25 -25
- package/dist/analysis-core/chunks/{YVDCJN7D.js → IVDDV6CU.js} +1 -1
- package/dist/analysis-core/chunks/JKWTHRUR.js +1 -0
- package/dist/analysis-core/chunks/K5OTWBTT.js +22 -0
- package/dist/analysis-core/chunks/{VFENG4MR.js → MJGB25S5.js} +1 -1
- package/dist/analysis-core/chunks/{DTMHXKP6.js → MXXNED6N.js} +1 -1
- package/dist/analysis-core/chunks/NCWEOJVJ.js +6 -0
- package/dist/analysis-core/chunks/{M7MMAUAK.js → O652FQQH.js} +1 -1
- package/dist/analysis-core/chunks/{QPXNXMLC.js → QMIXCT62.js} +1 -1
- package/dist/analysis-core/chunks/QV2EOS7U.js +1 -0
- package/dist/analysis-core/chunks/T2SAP7OV.js +60 -0
- package/dist/analysis-core/chunks/{VER355VN.js → T66VDFXF.js} +1 -1
- package/dist/analysis-core/chunks/{IL2KRP3T.js → V7BFUTM7.js} +1 -1
- package/dist/analysis-core/contracts/requests.js +1 -1
- package/dist/analysis-core/conventions/analysis-fit.js +1 -0
- package/dist/analysis-core/conventions/file-admission.js +1 -1
- package/dist/analysis-core/errors.js +1 -1
- package/dist/analysis-core/import/outside-loader-sources.js +1 -1
- package/dist/analysis-core/index.js +3 -3
- package/dist/analysis-core/llm/cache-policy.js +1 -1
- package/dist/analysis-core/llm/cost.js +1 -1
- package/dist/analysis-core/requests/local-plan.js +1 -1
- package/dist/analysis-core/requests/registry.js +1 -1
- package/dist/analysis-core/requests/template-version.js +1 -1
- package/dist/analysis-core/requests/tools.js +1 -1
- package/dist/analysis-core/settings.js +1 -1
- package/dist/bundle/seal/signature.js +2 -2
- package/dist/cli/commands/analyze.js +4 -2
- package/dist/cli/development-relay.js +34 -0
- package/dist/cli/relay-check.js +2 -2
- package/dist/cli/relay-preparation.js +3 -1
- package/dist/contract/cli-refusals.js +2 -0
- package/dist/contract/cli-version.js +1 -1
- package/dist/contract/console.js +20 -0
- package/dist/gatekeeper/connection-exchange.js +2 -1
- package/dist/gatekeeper/console.js +11 -4
- package/package.json +2 -2
- package/dist/analysis-core/chunks/7QDOHWSY.js +0 -27
- package/dist/analysis-core/chunks/BZNHHLNP.js +0 -1
- package/dist/analysis-core/chunks/KEKTZDIK.js +0 -1
- package/dist/analysis-core/chunks/ORCYIIHB.js +0 -60
- package/dist/analysis-core/chunks/PVPEY7NF.js +0 -1
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import{b as Fe}from"./IL2KRP3T.js";import{b as ae}from"./2PSNOSJ2.js";import{$ as wt,B as pt,E as de,F as mt,G as Be,H as ut,Ia as se,J as ve,K as ht,L as gt,La as Ke,M as kt,Ma as Ue,Na as Y,Oa as Je,Qa as Ot,Ra as Ft,Sa as $t,Ta as Mt,U as xe,Ua as Et,W as yt,Za as Ct,b as Pe,c as We,d as G,f as Se,g as H,ga as L,h as A,i as R,j as F,k as $,l as ee,m as N,n as U,o as fe,oa as bt,p as ft,pa as Pt,q as V,r as Z,s as ct,sa as St,ta as Oe,u as dt,ua as vt,v as te,w as ce,wa as xt,x as ne,xa as pe,y as ze,za as oe}from"./EQTIRIMU.js";import{a as Te,b as K,c as M,e as De}from"./T5TREZCQ.js";function so({prompt:e,link:t}){return{path:t?.callPath??e.path,...t?{line:t.callLine}:{},symbol:e.symbol,promptPath:e.path,promptStart:e.start,...t?.kind==="L4"?{loadedPrompt:!0,...t.callStart!==void 0?{callStart:t.callStart}:{}}:{}}}function Lt(e,t,n,r,o){return r?Ct(t,n,o):{tools:[],warnings:[],from:{}}}var $e=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function Mn(e,t,n,r={}){let o=new Map(e.map(s=>[$e(s),s]));return t.flatMap(s=>{let i=Object.hasOwn(n,s)?n[s]:void 0;if(i===void 0||!L(r,{path:s},{purpose:"code-support",route:"github"}).admitted)return[];let a=R(s,i,A(s)).toks;return a.flatMap((c,k)=>{if(!$(c))return[];let d=o.get($e(c.text));if(!d)return[];let f=!1;if($(a[k-1],"function")||$(a[k-1],"def"))f=F(a[k+1],"(");else if(["const","let","var"].some(l=>$(a[k-1],l))){for(let l=k+1;l<a.length&&l<k+80&&!F(a[l],";");l++)if(F(a[l],"=")){let m=$(a[l+1],"async")?l+2:l+1,p=F(a[m],"(")?N(a,m)+1:m+1;f=$(a[m],"function")||F(a[p],"=")&&F(a[p+1],">");break}}return f?[{name:d,sourcePath:s,sourceLine:c.line}]:[]})})}function jt(e,t,n,r,o={}){let s=new Set(e.map($e)),i=d=>L(o,{path:d},{purpose:"code-support",route:"github"}).admitted,a=d=>Mn(e,[d],n,o).length>0,c=t.filter(d=>i(d)&&a(d)),k=r.filter(d=>i(d)&&s.has($e(d.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(n[d]===void 0||a(d))).sort();return[...new Set([...c,...k])]}function T(e,t,n){let r=se(e,t.filter(o=>L(e,{path:o},{purpose:"override",route:"github"}).admitted),{root:n});return qe(r)}function qe(e){let t=new Map(e.scoped.map(o=>[o.path,o.relativePath])),n=(o,s,i=!1)=>e.files.find(a=>a.role===o&&a.kind!=="background"&&a.preferred!==!1&&(!s||a.kind===s)&&(!i||a.preferred))?.path??null,r=(o,s,i=!1)=>e.files.filter(a=>a.role===o&&(!s||a.kind===s)&&a.ownerPath!==void 0===i).map(a=>a.path).sort();return{scoped:e.scoped.map(o=>o.path),stripRoot:o=>t.get(o)??o,configPath:n("marker"),promptPath:n("prompt","dedicated",!0),claudePath:n("prompt","fallback"),toolsPath:n("tool file","json"),toolsTsPath:n("tool file","sdk"),cliPath:n("tool file","cli"),mcpPath:n("MCP config",void 0,!0),registry:e.registry,soulPath:n("soul"),knowledgePath:n("knowledge"),subagentPaths:r("sub-agent"),skillPaths:r("skill"),skillNames:Object.fromEntries(e.files.filter(o=>o.role==="skill"&&o.name).map(o=>[o.path,o.name])),skillRefNames:Object.fromEntries(e.files.filter(o=>o.role==="reference"&&o.kind==="skill"&&o.name).map(o=>[o.path,o.name])),templatePaths:r("reference","template"),skillRefPaths:r("reference","skill"),subagentSkillPaths:r("skill",void 0,!0),subagentSkillRefPaths:r("reference","skill",!0),subagentSkillOwners:Object.fromEntries(e.files.filter(o=>o.ownerPath!==void 0).map(o=>[o.path,o.ownerPath]))}}function Q(e){return!!(e.promptPath||e.toolsPath||e.toolsTsPath||e.cliPath||e.mcpPath||e.soulPath||e.knowledgePath||e.subagentPaths.length||e.skillPaths.length)}function Me(e,t){return!!e.configPath||!!e.claudePath&&t==="prompt"||Q(e)}function Ge(e){return te(e,"CF_IMPORT_LAYOUTS")}function _t(e,t){return Ge(e)?[...new Set(t)].sort().flatMap(n=>{if(n.includes("\\")||/[:\0]/.test(n)||n.split("/").some(o=>!o||o==="."||o===".."))return[];let r=/^(?:(.*)\/)?\.claude-plugin\/plugin\.json$/i.exec(n);return r?[{folder:r[1]??"",path:n}]:[]}):[]}function Rt(e,t,n){let r=t.split("/");for(let o=0;o<r.length-2;o++)if(!(r[o].toLowerCase()!=="plugins"||!r[o+1])&&At(e,r.slice(o+2).join("/")))return r.slice(0,o+2).join("/");for(let o of[...n].sort((s,i)=>i.folder.length-s.folder.length)){let s=M(t,o.folder);if(s!==null&&At(e,s))return o.folder}return null}function At(e,t){return t.toLowerCase().startsWith(`${Oe}/`)&&pe.test(t)||!!(oe(e)&&t.toLowerCase().startsWith(`${vt}/`)&&ce(t)?.definition)}import{posix as me}from"node:path";function Ve(e,t=1){let n=new Set,r=[],o=e.replace(/{#[\s\S]*?#}|{%[-+]?\s*raw\s*[-+]?%}[\s\S]*?(?:{%[-+]?\s*endraw\s*[-+]?%}|$)/g,s=>s.replace(/[^\n]/g," "));for(let s of o.matchAll(/{%[-+]?\s*(include|extends|import|from)\s+(.+?)\s*[-+]?%}/g)){let i=s[2].match(/^(["'])([^"']+)\1(?:\s+(?:as\s+\w+|import\s+.+|ignore missing|with context|without context))?$/),a=t+e.slice(0,s.index).split(`
|
|
2
|
-
`).length-1;r.push({source:i?.[2]??s[2],span:{from:a,to:a},...i?{}:{reason:"dynamic"}})}for(let s of o.matchAll(/{{[-+]?\s*([\w]+)|{%[-+]?\s*(?:if|elif|for\s+\w+\s+in|set\s+\w+\s*=)\s+([\w]+)/g)){let i=s[1]??s[2];!["true","false","none"].includes(i.toLowerCase())&&!/^\d/.test(i)&&n.add(i)}return{variables:[...n],loaders:r}}function It(e){let t=e.split(`
|
|
3
|
-
`),n=[],r=[],o=(s,i,a)=>{let c=new Set;for(let k of ut(s.join(`
|
|
4
|
-
`))){let d=a?`${a}.${k.key}`:k.key,f={from:i+k.span.from,to:i+k.span.to},l=s.slice(k.span.from-1,k.span.to);c.has(k.key)&&r.push({key:d,span:f,reason:"duplicate"}),c.add(k.key);let m=l[0].slice(l[0].indexOf(":")+1).trim();if(!m||m.startsWith("#")){let y=l.slice(1),g=y.find(b=>b.trim()&&!b.trimStart().startsWith("#"))?.match(/^ */)?.[0].length;if(g){o(y.map(b=>b.slice(g)),f.from,d);continue}}let p=mt(l.join(`
|
|
5
|
-
`))?.[k.key],h=typeof p=="string"?p:null,u=d.endsWith("_template");(u&&h===null||/^[!&*]/.test(m))&&r.push({key:d,span:f,reason:"invalid"}),n.push({key:d,span:f,text:t.slice(f.from-1,f.to).join(`
|
|
6
|
-
`),value:h,...u&&h!==null?Ve(h,f.from+(/^[|>]/.test(m)?1:0)):{variables:[],loaders:[]}})}};o(t,0,"");for(let s of r.filter(i=>i.reason==="duplicate"))for(let i of n.filter(a=>a.key===s.key||a.key.startsWith(`${s.key}.`)))i.value=null;return{fields:n,unresolved:r}}function Nt(e){return te(e,"CF_IMPORT_LAYOUTS")}function Tt(e,t){if(!Nt(e))return[];let n=new Set(t),r=[];for(let o of[...n].sort()){let s=o.match(/^((?:[^/]+\/)*?)(?:src\/)?minisweagent\/agents\/default\.py$/);if(!s)continue;let i=o.slice(0,-18),a=`${i}/config`,c=`${a}/__init__.py`,k=`${i}/run/mini.py`;if(!n.has(c)||!n.has(k))continue;let d=[...n].filter(f=>M(f,a)!==null&&/\.ya?ml$/.test(f)).sort();d.length&&r.push({folder:s[1].replace(/\/$/,""),configFolder:a,agentPath:o,loaderPath:c,runnerPath:k,configs:d,templates:[...n].filter(f=>M(f,a)!==null&&/\.(?:j2|jinja2?)$/.test(f)).sort()})}return r}function En(e,t){let n=R(e.agentPath,t[e.agentPath]??"","py").toks,r=R(e.loaderPath,t[e.loaderPath]??"","py").toks,o=R(e.runnerPath,t[e.runnerPath]??"","py").toks;if(!["system_template","instance_template"].every(i=>n.some((a,c)=>$(a,i)&&F(n[c-1],".")))||!r.some((i,a)=>$(i,"safe_load")&&F(r[a+1],"("))||!r.some((i,a)=>$(i,"read_text")&&F(r[a+1],"("))||!o.some((i,a)=>$(i,"get_config_from_spec")&&F(o[a+1],"("))||!o.some((i,a)=>$(i,"get_agent")&&F(o[a+1],"("))||!o.some((i,a)=>$(i,"get")&&F(o[a+1],"(")&&o[a+2]?.value==="agent"))return null;let s=o.flatMap((i,a)=>{if(!$(i,"DEFAULT_CONFIG_FILE")||!F(o[a+1],"="))return[];let c=o.slice(a+2).filter(k=>k.line===i.line);return c.flatMap((k,d)=>$(k,"builtin_config_dir")&&F(c[d+1],"/")&&c[d+2]?.kind==="string"?[me.join(e.configFolder,c[d+2].value)]:[])});return s.length===1?s[0]:null}function Dt(e,t,n,r){let o={variants:[],selectedPaths:[],fields:[],model:null,loaded:[],unresolved:[],edges:[]};if(!Nt(e))return o;let s=En(t,n);if(!s)return o.unresolved.push({path:t.runnerPath,source:"config",reason:"dynamic"}),o;let i=new Map,a=new Set(Object.keys(n)),c=l=>{let m=L(e,{path:l,text:n[l],size:n[l]===void 0?void 0:Buffer.byteLength(n[l])},{purpose:"pointer",route:"github",root:t.configFolder,listing:a,managedFiles:n});return m.admitted||i.set(l,m.reason),m.admitted},k=new Map([...new Set([...t.configs,...r??[]])].flatMap(l=>c(l)&&Object.hasOwn(n,l)?[[l,It(n[l])]]:[]));o.variants=t.configs.map(l=>({path:l,fields:(k.get(l)?.fields??[]).map(m=>({...m,path:l}))})),o.selectedPaths=r?[...r]:[s];let d=new Map;for(let l of o.selectedPaths){if(M(l,t.configFolder)===null){o.unresolved.push({path:l,source:l,reason:"out-of-scope"});continue}let m=k.get(l);if(!m){o.unresolved.push({path:l,source:l,reason:i.get(l)??"missing"});continue}o.unresolved.push(...m.unresolved.map(p=>({path:l,source:p.key,span:p.span,reason:p.reason})));for(let p of m.fields)if(/^(?:agent|model|environment)(?:\.|$)/.test(p.key)){for(let h of d.keys())(h.startsWith(`${p.key}.`)||p.key.startsWith(`${h}.`))&&d.delete(h);d.set(p.key,{...p,path:l})}}o.fields=[...d.values()],o.model=d.get("model.model_name")?.value??null;let f=new Set;for(let l of o.fields){let m=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:u,facts:y}=h;if(h.next===0)for(let P of y.variables)o.unresolved.push({path:u,source:P,reason:"runtime-variable"});if(h.next>=y.loaders.length){m.delete(u),p.pop();continue}let g=y.loaders[h.next++],b=me.normalize(me.join(me.dirname(u),g.source)),w=g.reason??(me.isAbsolute(g.source)||M(b,t.configFolder)===null?"out-of-scope":c(b)?m.has(b)?"cycle":Object.hasOwn(n,b)?null:"missing":i.get(b));if(w){o.unresolved.push({path:u,source:g.source,...g.reason?{}:{target:b},span:g.span,reason:w});continue}o.edges.push({from:u,to:b,span:g.span}),!f.has(b)&&(f.add(b),o.loaded.push({path:b}),m.add(b),p.push({path:b,facts:Ve(n[b]),next:0}))}}return o}var Cn=new Set([...Pt,bt.soul].map(e=>e.toLowerCase())),Ln=["templates","default_prompts","prompts/default","docs","evals","benchmarks"],jn=["tests","__tests__","fixtures","test_data","evals","benchmarks","templates","default_prompts","prompts/default","docs"];function zt(e,t=""){return e===t?null:`folder:${e}`}function Wo(e,t,n){let r=Ee(e,t,n),o=Te(n),s=t.filter(m=>!Z(e,m,o)),i=s.filter(m=>r.ownerOf(m)?.key===null),a=T(e,i,o),c=Q(a)||!!a.configPath,k=se(e,i,{root:o}).files.filter(m=>m.role!=="reference"&&m.kind!=="background"),d=new Set(k.map(m=>m.relativePath)),f=k.flatMap(m=>m.role==="sub-agent"?[m.relativePath.slice(0,-3)]:m.role==="skill"?[m.relativePath.slice(0,m.relativePath.lastIndexOf("/"))]:[]),l=new Map(r.scopes.map(m=>[m.folder,{scope:m,paths:[]}]));for(let m of[...new Set(s)]){let p=r.ownerOf(m);if(!p)continue;let h=M(m,o),u=h.split("/");if(p.key===null&&c&&u.length>1&&!d.has(h)&&!f.some(y=>M(h,y)!==null)){let y=u.slice(0,-1).findIndex((b,w)=>![...d].some(P=>P.startsWith(`${u.slice(0,w+1).join("/")}/`))),g=De(u.slice(0,y<0?-1:y+1).join("/"),o);l.has(g)||l.set(g,{scope:{key:zt(g,o),folder:g,kind:"folder"},paths:[]}),p=l.get(g).scope}l.get(p.folder).paths.push(m)}return[...l.values()].sort((m,p)=>m.scope.folder<p.scope.folder?-1:m.scope.folder>p.scope.folder?1:0).map(({scope:m,paths:p})=>{let h=T(e,p,m.folder),u=r.scopes.includes(m);return{scope:m,paths:p,convention:u&&(!!m.managed||!!m.miniSwe||m.kind==="crew"||Q(h)),markerPath:u?h.configPath:null}})}function Ee(e,t,n){let r=Te(n),o=H(e),s=_t(e,t),{scopes:i,skipped:a,pluginFolders:c}=o?An(e,t,r,s):{scopes:[{key:null,folder:r,kind:"root"}],skipped:[],pluginFolders:[]},k=l=>Bt(i,l),d=t.filter(l=>Z(e,l,r)||o&&k(l)&&xe(e,l,c)),f=o?t.filter(l=>{let m=k(l);return m?.kind==="crew"&&M(l,m.folder)?.toLowerCase().startsWith("tools/")}):[];return{scopes:i,skipped:a,ownerOf:k,pluginFolders:c,ignoredPaths:d,ignoredImportPaths:f,...s.length?{pluginDeclarations:s.filter(l=>c.includes(l.folder))}:{}}}function Bt(e,t){return e.findLast(n=>M(t,n.folder)!==null)??null}function An(e,t,n,r){let o=[...new Set(t)].filter(f=>!xe(e,f)).sort().flatMap(f=>{let l=M(f,n);return l===null?[]:[{path:f,relativePath:l}]}),s=[],i=new Map,a=o.filter(f=>!Z(e,f.path,n)).map(f=>f.path);for(let f of ve(e,a))i.set(f.folder,f.agents.map(l=>({path:l,plugin:!1,crew:!1,checkPath:`${f.folder}/`,managed:f})));for(let f of Tt(e,a))i.set(f.folder,[...i.get(f.folder)??[],{path:f.agentPath,plugin:!1,crew:!1,checkPath:`${f.folder}/`,miniSwe:f}]);for(let{path:f,relativePath:l}of o){let m=l.split("/"),p=Cn.has(m.pop().toLowerCase())&&m.length>0,h=Rt(e,f,r);h===n&&!Z(e,f,n)&&!s.includes(n)&&s.push(n);let u=h!==null&&h!==n&&!!M(`${h}/`,n),y=l.toLowerCase()==="config/agents.yaml"||l.toLowerCase().endsWith("/config/agents.yaml");if(!p&&!u&&!y)continue;let g=y?f.slice(0,-18).replace(/\/$/,""):u?h:De(m.join("/"),n),b=i.get(g)??[];b.push({path:f,plugin:u,crew:y,checkPath:u?`${g}/`:f}),i.set(g,b)}let c=dt(e),k={settings:e,folder:n,scoped:o,candidates:i,rootPlugins:s,excludedFolders:c?Ln:jn},d=Wt(k,new Set);if(c){let f=[...new Set(d.accepted.map(u=>u.folder))].filter(u=>u!==n),l=o.filter(u=>!Z(e,u.path,n)&&!f.some(y=>M(u.path,y)!==null)).map(u=>u.path),m=se(e,l,{root:n,folderAgentsFound:f.length>0}),p=Kt(e,m,f.length>0)?[{path:`${n}/`,checkPath:`${n}/`}]:[],h=ct([...d.accepted,...p],u=>u.checkPath,{root:n,listing:new Set(o.map(u=>u.path))});if(d.accepted.some(u=>h(u.checkPath))){let u=new Set([...i.values()].flat().filter(y=>h(y.checkPath)).map(y=>y.path));d=Wt(k,u)}}return d.skipped.sort((f,l)=>f.path<l.path?-1:f.path>l.path?1:0),{scopes:d.scopes,skipped:d.skipped,pluginFolders:d.pluginFolders}}function Wt({settings:e,folder:t,scoped:n,candidates:r,rootPlugins:o,excludedFolders:s},i){let a=[{key:null,folder:t,kind:"root"}],c=[],k=[...o],d=[],f=new Map;for(let l of[...r.keys()].sort()){let m=r.get(l),p=Bt(a,m[0].path),h=f.get(p.folder)??_n(n.map(S=>S.path),p.folder);f.set(p.folder,h);let u=[];for(let S of m){let{path:v,checkPath:x}=S;if(xe(e,v,k))continue;let _=Z(e,v,t)?"excluded-folder":l===t?null:i.has(v)?"excluded-folder":Rn(M(x,t),M(x,p.folder),h,s);_?c.push({path:v,reason:_}):(u.push(S),d.push({path:v,folder:l,checkPath:x}))}if(!u.length)continue;let y=u.find(S=>S.crew),g=zt(l,t),b=y?{key:g,folder:l,kind:"crew",agentsPath:y.path,tasksPath:n.find(S=>M(S.path,l)?.toLowerCase()==="config/tasks.yaml")?.path??null}:{key:g,folder:l,kind:"folder"},w=m.find(S=>S.managed)?.managed;w&&(b.managed=w);let P=m.find(S=>S.miniSwe)?.miniSwe;P&&(b.miniSwe=P),l===t?a[0]=b:a.push(b),u.some(S=>S.plugin)&&!k.includes(l)&&k.push(l)}return{scopes:a,skipped:c,pluginFolders:k,accepted:d}}function ue(e,t,n,r={}){let o=Ee(e,t,n),{scopes:s,ownerOf:i,ignoredPaths:a}=o,c=new Set(a),k=new Map(s.map(h=>[h,[]]));for(let h of t){if(c.has(h))continue;let u=i(h);u&&k.get(u).push(h)}let d=s.map(h=>se(e,k.get(h),{root:h.folder,mode:r.mode,folderAgentsFound:h.key===null&&(s.length>1||h.kind==="crew")})),f=(h,u)=>Kt(e,h,s[u].key===null&&(s.length>1||s[u].kind==="crew")),l=s.length===1?d:d.filter((h,u)=>s[u].managed||s[u].miniSwe||s[u].kind==="crew"||f(h,u)),m=!l.length||l.some(h=>{let u=d.indexOf(h);return s[u].managed||s[u].miniSwe||s[u].kind==="crew"&&!f(h,u)?!1:!h.registry&&(!h.files.some(y=>y.role==="prompt")||!h.files.some(y=>y.role==="tool file"))}),p=d.flatMap((h,u)=>{let y=s[u];if(y.miniSwe)return[...h.files,...[...y.miniSwe.configs,...y.miniSwe.templates,y.miniSwe.agentPath,y.miniSwe.loaderPath,y.miniSwe.runnerPath].map(w=>({path:w,relativePath:M(w,y.folder),role:"knowledge",kind:"entry"}))];if(y.managed)return[...y.managed.agents,...y.managed.configs].flatMap(w=>{let P=ce(M(w,y.folder))?.definition;if(P&&(r.mode==="core"||!oe(e)))return[];let S=y.managed.agents.includes(w);return[{path:w,relativePath:M(w,y.folder),role:S?"prompt":P?"skill":"knowledge",kind:S?"entry":P?"skill":"json"}]});let g=(o.pluginDeclarations??[]).filter(w=>w.folder===y.folder).map(w=>({path:w.path,relativePath:M(w.path,y.folder),role:"marker",kind:"entry"}));if(y.kind!=="crew")return[...h.files,...g];let b=[{path:y.agentsPath,relativePath:M(y.agentsPath,y.folder),role:"prompt",kind:"entry"}];return y.tasksPath&&b.push({path:y.tasksPath,relativePath:M(y.tasksPath,y.folder),role:"knowledge",kind:"entry"}),[...h.files,...b,...g]});return{...o,files:p,needsExtraction:m}}function Kt(e,t,n){let r=qe(t),o=Se({codeAgentsFound:!1,folderAgentsFound:n,otherDefinitions:Q(r),codeImportV2:G(e)});return Me(r,o)}function _n(e,t){let n=new Set;for(let r of e){let o=M(r,t);o!==null&&pe.test(o)&&n.add(o.slice(0,-3).toLowerCase())}return n}function Rn(e,t,n,r){let o=e.toLowerCase();if(r.some(a=>`/${o}`.includes(`/${a}/`)))return"excluded-folder";let s=o.slice(0,o.lastIndexOf("/"));if(ce(e,{nested:!0})||xt.some(a=>s===a||s.endsWith(`/${a}`)))return"skill-folder";if(`/${o}`.includes(`/${St}/${Oe}/`)||pe.test(t))return"sub-agent-folder";let i=t.toLowerCase().split("/");return i.some((a,c)=>n.has(i.slice(0,c).join("/")))?"sub-agent-folder":null}function Ut(e){return te(e,"CF_IMPORT_MANIFEST")}function Ce(e,t,n,r){let o=A(e);if(!o)return[];let s=R(e,t,o),{toks:i}=s,a=fe(s),c=Y(s,{includeMembers:!0}),k=X(s,"default");k?.name==="default"&&c.push(k),c.sort((p,h)=>p.from-h.from||h.to-p.to);let d=[],f=Dn(s),l=Tn(s,r),m=p=>c.filter(h=>h.params!==null&&h.from<p&&p<h.to).at(-1)?.name??null;for(let p of Mt(e,t,o,!0)){let h=a.find(b=>b.source===p.source&&b.names.join("\0")===p.names.join("\0")),u=h?.names.map(b=>({name:b,imported:h.defaultName===b?"default":h.renamed?.[b]??b}))??Nn(s,p.source),y=h?.line??i.find(b=>b.kind==="string"&&b.value===p.source)?.line??1,g=In(s,y);for(let{name:b,imported:w}of u){let P=Ke(e,p.source,[w],o,n,!0)??null,S={from:e,to:P,symbol:b,imported:w,source:p.source,...P?{}:{reason:p.source.startsWith(".")?"missing":"external"}},v=i.some((C,E)=>E>g&&$(C,b)&&ee(i,E+1))||c.some(C=>C.name===b&&C.from>g&&!c.some(E=>E.from<C.from&&C.from<E.to&&(E.params!==null||E.kind==="class")));if(v)continue;let x=Jt(s,b);for(let C of x)d.push({...S,symbol:C,kind:"import",usage:"reexport",within:null,span:{from:y,to:y}});let _=h?i.flatMap((C,E)=>!v&&$(C,b)&&E>g&&!["def","function","class"].includes(i[E-1]?.text??"")&&(!F(i[E-1],".")||F(i[E-2],".")&&F(i[E-3],"."))&&!c.some(I=>I.from<E&&E<I.to&&I.params?.includes(b))?[E]:[]):[];!_.length&&!x.length&&d.push({...S,kind:"import",usage:"reexport",within:null,span:{from:y,to:y}});for(let C of _){let E=f.find(J=>J.from<=C&&C<J.to),I=!l||l.from<=(E?.at??C)&&(E?.at??C)<l.to,D=E&&!I&&(E.kind!=="tool-registration"||l?.to===0),re=E&&(I||D)?E.kind:"import";d.push({...S,...D?{reason:"unlinked"}:{},kind:re,usage:Ue(i,C,s)?"call":"reference",within:m(C),span:{from:Math.min(i[E?.at??C].line,i[C].line),to:Math.max(i[E?.at??C].endLine,i[C].endLine)}})}}if(!u.length){let b=Ke(e,p.source,[],o,n,!0)??null;d.push({from:e,to:b,kind:"import",symbol:"*",imported:"*",source:p.source,usage:"reexport",within:null,span:{from:y,to:y},...b?{}:{reason:p.source.startsWith(".")?"missing":"external"}})}}for(let p=0;p<i.length;p++)!$(i[p])||!["import","import_module","require"].includes(i[p].text)||!F(i[p+1],"(")||i[p+2]?.kind==="string"&&F(i[p+3],")")||d.push({from:e,to:null,kind:"import",symbol:"*",imported:"*",source:"",usage:"call",within:m(p),reason:"dynamic",span:{from:i[p].line,to:i[p].endLine}});return d.filter((p,h)=>d.findIndex(u=>JSON.stringify(u)===JSON.stringify(p))===h)}function In(e,t){let{toks:n}=e,r=n.findIndex(o=>o.line===t);for(let o=r;o<n.length;o++){if(e.lang==="py"&&n[o].line>t)return o-1;if(F(n[o],";")||e.lang==="js"&&n[o].kind==="string")return o}return n.length-1}function Nn(e,t){let{toks:n}=e,r=[];for(let o=0;o<n.length;o++){if(!$(n[o],"export"))continue;let s=o+1;if(!F(n[s],"{"))continue;let i=N(n,s);!$(n[i+1],"from")||n[i+2]?.value!==t||r.push(...U(n,s).flatMap(a=>$(n[a.from])?[{name:n[a.to-1].text,imported:n[a.from].text}]:[]))}return r}function Jt(e,t){let{toks:n}=e,r=[];for(let o=0;o<n.length;o++)if(!(!$(n[o],"export")||!F(n[o+1],"{"))&&!$(n[N(n,o+1)+1],"from"))for(let s of U(n,o+1))$(n[s.from],t)&&r.push(n[s.to-1].text);return r}function X(e,t){let n=Y(e),{toks:r}=e;if(t==="default"){let s=r.findIndex((i,a)=>$(i,"default")&&$(r[a-1],"export"));if(s>=0){let i=s+1;$(r[i],"async")&&i++;let a=$(r[i],"function"),c=a?i+1:i;if($(r[c])&&(t=r[c].text),F(r[c],"(")){let k=N(r,c),d=a?k+1:k+3;if(a||F(r[k+1],"=")&&F(r[k+2],">")){let f=F(r[d],"{")?N(r,d)+1:r.findIndex((l,m)=>m>=d&&F(l,";"));return{name:"default",line:r[i].line,from:i,to:f<0?r.length:f,params:U(r,c).map(l=>$(r[l.from])?r[l.from].text:null),kind:"function"}}}}}let o=n.find(s=>s.name===t);if(o)return o;for(let s of n)if(Jt(e,s.name).includes(t))return s;return null}function Tn(e,t){if(!t||t.path!==e.path)return null;let{toks:n}=e,r=new Set([t.symbol]);for(let c of fe(e))for(let k of c.names)(c.renamed?.[k]??k)===t.symbol&&r.add(k);let o=new Map;t.promptPath===e.path&&t.promptStart!==void 0&&o.set(t.promptStart,t.line??1);let s=Ot(e,[],o).filter(({site:c})=>(t.line===void 0||c.line===t.line)&&(c.value?.kind==="identifier"&&r.has(c.value.text)||c.value?.siteStart!=null&&c.value.siteStart===t.promptStart)),i=s.length===1?s[0].valueAt:void 0,a=[];for(let c=0;c<n.length;c++){if(!Ue(n,c,e))continue;let k=N(n,c+1);(t.callStart!==void 0?n[c].start===t.callStart:i!==void 0?c<i&&i<k:t.line!==void 0&&n[c].line<=t.line&&(n[k]?.endLine??0)>=t.line)&&a.push({from:c,to:k+1})}return i!==void 0||t.callStart!==void 0?a.at(-1)??{from:0,to:0}:a.length===1?a[0]:{from:0,to:0}}function Dn(e){let{toks:t}=e,n=[],r=(o,s,i)=>{if(s&&(n.push({...s,at:o,kind:i}),s.to===s.from+1&&$(t[s.from]))){let a=t.flatMap((c,k)=>$(c,t[s.from].text)&&F(t[k+1],"=")?[k+2]:[]);a.length===1&&F(t[a[0]],"[")&&n.push({from:a[0],to:N(t,a[0])+1,at:o,kind:i})}};for(let o=0;o<t.length;o++){let s=t[o].kind==="string"?t[o].value:t[o].text;if(["tools","state_schema","context_schema","config_schema","model_config","llm_config"].includes(s)&&(F(t[o+1],"=")||F(t[o+1],":"))){let a=o+2,c=F(t[a],"[")?N(t,a)+1:a+1;r(o,{from:a,to:c},s==="tools"?"tool-registration":"config")}if(!F(t[o+1],"("))continue;let i=U(t,o+1);["add_node","addNode"].includes(s)&&r(o,i[1],"graph-node"),["StateGraph"].includes(s)&&r(o,i[0],"config"),["bind_tools","bindTools","ToolNode"].includes(s)&&r(o,i[0],"tool-registration")}return n}import{posix as he}from"node:path";function Gt(e){return[...e].filter(t=>he.basename(t)==="langgraph.json")}function Ye(e,t,n,r={}){if(he.basename(e)==="langgraph.json")return Wn(e,t,n,r.root);if(A(e)!=="py")return[];let o=R(e,t,"py"),{toks:s}=o,i=Y(o),a=fe(o),c=r.root?`${r.root}/llm_config.yaml`:"llm_config.yaml",k=[];for(let d of a.filter(f=>f.source==="chainlite"))for(let f of d.names){if((d.renamed?.[f]??f)!=="llm_generation_chain"||a.filter(g=>g.names.includes(f)).length!==1)continue;let l=s.findIndex(g=>g.line===d.line),m=s.findIndex((g,b)=>b>l&&(g.line>d.line||F(g,";"))),p=m<0?s.length:m;if(s.some((g,b)=>b>=p&&$(g,f)&&!F(s[b+1],"("))||i.some(g=>g.name===f)||s.some((g,b)=>$(g,"import")&&F(s[b+1],"*")))continue;let h=s.flatMap((g,b)=>b>=p&&$(g,f)&&F(s[b+1],"(")&&!F(s[b-1],".")&&!i.some(w=>w.from<b&&b<w.to&&w.params?.includes(f))?[b]:[]),u=r.call?.path===e?r.call:void 0,y=h.filter(g=>u?.callStart!==void 0?s[g].start===u.callStart:u?.line===void 0||s[g].line===u.line);for(let g of h){let b=N(s,g+1),w=i.filter(P=>P.params!==null&&P.from<g&&g<P.to).at(-1)?.name??null;k.push({from:e,to:n.has(c)?c:null,kind:"config",symbol:f,imported:"*",source:c,usage:"call",within:w,span:{from:s[g].line,to:s[Math.min(b,s.length-1)].endLine},...n.has(c)?u&&(y.length!==1||y[0]!==g)?{reason:"unlinked"}:{}:{reason:"missing"}})}}return k}function Wn(e,t,n,r){let o=()=>[{from:e,to:null,kind:"graph-node",symbol:"graphs",imported:"*",source:"",usage:"reference",within:null,span:{from:1,to:Math.max(1,t.split(`
|
|
7
|
-
`).length)},reason:"dynamic"}],s;try{s=JSON.parse(t)}catch{return o()}if(!qt(s)||!qt(s.graphs))return[];let i=s.graphs,a=R(e,t,"js"),{toks:c}=a,k=U(c,0).filter(f=>c[f.from]?.value==="graphs");if(k.length!==1)return o();let d=U(c,k[0].from+2);return d.map(f=>{let l=c[f.from].value,m=i[l],p=d.filter(g=>c[g.from].value===l).length!==1,h=typeof m=="string"?/^(.+):([A-Za-z_$][\w$]*)$/.exec(m):null,u=null,y;if(p||!h)y="dynamic";else if(/^[a-z][a-z\d+.-]*:\/\//i.test(h[1])||!h[1].includes("/")&&!A(h[1]))y="external";else{let g=he.normalize(he.join(he.dirname(e),h[1]));!h[1].startsWith("/")&&!h[1].includes("\\")&&!/^[A-Za-z]:/.test(h[1])&&g!==".."&&!g.startsWith("../")&&M(g,r)!==null&&A(g)&&n.has(g)?u=g:y="missing"}return{from:e,to:u,kind:"graph-node",symbol:l,imported:h?.[2]??"*",source:typeof m=="string"?m:"",usage:"reference",within:l,span:{from:c[f.from].line,to:c[f.to-1].endLine},...y?{reason:y}:{}}})}function Vt(e,t,n,r){let o=A(e);if(!o)return[];let s=R(e,t,o),{toks:i}=s,a=X(s,n);if(!a||a.params!==null)return[];let c=i.findIndex((y,g)=>g>=a.from&&g<a.to&&ee(i,g));if(c<0)return[];let k=$(i[c+1])&&F(i[c+2],".")&&$(i[c+3],"compile"),d=k?i[c+1].text:n,f=k?X(s,d):a;if(!f||!i.slice(f.from,f.to).some(y=>$(y,"StateGraph")))return[];if([n,d].some(y=>i.filter((g,b)=>$(g,y)&&ee(i,b+1)).length!==1))return[];let l=Y(s),m=y=>l.filter(g=>g.params!==null&&g.from<y&&y<g.to).map(g=>g.from).join(","),p=[{from:f.from,to:f.to}];for(let y=0;y<i.length;y++)$(i[y],d)&&F(i[y+1],".")&&["add_node","addNode"].includes(i[y+2]?.text)&&F(i[y+3],"(")&&m(y)===m(f.from)&&p.push({from:y,to:N(i,y+3)+1});let h=[];for(let y of p)for(let g=y.from;g<y.to;g++){if(!["add_node","addNode"].includes(i[g]?.text)||!F(i[g+1],"(")||m(g)!==m(f.from))continue;let b=U(i,g+1)[1];if(!b||b.to!==b.from+1||!$(i[b.from]))continue;let w=i[b.from].text;!Xt(s,w)||i.some((S,v)=>$(S,w)&&ee(i,v+1))||h.push({from:e,to:e,kind:"graph-node",symbol:w,imported:w,source:w,usage:"reference",within:null,span:{from:i[g].line,to:i[b.from].endLine}})}return[...Ce(e,t,r).filter(y=>(y.kind==="config"||y.kind==="graph-node")&&p.some(g=>i.slice(g.from,g.to).some(b=>$(b,y.symbol)&&b.line>=y.span.from&&b.line<=y.span.to))),...h].filter((y,g,b)=>b.findIndex(w=>JSON.stringify(w)===JSON.stringify(y))===g)}function Yt(e,t,n,r){let o=A(e);if(!o||r?.path!==e)return!1;let s=R(e,t,o),i=Xt(s,n);if(!i)return!1;let a=(c,k)=>r.callStart!==void 0?s.toks[c].start<=r.callStart&&s.toks[k-1].end>r.callStart:r.line!==void 0&&s.toks[c].line<=r.line&&s.toks[k-1].endLine>=r.line;return a(i.from,i.to)&&(r.callStart!==void 0||Y(s).filter(c=>c.params!==null&&a(c.from,c.to)).length===1)}function Xt(e,t){let n=X(e,t);return n&&n.params!==null&&Y(e).filter(r=>r.name===n.name).length===1?n:null}function qt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ge(e,t){if(!ne(e))return null;let n=new Set(t.paths),r=ze(e,t),o=new Set(t.skillPaths),s=new Set(t.referencePaths),i=g=>Object.hasOwn(t.files,g)?Buffer.byteLength(t.files[g]):t.sizes?.get(g),a=t.selected??t.skillPaths.filter(g=>Object.hasOwn(t.files,g)).map(g=>({path:g,size:i(g)})),c=[...new Map(a.filter(g=>!s.has(g.path)||o.has(g.path)).map(g=>[g.path,g])).values()],k=new Set(c.map(g=>g.path)),d=c.filter(g=>o.has(g.path)),f=d.length,l=V.conventionImport.skillBytes-d.reduce((g,b)=>g+(i(b.path)??b.size),0),m=H(e)?V.codeAgent.importBytes-c.reduce((g,b)=>g+(i(b.path)??b.size),0):1/0,p=new Map(d.map(g=>[g.path,null])),h=(g,b=!1)=>{if(p.has(g))return;let w=i(g),P=L(e,{path:g,size:w,text:t.files[g]},{...t.admission,purpose:"skill",route:"github",root:t.root,listing:n,managedFiles:t.files}),S=k.has(g)?0:w,v=P.admitted?w===void 0?"missing":f>=V.conventionImport.skillFiles?"allowance":w>l||S>m?"total":null:P.reason;p.set(g,v),(b||!v)&&f++,v||(l-=w,m-=S)};for(let g of s)h(g,!0);let u=[...new Set(t.skillPaths)].sort().filter(g=>Object.hasOwn(t.files,g)).map(g=>{let b={ownerPath:g,files:[],cycles:[],unresolved:[],refused:[]},w=new Set([g]);for(let P of r.references.filter(S=>S.ownerPath===g)){if(!w.has(P.fromPath))continue;h(P.path);let S=p.get(P.path);if(S){b.refused.push({path:P.path,reason:S});continue}w.add(P.path);let v=b.files.find(x=>x.path===P.path);v||(v={path:P.path,evidence:[],sharedOwners:[]},b.files.push(v)),v.evidence.push(P)}return b.cycles=r.cycles.filter(P=>P.ownerPath===g&&w.has(P.fromPath)),b.unresolved=r.unresolved.filter(P=>P.ownerPath===g&&w.has(P.fromPath)),b.refused=ae(b.refused),b}),y=new Map;for(let g of u)for(let b of g.files)y.set(b.path,[...y.get(b.path)??[],g.ownerPath]);for(let g of u)for(let b of g.files)b.sharedOwners=y.get(b.path);return u}var Qt="model call";function Zt(e,t,n,r){let o=Lt(e,t.ownPaths,n,r,t.toolCall);return{tools:o.tools.map(s=>({tool:s,from:o.from[s.name]})),toolWarnings:o.warnings}}function Xe(e=new Map,t){return{left:Math.max(0,V.codeAgent.importBytes-[...e.values()].reduce((n,r)=>n+r,0)),chosen:new Set([...e.keys()].filter(n=>!t?.has(n))),...t?{replacementBytes:t}:{}}}function zn(e,t){return e.modelId??(t.length===1?t[0]:null)}function Fs(e,t){return Bn(e,zn(e,t))}function Bn(e,t){let{prompt:n,link:r}=e,o=[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 i of e.alsoLoads??[])o.push({role:"system prompt",label:"also loaded",path:i});r&&o.push({role:"code",label:Qt,path:r.callPath}),r?.wrapper&&o.push({role:"code",label:"model wrapper",path:r.wrapper.path}),t&&o.push({role:"code",label:"model setting",path:t.path}),e.shape&&o.push({role:"code",label:"answer shape",path:e.shape.path});let s=new Set;return o.filter(i=>!s.has(i.path)&&!!s.add(i.path))}function $s(e,t){let{prompt:n}=e,r=t[n.path]??"";return n.kind==="file"?r:r.split(`
|
|
8
|
-
`).slice(n.span.from-1,n.span.to).join(`
|
|
9
|
-
`)}function Ht(e,t,n){let{files:r,sizes:o,root:s,total:i=Xe()}=n,a=[...new Set([...t.ownPaths,...n.guides??[]])],c=[],k=new Set(a);a=a.filter(P=>{let S=L(e,{path:P},{purpose:"override",route:"github"});return S.admitted||c.push({path:P,reason:S.reason}),S.admitted});let d=[...o.keys()].filter(P=>{let S=L(e,{path:P},{purpose:"code-support",route:"github",root:s});return!S.admitted&&!k.has(P)&&c.push({path:P,reason:S.reason}),S.admitted}),f=Object.fromEntries(a.filter(P=>r[P]!==void 0).map(P=>[P,r[P]])),l=Et(f,d).filter(P=>!a.includes(P)),m=Object.fromEntries([...a,...l].filter(P=>r[P]!==void 0).map(P=>[P,r[P]])),p=Zt(e,{ownPaths:a,toolCall:t.toolCall},m,!0).tools.map(({tool:P})=>P.name),h=new Set(jt(p,l,r,d,e)),u=en(e,a,{...n,total:i});for(let P of new Set([...a,...l,...h]))u.take(P,h.has(P)&&!a.includes(P));let{paths:y,skipped:g}=u,b=Object.fromEntries(y.filter(P=>r[P]!==void 0).map(P=>[P,r[P]])),w=Zt(e,t,b,!0);return{paths:y,skipped:g,refused:ae(c,u.refused),...w}}function en(e,t,{sizes:n,total:r=Xe()}){let o=[],s=[],i=[],a=V.codeAgent.extraBytes,c=0;return{paths:o,skipped:s,refused:i,take:(d,f,l=!1)=>{if(o.includes(d))return!0;let m=n.get(d),p=d===t[0],h=Math.max(0,(m??0)-(r.replacementBytes?.get(d)??0)),u=t.includes(d)||l?"pointer":"code-support",y=L(e,{path:d,size:m},{purpose:u,route:"github"});y.admitted||i.push({path:d,reason:y.reason});let g=m===void 0?"missing":y.admitted?!p&&m>a?"allowance":!r.chosen.has(d)&&(h>r.left||r.wholeBytesLeft!==void 0&&m>r.wholeBytesLeft)?"total":f&&c>=V.codeAgent.toolCodeFiles?"tool-limit":null:y.reason;return g?(s.push({path:d,reason:g}),!1):(p||(a-=m),f&&c++,r.chosen.has(d)||(r.left-=h,r.wholeBytesLeft!==void 0&&(r.wholeBytesLeft-=m),r.chosen.add(d)),o.push(d),!0)}}}function Ms(e,t,n){if(!Ut(e))return null;let r=n.scopes??Ee(e,[...n.sizes.keys()],n.root??void 0),o=n.total??Xe(),s=new Set(n.sizes.keys()),i=Gt(s).flatMap(f=>n.files[f]===void 0?[]:Ye(f,n.files[f],s,{root:n.root??void 0})),a=new Map(i.map(f=>[f,f.to&&n.files[f.to]!==void 0?Vt(f.to,n.files[f.to],f.imported,s):[]])),c=new Set(i.filter(f=>{let l=f.to&&A(f.to),m=f.to&&n.files[f.to];return l&&m!==void 0&&m!==null&&!X(R(f.to,m,l),f.imported)})),k=t.map(f=>{let l=[...new Set(f.ownFiles.map(v=>v.path))],m=en(e,l,{...n,total:o}),p={schemaVersion:1,agentId:f.id,scope:{...f.scope},files:[],edges:[],unresolved:[],refused:[]},h=f.ownFiles.map(v=>({path:v.path,symbol:null,role:v.role,evidence:null,span:v.span})),u=i.filter(v=>v.to!==null&&l.includes(v.to)),y=u.filter(v=>new Set(u.filter(x=>x.to===v.to).map(x=>x.imported)).size>1),g=i.filter(v=>!c.has(v)&&(u.includes(v)&&!f.toolCall&&!y.includes(v)||a.get(v).some(x=>{if(x.kind!=="graph-node"||!x.to||!l.includes(x.to)||!f.toolCall||f.toolCall.path!==x.to)return!1;let _=n.files[x.to];return _!==void 0&&Yt(x.to,_,x.imported,f.toolCall)})));p.unresolved.push(...u.filter(v=>!g.includes(v)).map(v=>({...v,reason:c.has(v)?"missing":"unlinked"})));for(let v of g)h.push({path:v.from,symbol:v.symbol,role:"config",evidence:v,explicit:!0});let b=new Set,w=new Map,P=new Set,S=new Set;for(let v=0;v<h.length;v++){let x=h[v],_=JSON.stringify([x.path,x.symbol,x.role]);if(b.has(_))continue;b.add(_);let C=r.ownerOf(x.path),E=L(e,{path:x.path},{purpose:l.includes(x.path)||x.explicit?"pointer":"code-support",route:"github",root:n.root}),I=E.admitted?!C||C.key!==f.scope.key||C.folder!==f.scope.folder?"out-of-scope":!l.includes(x.path)&&t.some(O=>O.id!==f.id&&O.ownFiles.some((z,le)=>z.path===x.path&&(le===0||z.label===Qt)))?"other-agent":null:E.reason;if(I){p.refused.push({path:x.path,reason:I});continue}let D=n.files[x.path],re=A(x.path),J=D!==void 0&&re?R(x.path,D,re):null,ie=J&&x.symbol?X(J,x.symbol):null,q=ie?.name??x.symbol;if(D!==void 0&&!w.has(x.path)){let O=i.filter(j=>j.from===x.path),z=[...O.length?O:Ye(x.path,D,s,{root:f.scope.folder,call:f.toolCall}),...[...S].filter(j=>j.to===x.path).flatMap(j=>a.get(j))];z.forEach(j=>P.add(j));let le=Ce(x.path,D,s,l.includes(x.path)?f.toolCall:void 0).flatMap(j=>z.some(B=>!B.reason&&B.kind===j.kind&&B.symbol===j.symbol&&B.span.from===j.span.from)?[]:g.some(B=>B.to===x.path)&&!l.includes(x.path)&&(j.kind==="config"||j.kind==="graph-node")&&!j.reason?[{...j,reason:"unlinked"}]:[j]);w.set(x.path,[...le,...z,...(n.links??[]).filter(j=>j.from===x.path)])}let at=w.get(x.path)??[];if(x.role==="code"&&x.evidence?.kind==="import"&&at.some(O=>O.reason==="external"&&O.usage==="call"&&(O.within===q||O.within===null)&&ft(O.source,re))){p.refused.push({path:x.path,reason:"provider-transport"});continue}let Fn=x.role==="tool"&&ie?.params!=null&&!l.includes(x.path);if(!m.take(x.path,Fn,x.explicit))continue;p.unresolved.push(...i.filter(O=>O.from===x.path&&(O.reason||c.has(O))).map(O=>c.has(O)?{...O,reason:"missing"}:O));let W=p.files.find(O=>O.path===x.path);W||(W={path:x.path,roles:[],spans:[],evidence:[],sharedOwners:[]},p.files.push(W)),W.roles.includes(x.role)||W.roles.push(x.role);let be=x.span??(J&&ie?{from:J.toks[ie.from].line,to:J.toks[ie.to-1].endLine}:void 0);if(be&&!W.spans.some(O=>O.from===be.from&&O.to===be.to)&&W.spans.push(be),x.evidence?W.evidence.push(x.evidence):W.evidence.push({kind:"entry",from:x.path,to:x.path,...x.span?{span:x.span}:{}}),D!==void 0)for(let O of at){let z=O.usage==="reexport"&&(O.symbol===q||O.symbol==="*"),le=O.usage==="call"&&O.within===q;if(!(O.kind!=="import"&&(q===null||O.within===q)||q!==null&&(z||le)||O.reason==="dynamic"&&(q===null||O.within===q)))continue;if(!O.to||O.reason){p.unresolved.push(O);continue}let B=g.includes(O);B&&(S.add(O),w.delete(O.to)),p.edges.push(O);let $n=O.kind==="tool-registration"?"tool":O.kind==="config"?"config":O.kind==="graph-node"?"workflow":z?x.role:"code";h.push({path:O.to,symbol:B?null:O.imported==="*"?x.symbol:O.imported,role:$n,evidence:O,explicit:P.has(O)})}}return p.refused.push(...ae(m.skipped,m.refused)),p.unresolved=p.unresolved.filter(v=>v.reason!=="unlinked"||!p.edges.some(x=>x.from===v.from&&x.to===v.to&&x.kind===v.kind&&x.symbol===v.symbol&&x.span.from===v.span.from)),p.unresolved=[...new Map(p.unresolved.map(v=>[JSON.stringify(v),v])).values()],p.refused=p.refused.filter((v,x,_)=>_.findIndex(C=>C.path===v.path&&C.reason===v.reason)===x),p}),d=new Map;for(let f of k)for(let l of f.files)d.set(l.path,[...d.get(l.path)??[],f.agentId]);for(let f of k)for(let l of f.files)l.sharedOwners=[...new Set(d.get(l.path))].sort();return k}import{basename as Vn}from"node:path";import{basename as Jn}from"node:path";var nn=/^[\w.*:/()-]+$/,on=/^(?:true|false|null|~|[-+]?(?:\d[\d_.eExXoObB+-]*|\.\d[\d_eE+-]*|\.inf|\.nan)|\d{4}-\d{1,2}-\d{1,2}(?:[Tt].*)?)$/i,je=e=>nn.test(e)&&!e.startsWith("*")&&!on.test(e);function Le(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 ye(e,t=!1,n=!1){let r=[],o="",s=0,i=-1,a=0,c=()=>{i>=0&&r.push([i,a]),i=-1};for(let k=0;k<e.length;k++){let d=e[k];if(o){o==='"'&&d==="\\"?k++:d===o&&(o==="'"&&e[k+1]==="'"?k++:o=""),a=k+1;continue}if(!n&&d==="#"&&(k===0||/\s/.test(e[k-1]))){if(!t)return c(),{spans:r,end:k,comment:e.slice(k)};let f=e.indexOf(`
|
|
10
|
-
`,k);k=f<0?e.length:f;continue}if(t&&d==="]"&&s===0)return c(),{spans:r,end:k,comment:""};if(d===","&&s===0){c();continue}/\s/.test(d)||(i<0&&(i=k),(d==='"'||d==="'")&&(i===k||s>0)?o=d:d==="("?s++:d===")"&&s>0&&s--,a=k+1)}if(t)throw new Error("Unclosed frontmatter tool list");return c(),{spans:r,end:e.length,comment:""}}function tn(e,t){let n=e.startsWith("["),r=ye(n?e.slice(1):e,n),o=(n?e.slice(1,r.end+1):e.slice(0,r.end)).trimEnd(),s=!n&&r.spans.length===1&&/^["']/.test(o)&&Le(o)!==o?o[0]:"",i=s?Le(o):n?e.slice(1,r.end+1):e.slice(0,r.end).trimEnd(),a=n?r.spans:ye(i,!1,!!s).spans,c=0,k=a.flatMap(([f,l],m)=>{let p=i.slice(f,l),h=Le(p),u=i.slice(c,f).replace(/[^\S\n]*#[^\n]*/g,""),y=n?i.slice(l,a[m+1]?.[0]??i.length):"",g=y.match(/[^\S\n]*#[^\n]*/g)?.join(`
|
|
11
|
-
`)??"";return c=l,h?[{name:h,raw:p,before:u,note:g,noteAfterComma:/^[^\S\n]*,/.test(y)}]:[]}),d=n?e.slice(r.end+2).split(`
|
|
12
|
-
`)[0]:e.slice(o.length);return{style:n?"flow":"comma",outerQuote:s,quote:k.find(f=>/^["']/.test(f.raw))?.raw[0]??"",prefix:"",suffix:d,head:(k[0]?.before??i).replace(/,/g,""),tail:k.length?i.slice(c).replace(/[^\S\n]*#[^\n]*/g,""):"",separator:k[1]?.before.replace(/#[^\n]*/g,"")??(i.includes(`
|
|
13
|
-
`)?`,
|
|
14
|
-
${i.match(/\n([^\S\n]*)/)[1]}`:", "),entries:k,first:t,last:t+e.slice(0,n?r.end+2:e.length).split(`
|
|
15
|
-
`).length-1,indent:" - ",blockComments:[]}}function Kn(e){let t=de(e),n=t?.raw.map(a=>a.replace(/\r$/,""))??null,r=[],o=[],s={},i=[];if(n)for(let a=0;a<n.length;a++){let c=/^([A-Za-z_][\w-]*\s*:[^\S\n]*)(.*)$/.exec(n[a]);if(!c||!/^tools\s*:/i.test(c[1]))continue;let k=ye(c[2]),d;c[2].startsWith("[")?d=tn(n.slice(a).join(`
|
|
16
|
-
`).slice(c[1].length),a):d=tn(c[2],a),d.prefix=c[1];let f=d.style==="flow"?ye(d.suffix).comment:k.comment;if(f&&(s[d.style==="flow"?d.last:a]=f),d.style==="flow")for(let l of d.entries)l.note&&i.push({tool:l.name,comment:l.note.trim()});if(!c[2].slice(0,k.end).trim()){d.style="block",d.suffix=c[2];for(let l=a+1;l<n.length;l++){if(!n[l].trim()||/^\s*#/.test(n[l])){/^\s+#/.test(n[l])&&d.blockComments.push(l);continue}let m=/^(\s*-\s+)(.*)$/.exec(n[l]);if(!m)break;let p=ye(m[2]),h=m[2].slice(0,p.end).trimEnd(),u=Le(h);d.indent=m[1],u&&d.entries.push({name:u,raw:h,before:"",note:"",noteAfterComma:!1,row:n[l]}),p.comment&&u&&i.push({tool:u,comment:p.comment}),o.push(l),d.last=l}d.quote=d.entries.map(l=>l.raw).find(l=>/^["']/.test(l))?.[0]??""}for(let l=a;l<=(d.style==="block"?a:d.last);l++)o.push(l);r.push(d),a=d.last}return{header:t,lists:r,tools:r.length?r.flatMap(a=>a.entries.map(c=>c.name)):null,lines:n,toolLines:o,toolComments:s,itemComments:i}}function sn(e){try{return Kn(e)}catch{let t=de(e);return{header:t,lists:[],tools:[],lines:t.raw.map(n=>n.replace(/\r$/,"")),toolLines:[],toolComments:{},itemComments:[],error:"Unclosed frontmatter tool list"}}}function Un(e){let{tools:t,lines:n,toolLines:r,toolComments:o,itemComments:s,error:i}=sn(e);return{tools:t,lines:n,toolLines:r,toolComments:o,itemComments:s,...i?{error:i}:{}}}function rn(e){let t=Un(e);if(t.error)throw new Error(t.error);let{tools:n,lines:r,toolLines:o,toolComments:s,itemComments:i}=t;return{tools:n,lines:r,toolLines:o,toolComments:s,itemComments:i}}function Ae(e){return e.every(t=>nn.test(t)&&!t.startsWith("*"))&&(e.length!==1||je(e[0]))?e.join(", "):`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}function ke(e,t){return t==="'"&&!/[\r\n]/.test(e)?`'${e.replace(/'/g,"''")}'`:t==='"'||!je(e)?JSON.stringify(e):e}function js(e,t){let n=sn(e);if(n.error)return e;let r=n.tools??[],o=t([...r]);if(o.length===r.length&&o.every((p,h)=>p===r[h]))return e;if(!n.header){let p=e.startsWith("\uFEFF")?"\uFEFF":"";return`${p}---
|
|
17
|
-
tools: ${Ae(o)}
|
|
18
|
-
---
|
|
19
|
-
${e.slice(p.length)}`}let{header:s,lists:i,toolLines:a,toolComments:c}=n,k=new Map,d=i[0];if(d){let p=i.flatMap(y=>y.entries),h=o.map(y=>{let g=p.findIndex(b=>b.name===y);return g<0?{name:y,raw:ke(y,d.quote),before:d.separator,note:"",noteAfterComma:!1}:p.splice(g,1)[0]}),u=d.prefix.endsWith(" ")?d.prefix:`${d.prefix} `;if(!o.length)k.set(d.first,`${u}[]${d.style==="block"&&d.suffix?` ${d.suffix}`:d.suffix}`);else if(d.style==="block"){k.set(d.first,`${d.prefix}${d.suffix}`);let y=a.filter(g=>g>d.first&&g<=d.last).sort((g,b)=>g-b);for(let g=0;g<h.length;g++){let b=h[g],w=d.entries.includes(b)&&b.row?je(b.raw)||/^["']/.test(b.raw)?b.row:b.row.replace(b.raw,ke(b.name,d.quote)):`${d.indent}${ke(b.name,d.quote)}`,P=y[Math.min(g,y.length-1)]??d.first;k.set(P,`${k.has(P)?`${k.get(P)}${s.newline}`:""}${w}`)}}else{let y=d.style==="flow"||o.length===1&&on.test(o[0])||o.some(P=>P.includes(",")||P!==P.trim()||/[\r\n]|(?:^|\s)#|:\s|^[[\]{}&*!|>'"%@`]/.test(P)),g=d.head;for(let[P,S]of h.entries()){if(P){let v=S.before||d.separator,x=h[P-1];x.note&&(x.noteAfterComma?(v=v.replace(/,[^\S\n]*/,`,${x.note}`),v.includes(`
|
|
20
|
-
`)||(v+=`
|
|
21
|
-
`)):v=`${x.note}${/^[^\S\n]*\n/.test(v)?"":`
|
|
22
|
-
`}${v}`),g+=v}g+=y?/^["']/.test(S.raw)||je(S.raw)?S.raw:ke(S.name,d.quote):S.name}let b=h[h.length-1];b.note?(g+=b.noteAfterComma&&!d.tail.includes(",")?",":"",g+=b.noteAfterComma&&d.tail.includes(",")?d.tail.replace(",",`,${b.note}`):`${b.note}${d.tail}`,d.tail.includes(`
|
|
23
|
-
`)||(g+=`
|
|
24
|
-
`)):g+=d.tail;let w=y?`[${g}]`:d.outerQuote?ke(g,d.outerQuote):g;k.set(d.first,`${d.prefix}${w}${d.suffix}`.replace(/\n/g,s.newline))}}let f=new Set(a),l=s.raw.map((p,h)=>k.has(h)?`${k.get(h)}${s.newline}`:f.has(h)?c[h]&&h>d.last?`${c[h]}${s.newline}`:"":`${!o.length&&i.some(y=>y.blockComments.includes(h))?p.trimStart():p}
|
|
25
|
-
`).join(""),m=d?"":`tools: ${Ae(o)}${s.newline}`;return`${e.slice(0,s.start)}${l}${m}${e.slice(s.end)}`}function Ze(e){return e.CF_LEGACY_TOOL_LISTS!=="1"}function Rs(e,t){return Ze(e)?Ae(t):t.join(", ")}var qn=/^\s*(name|description|tools|model)\s*:\s*(.+?)\s*$/i;function Gn(e){if(e.startsWith('"')&&e.endsWith('"'))try{return JSON.parse(e)}catch{}return e.replace(/^["']|["']$/g,"")}function we(e,t,n,r){let o=Ze(e),s=Jn(t).replace(/\.md$/i,""),i,a,c=[],k=!1,d=n,f=[],l=de(n,o?void 0:"markdown");if(l){d=n.slice(l.bodyStart).trim();let p=o?l.raw.map(h=>h.replace(/\r$/,"")):l.raw;for(let h=0;h<p.length;h++){let y=p[h].match(qn);if(!y)continue;let g=y[1].toLowerCase(),b=Gn(y[2]);if(g==="name")s=b;else if(g==="description")if(/^[>|][+-]?$/.test(y[2])){let w=[];for(;h+1<p.length&&(/^\s+\S/.test(p[h+1])||p[h+1].trim()==="");)w.push(p[++h].trim());i=w.join(b[0]===">"?" ":`
|
|
26
|
-
`).trim()}else i=b;else g==="model"?a=b:g==="tools"&&!o&&(k=!0,c=b.replace(/^\[|\]$/g,"").split(",").map(w=>w.trim()).filter(Boolean))}}if(o)try{let p=rn(n);c=p.tools??[],k=p.tools!==null}catch{k=!0,f.push("tools could not be read; check the tool list")}let m=d.trim();return{name:s,...i!==void 0?{description:i}:{},...m?{prompt:m}:{},...!r?.preserveToolAbsence||k?{tools:c}:{},...a!==void 0?{model:a}:{},...f.length?{warnings:f}:{}}}function ln(e,t,n){let r=t.managed,o=[],s=new Set([...r.agents,...r.configs,...Object.keys(n.files),...n.listedPaths??[]]),i=new Set(ht(e,[...s],n.files)),a=Object.fromEntries(Object.entries(n.files).filter(([l,m])=>{if(i.has(l))return!1;let p=L(e,{path:l,text:m},{purpose:"override",route:"github",root:t.folder,listing:s,managedFiles:n.files});return!p.admitted&&p.reason==="secret"&&o.push({path:l,reason:"secret"}),p.admitted})),c=new Map;for(let l of r.agents){if(a[l]===void 0){o.some(p=>p.path===l)||o.push({path:l,reason:"missing"});continue}let m=gt(l,a[l],r,n.listedPaths??Object.keys(n.files));o.push(...m.refused),c.set(l,m)}let k=new Set([...c.values()].flatMap(l=>l.relationships.filter(m=>m.kind==="agent").map(m=>m.path))),d=[...c.values()].filter(l=>!k.has(l.path));return!d.length&&c.size&&d.push(c.values().next().value),{agents:d.map(l=>{let m=[{path:l.path,role:"system prompt",label:null}],p=[],h=[],u=(y,g,b)=>{for(let w of y.relationships){if(a[w.path]===void 0){o.some(P=>P.path===w.path)||o.push({path:w.path,reason:"missing"});continue}if(w.kind==="agent"){if(g.has(w.path)){o.push({path:w.path,reason:"cycle"});continue}let P=c.get(w.path);if(!P||h.some(v=>v.path===P.path))continue;let S=[];h.push({path:P.path,name:P.name,description:P.description,prompt:P.prompt,...P.model?{model:P.model}:{},tools:[],skillPaths:[],files:S}),u(P,new Set([...g,P.path]),S)}else if(w.kind==="skill"&&n.skills&&oe(e)||w.kind==="config"&&kt(a[w.path])){if(b.some(P=>P.path===w.path))continue;if(b.push({path:w.path,role:w.kind==="skill"?"skill":"config",label:null}),w.kind==="skill"&&y===l){let P=we(e,Vn(w.path),a[w.path]);p.push({path:w.path,name:P.name,description:P.description??"",body:P.prompt??""})}}}};return u(l,new Set([l.path]),m),{key:`managed:${l.path}`,name:l.name,model:l.model,description:l.description,prompt:{kind:"dedicated",path:l.path},files:m,tools:[],skills:p,subagents:h}}),notes:[],registry:!1,refused:o}}function an(e,t,n){let r=t.miniSwe,o=n.templateSelection?.agentPath===r.agentPath?n.templateSelection.configPaths:void 0,s=Dt(e,r,n.files,o),i=s.unresolved.filter(u=>u.reason!=="runtime-variable").map(u=>({path:u.target??u.path,reason:u.reason==="duplicate"?"invalid":u.reason})),a=s.fields.find(u=>u.key==="agent.system_template"&&u.value!==null),c=s.fields.find(u=>u.key==="agent.instance_template"&&u.value!==null),k=s.unresolved.some(u=>s.selectedPaths.includes(u.path)&&u.source===u.path);if(!a||!c||k||i.some(u=>u.reason==="invalid"))return{agents:[],notes:[],registry:!1,refused:i};let d=[a,...s.fields.filter(u=>u!==a)].map(u=>({path:u.path,span:u.span,label:u.key,role:u===a?"system prompt":u.key.endsWith("_template")?"template":"config"}));d.push(...s.loaded.map(u=>({path:u.path,role:"template",label:null})));let f=[];for(let u of d){let y=f.find(g=>g.path===u.path);y?y.span&&u.span&&(y.span={from:Math.min(y.span.from,u.span.from),to:Math.max(y.span.to,u.span.to)}):f.push({...u})}let l=[...new Set(f.map(u=>u.path))],m=Object.fromEntries(l.map(u=>[u,n.files[u]])),p=new Map(l.map(u=>[u,Buffer.byteLength(m[u])])),h=Ht(e,{ownPaths:l},{files:m,sizes:p,root:t.folder});return i.push(...h.refused,...h.skipped),s.fields.some(u=>!h.paths.includes(u.path))?{agents:[],notes:[],registry:!1,refused:i}:(s.loaded=s.loaded.filter(u=>h.paths.includes(u.path)),s.edges=s.edges.filter(u=>h.paths.includes(u.from)&&h.paths.includes(u.to)),{agents:[{key:t.key,name:n.fallbackName,model:s.model,description:null,prompt:{kind:"entry",path:a.path,span:a.span,text:a.value},files:f.filter(u=>h.paths.includes(u.path)),tools:[],skills:[],subagents:[],templateVariants:s}],notes:[],registry:!1,refused:i})}function _e(e,t,n){return e.filter(r=>t.some(o=>o.includes(n(r))))}function fn(e,t,n){if(!t.skills||!ne(e))return n;let r=[...new Set([...Object.keys(t.files),...t.listedPaths??[]])],o=ue(e,r,t.root),s=new Set(o.files.filter(f=>f.role==="skill").map(f=>f.path)),i=f=>[...new Set([...f.skillPaths.filter(l=>s.has(l)),...f.files?.filter(l=>l.role==="skill").map(l=>l.path)??[]])],a=n.agents.flatMap(f=>[...f.skills.map(l=>l.path),...f.subagents.flatMap(i)]),c=ge(e,{skillPaths:a,paths:r,files:t.files,root:t.root});for(let f of c)f.files=f.files.filter(l=>Object.hasOwn(t.files,l.path));let k=new Map(c.map(f=>[f.ownerPath,f])),d=(f,l)=>{let m=new Set(l.flatMap(h=>h.refused.map(u=>u.path))),p=f.filter(h=>h.role!=="reference"||!m.has(h.path));for(let h of l)for(let u of h.files)p.some(y=>y.path===u.path)||p.push({path:u.path,role:"reference",label:null});return p};return{...n,agents:n.agents.map(f=>{let l=f.skills.flatMap(m=>k.has(m.path)?[k.get(m.path)]:[]);return{...f,files:d(f.files,l),skills:f.skills.map(m=>({...m,...k.has(m.path)?{manifest:k.get(m.path)}:{}})),subagents:f.subagents.map(m=>{let p=i(m).flatMap(S=>k.has(S)?[k.get(S)]:[]);if(!p.length)return m;let h=o.ownerOf(m.path),u=T(e,r.filter(S=>o.ownerOf(S)===h),h?.folder),y=m.files??m.skillPaths.map(S=>({path:S,role:s.has(S)?"skill":"reference",label:u.skillNames[S]??u.skillRefNames[S]??null})),g=new Set([...f.files.map(S=>S.path),...u.subagentPaths,...Object.keys(u.subagentSkillOwners)]),b=u.scoped.filter(S=>!g.has(S)&&Pe(S)&&Object.hasOwn(t.files,S)).sort(),w=m.files?[]:_e(b,[t.files[m.path],...y.filter(S=>S.role==="reference").map(S=>t.files[S.path])],u.stripRoot).map(S=>({path:S,role:"reference",label:null})),P=d([...y,...w],p);return{...m,files:P,skillPaths:[...new Set([...m.skillPaths,...i(m),...p.flatMap(S=>S.files.map(v=>v.path))])].filter(S=>P.some(v=>v.path===S)),skillManifests:p}})}})}}import{basename as vn}from"node:path";function Qe(e){let t;try{t=JSON.parse(e)}catch{return{config:null,invalid:!0}}if(typeof t!="object"||t===null||Array.isArray(t))return{config:null,invalid:!0};let n=t,r={};for(let o of["name","model","description","prompt"]){let s=Re(n[o]);s&&(r[o]=s)}if(Array.isArray(n.agents)){let o=n.agents.flatMap(s=>{let i=Yn(s);return i?[i]:[]});o.length>0?r.agents=o:r.invalidAgents=!0}return{config:r,invalid:!1}}function cr(e){let{config:t}=Qe(e);return t?He(t):"bare"}function He(e){return e.agents&&e.agents.length>0?"agents":e.prompt?"prompt":"bare"}function cn(e,t,n){return dn(e,t,n).paths}function dn(e,t,n,r={}){let o=He(t)==="agents"?(t.agents??[]).map(a=>a.prompt):t.prompt?[t.prompt]:[],s=[],i=[];for(let a of o){let c=tt(a).path,k=nt(n,c);if(k===null){i.push({path:c,reason:"out-of-scope"});continue}let d=L(e,{path:k},{purpose:"pointer",route:"github",...r});d.admitted?s.push(k):i.push({path:k,reason:d.reason})}return{paths:s,refused:i}}function et(e,t,n){let r=nt(n.markerDir,tt(t).path),o=r!==null?L(e,{path:r},{purpose:"pointer",route:"github"}):null;if(o&&!o.admitted&&o.reason==="secret")return{kind:"secret",path:r};let s=Xn(t,n,$t(e));return s?{kind:"resolved",prompt:s}:{kind:"missed"}}function dr(e,t,n){let r=[],o=[];t.invalidAgents&&o.push(`${n.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let s=He(t),i=s==="agents"?t.agents??[]:t.prompt?[{name:t.name,model:t.model,prompt:t.prompt}]:[];for(let a of i){let c=et(e,a.prompt,n);if(c.kind==="secret"){o.push(wt(c.path));continue}if(c.kind==="missed"){o.push(`${n.repoKey}: counterfact.json points at ${a.prompt}, which was not found; ignored`);continue}r.push({name:a.name??null,model:a.model??null,description:s==="prompt"?t.description??null:null,prompt:c.prompt})}return{agents:r,warnings:o,refused:dn(e,t,n.markerDir).refused}}function Re(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Yn(e){if(typeof e!="object"||e===null)return null;let t=e,n=Re(t.prompt);if(!n)return null;let r={prompt:n},o=Re(t.name),s=Re(t.model);return o&&(r.name=o),s&&(r.model=s),r}function tt(e){let t=e.replace(/\\/g,"/"),n=t.indexOf("#");if(n>=0)return{path:t.slice(0,n),symbol:t.slice(n+1),line:null};let r=/^(.*):(\d+)$/.exec(t);return r?{path:r[1],symbol:null,line:Number(r[2])}:{path:t,symbol:null,line:null}}function nt(e,t){let n=[];for(let r of[...e.split("/"),...t.split("/")])if(r===".."){if(n.pop()===void 0)return null}else r!=="."&&r!==""&&n.push(r);return n.join("/")}function Xn(e,t,n){let{path:r,symbol:o,line:s}=tt(e),i=nt(t.markerDir,r);if(i===null||!Object.hasOwn(t.files,i))return null;let a=t.files[i];if(a===void 0)return null;if(o===null&&s===null)return A(i)?null:pt(i,a);let{sites:c}=Ft(i,a,{minChars:1,promptFunctions:n});return o!==null?c.find(k=>k.symbol===o)??null:Zn(c,s)}function Zn(e,t){let n=o=>Math.min(o.line,o.span.from),r=e.filter(o=>n(o)<=t&&t<=o.span.to);return r.sort((o,s)=>o.span.to-n(o)-(s.span.to-n(s))),r[0]??null}var Qn=25;function pn(e,{modelReader:t,codeImportV2:n=G(e)}){return We(e)||n||t?Qn:8}function Hn(e,t,n){return We(e)&&t!==null&&typeof t=="object"&&"groupKey"in t&&typeof t.groupKey=="string"&&t.groupKey?t.groupKey:n}function mn(e,t,n){let r=pn(e,n),o=new Set,s=[],i=[];return t.forEach((a,c)=>{let k=Hn(e,a,c);o.has(k)||o.size<r?(o.add(k),s.push(a)):i.push(a)}),{kept:s,leftOut:i}}function un(e,t,n){let r=t.codeImportV2??G(e),o=pn(e,{...t,codeImportV2:r});if(n.kind==="layout")return`Only ${o} agents can be added per import, so ${n.leftOut} were left out.`;if(n.kind==="scan"){let i=n.found-o;return r?`${i} ${i===1?"agent wasn't":"agents weren't"} read because the repository is large.`:`${n.repoKey}: found ${n.found} agents in code; the ${o} strongest are shown, the rest are listed here: ${n.list}`}let s=n.kind==="import"&&r?`Not added: this import already has ${o} agents.`:`Only the ${o} strongest agents of a repository are added.`;return n.kind==="model"?`${n.name}: ${s}`:s}function hn(e){return e.CF_MODEL_READER!=="0"}var ot="crew:";function st(e){return e.startsWith(ot)}function gn(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,r])=>`${n}: ${r}`).join(`
|
|
27
|
-
`)}function yn(e,t){let n=[],r=[],o=(a,c)=>r.push({code:"unreadable-crew",path:a,detail:c?`${c} could not be read; some instructions may be missing.`:"could not be read; some instructions may be missing."}),s=Be(t[e.agentsPath]??""),i=e.tasksPath?Be(t[e.tasksPath]??""):[];s?.length||o(e.agentsPath),i===null&&o(e.tasksPath);for(let{key:a,value:c,span:k}of s??[]){if(!kn(c)){o(e.agentsPath,a);continue}let{llm:d,tools:f,...l}=c,m=gn(l);if(m===null&&Object.keys(l).length){o(e.agentsPath,a);continue}let p=[{role:"system prompt",path:e.agentsPath,label:a,span:k}];for(let h of i??[])kn(h.value)&&h.value.agent===a&&p.push({role:"knowledge",path:e.tasksPath,label:h.key,span:h.span});n.push({key:`${ot}${e.agentsPath}#${a}`,name:a,model:typeof d=="string"?d:null,description:typeof c.goal=="string"?c.goal:null,entry:{path:e.agentsPath,span:k,text:m},files:p,tools:Array.isArray(f)?[...new Set(f.filter(h=>typeof h=="string"&&!!h.trim()))]:[],skills:[],subagents:[]})}return{agents:n,notes:r,registry:!1}}function kn(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}import{basename as wn,posix as Ie}from"node:path";function bn(e,t,n){let r={...t.selected,codeAgentsFound:t.codeAgentsFound||t.selected.codeAgentsFound};if(!rt(e,r,n))return{kind:"none"};let o={...t.bodies,...r.files},s=T(e,Object.keys(o),K(r.root)).templatePaths,i=it(e,{...r,files:o},s);if(!t.entries)return{kind:"search",paths:[],ownedPaths:i.ownedPaths};let a=new Set([...Object.keys(o),...t.attemptedPaths??[]]),c=new Set(i.facts.dependencies);for(let p of i.relatedReads)p.target.kind==="file"&&c.add(p.target.path);for(let p of t.entries)i.relatedReads.some(h=>h.target.kind==="directory"&&Ne(h,p.path))&&c.add(p.path);let k=(p,h)=>{let u=L(e,p,{purpose:h,route:"local-folder"});return u.admitted||u.reason==="too-large"},d=[...new Set(t.entries.filter(p=>!a.has(p.path)&&(c.has(p.path)?k(p,"pointer"):M(p.path,r.root)===null&&A(p.path)!==null&&k(p,"code-support"))).map(p=>p.path))],f=K(r.root)??"",l=p=>Ie.parse(p).name===(f?wn(f):r.fallbackName)?0:yt.test(wn(p))?1:2,m=p=>Ie.relative(f||".",Ie.dirname(p)).split("/").filter(h=>h&&h!==".").length;return d.sort((p,h)=>Number(c.has(h))-Number(c.has(p))||l(p)-l(h)||m(p)-m(h)||(p<h?-1:p>h?1:0)),{kind:"search",paths:d,ownedPaths:i.ownedPaths}}function Ne(e,t){return e.target.kind==="file"?e.target.path===t:Ie.dirname(t)===e.target.path&&(!e.target.extension||t.endsWith(e.target.extension))}function rt(e,t,n){if(!Fe(e)||t.codeAgentsFound||t.explicitPrompt!==void 0||n.agents.length||t.listedPaths&&T(e,[...t.listedPaths],K(t.root)).configPath)return null;let r=T(e,Object.keys(t.files),K(t.root)).templatePaths;if(!r.length)return null;let o=Object.fromEntries(Object.entries(t.files).filter(([s])=>M(s,t.root)!==null&&L(e,{path:s},{purpose:"override",route:"github"}).admitted));return Je(o).reads.some(s=>r.some(i=>Ne(s,i)))?null:r}function it(e,t,n){let r=Object.fromEntries(Object.entries(t.files).filter(([l])=>L(e,{path:l},{purpose:"override",route:"github"}).admitted)),o=Je(r),s=o.reads.filter(l=>M(l.sourcePath,t.root)===null&&n.some(m=>Ne(l,m))),i=n.filter(l=>s.some(m=>Ne(m,l))).sort(),a=[...new Set(s.map(l=>l.sourcePath))].sort(),c=o.reads.filter(l=>a.includes(l.sourcePath)),k=c.flatMap(l=>l.target.kind==="file"&&Object.hasOwn(r,l.target.path)&&M(l.target.path,t.root)!==null&&!n.includes(l.target.path)?[l.target.path]:[]).sort(),d=s.flatMap(l=>l.consumerPaths).sort(),f=i.length?[...new Set([i[0],...n.filter(l=>l!==i[0]),...k,...a,...d])]:[];return{facts:o,relatedReads:c,provenTemplates:i,ownedPaths:f}}function ni(e,t){let n=fn(e,t,xn(e,t)),r=rt(e,t,n);if(!r)return n;let o=it(e,t,r);if(!o.provenTemplates.length)return n;let s=o.provenTemplates[0],i=new Set(n.agentScopes?.find(c=>c.key===null)?.notes),a=c=>!(c.code==="no-prompt"&&c.detail==="no-conventions"&&c.path===(K(t.root)??""));return{...n,projection:"conventions",notes:n.notes.filter(a),...n.agentScopes?{agentScopes:n.agentScopes.map(c=>({...c,notes:c.notes.filter(a)}))}:{},...n.unassignedNotes?{unassignedNotes:n.unassignedNotes.filter(c=>!i.has(c))}:{},agents:[{key:null,name:t.fallbackName,model:null,description:null,prompt:{kind:"dedicated",path:s},files:o.ownedPaths.map(c=>({path:c,role:c===s?"system prompt":r.includes(c)?"template":"reference",label:null})),skills:[],subagents:[]}]}}function oi(e,t){return Fe(e)?bn(e,t,xn(e,t.selected)):{kind:"none"}}function xn(e,t){if(!H(e)){let{agents:w,notes:P}=lt(e,t,null);return{agents:w,notes:P}}let n=ve(e,t.listedPaths??[]).flatMap(w=>[...w.agents,...w.configs]),r=[...new Set([...Object.keys(t.files),...n])],{scopes:o,ownerOf:s,ignoredPaths:i,pluginFolders:a}=ue(e,r,t.root),c=new Set(i),k=new Map(o.map(w=>[w,{}]));for(let[w,P]of Object.entries(t.files)){if(c.has(w))continue;let S=s(w);S&&(k.get(S)[w]=P)}let d=o.map(w=>{let P=k.get(w),S={...t,files:P,root:w.folder,fallbackName:w.key===null?t.fallbackName:vn(w.folder),explicitPrompt:w.key===null?t.explicitPrompt:void 0,...t.pointerFiles?{pointerFiles:Object.fromEntries(Object.entries(t.pointerFiles).filter(([v])=>!c.has(v)&&s(v)===w))}:{}};return{scope:w,input:S,answer:Pn(e,w,S)}}),f=[],l=new Map,m=d.filter(({scope:w,input:P,answer:S})=>{let v=S.agents[0];if(!v)return!0;let x=Object.entries(P.files).map(([E,I])=>[M(E,w.folder),I]).sort(([E],[I])=>E<I?-1:E>I?1:0),_=JSON.stringify([v.name,x,...w.managed||Ge(e)&&a.includes(w.folder)?[w.folder]:[]]),C=l.get(_);return C!==void 0?(f.push({code:"duplicate-agent",path:w.folder,detail:C}),!1):(l.set(_,w.folder),!0)});if(m.some(({scope:w,answer:P})=>w.key!==null&&P.agents.length)){let w=m.find(({scope:P})=>P.key===null);w.answer=Pn(e,w.scope,w.input,!0),w.answer.notes=w.answer.notes.filter(P=>P.detail!=="no-conventions")}let p={modelReader:hn(e),codeImportV2:G(e)},{kept:h,leftOut:u}=mn(e,m.flatMap(({answer:w})=>w.agents),p),y=[...f,...u.length?[{code:"agent-cap",detail:un(e,p,{kind:"layout",leftOut:u.length})}]:[]],g=new Set(h.map(w=>w.key));return{...!t.definitionsOmitted&&m.some(({scope:w})=>w.kind==="crew")&&m.every(({scope:w,answer:P})=>P.notes.length===0&&(w.kind==="crew"?P.agents.length>0&&P.agents.every(S=>st(S.key??"")):P.agents.length===0))&&(!t.listedPaths||ue(e,t.listedPaths,t.root).files.every(w=>Object.hasOwn(t.files,w.path)))?{complete:!0}:{},...m.some(({scope:w,answer:P})=>w.miniSwe&&P.agents.length)&&!t.codeAgentsFound?{projection:"conventions"}:{},capOptions:p,agents:h,notes:[...m.flatMap(({answer:w})=>w.notes),...y],...n.length?{scopePaths:r}:{},...m.some(({answer:w})=>w.refused?.length)?{refused:m.flatMap(({answer:w})=>w.refused??[])}:{},...o.length>1||o.some(w=>w.kind==="crew"||w.managed||w.miniSwe)?{agentScopes:m.flatMap(({scope:w,answer:P})=>(P.agents.length?P.agents:[{key:w.key}]).map((S,v)=>({key:S.key,folder:w.folder,registry:P.registry&&!st(S.key??""),notes:P.notes.filter(x=>x.code!=="unreadable-crew"||v===0)}))),unassignedNotes:[...m.filter(({answer:w})=>!w.agents.some(P=>g.has(P.key))).flatMap(({answer:w})=>w.notes),...y]}:{}}}function Pn(e,t,n,r=!1){if(t.managed)return ln(e,t,n);if(t.miniSwe&&n.explicitPrompt===void 0)return an(e,t,n);if(t.kind!=="crew")return lt(e,n,t.key,r);let o=eo(e,t,n.files),s=lt(e,n,t.key,r||t.key===null&&o.agents.length>0);return{agents:[...s.agents,...o.agents],notes:[...s.notes.filter(i=>i.detail!=="no-conventions"),...o.notes],registry:s.registry}}function eo(e,t,n){let{agents:r,notes:o,registry:s}=yn(t,n);return{agents:r.map(({entry:i,...a})=>({...a,prompt:On(e,{entry:i},o)})),notes:o,registry:s}}function lt(e,t,n,r=!1){let{files:o,skills:s,fallbackName:i}=t,a=K(t.root),c=T(e,Object.keys(o),a),k=[],d=t.explicitPrompt,f=typeof d=="string"&&Object.hasOwn(o,d)&&L(e,{path:d},{purpose:"override",route:"github"}).admitted?d:null,l={...c,skillPaths:s?c.skillPaths:[]},m=Q(l),p=Se({codeAgentsFound:!1,folderAgentsFound:r,otherDefinitions:m,codeImportV2:G(e)});if(!(d===null||f!==null||Me(l,p)))return Sn(c,s,k),{agents:[],notes:[...k,{code:"no-prompt",path:a??"",detail:"no-conventions"}],registry:c.registry};let u=to(o,c.configPath,k),y=On(e,{files:o,c,guideRole:p,folderAgentsFound:r,root:a,config:u,explicitPath:d===null?null:f??void 0,pointerFiles:t.pointerFiles},k),g=s?c.skillPaths.map(P=>{let S=we(e,`${c.skillNames[P]}.md`,o[P]);return k.push(...(S.warnings??[]).map(v=>({code:"frontmatter",path:P,detail:v}))),{path:P,name:S.name,description:S.description??"",body:S.prompt??""}}):[];Sn(c,s,k);let b=s?[...c.subagentSkillPaths,...c.subagentSkillRefPaths]:[],w=c.subagentPaths.map(P=>{let S=we(e,vn(P),o[P],{preserveToolAbsence:!0});return k.push(...(S.warnings??[]).map(v=>({code:"frontmatter",path:P,detail:v}))),{path:P,name:S.name,description:S.description??null,prompt:S.prompt??"",...S.tools!==void 0?{tools:S.tools}:{},...S.model!==void 0?{model:S.model}:{},skillPaths:b.filter(v=>c.subagentSkillOwners[v]===P)}});return{agents:[{key:n,name:u?.name??i,model:u?.model??null,description:u?.description??null,prompt:y,files:no(e,o,c,y,s),skills:g,subagents:w}],notes:k,registry:c.registry}}function si(e,t,n,r){let o=T(e,Object.keys(n),K(r));return Object.hasOwn(o.subagentSkillOwners,t)?!0:ge(e,{skillPaths:o.subagentSkillPaths,paths:o.scoped,files:n,root:r})?.some(s=>s.files.some(i=>i.path===t))??!1}function to(e,t,n){if(!t)return null;let r=Qe(e[t]);if(r.invalid)try{JSON.parse(e[t])}catch{n.push({code:"invalid-config",path:t})}return r.config}function On(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:r,c:o,guideRole:s,folderAgentsFound:i,root:a,config:c,explicitPath:k,pointerFiles:d}=t;if(k===null)return{kind:"none"};if(k!==void 0)return{kind:"explicit",path:k};let f=c?.agents?.[0]?.prompt??c?.prompt,l=c?cn(e,c,a??"")[0]:void 0,m=f?et(e,f,{repoKey:"",markerDir:a??"",files:d??r}):null,p=l!==void 0&&Object.hasOwn(r,l),h=p&&!!r[l];if(p&&(h||d!==void 0)&&Object.hasOwn(o.subagentSkillOwners,l))n.push({code:"pointer-owned-by-subagent",path:l});else if(p&&(d===void 0?h:m?.kind==="resolved")){let u=m?.kind==="resolved"?m.prompt:null;return{kind:"pointer",path:l,...u&&u.kind!=="file"?{span:{...u.span},site:{kind:u.kind,start:u.start,symbol:u.symbol}}:{}}}else f&&n.push(d!==void 0&&m?.kind==="secret"?{code:"secret-file",path:m.path}:{code:"pointer-missed",...l?{path:l}:{},detail:f});return o.promptPath?{kind:"dedicated",path:o.promptPath}:o.registry&&o.soulPath?{kind:"registry",path:o.soulPath}:o.claudePath&&s==="prompt"?(n.push({code:"claude-fallback"}),{kind:"fallback",path:o.claudePath}):(n.push({code:"no-prompt",path:a??"",...i?{folderAgentsFound:!0}:{}}),{kind:"none"})}function Sn(e,t,n){if(t)for(let r of[...e.subagentSkillPaths,...e.subagentSkillRefPaths])e.subagentSkillOwners[r]||n.push({code:"orphan-skill",path:r})}function no(e,t,n,r,o){let s=[],i=(f,l,m=null)=>({role:f,label:m,path:l});if(r.kind!=="none"&&r.kind!=="registry"&&s.push(i("system prompt",r.path)),n.soulPath&&s.push(i("soul",n.soulPath)),n.knowledgePath&&s.push(i("knowledge",n.knowledgePath)),o)for(let f of n.skillPaths)s.push(i("skill",f,n.skillNames[f]));for(let f of n.templatePaths)s.push(i("template",f));if(o)for(let f of n.skillRefPaths)s.push(i("reference",f,n.skillRefNames[f]));let a=[];n.configPath&&a.push(i("config",n.configPath));for(let f of[n.toolsPath,n.toolsTsPath,n.cliPath])f&&a.push(i("tools",f));n.mcpPath&&a.push(i("mcp",n.mcpPath));let c=new Set([...s.map(f=>f.path),...a.map(f=>f.path),...n.subagentPaths,...Object.keys(n.subagentSkillOwners),...n.skillPaths,...n.skillRefPaths]),k=n.scoped.filter(f=>!c.has(f)&&Pe(f)).sort(),d=ne(e)?s.filter(f=>f.role!=="skill"):s;return s.push(..._e(k,d.map(f=>t[f.path]),n.stripRoot).map(f=>i("reference",f)),...a),s}export{so as a,Mn as b,jt as c,T as d,Q as e,Wo as f,Ee as g,ue as h,Ut as i,Gt as j,ge as k,Zt as l,Xe as m,zn as n,Fs as o,$s as p,Ht as q,Ms as r,Un as s,js as t,Ze as u,Rs as v,we as w,_e as x,Qe as y,cr as z,He as A,cn as B,dn as C,dr as D,pn as E,mn as F,un as G,hn as H,ni as I,oi as J,si as K};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=class extends Error{code;retryable;constructor(n,s,c){super(s),this.code=n,this.name="JobError",this.retryable=c?.retryable??!1}};function i(e){if(e instanceof t&&["org_spend_limit","lease_lost","cancelled","canceled","replay_miss"].includes(e.code)||e instanceof Error&&e.name==="AbortError"||e&&typeof e=="object"&&"kind"in e&&["spending_stop","lease_lost","cancelled"].includes(String(e.kind)))throw e}export{t as a,i as b};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as p}from"./BZNHHLNP.js";var c=.1,s=Object.freeze({"5m":1.25,"1h":2}),n=Object.freeze(Object.fromEntries([...Object.entries({"claude-opus-5-5":{input:4,output:20},"claude-opus-4-8":{input:5,output:25},"claude-sonnet-5":{input:2,output:10},"claude-haiku-4-5":{input:1,output:5}}).map(([t,e])=>[t,Object.freeze({...e,cachedInput:e.input*(t==="claude-opus-5-5"?.05:c),provider:"anthropic"})]),["gpt-6-luna",Object.freeze({input:.1,output:.5,cachedInput:.01,provider:"openai"})]])),a=(()=>{let t=Object.entries(n);if(t.length===0)throw new Error("PRICE_PER_MTOK is empty");return t.reduce((e,r)=>r[1].input+r[1].output>e[1].input+e[1].output?r:e)[0]})();function h(t,e="5m"){return n[t]?.provider==="openai"?1:s[e]}function x(t){return Math.ceil(t/4)}function f(t,e,r,o=1){let u=Object.hasOwn(n,t)?n[t]:n[a];return(e*u.input*o+r*u.output)/1e6}function O(t,e,r,o,u=1){return{label:t,model:e,inputTokens:r,outputTokens:o,usd:f(e,r,o,u)}}function _(t,e){return{lines:t,totalUsd:t.reduce((r,o)=>r+o.usd,0),capUsd:e}}function d(t){return t.totalUsd>t.capUsd}function i(t){return t>0&&t<.01?`$${t.toFixed(3)}`:`$${t.toFixed(2)}`}function l(t){if(d(t))throw new p("over_cap",`The estimate (${i(t.totalUsd)}) is over the ${i(t.capUsd)} cap. Analyze fewer repositories.`)}export{c as a,s as b,n as c,a as d,h as e,x as f,f as g,O as h,_ as i,d as j,i as k,l};
|