@counterfact-labs/cli 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +7 -1
  2. package/bundle/client-release.json +1 -1
  3. package/dist/adapters/anthropic.js +11 -2
  4. package/dist/adapters/completion.js +3 -0
  5. package/dist/adapters/durable-write.js +9 -2
  6. package/dist/adapters/files.js +25 -13
  7. package/dist/adapters/git-ignore.js +28 -14
  8. package/dist/adapters/git.js +1 -1
  9. package/dist/adapters/gitignore-output.js +41 -0
  10. package/dist/adapters/models.js +1 -6
  11. package/dist/adapters/output-paths.js +5 -2
  12. package/dist/adapters/public-instructions.js +1 -1
  13. package/dist/adapters/relay-plan.js +2 -5
  14. package/dist/adapters/release.js +2 -1
  15. package/dist/adapters/repository-files.js +164 -4
  16. package/dist/adapters/repository-root.js +18 -2
  17. package/dist/adapters/results.js +8 -4
  18. package/dist/adapters/settings.js +26 -1
  19. package/dist/adapters/snapshot.js +86 -15
  20. package/dist/analysis-core/analysis/finding-audience-switch.js +1 -0
  21. package/dist/analysis-core/analysis/schemas.js +1 -1
  22. package/dist/analysis-core/analysis/source-notes/types.js +1 -1
  23. package/dist/analysis-core/chunks/377MLK4M.js +21 -0
  24. package/dist/analysis-core/chunks/{D6AWHLRI.js → 3JWEFCTJ.js} +1 -1
  25. package/dist/analysis-core/chunks/{3227KXHF.js → 4H23CSUM.js} +1 -1
  26. package/dist/analysis-core/chunks/5DGPLXYB.js +1 -0
  27. package/dist/analysis-core/chunks/5TATKWLG.js +1 -0
  28. package/dist/analysis-core/chunks/{EH3QQ3T4.js → 6B2HILSY.js} +1 -1
  29. package/dist/analysis-core/chunks/6QY5BV5B.js +14 -0
  30. package/dist/analysis-core/chunks/6U2IR4XB.js +1 -0
  31. package/dist/analysis-core/chunks/A7WJJMRY.js +1 -0
  32. package/dist/analysis-core/chunks/C6X5GDG4.js +1 -0
  33. package/dist/analysis-core/chunks/DLPVYWHZ.js +1 -0
  34. package/dist/analysis-core/chunks/DZZBQDGO.js +1 -0
  35. package/dist/analysis-core/chunks/F3R4J3ND.js +1 -0
  36. package/dist/analysis-core/chunks/FOKDE64Y.js +1 -0
  37. package/dist/analysis-core/chunks/K2GNDX3W.js +1 -0
  38. package/dist/analysis-core/chunks/KTNA2KTN.js +7 -0
  39. package/dist/analysis-core/chunks/KWECQJ6X.js +1 -0
  40. package/dist/analysis-core/chunks/{SL27GMEN.js → M6HYSTQD.js} +1 -1
  41. package/dist/analysis-core/chunks/{ZAA44GPI.js → N7U5N42V.js} +1 -1
  42. package/dist/analysis-core/chunks/NIOS7U6C.js +41 -0
  43. package/dist/analysis-core/chunks/{QMIXCT62.js → OPMA32A6.js} +1 -1
  44. package/dist/analysis-core/chunks/PECX3OXB.js +1 -0
  45. package/dist/analysis-core/chunks/QFY6A3MS.js +66 -0
  46. package/dist/analysis-core/chunks/SKVEBOGA.js +1 -0
  47. package/dist/analysis-core/chunks/{T66VDFXF.js → STI4JE7L.js} +1 -1
  48. package/dist/analysis-core/chunks/SVMEWGD3.js +1 -0
  49. package/dist/analysis-core/chunks/X7WZAA7S.js +1 -0
  50. package/dist/analysis-core/chunks/YDBO7P4X.js +1 -0
  51. package/dist/analysis-core/chunks/YUY436SM.js +1 -0
  52. package/dist/analysis-core/chunks/ZTOVBAG7.js +1 -0
  53. package/dist/analysis-core/contracts/file-safety.js +1 -0
  54. package/dist/analysis-core/contracts/relay-analysis.js +1 -0
  55. package/dist/analysis-core/contracts/requests.js +1 -1
  56. package/dist/analysis-core/conventions/analysis-fit.js +1 -1
  57. package/dist/analysis-core/conventions/file-admission.js +1 -1
  58. package/dist/analysis-core/data/finding-types.js +1 -1
  59. package/dist/analysis-core/findings/sites.js +1 -0
  60. package/dist/analysis-core/github/repo-key.js +1 -1
  61. package/dist/analysis-core/import/outside-loader-sources.js +1 -1
  62. package/dist/analysis-core/index.js +3 -3
  63. package/dist/analysis-core/llm/output-limit.js +1 -1
  64. package/dist/analysis-core/llm/types.js +1 -0
  65. package/dist/analysis-core/requests/answer-formats.js +1 -1
  66. package/dist/analysis-core/requests/headline-request.js +1 -1
  67. package/dist/analysis-core/requests/local-plan.js +1 -1
  68. package/dist/analysis-core/requests/registry.js +1 -1
  69. package/dist/analysis-core/requests/template-version.js +1 -1
  70. package/dist/analysis-core/requests/tools.js +1 -1
  71. package/dist/analysis-core/settings.js +1 -1
  72. package/dist/analysis-core/stages/engine-entry.js +1 -0
  73. package/dist/analysis-core/stages/execution-ports.js +1 -0
  74. package/dist/bundle/seal/deserialise.js +9 -1
  75. package/dist/bundle/seal/engine.js +76 -0
  76. package/dist/bundle/seal/freeze.js +9 -0
  77. package/dist/bundle/seal/metadata.js +3 -0
  78. package/dist/bundle/seal/open-engine.js +26 -0
  79. package/dist/bundle/seal/open.js +2 -8
  80. package/dist/cli/agent-folder.js +3 -3
  81. package/dist/cli/commands/analyze.js +39 -6
  82. package/dist/cli/commands/balance.js +6 -3
  83. package/dist/cli/commands/finding.js +9 -3
  84. package/dist/cli/context.js +6 -1
  85. package/dist/cli/finding-display.js +39 -0
  86. package/dist/cli/finding-lookup.js +92 -0
  87. package/dist/cli/finding-settings.js +5 -0
  88. package/dist/cli/fix-requests.js +42 -0
  89. package/dist/cli/intake-payload.js +19 -11
  90. package/dist/cli/main.js +9 -4
  91. package/dist/cli/mcp-failure.js +8 -0
  92. package/dist/cli/mcp.js +125 -37
  93. package/dist/cli/relay-check.js +47 -14
  94. package/dist/cli/relay-preparation.js +28 -5
  95. package/dist/cli/result-check.js +68 -0
  96. package/dist/cli/sign-in.js +61 -2
  97. package/dist/cli/summary.js +10 -3
  98. package/dist/contract/agent-choice.js +15 -0
  99. package/dist/contract/agent-proposal.js +38 -0
  100. package/dist/contract/attestation.js +106 -0
  101. package/dist/contract/cli-api-messages.js +2 -0
  102. package/dist/contract/cli-refusals.js +69 -1
  103. package/dist/contract/cli-version.js +1 -1
  104. package/dist/contract/console.js +21 -16
  105. package/dist/contract/email-sign-in-messages.js +4 -0
  106. package/dist/contract/engine.js +44 -0
  107. package/dist/contract/findings.js +28 -0
  108. package/dist/contract/fix-requests.js +30 -0
  109. package/dist/contract/messages.js +6 -94
  110. package/dist/contract/public-report.js +1 -0
  111. package/dist/contract/runtime-environment.js +12 -1
  112. package/dist/core/analysis/run-to-end.js +7 -52
  113. package/dist/gatekeeper/attestation.js +1 -1
  114. package/dist/gatekeeper/channel-binding.js +15 -0
  115. package/dist/gatekeeper/cli-api.js +28 -9
  116. package/dist/gatekeeper/connection-exchange.js +17 -12
  117. package/dist/gatekeeper/console.js +31 -17
  118. package/dist/gatekeeper/model.js +2 -1
  119. package/dist/gatekeeper/production-attestation.js +23 -17
  120. package/dist/gatekeeper/trust/policy.js +4 -1
  121. package/dist/gatekeeper/trust/schema.js +4 -0
  122. package/dist/transport/kms.js +25 -0
  123. package/package.json +4 -3
  124. package/dist/adapters/quality.js +0 -6
  125. package/dist/adapters/report.js +0 -29
  126. package/dist/analysis-core/analysis/analysis-flags.js +0 -1
  127. package/dist/analysis-core/analysis/finding-quality/config.js +0 -1
  128. package/dist/analysis-core/analysis/finding-quality/policy.js +0 -1
  129. package/dist/analysis-core/analysis/headlines/attachment.js +0 -1
  130. package/dist/analysis-core/analysis/headlines/input.js +0 -1
  131. package/dist/analysis-core/chunks/3CKW5JIF.js +0 -1
  132. package/dist/analysis-core/chunks/6YCABS5T.js +0 -1
  133. package/dist/analysis-core/chunks/7OYIBWX3.js +0 -1
  134. package/dist/analysis-core/chunks/DRGDIIFA.js +0 -1
  135. package/dist/analysis-core/chunks/FTODBFQW.js +0 -1
  136. package/dist/analysis-core/chunks/HPIAEQHE.js +0 -37
  137. package/dist/analysis-core/chunks/IVDDV6CU.js +0 -14
  138. package/dist/analysis-core/chunks/JF4GYMOZ.js +0 -1
  139. package/dist/analysis-core/chunks/K5OTWBTT.js +0 -22
  140. package/dist/analysis-core/chunks/MXXNED6N.js +0 -7
  141. package/dist/analysis-core/chunks/NCWEOJVJ.js +0 -6
  142. package/dist/analysis-core/chunks/O652FQQH.js +0 -1
  143. package/dist/analysis-core/chunks/OFBJNHC6.js +0 -1
  144. package/dist/analysis-core/chunks/QV2EOS7U.js +0 -1
  145. package/dist/analysis-core/chunks/STZOC7LN.js +0 -1
  146. package/dist/analysis-core/chunks/T2SAP7OV.js +0 -60
  147. package/dist/analysis-core/chunks/T5TREZCQ.js +0 -1
  148. package/dist/analysis-core/chunks/TDNTU4TF.js +0 -1
  149. package/dist/analysis-core/chunks/U5HOEVPE.js +0 -1
  150. package/dist/analysis-core/chunks/UEWL3GMQ.js +0 -1
  151. package/dist/analysis-core/chunks/V7BFUTM7.js +0 -1
  152. package/dist/core/analysis/finding-quality/config.js +0 -4
  153. package/dist/core/analysis/structural-run.js +0 -16
@@ -0,0 +1 @@
1
+ import{z as s}from"zod";import{z as t}from"zod";var n=t.string(),l=n.nullable(),R=t.number().int().nonnegative().safe(),F=t.number().int().positive().safe(),z=t.enum(["ordering","reliability","coverage","cost","safety","correctness"]),H=t.enum(["low","medium","high","critical"]),V={headline:n.optional(),ifLeft:n.optional()},_e=t.strictObject({path:n,line:F.nullable()}),G=t.strictObject({nodes:t.array(t.strictObject({id:n,change:n,label:l})),edges:t.array(t.strictObject({from:n,to:n,kind:n,change:n,detail:l}))}),Oe=t.strictObject({sites:t.array(t.strictObject({index:R,role:t.enum(["Says","But also says","Unclear","Context","Requirement","What actually happens","Why it's a gap","Evidence"]),meaning:n,keyPhrase:n})),support:t.enum(["supported","partly","not_supported"]),supportNote:n,counterEvidence:t.array(t.strictObject({repo:n,path:n,line:F,excerpt:n,meaning:n}))}),S=t.strictObject({kind:z,severity:H,title:n,cause:n,summary:l,category:l,question:l,audience:t.enum(["users","team"]).optional(),siteRepo:l,site:_e.nullable(),excerpt:l,otherSites:t.array(t.strictObject({repo:n,path:n,line:F,excerpt:n})),fixes:t.array(t.strictObject({title:n,approach:n,kind:t.enum(["code","prompt"]),targetFiles:t.array(t.strictObject({path:n,create:t.boolean().nullable()})),expectedOutcome:n,summary:l,impact:l,confidence:l,objective:l,status:l,blockedBy:l,alsoFixes:t.array(n).nullable(),delta:G.nullable()})),sourceNotes:Oe.nullable().optional(),...V}),Y=t.strictObject({path:n.optional(),startLine:F,endLine:F}),N=t.number(),X=t.strictObject({subKind:t.enum(["split_monolith","single_source","fold_patches","extract_subagent","merge_subagents","move_rule","move_tool","reorder"]),kind:z,severity:H,title:n,cause:n,summary:n.optional(),evidence:t.array(t.strictObject({path:n,line:F,excerpt:n})),files:t.array(t.strictObject({path:n,action:t.enum(["create","shrink","edit","delete"]),role:t.enum(["system prompt","soul","knowledge","skill","config","tools","mcp","template","reference","log","code"]),unit:n,loadMode:t.enum(["always","on_demand","never"]),loadVia:l,purpose:n,frontmatter:t.strictObject({name:n,description:n,tools:t.array(n)}).nullable()})),segments:t.array(t.strictObject({path:n,startLine:N,endLine:N,to:n,disposition:t.enum(["move","fold_into","remove_duplicate","remove_superseded"]),into:t.strictObject({path:n,line:N}).nullable(),childRef:l,heading:l,reason:n})),additions:t.array(t.strictObject({path:n,text:n,kind:t.enum(["pointer","handoff","reference_update"]),heading:l})),reorder:t.strictObject({path:n,startLine:N,endLine:N,steps:t.array(t.strictObject({from:F,reason:l}))}).nullable(),toolMoves:t.array(t.strictObject({tool:n,fromUnit:n,toUnit:n,reason:n,fromPath:l,toPath:l})),motivation:t.array(t.strictObject({kind:n,reason:n,evidence:n})).optional(),outcomes:t.array(t.strictObject({improvement:n,measurement:n})).optional(),split:t.strictObject({root:n.optional(),frontDoor:t.strictObject({name:n.optional(),job:n,skills:t.array(n)}),subAgents:t.array(t.strictObject({name:n,job:n,description:n,path:n,handoff:n.optional(),resolves:t.array(n).optional(),skills:t.array(t.strictObject({name:n,from:n,to:n})),tools:t.array(n),noTools:t.boolean().optional(),movedKnowledge:t.array(Y),neededKnowledge:t.array(Y)}))}).optional()}),Ce=t.strictObject({nodes:t.array(G.shape.nodes.element.extend({change:t.enum(["added","edited","removed"]),label:l.optional()})),edges:t.array(G.shape.edges.element.extend({kind:t.enum(["invokes","delegates","reads","writes","emits"]),change:t.enum(["added","edited","removed"]),detail:l.optional()})),files:t.array(t.strictObject({path:n,role:X.shape.files.element.shape.role,node:n,change:t.enum(["added","removed","moved","shrunk","grown","reordered"]),fromNode:n.optional(),fromPath:n.optional(),segments:R})),tools:t.array(t.strictObject({label:n,fromNode:n,toNode:n}))}),L=t.strictObject({repo:n,children:t.array(t.strictObject({ref:n,how:n})),sourceHashes:t.record(n,n),body:X,delta:Ce,...V}),P=t.enum(["secret","secret-content","hidden","excluded","wrong-type","too-large","empty","out-of-scope","allowance","total","scan-limit","tool-limit","missing","unreadable"]),k=t.enum([...P.options,"coding-guide","duplicate"]),me=t.strictObject({fromProposal:R,fromRulesOnly:R,rejected:R,rejectedByReason:t.partialRecord(k,R)}),fe=t.strictObject({repoKey:n,findings:t.array(S),structures:t.array(L),warnings:t.array(n),proposalCounts:me.optional(),refusedFiles:t.array(t.strictObject({path:n,reason:P}))});function W(e){return{nodes:e.nodes.map(({id:o,change:r,label:i})=>({id:o,change:r,...i===void 0?{}:{label:i}})),edges:e.edges.map(({from:o,to:r,kind:i,change:c,detail:a})=>({from:o,to:r,kind:i,change:c,...a===void 0?{}:{detail:a}}))}}function $(e,o=r=>r){let{kind:r,severity:i,title:c,cause:a,summary:u,category:d,question:E,excerpt:f}=e;return{kind:r,severity:i,title:c,cause:a,summary:u,category:d,question:E,excerpt:f,siteRepo:o(e.siteRepo),site:e.site&&{path:e.site.path,line:e.site.line},otherSites:e.otherSites.map(({repo:C,path:y,line:I,excerpt:b})=>({repo:o(C),path:y,line:I,excerpt:b})),fixes:e.fixes.map(({title:C,approach:y,kind:I,targetFiles:b,expectedOutcome:M,summary:oe,impact:ie,confidence:ae,objective:ce,status:le,blockedBy:de,alsoFixes:B,delta:q})=>({title:C,approach:y,kind:I,targetFiles:b.map(({path:ue,create:pe})=>({path:ue,create:pe})),expectedOutcome:M,summary:oe,impact:ie,confidence:ae,objective:ce,status:le,blockedBy:de,alsoFixes:B&&B.slice(),delta:q&&W(q)})),...e.sourceNotes===void 0?{}:{sourceNotes:e.sourceNotes&&{sites:e.sourceNotes.sites.map(({index:C,role:y,meaning:I,keyPhrase:b})=>({index:C,role:y,meaning:I,keyPhrase:b})),support:e.sourceNotes.support,supportNote:e.sourceNotes.supportNote,counterEvidence:e.sourceNotes.counterEvidence.map(({repo:C,path:y,line:I,excerpt:b,meaning:M})=>({repo:o(C),path:y,line:I,excerpt:b,meaning:M}))}}}}function Q(e){return{...e.headline===void 0?{}:{headline:e.headline},...e.ifLeft===void 0?{}:{ifLeft:e.ifLeft}}}function Ee(e){let o=e.body;return{repo:e.repo,children:e.children.map(({ref:r,how:i})=>({ref:r,how:i})),sourceHashes:Object.fromEntries(Object.entries(e.sourceHashes)),body:{subKind:o.subKind,kind:o.kind,severity:o.severity,title:o.title,cause:o.cause,...o.summary===void 0?{}:{summary:o.summary},evidence:o.evidence.map(({path:r,line:i,excerpt:c})=>({path:r,line:i,excerpt:c})),files:o.files.map(({path:r,action:i,role:c,unit:a,loadMode:u,loadVia:d,purpose:E,frontmatter:f})=>({path:r,action:i,role:c,unit:a,loadMode:u,loadVia:d,purpose:E,frontmatter:f&&{name:f.name,description:f.description,tools:f.tools.slice()}})),segments:o.segments.map(({path:r,startLine:i,endLine:c,to:a,disposition:u,into:d,childRef:E,heading:f,reason:C})=>({path:r,startLine:i,endLine:c,to:a,disposition:u,into:d&&{path:d.path,line:d.line},childRef:E,heading:f,reason:C})),additions:o.additions.map(({path:r,text:i,kind:c,heading:a})=>({path:r,text:i,kind:c,heading:a})),reorder:o.reorder&&{path:o.reorder.path,startLine:o.reorder.startLine,endLine:o.reorder.endLine,steps:o.reorder.steps.map(({from:r,reason:i})=>({from:r,reason:i}))},toolMoves:o.toolMoves.map(({tool:r,fromUnit:i,toUnit:c,reason:a,fromPath:u,toPath:d})=>({tool:r,fromUnit:i,toUnit:c,reason:a,fromPath:u,toPath:d})),...o.motivation===void 0?{}:{motivation:o.motivation.map(({kind:r,reason:i,evidence:c})=>({kind:r,reason:i,evidence:c}))},...o.outcomes===void 0?{}:{outcomes:o.outcomes.map(({improvement:r,measurement:i})=>({improvement:r,measurement:i}))},...o.split===void 0?{}:{split:{...o.split.root===void 0?{}:{root:o.split.root},frontDoor:{...o.split.frontDoor.name===void 0?{}:{name:o.split.frontDoor.name},job:o.split.frontDoor.job,skills:o.split.frontDoor.skills.slice()},subAgents:o.split.subAgents.map(r=>({name:r.name,job:r.job,description:r.description,path:r.path,...r.handoff===void 0?{}:{handoff:r.handoff},...r.resolves===void 0?{}:{resolves:r.resolves.slice()},skills:r.skills.map(({name:i,from:c,to:a})=>({name:i,from:c,to:a})),tools:r.tools.slice(),...r.noTools===void 0?{}:{noTools:r.noTools},movedKnowledge:r.movedKnowledge.map(Z),neededKnowledge:r.neededKnowledge.map(Z)}))}}},delta:{...W(e.delta),files:e.delta.files.map(({path:r,role:i,node:c,change:a,fromNode:u,fromPath:d,segments:E})=>({path:r,role:i,node:c,change:a,segments:E,...u===void 0?{}:{fromNode:u},...d===void 0?{}:{fromPath:d}})),tools:e.delta.tools.map(({label:r,fromNode:i,toNode:c})=>({label:r,fromNode:i,toNode:c}))},...Q(e)}}function Z({path:e,startLine:o,endLine:r}){return{...e===void 0?{}:{path:e},startLine:o,endLine:r}}function ye(e,o){return{repoKey:e.repoKey,findings:e.findings.map(r=>({...$(r),...Q(r),...r.audience===void 0?{}:{audience:r.audience}})),structures:e.structures.map(Ee),warnings:e.warnings.slice(),...e.proposalCounts?{proposalCounts:{fromProposal:e.proposalCounts.fromProposal,fromRulesOnly:e.proposalCounts.fromRulesOnly,rejected:e.proposalCounts.rejected,rejectedByReason:Object.fromEntries(k.options.filter(r=>e.proposalCounts.rejectedByReason[r]!==void 0).map(r=>[r,e.proposalCounts.rejectedByReason[r]]))}}:{},refusedFiles:o.map(({path:r,reason:i})=>({path:r,reason:i}))}}function Ie(e){if(e.redacted)throw new Error("Relay refused the request: leak_refused");return e.answer}import{z as A}from"zod";var g=1,J=A.string().min(1).max(128),U=["file_reads","repository_listing","sealed_delivery"],be=A.strictObject({protocol:A.literal(g),bundleVersion:J,engineVersion:J,capabilities:A.array(A.enum(U)).refine(e=>e.length===U.length&&new Set(e).size===U.length)});var te=Object.freeze(["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_IMPORT_GUIDES_AS_PROMPT","CF_CONFIGURATION_GUIDE_PROMPT","CF_CHOOSE_AGENT","CF_IMPORT_PROPOSAL","CF_LOCAL_COMMITTED_ONLY","CF_LOCAL_GITIGNORE_OUTPUT","CF_REFUSE_TOO_LARGE","CF_FINDING_AUDIENCE","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"]),w=te.filter(e=>e!=="CF_RESULT_SAFETY_CHECK"&&e!=="CF_LOCAL_COMMITTED_ONLY"&&e!=="CF_LOCAL_GITIGNORE_OUTPUT"),ne=w.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");function qe(e,o="request"){return Object.freeze(Object.fromEntries((o==="saved"?te:o==="engine"?w:ne).filter(i=>Object.hasOwn(e,i)&&e[i]!==void 0).map(i=>[i,e[i]])))}var Ye=s.partialRecord(s.enum(ne),s.string()),Fe=s.partialRecord(s.enum(w),s.string()),T=Object.freeze({findings:2e4,textBytes:4096,quoteBytes:2e3,freeTextBytesPerFinding:16*1024}),ze=T.freeTextBytesPerFinding*T.findings;function se(e){return typeof e=="string"?!e.includes("\0")&&!/[\uD800-\uDFFF]/u.test(e):e===null||typeof e!="object"||Object.values(e).every(se)}var Re=S.superRefine((e,o)=>{let r=0;function i(c,a){if(typeof c=="string"){let u=a.at(-1)==="excerpt"||a.at(-1)==="keyPhrase",d=new TextEncoder().encode(c).byteLength;u||(r+=d),(d>(u?T.quoteBytes:T.textBytes)||!se(c))&&o.addIssue({code:"custom",path:a,message:"Invalid result text"})}else Array.isArray(c)?c.forEach((u,d)=>i(u,[...a,d])):c!==null&&typeof c=="object"&&Object.entries(c).forEach(([u,d])=>i(d,[...a,u]))}i(e,[]),r>T.freeTextBytesPerFinding&&o.addIssue({code:"custom",message:"Result text exceeds the finding budget"})}),He=s.array(Re).max(T.findings),O=s.string(),p=s.number().int().nonnegative().safe(),h=s.number().int().positive().safe(),v=s.enum(["bad_request","unavailable","reservation","leak_refused","cancelled"]);function Xe(e){let o=v.safeParse(e);return o.success?o.data:"unavailable"}function Ze(e){return Object.assign(new Error(e),{code:e})}var Te=1024*1024,ee=O.min(1).max(128),j=O.regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/),D=O.regex(/^[a-f0-9]{64}$/),_={protocol:s.literal(g),analysisId:s.uuid(),nonce:O.min(16).max(256),bundleVersion:ee,engineVersion:ee};function m(e){return s.unknown().refine(o=>{try{let r=JSON.stringify(o);return typeof r=="string"&&new TextEncoder().encode(r).byteLength<=Te}catch{return!1}}).pipe(e)}var Ne=O.min(1).refine(e=>!/[\\\0\r\n]/.test(e)&&!/^(?:\/|[a-zA-Z]:)/.test(e)&&e.split("/").every(o=>o!==""&&o!=="."&&o!=="..")),Se=s.strictObject({id:j,path:Ne,size:p,hash:D}),K=s.array(Se).refine(e=>new Set(e.map(o=>o.id)).size===e.length&&new Set(e.map(o=>o.path)).size===e.length),re=s.strictObject({snapshot:D,commit:O.regex(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/),files:K,entriesVisited:p.optional(),truncated:s.boolean().optional(),complete:s.boolean(),cursor:O.min(1).max(256).optional()}).refine(e=>e.complete?e.cursor===void 0:e.cursor!==void 0),We=m(s.strictObject({..._,settings:Fe,manifest:re})),$e=s.strictObject(_),Ae=s.strictObject({startByte:p,endByte:p}).refine(e=>e.endByte>e.startByte),he=s.strictObject({startLine:h,endLine:h}).refine(e=>e.endLine>=e.startLine),Le=m(s.strictObject({..._,type:s.literal("need_files"),sequence:p,reads:s.array(s.strictObject({id:j,range:s.union([Ae,he])})).min(1)})),Pe=m(s.strictObject({..._,type:s.literal("need_listing"),sequence:p,cursor:O.min(1).max(256).nullable()})),Qe=m(s.discriminatedUnion("type",[s.strictObject({..._,type:s.literal("files"),sequence:p,files:s.array(s.union([s.strictObject({id:j,startByte:p,text:O,complete:s.boolean(),hash:D}),s.strictObject({id:j,refused:P})])).min(1)}),s.strictObject({..._,type:s.literal("listing"),sequence:p,manifest:re}),s.strictObject({..._,type:s.literal("reservation"),sequence:p,reservationId:s.uuid(),reservationToken:O.min(1).max(256)}),s.strictObject({..._,type:s.literal("delivery"),sequence:p,callId:s.uuid(),attemptId:s.uuid().nullable()}),s.strictObject({..._,type:s.literal("chunk"),sequence:p,callId:s.uuid(),attemptId:s.uuid(),chunk:h})])),x={chunk:p,chunks:h},ge=s.strictObject({..._,type:s.literal("result"),finalFiles:K,findings:s.array(S),structures:s.array(L),notices:s.array(O)}),je=m(ge.extend(x).refine(e=>e.chunk<e.chunks)),xe=m(s.strictObject({..._,type:s.literal("result_chunk"),...x,text:O,hash:D}).refine(e=>e.chunk<e.chunks)),De=m(s.strictObject({..._,type:s.literal("call_failed"),sequence:p,callId:s.uuid(),attemptId:s.uuid().nullable(),code:v}));function Je(e){let o=m(s.strictObject({..._,type:s.literal("plan"),sequence:p,...x,plan:e.plan,finalFiles:K}).refine(a=>a.chunk<a.chunks)),r=O.regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/).min(1).refine(a=>!/\s/.test(a)),i=m(s.strictObject({..._,type:s.literal("sealed_delivery"),sequence:p,callId:s.uuid(),attemptId:s.uuid(),algorithm:s.literal("AES-256-GCM"),iv:r.length(16),...x,ciphertext:r,tag:O.regex(/^[A-Za-z0-9+/]{21}[AQgw]==$/).length(24).optional(),delivery:s.strictObject({confirmation:e.deliveryConfirmation,deadlineMs:h}).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=s.strictObject({..._,type:s.literal("refused"),code:v});return{plan:o,sealedDelivery:i,response:s.union([Le,Pe,o,i,De,je,xe,c])}}export{S as a,L as b,fe as c,$ as d,ye as e,Ie as f,g,be as h,te as i,qe as j,Ye as k,Fe as l,T as m,ze as n,se as o,Re as p,He as q,v as r,Xe as s,Ze as t,Te as u,Se as v,re as w,We as x,$e as y,Le as z,Pe as A,Qe as B,ge as C,je as D,xe as E,De as F,Je as G};
@@ -0,0 +1 @@
1
+ import{Ba as p,ta as t,va as o,za as a}from"./QFY6A3MS.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{c as a}from"./C6X5GDG4.js";import{dirname as m,isAbsolute as x,posix as c,relative as s,resolve as i,sep as T}from"node:path";function E(t){return t.CF_RESPECT_GITIGNORE!=="0"}function u(t){return t.CF_LOCAL_SYMLINK_GUARD!=="0"}var R=/(^|\/)\.?(?:credentials|secrets)$/i,f=/(^|\/)(\.env(?:\.[^/]*)?|\.(?:npmrc|pypirc|netrc)|(?:secret|secrets|token|tokens)\.json|(?:credentials|secrets)\.(?:json|ya?ml)|secrets\.toml|[^/]+-credentials\.json|service-account[^/]*\.json|id_(?:rsa|dsa|ecdsa|ed25519)|[^/]+\.(?:pem|key|p12|pfx|tfvars|tfstate|ppk|jks|keystore))$/i,_=new RegExp(`${f.source}|${R.source}`,"i");function d(t,r=!1){return!(r?f:_).test(t.replace(/\\/g,"/"))}function y(t){return`Secret file was not read: ${t}.`}function L(t,r){return r==="secret"?y(t):`File outside the folder was not read: ${t}.`}function $(t,r,e){if(a(r.path,e.root)===null)return{admitted:!1,reason:"out-of-scope"};if(!d(r.path,r.directory))return{admitted:!1,reason:"secret"};let n=u(t)&&e.gitIgnored!==void 0&&e.localTarget?.parent!==void 0&&e.localTarget.parent!==m(i(e.localTarget.root,r.path));if(e.route==="local-folder"&&E(t)&&(n||e.gitIgnored?.has(r.path)||e.localTarget&&(e.gitIgnored?.has(e.localTarget.path)||e.gitIgnored?.has(i(e.localTarget.root,r.path)))))return{admitted:!1,reason:"excluded"};if(p(r.path,e.exclusions)||e.route==="local-folder"&&e.localTarget&&(p(s(e.localTarget.root,e.localTarget.path),e.exclusions)||e.localTarget.excludedTargets?.some(l=>h(e.localTarget.path,l))))return{admitted:!1,reason:"excluded"};if(e.exclusions?.length&&e.listing&&!e.listing.has(r.path))return{admitted:!1,reason:"excluded"};if(e.route==="local-folder"&&(u(t)||e.requireLocalTarget)&&e.localTarget){let l=s(e.localTarget.root,e.localTarget.path);if(!(e.allowSelectedFile&&e.localTarget.path===e.localTarget.selectedPath)&&(l===".."||l.startsWith(`..${T}`)||x(l)))return{admitted:!1,reason:"out-of-scope"};if(!d(l,r.directory))return{admitted:!1,reason:"secret"}}return{admitted:!0}}function g(t=[]){return t.map(r=>{let e=r.replace(/\\/g,"/"),o=e.endsWith("/**"),n=o?e.slice(0,-3):e,l=c.normalize(n);if(!e||n.includes("*")||n.includes("\0")||n.split("/").includes("..")||c.isAbsolute(e)||/^[A-Za-z]:/.test(l))throw new Error("Use repository-relative exclusion paths or directory trees ending in /**.");return{path:l,tree:o}})}function h(t,r){let e=c.normalize(t.replace(/\\/g,"/")),o=c.normalize(r.path.replace(/\\/g,"/"));return e===o||r.tree&&(o==="."?e!==".."&&!e.startsWith("../")&&!c.isAbsolute(e):e.startsWith(o.endsWith("/")?o:`${o}/`))}function p(t,r=[]){return g(r).some(e=>h(t,e))}async function b(t,r){let e=[];for(let o of g(t.exclusions)){let n=await r(o.path);n!==null&&e.push({...o,path:n})}return e}export{E as a,u as b,_ as c,d,y as e,L as f,$ as g,b as h};
@@ -0,0 +1 @@
1
+ import{j as n}from"./X7WZAA7S.js";function r(e){return e.CF_FINDING_HEADLINES==="1"}function o(e){return e.CF_RESULT_SAFETY_CHECK==="1"}function i(e){return e.CF_IMPORT_OUTSIDE_LOADERS==="1"}function E(e){return e.CF_PROMPT_AGREE==="1"}function u(e){return n(e,"saved")}export{r as a,o as b,i as c,E as d,u as e};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h}from"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";export{c as SECRET_FILE_RE,g as checkFileSafety,f as fileRefusalWarning,d as isReadableRepoPath,b as localSymlinkGuardEnabled,h as resolveLocalExclusions,a as respectGitignore,e as secretFileWarning};
@@ -0,0 +1 @@
1
+ import{A,B,C,D,E,F,G,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunks/X7WZAA7S.js";export{u as ANALYSIS_DATA_FRAME_BYTES,g as ANALYSIS_PROTOCOL,i as ANALYSIS_SETTING_NAMES,n as RESULT_CHECK_FREE_TEXT_BYTES,m as RESULT_CHECK_LIMITS,B as analysisAdvance,F as analysisCallFailure,s as analysisCallFailureCode,y as analysisCancel,h as analysisCapabilities,t as analysisFailure,r as analysisFailureCode,v as analysisFile,C as analysisFinalResult,w as analysisManifest,z as analysisNeedFiles,A as analysisNeedListing,D as analysisResult,E as analysisResultChunk,l as analysisSettings,x as analysisStart,j as filterAnalysisSettings,d as projectPublicFinding,e as projectPublicReport,a as publicFinding,c as publicReportSchema,b as publicStructure,G as relayAnalysisSchemas,k as requestAnalysisSettings,p as resultCheckFinding,q as resultCheckFindings,f as unredactedAnswer,o as validIntakeText};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h,i,j,k}from"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";export{a as ANALYSIS_SETTING_NAMES,g as analysisExecutionRequest,c as executionInputs,f as executionRequest,b as filterAnalysisSettings,d as modelName,k as recoverRequestFailure,e as requestLimits,h as requestPolicy,i as selectAnalysisTemplate,j as selectAnswerFormat};
1
+ import{a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k}from"../chunks/5DGPLXYB.js";import"../chunks/6U2IR4XB.js";import"../chunks/MJGB25S5.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";import{i as a,j as b}from"../chunks/X7WZAA7S.js";export{a as ANALYSIS_SETTING_NAMES,g as analysisExecutionRequest,c as executionInputs,f as executionRequest,b as filterAnalysisSettings,d as modelName,k as recoverRequestFailure,e as requestLimits,h as requestPolicy,i as selectAnalysisTemplate,j as selectAnswerFormat};
@@ -1 +1 @@
1
- import{b as a,c as b,d as c,e as d}from"../chunks/QV2EOS7U.js";import"../chunks/7OYIBWX3.js";import"../chunks/NCWEOJVJ.js";import"../chunks/HPIAEQHE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";import"../chunks/T5TREZCQ.js";import"../chunks/724WZMYW.js";export{a as analysisSizeLimits,c as assessAnalysisSize,d as measureAnalysisSize,b as parseAnalysisSize};
1
+ import{a,b,c,d}from"../chunks/PECX3OXB.js";import"../chunks/SVMEWGD3.js";import"../chunks/FOKDE64Y.js";import"../chunks/KTNA2KTN.js";import"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/FSLWD2PE.js";export{a as analysisSizeLimits,c as assessAnalysisSize,d as measureAnalysisSize,b as parseAnalysisSize};
@@ -1 +1 @@
1
- import{$ as q,L as a,M as b,N as c,O as d,P as e,Q as f,R as g,S as h,T as i,U as j,V as k,W as l,X as m,Y as n,Z as o,_ as p,aa as r,ba as s,ca as t,da as u,ea as v,fa as w,ga as x,ha as y,ia as z,ja as A,ka as B,la as C}from"../chunks/HPIAEQHE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";import"../chunks/T5TREZCQ.js";import"../chunks/724WZMYW.js";export{t as CODE_EXT_RE,k as EXTRACTION_CANDIDATE_RE,l as EXTRACTION_EXT_RE,b as FileReadRefusal,v as GIT_DIR_RE,m as LOCK_FILE_RE,u as NON_SOURCE_FOLDER_RE,e as REFERENCE_FILE_EXTENSIONS,n as SECRET_FILE_RE,x as SOURCE_CUT_MARKER,s as SOURCE_EXCLUDE_RE,r as SOURCE_NON_LOCK_EXCLUDE_RE,w as admitFile,B as admittedFileAccess,C as assertSnapshotAdmission,a as discoveredFilePurpose,q as fileRefusalWarning,g as isFetchableReferencePath,h as isFetchableSourcePath,f as isHtmlReferencePath,j as isReadableLocalPath,o as isReadableRepoPath,i as isUnreadCommandPath,d as localSymlinkGuardEnabled,z as readAdmittedSource,y as readRepoFile,A as resolveLocalExclusions,c as respectGitignore,p as secretFileWarning};
1
+ import{aa as h,ba as i,ca as j,da as k,ea as l,fa as m,ga as n,ha as o,ia as p,ja as q,ka as r,la as s,ma as t,na as u,oa as v,pa as w,qa as x,ra as y,sa as z,ta as A,ua as B,va as C,wa as D}from"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import{a,b,c,d,e,f,h as g}from"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/FSLWD2PE.js";export{v as CODE_EXT_RE,s as DEPENDENCY_BUILD_FOLDER_RE,p as EXTRACTION_CANDIDATE_RE,q as EXTRACTION_EXT_RE,i as FileReadRefusal,x as GIT_DIR_RE,r as LOCK_FILE_RE,w as NON_SOURCE_FOLDER_RE,j as REFERENCE_FILE_EXTENSIONS,c as SECRET_FILE_RE,z as SOURCE_CUT_MARKER,u as SOURCE_EXCLUDE_RE,t as SOURCE_NON_LOCK_EXCLUDE_RE,y as admitFile,C as admittedFileAccess,D as assertSnapshotAdmission,h as discoveredFilePurpose,f as fileRefusalWarning,l as isFetchableReferencePath,m as isFetchableSourcePath,k as isHtmlReferencePath,o as isReadableLocalPath,d as isReadableRepoPath,n as isUnreadCommandPath,b as localSymlinkGuardEnabled,B as readAdmittedSource,A as readRepoFile,g as resolveLocalExclusions,a as respectGitignore,e as secretFileWarning};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f}from"../chunks/JF4GYMOZ.js";export{b as fixConfidenceSchema,c as fixDeltaChangeSchema,d as fixDeltaEdgeKindSchema,e as fixDeltaSchema,f as fixFactsSchema,a as fixStatusSchema};
1
+ import{a,b,c,d,e,f,g}from"../chunks/SKVEBOGA.js";export{b as findingAudienceSchema,c as fixConfidenceSchema,d as fixDeltaChangeSchema,e as fixDeltaEdgeKindSchema,f as fixDeltaSchema,g as fixFactsSchema,a as fixStatusSchema};
@@ -0,0 +1 @@
1
+ import{a}from"../chunks/DZZBQDGO.js";export{a as findingSitesInOrder};
@@ -1 +1 @@
1
- import{f as a,g as b,h as c,i as d,j as e}from"../chunks/T5TREZCQ.js";export{e as folderOfRepoKey,b as localRepoKeyFor,a as repoKeyFor,c as repoKeyOfRepoPath,d as savedRepoKeyOf};
1
+ import{a,b,c,d,e}from"../chunks/5TATKWLG.js";import"../chunks/C6X5GDG4.js";export{e as folderOfRepoKey,b as localRepoKeyFor,a as repoKeyFor,c as repoKeyOfRepoPath,d as savedRepoKeyOf};
@@ -1 +1 @@
1
- import{a as c}from"../chunks/D6AWHLRI.js";import"../chunks/K5OTWBTT.js";import"../chunks/326F4XNG.js";import"../chunks/V7BFUTM7.js";import"../chunks/NCWEOJVJ.js";import"../chunks/2PSNOSJ2.js";import"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import{o as b}from"../chunks/HPIAEQHE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";import{e as a}from"../chunks/T5TREZCQ.js";import"../chunks/724WZMYW.js";export{b as READ_LIMITS,c as readOutsideLoaderSources,a as repoPathFrom};
1
+ import{a as c}from"../chunks/3JWEFCTJ.js";import"../chunks/377MLK4M.js";import"../chunks/326F4XNG.js";import"../chunks/ZTOVBAG7.js";import"../chunks/KTNA2KTN.js";import"../chunks/2PSNOSJ2.js";import{A as b}from"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import"../chunks/YUY436SM.js";import{e as a}from"../chunks/C6X5GDG4.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/FSLWD2PE.js";import"../chunks/X7WZAA7S.js";export{b as READ_LIMITS,c as readOutsideLoaderSources,a as repoPathFrom};
@@ -1,6 +1,6 @@
1
- import{$ as Ar,A as Fr,B as Rr,C as he,D as q,E as At,F as _t,G as ge,H as Mt,I as ke,J as Bt,K as Ce,L as Tt,M as It,N as Lt,O as Nt,P as jt,Q as Kt,R as Ht,S as vr,T as Dt,U as zt,V as Ut,W as qt,Y as Or,_ as Cr,a as wt,b as Y,ba as _r,c as St,d as fe,da as Mr,e as U,f as Pt,g as Q,h as bt,i as V,j as Z,k as ee,l as yt,m as Et,n as xt,o as te,p as Ft,q as Rt,r as vt,s as me,t as Ot,u as ue,v as Ct,w as ve,x as Oe,y as Er,z as xr}from"./chunks/T2SAP7OV.js";import{a as J}from"./chunks/QMIXCT62.js";import"./chunks/T66VDFXF.js";import"./chunks/J4AXGE5W.js";import{a as Pr,d as kt,k as br,l as yr}from"./chunks/IVDDV6CU.js";import"./chunks/Y7JGSUOA.js";import"./chunks/3MTXB4MK.js";import{i as gt}from"./chunks/TDNTU4TF.js";import"./chunks/HTLIRVP7.js";import{a as D}from"./chunks/QDYMR6KS.js";import{b as Sr}from"./chunks/E7TFIHC5.js";import{a as ht}from"./chunks/D6AWHLRI.js";import{C as wr,d as pe,e as pt,f as ft,t as ut}from"./chunks/K5OTWBTT.js";import{a as L}from"./chunks/326F4XNG.js";import{a as Re,b as mt,d as kr}from"./chunks/V7BFUTM7.js";import"./chunks/4F6ZIHXU.js";import"./chunks/VGYWI4X2.js";import"./chunks/PYKAERZZ.js";import{a as lt,b as mr,c as ur,d as hr,e as gr}from"./chunks/QV2EOS7U.js";import{a as nt,d as at,g as it,h as ct,i as dt,o as le}from"./chunks/7OYIBWX3.js";import{h as X}from"./chunks/NCWEOJVJ.js";import{b as B,c as ae}from"./chunks/2PSNOSJ2.js";import{b as He,c as De,k as st,o as Fe,q as fr}from"./chunks/DRGDIIFA.js";import"./chunks/6YCABS5T.js";import"./chunks/SL27GMEN.js";import"./chunks/3CKW5JIF.js";import"./chunks/STZOC7LN.js";import{c as _}from"./chunks/MJGB25S5.js";import"./chunks/UEWL3GMQ.js";import{a as Le,c as se}from"./chunks/OFBJNHC6.js";import"./chunks/MXXNED6N.js";import"./chunks/U5HOEVPE.js";import"./chunks/FTODBFQW.js";import"./chunks/ZAA44GPI.js";import{a as M,b as Ke}from"./chunks/3227KXHF.js";import"./chunks/O652FQQH.js";import"./chunks/57M4OQJM.js";import"./chunks/IBCFGUHI.js";import"./chunks/KU5DINLW.js";import{G as I,H as Ge,I as de,Ja as Ve,L as We,M as Xe,e as Ee,eb as Ze,fa as F,ia as Je,ib as et,ka as z,la as H,ma as Ye,mb as tt,o as v,p as Ue,r as qe,u as $e,ub as rt,v as xe,ya as Qe,zb as ot}from"./chunks/HPIAEQHE.js";import"./chunks/74FPPPIG.js";import"./chunks/EH3QQ3T4.js";import{f as K,i as ie,j as Ne,m as je,n as ce}from"./chunks/JKWTHRUR.js";import"./chunks/FSLWD2PE.js";import"./chunks/JF4GYMOZ.js";import{a as pr,b as ye}from"./chunks/3GUKUEEJ.js";import{a as ze,c as C,e as W}from"./chunks/T5TREZCQ.js";import{b as ne}from"./chunks/724WZMYW.js";function $(r,e,o,s){let t=new Set(o.map(c=>C(c.path,s))),n=r.CF_READING_NOTE_AGENT_ONLY!=="0"&&nt(r),l=new Set(e.agents),u=c=>!t.has(c)&&(!n||l.has(c)),g=e.instruction.filter(u),h=e.code.filter(u),p=e.agents.filter(c=>!t.has(c)),f=new Set(ct(p)),w=[...g,...h].every(c=>f.has(c)),b=g.length,i=h.length,m=[!w&&b>0&&`${b} instruction file${b===1?"":"s"} left out by the ${Math.round(v.sourceFetch.instructionBytes/1e3)}KB instruction budget`,!w&&i>0&&`${i} analyzable file${i===1?"":"s"} left out by the ${Math.round(v.sourceFetch.codeBytes/1e3)}KB/${v.sourceFetch.codeFiles}-file code budget \u2014 the analysis reads the most agent-shaped files first`,dt(p,n)].filter(Boolean),a=o.filter(c=>c.readBytes!==void 0).map(c=>C(c.path,s));return a.length&&m.push(`${a.join(", ")}: only the first ${v.sourceFetch.codeFileBytes/1e3} KB was read`),m.length?m.map((c,d)=>d<m.length-1?String(c).replace(/\.$/,""):c).join("; "):void 0}function we(r,e,o){let{descriptions:s,priority:t,declarations:n}=lt(r,e,{root:o}),l=[],u=s.flatMap(d=>d.admission.admitted?[{entry:d.readEntry,rel:d.rel,score:d.score,size:d.readEntry.size,pool:d.pool,...d.tier===void 0?{}:{tier:d.tier}}]:(l.push({path:d.entry.path,reason:d.admission.reason}),[])),g=u.filter(({score:d})=>d===0).sort(le),h=u.filter(({score:d})=>d>0).sort(le),p=[],f={instruction:0,code:0},w={instruction:[],code:[]},b=0,i=(t.enabled?[...u].sort(le):[...g,...h]).sort((d,k)=>Number(n.has(k.entry.path))-Number(n.has(d.entry.path)));for(let{entry:d,rel:k,pool:P}of i){let y=P==="instruction"?v.sourceFetch.instructionBytes:v.sourceFetch.codeBytes;if(f[P]+d.size>y||P==="code"&&b>=v.sourceFetch.codeFiles){w[P].push(k),l.push({path:d.path,reason:f[P]+d.size>y?"total":"allowance"});continue}p.push(d),f[P]+=d.size,P==="code"&&(b+=1)}let m=it(t,l.flatMap(d=>{let k=C(d.path,o);return k===null?[]:[{...d,path:k}]})),a={...w,agents:m},c=$(r,a,p,o);return{selected:p,totalBytes:f.instruction+f.code,refused:l,...c?{skippedNote:c}:{},...t.enabled&&c?{readingNotes:a}:{}}}var $t=(r,e)=>{let{markerToRead:o}=fe(e.settings,{paths:r.map(({path:s})=>s),root:e.dir??void 0,scanFlag:e.flags.scan,marker:null});return o?{strength:"partial",wants:[o]}:null};function Gt(r,e,o="bare"){let{scan:s}=fe(e.settings,{paths:r.map(({path:t})=>t),root:e.dir??void 0,scanFlag:e.flags.scan,marker:o});return s?{strength:"partial",wants:[]}:null}var Br=2e3;function Wt(r,e,o,s={}){let t=e.filter(S=>C(S.path,o)!=null),n={},l=[],u=new Map,g=s.mode!=="core"&&Qe(r),h=X(r,t.map(S=>S.path),o,{mode:g?"all":"core"}),p=new Set([...h.ignoredPaths,...h.ignoredImportPaths]),f=new Map(h.files.filter(S=>S.role!=="reference").map(S=>[S.path,S])),w=new Map(h.scopes.map(S=>[S.key,v.conventionImport.totalBytes])),b=v.conventionImport.skillBytes,i=Ee(r)?v.codeAgent.importBytes:1/0,m=0,a=S=>C(S.path,h.ownerOf(S.path).folder)??S.path,c=(S,E)=>{u.set(S.path,{path:S.path,reason:E})},d=(S,E)=>{let x=F(r,S,{purpose:E,route:"github",root:o});return x.admitted?!0:(c(S,x.reason),!1)},k=S=>{if(n[S.path])return;let E=g&&f.get(S.path)?.role==="skill"?"skill":"core",x=h.ownerOf(S.path),A=E==="skill"?b:w.get(x.key),T=S.size??0;if(E==="skill"&&m>=v.conventionImport.skillFiles){c(S,"allowance");return}if(T>A||T>i){c(S,"total");return}n[S.path]=S.ref,l.push(S.path),i-=T,E==="skill"?(b-=T,m++):w.set(x.key,A-T)},P=t.filter(S=>f.has(S.path));for(let S of P)d(S,We(f.get(S.path).role))&&k(S);let y=0;if(pe(r))for(let S of pt(new Set(t.map(E=>E.path)))){let E=t.find(x=>x.path===S);if(y>=v.conventionImport.extractionFiles){c(E,"allowance");continue}if(d(E,"source")&&d(E,"definition")){let x=l.length;k(E),l.length>x&&y++}}let R=h.needsExtraction;if(R){let S=t.flatMap(x=>{if(p.has(x.path)||n[x.path]||g&&$e(a(x)))return[];if(!d(x,"extraction"))return[];let A=Ye(a(x));return A===null?[]:[{entry:x,rank:A}]}).sort((x,A)=>x.rank-A.rank||(x.entry.size??0)-(A.entry.size??0)),E=y;for(let{entry:x}of S){if(E>=v.conventionImport.extractionFiles){c(x,"allowance");continue}let A=l.length;k(x),l.length>A&&E++}}if(g&&s.files){let S=Ae(r,{entries:e,selected:t.filter(E=>Object.hasOwn(n,E.path)),files:s.files,root:o});for(let E of S.paths)Object.hasOwn(n,E)||(l.push(E),n[E]=t.find(x=>x.path===E).ref);for(let E of S.refused)u.set(E.path,E)}return{...Ee(r)&&P.some(S=>!Object.hasOwn(n,S.path))?{definitionsOmitted:!0}:{},selectedPaths:l,shaByPath:n,treeListing:t.slice(0,Br).map(S=>S.path),needsExtraction:R,refused:[...u.values()]}}function Ae(r,e){let o=new Set(e.selected.map(n=>n.path)),s=X(r,e.entries.map(n=>n.path),e.root).files.filter(n=>n.role==="skill"&&o.has(n.path)).map(n=>n.path),t=ft(r,{skillPaths:s,paths:e.entries.map(n=>n.path),files:e.files,sizes:new Map(e.entries.map(n=>[n.path,n.size])),selected:e.selected,root:e.root,admission:e.admission,referencePaths:e.referencePaths});return{paths:[...new Set(t?.flatMap(n=>n.files.map(l=>l.path))??[])],refused:t?.flatMap(n=>n.refused)??[]}}var Xt=(r,e)=>{let o=Wt(e.settings,r,e.dir??void 0,{mode:e.mode});return{strength:"partial",wants:o.selectedPaths,state:{needsExtraction:o.needsExtraction,treeListing:o.treeListing,shaByPath:o.shaByPath,refused:o.refused,...o.definitionsOmitted?{definitionsOmitted:!0}:{}}}};var Jt=["marker","code-scan","conventions"];var Tr={marker:$t,"code-scan":Gt,conventions:Xt};function Se(r,e,o,s,t=Tr){let n={...o,settings:r},l={readers:[]};for(let u of Jt)if(!(s&&!s.includes(u)))try{let g=t[u]?.(e,n);g&&l.readers.push({id:u,claim:g,done:!1})}catch{}return l}function Ir(r){return{readers:r.readers.map(({id:e,done:o})=>({id:e,done:o}))}}function _e(r){let e=r.readers.find(({id:o})=>o==="conventions").claim;return{selectedPaths:e.wants,...e.state}}function Me(r,e){let o={dir:e.root??null,mode:e.profile==="hosted-import"?e.mode??"all":"all",flags:e.profile==="hosted-import"?e.flags??ee(r):ee(r)};if(e.profile==="hosted-import"){let n=Se(r,e.listing,o);return{profile:e.profile,...n,selection:_e(n)}}let s=e.listing.filter(n=>F(r,n,{purpose:"pointer",route:"github",root:e.root}).admitted),t=Se(r,s,o,["marker","code-scan"]);return{profile:e.profile,...t,listing:s,selection:e.selection??we(r,e.listing,e.root),context:o}}var G=20;function re(r,e,o,s){e.requestedPaths.push(...o);let t=ue(r,e.selected,o,s);e.selected=t.selected,e.refused.push(...t.refused)}function Pe(r,e,o){let s=r.hosted;if(!s)return;let t=new Set(e),n=r.selected.filter(l=>t.has(l.path));o==="code"?s.codePaths&&(s.codePaths=[...new Set([...s.codePaths,...n.map(l=>l.path)])]):s.weakCodeFallback&&(r.conventionPaths=[...new Set([...r.conventionPaths,...n.map(l=>l.path)])],s.fallback={...s.fallback,selectedPaths:[...new Set([...s.fallback.selectedPaths,...n.map(l=>l.path)])],shaByPath:{...s.fallback.shaByPath,...Object.fromEntries(n.map(l=>[l.path,l.ref]))}})}function be(r,e){let o=new Set(r.conventionPaths);if(r.decision.kind==="settled"&&r.decision.scanPaths&&r.markerKind&&r.markerKind!=="bare")for(let t of r.selected)o.add(t.path);let s=new Map(e.map(t=>[t.path,t]));for(let t of r.selected)o.has(t.path)&&!s.has(t.path)&&s.set(t.path,t);r.selected=[...s.values()],r.cursor=0,r.hosted&&(r.hosted.codeMode=!0,r.hosted.needsExtraction=!1)}function Yt(r,e=Pt(r.ranked,r.scan)){return e.agents.length>0}function Qt(r,e){if(r.hosted&&(r.hosted.codePaths=e.map(s=>s.path)),!r.hosted?.weakCodeFallback||r.hosted.codeMode||Yt(r)){be(r,e);return}let o=new Map(r.selected.map(s=>[s.path,s]));for(let s of e)o.has(s.path)||o.set(s.path,s);r.selected=[...o.values()],r.cursor=0}function Vt(r,e){let o=r.hosted;if(!o?.weakCodeFallback||!o.codePaths||r.markerKind&&r.markerKind!=="bare")return;let s=new Map([...r.entries,...r.selected].map(n=>[n.path,n]));Yt(r,e)?be(r,o.codePaths.map(n=>s.get(n))):(r.selected=o.fallback.selectedPaths.map(n=>s.get(n)),r.cursor=0,o.codeMode=!1,o.needsExtraction=o.fallback.needsExtraction);let t=new Set(r.selected.map(n=>n.path));r.files=Object.fromEntries(Object.entries(r.files).filter(([n])=>t.has(n)))}function Be(r,e){if(!I(r))return;let o=new Set(e.entries.map(n=>n.path)),s=Object.fromEntries(Object.entries(e.files).filter(([n])=>e.selected.some(l=>l.path===n&&l.readBytes===void 0))),t=new Set(de(r,[...o],s));for(let[n,l]of Object.entries(e.files)){let u=F(r,{path:n,text:l},{...e.admission,purpose:"override",route:"github",root:e.root,listing:o,managedFiles:e.files});(!u.admitted||t.has(n))&&(delete e.files[n],e.refused.push({path:n,reason:u.admitted?"unreadable":u.reason}))}}function N(r,e,o){Be(r,e);let s=e.selected.filter(u=>e.files[u.path]!==void 0),t=new Set(s.filter(u=>u.readBytes===void 0).map(u=>u.path)),n=new Set(e.requestedPaths),l=B(e.selectionRefused.filter(u=>!n.has(u.path)),e.refused).filter(u=>!t.has(u.path));return{state:e,requestedReads:o,files:e.files,settled:s,refused:l,treeTruncated:e.treeTruncated}}async function Zt(r,e,o){e.manifestReadPaths??=e.selected.slice(0,e.cursor).filter(a=>a.readBytes===void 0).map(a=>a.path);let s=new Set(e.selected.filter(a=>a.readBytes===void 0).map(a=>a.path)),t=Object.fromEntries(Object.entries(e.files).filter(([a])=>s.has(a))),n=new Map(e.entries.map(a=>[a.path,a.size])),l=new Map(Object.entries(e.files).map(([a,c])=>[a,Buffer.byteLength(c)]));for(let[a,c]of Object.entries(t))n.set(a,Buffer.byteLength(c));let u=Y(r,e.ranked,n,l,{files:t,root:e.root}),g=new Set(e.manifestReadPaths),h=u.paths.filter(a=>t[a]===void 0&&!g.has(a)),p=new Map(e.selected.filter(a=>a.readBytes!==void 0).map(a=>[a.path,a]));e.requestedPaths.push(...h.filter(a=>p.has(a))),re(r,e,h.filter(a=>!p.has(a)),e.entries);let f=new Set(h),w=new Map(e.entries.map(a=>[a.path,a])),b=e.selected.filter(a=>f.has(a.path)).map(a=>p.has(a.path)?w.get(a.path):a).slice(0,G);if(b.length){let a=await L(b,4,async y=>{let R=F(r,y,{...e.admission,purpose:"pointer",route:"github",root:e.root});return R.admitted?o(y):(e.refused.push({path:y.path,reason:R.reason}),null)});e.manifestReadPaths=[...e.manifestReadPaths,...b.map(y=>y.path)];let c=new Map(n);b.forEach((y,R)=>{a[R]!==null&&c.set(y.path,Buffer.byteLength(a[R]))});let d=new Map(b.filter((y,R)=>p.has(y.path)&&a[R]!==null).map(y=>[y.path,l.get(y.path)])),k=Y(r,e.ranked,c,l,{files:t,root:e.root,replacementBytes:d}),P=new Set(k.paths);b.forEach((y,R)=>{a[R]!==null&&(P.has(y.path)?(e.files[y.path]=a[R],e.selected=e.selected.map(S=>S.path===y.path?y:S)):e.refused.push(k.refused.find(S=>S.path===y.path)??{path:y.path,reason:"total"}))});return}let i=new Map((u.manifests??[]).map(a=>{let d=a.files.filter(k=>t[k.path]===void 0).map(k=>e.refused.find(P=>P.path===k.path)??{path:k.path,reason:"missing"});return[a.agentId,{...a,files:a.files.filter(k=>t[k.path]!==void 0),refused:[...a.refused,...d]}]})),m=a=>{let c=i.get(Ve(a.prompt));return c?{...a,manifest:c}:a};e.ranked={...e.ranked,strong:e.ranked.strong.map(m),possible:e.ranked.possible.map(m)},Pe(e,[...i.values()].flatMap(a=>a.files.map(c=>c.path)),"code"),e.refused.push(...[...i.values()].flatMap(wt)),e.phase="done"}async function er(r,e,o){if(!I(r))return!1;let s=Ge(r,e.entries.map(f=>f.path));if(!s.length)return!1;let t=new Set(s.flatMap(f=>f.agents)),n=new Map(e.selected.map(f=>[f.path,f])),l=new Set(e.selected.filter(f=>f.readBytes===void 0&&e.files[f.path]!==void 0).map(f=>f.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 u=new Set([...e.managedReadPaths,...l]),g=e.entries.filter(f=>t.has(f.path)&&n.has(f.path)&&!u.has(f.path)),h=g.slice(0,G);if(!h.length)return!1;let p=await L(h,4,async f=>{let w=F(r,f,{...e.admission,purpose:"pointer",route:"github",root:e.root});return w.admitted?o(f):(e.refused.push({path:f.path,reason:w.reason}),null)});if(h.forEach((f,w)=>{p[w]!==null&&(e.files[f.path]=p[w],e.selected=e.selected.map(b=>b.path===f.path?f:b))}),e.managedReadPaths.push(...h.map(f=>f.path)),g.length>h.length){for(let f of Object.keys(e.files))!t.has(f)&&s.some(w=>C(f,w.folder)!==null)&&delete e.files[f];e.cursor=0,(e.phase==="done"||e.phase==="manifest")&&(e.phase="files")}return!0}function tr(r,e){let{plan:o,entries:s}=e,t=o.profile==="local-analysis"?o.context.dir??"":e.root??"",n=o.readers.find(p=>p.id==="marker")?.claim.wants[0],l=o.readers.some(p=>p.id==="code-scan"),u=new Map(s.map(p=>[p.path,p])),g=o.profile==="local-analysis"?o.selection.selected:o.selection.selectedPaths.flatMap(p=>u.has(p)?[u.get(p)]:[]),h=St(r)?U(r,{phase:"start",root:t,paths:s.map(p=>p.path),scanFlag:!!n||l}):void 0;return{version:1,profile:o.profile,root:t,entries:s,selected:[...g],conventionPaths:o.profile==="hosted-import"?X(r,s.map(p=>p.path),t).files.filter(p=>p.role!=="reference").map(p=>p.path):[],...e.admission?{admission:e.admission}:{},selectionRefused:o.selection.refused,requestedPaths:[],refused:[],files:{},cursor:0,treeTruncated:e.treeTruncated??!1,...o.profile==="hosted-import"?{hosted:{fallback:structuredClone(o.selection),weakCodeFallback:r.CF_IMPORT_WEAK_CODE_FALLBACK!=="0",codeMode:!1,needsExtraction:o.selection.needsExtraction}}:{},decision:h??(n?{kind:"marker",markerPath:n,scanIfBare:l}:{kind:"settled",markerPath:null,markerKind:null,scan:l}),phase:n?"marker":l?"scan":"files"}}function Lr(r,e){e.ranked??=me(r,e.scan,new Map);let o=Y(r,e.ranked,vt(e.scan.plan),new Map),s=[...o.refused,...e.ranked.skippedFiles??[]];if(e.requestedPaths.push(...s.map(t=>t.path)),e.refused.push(...s),e.profile==="hosted-import"&&o.paths.length){let t=ue(r,[],o.paths,e.scan.plan);e.refused.push(...t.refused),Qt(e,t.selected)}else re(r,e,o.paths,e.scan.plan);e.phase=e.selected.length?"files":"done"}async function rr(r,e,o){if(e.version!==1)throw new Error("unsupported-import-checkpoint");let s=e.profile==="hosted-import"?{...r,CF_IMPORT_CALLS:"0"}:r,t={...e,selected:[...e.selected],files:{...e.files},requestedPaths:[...e.requestedPaths],refused:[...e.refused],...e.hosted?{hosted:{...e.hosted}}:{},...e.managedReadPaths?{managedReadPaths:[...e.managedReadPaths]}:{}},n=new Set(t.entries.map(i=>i.path)),l=Object.fromEntries(Object.entries(t.files).filter(([i])=>t.selected.some(m=>m.path===i&&m.readBytes===void 0))),u=new Set(de(s,[...n],l)),g=[],h=new Set,p=async i=>{if(u.has(i.path)||t.managedReadPaths?.includes(i.path)&&t.files[i.path]===void 0)return t.refused.push({path:i.path,reason:"unreadable"}),null;g.push(i);try{let m=await o.read(i);if(m!==null){if(h.has(i.path)){let a=F(s,{path:i.path,size:Buffer.byteLength(m),text:m},{...t.admission,purpose:"skill",route:"github",root:t.root,listing:n,managedFiles:t.files});if(!a.admitted)return t.refused.push({path:i.path,reason:a.reason}),null}if(I(s)||ne(s)){let a=F(s,{path:i.path,text:m},{...t.admission,purpose:"override",route:"github",root:t.root,listing:n,managedFiles:t.files});if(!a.admitted)return t.refused.push({path:i.path,reason:a.reason}),null}if(t.phase==="manifest"){let a=F(s,{path:i.path,size:Buffer.byteLength(m)},{...t.admission,purpose:"pointer",route:"github",root:t.root});if(!a.admitted)return t.refused.push({path:i.path,reason:a.reason}),null}return m}}catch(m){if(m instanceof Xe&&(m.reason==="secret-content"||I(s)||h.has(i.path)))return t.refused.push({path:i.path,reason:m.reason}),null;if(t.profile==="hosted-import"&&!h.has(i.path))throw m}return t.refused.push({path:i.path,reason:"unreadable"}),null};if(await er(s,t,p))return N(s,t,g);if(Be(s,t),t.phase==="done")return o.resolvedCode&&Vt(t,o.resolvedCode),N(s,t,g);if(t.phase==="manifest")return await Zt(s,t,p),N(s,t,g);if(t.phase==="marker"&&t.decision.kind==="marker"){let i=t.decision,m=i.markerPath,a=t.entries.find(d=>d.path===m);if(t.profile==="hosted-import"){let d=F(s,a,{purpose:"pointer",route:"github",root:t.root});if(!d.admitted)return t.refused.push({path:m,reason:d.reason}),t.decision={kind:"settled",markerPath:null,markerKind:null,scan:i.scanIfBare},t.phase=i.scanIfBare?"scan":"files",N(s,t,g)}re(s,t,[m],t.entries);let c=await p(a);if(c!==null&&(t.files[m]=c),t.decision=U(s,{phase:"read",pending:i,text:c}),t.markerPath=m,t.markerKind=t.decision.markerKind,t.markerKind!=="bare"){let d=t.profile==="hosted-import"?await o.listing():{entries:t.entries,truncated:!1};t.treeTruncated||=d.truncated;let k=await Ct(s,{config:ut(c).config,markerDir:m.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()=>d.entries});t.requestedPaths.push(...k.requestedPaths),t.refused=k.refused,t.profile==="hosted-import"?be(t,k.selected??[]):k.selected&&(t.selected=k.selected)}if(t.phase=t.decision.scan?"scan":"files",t.profile!=="hosted-import"||t.markerKind!=="bare"||t.decision.scan)return N(s,t,g)}if(t.phase==="scan"){if(!t.scan){let i=xt(s,t.entries,t.root,!0,t.decision.kind==="settled"?t.decision.scanPaths:void 0);t.scan=i.state,t.refused.push(...i.refused)}if(!te(t.scan)){let i=await Ot(s,t.scan,p,{modelReader:!1,alreadyRead:new Map,size:{batch:yt,parallel:4}});t.scan=i.scan,i.selection&&(t.ranked=i.selection.ranked)}return te(t.scan)&&Lr(s,t),N(s,t,g)}xe(s)&&(h=new Set(t.skillReferencePaths));let f=t.selected.slice(t.cursor,t.cursor+G),w=f.filter(i=>t.files[i.path]===void 0),b=await L(w,4,p);if(w.forEach((i,m)=>{b[m]!==null&&(t.files[i.path]=b[m])}),t.cursor+=f.length,xe(s)){let i=Object.fromEntries(Object.entries(t.files).filter(([P])=>t.selected.some(y=>y.path===P&&y.readBytes===void 0))),m=Ae(s,{entries:t.entries,selected:t.selected,files:i,root:t.root,admission:t.admission,referencePaths:t.skillReferencePaths});t.refused=B(t.refused,m.refused);for(let P of m.refused)h.has(P.path)&&delete t.files[P.path];if(t.cursor<t.selected.length)return N(s,t,g);let a=new Map(t.selected.map(P=>[P.path,P])),c=m.paths.filter(P=>!a.has(P)||a.get(P).readBytes!==void 0),d=new Set(c.filter(P=>a.has(P)));t.cursor-=t.selected.slice(0,t.cursor).filter(P=>d.has(P.path)).length,t.selected=t.selected.filter(P=>!d.has(P.path));for(let P of d)delete t.files[P];t.requestedPaths.push(...c),c.length&&(t.skillReferencePaths=[...t.skillReferencePaths??[],...c]);let k=new Map(t.entries.map(P=>[P.path,P]));t.selected.push(...c.map(P=>{let y=k.get(P);return{path:P,size:y.size,ref:y.ref}})),Pe(t,c,"fallback")}return t.cursor>=t.selected.length&&(t.phase=pe(s)&&t.ranked?"manifest":"done"),N(s,t,g)}async function or(r,e){let o=tr(r,e),s;do s=await rr(r,o,{listing:async()=>({entries:e.entries,truncated:!1}),read:e.read}),o=s.state;while(o.phase!=="done");let t={};return o.markerPath!==void 0&&(t.markerPath=o.markerPath,t.markerKind=o.markerKind),o.ranked!==void 0&&(t.ranked=o.ranked,t.scan=o.scan),{files:s.files,settled:s.settled,skippedFiles:s.refused,...t}}async function Te(r,e){let o=Me(r,{profile:"local-analysis",listing:e.entries,selection:e.selection}),{files:s,settled:t,skippedFiles:n,...l}=await or(r,{entries:e.entries,read:e.read,admission:e.admission,plan:o}),u=s,g=t,h=n,p=Q({key:e.repoKey,files:u,...l},o.context.flags,void 0,{markerPolicy:"any-read"}),{selection:f}=o,w;if(mt(r)&&e.repository){let a=await ht(r,{selected:{files:u,listedPaths:e.entries.map(d=>d.path),fallbackName:bt(e),skills:!0},selection:f,codeAgentsFound:(p?.resolved?.agents.length??0)>0,port:e.repository}),c=new Set(Object.keys(u).map(d=>W(d,a.root)));if(u=a.files,f=a.selection,w=a.root,w!==void 0){h=h.map(k=>({...k,path:W(k.path,w)})),g=g.map(k=>({...k,path:W(k.path,w)}));let d=new Set(g.map(k=>k.path));g.push(...f.selected.filter(k=>!d.has(k.path)&&Object.hasOwn(u,k.path)))}h=B(h,a.skippedFiles).filter(d=>c.has(d.path)||!Object.hasOwn(u,d.path))}let b={repoKey:e.repoKey,files:u,listedPaths:e.entries.map(a=>W(a.path,w)),...w!==void 0?{root:w}:{},forLocal:!0,code:p},i=Z(r,V(r,b)),m=f.readingNotes?$(r,f.readingNotes,g):f.skippedNote;return{...i,files:u,...w!==void 0?{root:w}:{},skippedFiles:h,warnings:[...new Set([...i.warnings,...m?[m]:[],...ae(h)])],selection:f}}var Nr=new Set;function jr(r,e={}){let o=ze(e.dir),s=e.limits??v.archive,t=e.listing??Nr,n={commit:null,files:new Map,skipped:[]},l=new Set,u=0,g=0;function h(i){let m=i.replace(/\/$/,"").split("/");return!i.startsWith("/")&&!i.includes("\\")&&!/^[a-z]:/i.test(i)&&!m.some(a=>a===".."||a==="."||!a)}function p(i,m,a,c=t){if(!a||!h(i)||!Number.isSafeInteger(m)||m<0)return"refused";let d=F(r,{path:i,size:m},{purpose:"archive",route:"github",root:o});return d.admitted?e.exampleFolders?.some(k=>i.startsWith(k))||qe(i,{root:o,listing:c})?"example":null:d.reason==="excluded"&&Ue(r,i,o)?"example":d.reason==="excluded"||d.reason==="wrong-type"?"excluded":"refused"}function f(i,m){l.has(i)||(l.add(i),n.skipped.push({path:i,reason:m}))}function w(i,m=t){let a=i.split("/");for(let c=1;c<=a.length;c++){let d=a.slice(0,c).join("/");if(d===o||o.startsWith(`${d}/`))continue;if(C(d,o)===null)return!1;let k=p(`${d}/`,0,!0,m);if(k)return f(`${d}/`,k),!1}return!0}function b(i,m,a=!0){if(C(i,o)===null)return!1;if(!h(i))return f(i,"refused"),!1;let c=i.split("/");if(c.length>1&&!w(c.slice(0,-1).join("/")))return!1;let d=p(i,m,a);return d?(f(i,d),!1):g>=s.files||m>s.bytes-u?(f(i,"over-limit"),!1):(u+=m,g++,!0)}return{result:n,accept:b,enterFolder:w}}var Kr=new Set(ve);function Hr(r,e){for(let s of[...Object.keys(e.set),...e.clear])if(!Kr.has(s))throw new Error(`Unknown analysis field: ${s}`);let o={...r,...e.set};for(let s of e.clear)o[s]=void 0;return o}function sr(r){return r.CF_MODEL_READER!=="0"}async function Dr(r,e,o,s){o=z(r,o);let t=structuredClone(e);for(t.files??={},t.cursor=0;;){let n=await ge(r,t,o,s);if(n){t=n;continue}let l=t.selected??[];if((t.cursor??0)>=l.length)return t;let u=l.slice(t.cursor).filter(p=>!Object.hasOwn(t.files,p.path)),g=[],h=await L(u,4,async p=>{try{return{path:p.path,text:await he(p,f=>o.read(f),g,t.refused)}}catch(f){return{error:f}}});for(let p of h){if("error"in p)throw p.error;p.text!==null&&(t.files[p.path]=p.text)}g.length&&(t.refused=B(t.refused,g)),t.cursor=l.length}}async function nr(r,e,o,s){let{codeFindingNote:t}=kt(s),n={deriveBytes:0,codeEvidence:[]};if(!e.findingQuality?.config.switches.codeInputs||!e.projectAgents?.enabled)return n;let l=e.projectAgents,u=(e.repos??[]).filter(c=>[...l.byRepo[c.key]??[],...l.codeByRepo?.[c.key]??[]].some(d=>d.codeInputsJson&&(d.codeInputsJson.tools.length||d.codeInputsJson.contextInputs.length))),h=(await L(u,1,async c=>{try{let d=o.find(k=>k.repoKey===c.key);if(!d)throw new Error("Source reader is missing.");return{repo:await Dr(r,c,d,e.modelReader??!1)}}catch(d){return{error:d}}})).map(c=>{if("error"in c)throw c.error;return c.repo}),p=h.map(c=>{let d=ke(r,c,q(r,e),e.modelReader,l);return Object.assign(c.files,d.virtualFiles),d.fragment}),f=Object.fromEntries(h.map(c=>[c.key,c.files??{}])),b=Bt({...e,repos:h,mapped:p}).findingQuality?.codeEvidence?.filter(c=>Object.keys(c.input.files).length)??[];if(!b.length)return n;let i=b.map(c=>({repo:c.repo,unitKey:c.unitKey,enabled:!0,inputs:[c.input],files:f[c.repo]}));return{deriveBytes:[...new Map(b.flatMap(c=>Object.entries(c.input.files).map(([d,k])=>[JSON.stringify([c.repo,d]),{path:d,text:k}]))).values()].reduce((c,{path:d,text:k})=>c+Buffer.byteLength(`### ${d}
1
+ import{a as pe,b as $e,c as Xe,d as Je,e as Ge,f as Qe,h as X,i as tr,j as nr}from"./chunks/DLPVYWHZ.js";import{$ as xe,Aa as dr,Ca as lr,M as We,N as Ye,O as Ve,P as Ze,Q as er,R as rr,S as me,T as ue,U as M,V as N,W as he,X as ge,Y as B,_ as ye,aa as J,ba as Se,ca as Ee,da as Ae,ea as G,fa as or,ga as we,ha as be,ia as Ce,ja as _e,ka as Re,la as Fe,na as sr,ua as ir,wa as cr,ya as ar}from"./chunks/QFY6A3MS.js";import{a as $}from"./chunks/OPMA32A6.js";import"./chunks/STI4JE7L.js";import"./chunks/N7U5N42V.js";import{a as ze,e as le,l as qe,m as Ue}from"./chunks/6QY5BV5B.js";import"./chunks/Y7JGSUOA.js";import"./chunks/3MTXB4MK.js";import"./chunks/K2GNDX3W.js";import"./chunks/HTLIRVP7.js";import{a as U}from"./chunks/QDYMR6KS.js";import{b as Ke}from"./chunks/E7TFIHC5.js";import"./chunks/4F6ZIHXU.js";import"./chunks/M6HYSTQD.js";import{a as b,d as fe}from"./chunks/4H23CSUM.js";import"./chunks/VGYWI4X2.js";import"./chunks/57M4OQJM.js";import"./chunks/J4AXGE5W.js";import{a as Ne,b as Be,c as Pe,d as je}from"./chunks/PECX3OXB.js";import"./chunks/SVMEWGD3.js";import{d as de}from"./chunks/FOKDE64Y.js";import"./chunks/IBCFGUHI.js";import"./chunks/DZZBQDGO.js";import"./chunks/3JWEFCTJ.js";import{H as He}from"./chunks/377MLK4M.js";import{a as q}from"./chunks/326F4XNG.js";import{a as z,e as De}from"./chunks/ZTOVBAG7.js";import"./chunks/KTNA2KTN.js";import{b as I}from"./chunks/2PSNOSJ2.js";import"./chunks/KU5DINLW.js";import{A as re,Cb as ie,E as te,G as oe,Rb as ce,Wb as ae,n as ee,ra as k,ua as se,va as R,wa as O,yb as ne}from"./chunks/NIOS7U6C.js";import"./chunks/74FPPPIG.js";import"./chunks/5TATKWLG.js";import{b as W}from"./chunks/724WZMYW.js";import"./chunks/PYKAERZZ.js";import"./chunks/YUY436SM.js";import{a as Z,c as v}from"./chunks/C6X5GDG4.js";import"./chunks/5DGPLXYB.js";import"./chunks/6U2IR4XB.js";import{c as w}from"./chunks/MJGB25S5.js";import"./chunks/6B2HILSY.js";import{f as F,i as Y,n as V}from"./chunks/JKWTHRUR.js";import"./chunks/SKVEBOGA.js";import{a as Me,b as K}from"./chunks/3GUKUEEJ.js";import"./chunks/A7WJJMRY.js";import"./chunks/KWECQJ6X.js";import"./chunks/FSLWD2PE.js";import"./chunks/X7WZAA7S.js";var fr=new Set;function pr(o,e={}){let n=Z(e.dir),a=e.limits??re.archive,t=e.listing??fr,c={commit:null,files:new Map,skipped:[]},m=new Set,g=0,h=0;function u(i){let l=i.replace(/\/$/,"").split("/");return!i.startsWith("/")&&!i.includes("\\")&&!/^[a-z]:/i.test(i)&&!l.some(p=>p===".."||p==="."||!p)}function d(i,l,p,r=t){if(!p||!u(i)||!Number.isSafeInteger(l)||l<0)return"refused";let s=k(o,{path:i,size:l},{purpose:"archive",route:"github",root:n});return s.admitted?e.exampleFolders?.some(y=>i.startsWith(y))||oe(i,{root:n,listing:r})?"example":null:s.reason==="excluded"&&te(o,i,n)?"example":s.reason==="excluded"||s.reason==="wrong-type"?"excluded":"refused"}function f(i,l){m.has(i)||(m.add(i),c.skipped.push({path:i,reason:l}))}function S(i,l=t){let p=i.split("/");for(let r=1;r<=p.length;r++){let s=p.slice(0,r).join("/");if(s===n||n.startsWith(`${s}/`))continue;if(v(s,n)===null)return!1;let y=d(`${s}/`,0,!0,l);if(y)return f(`${s}/`,y),!1}return!0}function E(i,l,p=!0){if(v(i,n)===null)return!1;if(!u(i))return f(i,"refused"),!1;let r=i.split("/");if(r.length>1&&!S(r.slice(0,-1).join("/")))return!1;let s=d(i,l,p);return s?(f(i,s),!1):h>=a.files||l>a.bytes-g?(f(i,"over-limit"),!1):(g+=l,h++,!0)}return{result:c,accept:E,enterFolder:S}}function ve(o){return o.CF_MODEL_READER!=="0"}async function mr(o,e,n,a){n=R(o,n);let t=structuredClone(e);for(t.files??={},t.cursor=0;;){let c=await B(o,t,n,a);if(c){t=c;continue}let m=t.selected??[];if((t.cursor??0)>=m.length)return t;let g=m.slice(t.cursor).filter(d=>!Object.hasOwn(t.files,d.path)),h=[],u=await q(g,4,async d=>{try{return{path:d.path,text:await M(d,f=>n.read(f),h,t.refused)}}catch(f){return{error:f}}});for(let d of u){if("error"in d)throw d.error;d.text!==null&&(t.files[d.path]=d.text)}h.length&&(t.refused=I(t.refused,h)),t.cursor=m.length}}async function ke(o,e,n,a){let{codeFindingNote:t}=le(a),c={deriveBytes:0,codeEvidence:[]};if(!e.findingQuality?.config.switches.codeInputs||!e.projectAgents?.enabled)return c;let m=e.projectAgents,g=(e.repos??[]).filter(r=>[...m.byRepo[r.key]??[],...m.codeByRepo?.[r.key]??[]].some(s=>s.codeInputsJson&&(s.codeInputsJson.tools.length||s.codeInputsJson.contextInputs.length))),u=(await q(g,1,async r=>{try{let s=n.find(y=>y.repoKey===r.key);if(!s)throw new Error("Source reader is missing.");return{repo:await mr(o,r,s,e.modelReader??!1)}}catch(s){return{error:s}}})).map(r=>{if("error"in r)throw r.error;return r.repo}),d=u.map(r=>{let s=ye(o,r,N(o,e),e.modelReader,m);return Object.assign(r.files,s.virtualFiles),s.fragment}),f=Object.fromEntries(u.map(r=>[r.key,r.files??{}])),E=xe({...e,repos:u,mapped:d}).findingQuality?.codeEvidence?.filter(r=>Object.keys(r.input.files).length)??[];if(!E.length)return c;let i=E.map(r=>({repo:r.repo,unitKey:r.unitKey,enabled:!0,inputs:[r.input],files:f[r.repo]}));return{deriveBytes:[...new Map(E.flatMap(r=>Object.entries(r.input.files).map(([s,y])=>[JSON.stringify([r.repo,s]),{path:s,text:y}]))).values()].reduce((r,{path:s,text:y})=>r+Buffer.byteLength(`### ${s}
2
2
  \`\`\`
3
- ${ot(k)}
3
+ ${ae(y)}
4
4
  \`\`\`
5
5
 
6
- `),0)+Buffer.byteLength(t(b.flatMap(c=>c.input.sources))),codeEvidence:i}}function cr(r,e,o,s,t){let n=e.analysisFlags,l=[],u=new Set,g=0,h=0;for(let d of e.repos??[]){h+=(d.selected??[]).reduce((P,y)=>P+(y.readBytes??y.size),0),l.push(...(d.selected??[]).map(P=>({path:C(P.path,d.root)??P.path,size:P.size})));let k=et(e.projectAgents,d.key,{nodes:[],edges:[],warnings:[]},t);for(let[P,y]of Object.entries(k.files)){let R=at(y).length;g+=R,l.push({path:P,size:R}),u.add(P)}}g+=h;let p=Nt(l,n.multiPass,u),f=p>1?24:rt,w=(u.size?g:Math.min(g,15e4))+s.deriveBytes,b=Fe("derive",r,o),i=Array.from({length:p},(d,k)=>_(r,{template:b},p>1?`Derive findings (part ${k+1} of ${p})`:"Derive findings",M.generate,K(w+jt(g,p))+4e3,Ke)),m=n.multiPass&&u.size?h:Math.min(h,15e4);i.push(_(r,{template:"derive-structure"},"Structural pass",M.generate,K(m)+4e3,12e3));let a=Math.ceil(f/He)*(1+De);i.push(_(r,{template:"scope-findings"},"Scope check",o.switches.enabled?o.models.scope:M.mechanical,a*(4e3+K(s.scopeBytes)),a*1e3));let c=st(r,f,n.findingCheck??!0,Fe("check",r,o),o.switches.fullContext?"whole-file":"legacy");return c&&i.push(c),(n.sourceNotes??!0)&&i.push(_(r,{template:"explain-sources"},"Explain sources",Tt,K(Lt)*f,It*f)),e.codeAgents?.model&&e.repos?.some(d=>d.scanNeeded)&&i.push(_(r,{template:"judge-code-prompt"},"Check possible agents in code",M.mechanical,6*3e3,1200)),i.push(...Kt(Re(r),r)),i}var $r=async(r,e)=>{if(e.progress.assertHeld(),e.progress.signal?.throwIfAborted(),!e.model)throw new ye("llm","Analysis needs a live model; no provider key is configured.");if(!e.readers.length)throw new ye("not_found","This project has no analyzable repository.");let o=r.execution.preparation;if(!o)throw new Error("Preparation options are required for estimation.");let{state:s,settings:t}=r;await H(t,s,e.readers),await e.context.refreshStructureParts?.().catch(()=>{});let n=D(await e.instructions()),l=J(n),u=n.bundleText("model-reader-runtime-prompt"),g=[...s.warnings??[]],h=q(t,s),p=s.modelReader??sr(t),f=s.analysisFlags?se(t,s):Le(t),w=s.findingQuality??{config:o.qualityConfig},b=await Ze(t,s.projectAgents,e.context.loadProjectAgents,void 0,w.config.switches.codeInputs),i=[],m=[],a=e.readers.map(O=>z(t,O));for(let O of a){e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let oe=await O.head(),Ie=await O.list(),j=we(t,Ie,O.root);!j.readingNotes&&j.skippedNote&&g.push(`${O.repoKey}: ${j.skippedNote}`),m.push({key:O.repoKey,kind:"github",root:O.root,selected:j.selected}),i.push({key:O.repoKey,...O.source??{kind:O.repoKey.startsWith("local:")?"fs":"github"},headSha:oe.sha,branch:oe.branch,selected:j.selected,...j.readingNotes?{sourceReadNotes:j.readingNotes}:{},cursor:0,files:{},...O.root?{root:O.root}:{},...At(t,Ie,j.selected,O.root,h,p)})}let c={...s,repos:i,projectAgents:b,codeAgents:h,modelReader:p,analysisFlags:f,findingQuality:w};await H(t,c,a);let d=await nr(t,c,a,n),{sources:k,files:P}=Ce({qualityConfig:w.config,codeEvidence:d.codeEvidence}),y=l.enrichRequestInputs("scope-findings",{codeSources:k,codeFiles:P},t),R=Buffer.byteLength(String(y.code))+Math.max(0,Buffer.byteLength(String(y.system))-Buffer.byteLength(l.RULE)),S=[...o.uploadReadingAllowance?[o.uploadReadingAllowance]:[],...cr(t,{...c,repos:m},w.config,{deriveBytes:d.deriveBytes,scopeBytes:R},u)],E=await e.context.loadOpenStructures?.()??[],x=(await e.context.loadPendingRechecks?.().catch(()=>[])??[]).reduce((O,oe)=>O+oe.children.length,0);x&&S.push(_(t,{template:"structure-recheck"},"Post-merge re-check",M.mechanical,x*3e3,x*300));let A=await e.context.chatFindingCount?.().catch(()=>(e.progress.log({level:"warn",code:"chat.count_failed"}),0))??0;A&&S.push(_(t,{},"Re-check chat findings",M.mechanical,A*3e3,A*300));let T=ie(S,o.capUsd);return ce(T,e.progress.log),{next:o.confirmPrice?"awaiting_confirm":"fetching_files",clear:[],estimate:T,set:{repos:i,warnings:g,openStructures:E,codeAgents:h,modelReader:p,analysisFlags:f,projectAgents:b,findingQuality:w,...f.splitCheck?{splitEstimateBase:T}:{}}}};var Gr=async({state:r,settings:e},o)=>{o.progress.assertHeld(),o.progress.signal?.throwIfAborted();let s=[...r.repos??[]];await H(e,r,o.readers);let t=r.repoCursor??0;if(t>=s.length)return{next:"mapping",set:{repoCursor:0},clear:[]};let n=structuredClone(s[t]),l=o.readers.find(m=>m.repoKey===n.key);if(!l)throw new Error(`no reader for ${n.key}`);let u=z(e,l),g=await ge(e,n,u,r.modelReader??!1);if(g)return s[t]=g,{next:"fetching_files",set:{repos:s},clear:[]};let h=n.selected??[],p=n.cursor??0,f=h.slice(p,p+20),w={...n.files??{}},b=[];for(let m of f){if(o.progress.assertHeld(),o.progress.signal?.throwIfAborted(),w[m.path]!==void 0)continue;let a=await he(m,c=>u.read(c),b,n.refused);a!==null&&(w[m.path]=a)}b.length&&(n.refused=B(n.refused,b)),n.files=w,n.cursor=p+f.length,s[t]=n;let i=n.cursor>=h.length&&!_t(n);return{next:"fetching_files",set:{repos:s,repoCursor:i?t+1:t},clear:[]}};async function Wr(r,e){let o=e.admission?.exclusions?.length?e.entries.filter(n=>F(r,n,{purpose:"override",route:"github",...e.admission}).admitted):e.entries,s=I(r)?new Set(o.map(n=>n.path)):void 0,t=!e.admission?.exclusions?.length&&!ne(r)?e.read:n=>Je(r,n,e.read,{...e.admission,...s?{listing:s}:{}});return Te(r,{...e,entries:o,read:t})}async function Xr(r,e,o){let s=Object.entries(e).map(([n,l])=>({path:n,size:Buffer.byteLength(l),ref:n})),t=Et(r,s,o.root,!1,o.scanPaths);for(;!te(t);)t=await Ft(t,async n=>e[n.path]??null);return{scan:me(r,t),summary:Rt(t)}}async function dr(r,e,o){let{repoKey:s,root:t,codingGuides:n,forLocal:l}=o,u=o.flags??ee(r),g=Object.keys(e),h=U(r,{phase:"start",paths:g,root:t,scanFlag:u.scan}),p=h.kind==="marker"?U(r,{phase:"read",pending:h,text:e[h.markerPath]??null}):h,f=p.kind==="off"?null:p.markerPath,w=p.kind==="off"?null:p.markerKind;if(p.kind==="off"||!p.scan){let d=Q({key:s,files:e,markerPath:f,markerKind:w},u,void 0,{markerPolicy:"any-read"});return{...Z(r,V(r,{repoKey:s,files:e,root:t,codingGuides:n,forLocal:l,code:d})),scanned:!1,resolved:null}}let{scan:b,summary:i}=await Xr(r,e,{repoKey:s,root:t,scanPaths:p.scanPaths}),m=Q({key:s,files:e,ranked:b,scan:i,markerPath:f,markerKind:w},u,void 0,{markerPolicy:"any-read"});return{...Z(r,V(r,{repoKey:s,files:e,root:t,codingGuides:n,forLocal:l,code:m})),scanned:!0,resolved:m.resolved}}async function lr(r,e){let{state:o,settings:s}=r;if(!se(s,o).splitCheck||!o.splitEstimateBase)return{next:"inspecting",set:{repoCursor:0},clear:[]};let n=r.execution.preparation?.capUsd??o.splitEstimateBase.capUsd,l={...o.splitEstimateBase,capUsd:n};ce(l,e.progress.log);let u=Ht(s,o),g={next:"inspecting",set:{repoCursor:0,splitCheckPriced:!0,splitFindingsPriced:!0},clear:["splitEstimateBase"]};if(!u.length)return g;let h=J(D(await e.instructions())),p=u.reduce((m,{inventory:a})=>m+K(Buffer.byteLength(zt({tools:h},{...a,findings:[]}).prompt))+K(h.SHAPE_FINDINGS_INPUT_BYTES),0),f=l.lines.find(m=>m.label==="Scope check"),w=_(s,{template:"scope-findings"},"Scope check",M.mechanical,(f?.inputTokens??0)+u.length*qt,(f?.outputTokens??0)+u.length*Ut),b=l.lines.map(m=>m.label==="Scope check"?w:m);f||b.push(w),b.push(_(s,{template:"derive-shape"},"Split check",Dt,p,u.length*gt));let i=ie(b,n);return Ne(i)?(g.estimate=l,g.clear.push("splitCheckPriced","splitFindingsPriced"),delete g.set.splitCheckPriced,delete g.set.splitFindingsPriced,e.progress.log({level:"warn",code:"analysis.split_check_over_cap",counts:{totalUsd:i.totalUsd,capUsd:i.capUsd}}),g.set.warnings=[...o.warnings??[],je]):g.estimate=i,g}var Jr=async(r,e)=>{e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let{state:o,settings:s}=r,t=o.repos??[];await H(s,o,e.readers);let n=o.repoCursor??0;if(n>=t.length)return lr(r,e);let l=t[n],u=r.execution.forLocal,g=u?o.mapped?.[n]?{fragment:Oe(o,n),warnings:[]}:await dr(s,l.files??{},{repoKey:l.key,root:l.root,forLocal:!0}):void 0,h=g?(()=>{let i=tt(g.fragment,l.key);return{...i,warnings:[...g.warnings,...i.warnings]}})():ke(s,l,q(s,o),o.modelReader??!1,o.projectAgents,D(await e.instructions()).bundleText("model-reader-runtime-prompt")),p=!u&&l.sourceReadNotes?$(s,l.sourceReadNotes,l.selected??[],l.root):void 0,f=u?[]:ae((l.refused??[]).filter(i=>i.reason==="secret-content")),w="virtualFiles"in h?h.virtualFiles:void 0,b=[...o.mapped??[]];return b[n]=h.fragment,{next:"mapping",clear:[],set:{...w?{repos:t.map((i,m)=>m===n?{...i,files:{...i.files,...w}}:i)}:{},mapped:b,warnings:[...o.warnings??[],...p?[`${l.key}: ${p}`]:[],...f,...h.warnings,...Mt(l)],repoCursor:n+1}}};function Yr(r,e){let o=e?.findingHeadlineDiagnostics??(r.findingHeadlines?.version===2?r.findingHeadlines.diagnostics:r.findingHeadlineDiagnostics);return{set:{...o?{findingHeadlineDiagnostics:o}:{},repos:(r.repos??[]).map(s=>({...s,files:{},selected:[],scan:void 0,ranked:void 0})),...r.projectAgents?{projectAgents:{enabled:r.projectAgents.enabled,byRepo:{}}}:{}},clear:["passResults","sourceNotes","findingHeadlines","findingsRaw","structuresRaw","loadModes","rechecks","recheckedChangeIds","readPaths","inspectPlan","passFindings","codeChecks","newVerdicts",...r.shapeFindings?["shapeFindings"]:[]]}}export{ve as ANALYSIS_FIELDS,pr as FOLDER_TOO_LARGE_MESSAGE,br as InputBudgetError,M as MODELS,F as admitFile,Rr as analysisFieldsOf,vr as analysisRuntime,mr as analysisSizeLimits,Hr as applyAnalysisDelta,hr as assessAnalysisSize,Ar as buildAnalysisResult,Pr as buildRequest,D as createInstructionText,yr as createRequestRegistry,J as createRequestTools,Te as discoverLocalSources,Se as discoverReaders,$r as estimateStage,Wr as fetchLocalSources,Gr as fetchStage,Fr as fetchedPathsOf,Re as findingHeadlinesEnabled,Yr as finishAnalysis,_r as headlinesStage,Or as inspectStage,Jr as mapStage,gr as measureAnalysisSize,ur as parseAnalysisSize,Ir as planForJob,Me as planImport,fr as readFindingQualityConfig,Sr as render,jr as repoCollector,wr as resolveAgents,Oe as savedFragmentAt,xr as savedFragmentsOf,Ce as scopeCodeContext,_e as selectionOfPlan,kr as snapshotSettings,Cr as sourceNotesStage,Mr as structureStage,Er as trySavedFragmentAt};
6
+ `),0)+Buffer.byteLength(t(E.flatMap(r=>r.input.sources))),codeEvidence:i}}function Le(o,e,n,a,t){let c=e.analysisFlags,m=[],g=new Set,h=0,u=0;for(let s of e.repos??[]){u+=(s.selected??[]).reduce((A,_)=>A+(_.readBytes??_.size),0),m.push(...(s.selected??[]).map(A=>({path:v(A.path,s.root)??A.path,size:A.size})));let y=ie(e.projectAgents,s.key,{nodes:[],edges:[],warnings:[]},t);for(let[A,_]of Object.entries(y.files)){let T=de(_).length;h+=T,m.push({path:A,size:T}),g.add(A)}}h+=u;let d=_e(m,c.multiPass,g),f=d>1?24:ce,S=(g.size?h:Math.min(h,15e4))+a.deriveBytes,E=G("derive",o,n),i=Array.from({length:d},(s,y)=>w(o,{template:E},d>1?`Derive findings (part ${y+1} of ${d})`:"Derive findings",b.generate,F(S+Re(h,d))+4e3,fe)),l=c.multiPass&&g.size?u:Math.min(u,15e4);i.push(w(o,{template:"derive-structure"},"Structural pass",b.generate,F(l)+4e3,12e3));let p=Math.ceil(f/Se)*(1+Ee);i.push(w(o,{template:"scope-findings"},"Scope check",n.switches.enabled?n.models.scope:b.mechanical,p*(4e3+F(a.scopeBytes)),p*1e3));let r=Ae(o,f,c.findingCheck??!0,G("check",o,n),n.switches.fullContext?"whole-file":"legacy");return r&&i.push(r),(c.sourceNotes??!0)&&i.push(w(o,{template:"explain-sources"},"Explain sources",we,F(Ce)*f,be*f)),e.codeAgents?.model&&e.repos?.some(s=>s.scanNeeded)&&i.push(w(o,{template:"judge-code-prompt"},"Check possible agents in code",b.mechanical,6*3e3,1200)),i.push(...Fe(z(o),o)),i}var yr=async(o,e)=>{if(e.progress.assertHeld(),e.progress.signal?.throwIfAborted(),!e.model)throw new K("llm","Analysis needs a live model; no provider key is configured.");if(!e.readers.length)throw new K("not_found","This project has no analyzable repository.");let n=o.execution.preparation;if(!n)throw new Error("Preparation options are required for estimation.");let{state:a,settings:t}=o;await O(t,a,e.readers),await e.context.refreshStructureParts?.().catch(()=>{});let c=U(await e.instructions()),m=$(c),g=c.bundleText("model-reader-runtime-prompt"),h=[...a.warnings??[]],u=N(t,a),d=a.modelReader??ve(t),f=a.analysisFlags?ue(t,a):me(t),S=a.findingQuality??{config:n.qualityConfig},E=await ne(t,a.projectAgents,e.context.loadProjectAgents,void 0,S.config.switches.codeInputs),i=[],l=[],p=e.readers.map(x=>R(t,x));for(let x of p){e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let L=await x.head(),Q=await x.list(),C=pe(t,Q,x.root);!C.readingNotes&&C.skippedNote&&h.push(`${x.repoKey}: ${C.skippedNote}`),l.push({key:x.repoKey,kind:"github",root:x.root,selected:C.selected}),i.push({key:x.repoKey,...x.source??{kind:x.repoKey.startsWith("local:")?"fs":"github"},headSha:L.sha,branch:L.branch,selected:C.selected,...C.readingNotes?{sourceReadNotes:C.readingNotes}:{},cursor:0,files:{},...x.root?{root:x.root}:{},...he(t,Q,C.selected,x.root,u,d)})}let r={...a,repos:i,projectAgents:E,codeAgents:u,modelReader:d,analysisFlags:f,findingQuality:S};await O(t,r,p);let s=await ke(t,r,p,c),{sources:y,files:A}=J({qualityConfig:S.config,codeEvidence:s.codeEvidence}),_=m.enrichRequestInputs("scope-findings",{codeSources:y,codeFiles:A},t),T=Buffer.byteLength(String(_.code))+Math.max(0,Buffer.byteLength(String(_.system))-Buffer.byteLength(m.RULE)),P=[...n.uploadReadingAllowance?[n.uploadReadingAllowance]:[],...Le(t,{...r,repos:l},S.config,{deriveBytes:s.deriveBytes,scopeBytes:T},g)],Ie=await e.context.loadOpenStructures?.()??[],j=(await e.context.loadPendingRechecks?.().catch(()=>[])??[]).reduce((x,L)=>x+L.children.length,0);j&&P.push(w(t,{template:"structure-recheck"},"Post-merge re-check",b.mechanical,j*3e3,j*300));let D=await e.context.chatFindingCount?.().catch(()=>(e.progress.log({level:"warn",code:"chat.count_failed"}),0))??0;D&&P.push(w(t,{},"Re-check chat findings",b.mechanical,D*3e3,D*300));let H=Y(P,n.capUsd);return V(H,e.progress.log),{next:n.confirmPrice?"awaiting_confirm":"fetching_files",clear:[],estimate:H,set:{repos:i,warnings:h,openStructures:Ie,codeAgents:u,modelReader:d,analysisFlags:f,projectAgents:E,findingQuality:S,...f.splitCheck?{splitEstimateBase:H}:{}}}};var xr=async({state:o,settings:e},n)=>{n.progress.assertHeld(),n.progress.signal?.throwIfAborted();let a=[...o.repos??[]];await O(e,o,n.readers);let t=o.repoCursor??0;if(t>=a.length)return{next:"mapping",set:{repoCursor:0},clear:[]};let c=structuredClone(a[t]),m=n.readers.find(l=>l.repoKey===c.key);if(!m)throw new Error(`no reader for ${c.key}`);let g=R(e,m),h=await B(e,c,g,o.modelReader??!1);if(h)return a[t]=h,{next:"fetching_files",set:{repos:a},clear:[]};let u=c.selected??[],d=c.cursor??0,f=u.slice(d,d+20),S={...c.files??{}},E=[];for(let l of f){if(n.progress.assertHeld(),n.progress.signal?.throwIfAborted(),S[l.path]!==void 0)continue;let p=await M(l,r=>g.read(r),E,c.refused);p!==null&&(S[l.path]=p)}E.length&&(c.refused=I(c.refused,E)),c.files=S,c.cursor=d+f.length,a[t]=c;let i=c.cursor>=u.length&&!ge(e,c);return{next:"fetching_files",set:{repos:a,repoCursor:i?t+1:t},clear:[]}};async function Sr(o,e){let n=e.admission?.exclusions?.length?e.entries.filter(c=>k(o,c,{purpose:"override",route:"github",...e.admission}).admitted):e.entries,a=ee(o)?new Set(n.map(c=>c.path)):void 0,t=!e.admission?.exclusions?.length&&!W(o)?e.read:c=>se(o,c,e.read,{...e.admission,...a?{listing:a}:{}});return X(o,{...e,entries:n,read:t})}function Er(o,e){let n=e?.findingHeadlineDiagnostics??(o.findingHeadlines?.version===2?o.findingHeadlines.diagnostics:o.findingHeadlineDiagnostics);return{set:{...n?{findingHeadlineDiagnostics:n}:{},repos:(o.repos??[]).map(a=>({...a,files:{},selected:[],scan:void 0,ranked:void 0})),...o.projectAgents?{projectAgents:{enabled:o.projectAgents.enabled,byRepo:{}}}:{}},clear:["passResults","sourceNotes","findingHeadlines","findingsRaw","structuresRaw","loadModes","rechecks","recheckedChangeIds","readPaths","inspectPlan","passFindings","codeChecks","newVerdicts",...o.shapeFindings?["shapeFindings"]:[]]}}export{We as ANALYSIS_FIELDS,Me as FOLDER_TOO_LARGE_MESSAGE,qe as InputBudgetError,b as MODELS,k as admitFile,rr as analysisFieldsOf,sr as analysisRuntime,Ne as analysisSizeLimits,tr as applyAnalysisDelta,Pe as assessAnalysisSize,ar as buildAnalysisResult,ze as buildRequest,U as createInstructionText,Ue as createRequestRegistry,$ as createRequestTools,X as discoverLocalSources,$e as discoverReaders,yr as estimateStage,Sr as fetchLocalSources,xr as fetchStage,er as fetchedPathsOf,z as findingHeadlinesEnabled,Er as finishAnalysis,dr as headlinesStage,Qe as importProposalEnabled,ir as inspectStage,nr as mapStage,je as measureAnalysisSize,Be as parseAnalysisSize,Xe as planForJob,Ge as planImport,or as readFindingQualityConfig,Ke as render,pr as repoCollector,He as resolveAgents,Ye as savedFragmentAt,Ze as savedFragmentsOf,J as scopeCodeContext,Je as selectionOfPlan,De as snapshotSettings,cr as sourceNotesStage,lr as structureStage,Ve as trySavedFragmentAt};
@@ -1 +1 @@
1
- import{a,b,c}from"../chunks/SL27GMEN.js";import"../chunks/3227KXHF.js";export{a as NONSTREAM_MAX_TOKENS,c as anthropicStructuredLimit,b as supportsReasoningControls};
1
+ import{a,b,c}from"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";export{a as NONSTREAM_MAX_TOKENS,c as anthropicStructuredLimit,b as supportsReasoningControls};
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"../chunks/4H23CSUM.js";export{b as EFFORTS,a as MODELS,d as STREAMED_MAX_TOKENS,c as THINKING_MODES};
@@ -1 +1 @@
1
- import{j as a}from"../chunks/TDNTU4TF.js";import"../chunks/STZOC7LN.js";import"../chunks/UEWL3GMQ.js";import"../chunks/U5HOEVPE.js";import"../chunks/EH3QQ3T4.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";export{a as answerFormats};
1
+ import{j as a}from"../chunks/K2GNDX3W.js";import"../chunks/6U2IR4XB.js";import"../chunks/6B2HILSY.js";import"../chunks/SKVEBOGA.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";export{a as answerFormats};
@@ -1 +1 @@
1
- import{a,b,c}from"../chunks/ZAA44GPI.js";import"../chunks/3227KXHF.js";export{a as FINDING_HEADLINES_MODEL,b as FINDING_HEADLINES_OUTPUT_TOKENS,c as headlineRequest};
1
+ import{a,b,c}from"../chunks/N7U5N42V.js";import"../chunks/4H23CSUM.js";export{a as FINDING_HEADLINES_MODEL,b as FINDING_HEADLINES_OUTPUT_TOKENS,c as headlineRequest};
@@ -1 +1 @@
1
- import{X as o,Z as p,aa as e,ca as m}from"../chunks/T2SAP7OV.js";import"../chunks/QMIXCT62.js";import"../chunks/T66VDFXF.js";import"../chunks/J4AXGE5W.js";import"../chunks/IVDDV6CU.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/TDNTU4TF.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/K5OTWBTT.js";import"../chunks/326F4XNG.js";import"../chunks/V7BFUTM7.js";import"../chunks/4F6ZIHXU.js";import"../chunks/VGYWI4X2.js";import"../chunks/PYKAERZZ.js";import"../chunks/7OYIBWX3.js";import"../chunks/NCWEOJVJ.js";import"../chunks/2PSNOSJ2.js";import"../chunks/DRGDIIFA.js";import"../chunks/6YCABS5T.js";import"../chunks/SL27GMEN.js";import"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import"../chunks/OFBJNHC6.js";import"../chunks/MXXNED6N.js";import"../chunks/U5HOEVPE.js";import"../chunks/FTODBFQW.js";import"../chunks/ZAA44GPI.js";import"../chunks/3227KXHF.js";import"../chunks/O652FQQH.js";import"../chunks/57M4OQJM.js";import"../chunks/IBCFGUHI.js";import"../chunks/KU5DINLW.js";import"../chunks/HPIAEQHE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";import"../chunks/T5TREZCQ.js";import"../chunks/724WZMYW.js";function i(l,r,a={}){let n=o(l,r,a.structureState);return[...n.calls,...p(l,n.findings),...m(l,r,a),...e(l)]}export{i as localCallPlan};
1
+ import{a,b}from"../chunks/YDBO7P4X.js";import"../chunks/QFY6A3MS.js";import"../chunks/OPMA32A6.js";import"../chunks/STI4JE7L.js";import"../chunks/N7U5N42V.js";import"../chunks/6QY5BV5B.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/K2GNDX3W.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/4F6ZIHXU.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VGYWI4X2.js";import"../chunks/57M4OQJM.js";import"../chunks/J4AXGE5W.js";import"../chunks/FOKDE64Y.js";import"../chunks/IBCFGUHI.js";import"../chunks/DZZBQDGO.js";import"../chunks/377MLK4M.js";import"../chunks/326F4XNG.js";import"../chunks/ZTOVBAG7.js";import"../chunks/KTNA2KTN.js";import"../chunks/2PSNOSJ2.js";import"../chunks/KU5DINLW.js";import"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import"../chunks/PYKAERZZ.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/5DGPLXYB.js";import"../chunks/6U2IR4XB.js";import"../chunks/MJGB25S5.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";import"../chunks/X7WZAA7S.js";export{a as localCallPlan,b as localSourcePlan};
@@ -1 +1 @@
1
- import{k as a,l as b,m as c,n as d}from"../chunks/IVDDV6CU.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/TDNTU4TF.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/V7BFUTM7.js";import"../chunks/6YCABS5T.js";import"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import"../chunks/U5HOEVPE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";export{a as InputBudgetError,d as buildAnalysisCall,c as callInputBytes,b as createRequestRegistry};
1
+ import{l as a,m as b,n as c,o as d}from"../chunks/6QY5BV5B.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/K2GNDX3W.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/ZTOVBAG7.js";import"../chunks/74FPPPIG.js";import"../chunks/5DGPLXYB.js";import"../chunks/6U2IR4XB.js";import"../chunks/MJGB25S5.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";import"../chunks/X7WZAA7S.js";export{a as InputBudgetError,d as buildAnalysisCall,c as callInputBytes,b as createRequestRegistry};
@@ -1 +1 @@
1
- import{a}from"../chunks/T66VDFXF.js";import"../chunks/E7TFIHC5.js";import"../chunks/V7BFUTM7.js";import"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";export{a as createTemplateVersion};
1
+ import{a}from"../chunks/STI4JE7L.js";import"../chunks/E7TFIHC5.js";import"../chunks/ZTOVBAG7.js";import"../chunks/X7WZAA7S.js";export{a as createTemplateVersion};
@@ -1 +1 @@
1
- import{a}from"../chunks/QMIXCT62.js";import"../chunks/T66VDFXF.js";import"../chunks/IVDDV6CU.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/TDNTU4TF.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/V7BFUTM7.js";import"../chunks/6YCABS5T.js";import"../chunks/3CKW5JIF.js";import"../chunks/STZOC7LN.js";import"../chunks/MJGB25S5.js";import"../chunks/UEWL3GMQ.js";import"../chunks/U5HOEVPE.js";import"../chunks/74FPPPIG.js";import"../chunks/EH3QQ3T4.js";import"../chunks/JKWTHRUR.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/3GUKUEEJ.js";export{a as createRequestTools};
1
+ import{a}from"../chunks/OPMA32A6.js";import"../chunks/STI4JE7L.js";import"../chunks/6QY5BV5B.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/K2GNDX3W.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/ZTOVBAG7.js";import"../chunks/74FPPPIG.js";import"../chunks/5DGPLXYB.js";import"../chunks/6U2IR4XB.js";import"../chunks/MJGB25S5.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";import"../chunks/X7WZAA7S.js";export{a as createRequestTools};
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunks/V7BFUTM7.js";import"./chunks/3CKW5JIF.js";import"./chunks/STZOC7LN.js";import"./chunks/MJGB25S5.js";import"./chunks/UEWL3GMQ.js";import"./chunks/EH3QQ3T4.js";import"./chunks/JKWTHRUR.js";import"./chunks/FSLWD2PE.js";import"./chunks/JF4GYMOZ.js";import"./chunks/3GUKUEEJ.js";export{a as findingHeadlinesEnabled,b as outsideLoadersEnabled,c as promptAgreementEnabled,d as snapshotSettings};
1
+ import{a,b,c,d,e}from"./chunks/ZTOVBAG7.js";import"./chunks/X7WZAA7S.js";export{a as findingHeadlinesEnabled,c as outsideLoadersEnabled,d as promptAgreementEnabled,b as resultSafetyCheckEnabled,e as snapshotSettings};
@@ -0,0 +1 @@
1
+ import{a as B,b as S}from"../chunks/F3R4J3ND.js";import{b as V}from"../chunks/YDBO7P4X.js";import{g as v,h as K,i as A,j as O}from"../chunks/DLPVYWHZ.js";import{Aa as T,Ca as j,S as E,fa as M,sa as z,ua as H,wa as Q,xa as D,ya as N}from"../chunks/QFY6A3MS.js";import"../chunks/OPMA32A6.js";import"../chunks/STI4JE7L.js";import{c as _}from"../chunks/N7U5N42V.js";import"../chunks/6QY5BV5B.js";import"../chunks/Y7JGSUOA.js";import"../chunks/3MTXB4MK.js";import"../chunks/K2GNDX3W.js";import"../chunks/HTLIRVP7.js";import"../chunks/QDYMR6KS.js";import"../chunks/E7TFIHC5.js";import"../chunks/4F6ZIHXU.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VGYWI4X2.js";import"../chunks/57M4OQJM.js";import"../chunks/J4AXGE5W.js";import"../chunks/SVMEWGD3.js";import"../chunks/FOKDE64Y.js";import"../chunks/IBCFGUHI.js";import"../chunks/DZZBQDGO.js";import"../chunks/3JWEFCTJ.js";import"../chunks/377MLK4M.js";import"../chunks/326F4XNG.js";import{a as I}from"../chunks/ZTOVBAG7.js";import"../chunks/KTNA2KTN.js";import"../chunks/2PSNOSJ2.js";import"../chunks/KU5DINLW.js";import{ta as P}from"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import"../chunks/PYKAERZZ.js";import"../chunks/YUY436SM.js";import{e as L}from"../chunks/C6X5GDG4.js";import"../chunks/5DGPLXYB.js";import"../chunks/6U2IR4XB.js";import"../chunks/MJGB25S5.js";import"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import{b as F}from"../chunks/3GUKUEEJ.js";import"../chunks/A7WJJMRY.js";import"../chunks/KWECQJ6X.js";import"../chunks/FSLWD2PE.js";import{t as k}from"../chunks/X7WZAA7S.js";function G(s,t){return M(s,t,{codeInputs:!1,recall:!1,secondOpinion:!1})}function C(s,t,i,l){let a=t.findingQuality,y={...i.findingCheck?.state?.result??{kept:t.findings,dropped:[],warnings:[]}};a?.assessments&&y.qualityAudit&&(y.qualityAudit={coverage:a.coverage??[],verdicts:a.verdicts??[],assessments:a.assessments,...a.shadow?{shadow:a.shadow}:{}});let e=D(t.findings,t.structures,t.findingHeadlines??[],t.findingHeadlineDiagnostics),g=new Map(e.rows.filter(r=>r.target==="finding").map(r=>[r.index,{headline:r.headline,ifLeft:r.ifLeft}])),m=new Map(e.rows.filter(r=>r.target==="structure").map(r=>[r.index,{headline:r.headline,ifLeft:r.ifLeft}])),R=m.size?t.structures.map((r,w)=>m.has(w)?{...r,...m.get(w)}:r):t.structures,x=g.size?t.findings.map((r,w)=>g.has(w)?{...r,...g.get(w)}:r):t.findings,d=i.findingQuality?.config.switches.ranking?z(x,a?.assessments??[]):void 0;return{repoKey:s,findings:d?.ordered??x,structures:R,graph:t.graph,warnings:t.warnings,...l?{proposalCounts:l}:{},...e.diagnostics?{findingHeadlineDiagnostics:e.diagnostics}:{},skippedFiles:i.inspectPlan?.skipped??[],passes:i.inspectPlan?.passes.length??1,findingCheck:y,...d?{ranking:{defaultIds:d.defaultIds,hiddenIds:d.hiddenIds,emptyMessage:d.emptyMessage}}:{}}}async function J(s,t,i,l=B){let a={...i.state,repos:i.repos,mapped:i.fragments.map(({fragment:e})=>e),findingsRaw:i.findings,warnings:i.state?.warnings??[],splitCheckPriced:!0,splitFindingsPriced:!0},y=S(t,l);for(;;){let e=await j({phase:"structuring",state:a,settings:s,execution:{scopeConcurrency:4,forLocal:!0}},y);if(a=A(a,e),e.next==="persisting")return{state:a,structures:a.structuresRaw??[],warnings:a.warnings??[]}}}function W(s,t){I(t)&&s.requestTools.headlinePlan(_([]))}async function U(s,t,i={}){let{settings:l,qualityConfig:a}=s;W(t,l);let y=E(l);if(!Object.keys(s.files).length)throw new F("empty_folder","No admitted source files were found.");let e={repos:[{key:s.repoKey,kind:"fs",files:s.files,...s.root!==void 0?{root:s.root}:{}}],warnings:s.warnings??[],...s.fragment?{mapped:[s.fragment]}:{}},g=S(t,t.progress);for(;;){let d=await O({phase:"mapping",state:e,settings:l,execution:{scopeConcurrency:4,forLocal:!0,preparation:{capUsd:20,confirmPrice:!1,qualityConfig:a}}},g);if(e=A(e,d),d.next!=="mapping")break}e={...e,analysisFlags:{...y,sourceNotes:!i.findingsOnly&&y.sourceNotes},findingQuality:{config:a},warnings:[...e.warnings??[],...a.diagnostics]};let m="inspecting";for(g.progress.checkpoint=async(d,r)=>{e={...e,...d,...r?{passResults:{...e.passResults,[r.index]:r.result}}:{}},await t.progress.checkpoint(d,r)};m!=="structuring";){let r=await(m==="inspecting"?H:Q)({phase:m,state:e,settings:l,execution:{scopeConcurrency:4,passConcurrency:4,forLocal:!0}},g);e=A(e,r),m=r.next}let R=()=>N({phase:"persisting",state:e,settings:l,execution:{scopeConcurrency:4}});if(!i.findingsOnly){let d=C(s.repoKey,R(),e,s.proposalCounts),r=e.findingsRaw;e={...(await J(l,t,{repos:e.repos,fragments:[{repoKey:s.repoKey,fragment:e.mapped[0]}],graph:d.graph,findings:d.findings,state:e},g.progress)).state,findingsRaw:r}}e=A(e,await T({phase:"persisting",state:e,settings:l,execution:{scopeConcurrency:4,forLocal:!0}},g));let x=R();return await i.resultSink?.(x),C(s.repoKey,x,e,s.proposalCounts)}import{createHash as X}from"node:crypto";async function Y(s,t,i){let l=new Map,a=new Map,y=[],e,g=[],m=()=>{if(i.signal?.throwIfAborted(),e)throw k(e)},R=async f=>{m();try{return await i.list(f)}catch{throw i.signal?.throwIfAborted(),k("unavailable")}},x=async f=>{let u=[],o=new Set,h=new Set,c=new Set,p=f;for(;;){if(m(),p.snapshot!==t.manifest.snapshot||p.commit!==t.manifest.commit)throw k("bad_request");for(let n of p.files){let b=l.get(n.id);if(o.has(n.path)||h.has(n.id)||b&&(b.hash!==n.hash||b.size!==n.size))throw k("bad_request");o.add(n.path),h.add(n.id);let q={...n};l.set(n.id,q),u.push(q)}if(p.complete)return u;if(!p.cursor||c.has(p.cursor))throw k("bad_request");c.add(p.cursor),p=await R(p.cursor)}},d=f=>f.map(({id:u,path:o,size:h})=>({path:o,size:h,ref:u})),r=v(async f=>{if(i.signal?.throwIfAborted(),e)return f.map(()=>null);let u=[...new Set(f.map(o=>o.ref))].filter(o=>!a.has(o)).map(o=>l.get(o));if(u.length){let o;try{o=await i.read(u)}catch{return i.signal?.throwIfAborted(),e="unavailable",f.map(()=>null)}i.signal?.throwIfAborted();let h=new Map(u.map(c=>[c.id,c]));for(let c of o){let p=h.get(c.id);if(!p||c.text!==null&&!c.refusal&&(Buffer.byteLength(c.text)!==p.size||X("sha256").update(c.text).digest("hex")!==p.hash)){e="bad_request";break}h.delete(c.id),a.set(c.id,{text:c.refusal?null:c.text,bytesRead:c.bytesRead,...c.refusal?{refusal:c.refusal}:{}})}if(h.size&&(e="bad_request"),e)return f.map(()=>null)}return f.map(o=>a.get(o.ref)?.text??null)}),w=async f=>{let u=await r(f);return u===null?null:P(s,f,async()=>u)};try{let f=await x(t.manifest),u=await K(s,{repoKey:t.repoKey,entries:d(f),read:w,localListing:!0,repository:{context:async()=>t.selectedRoot===null?null:{selectedRoot:t.selectedRoot},list:async()=>{let n=await R(null),b=await x(n);return y=b,{entries:d(b),truncated:n.truncated,entriesVisited:n.entriesVisited}},read:async n=>(await w(n),a.get(n.ref)??{text:null,bytesRead:0})}});m();let o={repoKey:t.repoKey,...u},h=new Map(f.map(n=>[L(n.path,o.root),n]));o.root!==void 0&&y.forEach(n=>h.set(n.path,n));let c=Object.keys(o.files).map(n=>{let b=h.get(n);if(!b)throw k("bad_request");return{...b,path:n}}),{calls:p}=V(s,o);return g=c.map(n=>n.id),{source:o,finalFiles:c,calls:p}}finally{a.clear(),l.clear(),i.finish?.(g)}}async function Le(s,t,i={}){let l=s.settings,a=G(l,t.requestTools);return U({...s,settings:l,qualityConfig:a},t,i)}export{Y as prepareRelayAnalysis,Le as runEngineAnalysis};
@@ -0,0 +1 @@
1
+ import{a,b}from"../chunks/F3R4J3ND.js";export{a as NO_PROGRESS,b as executionPorts};
@@ -12,6 +12,14 @@ const registryPayload = z.object({
12
12
  answerFormats: z.record(z.string(), z.object({ schema: z.string(), source: z.string() }).strict()),
13
13
  descriptions: z.record(z.string(), z.string()),
14
14
  }).strict();
15
+ export function validateRegistryPayload(value) {
16
+ try {
17
+ return registryPayload.parse(value);
18
+ }
19
+ catch {
20
+ throw new Error("Invalid registry payload");
21
+ }
22
+ }
15
23
  function restoreFormat(saved, local) {
16
24
  const source = z.record(z.string(), z.unknown()).parse(JSON.parse(saved.source));
17
25
  // Validate the provider shape while leaving defaults, catches and cleanup to the local core.
@@ -32,7 +40,7 @@ function restoreFormat(saved, local) {
32
40
  }
33
41
  export function deserialiseRegistry(bytes) {
34
42
  try {
35
- const payload = registryPayload.parse(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)));
43
+ const payload = validateRegistryPayload(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)));
36
44
  const text = createInstructionText({
37
45
  templates: payload.includes, descriptions: payload.descriptions,
38
46
  });
@@ -0,0 +1,76 @@
1
+ import { createHash, verify } from "node:crypto";
2
+ import { z } from "zod";
3
+ import { stableStringify } from "../../analysis-core/llm/stable-json.js";
4
+ import { engineIdentity, engineKeyPolicy, samePin } from "../../contract/engine.js";
5
+ export { ENGINE_ABI, ENGINE_SPAWNER_CONTRACT, engineIdentity } from "../../contract/engine.js";
6
+ export const ENGINE_IMPORTS = ["node:crypto", "node:path"];
7
+ export const ENGINE_EXPORTS = ["prepareRelayAnalysis", "runEngineAnalysis"];
8
+ const engineProgram = z.strictObject({ identity: engineIdentity, program: z.string().min(1),
9
+ imports: z.array(z.enum(ENGINE_IMPORTS)).refine(paths => paths.every((path, i) => i === 0 || paths[i - 1] < path)),
10
+ });
11
+ /** This format is separate from signed instruction data and is pinned by the image, never a bundle update. */
12
+ export const sealedEngine = z.strictObject({ kind: z.literal("counterfact-engine-v1"), identity: engineIdentity, keyPolicy: engineKeyPolicy,
13
+ sealed: z.string().min(1), iv: z.string().min(1), wrappedKey: z.string().min(1), signature: z.string().min(1),
14
+ });
15
+ export function engineHash(bytes) { return createHash("sha256").update(bytes).digest("hex"); }
16
+ export function validateEngineProgram(value) {
17
+ try {
18
+ const program = engineProgram.parse(value);
19
+ if (engineHash(program.program) !== program.identity.programSha256)
20
+ throw new Error();
21
+ return program;
22
+ }
23
+ catch {
24
+ throw new Error("Invalid engine program");
25
+ }
26
+ }
27
+ function signingBytes(value) {
28
+ // A distinct signature domain prevents an instruction signature from authorizing executable code.
29
+ return createHash("sha256").update("counterfact sealed engine v1\n").update(stableStringify(value)).digest();
30
+ }
31
+ export function verifyEngineArtifact(value, key) {
32
+ const { signature, ...unsigned } = sealedEngine.parse(value);
33
+ const bytes = Buffer.from(signature, "base64");
34
+ if (key.asymmetricKeyType !== "ed25519" || bytes.toString("base64") !== signature || !verify(null, signingBytes(unsigned), key, bytes)) {
35
+ throw new Error("Invalid engine signature");
36
+ }
37
+ }
38
+ export async function signEngineArtifact(value, signer) {
39
+ const unsigned = sealedEngine.omit({ signature: true }).parse(value);
40
+ const signed = { ...unsigned, signature: (await signer.sign(signingBytes(unsigned))).toString("base64") };
41
+ verifyEngineArtifact(signed, signer.publicKey);
42
+ return signed;
43
+ }
44
+ /** Hash the complete signed artifact so startup can require the exact ciphertext used in both image builds. */
45
+ export function engineArtifactSha256(value) {
46
+ return engineHash(stableStringify(sealedEngine.parse(value)));
47
+ }
48
+ /** Startup, publication and the launcher consume the same complete public pin. */
49
+ export function pinEngineArtifact(value) {
50
+ const artifact = sealedEngine.parse(value);
51
+ return { ...artifact.identity, artifactSha256: engineArtifactSha256(artifact), keyPolicy: artifact.keyPolicy };
52
+ }
53
+ export function deserialiseEngine(bytes) {
54
+ try {
55
+ return validateEngineProgram(JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)));
56
+ }
57
+ catch {
58
+ throw new Error("Invalid engine program");
59
+ }
60
+ }
61
+ export function serialiseEngine(program) {
62
+ return Buffer.from(stableStringify(validateEngineProgram(program)), "utf8");
63
+ }
64
+ /** Every loader and image stage uses this check before releasing a key or accepting ciphertext. */
65
+ export function verifyPinnedEngineArtifact(value, key, expected) {
66
+ try {
67
+ const artifact = sealedEngine.parse(value);
68
+ verifyEngineArtifact(artifact, key);
69
+ if (!samePin(pinEngineArtifact(artifact), expected))
70
+ throw new Error();
71
+ return artifact;
72
+ }
73
+ catch {
74
+ throw new Error("Engine artifact differs");
75
+ }
76
+ }
@@ -0,0 +1,9 @@
1
+ /** Opened instructions and programs share a snapshot that callers cannot mutate. */
2
+ export function freezeData(data) {
3
+ if (data && typeof data === "object") {
4
+ for (const child of Object.values(data))
5
+ freezeData(child);
6
+ Object.freeze(data);
7
+ }
8
+ return data;
9
+ }
@@ -63,6 +63,9 @@ export function verifyBundleMetadata(metadata, registry, key, policy) {
63
63
  delete expected.headlinePlan;
64
64
  else if (supplied.headlinePlan.resultVersion === undefined && expected.headlinePlan)
65
65
  delete expected.headlinePlan.resultVersion;
66
+ // Analysis compatibility is release data, independent of wording fingerprints.
67
+ if (supplied.analysis)
68
+ expected.analysis = supplied.analysis;
66
69
  if (stableStringify(supplied) !== stableStringify(expected)) {
67
70
  throw new Error("Invalid bundle metadata");
68
71
  }
@@ -0,0 +1,26 @@
1
+ import { enginePin } from "../../contract/engine.js";
2
+ import { stableStringify } from "../../analysis-core/llm/stable-json.js";
3
+ import { verifyPinnedEngineArtifact, deserialiseEngine } from "./engine.js";
4
+ import { decrypt } from "./encryption.js";
5
+ import { freezeData } from "./freeze.js";
6
+ /** Authentication and the compiled image pin precede key release. Loading executable code belongs to sealed startup. */
7
+ export async function openEngine(value, options) {
8
+ let key, plaintext;
9
+ try {
10
+ const pin = enginePin.strip().parse(options);
11
+ const artifact = verifyPinnedEngineArtifact(value, options.verificationKey, pin);
12
+ key = await options.keyService.unwrapKey(artifact.wrappedKey);
13
+ plaintext = decrypt(artifact.sealed, artifact.iv, key);
14
+ const program = deserialiseEngine(plaintext);
15
+ if (stableStringify(program.identity) !== stableStringify(artifact.identity))
16
+ throw new Error();
17
+ return freezeData(program);
18
+ }
19
+ catch {
20
+ throw new Error("Unable to open engine");
21
+ }
22
+ finally {
23
+ key?.fill(0);
24
+ plaintext?.fill(0);
25
+ }
26
+ }
@@ -3,16 +3,10 @@ import { decrypt } from "./encryption.js";
3
3
  import { deserialiseSealedRegistry } from "./deserialise.js";
4
4
  import { sameNames, verifyBundleMetadata } from "./metadata.js";
5
5
  import { verifyCompatibleRelease } from "./signature.js";
6
+ import { freezeData } from "./freeze.js";
6
7
  const authenticated = new WeakSet();
7
8
  export function isOpenedBundle(registry) { return authenticated.has(registry); }
8
- function freezeData(data) {
9
- if (data && typeof data === "object") {
10
- for (const child of Object.values(data))
11
- freezeData(child);
12
- Object.freeze(data);
13
- }
14
- return data;
15
- }
9
+ export { openEngine } from "./open-engine.js";
16
10
  export async function openBundle(value, options) {
17
11
  const parsed = sealedBundle.safeParse(value);
18
12
  if (!parsed.success)
@@ -1,5 +1,5 @@
1
1
  import { resolveFolderPath } from "../adapters/folder-path.js";
2
- import { START_FAILURE_MESSAGE } from "../contract/cli-refusals.js";
2
+ import { CliRefusalError } from "../contract/cli-refusals.js";
3
3
  import { isAbsolute, parse, relative, resolve, sep } from "node:path";
4
4
  export function resolveAgentFolder(path, cwd) {
5
5
  return resolve(cwd ?? process.cwd(), path);
@@ -8,10 +8,10 @@ export function resolveAgentFolder(path, cwd) {
8
8
  export async function resolveMcpAgentFolder(path, cwd, homeDir) {
9
9
  const [folder, launch, home] = await Promise.all([
10
10
  resolveFolderPath(resolveAgentFolder(path, cwd)), resolveFolderPath(cwd), resolveFolderPath(homeDir),
11
- ]).catch(() => { throw new Error(START_FAILURE_MESSAGE); });
11
+ ]).catch(() => { throw new CliRefusalError("folder_unavailable"); });
12
12
  const rel = relative(launch, folder);
13
13
  if (folder === parse(folder).root || folder === home || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
14
- throw new Error(START_FAILURE_MESSAGE);
14
+ throw new CliRefusalError("outside_project");
15
15
  }
16
16
  return folder;
17
17
  }