@counterfact-labs/cli 0.2.7 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/entry-files.js +5 -2
- package/dist/adapters/entry-packing.js +161 -0
- package/dist/adapters/entry-selection.js +13 -1
- package/dist/adapters/files.js +110 -5
- package/dist/adapters/git.js +10 -1
- package/dist/adapters/release.js +4 -1
- package/dist/adapters/results.js +9 -2
- package/dist/adapters/selection.js +19 -9
- package/dist/adapters/settings.js +37 -6
- 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/2CWULBP2.js +1 -0
- package/dist/analysis-core/chunks/2M55DR2J.js +35 -0
- package/dist/analysis-core/chunks/34NVU26H.js +1 -0
- package/dist/analysis-core/chunks/{RNTMH4MU.js → 5BTATES5.js} +1 -1
- package/dist/analysis-core/chunks/5UWDUYHF.js +1 -0
- package/dist/analysis-core/chunks/{6RWEWBHK.js → 5VQ4VYIP.js} +1 -1
- package/dist/analysis-core/chunks/66JRJPJC.js +1 -0
- package/dist/analysis-core/chunks/6JTHFDH3.js +1 -0
- package/dist/analysis-core/chunks/6VHZNBII.js +19 -0
- package/dist/analysis-core/chunks/6YCABS5T.js +1 -0
- package/dist/analysis-core/chunks/C77LGCKF.js +1 -0
- package/dist/analysis-core/chunks/CNQZLSAP.js +1 -0
- package/dist/analysis-core/chunks/DHVEGIU6.js +1 -0
- package/dist/analysis-core/chunks/HCPO6QPU.js +1 -0
- package/dist/analysis-core/chunks/I4F56VMG.js +1 -0
- package/dist/analysis-core/chunks/INVTU73D.js +1 -0
- package/dist/analysis-core/chunks/{6B2HILSY.js → JAPVLU4Z.js} +1 -1
- package/dist/analysis-core/chunks/KBTM5MBC.js +14 -0
- package/dist/analysis-core/chunks/LFJQ4YLP.js +3 -0
- package/dist/analysis-core/chunks/M5YWJY7P.js +1 -0
- package/dist/analysis-core/chunks/MKYLK6DB.js +1 -0
- package/dist/analysis-core/chunks/N2L4JMJE.js +1 -0
- package/dist/analysis-core/chunks/NCW5LJ5O.js +6 -0
- package/dist/analysis-core/chunks/P253B344.js +7 -0
- package/dist/analysis-core/chunks/PBHHWFR6.js +1 -0
- package/dist/analysis-core/chunks/Q5WR6B2H.js +2 -0
- package/dist/analysis-core/chunks/QPIBHTON.js +67 -0
- package/dist/analysis-core/chunks/QVXARKP7.js +1 -0
- package/dist/analysis-core/chunks/SJESFYBA.js +10 -0
- package/dist/analysis-core/chunks/SP6XFHNH.js +1 -0
- package/dist/analysis-core/chunks/TA2NIQAY.js +1 -0
- package/dist/analysis-core/chunks/UKX3A6AX.js +1 -0
- package/dist/analysis-core/chunks/VC3PYT2B.js +1 -0
- package/dist/analysis-core/chunks/VDUFPTDD.js +1 -0
- package/dist/analysis-core/chunks/VWRFSVLI.js +1 -0
- package/dist/analysis-core/chunks/VX6LYNXV.js +1 -0
- package/dist/analysis-core/chunks/W73WF226.js +1 -0
- package/dist/analysis-core/chunks/{FBTOOUPL.js → XVGLY4EO.js} +1 -1
- package/dist/analysis-core/chunks/YWL52FVW.js +2 -0
- package/dist/analysis-core/contracts/analysis-selection.js +1 -1
- 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/relay-analysis.js +1 -1
- package/dist/analysis-core/contracts/requests.js +1 -1
- 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 -1
- 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 +47 -5
- package/dist/cli/api.js +1 -1
- package/dist/cli/commands/analyze.js +55 -15
- package/dist/cli/commands/skipped.js +65 -0
- package/dist/cli/context.js +2 -1
- package/dist/cli/finding-display.js +102 -7
- package/dist/cli/finding-settings.js +3 -1
- package/dist/cli/intake-payload.js +25 -2
- package/dist/cli/main.js +21 -7
- package/dist/cli/mcp-failure.js +6 -5
- package/dist/cli/mcp.js +134 -28
- package/dist/cli/relay-check.js +103 -23
- package/dist/cli/relay-failure.js +4 -4
- package/dist/cli/relay-preparation.js +47 -9
- package/dist/cli/result-check.js +31 -12
- package/dist/cli/saved-results.js +10 -0
- package/dist/cli/scope-choices.js +3 -3
- 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 +31 -5
- package/dist/contract/cli-version.js +1 -1
- package/dist/contract/console-url.js +3 -0
- package/dist/contract/console.js +17 -38
- 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 +31 -11
- package/dist/contract/selection-offer.js +5 -8
- package/dist/gatekeeper/cli-api.js +70 -4
- package/dist/gatekeeper/console.js +8 -3
- package/dist/gatekeeper/model.js +5 -23
- package/dist/gatekeeper/trust/policy.js +2 -1
- package/package.json +4 -2
- 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/2PZF54KH.js +0 -10
- package/dist/analysis-core/chunks/6U2IR4XB.js +0 -1
- package/dist/analysis-core/chunks/7NEWZ74F.js +0 -1
- package/dist/analysis-core/chunks/CGCJN73D.js +0 -14
- package/dist/analysis-core/chunks/CWYVUGG4.js +0 -1
- package/dist/analysis-core/chunks/FSLWD2PE.js +0 -1
- package/dist/analysis-core/chunks/GOQVKWP3.js +0 -32
- package/dist/analysis-core/chunks/IHAVDX4L.js +0 -66
- package/dist/analysis-core/chunks/IVULXWQN.js +0 -21
- package/dist/analysis-core/chunks/K2GNDX3W.js +0 -1
- package/dist/analysis-core/chunks/K5FUABWW.js +0 -1
- package/dist/analysis-core/chunks/KGQYR62R.js +0 -7
- package/dist/analysis-core/chunks/KWECQJ6X.js +0 -1
- package/dist/analysis-core/chunks/PY5M22CL.js +0 -1
- package/dist/analysis-core/chunks/PYKAERZZ.js +0 -1
- package/dist/analysis-core/chunks/SLJ6CW7W.js +0 -1
- package/dist/analysis-core/chunks/UEORNVQB.js +0 -1
- package/dist/analysis-core/chunks/WYLIV2P2.js +0 -1
- package/dist/analysis-core/data/finding-types.js +0 -1
- /package/dist/analysis-core/chunks/{SKVEBOGA.js → 33EUZF25.js} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import{b as nn}from"./74FPPPIG.js";import{a as Fe}from"./MKYLK6DB.js";import{d as ho,e as ht}from"./5TATKWLG.js";import{f as ko}from"./JKWTHRUR.js";import{g as tn}from"./JAPVLU4Z.js";import{a as dt}from"./I4F56VMG.js";import{b as fo,d as Ht,e as uo}from"./33EUZF25.js";import{c as rn,d as sn,e as wt,g as wo}from"./YUY436SM.js";import{a as De,c as N,d as go,e as Be}from"./C6X5GDG4.js";import{a as ao,b as qt,c as co}from"./724WZMYW.js";import{a as G,b as S,c as _,d as J,e as Te,f as B,g as gt,h as Ne,i as he,j as Zt,k as I,l as T,m as mo,n as xe,o as z,p as Ve,q as ie,r as So,s as ee,t as Qt,u as q,v as U,w as te,x as yo,y as St}from"./YWL52FVW.js";import{a as W,b as po,d as xt,e as xo,f as ue}from"./SJESFYBA.js";import{a as kt}from"./INVTU73D.js";import{a as on}from"./A7WJJMRY.js";import{a as yt}from"./Q5WR6B2H.js";import{b as en}from"./VDUFPTDD.js";function bt(e,t,n){let o=e.split(`
|
|
2
|
+
`),r=Math.min(Math.max(t-1-3,0),o.length-1),s=0;for(let i=0;i<r;i++)s+=o[i].length+1;return{text:e.slice(s,s+n),fromLine:r+1}}var bo=/(^|\/)(?:(?:\.cursor|\.windsurf|\.claude|\.roo)\/rules\/|\.clinerules\/|\.junie\/guidelines\.md$|\.kiro\/steering\/|\.github\/instructions\/.*\.instructions\.md$)/;function Se(e){let t=e.toLowerCase(),n=t.split("/").pop();return["claude.md","agents.md","gemini.md",".cursorrules",".windsurfrules",".clinerules","copilot-instructions.md"].includes(n)||/^(claude|agents|gemini)\.(local|override)\.md$/.test(n)||bo.test(t)}function na(e){let t=e.toLowerCase();return t.includes("/")?t===".github/copilot-instructions.md"||bo.exec(t)?.index===0:Se(t)}function oa(e,t){return+(e.toLowerCase()==="agents.md")-+(t.toLowerCase()==="agents.md")||e.localeCompare(t)}var Xe=["claude.md","agents.md"];function vs(e){return!We(e)&&e.CF_CONFIGURATION_GUIDE_PROMPT!=="0"}function We(e){return e.CF_IMPORT_GUIDES_AS_PROMPT==="1"}function _o(e,t,n=!1){return n||We(e)||!Se(t)}function Eo(e,t){return We(e)?Xe.includes(t.toLowerCase()):Se(t)}function Ro({codeAgentsFound:e,folderAgentsFound:t=!1,otherDefinitions:n,agentConfiguration:o=!1,usage:r="import"},s){return We(s)?t?"background":r==="scan"?n?"prompt":"background":r==="map"?e?"background":"prompt":e&&!n?"background":"prompt":vs(s)&&o&&!e&&!t?"prompt":"background"}var $s=/\.(ts|tsx|js|jsx|mjs|cjs|py|go|rs|rb|java|kt|swift|c|cc|cpp|h|hpp|cs|php|sh|bash|zsh|ps1|sql|tf|hcl|lock|toml|gradle)$/i,As=/\.(md|mdx|txt|json|ya?ml)$/i,Ls=/^(licen[cs]e.*|copying|notice|authors|codeowners|readme|changelog|\.gitignore|\.gitattributes|\.editorconfig|\.gitkeep|\.nvmrc|\.python-version|\.tool-versions|\.prettierrc|\.npmignore|\.dockerignore)$/i;function ln(e){return $s.test(e.trim())}function ia(e){return!ln(e)&&As.test(e.trim())}function la(e){let t=e.trim();return!Se(t)&&!Ls.test(t.split("/").at(-1))&&!/\.(md|mdx|txt|text|jsonl?|ndjson|csv|tsv|pdf|rst|adoc|ini|cfg|ya?ml|toml|lock|png|jpe?g|gif|svg|ico|webp|avif|bmp|tiff?)$/i.test(t)}function vo(e){return{salesforce:"Salesforce",slack:"Slack",s3:"S3",anthropic:"Anthropic","http-client":"HTTP client"}[e.toLowerCase()]??e}function $o(e){let t=new Map;for(let n of e)!n.unitKey||!n.scope||(t.has(n.scope)||t.set(n.scope,new Map),t.get(n.scope).set(n.unitKey,n.id));return e.flatMap(n=>!n.unitKey||!n.scope?[]:(n.links??[]).flatMap(o=>{let r=t.get(n.scope)?.get(o.to);return r?[{from:n.id,to:r,kind:"invokes",label:o.kind,sourceRef:o.source??null}]:[]}))}function _t(e){return e.CF_IMPORT_CALLS==="1"}function ye(e){return e.CF_IMPORT_LAYOUTS==="1"}import{relative as Zs,sep as Qs}from"node:path";function ne(e,t){return e.CF_IMPORT_COVERAGE==="1"&&(t===void 0||e[t]==="1")}function V(e){return ne(e,"CF_IMPORT_LAYOUTS")}var Et=["eval","evals"],Ps=new RegExp(`(^|/)(${[...Et,"evaluations?","bench(?:mark)?s?"].join("|")})/`,"i"),Os=/^(evals?|bench(?:mark)?s?)[_-].+|.+[._-](evals?|bench(?:mark)?s?)[._-]/i;function Ao(e,t){if(Ps.test(e))return!0;let n=W(e);if((n||/\.(json|ya?ml|toml)$/i.test(e))&&Os.test(e.split("/").at(-1)))return!0;if(!n||t===void 0||!/(^|\/)scripts\//i.test(e))return!1;let o=G(e,t,n),{toks:r}=o;if(r.some((u,d)=>_(u,"export")||_(u,"exports")||n==="py"&&_(u,"def")||_(u,"module")&&S(r[d+1],".")&&_(r[d+2],"exports"))||!r.some(u=>_(u)&&/^(expected|dataset|fixtures|cases)$/i.test(u.text)))return!1;let s=r.flatMap((u,d)=>_(u)&&S(r[d+1],"(")&&!["for","if","while","switch","catch"].includes(u.text)&&!["function","def","class"].includes(r[d-1]?.text)?[d]:[]),l=z(o).filter(u=>u.names.some(d=>s.some(m=>_(r[m],d)&&!S(r[m-1],".")))),a=/(^|[/._-])(scores?|scoring|graders?|grading|evals?|evaluators?|bench(?:mark)?s?)([/._-]|$)/i,c=l.filter(u=>u.source.startsWith(".")&&/(^|[/._-])(agents?|runners?)([/._-]|$)/i.test(u.source)),p=[...c,...l.filter(u=>a.test(u.source))],f=new Set(p.flatMap(u=>u.names));return s.some(u=>S(r[u-1],".")?!(_(r[u-2],"console")&&["log","table"].includes(r[u].text)):_(r[u],"require")&&r[u+2]?.kind==="string"&&p.some(d=>d.source===r[u+2].value)?!1:!f.has(r[u].text)&&!(n==="py"&&_(r[u],"print")))?!1:l.some(u=>a.test(u.source))&&c.some(u=>!a.test(u.source))}var Oo=/(^|\/)(__tests__|__snapshots__)\/|\.(test|spec)\.[jt]sx?$|_test\.(go|py)$/i,an=new Set(["test","tests","__tests__","spec","specs","testdata","test-data","test_data","test-support","mocks","fixtures","fixture","__fixtures__","__mocks__","__snapshots__"]),Io=/^(examples?|samples?)(?:[-_].+)?$|^.+[-_](examples?|samples?)$/i,Mo=/\.(test|spec)\..+|^test_.*\.py$|_test\.(py|go)$|_spec\.rb$|^conftest\.py$/i,Is=new Set([...an].filter(e=>!["test","tests","__tests__","spec","specs"].includes(e))),Ms=new Set([".github","cassettes"]),Cs=new Set,Lo=new WeakMap;function vt(e){if(!ne(e))return[];let t=Lo.get(e);if(t)return t;let n=[];try{let o=JSON.parse(e.CF_IMPORT_SCOPES??"[]");Array.isArray(o)&&o.every(r=>{if(!r||typeof r!="object"||!["runtime","example","evaluator"].includes(r.kind)||typeof r.path!="string")return!1;let s=r.path.endsWith("/**"),i=s?r.path.slice(0,-3):r.path;return!!i&&!/[\\\0:*?]/.test(i)&&!i.split("/").some(l=>!l||l==="."||l==="..")&&!(r.kind==="evaluator"&&s)})&&new Set(o.map(r=>r.path)).size===o.length&&(n=Object.freeze(o.map(({path:r,kind:s})=>Object.freeze({path:r,kind:s}))))}catch{}return Lo.set(e,n),n}function ke(e,t,n){let o=N(t,n);if(o===null)return;let r=vt(e).filter(l=>l.path.endsWith("/**")?t.startsWith(l.path.slice(0,-2)):t===l.path).sort((l,a)=>a.path.replace(/\/\*\*$/,"").length-l.path.replace(/\/\*\*$/,"").length)[0];if(!r||r.kind==="runtime")return;let s=o.split("/"),i=s.pop();if(!(s.some(l=>Is.has(l.toLowerCase())||Ms.has(l.toLowerCase()))||/^conftest\.py$/i.test(i))&&!(r.kind==="example"&&(Mo.test(i)||s.some(l=>an.has(l.toLowerCase())))))return r}function cn(e,t,n={}){return!vt(e).some(r=>r.kind!=="runtime"&&(N(r.path,n.root)!==null||r.path.endsWith("/**")&&N(`${De(n.root)}/`,r.path.slice(0,-3))!==null))||ke(e,t,n.root)?!1:Rt(t,{root:n.root??void 0,listing:n.listing??Cs})!==null}var js=new Set(["example-agents","examples","example","fixtures","__fixtures__","testdata","test","tests","__tests__","demo","demos"]),Ts=/^examples?[-_]/i;function Co(e,t,n){if(e.CF_IMPORT_INCLUDE_EXAMPLES==="1"||ke(e,t,n))return!1;let o=ne(e),r=i=>js.has(i.toLowerCase())||Ts.test(i)||o&&(i.toLowerCase()==="fixture"||Io.test(i));if(De(n).split("/").some(r))return!1;let s=N(t,n);return s!==null&&s.split("/").slice(0,-1).some(r)}var Po=new WeakMap;function Ns(e){let t=Po.get(e);if(t)return t;let n={exact:new Set,foldedNames:new Set};for(let o of e.keys()){let r=0;for(let s=o.indexOf("/");s!==-1;s=o.indexOf("/",r))n.exact.add(o.slice(0,s)),n.foldedNames.add(o.slice(0,r)+o.slice(r,s).toLowerCase()),r=s+1}return Po.set(e,n),n}function Fs(e,t,n){let o=e.some(r=>Rt(t(r),n)===null);return r=>{if(n.settings&&ke(n.settings,r,n.root))return!1;if(n.settings&&cn(n.settings,r,n))return!0;let s=Rt(r,n);return s==="test"||s==="example"&&o}}function jo(e,t,n){let o=Fs(e,t,n),r=[],s=[];for(let i of e)(o(t(i))?s:r).push(i);return{kept:r,skipped:s}}function fn(e,t){return Rt(e,t)!==null}function Rt(e,t){let n=N(e,t.root);return n?Ds(e,n,t):null}function Ds(e,t,n){let o=Ns(n.listing),r=e.endsWith("/")||o.exact.has(e),s=t.split("/").filter(Boolean),i=r?"":s.pop()??"";return Mo.test(i)||s.some(a=>an.has(a.toLowerCase()))?"test":s.some((a,c)=>{let p=a.toLowerCase();if(Io.test(p))return!0;if(p!=="before"&&p!=="after")return!1;let f=De(Be(s.slice(0,c).join("/"),n.root)),u=f?`${f}/`:"",d=p==="before"?"after":"before";return o.foldedNames.has(u+d)})?"example":null}var Bs=new Set,To=new WeakMap;function No(e,t){let n={root:t.root,listing:t.listing??Bs};if(!fn(e,n))return!1;let o=t.listing;if(!o?.has(e))return!0;let r=To.get(o);r||To.set(o,r=new WeakMap);let s=r.get(t.settings);s||r.set(t.settings,s=new Map);let i=s.get(t.key);if(!i){let l=[...o.keys()].filter(a=>fn(a,n)||t.readable(a,"get"in o?o.get(a):void 0));i=new Set(jo(l,a=>a,n).skipped),s.set(t.key,i)}return i.has(e)}function Fo(e){return e.CF_IMPORT_EXAMPLE_FILTER!=="0"}import{posix as un}from"node:path";var pn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function le(e,t={}){let n=`(?:${Je.map(pn).join("|")})`,o=`(?:${$t.map(pn).join("|")})`,s=new RegExp(`^(${t.nested?"(?:.*?/)??":""}(?:(${n}/[^/]+)/${we}|${o})/([^/]+))/(.+)$`,t.caseSensitive?"":"i").exec(e);if(!s)return null;let i=t.caseSensitive?s[4]:s[4].toLowerCase(),l=t.caseSensitive?F.skill:F.skill.toLowerCase();return{folder:s[1],name:s[3],definition:i===l,reference:i.startsWith("references/"),...s[2]?{ownerPath:s[1].replace(/\/skills\/[^/]+$/i,".md")}:{}}}function mn(e){return le(e)?.reference??!1}function Ws(e){return ne(e,"CF_DISCOVERY_SKILLS")}function Ks(e){return!/[\\:\0]/.test(e)&&e.split("/").every(t=>t&&t!=="."&&t!=="..")}function Us(e){let t=[],n;for(let[o,r]of e.split(/\r?\n/).entries()){let s=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(r);if(n){if(s&&s[1][0]===n.marker[0]&&s[1].length>=n.marker.length&&!s[2].trim()){n=void 0;continue}if(!n.shell||!/^\s*(?:\$\s+)?(?:cat|less|more|head|tail)\s+/.test(r))continue}if(!n&&s){n={marker:s[1],shell:/^(?:sh|bash|shell|console)?$/i.test(s[2].trim())};continue}let i=/!?\[[^\]\n]*\]\(\s*(?:<([^>\n]+)>|([^\s)\n]+))(?:\s+["'][^"'\n]*["'])?\s*\)|^\s*\[[^\]]+\]:\s*(?:<([^>]+)>|(\S+))|`([^`\n]+)`|([^\s`<>"'()[\],;]+)/g;for(let l of r.matchAll(i)){let a=l.slice(1,5).some(d=>d!==void 0),c=l[1]??l[2]??l[3]??l[4]??l[5]??l[6],p=a?c:c.replace(/[.,;:]+$/,""),f=/^[^.\s][^\s]*\.(?:md|mdx|rst|txt|html?|json|ya?ml|toml|csv|ts|tsx|js|jsx|mjs|cjs|py|go|java|rb|rs|sh|prompt)(?:#.*)?$/i.test(p.split(/[/\\]/).at(-1)??""),u=l[5]!==void 0&&/[/\\]/.test(p)||/^\.{1,2}[/\\]/.test(p);p.startsWith("#")||!a&&(/\s/.test(p)||!(u||f))||t.push({target:p,span:{from:o+1,to:o+1},explicit:a||l[5]!==void 0,fileLike:f||u})}}return t}function Gs(e,t,n,o=!1){let r=t.split("#")[0];if(!r||/[\\:\0*?[\]$]/.test(r)||r.startsWith("/")||/[{}]/.test(r.replace(/(?:^|\/)\{lang\}(?=\/)/g,""))||o&&/[\s<>{}%~]/.test(r))return{reason:"unsupported"};let s=un.normalize(un.join(un.dirname(e),r));return s===".."||s.startsWith("../")||N(s,n)===null?{reason:"out-of-scope"}:{path:s}}function Aa(e,t){let n={references:[],cycles:[],unresolved:[]};if(!Ws(e))return n;let o=[...new Set(t.paths)].filter(s=>Ks(s)&&N(s,t.root)!==null).sort(),r=new Set(o);for(let s of[...new Set(t.skillPaths)].sort()){if(!r.has(s)||!le(s,{nested:!0})?.definition)continue;let i=new Set,l=new Set,a=c=>{if(!(i.has(c)||!Object.hasOwn(t.files,c))){i.add(c),l.add(c);for(let{target:p,span:f}of Us(t.files[c])){let u=k=>n.unresolved.push({ownerPath:s,fromPath:c,target:p,span:f,reason:k}),d=Gs(c,p,t.root);if(d.reason){u(d.reason);continue}let m=d.path,g=new RegExp(`^${m.split("/").map(k=>k==="{lang}"?"[^/]+":pn(k)).join("/")}$`),h=m.includes("{lang}")?o.filter(k=>g.test(k)):r.has(m)?[m]:[];if(!h.length){u("missing");continue}for(let k of h){let y={ownerPath:s,fromPath:c,path:k,span:f};l.has(k)?n.cycles.push(y):(n.references.push(y),a(k))}}l.delete(c)}};a(s)}return n}var be=/\.(?:md|txt|j2|hbs|mustache|prompt)$/i,Do=/(?:^|[/\\])(?:prompts?|templates?|instructions)(?=$|[/\\])/i,zs=/prompt|instructions|system/i,Vs=200;function At(e){if(!be.test(e))return!1;let t=e.split("/"),n=t[t.length-1];return t.slice(0,-1).some(r=>r.toLowerCase()==="prompts")||zs.test(n)}function Bo(e,t){return!At(e)||Buffer.byteLength(t)<Vs?null:Xs(e,t)}function Xs(e,t){let n=Buffer.byteLength(t),o=t.split(`
|
|
3
|
+
`).length;return{kind:"file",named:!1,prose:!1,path:e,start:0,line:1,endLine:o,span:{from:1,to:o},symbol:null,chars:n,excerpt:xe(t),enclosing:null}}function Oa(e,t){let n=e.toks[t.from];return t.to!==t.from+1||n?.kind!=="string"||!Te(n).closed?null:{kind:"named",named:!0,prose:!1,path:e.path,start:n.start,line:n.line,endLine:n.endLine,span:{from:n.line,to:n.endLine},symbol:null,chars:n.value.length,excerpt:xe(n.value),enclosing:null}}function dn(e){return/(?:^|\/)(?:pyproject\.toml|requirements\.txt)$/i.test(e)}function Ma(e,t){if(!dn(e))return!1;let n=t.split(/\r?\n/).map(s=>s.replace(/("(?:\\.|[^"\\])*"|'[^']*')|#.*/g,(i,l)=>l??""));if(/(?:^|\/)requirements\.txt$/i.test(e))return n.some(s=>/^\s*openai[-_.]agents(?:\[[^\]]*\])?(?=\s*(?:$|[<>=!~;@#]))/i.test(s));let o="",r=new Map;for(let s of n){let i=/^\s*\[([^\]]+)\]/.exec(s);i?o=i[1]:(r.has(o)||r.set(o,[]),r.get(o).push(s))}for(let[s,i]of r){let l=i.join(`
|
|
4
|
+
`);if(/^tool\.poetry(?:\.group\.[^.]+)?\.dependencies$/.test(s)){if(/^\s*["']?openai[-_.]agents["']?\s*=/im.test(l))return!0}else if(["project","project.optional-dependencies","dependency-groups"].includes(s)){let a=/^\s*([\w."'-]+)\s*=\s*\[((?:"(?:\\.|[^"\\])*"|'[^']*'|[^\]"'])*)\]/gm;for(let c of l.matchAll(a))if(!(s==="project"&&c[1].replace(/["']/g,"")!=="dependencies")&&/["']openai[-_.]agents(?=["'[<>=!~ ;@])/i.test(c[2]))return!0}}return!1}function Wo(e){return/\.json$/i.test(e)?"json":/\.ya?ml$/i.test(e)?"yaml":W(e)||/\.(cs|go|rb|java)$/i.test(e)?"code":/\.(md|markdown)$/i.test(e)?"markdown":"text"}import{posix as Y}from"node:path";function Ko(e,t){if(t==="markdown"){let l=e.startsWith("---")?e.indexOf(`
|
|
5
|
+
---`,3):-1;return l<0?null:{start:3,end:l+1,bodyStart:l+4,newline:`
|
|
6
|
+
`,raw:e.slice(3,l).split(`
|
|
7
|
+
`)}}if(t==="outline"){let l=e.split(`
|
|
8
|
+
`),a=l[0]==="---"?l.indexOf("---",1):-1;if(a<0)return null;let c=l.slice(0,a).join(`
|
|
9
|
+
`).length+1;return{start:4,end:c,bodyStart:Math.min(e.length,c+4),newline:`
|
|
10
|
+
`,raw:l.slice(1,a)}}let n=/^\uFEFF?---(\r?\n)/.exec(e);if(!n)return null;let o=e.slice(n[0].length),r=/^---(?:\r?\n|$)/m.exec(o);if(!r)return null;let s=o.slice(0,r.index),i=n[0].length+r.index;return{start:n[0].length,end:i,bodyStart:i+r[0].length,newline:n[1],raw:s?s.slice(0,-1).split(`
|
|
11
|
+
`):[]}}function Go(e){return(e.startsWith('"')?e.match(/^"((?:\\.|[^"\\])*)"\s*(?:#.*)?$/):e.match(/^'((?:''|[^'])*)'\s*(?:#.*)?$/))?.[1]??null}function Uo(e,t=!1){if(!e||e.startsWith("#"))return null;if(e.startsWith('"')||e.startsWith("'"))return Go(e);let n=e.replace(/\s+#.*$/,"");if(t&&/:\s*$/.test(n))return null;let o=t?n.trimEnd():n;return/^[[\]{}&*!?@`%|>]|^-(?:\s|$)|:\s/.test(o)||/^(?:[-+]?\d|[-+]?\.\d|[-+]?\.(?:inf|nan)$|null$|~$|true$|false$|yes$|no$|on$|off$|y$|n$)/i.test(o)?null:n}function Js(e,t=!1,n=!1){let o=[],r=new Map,s=null;return e.map(i=>{let l=i.replace(/\r$/,""),a=l.length-l.trimStart().length,c=()=>o.map(({key:g})=>g).join(".")||null;if(s&&(!l.trim()||a>s.indent))return l.trim()&&(s.contentIndent??=a),{location:c(),text:l.slice(s.contentIndent??a),keys:s.keys};if(s=null,!l.trim()||l.trimStart().startsWith("#"))return{location:c()};for(;o.length&&o.at(-1).indent>=a;)o.pop();if(n&&/^\s*-\s/.test(l)){let g=o.map(({key:y})=>y),h=JSON.stringify(g),k=r.get(h)??0;return r.set(h,k+1),{location:c(),keys:[...g,k]}}let p=l.match(/^\s*([\w.-]+):(?:\s+(.*))?$/);if(!p)return{location:c()};let f=p[2]??"",u=[...o.map(({key:g})=>g),p[1]];if(!f||f.startsWith("#"))return o.push({indent:a,key:p[1]}),{location:c(),...n?{keys:u}:{}};if(/^[|>][+-]?\s*(?:#.*)?$/.test(f))return s={indent:a,keys:u},{location:c()};let d=f.match(/^(["'])(.*)\1\s*(?:#.*)?$/),m=t?Go(f)??f.replace(/\s+#.*$/,""):d?d[2]:f.replace(/\s+#.*$/,"");return{location:c(),text:m,keys:u}})}function gn(e,t={}){let n=e.split(`
|
|
12
|
+
`).map(i=>i.replace(/\r$/,"")),o=Js(n,!0),r={},s=[{indent:-1,value:r}];for(let i=0;i<n.length;i++){let l=n[i];if(!l.trim()||l.trimStart().startsWith("#"))continue;if(l.includes(" "))return null;let a=l.length-l.trimStart().length,c=l.match(/^\s*([\w.-]+):(?:\s+(.*))?$/),p=l.match(/^\s*-(?:\s+(.*))?$/);if(!c&&!p)return null;for(;s.at(-1).indent>=a;)s.pop();let f=s.at(-1);if(f.childIndent??=a,f.childIndent!==a||f.indent===-1&&a!==0)return null;if(p){if(!t.lists)return null;let m=Uo(p[1]??"",!0);if(m===null||s.length===1)return null;if(!Array.isArray(f.value)){if(Object.keys(f.value).length)return null;f.value=[],Object.defineProperty(s.at(-2).value,f.key,{value:f.value,enumerable:!0,writable:!0})}f.value.push(m);continue}if(!c||Array.isArray(f.value)||Object.hasOwn(f.value,c[1]))return null;let u=c[2]??"";if(!u||u.startsWith("#")){let m={};Object.defineProperty(f.value,c[1],{value:m,enumerable:!0,writable:!0}),s.push({indent:a,key:c[1],value:m});continue}let d;if(/^[|>][+-]?\s*(?:#.*)?$/.test(u)){let m=i+1,g;for(;i+1<n.length;){let k=n[i+1],y=k.length-k.trimStart().length;if(k.trim()&&y<=a)break;if(k.includes(" ")||k.trim()&&(g??=y,y<g))return null;i++}let h=i;d=o.slice(m,h+1).flatMap(({text:k})=>k===void 0?[]:[k]).join(`
|
|
13
|
+
`)}else{let m=Uo(u);if(m===null)return null;d=m}Object.defineProperty(f.value,c[1],{value:d,enumerable:!0,writable:!0})}return r}function Fa(e){let t=gn(e,{lists:!0});return t?hn(e,{legacyBoundaries:!0}).map(n=>({key:n.key,value:t[n.key],span:n.span})):null}function hn(e,t={}){let n=e.split(`
|
|
14
|
+
`),o=n.flatMap((r,s)=>(t.legacyBoundaries?r.trim()&&!/^\s|^#/.test(r):/^[\w.-]+:(?:\s|$)/.test(r))?[s]:[]);return o.map((r,s)=>{let i=n[r].slice(0,n[r].indexOf(":")),l=o[s+1]??n.length;for(;l>o[s]+1&&!n[l-1].trim();)l--;return{key:i,span:{from:r+1,to:l}}})}function xn(e){let t=e.split(/^---(?:\s+#.*)?\s*$/m);if(t.length>1)return[...new Set(t.flatMap(xn))];let n=e.split(`
|
|
15
|
+
`).filter(i=>i.trim()&&!/^\s*(?:#|---\s*$|\.\.\.\s*$|%[A-Z])/.test(i)),o=n.join(`
|
|
16
|
+
`).trimStart().replace(/^(?:(?:&[\w.-]+|!<[^>]+>|![\w:/.!-]+)\s+)+/,"");if(o.startsWith("{"))return Ys(o);let r=i=>i.length-i.trimStart().length,s=n.reduce((i,l)=>Math.min(i,r(l)),1/0);return n.flatMap(i=>{let l=/^["']?([\w.-]+)["']?\s*:/.exec(i.trimStart());return r(i)===s&&l?[l[1]]:[]})}function Ys(e){let t=[],n=[],o="",r=!1;for(let s=0;s<e.length;s++){let i=e[s];if(o){i==="\\"&&o==='"'?s++:i===o&&(o==="'"&&e[s+1]==="'"?s++:o="");continue}if(i==="#"&&/\s/.test(e[s-1]??" ")){for(;s<e.length&&e[s]!==`
|
|
17
|
+
`;)s++;continue}if(r&&n.length===1&&!/\s/.test(i)&&i!=="}"&&i!=="?"){let l=/^(?:"((?:\\.|[^"\\])*)"|'((?:''|[^'])*)'|([\w.-]+))\s*:/.exec(e.slice(s));if(!l)return[];try{t.push(l[1]!==void 0?JSON.parse(`"${l[1]}"`):l[2]?.replace(/''/g,"'")??l[3])}catch{return[]}s+=l[0].length-1,r=!1;continue}if(i==='"'||i==="'")o=i;else if(i==="{"||i==="[")n.push(i),n.length===1&&(r=!0);else if(i==="}"||i==="]"){if(n.pop()!==(i==="}"?"{":"["))return[];if(!n.length)return t}else i===","&&n.length===1&&(r=!0)}return[]}function qe(e,t){return V(e)?[...new Set(t)].filter(n=>Vo(n)&&/(?:^|\/)\.claude-plugin\/(?:plugin|marketplace)\.json$/i.test(n)).sort():[]}function Ua(e,t,n={}){return qe(e,t).flatMap(o=>{let r=/^(?:(.*)\/)?\.claude-plugin\/plugin\.json$/i.exec(o);if(r)return[{folder:r[1]??"",path:o}];let s=o.split("/").slice(0,-2).join("/");try{let i=JSON.parse(n[o]);return!i||typeof i!="object"||!("plugins"in i)||!Array.isArray(i.plugins)?[]:[...new Set(i.plugins.flatMap(l=>{if(!l||typeof l!="object"||typeof l.source!="string")return[];let a=l.source.replace(/^\.\//,"");return Vo(a)?[Be(a,s)]:[]}))].map(l=>({folder:l,path:o}))}catch{return[]}})}function Vo(e){return!/[\\:\0?*#%]/.test(e)&&!e.split("/").some(t=>!t||t==="."||t==="..")}function Ga(e,t,n){let o=t.split("/");for(let r=0;r<o.length-2;r++)if(!(o[r].toLowerCase()!=="plugins"||!o[r+1])&&zo(e,o.slice(r+2).join("/")))return o.slice(0,r+2).join("/");for(let r of[...n].sort((s,i)=>i.folder.length-s.folder.length)){let s=N(t,r.folder);if(s!==null&&zo(e,s))return r.folder}return null}function zo(e,t){return t.toLowerCase().startsWith(`${Ye}/`)&&Sn.test(t)||!!(_e(e)&&t.toLowerCase().startsWith(`${we}/`)&&le(t)?.definition)}function yn(e,t,n={}){if(!V(e))return[];let o=[...new Set(t)].filter(s=>!/[\\:\0]/.test(s)&&s.split("/").every(i=>i&&i!=="."&&i!=="..")).sort(),r=new Map;for(let s of o){let i=/^(?:(.*)\/)?environments\/[^/]+\.ya?ml$/i.exec(s),l=/^(?:(.*)\/)?agents\/[^/]+\/environment\.ya?ml$/i.exec(s),a=i?.[1]??l?.[1]??(i||l?"":null);if(a===null||r.has(a))continue;let c=u=>N(u,a),p=o.filter(u=>/^agents\/(?:[^/]+\.md|[^/]+\/agent\.md)$/i.test(c(u)??""));if(!p.length)continue;let f=o.filter(u=>/^(?:environments\/[^/]+\.ya?ml|vaults\/[^/]+\.ya?ml|policy\.ya?ml|agents\/[^/]+\/(?:environment|policy|vault)\.ya?ml|skills\/[^/]+\/SKILL\.md)$/i.test(c(u)??""));r.set(a,{folder:a,agents:p,configs:f})}for(let s of r.values())for(let i of s.agents){if(n[i]===void 0)continue;let l=qs(i,n[i],s,o);for(let a of l.configPaths)s.configs.includes(a)||s.configs.push(a);for(let a of l.relationships)a.kind==="config"&&n[a.path]!==void 0&&Hs(n[a.path])&&!s.configs.includes(a.path)&&s.configs.push(a.path)}return[...r.values()].sort((s,i)=>s.folder<i.folder?-1:s.folder>i.folder?1:0)}function Qa(e,t,n){let o=yn(e,t,n).filter(s=>s.agents.some(i=>n[i]===void 0)),r=new Set(qe(e,t));return t.filter(s=>!r.has(s)&&/\.(?:ya?ml|json|md)$/i.test(s)&&o.some(i=>N(s,i.folder)!==null&&!i.agents.includes(s)&&!i.configs.includes(s)))}function qs(e,t,n,o){let r=Ko(t),s=r?.raw.join(`
|
|
18
|
+
`)??"",i=new Map(hn(s).map(h=>[h.key,s.split(`
|
|
19
|
+
`).slice(h.span.from-1,h.span.to).join(`
|
|
20
|
+
`)])),l=h=>i.has(h)?gn(i.get(h),{lists:!0})?.[h]:void 0,a=h=>typeof l(h)=="string"?l(h):null,c={path:e,name:a("name")??Y.basename(e,".md"),model:a("model"),description:a("description"),prompt:r?t.slice(r.bodyStart).trim():t.trim(),relationships:[],refused:[],configPaths:[]};r||c.refused.push({path:e,reason:"invalid"});let p=(h,k,y=!1)=>{if(/[\\:\0${}*]/.test(h)||h.startsWith("/")){c.refused.push({path:e,reason:"dynamic"});return}let b=Y.normalize(Y.join(Y.dirname(e),h));if(N(b,n.folder)===null||b===".."||b.startsWith("../")){c.refused.push({path:b,reason:"out-of-scope"});return}if(!o.includes(b)){c.refused.push({path:b,reason:"missing"});return}if(k==="agent"&&!n.agents.includes(b)){c.refused.push({path:b,reason:"out-of-scope"});return}c.relationships.some(x=>x.path===b&&x.kind===k)||c.relationships.push({path:b,kind:k}),y&&!c.configPaths.includes(b)&&c.configPaths.push(b)},f=(h,k)=>{let y=l(h);if(y===void 0&&!i.has(h))return;let b=typeof y=="string"?[y]:Array.isArray(y)?y:[];if(!b.length||b.some(x=>typeof x!="string")){c.refused.push({path:e,reason:"dynamic"});return}for(let x of b)p(x,k,k==="config")};for(let h of["environment","policy","vault","vault_schema"])f(h,"config");f("skills","skill");let u=l("multiagent");if(u&&typeof u=="object"&&"agents"in u&&Array.isArray(u.agents))for(let h of u.agents)typeof h=="string"?p(h,"agent"):c.refused.push({path:e,reason:"dynamic"});else i.has("multiagent")&&c.refused.push({path:e,reason:"dynamic"});let d=Y.basename(e,".md"),m=d.toLowerCase()==="agent",g=m?n.configs.filter(h=>Y.dirname(h)===Y.dirname(e)&&/\/environment\.ya?ml$/i.test(h)):n.configs.filter(h=>N(h,n.folder)?.match(/^environments\/([^/]+)\.ya?ml$/i)?.[1]===d);if(!i.has("environment")){let h=n.agents.length===1?n.configs.filter(k=>/^environments\/[^/]+\.ya?ml$/i.test(N(k,n.folder))):[];for(let k of g.length?g:h.length===1?h:[])p(Y.relative(Y.dirname(e),k),"config")}if(!i.has("policy")&&(m||n.agents.length===1))for(let h of n.configs.filter(k=>/(?:^|\/)policy\.ya?ml$/i.test(k)&&Y.dirname(k)===(m?Y.dirname(e):n.folder)))p(Y.relative(Y.dirname(e),h),"config");for(let h of c.prompt.matchAll(/(?:\]\(|[`\s])((?:\.\.?\/)[^\s`"'()]+\.(?:ya?ml|json|md))(?:[)`\s]|$)/g))p(h[1],/\/SKILL\.md$/i.test(h[1])?"skill":"config");return c}function Hs(e){let t=/^(?:config|networking|filesystem_policy|network_policies|policy|permissions|auth|injection_location|secret_name)$/;return xn(e).some(n=>t.test(n))}function Lc(e){return e==="skill"?"skill":"definition"}var bn=class extends Error{reason;constructor(t,n){super(t==="secret"?wt(n):t==="secret-content"?co(n):`File was not read: ${t}.`),this.reason=t}},En=["html"],qo=["md","json","yaml","yml",...En],Rn=e=>new RegExp(`\\.(?:${e.join("|")})$`,"i"),ei=Rn(qo),ti=Rn(En),ni=Rn(["ts","tsx","js","jsx","py","go","rb","java","rs","toml",...qo.filter(e=>!En.includes(e))]);function Ho(e,t,n){return t=It(e,t,n),mn(t)&&ti.test(t)}function oi(e,t,n){return t=It(e,t,n),mn(t)&&ei.test(t)&&(_e(e)||!Ho(e,t))}function ri(e,t,n){return ni.test(t)||oi(e,t,n)||ne(e)&&At(t)}function Zo(e,t,n=[]){if(!ye(e)||!t.toLowerCase().endsWith(".md"))return!1;let o=t.split("/");return o.some((r,s)=>r.toLowerCase()==="commands"&&s<o.length-1&&(o[s-1]?.toLowerCase()===Ee||n.includes(o.slice(0,s).join("/"))))}function Qo(e,t,n=!1){if(!sn(t,n)||Zo(e,t))return!1;let o=[Ee,...Ot.filter(s=>s.startsWith(".")),F.cli],r="";for(let s of t.toLowerCase().split("/")){let i=r?`${r}/${s}`:s,l=qe(e,[i]).length>0,a=V(e)&&(s===".claude-plugin"||l);if(s.startsWith(".")&&!o.includes(s)&&!a||r.split("/").at(-1)===".claude-plugin"&&!l||r===Ee&&!Je.includes(`${r}/${s}`)&&!($t.includes(`${r}/${s}`)&&_e(e)))return!1;r=r?`${r}/${s}`:s}return!0}var er=/(prompt|tool|agent|config|instruction)/i,Xo=/\.(md|json|ts|js|py|yaml|yml|txt)$/i,Ze=/(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|poetry\.lock|Cargo\.lock|go\.sum)$|\.lock$/i,si=/(^|\/)(node_modules|dist|build|out|vendor|target|__pycache__|coverage)\//i,Qe=new RegExp(`${si.source}|\\.min\\.|\\.(png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot|pdf|zip|gz|jar|bin|map)$`,"i"),He=new RegExp(`${Qe.source}|${Oo.source}|${Ze.source}|${rn.source}`,"i"),ii=/\.(ts|tsx|js|jsx|mjs|cjs|py)$/i,tr=new RegExp(`(^|/)(${Et.join("|")}|cassettes|docs|\\.github)/`,"i"),li=/(^|\/)([^/]*\.stories\.[^/]*|[^/]*\.d\.ts)$/i,ai=new RegExp(`(^|/)(${["test","tests","__tests__","test-support","testdata","fixtures","__fixtures__",...Et,"cassettes","mocks","__mocks__","examples","docs","\\.github"].join("|")})/`,"i"),ci=/(^|\/)([^/]*fixture[^/]*|[^/]*\.stories\.[^/]*|test_[^/]*\.py|conftest\.py|[^/]*\.d\.ts)$/i,Lt=/(^|\/)\.git\//i,kn=(e,t,n)=>n==="github"?Fe.conventionImport.fileBytes:void 0,Pt=()=>Fe.codeScan.fileBytes,fi={entry:{hidden:!0,excluded:[Qe,Ze,Lt]},archive:{hidden:!1,discovery:!0,excluded:[Qe,Ze,Lt]},listing:{hidden:!0},definition:{hidden:!0,discovery:!0,limit:kn},skill:{hidden:!0,discovery:!0,limit:kn},extraction:{hidden:!0,discovery:!0,accepts:(e,t)=>Xo.test(t),limit:kn},source:{hidden:!0,discovery:!0,excluded:[He],empty:!0,accepts:(e,t,n)=>wn(e,t,n)||ri(e,t,n),limit:(e,t,n,o)=>wn(e,t,o)?void 0:Ho(e,t,o)?Fe.sourceFetch.htmlReferenceBytes:Fe.sourceFetch.codeFileBytes},"code-scan":{hidden:!0,discovery:!0,excluded:[He,tr,li],relativeExclusions:!0,excludeExamples:!0,accepts:(e,t)=>ii.test(t)||At(t)||ye(e)&&dn(t)&&Qo(e,t),limit:Pt},"code-support":{hidden:!0,excluded:[He],accepts:(e,t)=>W(t)!==null,limit:Pt},pointer:{hidden:!1,limit:Pt},proposal:{hidden:!0,excluded:[Qe,Ze,Lt],empty:!0,limit:Pt},survey:{hidden:!0,discovery:!0,excluded:[He,Lt],relativeExclusions:!0,accepts:(e,t)=>Xo.test(t)||Wo(t)==="code",limit:()=>Fe.survey.fileBytes},override:{hidden:!1}};function Re(e,t,n){return _n(e,t,n,!0)}function Pc(e,t,n={}){let o=N(t.path,n.root);if(o===null)return!1;let r=ye(e),s=i=>["",...i.split("/").slice(0,-1).map((l,a,c)=>c.slice(0,a+1).join("/"))];return r&&(Zo(e,t.path,s(t.path))||vt(e).some(i=>i.kind!=="runtime"))?!1:(r?s(o):[""]).every(i=>{let l=Re(e,t,{...n,purpose:"source",route:"github",...r?{scopes:{ownerOf:()=>({key:null,kind:"root",folder:i})}}:{}});return l.admitted||l.reason==="too-large"})}var ui=/(?:^|\/)(?:vault\.ya?ml|(?:vaults?|auth)\/(?:credentials?|values?|tokens?)(?:\.[^/]+)?)$/i;function pi(e){let t=e.path.replace(/\\/g,"/");if(e.text===void 0||!/\.(?:ya?ml|json|md)$/i.test(t))return!1;let n=e.text,o=/(?:^|[\n{,])\s*(?:-\s*)?["']?(?:secret(?:_value)?|api[_-]?key|access[_-]?token|refresh[_-]?token|token|password|client[_-]?secret|private[_-]?key|credentials?)["']?\s*:/gim,r=/(?:^|[\n{,])\s*(?:-\s*)?["']?[A-Z][A-Z0-9_]*(?:_KEY|_TOKEN|_PASSWORD|_SECRET)["']?\s*:/gm;return[...n.matchAll(o),...n.matchAll(r)].some(i=>!/^\s*(["']?)(?:\$\{[A-Z_][A-Z0-9_]*\}|\$[A-Z_][A-Z0-9_]*)\1[^\S\n]*(?:#[^\n]*)?(?:[,}\r\n]|$)/.test(n.slice(i.index+i[0].length)))||/["']?auth["']?\s*:/.test(n)&&/(?:^|[\n{,])\s*["']?value["']?\s*:/m.test(n)||/-----BEGIN (?:[A-Z ]*PRIVATE KEY|CERTIFICATE)-----/.test(n)}function _n(e,t,n,o){let r=wo(e,t,{...n,allowSelectedFile:n.purpose==="override",requireLocalTarget:n.purpose==="proposal"});if(!r.admitted)return r;let s=N(t.path,n.root);if(V(e)&&ui.test(t.path.replace(/\\/g,"/")))return{admitted:!1,reason:"secret"};if(V(e)&&pi(t)&&(!n.listing||yn(e,[...n.listing.keys()],t.text===void 0?n.managedFiles:{...n.managedFiles,[t.path]:t.text}).some(f=>f.configs.includes(t.path)&&!/\/SKILL\.md$/i.test(t.path))))return{admitted:!1,reason:"secret"};if(n.route==="local-folder"&&(n.purpose==="proposal"||n.purpose==="entry")&&n.localTarget){let f=Zs(n.localTarget.root,n.localTarget.path).split(Qs).join("/"),u=_n(e,{...t,path:f},{...n,root:void 0,localTarget:void 0,gitIgnored:n.purpose==="entry"?n.gitIgnored:void 0},o);if(!u.admitted)return u}let i=fi[n.purpose];if(n.purpose==="proposal"&&Se(s))return{admitted:!1,reason:"wrong-type"};if(i.discovery&&Co(e,t.path,n.root))return{admitted:!1,reason:"excluded"};if(i.hidden&&n.route!=="github"&&!Qo(e,t.path,t.directory))return{admitted:!1,reason:"hidden"};if(i.hidden&&n.route==="local-folder"&&t.path.split("/").includes("node_modules"))return{admitted:!1,reason:"excluded"};let l=i.relativeExclusions?s:t.path,a=ke(e,t.path,n.root);if(!["listing","pointer","override"].includes(n.purpose)&&cn(e,t.path,n))return{admitted:!1,reason:"excluded"};if(i.excluded?.some(f=>a&&f===tr?!1:a&&f===He?Qe.test(l)||Ze.test(l):f.test(l)))return{admitted:!1,reason:"excluded"};if(n.purpose==="archive"&&_t(e)&&Ao(s,t.text)&&!a)return{admitted:!1,reason:"excluded"};if(i.excludeExamples&&!a){if(Fo(e)){if(o&&No(t.path,{root:n.root??void 0,listing:n.listing,settings:e,key:JSON.stringify([n.root??"",n.route,...n.exclusions?.length?[n.exclusions]:[]]),readable:(f,u)=>_n(e,{path:f,size:u},{...n,localTarget:void 0},!1).admitted}))return{admitted:!1,reason:"excluded"}}else if(ai.test(l)||ci.test(l))return{admitted:!1,reason:"excluded"}}if(i.empty&&t.size!==void 0&&t.size<=0)return{admitted:!1,reason:"empty"};if(i.accepts&&!(a?.kind==="example"&&n.purpose==="code-scan"&&/\.md$/i.test(s))&&!i.accepts(e,s,n.scopes))return{admitted:!1,reason:"wrong-type"};let c=i.limit?.(e,s,n.route,n.scopes);if(c!==void 0&&t.size!==void 0&&t.size>c)return{admitted:!1,reason:"too-large"};let p=ao(e,t.text);return p?{admitted:!1,reason:p}:{admitted:!0}}var mi=`
|
|
21
|
+
[The rest of this file was not read.]
|
|
22
|
+
`;async function di(e,t,n,o={}){let r=Re(e,t,{purpose:"override",route:"github",...o});if(!r.admitted)throw new Error(r.reason==="secret"?wt(t.path):`File was not read: ${r.reason}.`);let s=await n(),i=Re(e,{path:t.path,text:s},{purpose:"override",route:"github",...o});if(!i.admitted)throw new bn(i.reason,t.path);if(t.readBytes===void 0)return s;let l=Buffer.from(s,"utf8");if(l.length<=t.readBytes)return s;let a=Math.min(t.readBytes,l.length);for(;a>0&&(l[a]&192)===128;)a--;return l.subarray(0,a).toString("utf8")+mi}var gi=4096;function hi(e,t,n,o={}){let r=qt(e),s=r&&t.readBytes!==void 0?t.readBytes+gi:void 0;return di(e,r?t:{path:t.path},async()=>{let i=await n(s===void 0?t:{...t,readBytes:s});if(i===null)throw new Error("File is unavailable.");return s===void 0?i:Buffer.from(i.slice(0,s),"utf8").subarray(0,s).toString("utf8")},o)}var Jo=new WeakMap;function xi(e,t){let n=Jo.get(t);if(n?.settings===e)return t;t=n?.source??t;let o=t.admission;if(!o?.exclusions?.length&&!qt(e))return t;let r,s=()=>r??=(t.listAll?t.listAll():t.list()).then(a=>new Set(a.map(c=>c.path))),i=async a=>{let c=await(a&&t.listAll?t.listAll():t.list());return o?.exclusions?.length?c.filter(p=>Re(e,p,{purpose:"override",route:"github",...o}).admitted):c},l={repoKey:t.repoKey,root:t.root,source:t.source,admission:o,head:()=>t.head(),linkFor:(...a)=>t.linkFor(...a),list:()=>i(!1),...t.listAll?{listAll:()=>i(!0)}:{},read:async a=>hi(e,a,c=>t.read(c),{...o,...V(e)?{listing:await s()}:{}})};return Jo.set(l,{source:t,settings:e}),l}async function Oc(e,t,n){for(let o of n){if(!o.admission?.exclusions?.length)continue;let r=t.repos?.find(c=>c.key===o.repoKey);if(!r)continue;let s=new Map(Yo(t.projectAgents,r.key).map(c=>[c.path,Be(c.sourcePath,ht(r.key))])),i=[...Object.keys(r.files??{}).map(c=>s.get(c)??c),...s.values(),...(r.selected??[]).map(c=>c.path),...(r.scan?.plan??[]).map(c=>c.path)];if(!i.length)continue;let l=xi(e,o),a=new Set((await(l.listAll?l.listAll():l.list())).map(c=>c.path));for(let c of i)if(!Re(e,{path:c},{purpose:"override",route:"github",...o.admission,listing:a}).admitted)throw new Error("Saved files conflict with the current exclusions. Start a new analysis.")}}var $n="readme";function Dc(e){let t=e.toLowerCase();return t.startsWith($n)?0:t===F.agentGuide?1:t.endsWith(".md")&&e.split("/").length<=2?2:er.test(e)?3:null}var F={systemPrompt:"system_prompt.md",hyphenatedPrompt:"system-prompt.md",unseparatedPrompt:"systemprompt.md",system:"system.md",prompt:"prompt.md",promptFallback:"CLAUDE.md",soul:"soul.md",knowledge:"knowledge.md",tools:"tools.json",toolsSource:"tools.ts",cli:".cli.json",config:"counterfact.json",skill:"SKILL.md",readme:`${$n}.md`,agentGuide:"agents.md"},et=[F.systemPrompt,F.hyphenatedPrompt,F.system,F.prompt],An=F.promptFallback,Si=[...et,An].map(e=>e.toLowerCase()),Ot=[".mcp.json","mcp.json"],yi=[F.toolsSource,F.cli],Ee=".claude",Ye="agents",we="skills",Je=[`${Ee}/${Ye}`,Ye],Bc=/^(?:\.claude\/)?(skills|commands)\//i,$t=[we,`${Ee}/${we}`],ki=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),wi=e=>e.map(ki).join("|"),bi=`(?:${wi(Je)})`,Sn=new RegExp(`^${bi}/[^/]+\\.md$`,"i"),_i=/^templates\/.+/i;function Wc(e,t){return le(e,t)?.definition??!1}function _e(e){return e.CF_DISCOVERY_SKILLS!=="0"}var Ln=new Map([...et.map(e=>[e,{role:"prompt",kind:"dedicated"}]),[An.toLowerCase(),{role:"prompt",kind:"fallback"}],[F.soul,{role:"soul"}],[F.knowledge,{role:"knowledge"}],[F.config,{role:"marker"}],[F.tools,{role:"tool file",kind:"json"}],[F.toolsSource,{role:"tool file",kind:"sdk"}],[F.cli,{role:"tool file",kind:"cli"}],...Ot.map(e=>[e,{role:"MCP config"}])]),Ei=[...Ln.keys()];function vn(e){let t=Ln.get(e.toLowerCase());if(t)return t;if(Sn.test(e))return{role:"sub-agent"};let n=le(e),o=n?.ownerPath?{ownerPath:n.ownerPath}:{};return n?.definition?{role:"skill",name:n.name,...o}:n?.reference?{role:"reference",kind:"skill",name:n.name,...o}:_i.test(e)?{role:"reference",kind:"template"}:null}function Ri(e){let t=vn(e);return!!t&&t.role!=="skill"&&t.role!=="reference"}var vi=["package.json","pyproject.toml","go.mod","cargo.toml"],$i=[...Ei.filter(e=>!yi.includes(e)),...vi],Ai=new RegExp(`^${$n}[^/]*$`,"i");function It(e,t,n){let o=ye(e)?n?.ownerOf(t):void 0;return o?N(t,o.folder)??t:t}function wn(e,t,n){if(ye(e)&&n?.files?.some(l=>l.path===t&&l.kind==="entry"))return!0;t=It(e,t,n);let o=t.split("/").pop()??"",r=le(t),s=r?.definition&&(_e(e)||!r.ownerPath&&!r.folder.startsWith(`${Ee}/`)),i=r?.reference&&r.ownerPath&&_e(e);return $i.includes(o.toLowerCase())||Ai.test(o)||Ri(t)||!!s||!!i}var Kc=[...et,An].join(", "),Uc=`${F.config}, a system prompt file, ${F.tools}, an MCP config, ${F.soul}, ${F.knowledge}, ${Ye}/*.md and ${we}/*/${F.skill}`,Gc=/(agent|tool|prompt|llm|model|chain|graph|pipeline|workflow|handler|route|server|main|index|app|orchestr)/i,zc=/(^|\/)prompts?\/.*\.(md|txt|prompt)$/i;function Vc(e,t,n={}){let o=t.flatMap(m=>{let g=N(m,n.root);return g===null?[]:[{path:m,relativePath:g}]}),r=o.filter(({path:m})=>Re(e,{path:m},{purpose:"override",route:"github"}).admitted),s=new Map(r.map(m=>[m.relativePath.toLowerCase(),m.path])),i=et.map(m=>s.get(m)).find(Boolean),l=Ot.map(m=>s.get(m)).find(Boolean),a=m=>Eo(e,m),c=Ro({codeAgentsFound:n.codeAgentsFound??!1,folderAgentsFound:n.folderAgentsFound,agentConfiguration:n.agentConfiguration,otherDefinitions:r.some(({relativePath:m})=>{let g=vn(m);return!a(m)&&!!g&&g.role!=="reference"})},e),p=n.agentConfiguration&&c==="prompt",f=p?Xe.map(m=>s.get(m)).find(Boolean):void 0,u=!p&&s.has(F.soul)&&!(We(e)?Si:et).some(m=>s.has(m)),d=[];for(let m of r){let g=a(m.relativePath)&&(c==="background"||p&&!Xe.includes(m.relativePath.toLowerCase())),h=p&&Xe.includes(m.relativePath.toLowerCase())?{role:"prompt",kind:"fallback"}:g?{role:"knowledge",kind:"background"}:vn(m.relativePath);if(!h||n.mode==="core"&&(h.role==="skill"||h.role==="reference"))continue;let k;g?k=m.path===s.get(m.relativePath.toLowerCase()):p&&h.role==="prompt"&&h.kind==="fallback"?k=m.path===f:h.role==="prompt"&&h.kind==="dedicated"?k=m.path===i:h.role==="MCP config"?k=m.path===l:Ln.has(m.relativePath.toLowerCase())&&(k=m.path===s.get(m.relativePath.toLowerCase()));let y=h.ownerPath?{ownerPath:s.get(h.ownerPath.toLowerCase())??null}:{};d.push({...m,...h,...y,...k===void 0?{}:{preferred:k}})}return{files:d,scoped:o,registry:u}}function nr(e,t,n){let o;try{let r=JSON.parse(e),s=r?.mcpServers??r?.servers;o=s&&typeof s=="object"?Object.keys(s):[]}catch{return{servers:[],warnings:[`${t} is not valid JSON; ignored`]}}return{servers:o,warnings:!n&&o.length?[`found MCP config (servers: ${o.join(", ")}) but no ${F.tools}; tool schemas are discovered from a running server and were not extracted`]:[]}}import{z as ve}from"zod";var Li=ve.object({name:ve.string().min(1,"tool name is required"),description:ve.string().optional(),input_schema:ve.record(ve.string(),ve.unknown()).optional()}),Pi=ve.array(Li);function or(e){let t=[];if(e==null)return{tools:[],warnings:t};let n=e;if(typeof e=="string"){let r=e.trim();if(r==="")return{tools:[],warnings:t};try{n=JSON.parse(r)}catch(s){throw new Error(`tools is not valid JSON: ${s.message}`)}}let o=Pi.safeParse(n);if(!o.success)throw new Error(`tools do not match the expected shape (an array of {name, description?, input_schema?}): ${o.error.issues.map(r=>`${r.path.join(".")||"(root)"}: ${r.message}`).join("; ")}`);return o.data.length===0&&t.push("no tools were provided"),{tools:o.data,warnings:t}}import{posix as Pn}from"node:path";var H=e=>`${e.path}:${e.kind}:${e.start}`;function tt(e){return e.slice(e.lastIndexOf("/")+1)}function nt(e,t){let n=t.replace(/\\/g,"/").replace(/^(\.\/)+/,""),o=e.filter(r=>r.path===n||r.path.endsWith(`/${n}`));return o.length>0?o:e.filter(r=>tt(r.path)===tt(n))}function $e(e,t,n){let o=H(t);e.set(o,[...e.get(o)??[],n])}function Oi(e,t,n){let o=r=>r.replace(/\.(tsx?|jsx?|mjs|cjs|py)$/,"").replace(/\/(?:index|__init__)$/,"");if(t.startsWith(".")){let r=e.endsWith(".py"),s=r?/^\.+/.exec(t)?.[0].length??0:0,i=r?"../".repeat(Math.max(0,s-1))+t.slice(s).replace(/\./g,"/"):t,l=o(Pn.normalize(Pn.join(Pn.dirname(e),i)));return n.filter(a=>o(a)===l)}return n.filter(r=>xt(r,t))}function rr(e,t,n){if(!(!e.moduleResolver||e.moduleResolver.legacy))return new Set(e.moduleResolver.bindings(t.path,n.source,[n.imported]).flatMap(o=>o.status==="resolved"?[o.path]:[]))}function Ke(e,t,n){let o=rr(e,t,n)??new Set(Oi(t.path,n.source,e.files.map(r=>r.path)));return e.files.filter(r=>o.has(r.path))}function On(e,t,n,o,r=!1){let s=rr(e,t,n);if(s)return o.filter(a=>s.has(a.path));let i=r?[n.source,`${n.source}.${n.imported}`]:[n.source],l=o.filter(a=>i.some(c=>xt(a.path,c)));return l.length?l:o}function Ae(e,t,n,o){let r=(o.get(n)??[]).filter(c=>c.path===t.path);if(r.length)return r;let[s,i]=n.split("."),l=t.imports.find(c=>c.name===s);if(!l)return[];let a=new Set(Ke(e,t,l).map(c=>c.path));return(o.get(i??l.imported)??[]).filter(c=>a.has(c.path))}import{posix as Ft}from"node:path";var Mt=/^(claude-[a-z0-9.-]+|gpt-[a-z0-9.-]+|o[1-9](-[a-z0-9-]+)?|gemini-[a-z0-9.-]+)$/,Ii=/^\S+\.(?:md|txt|j2|hbs|mustache|prompt)$/i,ot=50,sr=200;function ir(e){let t=[],n=[],o=[];for(let[r,s]of e.toks.entries()){if(!J(s))continue;s.kind==="string"&&Mt.test(s.value)&&t.length<ot&&t.push({value:s.value,path:e.path,line:s.line});let i=s.value.length<=sr&&Ii.test(s.value),l=e.toks[r-2],a=S(e.toks[r-1],":")&&l&&/^(?:system_prompt|user_prompt|prompt|template)$/i.test(l.kind==="string"?l.value:l.text);if(i){let c={value:s.value,path:e.path,line:s.line};n.length<ot&&n.push(c),a&&o.length<ot&&o.push(c)}}return{modelIds:t,fileRefs:n,promptFileRefs:o}}function lr(e){let{toks:t}=e,n=[];for(let o=0;o<t.length&&n.length<ot;o++)if(!(!_(t[o])||!B(t,o+1)||!S(t[o+2],"{"))&&!(e.lang==="js"&&!_(t[o-1],"const")))for(let{from:r,to:s}of T(t,o+2)){let i=t[r],l=t[r+2];if(!(s!==r+3||!S(t[r+1],":")||l?.kind!=="string"||l.value.length>sr||!Mt.test(l.value))&&!(!_(i)&&i?.kind!=="string")&&(n.push({object:t[o].text,member:i.kind==="string"?i.value:i.text,value:l.value,path:e.path,line:l.line}),n.length===ot))break}return n}import{posix as Nt}from"node:path";import{posix as rt}from"node:path";function Ue(e,t){return e.filter(n=>n.from<t&&t<n.to).at(-1)??null}function pe(e){let{toks:t}=e,n=[];for(let o=0;o<t.length;o++){if(!_(t[o])||!q(t,o,e))continue;let r=o;for(;S(t[r-1],".")&&_(t[r-2]);)r-=2;if(S(t[r-1],".")&&S(t[r-2],")")){let a=ee(e,r-2);r=n.find(p=>p.open===a)?.from??a}let s=I(t,o+1);if(s===t.length)continue;let i=S(t[o-1],".")&&S(t[o-2],")")?o:r,l=t.slice(i,o+1).map(a=>a.text).join("");n.push({from:r,to:s+1,open:o+1,callee:l,args:T(t,o+1)})}return n}function ae(e,t,n){let o=yo(e,t,n);return S(e.toks[o-1],";")?o-1:o}function Ct(e){let{toks:t}=e,n=[];for(let o=0;o<t.length;o++){if(!_(t[o])||S(t[o-1],"."))continue;let r=o+1;if(S(t[r],":")){if(!(e.lang==="js"?["const","let","var"].includes(t[o-1]?.text):he(t,o)))continue;for(;r<o+Ne&&r<t.length&&!B(t,r)&&![";","{","}"].some(a=>S(t[r],a));)r++}let s=S(t[r],"+");if(s&&r++,!B(t,r))continue;let i=ee(e,o);e.lang==="py"&&S(t[i],"(")||(n.push({at:o,name:t[o].text,append:s,from:r+1,to:ae(e,r+1)}),o=r)}return n}function ar(e,t,n=pe(e)){let{toks:o}=e,{assignments:r,functions:s,owner:i,binding:l,inBlock:a,lexical:c,declarations:p}=t,f=z(e),u=U(e,{includeMembers:!0}),d=u.filter(x=>x.params!==null),m=x=>u.filter(w=>(w.params!==null||w.kind==="class")&&w.from<x&&x<w.to).sort((w,E)=>E.from-w.from)[0]??null,g=(x,w)=>{let E=m(x.from);return a(x.from,w)&&(E===null||E.from<w&&w<E.to)},h=z(e,{namespaceBindings:!0,bindingPositions:!0}).map(x=>{let w=x.bindingAt,E=x.names.map(v=>({local:v,name:x.renamed?.[v]??v,namespace:x.namespaceNames?.includes(v)===!0||e.lang==="js"&&(_(o[w],"require")&&!S(o[w-2],"}")||S(o[w+1],"*"))}));return{module:x,at:w,names:E}}),k=(x,w,E=!1)=>{if(E){if(i(w)?.params?.includes(x)||l(x,w)||s.some(A=>A.name===x))return null;let R=f.filter(A=>A.names.includes(x));return R.length===1?{module:R[0],name:R[0].renamed?.[x]??x,namespace:!1}:null}let v=m(w),$=[...v?.kind==="class"?[v]:[],...d.filter(R=>R.from<w&&w<R.to).sort((R,A)=>A.from-R.from),null];for(let R of $){let A=h.filter(P=>m(P.at)===R&&a(P.at,w)&&P.names.some(M=>M.local===x)),L=r.filter(P=>P.name===x&&m(P.at)===R&&(!c(p.get(P)??P)||a(P.at,w))&&!A.some(M=>_(o[M.at],"require")&&P.from<=M.at&&M.at<P.to)),O=u.filter(P=>P.name===x&&(P.params!==null||P.kind==="class")&&m(P.from)===R&&g(P,w));if(R?.params?.includes(x)||L.length||O.length)return null;if(!A.length)continue;if(A.length!==1||A[0].at>=w&&!(e.lang==="js"&&_(o[A[0].at],"import")))return null;let C=A[0],j=C.names.find(P=>P.local===x);return{module:C.module,name:j.name,namespace:j.namespace}}return null};return{importBinding:k,hasImport:(x,w)=>w?f.some(E=>E.names.includes(x)):h.some(E=>E.names.some(v=>v.local===x)),loaderImport:(x,w)=>{let E=x.callee.split(".")[0];if(w){let $=k(E,x.from);return $?ie([$.module],e.lang).find(R=>R.name===E)??null:null}let v=ie(f,e.lang).filter($=>$.name===E);return v.length!==1||i(n.find($=>$.callee===x.callee)?.open??0)?.params?.includes(E)?null:v[0]}}}function cr(e,t,n={}){let{toks:o}=e,r=Ct(e),s=t.filter(w=>w.params!==null),i=w=>Ue(s,w),l=(w,E)=>{let v=i(E);return r.findLast($=>$.at<E&&$.name===w&&i($.at)===v)??(v?.params?.includes(w)?void 0:r.findLast($=>$.at<E&&$.name===w&&i($.at)===null))},a=[],c=[];for(let w=0;w<o.length;w++)a.push([...c]),S(o[w],"{")?c.push(w):S(o[w],"}")&&c.pop();let p=(w,E)=>a[w].every((v,$)=>a[E]?.[$]===v),f=w=>["const","let"].includes(o[w.at-1]?.text),u=w=>f(w)||_(o[w.at-1],"var"),d=new Map;for(let w of r)d.set(w,u(w)?w:r.findLast(E=>E.at<w.at&&E.name===w.name&&i(E.at)===i(w.at)&&u(E)&&(!f(E)||p(E.at,w.at))));let m=(w,E,v)=>r.some($=>$.name===w&&i($.at)!==E&&v($.at)&&!d.get($)&&!i($.at)?.params?.includes(w)),g=(w,E)=>{let v=i(E);return!m(w,v,$=>v!==null&&v.from<$&&$<v.to)},h=w=>{let E=i(w.at);if(!E?.params?.includes(w.name))return!1;let v=o.findIndex(($,R)=>E.from<R&&R<w.at&&S($,"("));return v>=0&&w.at<I(o,v)},k=(w,E)=>{let v=i(w.from);return p(w.from,E)&&(v===null||(n.enclosingBindings?v.from<E&&E<v.to:v===i(E)))},y=w=>{for(let E=w.at-1;E>=0&&![";","{","}"].includes(o[E].text);E--){if([")","]"].includes(o[E].text)){E=ee(e,E);continue}if(["if","else","for","while","case","and","or"].includes(o[E].text)||["?","&","|"].includes(o[E].text))return!0}return!1};return{assignments:r,functions:s,owner:i,legacyBinding:l,inBlock:p,lexical:f,declarations:d,parameterIsCertain:g,parameterDefault:h,functionVisible:k,bindingIsCertain:(w,E)=>w.at<E&&p(w.at,E)&&(!n.enclosingBindings||!y(w))&&!m(w.name,i(w.at),v=>p(w.at,v)&&(!n.enclosingBindings||i(w.at)===null||i(w.at).from<v&&v<i(w.at).to)),binding:(w,E)=>{let v=i(E),$=r.filter(P=>{if(P.name!==w)return!1;let M=d.get(P);return!M||!f(M)||p(M.at,E)}),R=[...s.filter(P=>P.from<E&&E<P.to).sort((P,M)=>M.from-P.from),null],A=n.enclosingBindings?R.find(P=>P?.params?.includes(w)||$.some(M=>i(M.at)===P)||s.some(M=>M.name===w&&i(M.from)===P&&k(M,E))):void 0,L=$.filter(P=>n.enclosingBindings?i(P.at)===A:i(P.at)===v||!v?.params?.includes(w)&&i(P.at)===null),O=P=>{let M=d.get(P);return M&&f(M)?a[M.at].length:0},C=Math.max(-1,...L.map(O)),j=L.filter(P=>O(P)===C);return j.findLast(P=>P.at<E)??j[0]}}}function oe(e,t,n={}){let{toks:o}=e,r=pe(e),s=cr(e,t,n),{assignments:i,functions:l,owner:a,legacyBinding:c,binding:p,bindingIsCertain:f,parameterIsCertain:u,parameterDefault:d,functionVisible:m}=s,{importBinding:g,hasImport:h,loaderImport:k}=ar(e,s,r),y=(E,v=new Set)=>o.slice(E.from,E.to).flatMap(($,R)=>{let A=c($.text,E.from+R);return $.kind!=="ident"||!A||A.append||v.has(A.at)?[$]:y(A,new Set([...v,A.at]))}),b=E=>{let v=o[E.open-1].text;if(["readFileSync","readFile"].includes(v))return E.args[0]??null;if(!S(o[E.open-2],"."))return null;let $=E.open-3;if(v==="read_text"&&_(o[$]))return{from:E.from,to:$+1};if(!S(o[$],")"))return null;let R=ee(e,$),A=r.find(L=>L.open===R);return v==="read_text"?A?.callee==="Path"?A.args[0]??null:{from:R+1,to:$}:v==="read"&&A?.callee==="open"||v==="text"&&A?.callee==="Bun.file"?A?.args[0]??null:null},x=E=>{let[v,...$]=E.callee.split("."),R=g(v,E.open,!n.enclosingBindings);if(R){let L=R.module,O=$.at(-1)??R.name;return(/^(?:node:)?fs(?:\/promises)?$/.test(L.source)?["readFile","readFileSync","readdir","readdirSync"]:/^(?:node:)?path$/.test(L.source)?["join","resolve"]:/^(?:node:)?url$/.test(L.source)?["fileURLToPath"]:L.source==="pathlib"?["Path"]:[]).includes(O)?O:null}return(n.enclosingBindings?l.some(L=>L.from<E.open&&E.open<L.to&&L.params?.includes(v)):a(E.open)?.params?.includes(v))||p(v,E.open)||l.some(L=>L.name===v)||h(v,!n.enclosingBindings)||$.length&&!["fs","path","Bun"].includes(v)?null:$.at(-1)??v},w=r.flatMap(E=>{let v=b(E)??(["readFileSync","readFile"].includes(x(E)??"")?E.args[0]:null);return v?[{sourcePath:e.path,line:o[E.open-1].line,call:E,path:v,tokens:y(v)}]:[]});return{source:e,calls:r,assignments:i,functions:l,owner:a,binding:p,bindingIsCertain:f,parameterIsCertain:u,parameterDefault:d,functionVisible:m,pathTokens:y,importBinding:g,loaderImport:k,builtin:x,operations:w}}function ce({source:{toks:e}},t){let{from:n,to:o}=t;for(_(e[n],"await")&&n++;S(e[n],"(")&&I(e,n)===o-1;)n++,o--;return{from:n,to:o}}function Z(e,t){let{from:n,to:o}=ce(e,t);return e.calls.findLast(r=>r.to===o&&(r.from===n||_(e.source.toks[n],"new")&&r.from===n+1))}function In(e,t){let{toks:n}=e.source,{from:o}=t,r=o+1;if(S(n[o],"(")&&(r=I(n,o)+1,o++),!_(n[o])||!S(n[r],"=")||!S(n[r+1],">"))return null;let s=r+2;return S(n[s],"{")?_(n[s+1],"return")?(s+=2,{name:n[o].text,body:{from:s,to:ae(e.source,s)}}):null:{name:n[o].text,body:{from:s,to:t.to}}}function X(e,t,n=new Map,o=new Set){let{source:{toks:r,path:s},binding:i,builtin:l}=e,a=ce(e,t),{from:c,to:p}=a;if(c>=p||!r[c])return null;let f=r.slice(c,p).map(b=>b.text).join(""),u=b=>{let x=i(b,c);return!x||e.parameterDefault(x)&&n.has(b)&&n.get(b)!==void 0?e.parameterIsCertain(b,c)?n.get(b)??null:null:e.bindingIsCertain(x,c)&&!x.append&&!o.has(x.at)?X(e,x,n,new Set([...o,x.at])):null},d=b=>X(e,b,n,o);if(p===c+1){let b=r[c];if(e.source.lang==="py"&&b.formatted&&b.value.includes("{"))return null;if(b.kind==="string"||b.kind==="template"&&!b.value.includes("${"))return/^(?:[a-z]+:|[/\\])/i.test(b.value)?null:b.value;if(b.kind==="template"){let x=!1,w=b.value.replace(/\$\{([^}]*)\}/g,(E,v)=>{if(!/^[A-Za-z_$][\w$]*$/.test(v))return x=!0,"";let $=u(v);return $==null&&(x=!0),$??""});return x||/^(?:[a-z]+:|[/\\])/i.test(w)?null:w}if(_(b,"__dirname")&&!i(b.text,c)&&!e.owner(c)?.params?.includes(b.text))return`/repository/${rt.dirname(s)}`;if(_(b))return u(b.text)}let m=[];for(let b=c;b<p;b++){if(["(","[","{"].some(x=>S(r[b],x))){b=I(r,b);continue}m.push(b)}let g=m.find(b=>S(r[b],"?")&&S(r[b+1],"?"));if(g!==void 0){let b=d({from:c,to:g});if(b!==null)return b;let x=g===c+1&&_(r[c])&&!i(r[c].text,c)?r[c].text:null;return x&&e.owner(c)?.params?.includes(x)&&e.parameterIsCertain(x,c)&&(!n.has(x)||n.get(x)===void 0)?d({from:g+2,to:p}):null}let h=m.find(b=>S(r[b],"+"));if(h!==void 0){let b=d({from:c,to:h}),x=d({from:h+1,to:p});return b===null||x===null?null:b+x}if(f==="import.meta.url")return`/repository/${s}`;let k=Z(e,a);if(!k)return null;let y=l(k);if(y==="URL"&&k.args.length===2){let b=r.slice(k.args[1].from,k.args[1].to).map(w=>w.text).join(""),x=d(k.args[0]);return b==="import.meta.url"&&x!==null&&!/^(?:[a-z]+:|[/\\])/i.test(x)?rt.join("/repository",rt.dirname(s),x):null}if(y==="fileURLToPath"||y==="Path")return k.args.length===1?d(k.args[0]):null;if(y==="join"||y==="resolve"){let b=k.args.map(d);return b.length&&b.every(x=>x!==null)&&b.every(x=>x.startsWith("/repository/")||!/^(?:[a-z]+:|[/\\])/i.test(x))?y==="resolve"?rt.resolve("/repository",...b):rt.join(...b):null}return null}function fr(e,t){let n=ce(e,t),o=e.source.toks[n.from],r=_(o,"null")||_(o,"undefined")&&!e.binding(o.text,n.from)&&!e.owner(n.from)?.params?.includes(o.text);return n.to===n.from+1&&r?void 0:X(e,n)}import{posix as jt}from"node:path";function me(e,t){if(e===null)return null;let n=e.startsWith("/repository/")?e.slice(12):e.startsWith(".")?jt.join(jt.dirname(t),e):e,o=jt.normalize(n.replace(/\\/g,"/")).replace(/\/$/,"");return o===".."||o.startsWith("../")||/^(?:[a-z]+:|\/)/i.test(o)?null:o}function ur(e,t){return{from:t.from,to:t.open-2}}function Mn(e,t,n,o=new Set){let r=ce(e,t),{source:{toks:s},binding:i}=e;if(r.to===r.from+1&&_(s[r.from])){let u=i(s[r.from].text,r.from);return u&&e.bindingIsCertain(u,r.from)&&!u.append&&!o.has(u.at)?Mn(e,u,n,new Set([...o,u.at])):null}let l=Z(e,r);if(!l)return null;if(["readdirSync","readdir"].includes(e.builtin(l)??"")&&l.args[0]){let u=me(X(e,l.args[0],n),e.source.path);return u===null?null:{path:u}}if(s[l.open-1].text!=="filter"||l.args.length!==1)return null;let a=In(e,l.args[0]),c=a&&Z(e,a.body),p=c?.args[0]&&X(e,c.args[0]);if(!a||c?.callee!==`${a.name}.endsWith`||!p||!be.test(`template${p}`))return null;let f=Mn(e,ur(e,l),n,o);return f?{...f,extension:p}:null}function pr(e,t,n,o){let{source:{toks:r}}=e;for(let s of e.calls){if(r[s.open-1].text!=="map"||s.args.length!==1)continue;let i=In(e,s.args[0]);if(!i||!(i.body.from<=t.from&&t.to<=i.body.to))continue;let l=Mn(e,ur(e,s),o);if(!l?.extension||e.owner(t.open)!==e.owner(s.open)||r.slice(i.body.from,t.from).some((f,u)=>{let d=i.body.from+u;return _(f,"function")||S(f,"=")&&S(r[d+1],">")}))continue;let c=new Map(o).set(i.name,"__template_entry__");if(me(X(e,n,c),e.source.path)===jt.join(l.path,"__template_entry__"))return{kind:"directory",path:l.path,extension:l.extension}}return null}function mr(e,t){let n=e.owner(t.open),o=new Set(e.assignments.filter(r=>e.owner(r.at)===n&&r.from<=t.from&&t.to<=r.to));for(let r of e.assignments)e.owner(r.at)!==n||r.from<=t.from||Tt(e,r,o)&&o.add(r);return o}function Tt(e,t,n){return e.source.toks.slice(t.from,t.to).some((o,r)=>{let s=t.from+r;if(S(e.source.toks[s-1],".")||S(e.source.toks[s+1],":"))return!1;let i=_(o)&&e.binding(o.text,s);return i&&n.has(i)})}function dr(e,t,n,o){if(!t)return!1;let{toks:r}=e.source;for(let i=t.from;i<t.to;i++){if(!_(r[i],"return")||e.owner(i)!==t)continue;let l={from:i+1,to:ae(e.source,i+1)};if(l.from<=n.from&&n.to<=l.to||Tt(e,l,o))return!0}let s=r.findIndex((i,l)=>t.from<l&&l<n.from&&S(i,"=")&&S(r[l+1],">"));return s>=0&&!S(r[s+2],"{")}function Cn(e,t,n,o=!1){let r=(o?n.replace(be,""):n).replace(/\\/g,"/"),s=c=>o?c.path.replace(be,""):c.path,i=Nt.dirname(t);for(;;){let c=Nt.normalize(Nt.join(i,r)),p=e.filter(f=>s(f)===c);if(p.length)return p.length===1?p:[];if(i==="."||i==="/")break;i=Nt.dirname(i)}if(r.includes("/"))return[];let l=o?e.filter(c=>s(c)===r||s(c).endsWith(`/${r}`)):nt([...e],r),a=l.length||!o?l:e.filter(c=>tt(s(c))===tt(r));return a.length===1?a:[]}function gr(e){return e.filter(({call:t})=>{let n=t.callee.split(".").at(-1);return n==="readFile"||n==="readFileSync"||["read_text","read","text"].includes(n??"")&&t.from<t.open-1})}function Ge(e){return e.filter(t=>be.test(t))}function hr(e,t,n){let{tokens:o}=e,r=o.filter(a=>a.kind==="string"||a.kind==="template").filter(a=>a.value.length<=200).map(a=>a.value),s=r.map(a=>{let c=Do.exec(a);return c?a.slice(0,c.index+c[0].length).replace(/\\/g,"/"):null}).find(a=>a!==null)??null,i=Ge(r)[0]?.match(/\.[^./\\]+$/)?.[0]??null;if(s===null&&i===null)return null;let l=t.params.findIndex(a=>a!==null&&o.some((c,p)=>_(c,a)&&!S(o[p-1],".")?!0:c.kind!=="template"&&!c.formatted?!1:(c.value.match(/\$?\{[^}]*\}/g)??[]).some(f=>{let u=po(f.replace(/^\$?\{|\}$/g,""),n);return u.some((d,m)=>_(d,a)&&!S(u[m-1],"."))})));return l<0?null:{folder:s,ext:i,paramIndex:l}}function Mi(e,t,n,o){let r=t.loaderImport(n,V(e));if(!r)return null;let s=Ke({files:o.map(i=>({path:i.source.path}))},{path:t.source.path},r).map(i=>i.path);return{binding:r,paths:s}}function st(e,t){let n=e.builtin(t);if(["readFileSync","readFile"].includes(n??""))return!0;if(!["read_text","read","text"].includes(n??""))return!1;let o=n==="read_text"?"Path":n==="read"?"open":"file";return e.calls.some(r=>r.from===t.from&&r.to<t.to&&e.builtin(r)===o)}function xr(e,t,n,o="anchored"){let r=Object.entries(t).flatMap(([f,u])=>{if(n?.source.path===f)return[oe(n.source,n.scopes)];let d=W(f);if(!d)return[];let m=G(f,u,d);return[oe(m,U(m))]});n&&!r.some(f=>f.source===n.source)&&r.push(oe(n.source,n.scopes));let s=r.flatMap(f=>f.operations);if(o==="operations")return{operations:s,reads:[],dependencies:[]};let i=r.flatMap(f=>f.functions.map(u=>({syntax:f,scope:u}))),l=new Map,a=new Set,c=(f,u)=>{let d=u.callee.split(".")[0];if(f.owner(u.open)?.params?.includes(d))return[];let m=f.binding(d,u.open),g=i.filter(y=>y.syntax===f&&y.scope.name===u.callee&&f.functionVisible(y.scope,u.open));if(g.length)return g.filter(y=>!m||m.at===y.scope.from+1);if(m)return[];let h=Mi(e,f,u,r);if(!h)return[];if(!h.paths.length)for(let y of xo(f.source.path,h.binding.source,[h.binding.imported],f.source.lang,!0))a.add(y);let k=u.callee.split(".")[1]??h.binding.imported;return i.filter(y=>h.paths.includes(y.syntax.source.path)&&y.scope.name===k&&y.syntax.owner(y.scope.from)===null)};for(let f of r)for(let u of f.calls){let d=c(f,u);for(let m of d){let g=new Map((m.scope.params??[]).flatMap((k,y)=>k===null?[]:[[k,d.length!==1?null:u.args[y]?fr(f,u.args[y]):void 0]])),h=l.get(m.scope)??[];h.push({parameters:g,...d.length===1&&m.syntax!==f?{consumer:f.source.path}:{}}),l.set(m.scope,h)}}let p=[];for(let f of r)for(let u of f.operations){if(!st(f,u.call))continue;let d=f.owner(u.call.open),m=d?l.get(d)??[{parameters:new Map}]:[{parameters:new Map}];for(let g of m){let h=me(X(f,u.path,g.parameters),f.source.path),k=h===null?pr(f,u.call,u.path,g.parameters):{kind:"file",path:h};if(!k)continue;let y=mr(f,u.call),b=new Set(g.consumer&&dr(f,d,u.call,y)?[g.consumer]:[]);for(let E of f.calls){if(f.owner(E.open)!==d||!E.args.some($=>Tt(f,$,y)))continue;let v=c(f,E);v.length===1&&v[0].syntax!==f&&b.add(v[0].syntax.source.path)}let x=p.find(E=>E.sourcePath===u.sourcePath&&E.line===u.line&&JSON.stringify(E.target)===JSON.stringify(k)),w=[...b].sort();x?x.consumerPaths=[...new Set([...x.consumerPaths,...w])].sort():p.push({sourcePath:u.sourcePath,line:u.line,target:k,consumerPaths:w})}}return{operations:s,reads:p,dependencies:[...a].sort()}}var Ci=30;function Sr(e,t){let n=(e?.modelIds??[]).filter(o=>Math.abs(o.line-t)<=Ci);return n.sort((o,r)=>Math.abs(o.line-t)-Math.abs(r.line-t)||o.line-r.line),n[0]??null}function it(e,t,n,o){let r=Sr(e.byPath.get(t),n);return r||!o?r:Sr(e.byPath.get(o.path),o.line)}function ji(e,t,n){let o=n.model;if(o?.kind==="literal"&&Mt.test(o.text))return t.modelIds.find(u=>u.value===o.text&&u.line>=n.line)??{value:o.text,path:t.path,line:n.line};if(o?.kind!=="member")return null;let[r,s,i]=o.text.split(".");if(!s||i)return null;let l=new Map;for(let u of e.files)for(let d of u.modelMembers??[])l.set(d.object,[...l.get(d.object)??[],d]);let a=Ae(e,t,r,l).filter(u=>u.member===s);if(a.length!==1)return null;let{value:c,path:p,line:f}=a[0];return{value:c,path:p,line:f}}function Ti(e,t,n){if(!n.shape)return;let o=t.imports.find(s=>s.name===n.shape),r=o?Ke(e,t,o):[];return{name:n.shape,path:r.length===1?r[0].path:t.path,line:o?.line??n.line}}function jn(e,t){let n=new Map,o=new Map;for(let i of e.files){for(let l of i.loaders??[])n.set(l.name,[...n.get(l.name)??[],l]);for(let l of i.promptReturns??[])o.set(l.fn,[...o.get(l.fn)??[],l])}let r=e.files.flatMap(i=>i.sites.filter(l=>l.kind==="file")),s=(i,l,a,c=new Set)=>{let p=`${i.path}:${JSON.stringify(l)}`;if(c.has(p)||c.size>=50)return[];let f=new Set([...c,p]);if(l.kind==="site")return i.sites.filter(h=>h.start===l.siteStart).map(h=>({site:h,sdk:i.sdk}));if(l.kind==="symbol"||l.kind==="module-member"){let[h,k]=l.callee.split("."),y=h.replace(/\(\)$/,""),b=(i.promptBindings??[]).filter(R=>R.name===l.callee.replace("().","."));if(!l.importBinding&&b.length)return b.flatMap(R=>R.loads.flatMap(A=>s(i,A,a,f)));let x=l.importBinding?[l.importBinding]:i.imports.filter(R=>R.name===y);if(x.length!==1)return[];let w=x[0],E=Ke(e,i,w);if(E.length!==1)return[];let v=E[0],$=l.kind==="module-member"?k:k?`${w.imported}.${k}`:w.imported;return $?s(v,{kind:"symbol",callee:$,literals:[]},a,f):[]}if(l.kind==="bound-file"||l.kind==="chainlite")return l.literals.flatMap(h=>{let k=l.kind==="bound-file"?[h]:[Ft.join(Ft.dirname(i.path),h),Ft.join(Ft.dirname(i.path),"prompts",h)],y=r.filter(b=>k.includes(b.path));return y.length===1?y.map(b=>({site:b,sdk:l.kind==="chainlite"||i.sdk})):[]});let u=l.kind==="loader"||l.kind==="return",d=u?Ae(e,i,l.callee,n):[];if(d.length)return d.flatMap(h=>l.literals.flatMap(k=>{let y=h.ext&&!k.endsWith(h.ext)?k+h.ext:k,b=h.folder?`${h.folder}/${y}`:y;return Cn(r,h.path,b,!h.ext).map(w=>({site:w,sdk:e.byPath.get(h.path)?.sdk??!1}))}));let m=u&&a?Ae(e,i,l.callee,o):[];return m.length?m.flatMap(h=>h.loads.flatMap(k=>s(e.byPath.get(h.path),k,!1,f))):l.kind==="read"||l.kind==="file-key"?Ge(l.literals).flatMap(h=>Cn(r,i.path,h).map(k=>({site:k,sdk:i.sdk}))):[]};for(let i of e.files){if(i.sdk||i.callSites.some(a=>a.kind==="system-arg"))for(let a of i.loadedPromptRefs??[])for(let c of r.filter(p=>p.path===a.value))$e(t,c,{kind:"L3",callPath:i.path,callLine:a.line,callExcerpt:a.value,wrapper:null,shortLabel:null,sdk:i.sdk,modelId:it(e,i.path,a.line,null)});let l=new Map;for(let a of i.deliveries??[]){let c=`${a.callStart??a.line}:${a.callee}`;l.set(c,[...l.get(c)??[],a])}for(let a of l.values()){let c={...a[0],model:a.find(m=>m.model)?.model??null,shape:a.find(m=>m.shape)?.shape??null},p=a.flatMap(m=>m.loads.flatMap(g=>s(i,g,!0))),f=[...new Map(p.map(m=>[H(m.site),m.site])).values()];if(!f.length)continue;let u=f.slice(1).map(m=>m.path),d=Ti(e,i,c);$e(t,f[0],{kind:"L4",callPath:i.path,callLine:c.line,callExcerpt:`${c.callee}(\u2026)`,...c.callStart!==void 0?{callStart:c.callStart}:{},wrapper:null,shortLabel:null,sdk:i.sdk||p.some(m=>m.sdk),modelId:ji(e,i,c),...u.length?{alsoLoads:u}:{},...d?{shape:d}:{}})}}}function kr(e,t,n,o,r=!1){let s=e.files.filter(i=>i.path!==t.path).flatMap(i=>i.sites.filter(l=>l.symbol===n));return On(e,t,o,s,r)}function wr(e,t,n){let o=t.sites.filter(s=>s.symbol===n);if(o.length>0)return o;let r=t.imports.find(s=>s.name===n);return r?kr(e,t,r.imported,r):[]}function Ni(e,t,n,o){return kr(e,t,o,n,!0)}function Fi(e,t,n){let o=(e.wrappers.get(n)??[]).filter(i=>i.path===t.path);if(o.length>0)return o;let r=t.imports.find(i=>i.name===n);if(!r)return[];let s=e.wrappers.get(r.imported)??[];return On(e,t,r,s)}function Di(e,t,n,o){if(n.kind!=="system-arg"||!n.value)return!1;let r=br(e,t,n.value);for(let s of r)$e(o,s,{kind:"L1",callPath:t.path,callLine:n.line,callExcerpt:`system prompt ${n.value.text}`,wrapper:null,shortLabel:n.shortLabel??null,sdk:t.sdk,modelId:it(e,t.path,n.line,null)});return r.length>0}function Bi(e,t){return e.args.find(n=>n.name===t.paramName)??e.args.filter(n=>n.name===null)[t.paramIndex]}function br(e,t,n){return n.kind==="literal"&&n.siteStart!==null?t.sites.filter(o=>o.start===n.siteStart):n.kind==="identifier"?wr(e,t,n.text):n.kind==="member"?Wi(e,t,n.text):[]}function Wi(e,t,n){let o=/^(\w+)\.(\w+)$/.exec(n);if(!o)return[];let r=t.imports.find(s=>s.name===o[1]);return r?Ni(e,t,r,o[2]):/^(?:self|cls|this|[A-Z]\w*)$/.test(o[1])?wr(e,t,o[2]):[]}function Ki(e,t,n){for(let o of t.wrapperCalls)for(let r of Fi(e,t,o.name)){let s=Bi(o,r);if(s)for(let i of br(e,t,s))$e(n,i,{kind:"L2",callPath:t.path,callLine:o.line,callExcerpt:`${o.name}(\u2026)`,wrapper:r,shortLabel:o.shortLiterals.length===1?o.shortLiterals[0]:null,sdk:t.sdk||(e.byPath.get(r.path)?.sdk??!1),modelId:it(e,t.path,o.line,r)})}}function Tn(e,t=!1){return e.filter(n=>n.sdk||n.callSites.some(o=>o.kind==="system-arg")).flatMap(n=>t?n.priorFileRefs??[]:n.fileRefs)}function nu(e,t){let n=e.flatMap(o=>nt(t,o.value).map(r=>({promptPath:r.path,readerPath:o.path})));return[...new Map(n.map(o=>[JSON.stringify(o),o])).values()]}function yr(e,t){let n=e.files.flatMap(o=>o.sites.filter(r=>r.kind==="file"));if(n.length!==0)for(let o of Tn(e.files)){let r=e.byPath.get(o.path);for(let s of nt(n,o.value))$e(t,s,{kind:"L3",callPath:r.path,callLine:o.line,callExcerpt:o.value,wrapper:null,shortLabel:null,sdk:r.sdk,modelId:it(e,r.path,o.line,null)})}}function _r(e,t={}){let n=new Map;for(let a of e.flatMap(c=>c.wrappers))n.set(a.name,[...n.get(a.name)??[],a]);let o={byPath:new Map(e.map(a=>[a.path,a])),files:e,wrappers:n,moduleResolver:t.moduleResolver},r=new Map,s=[];for(let a of e){for(let c of a.callSites)c.kind!=="system-arg"||Di(o,a,c,r)||c.value&&c.value.kind!=="literal"&&s.push({path:a.path,line:c.line});Ki(o,a,r)}let i;if(t.includePrior&&e.some(a=>a.priorDeliveries!==void 0)){let a=e.map(p=>p.priorDeliveries===void 0?p:{...p,deliveries:p.priorDeliveries,fileRefs:p.priorFileRefs??p.fileRefs,promptBindings:void 0,loadedPromptRefs:void 0}),c={...o,files:a,byPath:new Map(a.map(p=>[p.path,p]))};i=new Map(r),yr(c,i),jn(c,i)}yr(o,r),jn(o,r);let l=new Set([...r.values()].flat().filter(a=>a.kind==="L4").map(a=>`${a.callPath}:${a.callLine}`));return{links:r,...i?{priorLinks:i}:{},callsWithoutPrompt:s.filter(a=>!l.has(`${a.path}:${a.line}`))}}var lt={named:3,prose:2,file:3,link:4,sdk:1},Ui=6,Gi=3,Er={L1:0,L2:1,L4:1.5,L3:2};function at(e,t){return e<t?-1:e>t?1:0}function zi(e){return[...e].sort((n,o)=>Er[n.kind]-Er[o.kind]||Number(o.sdk)-Number(n.sdk)||at(n.callPath,o.callPath)||n.callLine-o.callLine)[0]??null}function Vi(e){return(e.named?lt.named:0)+(e.prose?lt.prose:0)+(e.kind==="file"?lt.file:0)}function Nn(e,t,n){let o=zi(t),r=n||t.some(i=>i.sdk),s=Vi(e)+(o?lt.link:0)+(r?lt.sdk:0);return s<Gi?null:{tier:s>=Ui?"strong":"possible",score:s,prompt:e,link:o&&{kind:o.kind,callPath:o.callPath,callLine:o.callLine,callExcerpt:o.callExcerpt,...o.callStart!==void 0?{callStart:o.callStart}:{},wrapper:o.wrapper,shortLabel:o.shortLabel},sdk:r,modelId:o?.modelId??null,...o?.alsoLoads?.length?{alsoLoads:o.alsoLoads}:{},...o?.shape?{shape:o.shape}:{}}}function Dt(e,t){return(t.selectionScore??t.score)-(e.selectionScore??e.score)||at(e.prompt.path,t.prompt.path)||e.prompt.line-t.prompt.line}function vr(e,t){let n={files:e},o=new Map(e.map(a=>[a.path,a])),r=t.flatMap(a=>{let c=a.link;if(c?.kind!=="L4")return[];let p=o.get(c.callPath),f=p?.deliveries?.find(d=>d.line===c.callLine&&`${d.callee}(\u2026)`===c.callExcerpt&&(c.callStart===void 0||d.callStart===c.callStart));if(!f)return[];let u=p?.stepCalls?.find(d=>d.callStart===f.callStart&&d.line===f.line);return[{path:c.callPath,candidate:a,delivery:f,enclosingStart:u?.enclosingStart}]}),s=new Map;for(let a of r){let c=a.delivery.enclosing;c&&s.set(c,[...s.get(c)??[],a])}let i=new Map,l=(a,c,p)=>{let f=H(a.candidate.prompt),u=H(c.candidate.prompt);if(f===u)return;let d=i.get(f)??[];d.some(m=>m.to===u&&m.kind===p)||d.push({to:u,kind:p}),i.set(f,d)};for(let a of e){let c=r.filter(u=>u.path===a.path),p=[...a.stepCalls??[]];for(let{delivery:u}of c)p.some(d=>Rr(d,u))||p.push({callee:u.callee,line:u.line,callStart:u.callStart,enclosing:u.enclosing,resultVar:u.resultVar,argNames:[]});p.sort((u,d)=>u.line-d.line||(u.callStart??0)-(d.callStart??0));let f=new Map;for(let u of p){let d=u.localTarget===null?[]:Ae(n,a,u.callee,s).filter(k=>u.localTarget===void 0||k.enclosingStart===u.localTarget),m=c.filter(k=>k.delivery.enclosing!==null&&k.delivery.enclosing===u.enclosing&&(k.enclosingStart===void 0||u.enclosingStart===void 0||k.enclosingStart===u.enclosingStart));for(let k of m)for(let y of d)l(k,y,"calls");let g=`${u.enclosing??""}:${u.enclosingStart??""}`,h=f.get(g)??new Map;for(let k of u.argNames){let y=h.get(k);if(!(!y||u.argCalls&&Object.hasOwn(u.argCalls,k)&&u.argCalls[k]!==y.callStart))for(let b of y.steps)for(let x of d)l(b,x,"feeds")}u.resultVar&&h.set(u.resultVar,{steps:[...d,...c.filter(k=>Rr(u,k.delivery))],callStart:u.callStart}),f.set(g,h)}}return i}function Rr(e,t){return e.line===t.line&&e.callee===t.callee&&(t.callStart===void 0||e.callStart===t.callStart)}function Fn(e){let{links:t,callsWithoutPrompt:n,priorLinks:o}=_r(e,{includePrior:!0}),r=new Set([...t.values()].flatMap(p=>p.flatMap(f=>f.alsoLoads??[]))),s=[];for(let p of e)for(let f of p.sites){if(r.has(f.path)&&!(t.get(H(f))??[]).some(d=>d.kind!=="L3"))continue;let u=Nn(f,t.get(H(f))??[],p.sdk);if(u&&o){let d=Nn(f,o.get(H(f))??[],p.sdk);d?.score!==u.score&&(u.selectionScore=d?.score??0)}u&&s.push(u)}s.sort(Dt);let i=vr(e,s);for(let p of s){let f=i.get(H(p.prompt));f?.length&&(p.links=f)}let l=e.flatMap(p=>p.modelIds).sort((p,f)=>at(p.path,f.path)||p.line-f.line),a=Tn(e,!0),c=e.flatMap(p=>p.snippets??[]).map(p=>{let f=Fn([p.hits]),u={path:p.hits.path,span:p.span,imports:p.hits.imports,status:"unresolved"};return{...f,strong:f.strong.map(d=>({...d,documentation:u})),possible:f.possible.map(d=>({...d,documentation:u})),documentation:u}});return{...a.length?{filenameReferences:a}:{},strong:[...s.filter(p=>p.tier==="strong"),...c.flatMap(p=>p.strong)].sort(Dt),possible:[...s.filter(p=>p.tier==="possible"),...c.flatMap(p=>p.possible)].sort(Dt),callsWithoutPrompt:[...n,...c.flatMap(p=>p.callsWithoutPrompt)].sort((p,f)=>at(p.path,f.path)||p.line-f.line),repoModelIds:l,...c.length?{documentedImports:c.map(p=>p.documentation)}:{},scanned:e.length}}import{posix as pt}from"node:path";function ct(e,t){let{toks:n}=e;if(S(n[t],"(")){let o=Dn(e,t+1);return o&&S(n[o.next],")")?{...o,next:o.next+1}:null}return S(n[t],"[")?Ji(e,t):Dn(e,t)}function Dn(e,t){let{toks:n}=e,o=[],r=t;for(;J(n[r]);)o.push(n[r]),r++,S(n[r],"+")&&J(n[r+1])&&r++;return o.length===0?null:{start:o[0].start,line:o[0].line,endLine:o[o.length-1].endLine,text:o.map(s=>s.value).join(""),partStarts:o.map(s=>s.start),next:r,...o.some(Bn)?{filledAtRunTime:!0}:{}}}function Bn(e){return!!e.formatted&&(e.kind==="template"||Xi(e.value))}function Xi(e){for(let t=0;t<e.length;t++)if(e[t]==="{"){if(e[t+1]==="{"){t++;continue}return e.indexOf("}",t+1)>=0}return!1}function ft(e,t,n=e.toks.length){let{toks:o}=e;if(e.lang==="py")for(;t<n&&S(o[t],"(");)t++;if(e.lang==="py"&&_(o[t],"lambda")){for(let r=t+1;r<n;r++){if(S(o[r],":"))return r+1;["(","[","{"].some(s=>S(o[r],s))&&(r=I(o,r))}return null}if(e.lang!=="js")return null;for(;t<n;){let r=_(o[t],"async")?t+1:t,s=S(o[r],"(")?I(o,r):-1,i=s>=0?s+1:_(o[r])?r+1:-1;if(S(o[i],":")){let l=Math.min(n,i+Ne);for(;i<l&&!S(o[i],"=");)i++}if(i>=0&&i+2<n&&S(o[i],"=")&&S(o[i+1],">"))return i+2;if(s<0)return null;t=r+1,n=Math.min(n,s)}return null}function Ji(e,t){let{toks:n}=e,o=t+1;if(!S(n[o],"{"))return null;let r=I(n,o),s=S(n[r+1],",")?r+2:r+1;if(!S(n[s],"]"))return null;for(let i=o+1;i<r;i++){let l=n[i];if((_(l)&&l.text==="text"||l.kind==="string"&&l.value==="text")&&S(n[i+1],":")){let c=Dn(e,i+2);return c&&{...c,next:s+1}}}return null}var Wn={kind:"other",text:"",siteLine:null,siteStart:null};function Q(e,t,n,o=e.toks.length,r=!1){let{toks:s}=e,i=r?ft(e,n,o):null,l=ct(e,i??n);if(i!==null&&(!l||!t.has(l.start)))return Wn;if(l&&l.next<=o){let p=t.get(l.start)??null;return{kind:"literal",text:xe(l.text),siteLine:p,siteStart:p===null?null:l.start}}if(!_(s[n]))return Wn;let a=n+1,c=!1;for(;;){let p=S(s[a],"?")&&S(s[a+1],".")?a+1:a;if(!S(s[p],".")||!_(s[p+1]))break;a=p+2,c=!0}return a<o&&!Yi(s[a],he(s,a))?Wn:{kind:c?"member":"identifier",text:e.text.slice(s[n].start,s[a-1].end),siteLine:null,siteStart:null}}function Yi(e,t){return t||e.kind==="punct"&&",)}];".includes(e.text)}var $r=new Set(["system","systemPrompt","system_prompt","instructions"]);function Kn(e,t){let n=Le(e.toks[t-2]);if(n===null||!$r.has(n)||Ar(e,t-2)!==t)return!1;let o=ee(e,t-2);if(e.lang==="py"&&e.toks[t-2].kind==="ident")return q(e.toks,o-1,e)&&!S(e.toks[t-3],".");if(!S(e.toks[o],"{"))return!1;let r=ee(e,o);if(!q(e.toks,r-1,e))return!1;let s=o-1;return e.lang==="py"&&(S(e.toks[s],"*")&&S(e.toks[s-1],"*")||S(e.toks[s],"=")&&_(e.toks[s-1]))&&(s-=2),s===r||S(e.toks[s],",")}function de(e,t,n,o=!1,r=!1){let s=[];return e.toks.forEach((i,l)=>{let a=Ar(e,l);if(a===null)return;let c=qi(e,n,a,r&&Kn(e,a)),p=o?Hi(e,l):null;s.push({valueAt:a,site:{kind:"system-arg",path:e.path,line:i.line,value:c,enclosing:te(t,l),...p?{shortLabel:p}:{}}})}),s}function qi(e,t,n,o){let{toks:r}=e,s=Q(e,t,n,r.length,o);if(s.kind!=="other")return s;if(S(r[n],"[")){let l=I(r,n);for(let a=n+1;a<l;a++)if(Le(r[a])==="text"&&S(r[a+1],":"))return Q(e,t,a+2)}let i=S(r[n+1],"?")&&S(r[n+2],"?")||S(r[n+1],"|")&&S(r[n+2],"|");return _(r[n])&&i?Q(e,t,n,n+1):s}var Le=e=>e?.kind==="string"?e.value:e?.kind==="ident"?e.text:null;function Hi(e,t){let{toks:n}=e,o=0;for(let r=t-1;r>=0;r--){let s=n[r];if(s.kind==="punct"){if(")]}".includes(s.text))o++;else if("([{".includes(s.text)){if(o>0){o--;continue}let i=e.lang==="js"&&S(s,"{")?r-1:r;return!S(n[i],"(")||!Zi(e,i-1)||e.lang==="js"&&i===r?null:Qi(e,r)}}}return null}function Zi(e,t){let{toks:n}=e;if(e.lang==="js"&&S(n[t],">")){let o=0;do S(n[t],">")&&!S(n[t-1],"=")?o++:S(n[t],"<")&&o--,t--;while(t>=0&&o>0)}return _(n[t],"Agent")}function Qi(e,t){let{toks:n}=e;for(let{from:o,to:r}of T(n,t).reverse()){let s=n[o],i=(_(s,"get")||_(s,"set"))&&(Le(n[o+1])==="name"||S(n[o+1],"["));if(S(s,".")||S(s,"[")||S(s,"*")||i)return null;if(Le(s)!=="name")continue;let l=e.lang==="py"?B(n,o+1):S(n[o+1],":"),a=n[o+2];if(!l||r!==o+3||a?.kind!=="string")return null;let{prefix:c,closed:p}=Te(a);return p&&!/[fb]/i.test(c)&&a.value.trim()||null}return null}function Ar(e,t){let{toks:n}=e,o=n[t],r=Le(o),s=l=>B(n,l),i=l=>S(n[l],":")||e.lang==="py"&&s(l);return r!==null&&$r.has(r)?(e.lang==="py"&&o.kind==="ident"?s(t+1):i(t+1))?e.lang==="js"&&tl(e,t)?null:t+2:e.lang==="js"&&o.kind==="ident"&&(S(n[t-1],"{")||S(n[t-1],","))&&(S(n[t+1],",")||S(n[t+1],"}"))&&!Qt(e,t)?t:null:r==="role"&&i(t+1)&&n[t+2]?.kind==="string"&&n[t+2].value==="system"?el(e,t+3):(S(o,"(")||S(o,"["))&&n[t+1]?.kind==="string"&&n[t+1].value==="system"&&S(n[t+2],",")?t+3:_(o,"SystemMessage")&&S(n[t+1],"(")?Le(n[t+2])==="content"&&i(t+3)?t+4:t+2:null}function el(e,t){let{toks:n}=e;if(!S(n[t],",")||Le(n[t+1])!=="content")return null;let o=n[t+2];return S(o,":")||S(o,"=")?t+3:null}function tl(e,t){let n=e.toks[t+2];return _(n)&&So(n.text)||Qt(e,t)}function Lr(e,t,n,o,r={}){let s=W(e);if(!s)return[];let i=G(e,t,s),{toks:l}=i,a=z(i),c=U(i,{includeMembers:!0}),p=ut(i,"default");p?.name==="default"&&c.push(p),c.sort((g,h)=>g.from-h.from||h.to-g.to);let f=[],u=sl(i),d=rl(i,o),m=g=>c.filter(h=>h.params!==null&&h.from<g&&g<h.to).at(-1)?.name??null;for(let g of St(e,t,s,!0)){let h=a.find(x=>x.source===g.source&&x.names.join("\0")===g.names.join("\0")),k=h?.names.map(x=>({name:x,imported:h.defaultName===x?"default":h.renamed?.[x]??x}))??ol(i,g.source),y=h?.line??l.find(x=>x.kind==="string"&&x.value===g.source)?.line??1,b=nl(i,y);for(let{name:x,imported:w}of k){let E=ue(e,g.source,[w],s,n,!0)??null,v={from:e,to:E,symbol:x,imported:w,source:g.source,...E?{}:{reason:g.source.startsWith(".")?"missing":"external"}},$=l.some((L,O)=>O>b&&_(L,x)&&B(l,O+1))||c.some(L=>L.name===x&&L.from>b&&!c.some(O=>O.from<L.from&&L.from<O.to&&(O.params!==null||O.kind==="class")));if($)continue;let R=Pr(i,x);for(let L of R)f.push({...v,symbol:L,kind:"import",usage:"reexport",within:null,span:{from:y,to:y}});let A=h?l.flatMap((L,O)=>!$&&_(L,x)&&O>b&&!["def","function","class"].includes(l[O-1]?.text??"")&&(!S(l[O-1],".")||S(l[O-2],".")&&S(l[O-3],"."))&&!c.some(C=>C.from<O&&O<C.to&&C.params?.includes(x))?[O]:[]):[];if(!A.length&&!R.length){let L=ne(r,"CF_IMPORT_LEXICAL_FACTS")?m(l.findIndex(O=>O.line===y)):null;f.push({...v,kind:"import",usage:L?"reference":"reexport",within:L,span:{from:y,to:y}})}for(let L of A){let O=u.find(M=>M.from<=L&&L<M.to),C=!d||d.from<=(O?.at??L)&&(O?.at??L)<d.to,j=O&&!C&&(O.kind!=="tool-registration"||d?.to===0),P=O&&(C||j)?O.kind:"import";f.push({...v,...j?{reason:"unlinked"}:{},kind:P,usage:q(l,L,i)?"call":"reference",within:m(L),span:{from:Math.min(l[O?.at??L].line,l[L].line),to:Math.max(l[O?.at??L].endLine,l[L].endLine)}})}}if(!k.length){let x=ue(e,g.source,[],s,n,!0)??null;f.push({from:e,to:x,kind:"import",symbol:"*",imported:"*",source:g.source,usage:"reexport",within:null,span:{from:y,to:y},...x?{}:{reason:g.source.startsWith(".")?"missing":"external"}})}}for(let g=0;g<l.length;g++)!_(l[g])||!["import","import_module","require"].includes(l[g].text)||!S(l[g+1],"(")||l[g+2]?.kind==="string"&&S(l[g+3],")")||f.push({from:e,to:null,kind:"import",symbol:"*",imported:"*",source:"",usage:"call",within:m(g),reason:"dynamic",span:{from:l[g].line,to:l[g].endLine}});return f.filter((g,h)=>f.findIndex(k=>JSON.stringify(k)===JSON.stringify(g))===h)}function nl(e,t){let{toks:n}=e,o=n.findIndex(r=>r.line===t);for(let r=o;r<n.length;r++){if(e.lang==="py"&&n[r].line>t)return r-1;if(S(n[r],";")||e.lang==="js"&&n[r].kind==="string")return r}return n.length-1}function ol(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++){if(!_(n[r],"export"))continue;let s=r+1;if(!S(n[s],"{"))continue;let i=I(n,s);!_(n[i+1],"from")||n[i+2]?.value!==t||o.push(...T(n,s).flatMap(l=>_(n[l.from])?[{name:n[l.to-1].text,imported:n[l.from].text}]:[]))}return o}function Pr(e,t){let{toks:n}=e,o=[];for(let r=0;r<n.length;r++)if(!(!_(n[r],"export")||!S(n[r+1],"{"))&&!_(n[I(n,r+1)+1],"from"))for(let s of T(n,r+1))_(n[s.from],t)&&o.push(n[s.to-1].text);return o}function ut(e,t){let n=U(e),{toks:o}=e;if(t==="default"){let s=o.findIndex((i,l)=>_(i,"default")&&_(o[l-1],"export"));if(s>=0){let i=s+1;_(o[i],"async")&&i++;let l=_(o[i],"function"),a=l?i+1:i;if(_(o[a])&&(t=o[a].text),S(o[a],"(")){let c=I(o,a),p=l?c+1:c+3;if(l||S(o[c+1],"=")&&S(o[c+2],">")){let f=S(o[p],"{")?I(o,p)+1:o.findIndex((u,d)=>d>=p&&S(u,";"));return{name:"default",line:o[i].line,from:i,to:f<0?o.length:f,params:T(o,a).map(u=>_(o[u.from])?o[u.from].text:null),kind:"function"}}}}}let r=n.find(s=>s.name===t);if(r)return r;for(let s of n)if(Pr(e,s.name).includes(t))return s;return null}function rl(e,t){if(!t||t.path!==e.path)return null;let{toks:n}=e,o=new Set([t.symbol]);for(let a of z(e))for(let c of a.names)(a.renamed?.[c]??c)===t.symbol&&o.add(c);let r=new Map;t.promptPath===e.path&&t.promptStart!==void 0&&r.set(t.promptStart,t.line??1);let s=de(e,[],r).filter(({site:a})=>(t.line===void 0||a.line===t.line)&&(a.value?.kind==="identifier"&&o.has(a.value.text)||a.value?.siteStart!=null&&a.value.siteStart===t.promptStart)),i=s.length===1?s[0].valueAt:void 0,l=[];for(let a=0;a<n.length;a++){if(!q(n,a,e))continue;let c=I(n,a+1);(t.callStart!==void 0?n[a].start===t.callStart:i!==void 0?a<i&&i<c:t.line!==void 0&&n[a].line<=t.line&&(n[c]?.endLine??0)>=t.line)&&l.push({from:a,to:c+1})}return i!==void 0||t.callStart!==void 0?l.at(-1)??{from:0,to:0}:l.length===1?l[0]:{from:0,to:0}}function sl(e){let{toks:t}=e,n=[],o=(r,s,i)=>{if(s&&(n.push({...s,at:r,kind:i}),s.to===s.from+1&&_(t[s.from]))){let l=t.flatMap((a,c)=>_(a,t[s.from].text)&&S(t[c+1],"=")?[c+2]:[]);l.length===1&&S(t[l[0]],"[")&&n.push({from:l[0],to:I(t,l[0])+1,at:r,kind:i})}};for(let r=0;r<t.length;r++){let s=t[r].kind==="string"?t[r].value:t[r].text;if(["tools","state_schema","context_schema","config_schema","model_config","llm_config"].includes(s)&&(S(t[r+1],"=")||S(t[r+1],":"))){let l=r+2,a=S(t[l],"[")?I(t,l)+1:l+1;o(r,{from:l,to:a},s==="tools"?"tool-registration":"config")}if(!S(t[r+1],"("))continue;let i=T(t,r+1);["add_node","addNode"].includes(s)&&o(r,i[1],"graph-node"),["StateGraph"].includes(s)&&o(r,i[0],"config"),["bind_tools","bindTools","ToolNode"].includes(s)&&o(r,i[0],"tool-registration")}return n}function Bu(e){return[...e].filter(t=>pt.basename(t)==="langgraph.json")}function Ir(e,t,n,o={}){if(pt.basename(e)==="langgraph.json")return il(e,t,n,o.root);if(W(e)!=="py")return[];let r=G(e,t,"py"),{toks:s}=r,i=U(r),l=oe(r,i,{enclosingBindings:!0}),a=o.root?`${o.root}/llm_config.yaml`:"llm_config.yaml",c=[],p=new Map;for(let f of l.calls){if(f.callee.includes("."))continue;let u=l.importBinding(f.callee,f.from);u?.module.source!=="chainlite"||u.name!=="llm_generation_chain"||s.some((d,m)=>_(d,f.callee)&&d.line!==u.module.line&&!S(s[m+1],"(")&&l.importBinding(f.callee,m)?.module===u.module)||s.some((d,m)=>_(d,"import")&&S(s[m+1],"*"))||p.set(f.callee,[...p.get(f.callee)??[],f.from])}for(let[f,u]of p){let d=o.call?.path===e?o.call:void 0,m=u.filter(g=>d?.callStart!==void 0?s[g].start===d.callStart:d?.line===void 0||s[g].line===d.line);for(let g of u){let h=I(s,g+1),k=i.filter(y=>y.params!==null&&y.from<g&&g<y.to).at(-1)?.name??null;c.push({from:e,to:n.has(a)?a:null,kind:"config",symbol:f,imported:"*",source:a,usage:"call",within:k,span:{from:s[g].line,to:s[Math.min(h,s.length-1)].endLine},...n.has(a)?d&&(m.length!==1||m[0]!==g)?{reason:"unlinked"}:{}:{reason:"missing"}})}}return c}function il(e,t,n,o){let r=()=>[{from:e,to:null,kind:"graph-node",symbol:"graphs",imported:"*",source:"",usage:"reference",within:null,span:{from:1,to:Math.max(1,t.split(`
|
|
23
|
+
`).length)},reason:"dynamic"}],s;try{s=JSON.parse(t)}catch{return r()}if(!Or(s)||!Or(s.graphs))return[];let i=s.graphs,l=G(e,t,"js"),{toks:a}=l,c=T(a,0).filter(f=>a[f.from]?.value==="graphs");if(c.length!==1)return r();let p=T(a,c[0].from+2);return p.map(f=>{let u=a[f.from].value,d=i[u],m=p.filter(y=>a[y.from].value===u).length!==1,g=typeof d=="string"?/^(.+):([A-Za-z_$][\w$]*)$/.exec(d):null,h=null,k;if(m||!g)k="dynamic";else if(/^[a-z][a-z\d+.-]*:\/\//i.test(g[1])||!g[1].includes("/")&&!W(g[1]))k="external";else{let y=pt.normalize(pt.join(pt.dirname(e),g[1]));!g[1].startsWith("/")&&!g[1].includes("\\")&&!/^[A-Za-z]:/.test(g[1])&&y!==".."&&!y.startsWith("../")&&N(y,o)!==null&&W(y)&&n.has(y)?h=y:k="missing"}return{from:e,to:h,kind:"graph-node",symbol:u,imported:g?.[2]??"*",source:typeof d=="string"?d:"",usage:"reference",within:u,span:{from:a[f.from].line,to:a[f.to-1].endLine},...k?{reason:k}:{}}})}function Wu(e,t,n,o,r={}){let s=W(e);if(!s)return[];let i=G(e,t,s),{toks:l}=i,a=ut(i,n);if(!a||a.params!==null)return[];let c=l.findIndex((y,b)=>b>=a.from&&b<a.to&&B(l,b));if(c<0)return[];let p=_(l[c+1])&&S(l[c+2],".")&&_(l[c+3],"compile"),f=p?l[c+1].text:n,u=p?ut(i,f):a;if(!u||!l.slice(u.from,u.to).some(y=>_(y,"StateGraph")))return[];if([n,f].some(y=>l.filter((b,x)=>_(b,y)&&B(l,x+1)).length!==1))return[];let d=U(i),m=y=>d.filter(b=>b.params!==null&&b.from<y&&y<b.to).map(b=>b.from).join(","),g=[{from:u.from,to:u.to}];for(let y=0;y<l.length;y++)_(l[y],f)&&S(l[y+1],".")&&["add_node","addNode"].includes(l[y+2]?.text)&&S(l[y+3],"(")&&m(y)===m(u.from)&&g.push({from:y,to:I(l,y+3)+1});let h=[];for(let y of g)for(let b=y.from;b<y.to;b++){if(!["add_node","addNode"].includes(l[b]?.text)||!S(l[b+1],"(")||m(b)!==m(u.from))continue;let x=T(l,b+1)[1];if(!x||x.to!==x.from+1||!_(l[x.from]))continue;let w=l[x.from].text;!Mr(i,w)||l.some((v,$)=>_(v,w)&&B(l,$+1))||h.push({from:e,to:e,kind:"graph-node",symbol:w,imported:w,source:w,usage:"reference",within:null,span:{from:l[b].line,to:l[x.from].endLine}})}return[...Lr(e,t,o,void 0,r).filter(y=>(y.kind==="config"||y.kind==="graph-node")&&g.some(b=>l.slice(b.from,b.to).some(x=>_(x,y.symbol)&&x.line>=y.span.from&&x.line<=y.span.to))),...h].filter((y,b,x)=>x.findIndex(w=>JSON.stringify(w)===JSON.stringify(y))===b)}function Ku(e,t,n,o){let r=W(e);if(!r||o?.path!==e)return!1;let s=G(e,t,r),i=Mr(s,n);if(!i)return!1;let l=(a,c)=>o.callStart!==void 0?s.toks[a].start<=o.callStart&&s.toks[c-1].end>o.callStart:o.line!==void 0&&s.toks[a].line<=o.line&&s.toks[c-1].endLine>=o.line;return l(i.from,i.to)&&(o.callStart!==void 0||U(s).filter(a=>a.params!==null&&l(a.from,a.to)).length===1)}function Mr(e,t){let n=ut(e,t);return n&&n.params!==null&&U(e).filter(o=>o.name===n.name).length===1?n:null}function Or(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}var ze=50,ll=new Set(["replace","replaceAll","format","format_messages","formatMessages"]),al=new Set(["withStructuredOutput","with_structured_output","bind","bind_tools","bindTools"]);function Cr(e,t){let n=e.source,{toks:o}=n,r=(u,d)=>{let m=e.importBinding(u,d),g=m&&ie([m.module],n.lang).find(h=>h.name===u);return g?{namespace:m.namespace,importBinding:g}:null},s=u=>[...new Map(u.map(d=>[JSON.stringify(d),d])).values()].slice(0,ze),i=u=>{let d=T(o,u),m=d.map(h=>o[h.from]);return!d.every(h=>(_(o[h.from])||o[h.from].kind==="string")&&(S(o[h.from+1],":")||_(o[h.from])&&h.to===h.from+1))||new Set(m.map(h=>h.value||h.text)).size!==m.length?null:d},l=(u,d)=>e.functions.some(m=>m.from<d&&d<m.to&&m.params?.includes(u)),a=(u,d)=>{let m=/^([A-Za-z_$][\w$]*)(\(\))?(?:\.([A-Za-z_$][\w$]*))?$/.exec(u.trim()),g=m&&r(m[1],d);return!m||!g?[]:[{kind:g.namespace&&m[3]&&!m[2]?"module-member":"symbol",callee:`${m[1]}${m[2]&&m[3]?"()":""}${m[3]?`.${m[3]}`:""}`,literals:[],importBinding:g.importBinding}]},c=(u,d,m)=>{let g=r(u,d);if(g)return[{kind:"symbol",callee:u,literals:[],importBinding:g.importBinding}];let h=e.binding(u,d);return h&&e.bindingIsCertain(h,d)&&!h.append&&!m.has(h.at)&&(!l(u,d)||e.owner(h.at)===e.owner(d))?p(h,new Set([...m,h.at])):[]},p=(u,d=new Set)=>{let m=ce(e,u),{from:g,to:h}=m;if(g>=h||!o[g])return[];let k=t.find(b=>b.start===o[g].start);if(J(o[g])&&h===g+1){let b=k?[{kind:"site",callee:"",literals:[],siteStart:k.start}]:[];if(h===g+1&&o[g].kind==="template")for(let x of o[g].value.matchAll(/\$\{([^{}]*)\}/g))b.push(...a(x[1],g));return s(b)}if(h===g+1&&_(o[g]))return c(o[g].text,g,d);let y=Z(e,m);if(y){let b=o[y.open-1].text;if(ll.has(b)&&S(o[y.open-2],"."))return p({from:y.from,to:y.open-2},d);let x=e.operations.find(w=>w.call.from===y.from&&w.call.to===y.to);if(x&&st(e,y)){let w=me(X(e,x.path),n.path);return w?[{kind:"bound-file",callee:y.callee,literals:[w]}]:[]}if(!y.args.length)return a(y.callee,g)}if(S(o[g],"[")&&I(o,g)===h-1)return s(T(o,g).flatMap(b=>p(b,d)));if(S(o[g],"{")&&I(o,g)===h-1){let b=i(g);if(!b)return[];let x=v=>b.find($=>(_(o[$.from],v)||o[$.from]?.value===v)&&S(o[$.from+1],":")),w=x("role"),E=x("content");return w&&E&&["system","user"].includes(o[w.from+2]?.value)?p({from:E.from+2,to:E.to},d):[]}if(h===g+3&&_(o[g])&&S(o[g+1],".")&&_(o[g+2]))return a(`${o[g].text}.${o[g+2].text}`,g);if(S(o[h-2],".")&&_(o[h-1])){let b=Z(e,{from:g,to:h-2});if(b&&!b.args.length)return a(`${b.callee}().${o[h-1].text}`,g)}return[]},f=(u,d=new Set)=>{let m=ce(e,u),{from:g,to:h}=m;if(h===g+1&&_(o[g])){let E=o[g].text,v=e.binding(E,g);return!!v&&e.bindingIsCertain(v,g)&&!v.append&&!d.has(v.at)&&(!l(E,g)||e.owner(v.at)===e.owner(g))&&f(v,new Set([...d,v.at]))}let k=Z(e,m);if(!k)return!1;let y=o[k.open-1].text;if(al.has(y))return f({from:k.from,to:k.open-2},d);let b=k.callee.split(".")[0],x=e.importBinding(b,g),w=k.callee.includes(".")?k.callee.split(".").at(-1):x?.name??b;return!!x&&Ve(x.module.source,n.lang)&&/^(?:Chat(?!Prompt|Message|History)|AzureChat|BaseChat|LLM)/.test(w)};return{values:p,modelValue:f,objectFields:i,unique:s}}var cl=new Set(["invoke","ainvoke","batch","abatch","stream","astream"]);function jr(e,t,n){let o=oe(e,t,{enclosingBindings:!0}),{toks:r}=e,{values:s,modelValue:i,objectFields:l,unique:a}=Cr(o,n),c=o.assignments.filter(m=>o.owner(m.at)===null).filter(m=>o.assignments.filter(g=>g.name===m.name&&o.owner(g.at)===null).length===1).filter(m=>o.bindingIsCertain(m,r.length)).map(m=>({name:m.name,loads:s(m,new Set([m.at]))})).filter(m=>m.loads.length).slice(0,ze),p=[],f=Ir(e.path,e.text,new Set),u=(m,g,h=null)=>{if(!g.length||p.length===ze)return;let k=o.assignments.find(y=>Z(o,y)===m);p.push({path:e.path,line:r[m.from].line,callStart:r[m.from].start,callee:m.callee,key:null,loads:a(g),model:h,shape:null,enclosing:o.owner(m.from)?.name??null,resultVar:k?.name??null})};for(let m of o.calls){if(f.some(g=>g.symbol===m.callee&&g.span.from===r[m.from].line)){let g=m.args[0],h=g&&X(o,g),k=m.args.find(y=>_(r[y.from],"engine")&&S(r[y.from+1],"="));h&&u(m,[{kind:"chainlite",callee:m.callee,literals:[h]}],k?Q(e,new Map,k.from+2,k.to):null);continue}cl.has(r[m.open-1].text)&&S(r[m.open-2],".")&&i({from:m.from,to:m.open-2})&&m.args[0]&&u(m,s(m.args[0]))}for(let m=0;m<r.length&&c.length<ze;m++){let g=_(r[m],"return")?o.owner(m):null;if(!g||o.owner(g.from)!==null||o.functions.filter(k=>k.name===g.name).length!==1||o.assignments.some(k=>k.name===g.name)||r.filter((k,y)=>_(k,"return")&&o.owner(y)===g).length!==1||r.slice(g.from,m).some(k=>k.kind==="ident"&&["if","for","while","switch","try","catch"].includes(k.text)))continue;if(S(r[m+1],"{")){let k=l(m+1);if(!k)continue;for(let y of k){let b=r[y.from];if(!_(b)&&b.kind!=="string")continue;let x=S(r[y.from+1],":")?y.from+2:y.from,w=s({from:x,to:y.to});w.length&&c.length<ze&&c.push({name:`${g.name}.${b.value||b.text}`,loads:w})}continue}let h=s({from:m+1,to:ae(e,m+1)});h.length&&c.push({name:g.name,loads:h})}let d=o.operations.flatMap(m=>{if(!st(o,m.call))return[];let g=me(X(o,m.path),e.path);return g?[{value:g,path:e.path,line:m.line}]:[]});return{bindings:c,deliveries:p,loadedRefs:d}}var fl=new Map([["python","py"],["py","py"],["javascript","js"],["js","js"]]);function Tr(e,t,n){return t.filter(o=>/\.md$/i.test(o)&&_o(e,o)&&ke(e,o,n)?.kind==="example")}function Bt(e,t){if(!/\.md$/i.test(e))return[];let n=[],o,r=0,s=t.split(`
|
|
24
|
+
`);for(let i=0;i<s.length;i++){let l=s[i].replace(/\r$/,""),a=/^ {0,3}(`{3,}|~{3,})(.*)$/.exec(l);if(a){let c=a[1][0],p=a[1].length,f=a[2].trim();o?c===o.marker&&p>=o.width&&!f&&(o.lang&&r>o.start&&n.push({path:e,lang:o.lang,start:o.start,end:r,span:{from:o.line,to:i}}),o=void 0):(c!=="`"||!f.includes("`"))&&(o={marker:c,width:p,lang:fl.get(f.split(/\s+/)[0].toLowerCase()),start:r+s[i].length+1,line:i+2})}r+=s[i].length+1}return n}function fp(e,t,n){let o=new Set(Tr(e,Object.keys(t)));if(!o.size)return t;let r=n.nodes.flatMap(s=>s.files??[]).filter(s=>s.role==="system prompt"&&s.span);return Object.fromEntries(Object.entries(t).map(([s,i])=>{if(!o.has(s))return[s,i];let l=r.filter(c=>c.path===s).map(c=>c.span),a=Bt(s,i).filter(c=>l.some(p=>c.span.from<=p.from&&p.to<=c.span.to));return a.length?[s,i.split(`
|
|
25
|
+
`).map((c,p)=>a.some(f=>f.span.from<=p+1&&p+1<=f.span.to)?c:"").join(`
|
|
26
|
+
`)]:[s,i]}))}function Nr(e,t,n,o,r){if(!o||!Tr(e,[t]).length)return null;let s=Bt(t,n).find(l=>l.span.from<=o.from&&o.to<=l.span.to);if(!s)return null;let i=bt(n.slice(s.start,s.end),o.from-s.span.from+1,r);return{text:i.text,fromLine:s.span.from+i.fromLine-1}}function up(e,t){return e.split("").map((n,o)=>/[\r\n]/.test(n)||t.some(r=>r.start<=o&&o<r.end)?n:" ").join("")}var Fr=200,Dr=300,Gn=/SYSTEM|PROMPT|INSTRUCTION/i,ul=/^\s*You(?:['’]re)?(?![\w'’])/;function Br(e,t,n={}){let o=n.minChars!==void 0,r=n.promptFunctions!==!1,s=[],i=new Map,l=new Set,a=(c,p)=>{l.has(c)||(l.add(c),s.push(p),i.set(c,p.span.from))};for(let c=0;c<e.toks.length;c++){let p=pl(e,c,o||r);if(!p)continue;let f=r?ft(e,p.valueAt):null,u=ct(e,f??p.valueAt);!u||u.text.length<(n.minChars??Fr)||!o&&!Gn.test(e.toks[p.nameAt].text)&&!(f!==null&&Wt(u.text,!!u.filledAtRunTime))||(a(u.start,Un(e,u,{named:!0,prose:Wt(u.text,r&&!!u.filledAtRunTime),line:e.toks[p.nameAt].line,symbol:e.toks[p.nameAt].text,enclosing:te(t,p.declAt)},r&&!!u.filledAtRunTime)),u.partStarts.forEach(d=>l.add(d)))}return r&&e.toks.forEach((c,p)=>{let f=_(c,"return")?t.filter(k=>k.params!==null&&k.from<p&&p<k.to).sort((k,y)=>y.from-k.from)[0]:void 0,u=Kn(e,p);if(!f&&!u)return;let d=f?p+1:p,m=u?ft(e,d):null,g=ct(e,m??d);if(!g||g.text.length<(n.minChars??Fr))return;let h=Wt(g.text,!!g.filledAtRunTime);f&&!o&&!Gn.test(f.name)&&!h||(a(g.start,Un(e,g,{named:!!f||!h,prose:h,line:f?.line??g.line,symbol:f?.name??null,enclosing:f?.name??te(t,p)},!!g.filledAtRunTime)),g.partStarts.forEach(k=>l.add(k)))}),e.toks.forEach((c,p)=>{if(!J(c)||l.has(c.start)||c.value.length<(n.minChars??Dr))return;let f=r&&Bn(c),u=Wt(c.value,f);if(!o&&!u)return;let d={start:c.start,line:c.line,endLine:c.endLine,text:c.value,partStarts:[c.start],next:p+1};a(c.start,Un(e,d,{named:!1,prose:u,line:c.line,symbol:null,enclosing:te(t,p)},f))}),s.sort((c,p)=>c.line-p.line),{sites:s,siteLineByStart:i}}function Wt(e,t=!1){let n=t?e.replace(/^(?:\s*\$?\{[^{}]*\})+\s*/,""):e;return e.length>=Dr&&ul.test(n)}function Un(e,t,n,o=!1){return{kind:n.named?"named":"prose",...n,path:e.path,endLine:t.endLine,span:{from:t.line,to:t.endLine},start:t.start,chars:t.text.length,excerpt:xe(t.text),...o?{filledAtRunTime:!0}:{}}}function pl(e,t,n){let{toks:o}=e,r=e.lang==="js";if(r&&!(_(o[t])&&["const","let","var"].includes(o[t].text)))return null;let s=r?t+1:t;if(!_(o[s])||!n&&!Gn.test(o[s].text)||!r&&!(he(o,t)&&ml(e,t)))return null;let i=s+1;if(S(o[i],":")){let l=i+Ne;for(;i<l&&i<o.length&&!B(o,i);)i++}return B(o,i)?{declAt:t,nameAt:s,valueAt:i+1}:null}function ml(e,t){let n=Zt(e.text,e.toks[t]);if(n===0)return!0;for(let o=t-1;o>=0;o--)if(!(!he(e.toks,o)||Zt(e.text,e.toks[o])>=n))return _(e.toks[o],"class");return!1}var dl=20,gl=/^(?:messages\.(?:create|stream)|chat\.completions\.create|responses\.create|generateText|streamText|Runner\.run)\(/,hl=/\/v1\/(?:messages|chat\/completions)$/;function Wr(e,t,n){let{toks:o}=e;return o.flatMap((r,s)=>{if(!_(r))return[];let i=o.slice(s,s+7).map(p=>p.text).join(""),l=gt.includes(o[s-1]?.text??""),a=t&&r.text==="query"&&o[s+1]?.text==="("&&o[s-1]?.text!==".";return(gl.test(i)&&(r.text!=="Runner"||n.layouts===!0&&t)||a)&&!l?[s]:[]})}function bp(e,t,n={}){let o=t.some(s=>Ve(s.source,e.lang,n,e)),r=Wr(e,o,n);return pe(e).filter(s=>r.some(i=>s.from<=i&&i<s.open&&e.toks.slice(i,s.open).every(l=>_(l)||S(l,"."))))}function Kt(e,t,n,o={}){let{toks:r}=e,s=n.filter(a=>Ve(a.source,e.lang,o,e)),i=s.length>0,l=s.map(a=>({line:a.line,at:null}));return r.forEach((a,c)=>{if(J(a)){hl.test(a.value)&&l.push({line:a.line,at:c});return}}),Wr(e,i,o).forEach(a=>l.push({line:r[a].line,at:a})),l.sort((a,c)=>a.line-c.line||(a.at??-1)-(c.at??-1)),l.slice(0,dl).map(({line:a,at:c})=>({kind:"sdk",path:e.path,line:a,value:null,enclosing:c===null?null:te(t,c)}))}function Ut(e,t,n){let o=[];for(let r of t){let{params:s}=r;if(s)for(let{site:i,valueAt:l}of n){if(i.value?.kind!=="identifier"||l<=r.from||l>=r.to)continue;let a=s.indexOf(i.value.text),c=o.some(p=>p.name===r.name&&p.paramIndex===a);a>=0&&!c&&o.push({name:r.name,paramIndex:a,paramName:i.value.text,path:e.path,line:r.line})}}return o}var xl=200,Sl=40;function Kr(e,t,n,o){let{toks:r}=e,s=[];for(let i=0;i<r.length&&s.length<xl;i++){let l=r[i];if(!q(r,i)||S(r[i-1],".")||gt.includes(r[i-1]?.text??""))continue;let a=T(r,i+1).map(p=>yl(e,n,p));a.some(p=>p.kind==="literal"&&p.siteLine!==null||p.kind==="identifier"&&o.has(p.text))&&s.push({name:l.text,path:e.path,line:l.line,args:a,shortLiterals:a.filter(p=>p.kind==="literal"&&p.siteLine===null&&p.text.length>0&&p.text.length<=Sl).map(p=>p.text),enclosing:te(t,i)})}return s}function yl(e,t,n){let{toks:o}=e,r=e.lang==="py"&&_(o[n.from])&&B(o,n.from+1),s=r?n.from+2:n.from;return{...Q(e,t,s,n.to),name:r?o[n.from].text:null}}var Ur=50;function Gt(e,t,n,o,r,s){let{toks:i}=e,l=new Set(t.map(f=>f.name)),a=f=>Ue(t,f),c=new Map(n.map(f=>[f.from,f])),p=new Set(s.map(f=>f.callStart));return n.filter(f=>l.has(f.callee)||r.has(f.callee.split(".")[0])||p.has(i[f.from].start)).slice(0,Ur).map(f=>{let u=a(f.from),d=[...new Set(f.args.flatMap($=>{let{from:R,to:A}=$;for(e.lang==="py"&&_(i[R])&&B(i,R+1)&&(R+=2);S(i[R],"(")&&I(i,R)===A-1;)R++,A--;if(!_(i[R]))return[];for(let L=R+1;L<A;L+=2)if(!S(i[L],".")||!_(i[L+1]))return[];return[i[R].text]}))].slice(0,Ur),m=$=>o.findLast(R=>R.name===$&&R.at<f.from&&a(R.at)===u&&!(R.from<=f.from&&f.from<R.to)),g=$=>{let R=_(i[$.from],"await")?$.from+1:$.from,A=c.get(R);return!$.append&&A?.to===$.to?A:null},h=Object.fromEntries(d.flatMap($=>{let R=m($);if(!R)return[];let A=g(R);return[[$,A?i[A.from].start:null]]})),k=o.find($=>g($)===f),y=t.filter($=>$.from<f.from&&f.from<$.to),b=t.filter($=>$.name===f.callee&&(!a($.from)||y.includes(a($.from)))).sort(($,R)=>(a(R.from)?.from??-1)-(a($.from)?.from??-1))[0],x=f.callee.split(".")[0],w=y.findLast($=>$.params?.includes(x)||o.some(R=>R.name===x&&R.at<f.from&&a(R.at)===$)),E=w&&(!b||(a(b.from)?.from??-1)<w.from),v=E?null:b?i[b.from].start:null;return{callee:f.callee,resultVar:k?.name??null,argNames:d,enclosing:u?.name??null,line:i[f.from].line,callStart:i[f.from].start,...u?{enclosingStart:i[u.from].start}:{},...b||E||l.has(f.callee)?{localTarget:v}:{},...Object.keys(h).length?{argCalls:h}:{}}})}var Pe=50,kl=200,Gr=new Set(["system","systemPrompt","system_prompt","instructions","prompt","template","template_file"]),wl=new Set(["model","engine","schema","response_format","output_type","outputSchema","tools","messages","max_tokens","maxTokens"]),bl=new Set(["schema","response_format","output_type","outputSchema"]),zr=/(?:template|template_file|prompt_file)$/;function Vr(e,t){let{toks:n}=e,o=t.filter(R=>R.params!==null),r=R=>Ue(o,R),s=pe(e),i=new Map(s.map(R=>[R.from,R])),l=z(e),a=new Set(ie(l,e.lang).map(R=>R.name)),c=Kt(e,t,l).length>0,p=Ut(e,t,de(e,t,new Map)),f=new Map(s.flatMap(R=>{let A=_l(e,R),L=p.find(C=>C.name===R.callee),O=A.filter(C=>c||L||A.some(j=>j.object===C.object&&wl.has(j.key)));return c||L||O.length?[[R,{fields:O,wrapper:L}]]:[]})),u=Ct(e),d=new Map(u.map(R=>[R.at,R])),m=new Map(u.filter(R=>!R.append).map(R=>[_(n[R.from],"await")?R.from+1:R.from,R.name])),g=xr({},{[e.path]:e.text},{source:e,scopes:t},"operations"),h=gr(g.operations),k=new Map(h.map(R=>[R.call.from,R.path])),y=[];for(let R of o){for(let A of h){if(r(A.call.from)!==R)continue;let L=hr(A,R,e.lang);if(!(!L||y.some(O=>O.name===R.name&&O.line===R.line))&&(y.push({name:R.name,paramIndex:L.paramIndex,folder:L.folder,ext:L.ext,path:e.path,line:R.line}),y.length===Pe))break}if(y.length===Pe)break}let b=new Set(y.map(R=>R.name)),x=new Map,w=R=>[...new Map(R.map(A=>[JSON.stringify(A),A])).values()].slice(0,Pe),E=R=>n.slice(R.from,R.to).filter(J).filter(A=>A.value.length<=kl).map(A=>A.value).slice(0,Pe),v=[];for(let R=0;R<2;R++){let A=new Map;v=[];let L=(O,C)=>{let{from:j,to:P}=O;for(_(n[j],"await")&&j++;S(n[j],"(")&&I(n,j)===P-1;)j++,P--;if(P===j+1&&_(n[j]))return A.get(C)?.get(n[j].text)??[];let M=i.get(j);if(M&&M.to===P){let Ie=k.get(j);if(Ie){let K=E(Ie);return Ge(K).length>0?[{kind:"read",callee:M.callee,literals:K}]:[]}if(f.get(M)?.fields.some(K=>Gr.has(K.key)||K.key==="messages"))return[];let Me=M.args[0]?E(M.args[0]):[],Ce=a.has(M.callee.split(".")[0]),D=[...x.keys()].some(K=>K.name===M.callee);if(D||(b.has(M.callee)||Ce)&&(Me.length>0||Ce&&M.args.length===0))return[{kind:D?"return":"loader",callee:M.callee,literals:Me}]}return[]};for(let O=0;O<n.length;O++){let C=r(O),j=d.get(O);if(j){let{name:D,append:K}=j,fe=A.get(C)??new Map;fe.set(D,w([...K?fe.get(D)??[]:[],...L(j,C)])),A.set(C,fe)}if(_(n[O],"return")&&C&&!y.some(D=>D.name===C.name&&D.line===C.line)){let D=L({from:O+1,to:ae(e,O+1)},C);D.length&&(x.has(C)||x.size<Pe)&&x.set(C,{fn:C.name,loads:w([...x.get(C)?.loads??[],...D]),path:e.path,line:C.line})}let P=i.get(O);if(!P||v.length===Pe)continue;let M=f.get(P);if(!M)continue;let{fields:Ie,wrapper:Me}=M,Ce=(D,K,fe=!1)=>{let re=L(D,C);if(!re.length&&fe){let se=E(D);Ge(se).length>0&&(re=[{kind:"file-key",callee:P.callee,literals:se}])}if(!re.length||v.length===Pe)return;let je=Ie.filter(se=>D.object===void 0||se.object===D.object),ge=je.find(se=>se.key==="model"||se.key==="engine"),Yt=je.find(se=>bl.has(se.key)),_s=ge?Q(e,new Map,ge.from,ge.to):null,lo=Yt?Q(e,new Map,Yt.from,Yt.to):null,Es=lo?.kind==="identifier"?lo.text:null,Rs=m.get(P.from)??null;v.push({path:e.path,line:n[P.from].line,callStart:n[P.from].start,callee:P.callee,key:K,loads:re,model:_s,shape:Es,enclosing:C?.name??null,resultVar:Rs})};for(let D of Ie)if((Gr.has(D.key)||zr.test(D.key))&&Ce(D,D.key,e.lang==="py"&&zr.test(D.key)),D.key==="messages")for(let K=D.from;K<D.to;K++){if(!S(n[K],"{"))continue;let fe=zn(e,K),re=fe.find(ge=>ge.key==="role");if(!re||n[re.from]?.kind!=="string"||!["system","user"].includes(n[re.from].value))continue;let je=fe.find(ge=>ge.key==="content");je&&re.from<je.from&&Ce({...je,object:D.object},"content"),K=I(n,K)}Me&&P.args[Me.paramIndex]&&!Ie.length&&Ce(P.args[Me.paramIndex],null)}}let $=Gt(e,o,s,u,a,v);return{loaders:y,promptReturns:[...x.values()],deliveries:v,stepCalls:$}}function zn(e,t){let{toks:n}=e;return T(n,t).flatMap(({from:o,to:r})=>{let s=_(n[o])?n[o].text:n[o]?.kind==="string"?n[o].value:null;return s?S(n[o+1],":")||e.lang==="py"&&B(n,o+1)?[{key:s,from:o+2,to:r,object:t}]:r===o+1?[{key:s,from:o,to:r,object:t}]:[]:[]})}function _l(e,t){return e.lang==="py"?zn(e,t.open):t.args.flatMap(n=>S(e.toks[n.from],"{")?zn(e,n.from):[])}function Vn(e){return{path:e,sites:[],callSites:[],sdk:!1,sdkLine:null,wrappers:[],wrapperCalls:[],imports:[],modelIds:[],fileRefs:[]}}function Jr(e,t,n={}){try{if(n.coverageLinks===!0&&n.documented===!0&&/\.md$/i.test(e)){let o=Bt(e,t).map(r=>({span:r.span,hits:Xr(e,t.slice(0,r.start).replace(/[^\r\n]/g," ")+t.slice(r.start,r.end),n,r.lang)}));return{...Vn(e),snippets:o}}return Xr(e,t,n)}catch{return Vn(e)}}function Xr(e,t,n,o=W(e)){if(!o){let x=Bo(e,t);return{...Vn(e),sites:x?[x]:[]}}let r=G(e,t,o),s=U(r,{promptFunctions:n.promptFunctions!==!1}),i=z(r),l=ie(i,o),{sites:a,siteLineByStart:c}=Br(r,s,n),p=Kt(r,s,i,n.sdk),f=de(r,s,c,n.sdk?.layouts===!0&&p.length>0,n.promptFunctions!==!1),u=new Set([...a.flatMap(x=>x.symbol?[x.symbol]:[]),...l.map(x=>x.name)]),d=n.promptLoaders!==!1?Vr(r,s):null,m=n.coverageLinks===!0&&d?jr(r,s,a):null,g=[...d?.deliveries??[],...m?.deliveries??[]],h=m?oe(r,s):null,k=h?Gt(r,h.functions,h.calls,h.assignments,new Set(l.map(x=>x.name)),g):d?.stepCalls,y=ir(r),b=n.promptLoaders!==!1?lr(r):[];return{path:e,sites:a,callSites:[...f.map(x=>x.site),...p].sort((x,w)=>x.line-w.line),sdk:p.length>0,sdkLine:p.length>0?p[0].line:null,wrappers:Ut(r,s,f),wrapperCalls:Kr(r,s,c,u),imports:l,modelIds:y.modelIds,fileRefs:m?y.promptFileRefs:y.fileRefs,...d?.loaders.length?{loaders:d.loaders}:{},...d?.promptReturns.length?{promptReturns:d.promptReturns}:{},...g.length?{deliveries:g}:{},...m?{priorDeliveries:d?.deliveries??[],priorFileRefs:y.fileRefs}:{},...k?.length?{stepCalls:k}:{},...m?.bindings.length?{promptBindings:m.bindings}:{},...m?.loadedRefs.length?{loadedPromptRefs:m.loadedRefs}:{},...b.length?{modelMembers:b}:{}}}var Yr=e=>e.CF_CODE_PROMPT_FUNCTIONS!=="0";var El=20;function zt(e,t){let n=new Set(t),o=new Set;for(let[r,s]of Object.entries(e)){let i=W(r);if(i)for(let l of St(r,s,i)){let a=ue(r,l.source,l.names,i,n);a!==void 0&&o.add(a)}}return[...o].sort()}function pm(e,t,n){return zt(e,t).filter(o=>!go(o,n)).slice(0,El)}function Rl(e,t){let n=De(e),o=n?n.split("/"):[],r=t.split("/").slice(0,-1),s=0;for(;s<o.length&&s<r.length&&o[s]===r[s];)s++;return o.slice(0,s).join("/")}function mm(e,t,n){let o=Yr(n),r=Fn(Object.entries(t).map(([l,a])=>Jr(l,a,{promptFunctions:o}))),s=r.strong[0]??r.possible[0];if(!s)return null;let i=s.prompt.path;return{suggestedDir:Rl(e,i),file:i,symbol:s.prompt.symbol}}function dm(e,t){let n=t.suggestedDir||"the repository root";return`no agent prompt in ${e}; its code imports ${t.file}, which defines ${t.symbol??"a prompt"} \u2014 import ${n} to include it`}function Xn(e,t){if(!t||!S(e[t.from],"{")||I(e,t.from)!==t.to-1)return null;let n=new Map;for(let o of T(e,t.from)){let r=e[o.from];if(!(_(r)||r?.kind==="string")||!S(e[o.from+1],":"))return null;let s=r.kind==="string"?r.value:r.text;if(n.has(s))return null;n.set(s,{from:o.from+2,to:o.to})}return n}function Oe(e,t,n=0){if(!t||n>32)return;let{from:o,to:r}=t,s=e[o];if(s?.kind==="string"&&Te(s).closed){if(r===o+1)return s.value;if(S(e[o+1],"+")){let a=Oe(e,{from:o+2,to:r},n+1);if(typeof a=="string")return s.value+a}}if(r===o+1){if(s?.kind==="number"){let a=Number(s.text.replace(/_/g,""));return Number.isFinite(a)?a:void 0}if(_(s,"true"))return!0;if(_(s,"false"))return!1;if(_(s,"null"))return null}if(S(s,"[")&&I(e,o)===r-1){let a=T(e,o).map(c=>Oe(e,c,n+1));return a.includes(void 0)?void 0:a}let i=Xn(e,t);if(!i)return;let l=[...i].map(([a,c])=>[a,Oe(e,c,n+1)]);return l.some(([,a])=>a===void 0)?void 0:Object.fromEntries(l)}function qr(e,t){let n=Xn(e,t);if(!n)return null;let o=Oe(e,n.get("type"));if(o==="function"&&n.has("function")&&(n=Xn(e,n.get("function"))),!n)return null;let r=n.get("input_schema")??(o==="function"?n.get("parameters"):void 0);if(!r)return null;let s=Oe(e,n.get("name")),i=Oe(e,n.get("description"));if(typeof s!="string"||!s.trim()||typeof i!="string")return{tools:[],warnings:["Some tools couldn't be read from code"]};let l=Oe(e,r),a=l!==null&&typeof l=="object"&&!Array.isArray(l);return{tools:[{name:s,description:i,...a?{input_schema:l}:{}}],warnings:a?[]:[`${s}'s arguments couldn't be read from code`]}}function qn(e,t){_(e[t],"as")&&_(e[t+1],"const")&&(t+=2);let n=e[t];return n===void 0||n.kind==="punct"&&",;)}]".includes(n.text)||_(n)&&n.line>(e[t-1]?.endLine??n.line)&&!["as","satisfies"].includes(n.text)}function Jn(e,t,n){for(;S(e[t],".");)t++;return _(e[t])?[e[t].text]:!S(e[t],"{")&&!S(e[t],"[")?[]:T(e,t).filter(o=>o.from<o.to&&o.to<=n).flatMap(o=>{let r=o.from;return S(e[t],"{")&&S(e[r+1],":")&&(r+=2),Jn(e,r,o.to)})}function Yn(e,t){let{toks:n}=e,o=new Map,r=new Map,s=new Map,i=[];for(let l=0;l<n.length;l++){if(S(n[l],"{")?i.push(l):S(n[l],"}")&&i.pop(),!_(n[l])||!["const","let","var"].includes(n[l].text))continue;let a=i.at(-1);if(t!==void 0&&a!==void 0&&(t<a||t>I(n,a)))continue;let c=_(n[l+1])?l+2:I(n,l+1)+1,p=Jn(n,l+1,c).filter(u=>t===void 0||(r.get(u)??-1)<=i.length);for(let u of p)o.set(u,null),r.set(u,i.length),s.set(u,l);if(!_(n[l],"const")||!_(n[l+1])||!p.length)continue;let f=n[l+1].text;for(let u=l+2;u<Math.min(n.length,l+40)&&!S(n[u],";");u++)if(S(n[u],"=")){o.set(f,null),r.set(f,i.length),S(n[u+1],"[")&&qn(n,I(n,u+1)+1)&&(o.set(f,u+1),r.set(f,i.length));break}}if(t!==void 0)for(let l of U(e)){if(l.params===null||t<=l.from||t>=l.to)continue;let a=l.params.filter(c=>c!==null);if(l.params.includes(null)){let c=n.findIndex((p,f)=>f>l.from&&f<t&&S(p,"("));c>=0&&a.push(...mo(n,c,"js").flatMap(({from:p,to:f})=>Jn(n,p,f)))}for(let c of a)(s.get(c)??-1)<=l.from&&o.set(c,null)}return o}function vl(e){let{toks:t}=e,n=new Map;for(let o=0;o<t.length;o++){if(!_(t[o],"export"))continue;let r=Yn(e,o);if(_(t[o+1],"const")){let s=t[o+2]?.text,i=r.get(s);i!=null&&n.set(s,i)}else if(_(t[o+1],"default")){let s=S(t[o+2],"[")?o+2:r.get(t[o+2]?.text),i=S(t[o+2],"[")?I(t,o+2)+1:o+3;s!=null&&qn(t,i)&&n.set("default",s)}else if(S(t[o+1],"{"))for(let s of T(t,o+1)){let i=r.get(t[s.from]?.text);i!=null&&n.set(t[s.to-1].text,i)}}return n}function Hr(e,t,n){return n.has(e[t.from]?.start)&&S(e[t.from+1],"(")&&I(e,t.from+1)===t.to-1}function $l(e,t){let n=t?.call;if(!n)return;let{toks:o}=e;if(n.loadedPrompt&&n.callStart!==void 0){let f=o.findIndex(u=>u.start===n.callStart);if(f<0)return;for(;S(o[f+1],".")&&_(o[f+2]);)f+=2;return q(o,f,e)?{from:f+1,to:I(o,f+1)+1}:void 0}let r=new Set([n.symbol]),s=new Set(Object.keys(t.imports));for(let f of z(e)){let u=ue(e.path,f.source,f.names,"js",s);if(!(n.promptPath&&u!==n.promptPath))for(let d of f.names)((f.renamed?.[d]??d)===n.symbol||u===n.promptPath&&d===f.defaultName)&&r.add(d)}let i=n.promptPath===e.path&&n.promptStart!==void 0?new Map([[n.promptStart,n.line??1]]):new Map,l=de(e,[],i).filter(({site:f})=>n.line===void 0||f.line===n.line),a=(l.find(({site:f})=>f.value?.siteStart!=null&&f.value.siteStart===n.promptStart)??l.find(({site:f})=>f.value&&r.has(f.value.text))??l[0])?.valueAt;if(a===void 0)return;let c,p;for(let f=0;f<a;f++){if(!S(o[f],"(")&&!S(o[f],"{"))continue;let u=I(o,f)+1;u<=a||(S(o[f],"{")?c={from:f,to:u}:p={from:f,to:u})}return p??c}function Zr(e,t,n,o){let r=G(t?.path??"tools.ts",e,"js"),{toks:s}=r,i=t?.call?.loadedPrompt?new Set(U(r).filter(x=>x.params!==null).map(x=>x.name)):new Set,l=Yn(r),a=new Map,c=t?.imports??{},p=new Set(Object.keys(c));for(let x of z(r)){let w=ue(r.path,x.source,x.names,"js",p);if(w===void 0)continue;let E=G(w,c[w],"js"),v=o(c[w]);for(let[$,R]of vl(E))for(let A of x.names)(x.defaultName===A?"default":x.renamed?.[A]??A)===$&&a.set(A,{toks:E.toks,open:R,path:w,calls:v})}let f=new Set,u=new Set,d=[],m="Some tools couldn't be read from code",g=$l(r,t),h=!1;for(let x=0;x<s.length;x++){if(g&&(x<g.from||x>=g.to))continue;let w=s[x];if(["input_schema","parameters"].includes(w.kind==="string"?w.value:w.text)&&S(s[x+1],":")&&S(s[x+2],"{")){x=I(s,x+2);continue}if((_(w,"tools")||w.kind==="string"&&w.value==="tools")&&S(s[x+1],":")){h=!0;let E=s[x+2],v=Yn(r,x),$=S(E,"[")?x+2:_(E)?v.get(E.text):void 0,R=S(E,"[")?I(s,x+2)+1:x+3;if(!qn(s,R)){d.push(m);continue}$==null?_(E)&&!v.has(E.text)&&a.has(E.text)?u.add(E.text):d.push(m):f.add($)}}if(!h)for(let x of l.values())x!==null&&T(s,x).some(w=>qr(s,w)||Hr(s,w,n))&&f.add(x);let k=[],y=new Map,b=[...f].map(x=>({toks:s,open:x,calls:n,path:null}));b.push(...[...u].map(x=>a.get(x)));for(let{toks:x,open:w,calls:E,path:v}of b){let $=A=>d.push(v?`${v}: ${A}`:A),R=I(x,w);if(!S(x[R],"]")){$(m);continue}for(let A of T(x,w)){let L=qr(x,A),O=Hr(x,A,E),C=A.to===A.from+1&&_(x[A.from])?x[A.from].text:null,j=h&&v===null&&C&&i.has(C)?{name:C,description:""}:null;if(!L&&!O&&!j)$(m);else{let P=L?L.tools:j?[j]:h&&O?[E.get(x[A.from].start)]:[];for(let M of P)y.has(M.name)||y.set(M.name,v??r.path);k.push(...P),L?.warnings.forEach($)}}}return{tools:k,warnings:d,selected:h,from:Object.fromEntries(y)}}var mt=String.raw`(?:"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')`,Al=new RegExp(String.raw`(${mt}|`+"`(?:[^`\\\\]|\\\\.)*`)"+String.raw`|\/\/[^\n]*|\/\*[\s\S]*?\*\/`,"g"),Ll=/(?<![\w$])tool\s*(<[^()]*>)?\(/g,Pl=new RegExp(`^${mt}$`),Ol=new RegExp(`^${mt}(?:\\s*\\+\\s*${mt})*$`),Il={n:`
|
|
27
|
+
`,t:" ",r:"\r"};function Qr(e){return e.slice(1,-1).replace(/\\(.)/g,(t,n)=>Il[n]??n)}function Ml(e){return e.replace(Al,(t,n)=>n?n[0]+"_".repeat(n.length-2)+n[n.length-1]:" ".repeat(t.length))}function es(e,t){let n=0;for(let o=t;o<e.length;o++){let r=e[o];if("([{".includes(r))n++;else if(")]}".includes(r)){if(n===0)return o;n--}else if(r===","&&n===0)return o}return e.length}function ts(e){let t=Ml(e),n=[],o=[],r=new Map,s="a tool( call in tools.ts was skipped: its name and description are not plain text";for(let i of t.matchAll(Ll)){let l=t.slice(Math.max(0,i.index-40),i.index).trimEnd();if(l.endsWith(".")&&!l.endsWith("...")||i[1]){o.push(s);continue}let c=es(t,i.index+i[0].length),p=c+1,f=es(t,p),u=e.slice(i.index+i[0].length,c).trim(),d=e.slice(p,f).trim();if(t[c]!==","||!Pl.test(u)||!Ol.test(d)){o.push(s);continue}let m=d.match(new RegExp(mt,"g")),g={name:Qr(u),description:m.map(Qr).join("")};n.push(g),r.set(i.index,g)}return{tools:n,warnings:o,readCalls:r}}function ns(e,t){let{tools:n,warnings:o}=os(e,t);return{tools:n,warnings:o}}function os(e,t){let{tools:n,warnings:o,readCalls:r}=ts(e),s=new Map(n.map(({name:l})=>[l,t?.path??"tools.ts"])),i=Zr(e,t,r,l=>ts(l).readCalls);if(i.selected)return i;n.push(...i.tools),o.push(...i.warnings);for(let[l,a]of Object.entries(i.from))s.has(l)||s.set(l,a);return{tools:n,warnings:o,from:Object.fromEntries(s),selected:!1}}function vm(e,t,n){let o=Object.fromEntries(e.filter(f=>W(f)==="js"&&t[f]!==void 0).map(f=>[f,t[f]])),r=zt(o,Object.keys(t)),s=f=>{let u=Object.fromEntries(zt({[f]:t[f]},Object.keys(t)).filter(m=>r.includes(m)).map(m=>[m,t[m]])),d=os(t[f],{path:f,imports:u,...n?.path===f?{call:n}:{}});return{...d,warnings:d.warnings.map(m=>`${f}: ${m}`)}},i=Object.keys(o).map(s),l=i.filter((f,u)=>f.selected&&(!n||Object.keys(o)[u]===n.path)),a=l.length?l:[...i,...r.filter(f=>!o[f]).map(s)],c=new Map;return{tools:a.flatMap(f=>f.tools.filter(u=>c.has(u.name)?!1:(c.set(u.name,f.from[u.name]),!0))),from:Object.fromEntries(c),warnings:[...new Set(a.flatMap(f=>f.warnings))]}}function rs(e){let t;try{t=JSON.parse(e)}catch{return{tools:[],warnings:[".cli.json is not valid JSON; ignored"]}}let n=t?.clis;return!n||typeof n!="object"||Array.isArray(n)?{tools:[],warnings:[]}:{tools:Object.entries(n).map(([r,s])=>{let i=s?.description;return{name:r,description:typeof i=="string"?i:""}}),warnings:[]}}function Vt(e){return{label:e,brand:Xt(e)}}function Im(e,t,n,o,r){let s=[],i=a=>{s.push(...a.tools.map(c=>c.name)),r.push(...a.warnings.map(c=>`${t}: ${c}`))};if(o.toolsPath)try{s.push(...or(n[o.toolsPath]).tools.map(a=>a.name))}catch{r.push(`${t}: tools.json is not a valid tool list; ignored`)}o.toolsTsPath&&i(ns(n[o.toolsTsPath])),o.cliPath&&i(rs(n[o.cliPath]));let l=[];if(o.mcpPath){let a=nr(n[o.mcpPath],o.mcpPath,o.toolsPath!==null);l.push(...a.servers),r.push(...a.warnings.map(c=>`${t}: ${c}`))}return[...new Set(s)].map(Vt).concat(l.map(a=>({...Vt(a),source:"mcp"})))}function ss(e){let t=e.sourceRef?.repo?`${e.sourceRef.repo}#`:null;return e.unitKey??(t&&e.id.startsWith(t)?e.id.slice(t.length):e.id.startsWith("model:")?e.id:e.id.slice(e.id.indexOf("#")+1))}function is(e){return ss(e).startsWith("model:")}function Hn(e){return new Set(e.nodes.filter(is).flatMap(t=>[...(t.files??[]).map(n=>n.path),...t.sourceRef?[t.sourceRef.path]:[]]))}function Zn(e,t){let n=e.trim().replace(/^(\.\/)+/,"");if(!t)return n.includes(" \u203A ")&&n.slice(n.lastIndexOf(" \u203A ")+3).includes("/");if(t.has(n))return!0;for(let o of t){let r=o.indexOf(" \u203A ");if(r>=0&&n.startsWith(o.slice(0,r+3)))return!0}return!1}async function Wm(e,t,n,o,r=!1,s){if(t)return t;let i={enabled:o??e.CF_ANALYSIS_IMPORTED_AGENTS!=="0",byRepo:{}};if(!i.enabled)return i;_t(e)&&(i.grouped=!0);let l=await n?.()??[];r&&(i.agentRows=structuredClone(s?.length?[...s]:l.map((a,c)=>({id:a.id??String(c),repoPath:a.repoPath,unitKey:a.unitKey,notFoundAt:a.notFoundAt??null}))));for(let a of l){if(!a.unitKey||!a.repoPath||!a.unitKey.startsWith("model:")&&(!r||!a.codeInputsJson))continue;let c=ho(a.repoPath);if(!c)continue;let p=a.unitKey.startsWith("model:")?i.byRepo:i.codeByRepo??={};(p[c]??=[]).push(structuredClone({unitKey:a.unitKey,name:a.name,...a.groupKey===void 0?{}:{groupKey:a.groupKey},...a.groupName===void 0?{}:{groupName:a.groupName},systemPrompt:a.systemPrompt,toolsJson:a.toolsJson,model:a.model,...a.codeInputsJson===void 0?{}:{codeInputsJson:a.codeInputsJson},...a.links===void 0?{}:{links:a.links},...a.services===void 0?{}:{services:a.services}}))}return i}function as(e,t){let n=e.slice(6).split("#")[0];return Cl(n,t)}function Cl(e,t){return t?N(e,ht(t))??e:e}function ls(e){return`${as(e.unitKey)} \u203A ${e.name}`}function Qn(e,t,n=""){let o=e?.enabled?e.byRepo[t]??[]:[],r=o.map(ls),s=new Set(Object.entries(e?.enabled?e.byRepo:{}).filter(([a])=>a!==t).flatMap(([,a])=>a.map(ls))),i=o.map((a,c)=>{let p=r.filter(h=>h===r[c]).length>1?`${r[c]} (${a.unitKey.split("#").slice(1).join("#")})`:r[c],f=s.has(r[c])?`${t} \u203A ${p}`:p,u=`${f}/system_prompt.md`,d={[u]:a.systemPrompt??n},m=[{role:"system prompt",label:null,path:u}];if(a.toolsJson?.length){let h=`${f}/tools.json`;d[h]=JSON.stringify(a.toolsJson,null,2),m.push({role:"tools",label:null,path:h})}if(a.services?.length){let h=`${f}/context.md`,k=a.services.map(({name:y,kind:b})=>`${vo(y)}${b===y?"":` (${b})`}`);d[h]=`This agent's code (not the model) reads from or writes to: ${k.join(", ")}.`,m.push({role:"reference",label:"Context",path:h})}return{node:{id:a.unitKey,label:a.name,kind:"agent",desc:"",meta:a.model,sourceRef:{path:u,line:1},files:m,tools:(a.toolsJson??[]).map(h=>Vt(h.name))},files:d,keys:[a.unitKey],sourcePath:as(a.unitKey,t),agentKey:a.unitKey.split("#").slice(1).join("#")}});if(!e?.grouped)return i.map(a=>({...a,steps:[a]}));let l=new Map;return i.forEach((a,c)=>{let p=o[c].groupKey?`group:${o[c].groupKey}`:`step:${c}`,f=l.get(p)??[];f.push(a),l.set(p,f)}),[...l.values()].map(a=>{let c=a[0],p=o.find(f=>f.unitKey===c.node.id);return{...c,steps:a,keys:a.flatMap(f=>f.keys),files:Object.assign({},...a.map(f=>f.files)),node:{...c.node,label:p.groupName??p.name,sourcePaths:[...new Set(a.map(f=>f.sourcePath))],files:a.flatMap(f=>f.node.files),tools:[...new Map(a.flatMap(f=>f.node.tools).map(f=>[f.label,f])).values()]}}})}function Yo(e,t){return Qn(e,t).flatMap(({steps:n})=>n.flatMap(({files:o,sourcePath:r,agentKey:s})=>Object.entries(o).map(([i,l])=>({path:i,text:l,sourcePath:r,agentKey:s,role:i.slice(i.lastIndexOf("/")+1)}))))}function Km(e,t,n,o=""){let r=new Set(n.nodes.filter(p=>p.kind==="agent").map(p=>p.id)),s=[],i={},l=Qn(e,t,o);for(let p of l)r.has(p.node.id)||(r.add(p.node.id),s.push(p.node),Object.assign(i,p.files));let a=new Map(l.flatMap(p=>p.keys.map(f=>[f,p.node.id]))),c=$o((e?.enabled?e.byRepo[t]??[]:[]).filter(p=>r.has(a.get(p.unitKey)??p.unitKey)).map(p=>{let f=a.get(p.unitKey)??p.unitKey;return{...p,id:f,scope:t,links:p.links?.map(u=>({...u,to:a.get(u.to)??u.to})).filter(u=>!e?.grouped||u.to!==f),unitKey:f}}));return{nodes:s,files:i,edges:c}}function Um(e,t,n){return n.length?t.filter(o=>!o.startsWith(`${e}: no agent found \u2014`)&&!o.startsWith(`${e}: no agent conventions found (`)):t}function Gm(e,t,n){let o=new Set(Qn(e,t).flatMap(r=>Object.keys(r.files)));return o.size?Object.fromEntries(Object.entries(n).filter(([r])=>!o.has(r))):n}var jl=["stripe","slack","postgresql","datadog","pagerduty","jira","googlecalendar"],Tl=new Set(jl);function Xt(e){if(!e)return null;let t=e.trim().toLowerCase();return Tl.has(t)?t:null}function Nl(e,t){let n=[...e.warnings],o=new Set(e.nodes.map(l=>l.id)),r=new Set,s=e.nodes.map(l=>{let a=[],c=new Set;for(let p of l.tools??[]){let f=p.label.trim();if(!f){n.push(`${t}: dropped a tool with no name on ${l.id}`);continue}let u=`${p.source??"tool"}:${f}`;if(c.has(u)){n.push(`${t}: ${l.id} lists ${f} twice \u2014 kept one`);continue}c.add(u);let d=Xt(p.brand);p.brand&&!d&&!r.has(p.brand)&&(r.add(p.brand),n.push(`${t}: "${p.brand}" is not a provider mark we can draw \u2014 those tools render without one`)),a.push({label:f,brand:d,...p.source?{source:p.source}:{}})}return{...l,tools:a}}),i=e.edges.filter(l=>{let a=o.has(l.from)&&o.has(l.to);return a||n.push(`${t}: dropped edge ${l.from} \u2192 ${l.to} (unknown endpoint)`),a});return e.nodes.some(l=>l.kind==="agent")||n.push(`${t}: the mapping found no agent node \u2014 the graph may be incomplete`),{fragment:{...e,nodes:s,edges:i,warnings:[]},warnings:n}}var Jt=2e4;function cs(e){return e.trim().replace(/^(?:\.?\/)+/,"")}function Fl(e,t,n,o={}){let r=[],s=new Map;for(let c of Object.keys(t))s.set(cs(c),c);let i={},l=Hn(e),a=e.nodes.map(c=>{let p=[],f=[];for(let u of c.files??[]){let d=u.path.trim();if(!d)continue;let m=s.get(cs(d));if(m===void 0){r.push(`${n}: node ${c.id} lists ${d} as a definition file, which the analysis never read \u2014 dropped`);continue}let g=t[m],h=g.length>Jt,k=(u.role==="system prompt"?Nr(o,m,g,u.span,Jt):null)??(h&&u.span&&u.role==="system prompt"&&ln(m)?bt(g,u.span.from,Jt):null),y=k?k.text:h?g.slice(0,Jt):g;h&&!Zn(m,l)&&r.push(`${n}: node ${c.id}'s ${u.role} file (${m}) is ${g.length} characters \u2014 stored truncated at ${y.length}`),p.push({role:u.role,label:u.label??null,path:m,...u.span?{span:u.span}:{},...u.filledAtRunTime?{filledAtRunTime:!0}:{}}),f.push({...u.filledAtRunTime?{filledAtRunTime:!0}:{},role:u.role,...u.label?{label:u.label}:{},path:m,tokens:ko(g.length),text:y,...h?{truncated:!0,storedChars:y.length}:{},...u.span?{span:u.span}:{},...k?{fromLine:k.fromLine}:{}})}return f.length&&(i[c.id]=f),{...c,files:p}});return{fragment:{...e,nodes:a},nodes:i,warnings:r}}function Dl(e){let t=[],n=[];for(let{repoKey:o,fragment:r,files:s}of e){let i=l=>`${o}#${l}`;for(let l of r.nodes){let a=s?.[l.id],c=(l.tools??[]).map(p=>({label:p.label,...p.brand?{brand:p.brand}:{},...p.source?{source:p.source}:{}}));t.push({id:i(l.id),label:l.label,kind:l.kind,desc:l.desc,meta:l.meta,...l.sourcePaths?{sourcePaths:l.sourcePaths}:{},sourceRef:l.sourceRef?{repo:o,path:l.sourceRef.path,line:l.sourceRef.line}:null,...a?.length?{files:a}:{},...c.length?{tools:c}:{}})}for(let l of r.edges)n.push({from:i(l.from),to:i(l.to),kind:l.kind,label:l.label,sourceRef:l.sourceRef?{repo:o,path:l.sourceRef.path,line:l.sourceRef.line}:null})}return{nodes:t,edges:n}}var Bl={critical:0,high:1,medium:2,low:3};function eo(e){return Bl[e]}function fs(e){let t=e?.trim();return t&&t.length<=280?t:null}var Wl=2,to=4,no=120,us="Which should the agent do?",Kl="asked to pose a question, answered with one fix";function ps(e){if(!nn(e.category))return{question:null,fixes:e.fixes,warnings:[]};let t=`finding "${e.title}"`;if(e.fixes.length<Wl)return{question:null,fixes:e.fixes,warnings:[`${t}: ${Kl}`]};let n=[],o=e.fixes;o.length>to&&(n.push(`${t}: ${o.length} options proposed; keeping the first ${to}`),o=o.slice(0,to));let r=(e.question??"").trim();return r?r.length>no&&(n.push(`${t}: the question is longer than ${no} characters; cut`),r=`${r.slice(0,no-1).trimEnd()}\u2026`):(n.push(`${t}: no question with ${o.length} options; asking "${us}"`),r=us),{question:r,fixes:o,warnings:n}}var Ul="users";function ms(e){let t=fo.safeParse(e);return t.success?t.data:Ul}function ds(e,t){if(on(t))return ms(e)}function Gl(e){let t={users:[],team:[]};for(let n of e)t[ms(n.audience)].push(n);return t}function ld(e){if(!e.every(t=>t===void 0))return e.every(t=>t==="team")?"team":"users"}function gs(e){let t=e.replace(/\s/g," "),n=[],o=[],r=!0;for(let s=0;s<e.length;s++){let i=t[s];i===" "&&r||(n.push(i),o.push(s),r=i===" ")}return{text:n.join("").trimEnd(),offsets:o}}function*hs(e,t){let n=gs(e),o=gs(t).text;if(!o)return;let r=l=>e.slice(0,n.offsets[l]).split(`
|
|
28
|
+
`).length,s=n.text.indexOf(o);if(s>=0){for(let l=s;l>=0;l=n.text.indexOf(o,l+1))yield[{from:r(l),to:r(l+o.length-1)}];return}let i=o.split(/\s*(?:\.{3}|…)\s*/);if(!(i.length<2||i.some(l=>!l)))for(let l=n.text.indexOf(i[0]);l>=0;l=n.text.indexOf(i[0],l+1)){let a=l+i[0].length,c=[{from:r(l),to:r(a-1)}],p=!0;for(let f of i.slice(1)){let u=n.text.indexOf(f,a);if(u<0||/\n\s*\n|\n\s*#{1,6}\s|\n[^\s][^:\n]*:/.test(e.slice(n.offsets[a-1]+1,n.offsets[u]))){p=!1;break}a=u+f.length,c.push({from:r(u),to:r(a-1)})}p&&(yield c)}}function xs(e,t){for(let n of hs(e,t))return n[0].from;return null}function cd(e,t,n){if(!Number.isInteger(n)||n<1)return null;for(let o of hs(e,t)){if(o[0].from===n)return o;if(o[0].from>n)break}return null}function oo(e){if(typeof e=="string")try{e=JSON.parse(e)}catch{return}let t=dt.safeParse(e);if(!t.success)return;let n=t.data;if(n.state==="active")return n;if(!(!n.reason.trim()||!n.evidence.length)&&!(n.state==="switched_off"&&(!n.gate?.trim()||n.evidence.length<2))&&!(n.state==="dead"&&n.gate!==null))return n}function ro(e,t){return kt(t)?oo(e):void 0}var Ss=/[\w$-]/;function ys(e,t){for(let n=e.indexOf(t);n!==-1;n=e.indexOf(t,n+1)){let o=n>0?e[n-1]:"",r=e[n+t.length]??"";if(!Ss.test(o)&&!Ss.test(r))return!0}return!1}function Vl(e,t,n,o){let r=t.evidence[0];if(![...e.site?[e.site]:[],...e.otherSites??[]].some(a=>a.path===r.path&&a.line===r.line)||!r.path.endsWith(".json"))return!1;try{JSON.parse(n[r.path])}catch{return!1}let i=r.excerpt.match(/^\s*[{]?\s*["']?([\w$-]+)["']?\s*:/)?.[1];if(o.some(a=>/\b(?:glob|rglob|readdir|readdirSync|listdir|scandir|iterdir)\b/.test(a))||!i||!Object.hasOwn(n,r.path)||o.reduce((a,c)=>a+c.split(i).length-1,0)!==1)return!1;let l=r.path.split("/").at(-1);return!o.some(a=>a.includes(r.path)||a.includes(l))}function Xl(e,t,n,o){let r=t.gate?.match(/^([A-Za-z_][\w]*)(?:=[^\r\n]+)?$/)?.[1];if(!r||t.evidence.length!==2||t.evidence.some(u=>!ys(u.excerpt,r)))return!1;let s=/^\s*if ["']([^"']+)["'] in os\.getenv\(["']([A-Za-z_]\w*)["'], ["']["']\)\.split\(["'],["']\):\s*$/,i=/^\s*if \(process\.env\.([A-Za-z_]\w*) === ["'](?:1|true)["']\)\s*\{?\s*$/,l=/^\s*(?:export )?([A-Za-z_]\w*)\s*=\s*(?:["']["']|false|False|0|null|None|undefined)?\s*(?:#.*)?$/,a=u=>s.exec(u)?.[2]===r||i.exec(u)?.[1]===r,c=u=>l.exec(u)?.[1]===r,[p,f]=t.evidence;return!a(p.excerpt)||!c(f.excerpt)||/^(?:false|False|0|null|None|undefined)$/.test(s.exec(p.excerpt)?.[1]??"")?!1:o.every(u=>u.split(`
|
|
29
|
+
`).every(d=>!ys(d,r)||a(d)||c(d)))&&Jl(e,t,n)}function Jl(e,t,n){let o=t.evidence[0],r=n[o.path].split(`
|
|
30
|
+
`),s=r[o.line-1],i=s.length-s.trimStart().length,l=[],a=!1,c=s.trimEnd().endsWith(":");if(!c&&!s.trimEnd().endsWith("{"))return!1;for(let f of r.slice(o.line)){if(f.trim()&&f.length-f.trimStart().length<=i){if(!c&&f.trim()!=="}")return!1;a=!0;break}if(f.includes(" ")||!c&&/[{}]/.test(f))return!1;l.push(f)}if(!c&&!a)return!1;let p=[...e.site?[e.site]:[],...e.otherSites??[]];return p.length>0&&p.every(f=>f.path===o.path?(f.line??0)>o.line&&(f.line??0)<=o.line+l.length:l.some(u=>u.includes(`"${f.path}"`)||u.includes(`'${f.path}'`)))}function dd(e,t,n,o=Object.values(t),r=!0){return e.map(s=>{let{activity:i,...l}=s,a=ro(i,n);return!a||!r&&a.state!=="active"||a.evidence.some(c=>{let p=Object.hasOwn(t,c.path)?t[c.path]:void 0;return typeof p!="string"||!Number.isInteger(c.line)||c.line<1||!c.excerpt.trim()||xs(p.split(`
|
|
31
|
+
`).slice(c.line-1).join(`
|
|
32
|
+
`),c.excerpt)!==1})||a.state==="dead"&&!Vl(s,a,t,o)||a.state==="switched_off"&&!Xl(s,a,t,o)?l:{...l,activity:a}})}function Yl(e,t=!0){let n=[],o=[];for(let r of e){let s=t?oo(r.activity):void 0;(s&&s.state!=="active"?o:n).push(r)}return{active:n,notActive:o}}function gd(e){let t=e.map(o=>oo(o.activity)),n=t[0];return n&&t.every(o=>o?.state===n.state&&o.gate===n.gate)?n:void 0}function so(e,t,n,o,r){if(t===null)return null;let s=e.safeParse(t);return s.success?s.data:(r.push(`${o}: ${n} "${t}" is not one of ${Object.values(e.enum).join(", ")} \u2014 dropped`),null)}var io=12,ks=3,ws=3;function bs(e,t){return Object.keys(e).find(n=>e[n].has(t))}function ql(e,t,n=io,o={},r=[]){let s=[],i=new Set(r),l=e;if(en(o)){let u=e.filter(d=>d.category==="better_as_code");if(u.length>ks){let d=u.sort((g,h)=>eo(g.severity)-eo(h.severity)).slice(0,ks),m=0;l=e.flatMap(g=>g.category!=="better_as_code"?[g]:m<d.length?[d[m++]]:[])}}let a=l.slice(0,n),c=new Set(a.map(yt));for(let u of r){let d=yt(u);c.has(d)||(a.push(u),c.add(d))}l.length>n&&!(en(o)&&n>io)&&s.push(`the model proposed ${l.length} findings; keeping the first ${n}`);let p=u=>{let d=(u.otherSites??[]).flatMap(k=>{let y=tn.safeParse(k);return y.success?[y.data]:(s.push(`finding "${u.title}" listed an other site in a shape we could not read \u2014 dropped`),[])}),m=i.has(u)?d.length:ws;d.length>m&&s.push(`finding "${u.title}" quoted ${d.length} other sites; keeping the first ${ws}`);let g=d.slice(0,m).flatMap(k=>{let y=bs(t,k.path);return y?[{...k,repo:y}]:(s.push(`finding "${u.title}" also cited ${k.path}, which the analysis never read \u2014 that site dropped`),[])});if(!u.site)return{...u,siteRepo:null,otherSites:g};let h=bs(t,u.site.path);return h?{...u,siteRepo:h,otherSites:g}:(s.push(`finding "${u.title}" cited ${u.site.path}, which the analysis never read \u2014 site dropped`),{...u,site:null,excerpt:u.excerpt,siteRepo:null,otherSites:g})};return{findings:a.map(u=>{let{audience:d,activity:m,...g}=p(u),h=ds(d,o),k=ro(m,o),y=ps(g);return s.push(...y.warnings),{...g,...h===void 0?{}:{audience:h},...k===void 0?{}:{activity:k},summary:fs(g.summary),fixes:y.fixes,question:y.question}}),warnings:s}}function Hl(e){let t=e.title.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),n=[...new Set(e.targetFiles.map(o=>o.path.trim().replace(/^(\.\/)+/,"")))].sort().join(`
|
|
33
|
+
`);return[e.kind,t,n].join("|")}function Zl(e,t,n){if(!e)return{delta:null,warnings:[]};let o=[],r=[];for(let l of e.nodes){let a=so(Ht,l.change,`delta node ${l.id} change`,n,o);if(a){if(a!=="added"&&!t.has(l.id)){o.push(`${n}: dropped delta node ${l.id} (not in the architecture)`);continue}r.push({id:l.id,change:a,label:l.label})}}let s=new Set([...t,...r.map(l=>l.id)]),i=[];for(let l of e.edges){let a=`${l.from} \u2192 ${l.to}`,c=so(Ht,l.change,`delta edge ${a} change`,n,o),p=so(uo,l.kind,`delta edge ${a} kind`,n,o);if(!(!c||!p)){if(!s.has(l.from)||!s.has(l.to)){o.push(`${n}: dropped delta edge ${a} (unknown node)`);continue}i.push({from:l.from,to:l.to,kind:p,change:c,detail:l.detail})}}return r.length===0&&i.length===0?{delta:null,warnings:o}:{delta:{nodes:r,edges:i},warnings:o}}function Ql(e){return yt(e)}function ea(e){let t=e.split(`
|
|
34
|
+
`);return t.length>1&&t[t.length-1]===""&&t.pop(),t.map((n,o)=>`${o+1} ${n}`).join(`
|
|
35
|
+
`)}export{na as a,oa as b,Xe as c,vs as d,We as e,_o as f,Ro as g,ne as h,V as i,Ao as j,_t as k,ye as l,vt as m,ke as n,cn as o,Co as p,Fs as q,fn as r,Fo as s,le as t,Ws as u,Us as v,Gs as w,Aa as x,Dc as y,F as z,et as A,An as B,Si as C,Ee as D,Ye as E,Je as F,Bc as G,$t as H,Sn as I,Wc as J,_e as K,Ri as L,Ai as M,It as N,wn as O,Kc as P,Uc as Q,Gc as R,zc as S,Vc as T,Do as U,At as V,Xs as W,Oa as X,dn as Y,Ma as Z,or as _,H as $,oe as aa,xr as ba,nu as ca,Fn as da,Lr as ea,ut as fa,Bu as ga,Ir as ha,Wu as ia,Ku as ja,Tr as ka,Bt as la,fp as ma,up as na,bp as oa,Jr as pa,Yr as qa,zt as ra,pm as sa,mm as ta,dm as ua,ns as va,vm as wa,rs as xa,ln as ya,ia as za,la as Aa,Xt as Ba,Nl as Ca,Fl as Da,Dl as Ea,Gl as Fa,ld as Ga,xs as Ha,cd as Ia,dd as Ja,Yl as Ka,gd as La,io as Ma,ql as Na,Hl as Oa,Zl as Pa,Ql as Qa,ea as Ra,Vt as Sa,Im as Ta,ss as Ua,is as Va,Hn as Wa,Zn as Xa,Wm as Ya,as as Za,Cl as _a,Qn as $a,Km as ab,Um as bb,Gm as cb,Ko as db,gn as eb,Fa as fb,hn as gb,qe as hb,Ua as ib,Ga as jb,yn as kb,Qa as lb,qs as mb,Hs as nb,Lc as ob,bn as pb,qo as qb,Ho as rb,oi as sb,ri as tb,Zo as ub,Qo as vb,er as wb,Xo as xb,Ze as yb,si as zb,Qe as Ab,He as Bb,ii as Cb,tr as Db,Lt as Eb,Re as Fb,Pc as Gb,mi as Hb,di as Ib,hi as Jb,xi as Kb,Oc as Lb};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as ne,b as se,c as ie,d as X,e as T}from"./CNQZLSAP.js";import{a as te}from"./I4F56VMG.js";import{z as t}from"zod";import{z as i}from"zod";var r=i.string(),S=r.nullable(),P=i.number().int().nonnegative().safe(),U=i.number().int().positive().safe(),re=i.strictObject({path:r.optional(),startLine:U,endLine:U}),h=i.number(),oe=i.strictObject({subKind:i.enum(["split_monolith","single_source","fold_patches","extract_subagent","merge_subagents","move_rule","move_tool","reorder"]),kind:ne,severity:se,title:r,cause:r,summary:r.optional(),evidence:i.array(i.strictObject({path:r,line:U,excerpt:r})),files:i.array(i.strictObject({path:r,action:i.enum(["create","shrink","edit","delete"]),role:i.enum(["system prompt","soul","knowledge","skill","config","tools","mcp","template","reference","log","code"]),unit:r,loadMode:i.enum(["always","on_demand","never"]),loadVia:S,purpose:r,frontmatter:i.strictObject({name:r,description:r,tools:i.array(r)}).nullable()})),segments:i.array(i.strictObject({path:r,startLine:h,endLine:h,to:r,disposition:i.enum(["move","fold_into","remove_duplicate","remove_superseded"]),into:i.strictObject({path:r,line:h}).nullable(),childRef:S,heading:S,reason:r})),additions:i.array(i.strictObject({path:r,text:r,kind:i.enum(["pointer","handoff","reference_update"]),heading:S})),reorder:i.strictObject({path:r,startLine:h,endLine:h,steps:i.array(i.strictObject({from:U,reason:S}))}).nullable(),toolMoves:i.array(i.strictObject({tool:r,fromUnit:r,toUnit:r,reason:r,fromPath:S,toPath:S})),motivation:i.array(i.strictObject({kind:r,reason:r,evidence:r})).optional(),outcomes:i.array(i.strictObject({improvement:r,measurement:r})).optional(),split:i.strictObject({root:r.optional(),frontDoor:i.strictObject({name:r.optional(),job:r,skills:i.array(r)}),subAgents:i.array(i.strictObject({name:r,job:r,description:r,path:r,handoff:r.optional(),resolves:i.array(r).optional(),skills:i.array(i.strictObject({name:r,from:r,to:r})),tools:i.array(r),noTools:i.boolean().optional(),movedKnowledge:i.array(re),neededKnowledge:i.array(re)}))}).optional()}),ye=i.strictObject({nodes:i.array(X.shape.nodes.element.extend({change:i.enum(["added","edited","removed"]),label:S.optional()})),edges:i.array(X.shape.edges.element.extend({kind:i.enum(["invokes","delegates","reads","writes","emits"]),change:i.enum(["added","edited","removed"]),detail:S.optional()})),files:i.array(i.strictObject({path:r,role:oe.shape.files.element.shape.role,node:r,change:i.enum(["added","removed","moved","shrunk","grown","reordered"]),fromNode:r.optional(),fromPath:r.optional(),segments:P})),tools:i.array(i.strictObject({label:r,fromNode:r,toNode:r}))}),v=i.strictObject({repo:r,children:i.array(i.strictObject({ref:r,how:r})),sourceHashes:i.record(r,r),body:oe,delta:ye,...ie}),K=i.enum(["secret","secret-content","hidden","excluded","wrong-type","too-large","empty","out-of-scope","allowance","total","scan-limit","tool-limit","missing","unreadable"]),Z=i.enum([...K.options,"coding-guide","duplicate"]),Re=i.strictObject({fromProposal:P,fromRulesOnly:P,rejected:P,rejectedByReason:i.partialRecord(Z,P)}),Te=i.strictObject({repoKey:r,findings:i.array(T),structures:i.array(v),warnings:i.array(r),proposalCounts:Re.optional(),refusedFiles:i.array(i.strictObject({path:r,reason:K}))});function ce(e){return{nodes:e.nodes.map(({id:n,change:s,label:o})=>({id:n,change:s,...o===void 0?{}:{label:o}})),edges:e.edges.map(({from:n,to:s,kind:o,change:c,detail:a})=>({from:n,to:s,kind:o,change:c,...a===void 0?{}:{detail:a}}))}}function le(e,n=s=>s){let{kind:s,severity:o,title:c,cause:a,summary:C,category:p,question:E,excerpt:m}=e;return{kind:s,severity:o,title:c,cause:a,summary:C,category:p,question:E,excerpt:m,...e.activity===void 0?{}:{activity:te.parse(e.activity)},siteRepo:n(e.siteRepo),site:e.site&&{path:e.site.path,line:e.site.line},otherSites:e.otherSites.map(({repo:O,path:F,line:f,excerpt:I})=>({repo:n(O),path:F,line:f,excerpt:I})),fixes:e.fixes.map(({title:O,approach:F,kind:f,targetFiles:I,expectedOutcome:A,summary:j,impact:D,confidence:g,objective:x,status:M,blockedBy:G,alsoFixes:L,delta:N})=>({title:O,approach:F,kind:f,targetFiles:I.map(({path:k,create:B})=>({path:k,create:B})),expectedOutcome:A,summary:j,impact:D,confidence:g,objective:x,status:M,blockedBy:G,alsoFixes:L&&L.slice(),delta:N&&ce(N)})),...e.sourceNotes===void 0?{}:{sourceNotes:e.sourceNotes&&{sites:e.sourceNotes.sites.map(({index:O,role:F,meaning:f,keyPhrase:I})=>({index:O,role:F,meaning:f,keyPhrase:I})),support:e.sourceNotes.support,supportNote:e.sourceNotes.supportNote,counterEvidence:e.sourceNotes.counterEvidence.map(({repo:O,path:F,line:f,excerpt:I,meaning:A})=>({repo:n(O),path:F,line:f,excerpt:I,meaning:A}))}}}}function de(e){return{...e.headline===void 0?{}:{headline:e.headline},...e.ifLeft===void 0?{}:{ifLeft:e.ifLeft}}}function be(e){let n=e.body;return{repo:e.repo,children:e.children.map(({ref:s,how:o})=>({ref:s,how:o})),sourceHashes:Object.fromEntries(Object.entries(e.sourceHashes)),body:{subKind:n.subKind,kind:n.kind,severity:n.severity,title:n.title,cause:n.cause,...n.summary===void 0?{}:{summary:n.summary},evidence:n.evidence.map(({path:s,line:o,excerpt:c})=>({path:s,line:o,excerpt:c})),files:n.files.map(({path:s,action:o,role:c,unit:a,loadMode:C,loadVia:p,purpose:E,frontmatter:m})=>({path:s,action:o,role:c,unit:a,loadMode:C,loadVia:p,purpose:E,frontmatter:m&&{name:m.name,description:m.description,tools:m.tools.slice()}})),segments:n.segments.map(({path:s,startLine:o,endLine:c,to:a,disposition:C,into:p,childRef:E,heading:m,reason:O})=>({path:s,startLine:o,endLine:c,to:a,disposition:C,into:p&&{path:p.path,line:p.line},childRef:E,heading:m,reason:O})),additions:n.additions.map(({path:s,text:o,kind:c,heading:a})=>({path:s,text:o,kind:c,heading:a})),reorder:n.reorder&&{path:n.reorder.path,startLine:n.reorder.startLine,endLine:n.reorder.endLine,steps:n.reorder.steps.map(({from:s,reason:o})=>({from:s,reason:o}))},toolMoves:n.toolMoves.map(({tool:s,fromUnit:o,toUnit:c,reason:a,fromPath:C,toPath:p})=>({tool:s,fromUnit:o,toUnit:c,reason:a,fromPath:C,toPath:p})),...n.motivation===void 0?{}:{motivation:n.motivation.map(({kind:s,reason:o,evidence:c})=>({kind:s,reason:o,evidence:c}))},...n.outcomes===void 0?{}:{outcomes:n.outcomes.map(({improvement:s,measurement:o})=>({improvement:s,measurement:o}))},...n.split===void 0?{}:{split:{...n.split.root===void 0?{}:{root:n.split.root},frontDoor:{...n.split.frontDoor.name===void 0?{}:{name:n.split.frontDoor.name},job:n.split.frontDoor.job,skills:n.split.frontDoor.skills.slice()},subAgents:n.split.subAgents.map(s=>({name:s.name,job:s.job,description:s.description,path:s.path,...s.handoff===void 0?{}:{handoff:s.handoff},...s.resolves===void 0?{}:{resolves:s.resolves.slice()},skills:s.skills.map(({name:o,from:c,to:a})=>({name:o,from:c,to:a})),tools:s.tools.slice(),...s.noTools===void 0?{}:{noTools:s.noTools},movedKnowledge:s.movedKnowledge.map(ae),neededKnowledge:s.neededKnowledge.map(ae)}))}}},delta:{...ce(e.delta),files:e.delta.files.map(({path:s,role:o,node:c,change:a,fromNode:C,fromPath:p,segments:E})=>({path:s,role:o,node:c,change:a,segments:E,...C===void 0?{}:{fromNode:C},...p===void 0?{}:{fromPath:p}})),tools:e.delta.tools.map(({label:s,fromNode:o,toNode:c})=>({label:s,fromNode:o,toNode:c}))},...de(e)}}function ae({path:e,startLine:n,endLine:s}){return{...e===void 0?{}:{path:e},startLine:n,endLine:s}}function Ae(e,n){return{repoKey:e.repoKey,findings:e.findings.map(s=>({...le(s),...de(s),...s.audience===void 0?{}:{audience:s.audience}})),structures:e.structures.map(be),warnings:e.warnings.slice(),...e.proposalCounts?{proposalCounts:{fromProposal:e.proposalCounts.fromProposal,fromRulesOnly:e.proposalCounts.fromRulesOnly,rejected:e.proposalCounts.rejected,rejectedByReason:Object.fromEntries(Z.options.filter(s=>e.proposalCounts.rejectedByReason[s]!==void 0).map(s=>[s,e.proposalCounts.rejectedByReason[s]]))}}:{},refusedFiles:n.map(({path:s,reason:o})=>({path:s,reason:o}))}}function Le(e){if(e.redacted)throw new Error("Relay refused the request: leak_refused");return e.answer}import{z as R}from"zod";var b=1,_e=R.string().min(1).max(128),$=["file_reads","repository_listing","sealed_delivery"],W=R.strictObject({protocol:R.literal(b),bundleVersion:_e,engineVersion:_e,capabilities:R.array(R.enum($)).refine(e=>e.length===$.length&&new Set(e).size===$.length)}),H=2;function pe(){return R.strictObject({...W.shape,protocol:R.literal(H)}).refine(e=>W.safeParse({...e,protocol:b}).success)}var Ce=Object.freeze(["CF_SKIPPED_FILES","CF_MECHANICAL_CHECKS","CF_MULTI_PASS","CF_SPLIT_CHECK","CF_FINDING_CHECK","CF_SOURCE_NOTES","CF_PARALLEL_PASSES","CF_PASS_CONCURRENCY","CF_PARALLEL_SCOPE_CHECK","CF_FINDING_QUALITY","CF_FINDING_FULL_CONTEXT","CF_FINDING_PRECISION_RULES","CF_PROMPT_AGREE","CF_FINDING_SECOND_OPINION","CF_FINDING_RANKING","CF_FINDING_SEMANTIC_MATCHING","CF_FINDING_CODE_INPUTS","CF_FINDING_RECALL","CF_FINDING_RECALL_VARIANT","CF_FINDING_SECOND_OPINION_MODEL","CF_FINDING_SECOND_OPINION_PROVIDER","CF_FIX_EXPECTED_OUTCOME","CF_UNTRUSTED_CONTENT_CHECK","CF_FINDING_BETTER_AS_CODE","CF_CODE_AGENTS","CF_CODE_AGENTS_MODEL","CF_FINDING_DEDUPE","CF_ANALYSIS_IMPORTED_AGENTS","CF_RECALL_SIGNALS","CF_READING_NOTE_AGENT_ONLY","CF_SPLIT_HELPER_TOOLS","CF_CODE_PROMPT_LOADERS","CF_CODE_PROMPT_FUNCTIONS","CF_READING_PRIORITY","CF_LOCAL_SYMLINK_GUARD","CF_IMPORT_EXAMPLE_FILTER","CF_IMPORT_OUTSIDE_LOADERS","CF_SECRET_SCAN","CF_RESPECT_GITIGNORE","CF_IMPORT_COVERAGE","CF_IMPORT_LEXICAL_FACTS","CF_IMPORT_PROMPT_FIELDS","CF_IMPORT_MANIFEST","CF_IMPORT_SCOPED_SCAN","CF_IMPORT_SCOPES","CF_IMPORT_AGENT_PAGES","CF_IMPORT_INCLUDE_EXAMPLES","CF_IMPORT_WEAK_CODE_FALLBACK","CF_FILE_SCOPE","CF_SCOPE_CHOICES","CF_FOLDER_PARTS","CF_PART_FILES","CF_LOCAL_IMPORT_RESOLUTION","CF_MULTI_ENTRY","CF_IMPORT_GUIDES_AS_PROMPT","CF_CONFIGURATION_GUIDE_PROMPT","CF_CHOOSE_AGENT","CF_IMPORT_PROPOSAL","CF_LOCAL_COMMITTED_ONLY","CF_LOCAL_GITIGNORE_OUTPUT","CF_LOCAL_ARCHITECTURE","CF_REFUSE_TOO_LARGE","CF_COST_FINDINGS","CF_FINDING_AUDIENCE","CF_NOT_ACTIVE_GROUP","CF_FINDING_HEADLINES","CF_IMPORT_LAYOUTS","CF_DISCOVERY_SKILLS","CF_IMPORT_CALLS","CF_PROMPT_CACHE","CF_MODEL_READER","CF_LEGACY_TOOL_LISTS","CF_RESULT_SAFETY_CHECK"]),Q=Ce.filter(e=>e!=="CF_SKIPPED_FILES"&&e!=="CF_RESULT_SAFETY_CHECK"&&e!=="CF_LOCAL_COMMITTED_ONLY"&&e!=="CF_LOCAL_GITIGNORE_OUTPUT"&&e!=="CF_LOCAL_ARCHITECTURE"&&e!=="CF_FOLDER_PARTS"&&e!=="CF_PART_FILES"&&e!=="CF_FILE_SCOPE"&&e!=="CF_SCOPE_CHOICES"&&e!=="CF_LOCAL_IMPORT_RESOLUTION"&&e!=="CF_MULTI_ENTRY"),Oe=Q.filter(e=>e!=="CF_IMPORT_OUTSIDE_LOADERS"&&e!=="CF_SECRET_SCAN"&&e!=="CF_RESPECT_GITIGNORE"&&e!=="CF_IMPORT_COVERAGE"&&e!=="CF_IMPORT_LEXICAL_FACTS"&&e!=="CF_IMPORT_PROMPT_FIELDS"&&e!=="CF_IMPORT_MANIFEST"&&e!=="CF_IMPORT_SCOPED_SCAN"&&e!=="CF_REFUSE_TOO_LARGE"&&e!=="CF_IMPORT_SCOPES"&&e!=="CF_IMPORT_AGENT_PAGES"&&e!=="CF_IMPORT_INCLUDE_EXAMPLES"&&e!=="CF_IMPORT_WEAK_CODE_FALLBACK"&&e!=="CF_IMPORT_GUIDES_AS_PROMPT"&&e!=="CF_CONFIGURATION_GUIDE_PROMPT"&&e!=="CF_CHOOSE_AGENT"&&e!=="CF_IMPORT_PROPOSAL"&&e!=="CF_FINDING_AUDIENCE"&&e!=="CF_MECHANICAL_CHECKS"&&e!=="CF_COST_FINDINGS"&&e!=="CF_NOT_ACTIVE_GROUP");function et(e,n="request"){return Object.freeze(Object.fromEntries((n==="saved"?Ce:n==="engine"?Q:Oe).filter(o=>Object.hasOwn(e,o)&&e[o]!==void 0).map(o=>[o,e[o]])))}var tt=t.partialRecord(t.enum(Oe),t.string()),Ee=t.partialRecord(t.enum(Q),t.string()),u=t.string(),d=t.number().int().nonnegative().safe(),y=t.number().int().positive().safe(),z=t.enum(["bad_request","unavailable","reservation","leak_refused","cancelled"]);function st(e){let n=z.safeParse(e);return n.success?n.data:"unavailable"}function it(e){return Object.assign(new Error(e),{code:e})}var Ne=1024*1024,ue=u.min(1).max(128),Y=u.regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/),q=u.regex(/^[a-f0-9]{64}$/),_={protocol:t.literal(b),analysisId:t.uuid(),nonce:u.min(16).max(256),bundleVersion:ue,engineVersion:ue};function l(e){return t.unknown().refine(n=>{try{let s=JSON.stringify(n);return typeof s=="string"&&new TextEncoder().encode(s).byteLength<=Ne}catch{return!1}}).pipe(e)}var he=u.min(1).refine(e=>!/[\\\0\r\n]/.test(e)&&!/^(?:\/|[a-zA-Z]:)/.test(e)&&e.split("/").every(n=>n!==""&&n!=="."&&n!=="..")),Pe=t.strictObject({id:Y,path:he,size:d,hash:q}),J=t.array(Pe).refine(e=>new Set(e.map(n=>n.id)).size===e.length&&new Set(e.map(n=>n.path)).size===e.length),ee=t.strictObject({snapshot:q,commit:u.regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),files:J,entriesVisited:d.optional(),truncated:t.boolean().optional(),complete:t.boolean(),cursor:u.min(1).max(256).optional()}).refine(e=>e.complete?e.cursor===void 0:e.cursor!==void 0),rt=l(t.strictObject({..._,settings:Ee,manifest:ee})),ot=t.strictObject(_),je=t.strictObject({startByte:d,endByte:d}).refine(e=>e.endByte>e.startByte),De=t.strictObject({startLine:y,endLine:y}).refine(e=>e.endLine>=e.startLine),me=l(t.strictObject({..._,type:t.literal("need_files"),sequence:d,reads:t.array(t.strictObject({id:Y,range:t.union([je,De])})).min(1)})),Fe=l(t.strictObject({..._,type:t.literal("need_listing"),sequence:d,cursor:u.min(1).max(256).nullable()})),ge=l(t.discriminatedUnion("type",[t.strictObject({..._,type:t.literal("files"),sequence:d,files:t.array(t.union([t.strictObject({id:Y,startByte:d,text:u,complete:t.boolean(),hash:q}),t.strictObject({id:Y,refused:K})])).min(1)}),t.strictObject({..._,type:t.literal("listing"),sequence:d,manifest:ee}),t.strictObject({..._,type:t.literal("reservation"),sequence:d,reservationId:t.uuid(),reservationToken:u.min(1).max(256)}),t.strictObject({..._,type:t.literal("delivery"),sequence:d,callId:t.uuid(),attemptId:t.uuid().nullable()}),t.strictObject({..._,type:t.literal("chunk"),sequence:d,callId:t.uuid(),attemptId:t.uuid(),chunk:y})])),w={chunk:d,chunks:y},xe=t.strictObject({..._,type:t.literal("result"),finalFiles:J,findings:t.array(T),structures:t.array(v),notices:t.array(u)}),Me=l(xe.extend(w).refine(e=>e.chunk<e.chunks)),Ge=l(t.strictObject({..._,type:t.literal("result_chunk"),...w,text:u,hash:q}).refine(e=>e.chunk<e.chunks)),fe=l(t.strictObject({..._,type:t.literal("call_failed"),sequence:d,callId:t.uuid(),attemptId:t.uuid().nullable(),code:z}));function ke(e){let n=l(t.strictObject({..._,type:t.literal("plan"),sequence:d,...w,plan:e.plan,finalFiles:J}).refine(a=>a.chunk<a.chunks)),s=u.regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/).min(1).refine(a=>!/\s/.test(a)),o=l(t.strictObject({..._,type:t.literal("sealed_delivery"),sequence:d,callId:t.uuid(),attemptId:t.uuid(),algorithm:t.literal("AES-256-GCM"),iv:s.length(16),...w,ciphertext:s,tag:u.regex(/^[A-Za-z0-9+/]{21}[AQgw]==$/).length(24).optional(),delivery:t.strictObject({confirmation:e.deliveryConfirmation,deadlineMs:y}).optional()}).refine(a=>a.chunk<a.chunks&&(a.chunk===a.chunks-1?a.tag!==void 0&&a.delivery!==void 0&&a.delivery.confirmation.callId===a.callId&&a.delivery.confirmation.attemptId===a.attemptId:a.tag===void 0&&a.delivery===void 0))),c=t.strictObject({..._,type:t.literal("refused"),code:z});return{plan:n,sealedDelivery:o,response:t.union([me,Fe,n,o,fe,Me,Ge,c])}}var at=t.strictObject({version:t.literal(1),serializedBytes:y,freeTextUtf8Bytes:y,fields:t.array(t.strictObject({pointer:u.regex(/^(?:\/(?:[^~/]|~[01])*)+$/),kind:t.enum(["string","array"]),max:y}))});function ct(e){let n={..._,protocol:t.literal(H)},s=e.context,o=l(t.strictObject({...n,settings:Ee,context:s.preparationContext,manifest:ee})),c=t.strictObject(n),a=l(t.union([...ge.out.options.map(V=>V.extend(n)),t.strictObject({...n,type:t.literal("next"),sequence:d,stream:t.enum(["plan","result"]),chunk:y})])),C=t.strictObject({kind:t.literal("ready"),plan:e.plan,finalFiles:s.finalFiles,analysisSize:s.analysisSize,membership:s.membership}),p=t.strictObject({kind:t.literal("agent_choice"),choice:e.choice}),E=t.strictObject({kind:t.literal("proposal_refused")}),m=t.union([C,p,E]),O=t.strictObject({finalFiles:s.finalFiles,report:e.report,membership:s.membership}),F=O.extend({...n,type:t.literal("result")}),f=l(t.strictObject({...n,type:t.literal("plan"),sequence:d,plan:e.plan,finalFiles:s.finalFiles,analysisSize:s.analysisSize,membership:s.membership})),I=e.planChunks,A=e.resultChunks,j=l(I.chunk.safeExtend({...n,type:t.literal("plan_chunk"),sequence:d,stream:t.literal("plan")})),D=l(A.chunk.safeExtend({...n,type:t.literal("result_chunk"),sequence:d,stream:t.literal("result")})),g=ke(e),x=l(t.strictObject({...g.sealedDelivery.out.shape,...n}).refine(V=>g.sealedDelivery.safeParse({...V,protocol:b}).success)),M=l(me.out.extend(n)),G=l(Fe.out.extend(n)),L=l(fe.out.extend(n)),N=t.strictObject({...n,type:t.literal("refused"),code:z}),k=t.strictObject({...n,type:t.literal("cancelled")}),B=l(t.union([M,G,f,x,L,l(F),j,D,N,k,t.strictObject({...n,type:t.literal("agent_choice"),choice:e.choice}),t.strictObject({...n,type:t.literal("proposal_refused")})])),Ie=t.union([O.extend({kind:t.literal("result")}),p,E]),Se=pe();return{start:o,cancel:c,advance:a,needFiles:M,needListing:G,ready:C,preparationOutcome:m,resultBody:O,finalResult:F,plan:f,planChunk:j,resultChunk:D,sealedDelivery:x,callFailure:L,refused:N,cancelled:k,response:B,clientOutcome:Ie,capabilities:Se}}export{v as a,Te as b,le as c,Ae as d,Le as e,b as f,W as g,H as h,Ce as i,et as j,tt as k,Ee as l,z as m,st as n,it as o,Ne as p,Pe as q,ee as r,rt as s,ot as t,me as u,Fe as v,ge as w,xe as x,Me as y,Ge as z,fe as A,ke as B,at as C,ct as D};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pa as t,ra as o,va as a,xa as p}from"./
|
|
1
|
+
import{pa as t,ra as o,va as a,xa as p}from"./QPIBHTON.js";function m(e,l,n={}){let r=t(e,l,n.structureState);return[...r.calls,...o(e,r.findings),...p(e,l,n),...a(e)]}function C(e,l){let n=Object.entries(l.files).map(([f,i])=>({path:f,size:Buffer.byteLength(i)})),r=m(e,n,{structureState:{repos:[{key:l.repoKey,kind:"fs",files:l.files,...l.root===void 0?{}:{root:l.root}}],mapped:[l.fragment]}});return{files:n,calls:r}}export{m as a,C as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as B}from"./VC3PYT2B.js";import{C as z}from"./P253B344.js";import{b as _,d as E}from"./W73WF226.js";import{a as A}from"./M5YWJY7P.js";import{Fb as b}from"./2M55DR2J.js";import{a as d}from"./MKYLK6DB.js";var L=t=>typeof t=="string"&&t.length>0&&!/[\\\0\r\n]/.test(t)&&!/^(?:\/|[a-zA-Z]:)/.test(t)&&t.split("/").every(n=>n!==""&&n!=="."&&n!=="..");function q(t){if(!B(t)||t.CF_PART_FILES===void 0)return;let n;try{n=JSON.parse(t.CF_PART_FILES)}catch{throw new Error("bad_request")}if(!Array.isArray(n)||!n.every(L))throw new Error("bad_request");return[...new Set(n)]}function S(t,n){let r=0,i=0,o=0;for(let c of t){let a=n.get(c);a.pool==="instruction"?r+=a.size:(i+=a.size,o++)}return{instruction:r,code:i,count:o}}function M(t,n,r){let{instruction:i,code:o,count:c}=S(t,n);return i<=d.sourceFetch.instructionBytes&&o<=d.sourceFetch.codeBytes&&c<=d.sourceFetch.codeFiles&&i+o<=d.codeAgent.importBytes&&E([...t].map(a=>({path:a,...n.get(a)})),r)!==void 0}var F=(t,n)=>new Set([...t,...n]);function N(t,n){let r=[];for(let i of t){let o=r.find(c=>M(F(c.files,i.files),n));o?(o.roots.push(i),o.files=F(o.files,i.files)):r.push({roots:[i],files:i.files})}return r}function P(t,n,r){let i=[...t].map(o=>[r.get(o).size,r.get(o).inputBytes??0]);return i.sort((o,c)=>o[0]-c[0]||o[1]-c[1]),JSON.stringify([S(t,r),i,[...t].filter(o=>n.has(o)).sort()])}function v(t,n,r,i){let o=[],c=new Set,a=t.map((f,e)=>new Set(t.slice(e).flatMap(s=>[...s.files]))),h=f=>{if(i.remaining--<=0)return!1;if(f===t.length)return!0;let e=l=>P(l,a[f],n),s=JSON.stringify([f,o.map(l=>e(l.files)).sort()]);if(c.has(s))return!1;let u=t[f],w=new Set;for(let l=0;l<=o.length&&l<r;l++){if(i.remaining<=0)return!1;let g=o[l],m=e(g?.files??new Set);if(w.has(m))continue;w.add(m);let p=g?F(g.files,u.files):u.files;if(M(p,n,i)){if(o[l]={roots:[...g?.roots??[],u],files:p},h(f+1))return!0;g?o[l]=g:o.pop()}}return c.add(s),!1};return h(0)?o:void 0}function I(t,n){if(!t.length)return[];let r=[...t].sort((e,s)=>s.weight-e.weight),i=N(r,n),o=S(new Set(t.flatMap(e=>[...e.files])),n),c=Math.max(1,Math.ceil(o.instruction/d.sourceFetch.instructionBytes),Math.ceil(o.code/d.sourceFetch.codeBytes),Math.ceil(o.count/d.sourceFetch.codeFiles)),a=_(),h=i;for(let e=c;e<i.length&&a.remaining>0;e++){let s=v(r,n,e,a);if(s){h=s;break}}let f=new Map(t.map((e,s)=>[e.path,s]));return h.map(e=>({paths:e.roots.map(s=>s.path).sort((s,u)=>f.get(s)-f.get(u)),files:[...e.files]})).sort((e,s)=>f.get(e.paths[0])-f.get(s.paths[0]))}function D(t,n){let r=new Map(n.entries.map(e=>[e.path,e])),{descriptions:i}=z(t,n.entries,{},{measureAnalysisSize:!0}),o=new Map(i.map(e=>[e.entry.path,e.analysisPool??e.pool])),c=new Map,a=new Map;for(let e of r.values()){if(!L(e.path)||!Number.isSafeInteger(e.size)||e.size<0){a.set(e.path,"unavailable");continue}let s=b(t,e,{purpose:"proposal",route:"local-folder"});if(!s.admitted){a.set(e.path,s.reason==="too-large"?"tooLarge":"unavailable");continue}let u=n.inputBytes?.[e.path];if(u!==void 0&&(!Number.isSafeInteger(u)||u<0)){a.set(e.path,"unavailable");continue}if(u!==void 0&&u>=8e5){a.set(e.path,"tooLarge");continue}c.set(e.path,{size:e.size,inputBytes:u,pool:o.get(e.path)??"code"})}let h={groups:[],tooLarge:[],unavailable:[]},f=[];for(let e of new Set(n.paths)){let s=new Set,u=[e],w=new Set,l=new Set,g;for(;u.length;){let p=u.pop();if(w.has(p))continue;w.add(p);let y=a.get(p)??(c.has(p)?void 0:"unavailable");if(y&&p!==e){l.add(p);continue}if(y){g=y;continue}s.add(p),n.dependencies&&Object.hasOwn(n.dependencies,p)&&u.push(...n.dependencies[p])}if(g){h[g].push(e);continue}if(l.size&&(h.missingContext??=[]).push({path:e,imports:[...l].sort()}),!M(s,c)){h.tooLarge.push(e);continue}let m=S(s,c);f.push({path:e,files:s,weight:Math.max(m.instruction/d.sourceFetch.instructionBytes,m.code/d.sourceFetch.codeBytes,m.count/d.sourceFetch.codeFiles)})}return h.groups=I(f,c),h}export{q as a,D as b};
|
|
@@ -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"./KBTM5MBC.js";import{d as s}from"./3MTXB4MK.js";import{a as S}from"./N2L4JMJE.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
|
+
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"./QPIBHTON.js";import{a as Ye}from"./5VQ4VYIP.js";import{i as $e}from"./6JTHFDH3.js";import{a as J}from"./QDYMR6KS.js";import{a as We}from"./XVGLY4EO.js";import{g as _}from"./6VHZNBII.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"./LFJQ4YLP.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"./DHVEGIU6.js";import{a as je,b as re}from"./5UWDUYHF.js";import{e as ke,g as Se}from"./VC3PYT2B.js";import{n as $}from"./P253B344.js";import{c as Ie}from"./W73WF226.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"./2M55DR2J.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as b,d as l}from"./VX6LYNXV.js";import{a as u,b as o,c as g}from"./QVXARKP7.js";import{a as r}from"./JAPVLU4Z.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};
|