@counterfact-labs/cli 0.2.6 → 0.2.9
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/README.md +20 -0
- package/bundle/client-release.json +1 -1
- package/dist/adapters/analysis-results.js +87 -0
- package/dist/adapters/combined-results.js +27 -0
- package/dist/adapters/completion-lock.js +95 -0
- package/dist/adapters/completion.js +132 -17
- package/dist/adapters/entry-files.js +129 -0
- package/dist/adapters/entry-packing.js +161 -0
- package/dist/adapters/entry-selection.js +57 -0
- package/dist/adapters/files.js +111 -5
- package/dist/adapters/git.js +10 -1
- package/dist/adapters/relay-plan.js +5 -7
- package/dist/adapters/release.js +4 -1
- package/dist/adapters/results.js +18 -3
- package/dist/adapters/selection.js +114 -0
- package/dist/adapters/settings.js +62 -4
- package/dist/adapters/source-relay-plan.js +7 -0
- package/dist/analysis-core/analysis/code-agents/skipped-files.js +1 -1
- package/dist/analysis-core/analysis/file-analysis-plan.js +1 -0
- package/dist/analysis-core/analysis/file-dependencies.js +1 -0
- package/dist/analysis-core/analysis/finding-activity-switch.js +1 -0
- package/dist/analysis-core/analysis/finding-identity.js +1 -0
- package/dist/analysis-core/analysis/finding-quality/policy.js +1 -0
- package/dist/analysis-core/analysis/folder-analysis-plan.js +1 -0
- package/dist/analysis-core/analysis/passes/full-file-passes.js +1 -0
- package/dist/analysis-core/analysis/project-architecture.js +1 -0
- package/dist/analysis-core/analysis/schemas.js +1 -1
- package/dist/analysis-core/chunks/2AASSZRO.js +35 -0
- package/dist/analysis-core/chunks/2YREYGOG.js +1 -0
- package/dist/analysis-core/chunks/33HRXJ5Q.js +1 -0
- package/dist/analysis-core/chunks/33IGHOYT.js +1 -0
- package/dist/analysis-core/chunks/4PT5C4IT.js +7 -0
- package/dist/analysis-core/chunks/4RXRAB5S.js +1 -0
- package/dist/analysis-core/chunks/4UDQBDDE.js +1 -0
- package/dist/analysis-core/chunks/{OPMA32A6.js → 5B5UCWD3.js} +1 -1
- package/dist/analysis-core/chunks/6YCABS5T.js +1 -0
- package/dist/analysis-core/chunks/CQQ4TTXE.js +1 -0
- package/dist/analysis-core/chunks/CTLHKFPH.js +19 -0
- package/dist/analysis-core/chunks/F54DOWKN.js +6 -0
- package/dist/analysis-core/chunks/FRXOQ2M6.js +3 -0
- package/dist/analysis-core/chunks/HCPO6QPU.js +1 -0
- package/dist/analysis-core/chunks/HHFDNY6V.js +14 -0
- package/dist/analysis-core/chunks/{3JWEFCTJ.js → HVQJKPQ4.js} +1 -1
- package/dist/analysis-core/chunks/INVTU73D.js +1 -0
- package/dist/analysis-core/chunks/JEWBPIQI.js +1 -0
- package/dist/analysis-core/chunks/JGK37AWN.js +1 -0
- package/dist/analysis-core/chunks/LFYTD7JF.js +1 -0
- package/dist/analysis-core/chunks/LMUXOKIM.js +1 -0
- package/dist/analysis-core/chunks/LOBIDUCA.js +1 -0
- package/dist/analysis-core/chunks/M5YWJY7P.js +1 -0
- package/dist/analysis-core/chunks/MGVIKA74.js +1 -0
- package/dist/analysis-core/chunks/MKYLK6DB.js +1 -0
- package/dist/analysis-core/chunks/MZOKZ3N6.js +1 -0
- package/dist/analysis-core/chunks/NXHVBJL4.js +1 -0
- package/dist/analysis-core/chunks/OKBK3JL3.js +1 -0
- package/dist/analysis-core/chunks/PBHHWFR6.js +1 -0
- package/dist/analysis-core/chunks/Q5WR6B2H.js +2 -0
- package/dist/analysis-core/chunks/QVXARKP7.js +1 -0
- package/dist/analysis-core/chunks/RQTNTIR4.js +1 -0
- package/dist/analysis-core/chunks/RUVMFAST.js +1 -0
- package/dist/analysis-core/chunks/S27VIQMZ.js +1 -0
- package/dist/analysis-core/chunks/{YDBO7P4X.js → S27Y2TP5.js} +1 -1
- package/dist/analysis-core/chunks/SJESFYBA.js +10 -0
- package/dist/analysis-core/chunks/SP6XFHNH.js +1 -0
- package/dist/analysis-core/chunks/VDUFPTDD.js +1 -0
- package/dist/analysis-core/chunks/W24SFYZM.js +67 -0
- package/dist/analysis-core/chunks/YTHF2E2S.js +1 -0
- package/dist/analysis-core/chunks/YWL52FVW.js +2 -0
- package/dist/analysis-core/contracts/analysis-selection.js +1 -0
- package/dist/analysis-core/contracts/analysis-size.js +1 -0
- package/dist/analysis-core/contracts/execution-request.js +1 -0
- package/dist/analysis-core/contracts/intake-finding.js +1 -0
- package/dist/analysis-core/contracts/model-call-identity.js +1 -0
- package/dist/analysis-core/contracts/module-resolution.js +1 -0
- package/dist/analysis-core/contracts/relay-analysis.js +1 -1
- package/dist/analysis-core/contracts/requests.js +1 -1
- package/dist/analysis-core/contracts/selection-paths.js +1 -0
- package/dist/analysis-core/conventions/analysis-fit.js +1 -1
- package/dist/analysis-core/conventions/file-admission.js +1 -1
- package/dist/analysis-core/conventions/read-limits.js +1 -0
- package/dist/analysis-core/import/calls/modules.js +1 -0
- package/dist/analysis-core/import/entry-selection.js +1 -0
- package/dist/analysis-core/import/outside-loader-sources.js +1 -1
- package/dist/analysis-core/index.js +3 -3
- package/dist/analysis-core/requests/answer-formats.js +1 -1
- package/dist/analysis-core/requests/local-plan.js +1 -1
- package/dist/analysis-core/requests/planned-limits.js +1 -0
- 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/analysis-core/stages/engine-entry.js +1 -1
- package/dist/bundle/seal/engine.js +1 -1
- package/dist/cli/analysis-selection.js +133 -0
- package/dist/cli/api.js +1 -1
- package/dist/cli/commands/analyze.js +82 -14
- package/dist/cli/commands/skipped.js +65 -0
- package/dist/cli/completion-delivery.js +63 -0
- package/dist/cli/completion-recovery.js +68 -14
- package/dist/cli/context.js +4 -2
- package/dist/cli/finding-display.js +102 -7
- package/dist/cli/finding-settings.js +3 -1
- package/dist/cli/intake-payload.js +26 -2
- package/dist/cli/main.js +37 -11
- package/dist/cli/mcp-failure.js +6 -5
- package/dist/cli/mcp.js +191 -26
- package/dist/cli/prior-completion.js +35 -0
- package/dist/cli/relay-check.js +260 -110
- package/dist/cli/relay-failure.js +32 -0
- package/dist/cli/relay-preparation.js +72 -21
- package/dist/cli/result-check.js +31 -12
- package/dist/cli/results-upload.js +131 -0
- package/dist/cli/saved-results.js +10 -0
- package/dist/cli/scope-choices.js +57 -0
- package/dist/cli/sign-in.js +2 -2
- package/dist/cli/skipped-files.js +22 -0
- package/dist/cli/summary.js +15 -1
- package/dist/contract/agent-choice.js +25 -2
- package/dist/contract/cli-api-messages.js +3 -0
- package/dist/contract/cli-refusals.js +39 -5
- package/dist/contract/cli-version.js +1 -1
- package/dist/contract/console-url.js +3 -0
- package/dist/contract/console.js +24 -40
- package/dist/contract/engine.js +1 -1
- package/dist/contract/messages.js +4 -3
- package/dist/contract/project-architecture.js +1 -0
- package/dist/contract/scope-choice.js +98 -0
- package/dist/contract/selection-metadata.js +9 -0
- package/dist/contract/selection-offer.js +40 -0
- package/dist/gatekeeper/cli-api.js +70 -4
- package/dist/gatekeeper/console.js +55 -28
- package/dist/gatekeeper/model.js +5 -23
- package/dist/gatekeeper/trust/policy.js +2 -1
- package/package.json +5 -3
- package/dist/analysis-core/analysis/source-notes/types.js +0 -1
- package/dist/analysis-core/chunks/2PSNOSJ2.js +0 -1
- package/dist/analysis-core/chunks/377MLK4M.js +0 -21
- package/dist/analysis-core/chunks/5DGPLXYB.js +0 -1
- package/dist/analysis-core/chunks/6B2HILSY.js +0 -1
- package/dist/analysis-core/chunks/6QY5BV5B.js +0 -14
- package/dist/analysis-core/chunks/6U2IR4XB.js +0 -1
- package/dist/analysis-core/chunks/DLPVYWHZ.js +0 -1
- package/dist/analysis-core/chunks/FOKDE64Y.js +0 -1
- package/dist/analysis-core/chunks/FSLWD2PE.js +0 -1
- package/dist/analysis-core/chunks/K2GNDX3W.js +0 -1
- package/dist/analysis-core/chunks/KTNA2KTN.js +0 -7
- package/dist/analysis-core/chunks/KWECQJ6X.js +0 -1
- package/dist/analysis-core/chunks/NIOS7U6C.js +0 -41
- package/dist/analysis-core/chunks/PECX3OXB.js +0 -1
- package/dist/analysis-core/chunks/PYKAERZZ.js +0 -1
- package/dist/analysis-core/chunks/QFY6A3MS.js +0 -66
- package/dist/analysis-core/chunks/SKVEBOGA.js +0 -1
- package/dist/analysis-core/chunks/STI4JE7L.js +0 -1
- package/dist/analysis-core/chunks/SVMEWGD3.js +0 -1
- package/dist/analysis-core/chunks/X7WZAA7S.js +0 -1
- package/dist/analysis-core/chunks/ZTOVBAG7.js +0 -1
- package/dist/analysis-core/data/finding-types.js +0 -1
|
@@ -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"./2AASSZRO.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
|
+
import{c as b,d as l}from"./NXHVBJL4.js";import{a as u,b as o,c as g}from"./QVXARKP7.js";import{a as r}from"./OKBK3JL3.js";import{z as _}from"zod";import{z as c}from"zod";function h(a=r){return c.object({rows:c.array(c.object({key:c.string().describe(a("finding-headlines-key")),headline:c.string().nullable().describe(a("finding-headlines-headline")),ifLeft:c.string().nullable().describe(a("finding-headlines-if-left"))}).strict())}).strict()}var A=h();import{z as n}from"zod";var p=n.object({verdicts:n.array(n.object({id:n.string(),inScope:n.boolean(),reason:n.string()}))});import{z as e}from"zod";var z=3,F=64e3,C=8,H=60,E=e.object({subKind:e.string().describe(r("analysis-structure-schema-1")),kind:e.string().describe(r("analysis-structure-schema-2")),severity:e.string().describe(r("analysis-structure-schema-3")),title:e.string(),cause:e.string(),evidence:e.array(e.object({path:e.string(),line:e.number(),excerpt:e.string()})),children:e.array(e.object({ref:e.string().describe(r("analysis-structure-schema-4")),how:e.string()})),files:e.array(e.object({path:e.string(),action:e.string().describe(r("analysis-structure-schema-5")),role:e.string().describe(r("analysis-structure-schema-6")),unit:e.string().describe(r("analysis-structure-schema-7")),loadMode:e.string().describe(r("analysis-structure-schema-8")),loadVia:e.string().describe(r("analysis-structure-schema-9")),purpose:e.string(),fmName:e.string().describe(r("analysis-structure-schema-10")),fmDescription:e.string(),fmTools:e.array(e.string())})),segments:e.array(e.object({path:e.string(),startLine:e.number(),endLine:e.number(),to:e.string().describe(r("analysis-structure-schema-11")),disposition:e.string().describe(r("analysis-structure-schema-12")),intoPath:e.string().describe(r("analysis-structure-schema-13")),intoLine:e.number().describe(r("analysis-structure-schema-14")),childRef:e.string().describe(r("analysis-structure-schema-15")),heading:e.string().describe(r("analysis-structure-schema-16")),reason:e.string()})),additions:e.array(e.object({path:e.string(),text:e.string(),kind:e.string().describe(r("analysis-structure-schema-17")),heading:e.string()})),reorders:e.array(e.object({path:e.string(),startLine:e.number(),endLine:e.number(),order:e.array(e.number()).describe(r("analysis-structure-schema-reorder-order")),reasons:e.array(e.string()).describe(r("analysis-structure-schema-reorder-reasons"))})).describe(r("analysis-structure-schema-18")),toolMoves:e.array(e.object({tool:e.string(),fromUnit:e.string(),toUnit:e.string(),reason:e.string()}))}),y=e.object({structures:e.array(E)}),f=e.object({verdict:e.string().describe(r("structure-recheck-verdict")),reason:e.string()}),S=e.object({verdicts:e.array(e.object({index:e.number(),inScope:e.boolean(),reason:e.string()}))});import{z as t}from"zod";var j=t.object({verdicts:t.array(o.shape.verdicts.element.extend({decisive:t.boolean(),quotes:t.array(t.object({side:t.enum(["against","for"]),repo:t.string(),path:t.string(),line:t.number().int().positive(),quote:t.string()}))}))});import{z as s}from"zod";var q=4,K=1,J=16e3,k=s.object({path:s.string(),startLine:s.number(),endLine:s.number()}),x=s.object({decision:s.string().describe(r("analysis-split-check-schema-1")),reason:s.string(),frontDoor:s.object({job:s.string().describe(r("analysis-split-check-schema-2")),skills:s.array(s.string()).describe(r("analysis-split-check-schema-3"))}),subAgents:s.array(s.object({name:s.string().describe(r("analysis-split-check-schema-4")),job:s.string().describe(r("analysis-split-check-schema-5")),description:s.string().describe(r("analysis-split-check-schema-6")),skills:s.array(s.string()),tools:s.array(s.string()).describe(r("analysis-split-check-schema-7")),promptSections:s.array(k),knowledgeSections:s.array(k).describe(r("analysis-split-check-schema-8")),resolves:s.array(s.string()).describe(r("analysis-split-check-schema-9")),evidence:s.array(s.object({path:s.string(),line:s.number(),excerpt:s.string()})),handoff:s.string().describe(r("analysis-split-check-schema-10"))}))});function ie(a=m=>m,T){let m={codeJudge:u,findings:l({}),scope:p,structures:y,structureScope:S,check:o,opinion:j,sourceNotes:g,shape:x,recheck:f,findingHeadlines:h(i=>T?.(i)??r(i)),judge:_.object({row:_.string().min(1).nullable()}).strict()},U=b().map(({name:i,schema:d})=>[i,d]);return Object.fromEntries([...Object.entries(m),...U].map(([i,d])=>[i,a(d)]))}export{A as a,z as b,F as c,C as d,H as e,j as f,q as g,K as h,J as i,ie as j};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as Z,B as dt,C as pt,D as ct,E as ft,F as O,G as mt,H as ht,I as ut,J as gt,P as Pt,R as wt,V as kt,W as St,a as ie,b as Je,c as Ve,d as Qe,e as Xe,f as V,g as le,h as z,i as Ze,j as K,ja as bt,k as N,l as et,la as vt,m as tt,ma as Rt,n as ot,na as Ft,o as q,oa as Et,p as st,q as at,r as de,s as Q,t as rt,u as nt,v as A,w as pe,x as X,y as it,z as lt}from"./W24SFYZM.js";import{a as Ye}from"./5B5UCWD3.js";import{i as $e}from"./4RXRAB5S.js";import{a as J}from"./QDYMR6KS.js";import{a as We}from"./HVQJKPQ4.js";import{g as _}from"./CTLHKFPH.js";import{E as Ge,d as ze,e as M,f as Ke,g as Ne,h as qe,o as He,q as C,s as Ue,t as De,y as Y}from"./FRXOQ2M6.js";import{a as L}from"./326F4XNG.js";import{b as T,c as U}from"./HCPO6QPU.js";import{a as Te,b as _e,c as ne}from"./33HRXJ5Q.js";import{a as je,b as re}from"./LOBIDUCA.js";import{e as ke,g as Se}from"./YTHF2E2S.js";import{n as $}from"./4PT5C4IT.js";import{c as Ie}from"./2YREYGOG.js";import{a as Ae}from"./4H23CSUM.js";import{c as ae}from"./MJGB25S5.js";import{$ as D,Ca as ye,Fb as k,Lb as Le,Ta as Ce,hb as G,i as y,kb as Be,lb as Me,pb as W,u as oe}from"./2AASSZRO.js";import{a as ve}from"./MKYLK6DB.js";import{f as se,i as Fe,j as Ee,m as Oe,n as xe}from"./JKWTHRUR.js";import{c as Re,e as x}from"./C6X5GDG4.js";import{b as we}from"./724WZMYW.js";import{a as be}from"./SJESFYBA.js";import{posix as Ut}from"node:path";function Ot(r,e,a){let s=new Set(e.entries.map(l=>l.path)),t=new Set(G(r,[...s])),d=Object.fromEntries(Object.entries(e.files).filter(([l])=>e.selected.some(o=>o.path===l&&o.readBytes===void 0))),n=new Set(Me(r,[...s],d)),f=[],c=new Set;return{read:async l=>{if(n.has(l.path)||e.managedReadPaths?.includes(l.path)&&e.files[l.path]===void 0)return e.refused.push({path:l.path,reason:"unreadable"}),null;f.push(l);try{let o=await a(l);if(o!==null){if(c.has(l.path)){let p=k(r,{path:l.path,size:Buffer.byteLength(o),text:o},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(y(r)||we(r)){let p=k(r,{path:l.path,text:o},{...e.admission,purpose:"override",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(e.phase==="manifest"){let p=k(r,{path:l.path,size:Buffer.byteLength(o)},{...e.admission,purpose:"pointer",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}return o}}catch(o){if(o instanceof W&&(o.reason==="secret-content"||y(r)||c.has(l.path)||t.has(l.path)))return e.refused.push({path:l.path,reason:o.reason}),null;if(e.profile==="hosted-import"&&!c.has(l.path)&&!t.has(l.path))throw o}return e.refused.push({path:l.path,reason:"unreadable"}),null},requestedReads:f,skillReads:c}}import{createHash as Ht}from"node:crypto";function ce(r){return Ht("sha256").update(JSON.stringify(r.map(({path:e,ref:a,size:s})=>({path:e,ref:a,size:s})))).digest("hex")}function xt(r,e,a){return _(r)?{settings:Se(r),commit:a??ce(e),revisionKind:a===void 0?"listing":"commit",completed:[]}:void 0}function yt(r,e,a){let s=r.agentPages;if(!s)return;let t=a??s.listingEntries??r.entries,d=s.revisionKind??(s.commit===ce(s.listingEntries??r.entries)?"listing":"commit");if(d==="commit"&&e!==void 0&&s.commit!==e||d==="listing"&&s.commit!==ce(t))throw new Error("stale-agent-page");return s.commit}function Ct(r,e,a){e.ranked??=Q(r,e.scan,new Map);let s=new Map([...de(e.scan.plan),...Object.entries(e.agentPages?.actualSizes??{})]),t=ie(r,e.ranked,s,new Map,{files:{},...e.agentPages?{page:{commit:e.agentPages.commit,scope:e.root,continuation:a}}:{}});t.page&&(e.ranked={...e.ranked,agentPage:t.page,strong:t.strong,possible:t.window,notRead:t.notRead,notReadMore:t.notReadMore});let d=[...t.refused,...e.ranked.skippedFiles??[]];if(e.requestedPaths.push(...d.map(n=>n.path)),e.refused.push(...d),e.profile==="hosted-import"&&t.paths.length||t.page){let n=nt(r,[],t.paths,e.scan.plan);e.refused.push(...n.refused),e.profile==="hosted-import"?pt(e,n.selected):(lt(r,e),Z(e,n.selected))}else X(r,e,t.paths,e.scan.plan);e.phase=e.selected.length?"files":"done"}function Bt(r,e,a,s){let t={...e.agentPages.actualSizes};a.forEach((o,p)=>{s[p]!==null&&(t[o.path]=Buffer.byteLength(s[p]))}),e.agentPages={...e.agentPages,actualSizes:t};let d=new Map([...de(e.scan.plan),...Object.entries(t)]),n=new Map(Object.entries(e.files).map(([o,p])=>[o,Buffer.byteLength(p)])),f=new Set(e.skillReferencePaths),c=new Set([...e.conventionPaths,...dt(e),...f,...e.markerPath?[e.markerPath]:[]]);for(let o of a)if(c.has(o.path)&&t[o.path]!==void 0){let p=k(r,{path:o.path,size:t[o.path]},{purpose:f.has(o.path)?"skill":"pointer",route:"github",root:e.root,listing:new Set(e.entries.map(u=>u.path)),managedFiles:e.files}),i=Ge(n).left+(n.get(o.path)??0);p.admitted&&t[o.path]<=i?n.set(o.path,t[o.path]):e.refused.push({path:o.path,reason:p.admitted?"total":p.reason})}let m=ie(r,e.ranked,d,n),l=new Set(m.paths);a.forEach((o,p)=>{s[p]!==null&&(l.has(o.path)||c.has(o.path)&&n.has(o.path)?e.files[o.path]=s[p]:e.refused.push(m.refused.find(i=>i.path===o.path)??m.skippedFiles?.find(i=>i.path===o.path)??{path:o.path,reason:"total"}))}),e.ranked={...e.ranked,agentPage:m.page,strong:m.strong,possible:m.window}}function fe(r){let e=r.ranked,a=e?.agentPage;if(!a||r.phase!=="done")return;let s=[...e.agentInventory.strong,...e.agentInventory.possible],t=new Set(a.selected),d=new Set(a.refusals.map(c=>c.id)),n=s.filter(c=>t.has(D(c.prompt))&&!d.has(D(c.prompt))&&r.files[c.prompt.path]===void 0),f=[...a.refusals,...n.map(c=>({id:D(c.prompt),reason:r.refused.find(m=>m.path===c.prompt.path)?.reason??"missing"}))];r.ranked={...e,strong:e.strong.filter(c=>r.files[c.prompt.path]!==void 0),possible:e.possible.filter(c=>r.files[c.prompt.path]!==void 0),agentPage:{...a,refusals:f,partial:f.length>0,estimatedInputBytes:Object.values(r.files).reduce((c,m)=>c+Buffer.byteLength(m),0)}}}async function Mt(r,e,a){if(!y(r))return!1;let s=Be(r,e.entries.map(o=>o.path));if(!s.length)return!1;let t=new Set(s.flatMap(o=>o.agents)),d=new Map(e.selected.map(o=>[o.path,o])),n=new Set(e.selected.filter(o=>o.readBytes===void 0&&e.files[o.path]!==void 0).map(o=>o.path));e.managedReadPaths||(e.managedReadPaths=[],(e.scan||e.ranked)&&(delete e.scan,delete e.ranked,delete e.manifestReadPaths,e.phase!=="marker"&&(e.phase="scan")));let f=new Set([...e.managedReadPaths,...n]),c=e.entries.filter(o=>t.has(o.path)&&d.has(o.path)&&!f.has(o.path)),m=c.slice(0,A);if(!m.length)return!1;let l=await L(m,4,async o=>{let p=k(r,o,{...e.admission,purpose:"pointer",route:"github",root:e.root});return p.admitted?a(o):(e.refused.push({path:o.path,reason:p.reason}),null)});if(m.forEach((o,p)=>{l[p]!==null&&(e.files[o.path]=l[p],e.selected=e.selected.map(i=>i.path===o.path?o:i))}),e.managedReadPaths.push(...m.map(o=>o.path)),c.length>m.length){for(let o of Object.keys(e.files))!t.has(o)&&s.some(p=>Re(o,p.folder)!==null)&&delete e.files[o];e.cursor=0,(e.phase==="done"||e.phase==="manifest")&&(e.phase="files")}return!0}async function Lt(r,e,a){if(e.marketplacePlanned)return!1;let s=new Set(G(r,e.entries.map(o=>o.path)));if(!e.selected.some(o=>s.has(o.path)))return!1;let t=new Set(e.marketplaceReadPaths),n=e.selected.filter(o=>s.has(o.path)&&!t.has(o.path)).slice(0,A),f=await L(n,4,async o=>{let p=k(r,o,{...e.admission,purpose:"definition",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:o.path,reason:p.reason}),null;let u=(o.readBytes===void 0?e.files[o.path]:void 0)??await a({path:o.path,size:o.size,ref:o.ref});if(u===null)return null;let g=k(r,{path:o.path,size:Buffer.byteLength(u),text:u},{...e.admission,purpose:"definition",route:"github",root:e.root});return g.admitted?u:(e.refused.push({path:o.path,reason:g.reason}),null)});n.forEach((o,p)=>{f[p]!==null?e.files[o.path]=f[p]:delete e.files[o.path]}),e.marketplaceReadPaths=[...t,...n.map(o=>o.path)];let c=new Map(n.flatMap((o,p)=>f[p]===null?[]:[[o.path,Buffer.byteLength(f[p])]]));e.agentPages&&c.size&&(e.agentPages={...e.agentPages,listingEntries:e.agentPages.listingEntries??e.entries}),e.entries=e.entries.map(o=>c.has(o.path)?{...o,size:c.get(o.path)}:o);let m,l=e.marketplaceSelection?new Set(e.marketplaceSelection):void 0;do{let o=new Set(e.marketplaceReadPaths.filter(h=>e.files[h]===void 0)),p=e.entries.filter(h=>!o.has(h.path)&&(!l||l.has(h.path))),i=e.profile==="local-analysis"?Ke(r,p,e.root,{files:e.files}):Ue(r,p,e.root,{files:e.files,mode:e.marketplaceMode}),u="selected"in i?i.selected.map(h=>h.path):i.selectedPaths,g=new Set(u),P=new Map(p.map(h=>[h.path,h]));e.selected=u.map(h=>P.get(h)),e.selectionRefused=i.refused,e.hosted&&"selectedPaths"in i&&(e.hosted.fallback=i,e.hosted.codeMode||(e.hosted.needsExtraction=i.needsExtraction)),m=Object.keys(e.files).filter(h=>s.has(h)&&!g.has(h));for(let h of m)e.refused.push(i.refused.find(w=>w.path===h)??{path:h,reason:"total"});for(let h of Object.keys(e.files))g.has(h)||delete e.files[h]}while(m.length);return e.conventionPaths=$(r,e.entries.filter(o=>!s.has(o.path)||e.files[o.path]!==void 0).map(o=>o.path),e.root,{files:e.files}).files.filter(o=>o.role!=="reference").map(o=>o.path),e.cursor=0,e.marketplacePlanned=!e.selected.some(o=>s.has(o.path)&&!e.marketplaceReadPaths.includes(o.path)),n.length>0||!e.marketplacePlanned}function me(r,e){let{plan:a,entries:s}=e,t=a.profile==="local-analysis"?a.context.dir??"":e.root??"",d=a.readers.find(l=>l.id==="marker")?.claim.wants[0],n=a.readers.some(l=>l.id==="code-scan"),f=new Map(s.map(l=>[l.path,l])),c=a.profile==="local-analysis"?a.selection.selected:a.selection.selectedPaths.flatMap(l=>f.has(l)?[f.get(l)]:[]),m=He(r)?C(r,{phase:"start",root:t,paths:s.map(l=>l.path),scanFlag:!!d||n}):void 0;return{..._(r)?{agentPages:xt(r,s,e.commit)}:{},version:1,profile:a.profile,root:t,entries:s,selected:[...c],..."mode"in a?{marketplaceMode:a.mode}:{},..."selectionPaths"in a?{marketplaceSelection:a.selectionPaths}:{},conventionPaths:a.profile==="hosted-import"||_(r)?$(r,s.map(l=>l.path),t).files.filter(l=>l.role!=="reference").map(l=>l.path):[],...e.admission?{admission:e.admission}:{},selectionRefused:a.selection.refused,requestedPaths:[],refused:[],files:{},cursor:0,treeTruncated:e.treeTruncated??!1,...a.profile==="hosted-import"?{hosted:{fallback:structuredClone(a.selection),weakCodeFallback:r.CF_IMPORT_WEAK_CODE_FALLBACK!=="0",codeMode:!1,needsExtraction:a.selection.needsExtraction}}:{},decision:m??(d?{kind:"marker",markerPath:d,scanIfBare:n}:{kind:"settled",markerPath:null,markerKind:null,scan:n}),phase:d?"marker":n?"scan":"files"}}async function At(r,e,a){if(e.version!==1)throw new Error("unsupported-import-checkpoint");e.agentPages&&(r=e.agentPages.settings,yt(e,a.commit));let s=pe(r,e.profile),t={...e,selected:[...e.selected],files:{...e.files},requestedPaths:[...e.requestedPaths],refused:[...e.refused],...e.hosted?{hosted:{...e.hosted}}:{},...e.managedReadPaths?{managedReadPaths:[...e.managedReadPaths]}:{}},{read:d,requestedReads:n,skillReads:f}=Ot(s,t,o=>a.read(o));if(await Lt(s,t,d))return O(s,t,n);if(await Mt(s,t,d))return O(s,t,n);if(ft(s,t),t.phase==="done")return a.resolvedCode&&ct(t,a.resolvedCode),O(s,t,n);if(t.phase==="manifest")return await mt(s,t,d),fe(t),O(s,t,n);if(t.phase==="marker"&&t.decision.kind==="marker"){let o=t.decision,p=o.markerPath,i=t.entries.find(g=>g.path===p);if(t.profile==="hosted-import"){let g=k(s,i,{purpose:"pointer",route:"github",root:t.root});if(!g.admitted)return t.refused.push({path:p,reason:g.reason}),t.decision={kind:"settled",markerPath:null,markerKind:null,scan:o.scanIfBare},t.phase=o.scanIfBare?"scan":"files",O(s,t,n)}X(s,t,[p],t.entries);let u=await d(i);if(u!==null&&(t.files[p]=u),t.decision=C(s,{phase:"read",pending:o,text:u}),t.markerPath=p,t.markerKind=t.decision.markerKind,t.markerKind!=="bare"){let g=t.profile==="hosted-import"?await a.listing():{entries:t.entries,truncated:!1};t.treeTruncated||=g.truncated;let P=await ht(s,{config:qe(u).config,markerDir:p.split("/").slice(0,-1).join("/"),selected:t.profile==="hosted-import"?[]:t.selected,admission:{...t.admission,root:t.root||void 0},modelReader:!1,priorRefused:t.refused,refusalMode:"append",requestedMode:"kept-and-refused",listing:async()=>g.entries});if(t.requestedPaths.push(...P.requestedPaths),t.refused=P.refused,t.agentPages&&P.selected){let h=new Set(P.requestedPaths);t.conventionPaths=[...new Set([...t.conventionPaths,...P.selected.filter(w=>h.has(w.path)).map(w=>w.path)])]}t.profile==="hosted-import"?Z(t,P.selected??[]):P.selected&&(t.selected=P.selected)}if(t.phase=t.decision.scan?"scan":"files",t.profile!=="hosted-import"||t.markerKind!=="bare"||t.decision.scan)return O(s,t,n)}if(t.phase==="scan"){if(!t.scan){let o=ot(s,t.entries,t.root,!0,t.decision.kind==="settled"?t.decision.scanPaths:void 0);t.scan=o.state,t.refused.push(...o.refused)}if(!q(t.scan)){let o=await rt(s,t.scan,d,{modelReader:!1,alreadyRead:new Map,size:{batch:et,parallel:4}});t.scan=o.scan,o.selection&&(t.ranked=o.selection.ranked)}return q(t.scan)&&Ct(s,t),O(s,t,n)}if(oe(s))for(let o of t.skillReferencePaths??[])f.add(o);let c=t.selected.slice(t.cursor,t.cursor+A),m=c.filter(o=>t.files[o.path]===void 0),l=await L(m,4,d);if(t.agentPages&&t.ranked&&t.scan?Bt(s,t,m,l):m.forEach((o,p)=>{l[p]!==null&&(t.files[o.path]=l[p])}),t.cursor+=c.length,oe(s)){let o=Object.fromEntries(Object.entries(t.files).filter(([h])=>t.selected.some(w=>w.path===h&&w.readBytes===void 0))),p=De(s,{entries:t.entries,selected:t.selected,files:o,root:t.root,admission:t.admission,referencePaths:t.skillReferencePaths});t.refused=T(t.refused,p.refused);for(let h of p.refused)f.has(h.path)&&delete t.files[h.path];if(t.cursor<t.selected.length)return O(s,t,n);let i=new Map(t.selected.map(h=>[h.path,h])),u=p.paths.filter(h=>!i.has(h)||i.get(h).readBytes!==void 0),g=new Set(u.filter(h=>i.has(h)));t.cursor-=t.selected.slice(0,t.cursor).filter(h=>g.has(h.path)).length,t.selected=t.selected.filter(h=>!g.has(h.path));for(let h of g)delete t.files[h];t.requestedPaths.push(...u),u.length&&(t.skillReferencePaths=[...t.skillReferencePaths??[],...u]);let P=new Map(t.entries.map(h=>[h.path,h]));t.selected.push(...u.map(h=>{let w=P.get(h);return{path:h,size:w.size,ref:w.ref}})),it(t,u,"fallback")}return t.cursor>=t.selected.length&&(t.phase=ze(s)&&t.ranked||y(s)?"manifest":"done"),fe(t),O(s,t,n)}async function ee(r,e){let a=me(r,e),s;do s=await At(r,a,{listing:async()=>({entries:e.entries,truncated:!1}),read:e.read}),a=s.state;while(a.phase!=="done");let t={};return a.markerPath!==void 0&&(t.markerPath=a.markerPath,t.markerKind=a.markerKind),a.ranked!==void 0&&(t.ranked=a.ranked,t.scan=a.scan),{files:s.files,settled:s.settled,skippedFiles:s.refused,...t}}function Dt(r){return r.CF_IMPORT_PROPOSAL!=="0"}var Gt=new Set(["secret","secret-content","out-of-scope"]);async function Wt(r,e,a,s,t,d,n){let f={...e.admission,purpose:"proposal",route:"local-folder"},c=k(r,s??{path:a},f);if(!c.admitted)return{reason:c.reason};if(!s)return{reason:n??"missing"};if(s.size>d)return{reason:"allowance"};try{let m=t??await(e.proposalRead??e.read)({...s,readBytes:void 0});if(m===null)return{reason:n??"unreadable"};let l=Buffer.byteLength(m),o=k(r,{path:a,size:l,text:m},f);return o.admitted?l>d?{reason:"allowance"}:{text:m}:{reason:o.reason}}catch(m){return m instanceof W?{reason:m.reason,invalidates:Gt.has(m.reason)}:{reason:"unreadable"}}}async function $t(r,e,a,s,t){let d=new Set(s.map(i=>i.path)),n=new Set(t.map(i=>i.path)),f=new Map(e.entries.map(i=>[i.path,i])),c=s.map(i=>({...f.get(i.path),readBytes:void 0})),m=i=>!d.has(i.path)&&!n.has(i.path),l=[...e.selection.selected.filter(m),...c],o=s.length||t.length?{...e.selection,selected:l,totalBytes:l.reduce((i,u)=>i+(u.readBytes??u.size),0),refused:e.selection.refused.filter(i=>!d.has(i.path))}:e.selection,p=e.evidence??{};if(t.length){let i=e.entries.filter(w=>!n.has(w.path)),{ranked:u,scan:g,markerPath:P,markerKind:h}=await ee(r,{entries:i,admission:e.admission,read:async w=>Object.hasOwn(a,w.path)?a[w.path]:null,plan:Y(r,{profile:"local-analysis",listing:i,selection:o})});p={ranked:u,scan:g,markerPath:P,markerKind:h}}return{...p,files:a,selection:o,settled:[...e.settled.filter(m),...c],skippedFiles:(e.skippedFiles??[]).filter(i=>!d.has(i.path)),...t.length?{invalidated:t}:{}}}async function te(r,e,a={}){if(!a.explicitScope&&!Dt(r)||!e.proposal)return;let s={...e.files},t=new Map(e.entries.map(p=>[p.path,p])),d=new Map(e.unavailable?.map(p=>[p.path,p.reason])),n={},f=[],c=[],m=new Set,l=new Set(e.settled.filter(p=>p.readBytes===void 0).map(p=>p.path)),o=Object.values(s).reduce((p,i)=>p+Buffer.byteLength(i),0);for(let p of e.proposal.files){let i=Ut.normalize(p.path.replace(/\\/g,"/")),u=Object.hasOwn(s,i)?Buffer.byteLength(s[i]):0,g=!e.proposalRead&&l.has(i)&&Object.hasOwn(s,i)?s[i]:void 0,P=m.has(i)?{reason:"duplicate"}:await Wt(r,e,i,t.get(i),g,ve.codeAgent.importBytes-o+u,d.get(i));if(m.add(i),"text"in P)o+=Buffer.byteLength(P.text)-u,s={...s,[i]:P.text},c.push({...p,path:i});else{let h=P.reason==="wrong-type"?"coding-guide":P.reason;n[h]=(n[h]??0)+1,P.invalidates&&Object.hasOwn(s,i)&&(o-=u,delete s[i],f.push({path:i,reason:P.reason}))}}return{...await $t(r,e,s,c,f),proposal:{...e.proposal,files:c},rejectedByReason:n}}function It(r,e=[],a){return e.find(s=>Ve(s.key,a)===r.id)?.folder??ne(r.files.length?r.files.map(s=>s.path):[r.sourceRef?.path??"."])}function Yt(r,e,a,s){let t=new Set(r.flatMap(f=>f.files.map(c=>c.path))),d=new Set(e.flatMap(f=>f.files.map(c=>c.path))),n=e.map(f=>It(f,a,s));return f=>d.has(f)||!t.has(f)&&n.some(c=>c==="."||c===""||f.startsWith(`${c}/`))}function Jt(r,e,a){let s=Object.fromEntries(Object.entries(e.files).filter(([o])=>a(o))),t=e.selection.selected.filter(o=>Object.hasOwn(s,o.path)),d=e.settled.filter(o=>a(o.path)),n=e.selection.refused.filter(o=>a(o.path)),f=e.selection.readingNotes,c=f?{instruction:f.instruction.filter(a),code:f.code.filter(a),agents:f.agents.filter(a)}:void 0,m=M(r,c??{instruction:[],code:[],agents:[]},d),l={...e.selection,selected:t,refused:n,readingNotes:c,skippedNote:m,totalBytes:t.reduce((o,p)=>o+(p.readBytes??p.size),0)};return{files:s,selection:l,settled:d,skippedFiles:e.skippedFiles.filter(o=>a(o.path)),invalidated:e.invalidated?.filter(o=>a(o.path))}}function Vt(r,e,a,s=[],t){let d=a??ne([...e]),n=r.filter(l=>l.kind==="agent").map(l=>{let o=It(l,s,t),p=o==="."||o===""||d===o||d.startsWith(`${o}/`);return{node:l,overlap:new Set(l.files.filter(i=>e.has(i.path)).map(i=>i.path)).size,containment:p?o.split("/").filter(i=>i&&i!==".").length+1:0}}).filter(l=>l.overlap||l.containment);n.sort((l,o)=>o.overlap-l.overlap||o.containment-l.containment);let[f,c]=n,m=!!f&&f.overlap===c?.overlap&&f.containment===c?.containment;return{target:m?void 0:f?.node,overlapping:n.filter(l=>l.overlap).map(l=>l.node),tied:m?n.filter(l=>l.overlap===f.overlap&&l.containment===f.containment).map(l=>l.node):[]}}function Qt(r,e,a){let s=new Set(r.map(n=>n.path)),t=!!a&&!r.some(n=>n.path===a.path&&n.role==="system prompt"),d=t?r.filter(n=>n.path!==a.path).map(n=>n.role==="system prompt"||n.role==="soul"?{...n,role:"reference"}:n):[...r];return d.push(...e.filter(n=>!s.has(n.path)&&n.path!==a?.path).map(n=>({path:n.path,role:n.role==="tools"||n.role==="config"?n.role:"reference",label:null}))),t&&d.unshift({path:a.path,role:"system prompt",label:null}),{files:d,promptChanged:t}}function Xt(r,e){let a=new Map(r.map(s=>[s.label,s]));for(let s of e)a.has(s.label)||a.set(s.label,s);return[...a.values()]}function Zt(r,e,a,s,t){return s.filter(d=>d.role==="tools"&&(/\.json$/i.test(d.path)||be(d.path)==="js")).flatMap(d=>Ce(r,e,a.files,{toolsPath:/\.json$/i.test(d.path)?d.path:null,toolsTsPath:/\.json$/i.test(d.path)?null:d.path,cliPath:null,mcpPath:null},t))}function eo(r,e,a,s,t,d){let n=Qt(s?.files??[],a,t),c={...s??{id:Je("",e.ruleResult.fragment.nodes.map(m=>m.id),()=>{})("agent"),kind:"agent",desc:le(null,n.files,!1),meta:null,tools:[],sourceRef:null},label:e.proposalSources.proposal.agentName,files:n.files,tools:Xt(s?.tools??[],Zt(r,e.repoKey,e.proposalSources,a,d))};return n.promptChanged&&t&&(c.desc=le(t.path,n.files,!1),c.sourceRef={path:t.path,line:null}),{agent:c,promptChanged:n.promptChanged}}function to(r,e,a,s,t){let{target:d,overlapping:n,tied:f}=a,{fragment:c}=r,m=new Set([e.id,...(t?[...n,...f]:c.nodes).map(i=>i.id)]);for(let i=-1;i!==m.size;){i=m.size;for(let u of c.edges)m.has(u.from)&&m.add(u.to)}let l=c.nodes.filter(i=>m.has(i.id)).map(i=>i===d?e:i);d||l.push(e);let o=c.edges.filter(i=>m.has(i.from)&&m.has(i.to)),p=r.codeAgents?.filter(i=>m.has(i.unitKey)).flatMap(i=>i.unitKey!==d?.id?[i]:s?[]:[{...i,name:e.label,ownFiles:e.files}]);return{fragment:{...c,nodes:l,edges:o},...p?{codeAgents:p}:{}}}function oo(r,e,a){let s=new Set(e.map(n=>n.path)),t=new Set([...r.flatMap(n=>n.files.map(f=>f.path)),...s]),d=s.size;return{fromProposal:d,fromRulesOnly:t.size-d,rejected:Object.values(a).reduce((n,f)=>n+f,0),rejectedByReason:a}}function jt(r){return r.files.some(e=>e.role==="system prompt"||e.role==="soul")}function so(r,e,a){if(e.some(t=>t.kind==="agent"&&!jt(t)))return new Set;let s=new Set([V({code:"no-prompt",detail:"no-conventions"},r),V({code:"no-prompt"},r),V({code:"no-prompt",folderAgentsFound:!0},r)]);return a!==void 0&&s.add(Xe(r,{scanned:a})),s}function Tt(r,e){let{ruleResult:a,proposalSources:s,root:t,repoKey:d,scopes:n,scanned:f,agentChoice:c}=e,m=a,{files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=s,g=[...a.warnings],P=s.proposal.files.map(v=>({...v,path:x(v.path,t)})),h=P.find(v=>v.role==="prompt"),w=!1;if(P.length){let v=Vt(m.fragment.nodes,new Set(P.map(E=>E.path)),h?.path,n,t);if(v.target||h||e.explicitScope){let{agent:E,promptChanged:B}=eo(r,e,P,v.target,h,g),I=c?.kind==="choose_agent";m={...m,...to(a,E,v,B,I)},I&&({files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=Jt(r,s,Yt(a.fragment.nodes,m.fragment.nodes,n,t))),w=jt(E);let H=so(d,m.fragment.nodes,f);g=g.filter(F=>!H.has(F))}}return{...m,files:l,selection:o,settled:p,skippedFiles:i,invalidated:u,...c&&!w&&!e.explicitScope?{agentChoice:c}:{},warnings:g,proposalCounts:oo(m.fragment.nodes,P,s.rejectedByReason)}}async function _t(r,e){let a=re(r,{entries:e.entries,paths:e.scope});if(a.tooLarge.length||a.unavailable.length||a.groups.length>1)throw new Error("bad_request");let s=new Map(e.proposal?.files.map(f=>[f.path,f])),t={agentName:e.proposal?.agentName??e.repoKey,files:e.scope.map(f=>s.get(f)??{path:f,role:"other"})},d=await te(r,{...e,proposal:t,files:{},settled:[],skippedFiles:[],selection:{selected:[],refused:[],totalBytes:0}},{explicitScope:!0});if(!d)throw new Error("bad_request");if(d.proposal.files.length!==new Set(e.scope).size)throw new Error("unavailable");let n=re(r,{entries:e.entries.map(f=>Object.hasOwn(d.files,f.path)?{...f,size:Buffer.byteLength(d.files[f.path])}:f),paths:Object.keys(d.files),inputBytes:Object.fromEntries(Object.entries(d.files).map(([f,c])=>[f,Ie(f,c)]))});if(n.tooLarge.length||n.unavailable.length||n.groups.length>1)throw new Error("bad_request");return d}function ao(r,e,a){return e.filter(s=>k(r,s,{purpose:"listing",route:"local-folder",...a}).admitted)}function Qs(r){let e=[],a=!1,s=Promise.resolve();return t=>new Promise((d,n)=>{e.push({entry:t,resolve:d,reject:n}),!a&&(a=!0,queueMicrotask(()=>{let f=e;e=[],a=!1,s=s.then(async()=>{try{let c=await r(f.map(m=>m.entry));if(c.length!==f.length)throw new Error("bad_request");f.forEach((m,l)=>m.resolve(c[l]))}catch(c){f.forEach(m=>m.reject(c))}})}))})}async function Xs(r,e){let a=je(r),s=a===void 0?void 0:new Set(a),t=S=>e.localListing?ao(r,S,e.admission):S,d=a===void 0?t(e.entries):e.entries.filter(S=>s.has(S.path)),n=Y(r,{profile:"local-analysis",listing:d,selection:e.selection}),f=a===void 0?await ee(r,{entries:d,read:e.read,admission:e.admission,plan:n}):{files:{},settled:[],skippedFiles:[]},{files:c,settled:m,skippedFiles:l,...o}=f,p=a!==void 0?await _t(r,{...e,entries:e.entries,scope:a}):await te(r,{proposal:e.proposal,entries:d,read:e.read,proposalRead:e.proposalRead,admission:e.admission,files:c,settled:m,skippedFiles:l,selection:n.selection,unavailable:e.proposalRefusals,evidence:o}),{files:i,settled:u,skippedFiles:g}=p??f,P=z({...p??o,key:e.repoKey,files:i},n.context.flags,void 0,{markerPolicy:"any-read"}),h=p?.selection??n.selection,w;if(a===void 0&&ke(r)&&e.repository){let S=e.repository,j=await We(r,{selected:{files:i,listedPaths:d.map(b=>b.path),fallbackName:Ze(e),skills:!0},selection:h,codeAgentsFound:Qe(r,P?.resolved,i),port:e.localListing?{context:()=>S.context(),read:(b,R)=>S.read(b,R),finish:b=>S.finish?.(b),list:async()=>{let b=await S.list();return{...b,entries:t(b.entries)}}}:S}),qt=new Set(Object.keys(i).map(b=>x(b,j.root)));if(i=j.files,h=j.selection,w=j.root,w!==void 0){g=g.map(R=>({...R,path:x(R.path,w)})),u=u.map(R=>({...R,path:x(R.path,w)}));let b=new Set(u.map(R=>R.path));u.push(...h.selected.filter(R=>!b.has(R.path)&&Object.hasOwn(i,R.path)))}g=T(g,j.skippedFiles).filter(b=>qt.has(b.path)||!Object.hasOwn(i,b.path))}let v={repoKey:e.repoKey,files:i,listedPaths:d.map(S=>x(S.path,w)),...w!==void 0?{root:w}:{},forLocal:!0,code:P},E=K(r,v),B=N(r,E),I=e.includeAgentPromptPaths?Te({codeAgents:B.codeAgents??[],conventions:E.conventions,root:w}):void 0,H=_e(r,{codeAgents:B.codeAgents??[],conventions:E.conventions,root:w,selection:e.membership}),F=p?Tt(r,{ruleResult:B,proposalSources:{...p,files:i,selection:h,settled:u,skippedFiles:g,invalidated:p.invalidated?.map(S=>({...S,path:x(S.path,w)}))},root:w,repoKey:e.repoKey,scopes:E.conventions.agentScopes,scanned:P?.resolved?.scanned,agentChoice:H,explicitScope:a!==void 0}):void 0,{settled:Nt,invalidated:he,...ue}=F??{...B,settled:u,invalidated:void 0};F&&(i=F.files,h=F.selection,u=Nt,g=F.skippedFiles);let ge=h.readingNotes?M(r,h.readingNotes,u):h.skippedNote,Pe=F?F.agentChoice:H;return{...ue,...Pe?{agentChoice:Pe}:{},...I?{agentPromptPaths:I}:{},files:i,...w!==void 0?{root:w}:{},skippedFiles:he?.length?T(g,he):g,...F?{proposalCounts:F.proposalCounts}:{},warnings:[...new Set([...ue.warnings,...ge?[ge]:[],...U(g)])],selection:h}}var ro=new Set(ut);function ta(r,e){for(let s of[...Object.keys(e.set),...e.clear])if(!ro.has(s))throw new Error(`Unknown analysis field: ${s}`);let a={...r,...e.set};for(let s of e.clear)a[s]=void 0;return a}async function no(r,e,a){let s=Object.entries(e).map(([d,n])=>({path:d,size:Buffer.byteLength(n),ref:d})),t=tt(r,s,a.root,!1,a.scanPaths);for(;!q(t);)t=await st(t,async d=>e[d.path]??null);return{scan:Q(r,t),summary:at(t)}}async function zt(r,e,a){let{repoKey:s,root:t,agentConfigurations:d,codingGuides:n,forLocal:f}=a,c=a.flags??Ne(r),m=Object.keys(e),l=C(r,{phase:"start",paths:m,root:t,scanFlag:c.scan}),o=l.kind==="marker"?C(r,{phase:"read",pending:l,text:e[l.markerPath]??null}):l,p=o.kind==="off"?null:o.markerPath,i=o.kind==="off"?null:o.markerKind;if(o.kind==="off"||!o.scan){let v=z({key:s,files:e,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:v})),scanned:!1,resolved:null}}let{scan:u,summary:g}=await no(r,e,{repoKey:s,root:t,scanPaths:o.scanPaths}),P=z({key:s,files:e,ranked:u,scan:g,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:P})),scanned:!0,resolved:P.resolved}}async function Kt(r,e){let{state:a,settings:s}=r;if(!Pt(s,a).splitCheck||!a.splitEstimateBase)return{next:"inspecting",set:{repoCursor:0},clear:[]};let d=r.execution.preparation?.capUsd??a.splitEstimateBase.capUsd,n={...a.splitEstimateBase,capUsd:d};xe(n,e.progress.log);let f=bt(s,a),c={next:"inspecting",set:{repoCursor:0,splitCheckPriced:!0,splitFindingsPriced:!0},clear:["splitEstimateBase"]};if(!f.length)return c;let m=Ye(J(await e.instructions())),l=f.reduce((g,{inventory:P})=>g+se(Buffer.byteLength(Rt({tools:m},{...P,findings:[]}).prompt))+se(m.SHAPE_FINDINGS_INPUT_BYTES),0),o=n.lines.find(g=>g.label==="Scope check"),p=ae(s,{template:"scope-findings"},"Scope check",Ae.mechanical,(o?.inputTokens??0)+f.length*Et,(o?.outputTokens??0)+f.length*Ft),i=n.lines.map(g=>g.label==="Scope check"?p:g);o||i.push(p),i.push(ae(s,{template:"derive-shape"},"Split check",vt,l,f.length*$e));let u=Fe(i,d);return Ee(u)?(c.estimate=n,c.clear.push("splitCheckPriced","splitFindingsPriced"),delete c.set.splitCheckPriced,delete c.set.splitFindingsPriced,e.progress.log({level:"warn",code:"analysis.split_check_over_cap",counts:{totalUsd:u.totalUsd,capUsd:u.capUsd}}),c.set.warnings=[...a.warnings??[],Oe]):c.estimate=u,c}var Ba=async(r,e)=>{e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let{state:a,settings:s}=r,t=a.repos??[];await Le(s,a,e.readers);let d=a.repoCursor??0;if(d>=t.length)return Kt(r,e);let n=t[d],f=r.execution.forLocal,c=f?a.mapped?.[d]?{fragment:gt(a,d),warnings:[]}:await zt(s,n.files??{},{repoKey:n.key,root:n.root,agentConfigurations:n.agentConfigurations??{},forLocal:!0}):void 0,m=c?(()=>{let u=ye(c.fragment,n.key);return{...u,warnings:[...c.warnings,...u.warnings]}})():St(s,n,wt(s,a),a.modelReader??!1,a.projectAgents,J(await e.instructions()).bundleText("model-reader-runtime-prompt")),l=!f&&n.sourceReadNotes?M(s,n.sourceReadNotes,n.selected??[],n.root):void 0,o=f?[]:U((n.refused??[]).filter(u=>u.reason==="secret-content")),p="virtualFiles"in m?m.virtualFiles:void 0,i=[...a.mapped??[]];return i[d]=m.fragment,{next:"mapping",clear:[],set:{...p?{repos:t.map((u,g)=>g===d?{...u,files:{...u.files,...p}}:u)}:{},mapped:i,warnings:[...a.warnings??[],...l?[`${n.key}: ${l}`]:[],...o,...m.warnings,...kt(n)],repoCursor:d+1}}};export{Dt as a,ao as b,Qs as c,Xs as d,ta as e,Ba as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as i,d as n,e as c,f as l,g as a,h as u,i as f,j as h,l as d}from"./HHFDNY6V.js";import{d as s}from"./3MTXB4MK.js";import{a as S}from"./MZOKZ3N6.js";import{z as y}from"zod";function Q(e){let t=d(e),m=h(e);return{...t,headlinePlan(o){let r=t.analysisRequest(o),p=m.headlineFallbackQuestion();return{inputBytes:t.callInputBytes(r),fallbackQuestion:p,identity:{system:r.system,data:r.prompt,schema:y.toJSONSchema(r.schema),fallbackQuestion:p}}},modelReaderPrompt:()=>e.bundleText("model-reader-runtime-prompt"),validateShapeInput:o=>{a(e).shapeInputs(o)},...u(e),...n(e),...i(e),...s(e),...c(e),...l(e),...a(e),...f(e),...m,...S(e)}}export{Q as a};
|
|
@@ -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"./FRXOQ2M6.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"./YTHF2E2S.js";import{Fb as x}from"./2AASSZRO.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,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"./FRXOQ2M6.js";import{b as st}from"./33IGHOYT.js";import{e as te,g as Ce}from"./YTHF2E2S.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"./4PT5C4IT.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"./2AASSZRO.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,6 @@
|
|
|
1
|
+
import{Ha as O,Ka as F,Qa as $}from"./2AASSZRO.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,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"./YTHF2E2S.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"./4PT5C4IT.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"./2AASSZRO.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
|
+
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,14 @@
|
|
|
1
|
+
import{a as M}from"./Y7JGSUOA.js";import{d as J}from"./3MTXB4MK.js";import{j as U}from"./4RXRAB5S.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"./YTHF2E2S.js";import{b as P}from"./6YCABS5T.js";import{a as N,b as v,c as D,d as $}from"./JEWBPIQI.js";import{a as E,b as R}from"./MJGB25S5.js";import{d as A}from"./RQTNTIR4.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{m as O}from"./CTLHKFPH.js";import{a as N}from"./326F4XNG.js";import{b as F}from"./HCPO6QPU.js";import{a as P}from"./MKYLK6DB.js";import{e as x}from"./C6X5GDG4.js";async function H(S,t){let a={entriesVisited:0,filesRead:0,bytesRead:0,truncated:!1},d=[],R=()=>({files:t.selected.files,selection:t.selection,skippedFiles:F(d),search:a});if(O(S,{selected:t.selected,codeAgentsFound:t.codeAgentsFound}).kind==="none")return R();let h=await t.port.context();if(!h)return R();let E=[];try{let r=e=>x(e,h.selectedRoot),L=e=>Object.fromEntries(Object.entries(e).map(([c,I])=>[r(c),I])),A={...t.selected,files:L(t.selected.files),root:h.selectedRoot,...t.selected.listedPaths?{listedPaths:t.selected.listedPaths.map(r)}:{},...t.selected.pointerFiles?{pointerFiles:L(t.selected.pointerFiles)}:{},...typeof t.selected.explicitPrompt=="string"?{explicitPrompt:r(t.selected.explicitPrompt)}:{}},l=await t.port.list();a.entriesVisited=l.entriesVisited,a.truncated=l.truncated;let w=new Map(l.entries.map(e=>[e.path,e])),u=new Set,p={},m=P.codeScan,b=()=>O(S,{selected:A,codeAgentsFound:t.codeAgentsFound,entries:l.entries,bodies:p,attemptedPaths:[...u],completeListing:!l.truncated}),n=b();for(;n.kind==="search"&&n.paths.length;){let e=[],c=0;for(let s of n.paths){let i=w.get(s);if(i.size>m.fileBytes){d.push({path:s,reason:"too-large"}),u.add(s);continue}let o=i.size+1;if(e.length>=4||a.filesRead+e.length>=m.files||a.bytesRead+c+o>m.bytes)break;e.push({entry:i,allowance:o}),c+=o}if(!e.length){if(n=b(),n.kind==="none"||!n.paths.length)break;a.truncated=!0,d.push(...n.paths.map(s=>({path:s,reason:"scan-limit"})));break}(await N(e,4,async({entry:s,allowance:i})=>{u.add(s.path),a.filesRead++;try{return await t.port.read(s,i)}catch(o){if(o instanceof Error&&o.name==="AbortError")throw o;return{text:null,bytesRead:i,refusal:"unreadable"}}},{settleStartedOnError:!0})).forEach((s,i)=>{let{entry:o,allowance:k}=e[i],z=Number.isSafeInteger(s.bytesRead)&&s.bytesRead>=0&&s.bytesRead<=k;a.bytesRead+=z?s.bytesRead:k,z&&s.text!==null&&!s.refusal&&s.bytesRead<=m.fileBytes&&s.bytesRead<k&&Buffer.byteLength(s.text)===s.bytesRead?p[o.path]=s.text:d.push({path:o.path,reason:s.refusal??"unreadable"})}),n=b()}let g=b();if(g.kind==="none"||!g.ownedPaths.length)return R();let f={...A.files};for(let e of g.ownedPaths)Object.hasOwn(p,e)&&(f[e]=p[e]);let v=e=>({...e,path:r(e.path),...e.ref===e.path?{ref:r(e.ref)}:{}}),B=t.selection.selected.map(v),M=new Set(B.map(e=>e.path)),j=g.ownedPaths.filter(e=>!M.has(e)&&Object.hasOwn(f,e)).map(e=>({...w.get(e),path:e,size:Buffer.byteLength(f[e]),ref:w.get(e)?.ref??e})),y=t.selection.readingNotes,V={files:f,root:h.selectedRoot,search:a,skippedFiles:F(d),selection:{...t.selection,selected:[...B,...j],totalBytes:t.selection.totalBytes+j.reduce((e,c)=>e+c.size,0),refused:t.selection.refused.map(e=>({...e,path:r(e.path)})),...y?{readingNotes:{instruction:y.instruction.map(r),code:y.code.map(r),agents:y.agents.map(r)}}:{}}};return E=Object.keys(f),V}finally{t.port.finish?.(E)}}export{H 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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as a,c as m}from"./NXHVBJL4.js";import{a as u}from"./MJGB25S5.js";import{d}from"./RQTNTIR4.js";import{h as c}from"./LMUXOKIM.js";import{a as l}from"./INVTU73D.js";function k(e,i={},o){let p={data:l(i)&&(e.answerFormat==="check"||e.answerFormat==="opinion")?{...e.inputs,findingActivityEnabled:!0}:e.inputs,settings:c(i),...o===void 0?{}:{maxInputBytes:o}};return d.parse({...e,answerFormat:Object.hasOwn(r,e.template)?g(e.template,e.answerFormat,i):e.answerFormat,limits:{...e.limits,promptCache:u(i,{template:e.template},e.model).enabled},inputs:JSON.parse(JSON.stringify(p))})}var n=(e,...i)=>Object.freeze({role:e,answerFormats:Object.freeze(i)}),s=m().map(e=>e.name),r=Object.freeze({"derive-findings":n("required",...s),"derive-findings-legacy":n("required",...s),"derive-findings-no-outcome":n("required",...s),"derive-findings-legacy-no-outcome":n("required",...s),"benchmark-judge":n("required","judge"),"judge-code-prompt":n("optional","codeJudge"),"derive-structure":n("optional","structures"),"structure-recheck":n("optional","recheck"),"derive-shape":n("optional","shape"),"scope-items":n("optional","structureScope"),"scope-findings":n("optional","scope"),"check-findings":n("optional","check"),"check-findings-precision-v1":n("optional","check"),"second-opinion":n("optional","opinion"),"explain-sources":n("optional","sourceNotes"),"finding-headlines":n("optional","findingHeadlines")});function A(){return r}function S(e,i,o){let t=o??(e==="derive"?"derive-findings":"check-findings");if(!Object.keys(r).filter(f=>r[f].answerFormats.includes(e==="derive"?"findings":"check")).includes(t))throw new Error("Unknown analysis template");return e==="derive"&&!a(i).switches.expectedOutcome&&!t.endsWith("-no-outcome")?`${t}-no-outcome`:t}function g(e,i,o){let t=i==="findings"?a(o).name:i;if(!Object.hasOwn(r,e)||!r[e].answerFormats.includes(t))throw new Error("Unsupported template answer format");return t}function E(e,i,o){if(o(i),!Object.hasOwn(r,e)||r[e].role!=="optional")throw i}export{k as a,A as b,S as c,g as d,E as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./PBHHWFR6.js";import{C as p}from"./4PT5C4IT.js";import{a as y}from"./MKYLK6DB.js";import{posix as d}from"node:path";var m=Object.freeze({totalLimitBytes:y.codeAgent.importBytes,instructionLimitBytes:y.sourceFetch.instructionBytes}),A=["totalBytes","instructionBytes","fileCount"],u=()=>new Error("Invalid analysis size"),z=e=>typeof e=="number"&&Number.isSafeInteger(e)&&e>=0;function g(e){let i=a(e);return i.totalBytes>m.totalLimitBytes?{fits:!1,measure:"total_text"}:i.instructionBytes>m.instructionLimitBytes?{fits:!1,measure:"instruction_text"}:{fits:!0,measure:null}}function v(e,i,n={}){return h(e,i,n,!1)}function b(e,i,n={}){return h(e,i,n,!0)}function h(e,i,n,c){let f=new Map;for(let t of i){if(!z(t.size)||typeof t.path!="string"||!t.path||t.path.includes("\0"))throw u();let s=d.normalize(t.path.replace(/\\/g,"/"));if(s==="."||s===".."||s.startsWith("../")||s.startsWith("/"))throw u();let r=f.get(s);if(r&&r.size!==t.size)throw u();f.set(s,{path:s,size:t.size,ref:s})}let S=[...f.values()],{descriptions:B}=p(e,S,n,{measureAnalysisSize:!0,measureAnalysisSizeLowerBound:c}),l=n.paths?new Set(n.paths):void 0,o={totalBytes:0,instructionBytes:0,fileCount:0};for(let t of B){if(!(c?t.countsTowardAnalysisSizeWithoutInventory:t.countsTowardAnalysisSize)||l&&!l.has(t.entry.path))continue;let{entry:s}=t;if(o.totalBytes+=s.size,(c?t.countsTowardInstructionSizeWithoutInventory:t.analysisPool==="instruction")&&(o.instructionBytes+=s.size),o.fileCount+=1,!A.every(r=>z(o[r])))throw u()}return a(o)}export{m as a,g as b,v as c,b as d};
|