@counterfact-labs/cli 0.2.6 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/bundle/client-release.json +1 -1
- package/dist/adapters/analysis-results.js +87 -0
- package/dist/adapters/combined-results.js +27 -0
- package/dist/adapters/completion-lock.js +95 -0
- package/dist/adapters/completion.js +132 -17
- package/dist/adapters/entry-files.js +129 -0
- package/dist/adapters/entry-packing.js +161 -0
- package/dist/adapters/entry-selection.js +57 -0
- package/dist/adapters/files.js +111 -5
- package/dist/adapters/git.js +10 -1
- package/dist/adapters/relay-plan.js +5 -7
- package/dist/adapters/release.js +4 -1
- package/dist/adapters/results.js +18 -3
- package/dist/adapters/selection.js +114 -0
- package/dist/adapters/settings.js +62 -4
- package/dist/adapters/source-relay-plan.js +7 -0
- package/dist/analysis-core/analysis/code-agents/skipped-files.js +1 -1
- package/dist/analysis-core/analysis/file-analysis-plan.js +1 -0
- package/dist/analysis-core/analysis/file-dependencies.js +1 -0
- package/dist/analysis-core/analysis/finding-activity-switch.js +1 -0
- package/dist/analysis-core/analysis/finding-identity.js +1 -0
- package/dist/analysis-core/analysis/finding-quality/policy.js +1 -0
- package/dist/analysis-core/analysis/folder-analysis-plan.js +1 -0
- package/dist/analysis-core/analysis/passes/full-file-passes.js +1 -0
- package/dist/analysis-core/analysis/project-architecture.js +1 -0
- package/dist/analysis-core/analysis/schemas.js +1 -1
- package/dist/analysis-core/chunks/2AASSZRO.js +35 -0
- package/dist/analysis-core/chunks/2YREYGOG.js +1 -0
- package/dist/analysis-core/chunks/33HRXJ5Q.js +1 -0
- package/dist/analysis-core/chunks/33IGHOYT.js +1 -0
- package/dist/analysis-core/chunks/4PT5C4IT.js +7 -0
- package/dist/analysis-core/chunks/4RXRAB5S.js +1 -0
- package/dist/analysis-core/chunks/4UDQBDDE.js +1 -0
- package/dist/analysis-core/chunks/{OPMA32A6.js → 5B5UCWD3.js} +1 -1
- package/dist/analysis-core/chunks/6YCABS5T.js +1 -0
- package/dist/analysis-core/chunks/CQQ4TTXE.js +1 -0
- package/dist/analysis-core/chunks/CTLHKFPH.js +19 -0
- package/dist/analysis-core/chunks/F54DOWKN.js +6 -0
- package/dist/analysis-core/chunks/FRXOQ2M6.js +3 -0
- package/dist/analysis-core/chunks/HCPO6QPU.js +1 -0
- package/dist/analysis-core/chunks/HHFDNY6V.js +14 -0
- package/dist/analysis-core/chunks/{3JWEFCTJ.js → HVQJKPQ4.js} +1 -1
- package/dist/analysis-core/chunks/INVTU73D.js +1 -0
- package/dist/analysis-core/chunks/JEWBPIQI.js +1 -0
- package/dist/analysis-core/chunks/JGK37AWN.js +1 -0
- package/dist/analysis-core/chunks/LFYTD7JF.js +1 -0
- package/dist/analysis-core/chunks/LMUXOKIM.js +1 -0
- package/dist/analysis-core/chunks/LOBIDUCA.js +1 -0
- package/dist/analysis-core/chunks/M5YWJY7P.js +1 -0
- package/dist/analysis-core/chunks/MGVIKA74.js +1 -0
- package/dist/analysis-core/chunks/MKYLK6DB.js +1 -0
- package/dist/analysis-core/chunks/MZOKZ3N6.js +1 -0
- package/dist/analysis-core/chunks/NXHVBJL4.js +1 -0
- package/dist/analysis-core/chunks/OKBK3JL3.js +1 -0
- package/dist/analysis-core/chunks/PBHHWFR6.js +1 -0
- package/dist/analysis-core/chunks/Q5WR6B2H.js +2 -0
- package/dist/analysis-core/chunks/QVXARKP7.js +1 -0
- package/dist/analysis-core/chunks/RQTNTIR4.js +1 -0
- package/dist/analysis-core/chunks/RUVMFAST.js +1 -0
- package/dist/analysis-core/chunks/S27VIQMZ.js +1 -0
- package/dist/analysis-core/chunks/{YDBO7P4X.js → S27Y2TP5.js} +1 -1
- package/dist/analysis-core/chunks/SJESFYBA.js +10 -0
- package/dist/analysis-core/chunks/SP6XFHNH.js +1 -0
- package/dist/analysis-core/chunks/VDUFPTDD.js +1 -0
- package/dist/analysis-core/chunks/W24SFYZM.js +67 -0
- package/dist/analysis-core/chunks/YTHF2E2S.js +1 -0
- package/dist/analysis-core/chunks/YWL52FVW.js +2 -0
- package/dist/analysis-core/contracts/analysis-selection.js +1 -0
- package/dist/analysis-core/contracts/analysis-size.js +1 -0
- package/dist/analysis-core/contracts/execution-request.js +1 -0
- package/dist/analysis-core/contracts/intake-finding.js +1 -0
- package/dist/analysis-core/contracts/model-call-identity.js +1 -0
- package/dist/analysis-core/contracts/module-resolution.js +1 -0
- package/dist/analysis-core/contracts/relay-analysis.js +1 -1
- package/dist/analysis-core/contracts/requests.js +1 -1
- package/dist/analysis-core/contracts/selection-paths.js +1 -0
- package/dist/analysis-core/conventions/analysis-fit.js +1 -1
- package/dist/analysis-core/conventions/file-admission.js +1 -1
- package/dist/analysis-core/conventions/read-limits.js +1 -0
- package/dist/analysis-core/import/calls/modules.js +1 -0
- package/dist/analysis-core/import/entry-selection.js +1 -0
- package/dist/analysis-core/import/outside-loader-sources.js +1 -1
- package/dist/analysis-core/index.js +3 -3
- package/dist/analysis-core/requests/answer-formats.js +1 -1
- package/dist/analysis-core/requests/local-plan.js +1 -1
- package/dist/analysis-core/requests/planned-limits.js +1 -0
- package/dist/analysis-core/requests/registry.js +1 -1
- package/dist/analysis-core/requests/template-version.js +1 -1
- package/dist/analysis-core/requests/tools.js +1 -1
- package/dist/analysis-core/settings.js +1 -1
- package/dist/analysis-core/stages/engine-entry.js +1 -1
- package/dist/bundle/seal/engine.js +1 -1
- package/dist/cli/analysis-selection.js +133 -0
- package/dist/cli/api.js +1 -1
- package/dist/cli/commands/analyze.js +82 -14
- package/dist/cli/commands/skipped.js +65 -0
- package/dist/cli/completion-delivery.js +63 -0
- package/dist/cli/completion-recovery.js +68 -14
- package/dist/cli/context.js +4 -2
- package/dist/cli/finding-display.js +102 -7
- package/dist/cli/finding-settings.js +3 -1
- package/dist/cli/intake-payload.js +26 -2
- package/dist/cli/main.js +37 -11
- package/dist/cli/mcp-failure.js +6 -5
- package/dist/cli/mcp.js +191 -26
- package/dist/cli/prior-completion.js +35 -0
- package/dist/cli/relay-check.js +260 -110
- package/dist/cli/relay-failure.js +32 -0
- package/dist/cli/relay-preparation.js +72 -21
- package/dist/cli/result-check.js +31 -12
- package/dist/cli/results-upload.js +131 -0
- package/dist/cli/saved-results.js +10 -0
- package/dist/cli/scope-choices.js +57 -0
- package/dist/cli/sign-in.js +2 -2
- package/dist/cli/skipped-files.js +22 -0
- package/dist/cli/summary.js +15 -1
- package/dist/contract/agent-choice.js +25 -2
- package/dist/contract/cli-api-messages.js +3 -0
- package/dist/contract/cli-refusals.js +39 -5
- package/dist/contract/cli-version.js +1 -1
- package/dist/contract/console-url.js +3 -0
- package/dist/contract/console.js +24 -40
- package/dist/contract/engine.js +1 -1
- package/dist/contract/messages.js +4 -3
- package/dist/contract/project-architecture.js +1 -0
- package/dist/contract/scope-choice.js +98 -0
- package/dist/contract/selection-metadata.js +9 -0
- package/dist/contract/selection-offer.js +40 -0
- package/dist/gatekeeper/cli-api.js +70 -4
- package/dist/gatekeeper/console.js +55 -28
- package/dist/gatekeeper/model.js +5 -23
- package/dist/gatekeeper/trust/policy.js +2 -1
- package/package.json +5 -3
- package/dist/analysis-core/analysis/source-notes/types.js +0 -1
- package/dist/analysis-core/chunks/2PSNOSJ2.js +0 -1
- package/dist/analysis-core/chunks/377MLK4M.js +0 -21
- package/dist/analysis-core/chunks/5DGPLXYB.js +0 -1
- package/dist/analysis-core/chunks/6B2HILSY.js +0 -1
- package/dist/analysis-core/chunks/6QY5BV5B.js +0 -14
- package/dist/analysis-core/chunks/6U2IR4XB.js +0 -1
- package/dist/analysis-core/chunks/DLPVYWHZ.js +0 -1
- package/dist/analysis-core/chunks/FOKDE64Y.js +0 -1
- package/dist/analysis-core/chunks/FSLWD2PE.js +0 -1
- package/dist/analysis-core/chunks/K2GNDX3W.js +0 -1
- package/dist/analysis-core/chunks/KTNA2KTN.js +0 -7
- package/dist/analysis-core/chunks/KWECQJ6X.js +0 -1
- package/dist/analysis-core/chunks/NIOS7U6C.js +0 -41
- package/dist/analysis-core/chunks/PECX3OXB.js +0 -1
- package/dist/analysis-core/chunks/PYKAERZZ.js +0 -1
- package/dist/analysis-core/chunks/QFY6A3MS.js +0 -66
- package/dist/analysis-core/chunks/SKVEBOGA.js +0 -1
- package/dist/analysis-core/chunks/STI4JE7L.js +0 -1
- package/dist/analysis-core/chunks/SVMEWGD3.js +0 -1
- package/dist/analysis-core/chunks/X7WZAA7S.js +0 -1
- package/dist/analysis-core/chunks/ZTOVBAG7.js +0 -1
- package/dist/analysis-core/data/finding-types.js +0 -1
package/dist/gatekeeper/model.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { unredactedAnswer } from "../contract/public-report.js";
|
|
3
|
-
import { executionRequest } from "../analysis-core/contracts/
|
|
3
|
+
import { executionRequest } from "../analysis-core/contracts/execution-request.js";
|
|
4
|
+
import { createModelCallIdentities } from "../analysis-core/contracts/model-call-identity.js";
|
|
4
5
|
export class ModelConfigurationError extends Error {
|
|
5
6
|
name = "ModelConfigurationError";
|
|
6
7
|
}
|
|
@@ -8,9 +9,7 @@ export function relayModel(options) {
|
|
|
8
9
|
const { client, bundleVersion, reservationId, reservationToken, onUsage } = options;
|
|
9
10
|
if (!bundleVersion.trim() || !reservationId.trim() || !reservationToken?.trim() || reservationToken.length > 256)
|
|
10
11
|
throw new ModelConfigurationError("Invalid relay configuration");
|
|
11
|
-
const identities =
|
|
12
|
-
const originals = new WeakMap();
|
|
13
|
-
let callCount = 0;
|
|
12
|
+
const identities = createModelCallIdentities({ mintId: options.mintId ?? randomUUID });
|
|
14
13
|
function view(retry) {
|
|
15
14
|
return {
|
|
16
15
|
settleStartedOnError: true,
|
|
@@ -29,24 +28,7 @@ export function relayModel(options) {
|
|
|
29
28
|
throw new Error("Invalid relay request data");
|
|
30
29
|
}
|
|
31
30
|
execution.onSend?.(inputBytes);
|
|
32
|
-
const
|
|
33
|
-
const matching = identities.get(key);
|
|
34
|
-
let identity;
|
|
35
|
-
if (retry > 0) {
|
|
36
|
-
const original = originals.get(request);
|
|
37
|
-
const candidates = original ? [...original].filter(id => matching?.has(id)) : [...matching ?? []];
|
|
38
|
-
if (candidates.length !== 1)
|
|
39
|
-
throw new Error("Ambiguous relay call identity");
|
|
40
|
-
identity = candidates[0];
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (callCount >= 4096)
|
|
44
|
-
throw new Error("Relay call limit reached");
|
|
45
|
-
identity = randomUUID();
|
|
46
|
-
callCount++;
|
|
47
|
-
identities.set(key, new Set([...matching ?? [], identity]));
|
|
48
|
-
originals.set(request, new Set([...originals.get(request) ?? [], identity]));
|
|
49
|
-
}
|
|
31
|
+
const identity = identities.resolve({ snapshot, originalKey: request, retry });
|
|
50
32
|
let reply;
|
|
51
33
|
try {
|
|
52
34
|
const signals = [options.signal, execution.signal].filter((signal) => !!signal);
|
|
@@ -29,9 +29,10 @@ export const workloadPolicy = z.object({
|
|
|
29
29
|
.refine(subject => workloadZones.some(zone => subject.includes(`/zones/${zone}/`)))),
|
|
30
30
|
imageSigningKeyIds: values(z.string().regex(/^[0-9a-f]{64}$/)),
|
|
31
31
|
}).strict();
|
|
32
|
+
export const engineRelease = z.strictObject({ imageDigest: z.string().regex(/^sha256:[0-9a-f]{64}$/), engine: enginePin });
|
|
32
33
|
const productionTrust = workloadPolicy.extend({
|
|
33
34
|
imageDigests: z.array(z.string().regex(/^sha256:[0-9a-f]{64}$/)).min(1),
|
|
34
|
-
engineReleases: z.array(
|
|
35
|
+
engineReleases: z.array(engineRelease).min(1).optional(),
|
|
35
36
|
}).refine(value => !value.engineReleases || value.engineReleases.every(release => value.imageDigests.includes(release.imageDigest)) &&
|
|
36
37
|
new Set(value.engineReleases.map(release => release.imageDigest)).size === value.engineReleases.length, "Engine release image differs");
|
|
37
38
|
export function validateWorkloadPolicy(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@counterfact-labs/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"homepage": "https://counterfactlabs.com",
|
|
5
5
|
"relaySource": "https://github.com/counterfact-labs/sealed-relay",
|
|
6
6
|
"type": "module",
|
|
@@ -20,10 +20,12 @@
|
|
|
20
20
|
"bench:replay": "tsx bench/replay.ts",
|
|
21
21
|
"bench:importer": "tsx bench/importer-coverage.ts",
|
|
22
22
|
"typecheck": "tsc --noEmit",
|
|
23
|
-
"test": "tsx --test ${TEST_SHARD:+--test-shard=$TEST_SHARD} --test-concurrency=4 --test-timeout=600000 \"core/**/*.test.ts\" \"adapters/**/*.test.ts\" \"cli/**/*.test.ts\" \"bench/**/*.test.ts\" \"bundle/**/*.test.ts\" \"contract/**/*.test.ts\" \"gatekeeper/**/*.test.ts\" \"relay/**/*.test.ts\" \"transport/**/*.test.ts\" \"packages/core/src/**/*.test.ts\" \"packages/core/*.test.ts\" \"packages/setup-pings/src/**/*.test.ts\" \"scripts/**/*.test.ts\"",
|
|
23
|
+
"test": "tsx --test ${TEST_SHARD:+--test-shard=$TEST_SHARD} --test-concurrency=4 --test-timeout=600000 \"core/**/*.test.ts\" \"adapters/**/*.test.ts\" \"cli/**/*.test.ts\" \"bench/**/*.test.ts\" \"bundle/**/*.test.ts\" \"contract/**/*.test.ts\" \"gatekeeper/**/*.test.ts\" \"relay/**/*.test.ts\" \"transport/**/*.test.ts\" \"packages/core/src/**/*.test.ts\" \"packages/core/*.test.ts\" \"packages/setup-pings/src/**/*.test.ts\" \"scripts/**/*.test.ts\" \".github/scripts/*.test.ts\"",
|
|
24
24
|
"build:core": "npm run build --workspace @counterfact-labs/analysis-core",
|
|
25
25
|
"build:setup-pings": "npm run build --workspace @counterfact-labs/setup-pings",
|
|
26
26
|
"pretest": "npm run build:core && npm run build:setup-pings",
|
|
27
|
+
"pretest:integration": "npm run build:core && npm run build:setup-pings",
|
|
28
|
+
"test:integration": "tsx --import ./tests/integration/offline.mjs --test --test-concurrency=1 --test-timeout=240000 tests/integration/*.test.ts",
|
|
27
29
|
"release:core": "tsx scripts/release-core.ts",
|
|
28
30
|
"build:cli": "npm run build:setup-pings && tsx scripts/build-cli.ts",
|
|
29
31
|
"prepack": "npm run build:core && npm run build:cli",
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
"tsx": "4.23.15",
|
|
46
48
|
"typescript": "6.0.3",
|
|
47
49
|
"typescript-eslint": "8.64.0",
|
|
48
|
-
"@counterfact-labs/analysis-core": "0.8.
|
|
50
|
+
"@counterfact-labs/analysis-core": "0.8.3",
|
|
49
51
|
"@counterfact-labs/setup-pings": "0.1.0"
|
|
50
52
|
},
|
|
51
53
|
"workspaces": [
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as c}from"../../chunks/PYKAERZZ.js";import{d as a,e as b}from"../../chunks/KWECQJ6X.js";import"../../chunks/FSLWD2PE.js";export{a as SOURCE_ROLES,c as rolesForCategory,b as sourceNotesSchema};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as f}from"./724WZMYW.js";function g(o){return o.skippedFiles??(o.notRead??[]).map(({path:t,kind:r})=>({path:t,reason:r==="prompt-too-large"?"too-large":"allowance"}))}function u(...o){let t={"secret-content":-7,secret:-6,hidden:-5,excluded:-4,"wrong-type":-3,empty:-2,"out-of-scope":-1,"too-large":0,allowance:1,"tool-limit":2,"scan-limit":3,total:4,unreadable:5,missing:6},r=new Map;for(let n of o)for(let e of n??[]){let s=r.get(e.path);(!s||t[e.reason]<t[s.reason])&&r.set(e.path,e)}return[...r.values()]}function d(o,t=0){let r=u(o),n=(...i)=>r.filter(({reason:p})=>i.includes(p)).length,e=r.filter(i=>i.reason==="secret-content").map(i=>f(i.path)),s=n("too-large"),a=n("allowance","tool-limit"),l=n("total","scan-limit"),c=n("missing","unreadable");return s&&e.push(`${s} ${s===1?"file was":"files were"} too big to read.`),a&&e.push(`${a} ${a===1?"file wasn't":"files weren't"} read because the file allowance was reached.`),l&&e.push(`${l} ${l===1?"file wasn't":"files weren't"} read because the repository is large.`),c&&e.push(`${c} ${c===1?"file couldn't":"files couldn't"} be read, so some tools may be missing.`),t>0&&e.push(`${t} more ${t===1?"file wasn't":"files weren't"} read.`),e}function w(o,t){return t?[...o.filter(n=>{let e=/^(\d+) more (?:file wasn't|files weren't) read\.$/.exec(n);return e?(t+=Number(e[1]),!1):!0}),...d([],t)]:[...o]}export{g as a,u as b,d as c,w as d};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import{c as Oe,e as Ut}from"./ZTOVBAG7.js";import{a as G,b as De,c as Bt,e as zt,f as Wt,g as Dt,h as Gt,i as Ge,j as Kt,k as Jt,m as qt,n as fe}from"./KTNA2KTN.js";import{b as de}from"./2PSNOSJ2.js";import{$ as wt,$a as $t,A as Z,C as dt,G as ut,I as Ie,J as le,Ja as St,K as ht,N as gt,O as ue,R as he,T as Se,Va as Ot,Wa as xt,Xa as Ct,Y as yt,Ya as Be,Z as kt,Za as Mt,_ as bt,a as lt,ab as ze,b as ft,bb as Ft,cb as We,d as Te,db as At,e as q,eb as jt,f as Pe,fb as Et,g as ct,gb as Rt,i as te,ia as vt,ib as Lt,jb as Nt,k as pt,kb as _t,l as ve,lb as Tt,m as ee,n as K,o as Q,p as oe,q as T,qb as It,r as B,ra as R,v as J,w as ne,y as mt}from"./NIOS7U6C.js";import{e as Pt}from"./YUY436SM.js";import{b as X,c as D}from"./C6X5GDG4.js";function Ke(e,t,o){if(!ee(e)||!t.filenameReferences?.length)return o;let r=o.agents.flatMap(s=>s.prompt.kind==="dedicated"?[{path:s.prompt.path}]:[]),i=Mt(t.filenameReferences,r);return{...o,agents:o.agents.map(s=>{if(s.prompt.kind!=="dedicated")return s;let c=s.prompt.path,l=i.filter(u=>u.promptPath===c&&!s.files.some(b=>b.path===u.readerPath)&&R(e,{path:u.readerPath},{purpose:"override",route:"github",root:t.root}).admitted);return l.length?{...s,files:[...s.files,...l.map(u=>({path:u.readerPath,role:"reference",label:"prompt filename reference"}))]}:s})}}function se(e,t,o){return e.filter(r=>t.some(i=>i.includes(o(r))))}function Yt(e,t,o){if(!e.length||o&&!K(o.settings))return;let r;if(o&&!q(o.settings)){let i=Object.keys(o.files).filter(l=>D(l,o.root)!==null&&R(o.settings,{path:l},{purpose:"override",route:"github",root:o.root}).admitted),s=i.filter(l=>lt(D(l,o.root))).sort((l,u)=>ft(D(l,o.root),D(u,o.root)));if(!s.length)return;let c=se(i.filter(l=>!s.includes(l)&&te(l)).sort(),s.map(l=>o.files[l]),l=>D(l,o.root));r=[...s.map(l=>({path:l,role:"reference",label:"developer guidance"})),...c.map(l=>({path:l,role:"reference",label:null}))]}else{if(!t||t.prompt.kind!=="fallback")return;let i=t.prompt.path;if(e.some(s=>s.files.some(c=>c.path===i)))return;r=t.files.map(s=>({...s,role:"reference",label:s.role==="system prompt"?"developer guidance":s.label}))}r=r.filter(i=>!e.some(s=>s.files.some(c=>c.path===i.path))),r.length&&(e[0]={...e[0],files:[...e[0].files,...r],sharedReferencePaths:[...e[0].sharedReferencePaths??[],...r.map(i=>i.path)]})}function yn({prompt:e,link:t}){return{path:t?.callPath??e.path,...t?{line:t.callLine}:{},symbol:e.symbol,promptPath:e.path,promptStart:e.start,...t?.kind==="L4"?{loadedPrompt:!0,...t.callStart!==void 0?{callStart:t.callStart}:{}}:{}}}function Vt(e,t,o){return It(e,t,o)}var xe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function No(e,t,o,r={}){let i=new Map(e.map(s=>[xe(s),s]));return t.flatMap(s=>{let c=Object.hasOwn(o,s)?o[s]:void 0;if(c===void 0||!R(r,{path:s},{purpose:"code-support",route:"github"}).admitted)return[];let l=oe(s,c,Q(s)).toks;return l.flatMap((u,b)=>{if(!B(u))return[];let p=i.get(xe(u.text));if(!p)return[];let v=!1;if(B(l[b-1],"function")||B(l[b-1],"def"))v=T(l[b+1],"(");else if(["const","let","var"].some(m=>B(l[b-1],m))){for(let m=b+1;m<l.length&&m<b+80&&!T(l[m],";");m++)if(T(l[m],"=")){let f=B(l[m+1],"async")?m+2:m+1,y=T(l[f],"(")?J(l,f)+1:f+1;v=B(l[f],"function")||T(l[y],"=")&&T(l[y+1],">");break}}return v?[{name:p,sourcePath:s,sourceLine:u.line}]:[]})})}function Xt(e,t,o,r,i={}){let s=new Set(e.map(xe)),c=p=>R(i,{path:p},{purpose:"code-support",route:"github"}).admitted,l=p=>No(e,[p],o,i).length>0,u=t.filter(p=>c(p)&&l(p)),b=r.filter(p=>c(p)&&s.has(xe(p.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(o[p]===void 0||l(p))).sort();return[...new Set([...u,...b])]}function Ce(e){return ee(e,"CF_IMPORT_MANIFEST")}function ge(e,t){if(!le(e))return null;let o=new Set(t.paths),r=ht(e,t),i=new Set(t.skillPaths),s=new Set(t.referencePaths),c=k=>Object.hasOwn(t.files,k)?Buffer.byteLength(t.files[k]):t.sizes?.get(k),l=t.selected??[...new Set([...t.skillPaths,...Object.keys(t.files).filter(k=>Ie(k,{nested:!0})?.reference)])].filter(k=>Object.hasOwn(t.files,k)).map(k=>({path:k,size:c(k)})),u=[...new Map(l.filter(k=>!s.has(k.path)||i.has(k.path)).map(k=>[k.path,k])).values()],b=new Set(u.map(k=>k.path)),p=u.filter(k=>i.has(k.path)),v=new Set(u.filter(k=>Ie(k.path,{nested:!0})?.reference).map(k=>k.path)),m=p.length,f=Z.conventionImport.skillBytes-u.filter(k=>i.has(k.path)||v.has(k.path)).reduce((k,P)=>k+(c(P.path)??P.size),0),y=ve(e)?Z.codeAgent.importBytes-u.reduce((k,P)=>k+(c(P.path)??P.size),0):1/0,h=new Map(p.map(k=>[k.path,null])),a=(k,P=!1)=>{if(h.has(k))return;let n=c(k),g=v.has(k),w=R(e,{path:k,size:n,text:t.files[k]},{...t.admission,purpose:"skill",route:"github",root:t.root,listing:o,managedFiles:t.files}),x=b.has(k)?0:n,C=w.admitted?n===void 0?"missing":!g&&m>=Z.conventionImport.skillFiles?"allowance":!g&&(n>f||x>y)?"total":null:w.reason;h.set(k,C),!g&&(P||!C)&&m++,!g&&!C&&(f-=n,y-=x)};for(let k of s)a(k,!0);let d=[...new Set(t.skillPaths)].sort().filter(k=>Object.hasOwn(t.files,k)).map(k=>{let P={ownerPath:k,files:[],cycles:[],unresolved:[],refused:[]},n=new Set([k]);for(let g of r.references.filter(w=>w.ownerPath===k)){if(!n.has(g.fromPath))continue;a(g.path);let w=h.get(g.path);if(w){P.refused.push({path:g.path,reason:w});continue}n.add(g.path);let x=P.files.find(C=>C.path===g.path);x||(x={path:g.path,evidence:[],sharedOwners:[]},P.files.push(x)),x.evidence.push(g)}return P.cycles=r.cycles.filter(g=>g.ownerPath===k&&n.has(g.fromPath)),P.unresolved=r.unresolved.filter(g=>g.ownerPath===k&&n.has(g.fromPath)),P.refused=de(P.refused),P}),S=new Map;for(let k of d)for(let P of k.files)S.set(P.path,[...S.get(P.path)??[],k.ownerPath]);for(let k of d)for(let P of k.files)P.sharedOwners=S.get(P.path);return d}var Zt="model call";function Qt(e,t){let o=Vt(e.ownPaths,t,e.toolCall);return{tools:o.tools.map(r=>({tool:r,from:o.from[r.name]})),toolWarnings:o.warnings}}function qe(e=new Map,t){return{left:Math.max(0,Z.codeAgent.importBytes-[...e.values()].reduce((o,r)=>o+r,0)),chosen:new Set([...e.keys()].filter(o=>!t?.has(o))),...t?{replacementBytes:t}:{}}}function _o(e,t){return e.modelId??(!e.documentation&&t.length===1?t[0]:null)}function qn(e,t,o){return To(e,_o(e,t),o)}function To(e,t,o){let{prompt:r,link:i}=e,s=[r.kind==="file"?{role:"system prompt",label:null,path:r.path}:{role:"system prompt",label:r.symbol??`line ${r.span.from}`,path:r.path,span:{from:r.span.from,to:r.span.to},...r.filledAtRunTime?{filledAtRunTime:!0}:{}}];for(let l of e.alsoLoads??[])s.push({role:"system prompt",label:"also loaded",path:l});i&&s.push({role:"code",label:Zt,path:i.callPath}),i?.wrapper&&s.push({role:"code",label:"model wrapper",path:i.wrapper.path}),t&&s.push({role:"code",label:"model setting",path:t.path}),e.shape&&s.push({role:"code",label:"answer shape",path:e.shape.path});let c=new Set;return s.filter(l=>!c.has(l.path)&&!!c.add(l.path)).map(l=>Pe(o,l.path,l.path===r.path&&e.promptSource==="marker")?l:{...l,role:"reference"})}function Un(e,t){let{prompt:o}=e,r=t[o.path]??"";return o.kind==="file"?r:r.split(`
|
|
2
|
-
`).slice(o.span.from-1,o.span.to).join(`
|
|
3
|
-
`)}function Yn(e,t){return t?Object.fromEntries(t.files.filter(o=>e[o.path]!==void 0).map(o=>[o.path,e[o.path]])):e}function Ht(e,t,o){let{files:r,sizes:i,root:s,total:c=qe()}=o,l=[...new Set([...t.ownPaths,...o.guides??[]])],u=[],b=new Set(l);l=l.filter(n=>{let g=R(e,{path:n},{purpose:"override",route:"github"});return g.admitted||u.push({path:n,reason:g.reason}),g.admitted});let p=[...i.keys()].filter(n=>{let g=R(e,{path:n},{purpose:"code-support",route:"github",root:s});return!g.admitted&&!b.has(n)&&u.push({path:n,reason:g.reason}),g.admitted}),v=Object.fromEntries(l.filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),m=Tt(v,p).filter(n=>!l.includes(n)),f=Object.fromEntries([...l,...m].filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),y=Qt({ownPaths:l,toolCall:t.toolCall},f).tools.map(({tool:n})=>n.name),h=new Set(Xt(y,m,r,p,e)),a=Je(e,l,{...o,total:c});for(let n of new Set([...l,...m,...h]))a.take(n,h.has(n)&&!l.includes(n));let{paths:d,skipped:S}=a,k=Object.fromEntries(d.filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),P=Qt(t,k);return{paths:d,skipped:S,refused:de(u,a.refused),...P}}function Je(e,t,{sizes:o,total:r=qe(),pool:i},s=[]){let c=[],l=[],u=[],b=Z.codeAgent.extraBytes,p=0;return{paths:c,skipped:l,refused:u,take:(m,f,y=!1)=>{if(c.includes(m))return!0;let h=o.get(m),a=m===t[0],d=s.includes(m),S=[r,...i?[i]:[]],k=w=>Math.max(0,(h??0)-(w.replacementBytes?.get(m)??0)),P=d?"override":t.includes(m)||y?"pointer":"code-support",n=R(e,{path:m,size:h},{purpose:P,route:"github"});n.admitted||u.push({path:m,reason:n.reason});let g=h===void 0?"missing":n.admitted?!d&&!a&&h>b?"allowance":!d&&S.some(w=>!w.chosen.has(m)&&(k(w)>w.left||w.wholeBytesLeft!==void 0&&h>w.wholeBytesLeft))?"total":f&&p>=Z.codeAgent.toolCodeFiles?"tool-limit":null:n.reason;if(g)return l.push({path:m,reason:g}),!1;!a&&!d&&(b-=h),f&&p++;for(let w of S)w.chosen.has(m)||(w.left-=k(w),w.wholeBytesLeft!==void 0&&(w.wholeBytesLeft-=h),w.chosen.add(m));return c.push(m),!0}}}function eo(e,t,o){if(!Ce(e)&&!(ee(e)&&t.some(d=>d.fileProfile==="layout")))return null;let r=o.scopes??qt(e,[...o.sizes.keys()],o.root??void 0,{},o.agentConfigurations??{}),i=o.total??qe(),s=new Set(o.confirmationIds),c=o.selectedIds&&new Set(o.selectedIds),l=t.filter(d=>!c||c.has(d.id));for(let d of l)for(let{path:S}of d.ownFiles.filter(k=>d.fileProfile==="convention"||d.sharedReferencePaths?.includes(k.path))){let k=o.sizes.get(S),P=d.scopeProof?.paths.includes(S)?void 0:o.root;k===void 0||i.chosen.has(S)||!R(e,{path:S},{purpose:"override",route:"github",root:P}).admitted||(i.left-=Math.max(0,k-(i.replacementBytes?.get(S)??0)),i.wholeBytesLeft!==void 0&&(i.wholeBytesLeft-=k),i.chosen.add(S))}let u=(d,S)=>{for(let k of d){let P=k.ownFiles[0]?.path;if(!P)continue;let n=r.ownerOf(P);!n||n.key!==k.scope.key||n.folder!==k.scope.folder||!R(e,{path:P},{purpose:"pointer",route:"github",root:o.root}).admitted||Je(e,[P],{...o,total:S,pool:void 0}).take(P,!1)}};u(l,i);let b,p=new Set,v=new Set(o.sizes.keys()),m=Ft(v).flatMap(d=>o.files[d]===void 0?[]:We(d,o.files[d],v,{root:o.root??void 0})),f=new Map(m.map(d=>[d,d.to&&o.files[d.to]!==void 0?At(d.to,o.files[d.to],d.imported,v,e):[]])),y=new Set(m.filter(d=>{let S=d.to&&Q(d.to),k=d.to&&o.files[d.to];return S&&k!==void 0&&k!==null&&!ze(oe(d.to,k,S),d.imported)})),h=t.map(d=>{let S=[...new Set(d.ownFiles.map($=>$.path))],k=new Set(d.fileProfile==="layout"?d.ownFiles.filter($=>$.role==="tools").map($=>$.path):[]),P={schemaVersion:1,agentId:d.id,scope:{...d.scope},files:[],edges:[],unresolved:[],refused:[]};if(c&&!c.has(d.id))return P;s.has(d.id)&&!b&&(b={left:Z.candidateFetch.check,chosen:new Set(p)},u(l.filter($=>s.has($.id)),b));let n=Je(e,S,{...o,total:i,pool:s.has(d.id)?b:void 0},d.fileProfile==="convention"?S:d.sharedReferencePaths),g=new Set(d.skillManifests?.flatMap($=>$.files.map(O=>O.path))),w=d.ownFiles.filter($=>$.role!=="reference"||!g.has($.path)||d.independentReferences?.includes($.path)).map($=>({path:$.path,symbol:null,role:$.role,evidence:null,span:$.span})),x=m.filter($=>$.to!==null&&S.includes($.to)),C=x.filter($=>new Set(x.filter(O=>O.to===$.to).map(O=>O.imported)).size>1),A=m.filter($=>!y.has($)&&(x.includes($)&&!d.toolCall&&!C.includes($)||f.get($).some(O=>{if(O.kind!=="graph-node"||!O.to||!S.includes(O.to)||!d.toolCall||d.toolCall.path!==O.to)return!1;let z=o.files[O.to];return z!==void 0&&jt(O.to,z,O.imported,d.toolCall)})));P.unresolved.push(...x.filter($=>!A.includes($)).map($=>({...$,reason:y.has($)?"missing":"unlinked"})));for(let $ of A)w.push({path:$.from,symbol:$.symbol,role:"config",evidence:$,explicit:!0});let M=new Set,E=new Map,j=new Set,N=new Set;for(let $=0;$<w.length;$++){let O=w[$],z=JSON.stringify([O.path,O.symbol,O.role]);if(M.has(z)){let F=P.files.find(L=>L.path===O.path);F&&O.span&&!F.spans.some(L=>L.from===O.span.from&&L.to===O.span.to)&&(F.spans.push(O.span),F.evidence.push({kind:"entry",from:O.path,to:O.path,span:O.span})),F&&O.evidence?.kind==="skill-reference"&&!F.evidence.some(L=>JSON.stringify(L)===JSON.stringify(O.evidence))&&F.evidence.push(O.evidence);continue}M.add(z);let _=r.ownerOf(O.path),ie=S.includes(O.path)&&d.scopeProof?.paths.includes(O.path),ce=R(e,{path:O.path},{purpose:S.includes(O.path)||O.explicit?"pointer":"code-support",route:"github",root:ie?void 0:o.root}),Ne=O.role==="reference"&&S.includes(O.path)&&(d.sharedReferencePaths?.includes(O.path)||d.skillManifests?.some(F=>P.files.some(L=>L.path===F.ownerPath)&&F.files.some(L=>L.path===O.path)&&!F.refused.some(L=>L.path===O.path))),it=ce.admitted?!ie&&(!_||!Ne&&(_.key!==d.scope.key||_.folder!==d.scope.folder))?"out-of-scope":!S.includes(O.path)&&t.some(F=>F.id!==d.id&&F.ownFiles.some((L,Y)=>L.path===O.path&&(Y===0||L.label===Zt)))?"other-agent":null:ce.reason;if(it){P.refused.push({path:O.path,reason:it});continue}let ae=o.files[O.path],_e=Q(O.path),pe=ae!==void 0&&_e?oe(O.path,ae,_e):null,me=pe&&O.symbol?ze(pe,O.symbol):null,H=me?.name??O.symbol;if(ae!==void 0&&!E.has(O.path)){let F=m.filter(I=>I.from===O.path),L=[...F.length?F:We(O.path,ae,v,{root:d.scope.folder,call:d.toolCall}),...[...N].filter(I=>I.to===O.path).flatMap(I=>f.get(I))];L.forEach(I=>j.add(I));let Y=$t(O.path,ae,v,S.includes(O.path)?d.toolCall:void 0,e).flatMap(I=>L.some(V=>!V.reason&&V.kind===I.kind&&V.symbol===I.symbol&&V.span.from===I.span.from)?[]:A.some(V=>V.to===O.path)&&!S.includes(O.path)&&(I.kind==="config"||I.kind==="graph-node")&&!I.reason?[{...I,reason:"unlinked"}]:[I]);E.set(O.path,[...Y,...L,...(o.links??[]).filter(I=>I.from===O.path)])}let at=E.get(O.path)??[];if(O.role==="code"&&O.evidence?.kind==="import"&&at.some(F=>F.reason==="external"&&F.usage==="call"&&(F.within===H||F.within===null)&&mt(F.source,_e))){P.refused.push({path:O.path,reason:"provider-transport"});continue}let Ro=k.has(O.path)||O.role==="tool"&&me?.params!=null&&!S.includes(O.path);if(!n.take(O.path,Ro,O.explicit))continue;P.unresolved.push(...m.filter(F=>F.from===O.path&&(F.reason||y.has(F))).map(F=>y.has(F)?{...F,reason:"missing"}:F));let U=P.files.find(F=>F.path===O.path);U||(U={path:O.path,roles:[],spans:[],evidence:[],sharedOwners:[]},P.files.push(U)),U.roles.includes(O.role)||U.roles.push(O.role);let we=O.span??(pe&&me?{from:pe.toks[me.from].line,to:pe.toks[me.to-1].endLine}:void 0);we&&!U.spans.some(F=>F.from===we.from&&F.to===we.to)&&U.spans.push(we),O.evidence?U.evidence.push(O.evidence):U.evidence.push({kind:"entry",from:O.path,to:O.path,...O.span?{span:O.span}:{}});for(let F of d.skillManifests??[])if(P.files.some(L=>L.path===F.ownerPath))for(let L of F.files)for(let Y of L.evidence)Y.fromPath===O.path&&w.push({path:L.path,symbol:null,role:"reference",explicit:!0,evidence:{kind:"skill-reference",from:Y.fromPath,to:L.path,span:Y.span}});if(ae!==void 0)for(let F of at){let L=F.usage==="reexport"&&(F.symbol===H||F.symbol==="*"),Y=F.usage==="call"&&F.within===H;if(!(F.kind!=="import"&&(H===null||F.within===H)||H!==null&&(L||Y)||F.reason==="dynamic"&&(H===null||F.within===H)))continue;if(!F.to||F.reason){P.unresolved.push(F);continue}let V=A.includes(F);V&&(N.add(F),E.delete(F.to)),P.edges.push(F);let Lo=F.kind==="tool-registration"?"tool":F.kind==="config"?"config":F.kind==="graph-node"?"workflow":L?O.role:"code";w.push({path:F.to,symbol:V?null:F.imported==="*"?O.symbol:F.imported,role:Lo,evidence:F,explicit:j.has(F)})}}if(P.refused.push(...de(n.skipped,n.refused)),P.unresolved=P.unresolved.filter($=>$.reason!=="unlinked"||!P.edges.some(O=>O.from===$.from&&O.to===$.to&&O.kind===$.kind&&O.symbol===$.symbol&&O.span.from===$.span.from)),P.unresolved=[...new Map(P.unresolved.map($=>[JSON.stringify($),$])).values()],P.refused=P.refused.filter(($,O,z)=>z.findIndex(_=>_.path===$.path&&_.reason===$.reason)===O),!s.has(d.id))for(let $ of P.files)p.add($.path);return P}),a=new Map;for(let d of h)for(let S of d.files)a.set(S.path,[...a.get(S.path)??[],d.agentId]);for(let d of h)for(let S of d.files)S.sharedOwners=[...new Set(a.get(S.path))].sort();return h}function Ue(e,t){return["[","{"].some(o=>T(e.source.toks[t.from],o))&&J(e.source.toks,t.from)===t.to?{...t,to:t.to+1}:e.calls.find(o=>o.from===t.from&&o.to===t.to+1&&T(e.source.toks[t.to],")"))??t}function W(e,t,o=new Set){let{toks:r}=e.source;if(t.to!==t.from+1||!B(r[t.from])||["True","False","None"].includes(r[t.from].text))return t;let i=e.binding(r[t.from].text,t.from);return!i||i.append||!e.bindingIsCertain(i,t.from)||o.has(i.at)||e.functions.some(s=>s.from<t.from&&t.from<s.to&&s.params?.includes(i.name))?null:W(e,Ue(e,i),new Set([...o,i.at]))}import{posix as to}from"node:path";function oo(e,t,o,r,i){let{source:{path:s,toks:c}}=e,l=[],u=[],b=[],p=[],v=(h,a)=>p.push({path:h,reason:a}),m=(h,a,d,S=null)=>({path:a,role:h,label:S,...d?{span:d}:{}}),f=(h,a)=>{let d=e.importBinding(h,a),S=t.filter(g=>g.name===h&&g.from<a&&(g.params!==null||g.kind==="class")&&(!e.owner(g.from)||e.owner(g.from)===e.owner(a)));if(!d)return S.length===1?{path:s,span:{from:c[S[0].from].line,to:c[S[0].to-1].endLine}}:null;let k=d.module.source,P=i.length===1?to.dirname(to.dirname(i[0])):"",n=Ot(k.startsWith(".")?s:`${P?`${P}/`:""}__root__.py`,k.startsWith(".")?k:`.${k}`,[d.name],"py",r);return n?{path:n}:null},y=o&&W(e,o);if(y&&T(c[y.from],"[")&&J(c,y.from)===y.to-1)for(let h of ne(c,y.from)){let a=h.to===h.from+1&&B(c[h.from])&&!e.binding(c[h.from].text,h.from)?h:W(e,h);if(!a||!B(c[a.from])){v(s,"dynamic");continue}let d=c[a.from].text;if(!(a.to===a.from+1||T(c[a.from+1],"(")&&J(c,a.from+1)===a.to-1)){v(s,"dynamic");continue}if(e.functions.some(P=>P.from<a.from&&a.from<P.to&&P.params?.includes(d))){v(s,"dynamic");continue}if(!e.importBinding(d,a.from)&&!t.some(P=>P.name===d&&(P.params!==null||P.kind==="class")&&P.from<a.from)){v(s,"dynamic");continue}l.push(d);let k=f(d,a.from);k&&(b.push(m("tools",k.path,k.span,d)),u.push(k.path))}else o&&v(s,"dynamic");return{names:l,files:b,proofPaths:u,refused:p}}function no(e,t,o,r,i,s){let c=t.source,{path:l,toks:u}=c,{files:b,paths:p,frameworks:v,defaultsByPath:m}=s,f={prompt:{kind:"none"},files:[]},y=[],h,a=(n,g)=>y.push({path:n,reason:g}),d=(n,g,w,x=null)=>({path:g,role:n,label:x,...w?{span:w}:{}});m.has(l)||m.set(l,Ge(l,c.text,p));let S=m.get(l),k=n=>{f.layoutProof??={kind:"outside-loader",paths:[]},f.layoutProof.paths.push(n);let g=b[n];if(g===void 0){f.files.push(d("template",n)),a(n,"missing");return}let w=Gt(g,e);if(w.unresolved.length||!w.fields.some(x=>x.key==="system_prompt"&&x.value!==null)){a(n,"invalid");return}for(let x of w.fields.filter(C=>C.value!==null))f.files.push(d(x.key==="system_prompt"?"system prompt":"template",n,x.span,x.key)),x.key==="system_prompt"&&(f.prompt={kind:"entry",path:n,span:x.span,text:x.value})},P=o.get("prompt_templates")??o.get("system_prompt");if(P){let n=W(t,P),g=n&&ue(c,n);if(g&&o.has("system_prompt"))f.prompt={kind:"entry",path:l,span:g.span,text:u[n.from].value},h={path:l,start:g.start},f.files.push(d("system prompt",l,g.span));else if(n&&T(u[n.from],"{")&&J(u,n.from)===n.to-1){let w=!1,x=(C,A="")=>{let M=new Set;for(let E of ne(u,C.from)){let j=u[E.from]?.kind==="string"?u[E.from].value:null;if(!j||M.has(j)||!T(u[E.from+1],":")){a(l,"invalid"),w=!0;return}M.add(j);let N=W(t,{from:E.from+2,to:E.to}),$=N&&ue(c,N);$?(f.files.push(d(j==="system_prompt"?"system prompt":"template",l,$.span,A+j)),j==="system_prompt"&&!A&&(f.prompt={kind:"entry",path:l,span:$.span,text:u[N.from].value},h={path:l,start:$.start})):N&&T(u[N.from],"{")?x(N,`${A}${j}.`):a(l,"dynamic")}};x(n),w&&(f.prompt={kind:"none"},f.files=[])}else{let w=n&&S.find(x=>x.start===u[n.from].start&&x.end===u[n.to-1].end);w?.path&&!w.reason?k(w.path):a(l,"dynamic")}}else if(r.args.some(n=>!B(u[n.from])||!T(u[n.from+1],"=")))a(l,"dynamic");else if(v.length===1){let n=v[0],g=b[n];if(g===void 0)f.files.push(d("config",n)),f.layoutProof={kind:"outside-loader",paths:[n]};else{m.has(n)||m.set(n,Ge(n,g,p));let w=m.get(n).filter(j=>j.className===i&&j.binding==="prompt_templates"&&j.forwarded),x=o.get("use_structured_outputs_internally"),C=x?W(t,x):null,A=C&&C.to===C.from+1&&["True","False"].includes(u[C.from].text)?u[C.from].text==="True":null,M=w.filter(j=>j.when?.every(N=>N.parameter==="use_structured_outputs_internally"&&N.value===(x?A:N.defaultValue))),E=M.length===1?M[0]:null;E?.path&&(!E.reason||E.reason==="missing")?k(E.path):a(n,"dynamic")}}else a(l,v.length>1?"dynamic":"missing");return{...f,promptSite:h,refused:y}}function so(e,t,o=t.files){let r={agents:[],refused:[]};if(!K(e))return r;let i={...o,...t.files},s=new Set([...Object.keys(i),...t.listedPaths??[]]),c=new Set(Et(e,[...s],t.root)),l=[...s].filter(p=>/(?:^|\/)smolagents\/agents\.py$/.test(p)),u=new Map,b=(p,v)=>r.refused.push({path:p,reason:v});for(let[p,v]of Object.entries(t.files)){if(!v.includes("smolagents")||ut(p,{listing:s,root:t.root})&&!dt(e,p,t.root)||!/\.py$/i.test(p)&&!c.has(p)||!R(e,{path:p,size:Buffer.byteLength(v)},{purpose:"code-scan",route:"github",root:t.root,listing:s}).admitted)continue;let m=c.has(p)?Rt(p,v).filter(n=>n.lang==="py"):null,f=m?Lt(v,m):v,y=oe(p,f,"py"),h=xt(y,{includeMembers:!0}),a=Ct(y,h,{enclosingBindings:!0}),{toks:d}=y,S=[],k=n=>{let g=n&&W(a,n);return g&&ue(y,g)?d[g.from].value:null},P=(n,g,w,x=null)=>({path:g,role:n,label:x,...w?{span:w}:{}});for(let n of a.calls){let g=a.importBinding(n.callee,n.from);if(!g||!["smolagents","smolagents.agents"].includes(g.module.source)||!["CodeAgent","ToolCallingAgent"].includes(g.name))continue;let w=new Map(n.args.flatMap(O=>B(d[O.from])&&T(d[O.from+1],"=")?[[d[O.from].text,{from:O.from+2,to:O.to}]]:[])),x=m?.find(O=>O.span.from<=d[n.from].line&&d[n.from].line<=O.span.to);if(x&&(g.module.line<x.span.from||x.span.to<g.module.line)){let O=w.get("managed_agents"),z=O&&W(a,O);if(!(z&&T(d[z.from],"[")&&ne(d,z.from).some(ie=>{let ce=W(a,ie);return ce&&S.some(Ne=>Ne.at===ce.from)})))continue}let A=a.assignments.find(O=>O.from===n.from&&Ue(a,O).to===n.to)?.name??`line-${d[n.from].line}`,M=`smolagents:${JSON.stringify([p,d[n.from].start])}`,E={from:d[n.from].line,to:d[n.to-1].endLine},j={key:M,name:k(w.get("name"))??A,model:null,description:k(w.get("description")),prompt:{kind:"none"},files:[],skills:[],tools:[],subagents:[],layoutCall:{path:p,callStart:d[n.from].start,line:E.from,loadedPrompt:!0}},N=no(e,a,w,n,g.name,{files:i,paths:s,frameworks:l,defaultsByPath:u});j.prompt=N.prompt,j.files.push(...N.files),N.layoutProof&&(j.layoutProof=N.layoutProof),N.promptSite&&(j.layoutCall.promptPath=N.promptSite.path,j.layoutCall.promptStart=N.promptSite.start),r.refused.push(...N.refused),j.files.push(P(m?"system prompt":"config",p,E));let $=oo(a,h,w.get("tools"),s,l);j.tools=$.names,j.files.push(...$.files),$.proofPaths.length&&(j.layoutProof??={kind:"outside-loader",paths:[]},j.layoutProof.paths.push(...$.proofPaths)),r.refused.push(...$.refused),r.agents.push(j),S.push({agent:j,name:A,at:n.from,children:w.get("managed_agents")})}for(let n of S){if(!n.children)continue;let g=W(a,n.children);if(!g||!T(d[g.from],"[")||J(d,g.from)!==g.to-1){b(p,"dynamic");continue}for(let w of ne(d,g.from)){let x=W(a,w),C=x&&S.find(M=>M.at===x.from&&x.to===a.calls.find(E=>E.from===M.at)?.to);if(!C||C===n){b(p,"dynamic");continue}let A=C.agent.prompt;n.agent.subagents.push({key:C.agent.key,path:A.kind==="none"?p:A.path,name:C.agent.name,description:C.agent.description,prompt:A.kind==="entry"?A.text:"",tools:C.agent.tools,skillPaths:[],files:C.agent.files})}}}return r}import{basename as Go}from"node:path";import{basename as zo}from"node:path";var io=/^[\w.*:/()-]+$/,ao=/^(?:true|false|null|~|[-+]?(?:\d[\d_.eExXoObB+-]*|\.\d[\d_eE+-]*|\.inf|\.nan)|\d{4}-\d{1,2}-\d{1,2}(?:[Tt].*)?)$/i,$e=e=>io.test(e)&&!e.startsWith("*")&&!ao.test(e);function Me(e){if(e.startsWith('"'))try{return JSON.parse(e)}catch{return e}return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/''/g,"'"):e}function ke(e,t=!1,o=!1){let r=[],i="",s=0,c=-1,l=0,u=()=>{c>=0&&r.push([c,l]),c=-1};for(let b=0;b<e.length;b++){let p=e[b];if(i){i==='"'&&p==="\\"?b++:p===i&&(i==="'"&&e[b+1]==="'"?b++:i=""),l=b+1;continue}if(!o&&p==="#"&&(b===0||/\s/.test(e[b-1]))){if(!t)return u(),{spans:r,end:b,comment:e.slice(b)};let v=e.indexOf(`
|
|
4
|
-
`,b);b=v<0?e.length:v;continue}if(t&&p==="]"&&s===0)return u(),{spans:r,end:b,comment:""};if(p===","&&s===0){u();continue}/\s/.test(p)||(c<0&&(c=b),(p==='"'||p==="'")&&(c===b||s>0)?i=p:p==="("?s++:p===")"&&s>0&&s--,l=b+1)}if(t)throw new Error("Unclosed frontmatter tool list");return u(),{spans:r,end:e.length,comment:""}}function ro(e,t){let o=e.startsWith("["),r=ke(o?e.slice(1):e,o),i=(o?e.slice(1,r.end+1):e.slice(0,r.end)).trimEnd(),s=!o&&r.spans.length===1&&/^["']/.test(i)&&Me(i)!==i?i[0]:"",c=s?Me(i):o?e.slice(1,r.end+1):e.slice(0,r.end).trimEnd(),l=o?r.spans:ke(c,!1,!!s).spans,u=0,b=l.flatMap(([v,m],f)=>{let y=c.slice(v,m),h=Me(y),a=c.slice(u,v).replace(/[^\S\n]*#[^\n]*/g,""),d=o?c.slice(m,l[f+1]?.[0]??c.length):"",S=d.match(/[^\S\n]*#[^\n]*/g)?.join(`
|
|
5
|
-
`)??"";return u=m,h?[{name:h,raw:y,before:a,note:S,noteAfterComma:/^[^\S\n]*,/.test(d)}]:[]}),p=o?e.slice(r.end+2).split(`
|
|
6
|
-
`)[0]:e.slice(i.length);return{style:o?"flow":"comma",outerQuote:s,quote:b.find(v=>/^["']/.test(v.raw))?.raw[0]??"",prefix:"",suffix:p,head:(b[0]?.before??c).replace(/,/g,""),tail:b.length?c.slice(u).replace(/[^\S\n]*#[^\n]*/g,""):"",separator:b[1]?.before.replace(/#[^\n]*/g,"")??(c.includes(`
|
|
7
|
-
`)?`,
|
|
8
|
-
${c.match(/\n([^\S\n]*)/)[1]}`:", "),entries:b,first:t,last:t+e.slice(0,o?r.end+2:e.length).split(`
|
|
9
|
-
`).length-1,indent:" - ",blockComments:[]}}function Io(e){let t=he(e),o=t?.raw.map(l=>l.replace(/\r$/,""))??null,r=[],i=[],s={},c=[];if(o)for(let l=0;l<o.length;l++){let u=/^([A-Za-z_][\w-]*\s*:[^\S\n]*)(.*)$/.exec(o[l]);if(!u||!/^tools\s*:/i.test(u[1]))continue;let b=ke(u[2]),p;u[2].startsWith("[")?p=ro(o.slice(l).join(`
|
|
10
|
-
`).slice(u[1].length),l):p=ro(u[2],l),p.prefix=u[1];let v=p.style==="flow"?ke(p.suffix).comment:b.comment;if(v&&(s[p.style==="flow"?p.last:l]=v),p.style==="flow")for(let m of p.entries)m.note&&c.push({tool:m.name,comment:m.note.trim()});if(!u[2].slice(0,b.end).trim()){p.style="block",p.suffix=u[2];for(let m=l+1;m<o.length;m++){if(!o[m].trim()||/^\s*#/.test(o[m])){/^\s+#/.test(o[m])&&p.blockComments.push(m);continue}let f=/^(\s*-\s+)(.*)$/.exec(o[m]);if(!f)break;let y=ke(f[2]),h=f[2].slice(0,y.end).trimEnd(),a=Me(h);p.indent=f[1],a&&p.entries.push({name:a,raw:h,before:"",note:"",noteAfterComma:!1,row:o[m]}),y.comment&&a&&c.push({tool:a,comment:y.comment}),i.push(m),p.last=m}p.quote=p.entries.map(m=>m.raw).find(m=>/^["']/.test(m))?.[0]??""}for(let m=l;m<=(p.style==="block"?l:p.last);m++)i.push(m);r.push(p),l=p.last}return{header:t,lists:r,tools:r.length?r.flatMap(l=>l.entries.map(u=>u.name)):null,lines:o,toolLines:i,toolComments:s,itemComments:c}}function lo(e){try{return Io(e)}catch{let t=he(e);return{header:t,lists:[],tools:[],lines:t.raw.map(o=>o.replace(/\r$/,"")),toolLines:[],toolComments:{},itemComments:[],error:"Unclosed frontmatter tool list"}}}function Bo(e){let{tools:t,lines:o,toolLines:r,toolComments:i,itemComments:s,error:c}=lo(e);return{tools:t,lines:o,toolLines:r,toolComments:i,itemComments:s,...c?{error:c}:{}}}function fo(e){let t=Bo(e);if(t.error)throw new Error(t.error);let{tools:o,lines:r,toolLines:i,toolComments:s,itemComments:c}=t;return{tools:o,lines:r,toolLines:i,toolComments:s,itemComments:c}}function Fe(e){return e.every(t=>io.test(t)&&!t.startsWith("*"))&&(e.length!==1||$e(e[0]))?e.join(", "):`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}function ye(e,t){return t==="'"&&!/[\r\n]/.test(e)?`'${e.replace(/'/g,"''")}'`:t==='"'||!$e(e)?JSON.stringify(e):e}function Ss(e,t){let o=lo(e);if(o.error)return e;let r=o.tools??[],i=t([...r]);if(i.length===r.length&&i.every((y,h)=>y===r[h]))return e;if(!o.header){let y=e.startsWith("\uFEFF")?"\uFEFF":"";return`${y}---
|
|
11
|
-
tools: ${Fe(i)}
|
|
12
|
-
---
|
|
13
|
-
${e.slice(y.length)}`}let{header:s,lists:c,toolLines:l,toolComments:u}=o,b=new Map,p=c[0];if(p){let y=c.flatMap(d=>d.entries),h=i.map(d=>{let S=y.findIndex(k=>k.name===d);return S<0?{name:d,raw:ye(d,p.quote),before:p.separator,note:"",noteAfterComma:!1}:y.splice(S,1)[0]}),a=p.prefix.endsWith(" ")?p.prefix:`${p.prefix} `;if(!i.length)b.set(p.first,`${a}[]${p.style==="block"&&p.suffix?` ${p.suffix}`:p.suffix}`);else if(p.style==="block"){b.set(p.first,`${p.prefix}${p.suffix}`);let d=l.filter(S=>S>p.first&&S<=p.last).sort((S,k)=>S-k);for(let S=0;S<h.length;S++){let k=h[S],P=p.entries.includes(k)&&k.row?$e(k.raw)||/^["']/.test(k.raw)?k.row:k.row.replace(k.raw,ye(k.name,p.quote)):`${p.indent}${ye(k.name,p.quote)}`,n=d[Math.min(S,d.length-1)]??p.first;b.set(n,`${b.has(n)?`${b.get(n)}${s.newline}`:""}${P}`)}}else{let d=p.style==="flow"||i.length===1&&ao.test(i[0])||i.some(n=>n.includes(",")||n!==n.trim()||/[\r\n]|(?:^|\s)#|:\s|^[[\]{}&*!|>'"%@`]/.test(n)),S=p.head;for(let[n,g]of h.entries()){if(n){let w=g.before||p.separator,x=h[n-1];x.note&&(x.noteAfterComma?(w=w.replace(/,[^\S\n]*/,`,${x.note}`),w.includes(`
|
|
14
|
-
`)||(w+=`
|
|
15
|
-
`)):w=`${x.note}${/^[^\S\n]*\n/.test(w)?"":`
|
|
16
|
-
`}${w}`),S+=w}S+=d?/^["']/.test(g.raw)||$e(g.raw)?g.raw:ye(g.name,p.quote):g.name}let k=h[h.length-1];k.note?(S+=k.noteAfterComma&&!p.tail.includes(",")?",":"",S+=k.noteAfterComma&&p.tail.includes(",")?p.tail.replace(",",`,${k.note}`):`${k.note}${p.tail}`,p.tail.includes(`
|
|
17
|
-
`)||(S+=`
|
|
18
|
-
`)):S+=p.tail;let P=d?`[${S}]`:p.outerQuote?ye(S,p.outerQuote):S;b.set(p.first,`${p.prefix}${P}${p.suffix}`.replace(/\n/g,s.newline))}}let v=new Set(l),m=s.raw.map((y,h)=>b.has(h)?`${b.get(h)}${s.newline}`:v.has(h)?u[h]&&h>p.last?`${u[h]}${s.newline}`:"":`${!i.length&&c.some(d=>d.blockComments.includes(h))?y.trimStart():y}
|
|
19
|
-
`).join(""),f=p?"":`tools: ${Fe(i)}${s.newline}`;return`${e.slice(0,s.start)}${m}${f}${e.slice(s.end)}`}function Ye(e){return e.CF_LEGACY_TOOL_LISTS!=="1"}function Cs(e,t){return Ye(e)?Fe(t):t.join(", ")}var Wo=/^\s*(name|description|tools|model)\s*:\s*(.+?)\s*$/i;function Do(e){if(e.startsWith('"')&&e.endsWith('"'))try{return JSON.parse(e)}catch{}return e.replace(/^["']|["']$/g,"")}function be(e,t,o,r){let i=Ye(e),s=zo(t).replace(/\.md$/i,""),c,l,u=[],b=!1,p=o,v=[],m=he(o,i?void 0:"markdown");if(m){p=o.slice(m.bodyStart).trim();let y=i?m.raw.map(h=>h.replace(/\r$/,"")):m.raw;for(let h=0;h<y.length;h++){let d=y[h].match(Wo);if(!d)continue;let S=d[1].toLowerCase(),k=Do(d[2]);if(S==="name")s=k;else if(S==="description")if(/^[>|][+-]?$/.test(d[2])){let P=[];for(;h+1<y.length&&(/^\s+\S/.test(y[h+1])||y[h+1].trim()==="");)P.push(y[++h].trim());c=P.join(k[0]===">"?" ":`
|
|
20
|
-
`).trim()}else c=k;else S==="model"?l=k:S==="tools"&&!i&&(b=!0,u=k.replace(/^\[|\]$/g,"").split(",").map(P=>P.trim()).filter(Boolean))}}if(i)try{let y=fo(o);u=y.tools??[],b=y.tools!==null}catch{b=!0,v.push("tools could not be read; check the tool list")}let f=p.trim();return{name:s,...c!==void 0?{description:c}:{},...f?{prompt:f}:{},...!r?.preserveToolAbsence||b?{tools:u}:{},...l!==void 0?{model:l}:{},...v.length?{warnings:v}:{}}}function co(e,t,o){let r=t.managed,i=[],s=new Set([...r.agents,...r.configs,...Object.keys(o.files),...o.listedPaths??[]]),c=new Set(kt(e,[...s],o.files)),l=Object.fromEntries(Object.entries(o.files).filter(([m,f])=>{if(c.has(m))return!1;let y=R(e,{path:m,text:f},{purpose:"override",route:"github",root:t.folder,listing:s,managedFiles:o.files});return!y.admitted&&y.reason==="secret"&&i.push({path:m,reason:"secret"}),y.admitted})),u=new Map;for(let m of r.agents){if(l[m]===void 0){i.some(y=>y.path===m)||i.push({path:m,reason:"missing"});continue}let f=bt(m,l[m],r,o.listedPaths??Object.keys(o.files));i.push(...f.refused),u.set(m,f)}let b=new Set([...u.values()].flatMap(m=>m.relationships.filter(f=>f.kind==="agent").map(f=>f.path))),p=[...u.values()].filter(m=>!b.has(m.path));return!p.length&&u.size&&p.push(u.values().next().value),{agents:p.map(m=>{let f=[{path:m.path,role:"system prompt",label:null}],y=[],h=[],a=(d,S,k)=>{for(let P of d.relationships){if(l[P.path]===void 0){i.some(n=>n.path===P.path)||i.push({path:P.path,reason:"missing"});continue}if(P.kind==="agent"){if(S.has(P.path)){i.push({path:P.path,reason:"cycle"});continue}let n=u.get(P.path);if(!n||h.some(w=>w.path===n.path))continue;let g=[];h.push({path:n.path,name:n.name,description:n.description,prompt:n.prompt,...n.model?{model:n.model}:{},tools:[],skillPaths:[],files:g}),a(n,new Set([...S,n.path]),g)}else if(P.kind==="skill"&&o.skills&&St(e)||P.kind==="config"&&wt(l[P.path])){if(k.some(n=>n.path===P.path))continue;if(k.push({path:P.path,role:P.kind==="skill"?"skill":"config",label:null}),P.kind==="skill"&&d===m){let n=be(e,Go(P.path),l[P.path]);y.push({path:P.path,name:n.name,description:n.description??"",body:n.prompt??""})}}}};return a(m,new Set([m.path]),f),{key:`managed:${m.path}`,name:m.name,model:m.model,description:m.description,prompt:{kind:"dedicated",path:m.path},files:f,tools:[],skills:y,subagents:h}}),notes:[],registry:!1,refused:i}}function po(e,t,o){let r=t.miniSwe,i=o.templateSelection?.agentPath===r.agentPath?o.templateSelection.configPaths:void 0,s=Kt(e,r,o.files,i),c=s.unresolved.filter(a=>a.reason!=="runtime-variable").map(a=>({path:a.target??a.path,reason:a.reason==="duplicate"?"invalid":a.reason})),l=s.fields.find(a=>a.key==="agent.system_template"&&a.value!==null),u=s.fields.find(a=>a.key==="agent.instance_template"&&a.value!==null),b=s.unresolved.some(a=>s.selectedPaths.includes(a.path)&&a.source===a.path);if(!l||!u||b||c.some(a=>a.reason==="invalid"))return{agents:[],notes:[],registry:!1,refused:c};let p=[l,...s.fields.filter(a=>a!==l)].map(a=>({path:a.path,span:a.span,label:a.key,role:a===l?"system prompt":a.key.endsWith("_template")?"template":"config"}));p.push(...s.loaded.map(a=>({path:a.path,role:"template",label:null})));let v=[];for(let a of p){let d=v.find(S=>S.path===a.path);d?d.span&&a.span&&(d.span={from:Math.min(d.span.from,a.span.from),to:Math.max(d.span.to,a.span.to)}):v.push({...a})}let m=[...new Set(v.map(a=>a.path))],f=Object.fromEntries(m.map(a=>[a,o.files[a]])),y=new Map(m.map(a=>[a,Buffer.byteLength(f[a])])),h=Ht(e,{ownPaths:m},{files:f,sizes:y,root:t.folder});return c.push(...h.refused,...h.skipped),s.fields.some(a=>!h.paths.includes(a.path))?{agents:[],notes:[],registry:!1,refused:c}:(s.loaded=s.loaded.filter(a=>h.paths.includes(a.path)),s.edges=s.edges.filter(a=>h.paths.includes(a.from)&&h.paths.includes(a.to)),{agents:[{key:t.key,name:o.fallbackName,model:s.model,description:null,prompt:{kind:"entry",path:l.path,span:l.span,text:l.value},files:v.filter(a=>h.paths.includes(a.path)),tools:[],skills:[],subagents:[],templateVariants:s}],notes:[],registry:!1,refused:c})}function mo(e,t,o){if(!t.skills||!le(e))return o;let r=[...new Set([...Object.keys(t.files),...t.listedPaths??[]])],i=fe(e,r,t.root,{files:t.files,listedPaths:t.listedPaths,agentConfigurations:t.agentConfigurations}),s=new Set(i.files.filter(v=>v.role==="skill").map(v=>v.path)),c=v=>[...new Set([...v.skillPaths.filter(m=>s.has(m)),...v.files?.filter(m=>m.role==="skill").map(m=>m.path)??[]])],l=o.agents.flatMap(v=>[...v.skills.map(m=>m.path),...v.subagents.flatMap(c)]),u=ge(e,{skillPaths:l,paths:r,files:t.files,root:t.root});for(let v of u)v.files=v.files.filter(m=>Object.hasOwn(t.files,m.path));let b=new Map(u.map(v=>[v.ownerPath,v])),p=(v,m)=>{let f=new Set(m.flatMap(h=>h.refused.map(a=>a.path))),y=v.filter(h=>h.role!=="reference"||!f.has(h.path));for(let h of m)for(let a of h.files)y.some(d=>d.path===a.path)||y.push({path:a.path,role:"reference",label:null});return y};return{...o,agents:o.agents.map(v=>{let m=v.skills.flatMap(f=>b.has(f.path)?[b.get(f.path)]:[]);return{...v,files:p(v.files,m),skills:v.skills.map(f=>({...f,...b.has(f.path)?{manifest:b.get(f.path)}:{}})),subagents:v.subagents.map(f=>{let y=c(f).flatMap(g=>b.has(g)?[b.get(g)]:[]);if(!y.length)return f;let h=i.ownerOf(f.path),a=G(e,r.filter(g=>i.ownerOf(g)===h),h?.folder),d=f.files??f.skillPaths.map(g=>({path:g,role:s.has(g)?"skill":"reference",label:a.skillNames[g]??a.skillRefNames[g]??null})),S=new Set([...v.files.map(g=>g.path),...a.subagentPaths,...Object.keys(a.subagentSkillOwners)]),k=a.scoped.filter(g=>!S.has(g)&&te(g)&&Object.hasOwn(t.files,g)).sort(),P=f.files?[]:se(k,[t.files[f.path],...d.filter(g=>g.role==="reference").map(g=>t.files[g.path])],a.stripRoot).map(g=>({path:g,role:"reference",label:null})),n=p([...d,...P],y);return{...f,files:n,skillPaths:[...new Set([...f.skillPaths,...c(f),...y.flatMap(g=>g.files.map(w=>w.path))])].filter(g=>n.some(w=>w.path===g)),skillManifests:y}})}})}}import{basename as Ao}from"node:path";function uo(e){return e.prompt.kind!=="none"}function ho(e,t,o){if(q(e))return o;let r=new Map(o.agentScopes?.map(c=>[c.key,c.folder])),i=Object.keys(t.files),s=new Map;return{...o,agents:o.agents.map(c=>{let l=r.get(c.key)??t.root,u=s.get(l);return u||(u=G(e,i,l,t.listedPaths??i),s.set(l,u)),{...c,definitionPaths:Ko(c,u)}})}}function Ko(e,t){if(uo(e))return[e.prompt.path];let o=s=>!t.developerCompanionPaths.includes(s),r=e.subagents.filter(s=>o(s.path));if(r.length)return r.map(s=>s.path);let i=e.files.filter(s=>["skill","tools","mcp"].includes(s.role)&&o(s.path));return e.key!==null||e.plugin||i.some(s=>s.role==="tools"||s.role==="mcp")||!t.hasRepositoryGuide?i.map(s=>s.path):[]}function Jo(e){return!!e.definitionPaths?.length}function Qs(e,t,o,r){return q(e)?o!==r:(t.key!==null||uo(t))&&Jo(t)}function Ve(e){let t;try{t=JSON.parse(e)}catch{return{config:null,invalid:!0}}if(typeof t!="object"||t===null||Array.isArray(t))return{config:null,invalid:!0};let o=t,r={};for(let i of["name","model","description","prompt"]){let s=Ae(o[i]);s&&(r[i]=s)}if(Array.isArray(o.agents)){let i=o.agents.flatMap(s=>{let c=qo(s);return c?[c]:[]});i.length>0?r.agents=i:r.invalidAgents=!0}return{config:r,invalid:!1}}function sr(e){let{config:t}=Ve(e);return t?Xe(t):"bare"}function Xe(e){return e.agents?.length?"agents":e.prompt?"prompt":"bare"}function je(e){let t=Xe(e);return t==="agents"?e.agents:t==="prompt"?[{name:e.name,model:e.model,prompt:e.prompt}]:[]}function go(e,t,o){return yo(e,t,o).paths}function yo(e,t,o,r={}){let i=je(t).map(l=>l.prompt),s=[],c=[];for(let l of i){let u=Ze(l).path,b=He(o,u);if(b===null){c.push({path:u,reason:"out-of-scope"});continue}let p=R(e,{path:b},{purpose:"pointer",route:"github",...r});p.admitted?s.push(b):c.push({path:b,reason:p.reason})}return{paths:s,refused:c}}function Qe(e,t,o){let r=He(o.markerDir,Ze(t).path),i=r!==null?R(e,{path:r},{purpose:"pointer",route:"github"}):null;if(i&&!i.admitted&&i.reason==="secret")return{kind:"secret",path:r};let s=Uo(t,o,_t(e));return s?{kind:"resolved",prompt:s}:{kind:"missed"}}function rr(e,t,o){let r=[],i=[];t.invalidAgents&&i.push(`${o.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let s=Xe(t);for(let c of je(t)){let l=Qe(e,c.prompt,o);if(l.kind==="secret"){i.push(Pt(l.path));continue}if(l.kind==="missed"){i.push(`${o.repoKey}: counterfact.json points at ${c.prompt}, which was not found; ignored`);continue}r.push({name:c.name??null,model:c.model??null,description:s==="prompt"?t.description??null:null,prompt:l.prompt})}return{agents:r,warnings:i,refused:yo(e,t,o.markerDir).refused}}function Ae(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function qo(e){if(typeof e!="object"||e===null)return null;let t=e,o=Ae(t.prompt);if(!o)return null;let r={prompt:o},i=Ae(t.name),s=Ae(t.model);return i&&(r.name=i),s&&(r.model=s),r}function Ze(e){let t=e.replace(/\\/g,"/"),o=t.indexOf("#");if(o>=0)return{path:t.slice(0,o),symbol:t.slice(o+1),line:null};let r=/^(.*):(\d+)$/.exec(t);return r?{path:r[1],symbol:null,line:Number(r[2])}:{path:t,symbol:null,line:null}}function He(e,t){let o=[];for(let r of[...e.split("/"),...t.split("/")])if(r===".."){if(o.pop()===void 0)return null}else r!=="."&&r!==""&&o.push(r);return o.join("/")}function Uo(e,t,o){let{path:r,symbol:i,line:s}=Ze(e),c=He(t.markerDir,r);if(c===null||!Object.hasOwn(t.files,c))return null;let l=t.files[c];if(l===void 0)return null;if(i===null&&s===null)return Q(c)?null:gt(c,l);let{sites:u}=Nt(c,l,{minChars:1,promptFunctions:o});return i!==null?u.find(b=>b.symbol===i)??null:Yo(u,s)}function Yo(e,t){let o=i=>Math.min(i.line,i.span.from),r=e.filter(i=>o(i)<=t&&t<=i.span.to);return r.sort((i,s)=>i.span.to-o(i)-(s.span.to-o(s))),r[0]??null}import{createHash as Vo}from"node:crypto";var ko=25,Xo=e=>ee(e,"CF_IMPORT_AGENT_PAGES");function pr(e,t,o,r,i=ko,s){if(!Xo(e))return null;let c=r?.pageSize??i,l=r?.offset??0;if(![8,25,400].includes(c)||!Number.isSafeInteger(l)||l<0)throw new Error("invalid-agent-page");let u=[...new Map(t.map(w=>[w.id,w])).values()],b=Vo("sha256").update(JSON.stringify({version:1,context:{commit:o.commit,scope:o.scope},size:c,budgets:s,settings:Object.entries(Ut(e)).filter(([,w])=>w!==void 0).sort(([w],[x])=>w.localeCompare(x)),rows:u.map(({id:w,path:x,groupKey:C,pool:A})=>({id:w,path:x,groupKey:C,pool:A}))})).digest("hex");if(r&&(r.version!==1||r.binding!==b))throw new Error("stale-agent-page");let p=u.map((w,x)=>{let C=wo(e,w,x);return typeof C=="string"?`group:${C}`:`agent:${w.id}`}),v=[...new Set(p)];if(l>0&&l>=v.length)throw new Error("invalid-agent-page");let m=r?.end;if(m!==void 0&&(!Number.isSafeInteger(m)||m<l||m>v.length||m>l+c||m===l&&v.length>0))throw new Error("invalid-agent-page");let f=new Set,y=new Set,h=s?{...s}:null,a=l,d=!1;for(let w of v.slice(l,m??l+c)){let x=new Map(u.filter((A,M)=>p[M]===w&&!y.has(u[M].path)).map(A=>[A.path,A])),C={strong:0,possible:0};for(let A of x.values())C[A.pool??"strong"]+=A.bytes;if(m===void 0&&h&&f.size&&(C.strong>h.strong||C.possible>h.possible)){d=!0;break}f.add(w),a++;for(let A of x.keys())y.add(A);h&&(h.strong=Math.max(0,h.strong-C.strong),h.possible=Math.max(0,h.possible-C.possible))}m!==void 0&&(d=a<v.length&&a-l<c);let S=new Set(v.slice(a)),k=u.filter((w,x)=>f.has(p[x])),P=u.filter((w,x)=>S.has(p[x])).map(w=>w.id),n={version:1,binding:b,offset:l,pageSize:c,end:a},g=new Map(k.map(w=>[w.path,w.bytes]));return{context:{...o},current:n,continuation:P.length?{version:1,binding:b,offset:a,pageSize:c}:null,detected:u.length,detectedGroups:v.length,selected:k.map(w=>w.id),remaining:P,refusals:P.map(w=>({id:w,reason:d?"prompt-over-limit":"page"})),partial:P.length>0,estimatedInputBytes:[...g.values()].reduce((w,x)=>w+x,0)}}function bo(){return ko}function wo(e,t,o){return pt(e)&&t!==null&&typeof t=="object"&&"groupKey"in t&&typeof t.groupKey=="string"&&t.groupKey?t.groupKey:o}function Po(e,t){let o=bo(),r=new Set,i=[],s=[];return t.forEach((c,l)=>{let u=wo(e,c,l);r.has(u)||r.size<o?(r.add(u),i.push(c)):s.push(c)}),{kept:i,leftOut:s}}function vo(e){let t=bo();if(e.kind==="layout")return`Only ${t} agents can be added per import, so ${e.leftOut} were left out.`;if(e.kind==="scan"){let r=e.found-t;return`${r} ${r===1?"agent wasn't":"agents weren't"} read because the repository is large.`}let o=e.kind==="import"?`Not added: this import already has ${t} agents.`:`Only the ${t} strongest agents of a repository are added.`;return e.kind==="model"?`${e.name}: ${o}`:o}var Ee="crew:";function et(e){return e.startsWith(Ee)}function tt(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Object.entries(e);return!t.length||t.some(([,o])=>typeof o!="string"||o.length>=2e3)?null:t.map(([o,r])=>`${o}: ${r}`).join(`
|
|
21
|
-
`)}function So(e,t,o={},r=Object.keys(t)){return K(o)?Qo(e,t,r):e.kind!=="crew"?{agents:[],notes:[],registry:!1}:Oo(e,t)}function Oo(e,t){let o=[],r=[],i=(l,u)=>r.push({code:"unreadable-crew",path:l,detail:u?`${u} could not be read; some instructions may be missing.`:"could not be read; some instructions may be missing."}),s=Se(t[e.agentsPath]??""),c=e.tasksPath?Se(t[e.tasksPath]??""):[];s?.length||i(e.agentsPath),c===null&&i(e.tasksPath);for(let{key:l,value:u,span:b}of s??[]){if(!re(u)){i(e.agentsPath,l);continue}let{llm:p,tools:v,...m}=u,f=tt(m);if(f===null&&Object.keys(m).length){i(e.agentsPath,l);continue}let y=[{role:"system prompt",path:e.agentsPath,label:l,span:b}];for(let h of c??[])re(h.value)&&h.value.agent===l&&y.push({role:"knowledge",path:e.tasksPath,label:h.key,span:h.span});o.push({key:`${Ee}${e.agentsPath}#${l}`,name:l,model:typeof p=="string"?p:null,description:typeof u.goal=="string"?u.goal:null,entry:{path:e.agentsPath,span:b,text:f},files:y,tools:Array.isArray(v)?[...new Set(v.filter(h=>typeof h=="string"&&!!h.trim()))]:[],skills:[],subagents:[]})}return{agents:o,notes:r,registry:!1}}function re(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qo(e,t,o){let r=new Set([...o,...Object.keys(t)]),i=Object.entries(t).filter(([f])=>f.endsWith(".py")).map(([f,y])=>Jt(f,y,r,e.folder)),s=i.flatMap(f=>f.agents),c=i.flatMap(f=>f.refused);if(!s.length)return e.kind==="crew"&&/\.ya?ml$/i.test(e.agentsPath)?{...Oo(e,t),refused:c}:{agents:[],notes:[],refused:c,registry:!1};let l=new Map,u=f=>{if(!l.has(f)){let y=t[f]===void 0?null:Se(t[f]);l.set(f,y),y===null&&c.push({path:f,reason:t[f]===void 0?"missing":"invalid"})}return l.get(f)??[]},b=i.flatMap(f=>f.tasks).flatMap(f=>{let y=f.config?.path?u(f.config.path).find(d=>d.key===f.config.key):void 0;if(f.config&&(!f.config.path||!y||!re(y.value)))return f.config.path&&c.push({path:f.config.path,reason:y?"invalid":"missing"}),[];let h=re(y?.value)?y.value:{},a=f.factory.includes(".")?f.factory.slice(0,f.factory.lastIndexOf(".")):null;return[{fact:f,path:f.config?.path??f.path,key:f.config?.key??f.factory,span:y?.span??f.span,agent:f.agent??(typeof h.agent=="string"?a?`${a}.${h.agent}`:h.agent:null),context:[...f.context,...Array.isArray(h.context)?h.context.filter(d=>typeof d=="string"):[]],tools:f.tools}]}),p=i.flatMap(f=>f.tasks).filter(f=>f.config),v=p.flatMap(f=>f.config?.path?[{path:f.config.path,source:f.path,owner:f.factory.includes(".")?f.factory.slice(0,f.factory.lastIndexOf(".")):null}]:[]);!p.length&&e.kind==="crew"&&e.tasksPath&&v.push({path:e.tasksPath,source:e.tasksPath,owner:null});for(let{path:f,source:y,owner:h}of v)for(let a of u(f)){if(b.some(S=>S.path===f&&S.key===a.key&&S.fact.path===y&&(S.fact.factory.includes(".")?S.fact.factory.slice(0,S.fact.factory.lastIndexOf(".")):null)===h)||!re(a.value))continue;let d=a.value;b.push({fact:{path:y,factory:h?`${h}.${a.key}`:a.key,span:a.span,callStart:0,agent:null,context:[],tools:[]},path:f,key:a.key,span:a.span,agent:typeof d.agent=="string"?h?`${h}.${d.agent}`:d.agent:null,context:Array.isArray(d.context)?d.context.filter(S=>typeof S=="string"):[],tools:[]})}let m=[];for(let f of s){let y=f.config?.path?u(f.config.path).find(C=>C.key===f.config.key):void 0;if(f.config&&(!f.config.path||!y||!re(y.value))){f.config.path&&c.push({path:f.config.path,reason:y?"invalid":"missing"});continue}let h=re(y?.value)?y.value:{},a={...Object.fromEntries(Object.entries(h).filter(([C,A])=>!["llm","tools"].includes(C)&&typeof A=="string")),...f.instructions},d=tt(a);if(!d){c.push({path:f.path,reason:"dynamic"});continue}let S=f.config?.key??f.factory.split(".").at(-1),k=f.config?.path??f.path,P=y?.span??f.span,n=[{path:k,role:"system prompt",label:S,span:P}];k!==f.path&&n.push({path:f.path,role:"config",label:f.factory,span:f.span});let g=b.filter(C=>C.fact.path===f.path?C.agent===f.factory||C.agent===S:/\.ya?ml$/i.test(C.fact.path)&&C.agent===S&&s.filter(A=>(A.config?.key??A.factory)===S).length===1),w=new Set,x=[...f.tools];for(let C=0;C<g.length;C++){let A=g[C];if(!w.has(A)&&(w.add(A),!(A.fact.config&&!A.fact.config.path))){n.push({path:A.path,role:"knowledge",label:A.key,span:A.span}),x.push(...A.tools);for(let M of A.context){let E=b.filter(j=>j.fact.path===A.fact.path&&j.fact.factory===M||j.path===A.path&&j.key===M);E.length===1?g.push(E[0]):c.push({path:A.path,reason:E.length?"dynamic":"missing"})}}}for(let C of x)C.path&&C.path!==f.path&&!n.some(A=>A.path===C.path)&&(t[C.path]===void 0&&c.push({path:C.path,reason:"missing"}),n.push({path:C.path,role:"tools",label:C.name}));m.push({key:`${Ee}${f.path}#${f.factory}`,name:S,model:typeof h.llm=="string"?h.llm:null,description:typeof a.goal=="string"?a.goal:null,entry:{path:k,span:P,text:d},files:n,tools:[...new Set([...x.map(C=>C.name),...Array.isArray(h.tools)?h.tools.filter(C=>typeof C=="string"):[]])],skills:[],subagents:[],crewCall:{path:f.path,callStart:f.callStart}})}return{agents:m,notes:[],refused:c,registry:!1}}import{basename as xo,posix as Re}from"node:path";function Co(e,t,o){let r={...t.selected,codeAgentsFound:t.codeAgentsFound||t.selected.codeAgentsFound};if(!ot(e,r,o))return{kind:"none"};let i={...t.bodies,...r.files},s=G(e,Object.keys(i),X(r.root)).templatePaths,c=nt(e,{...r,files:i},s);if(!t.entries)return{kind:"search",paths:[],ownedPaths:c.ownedPaths};let l=new Set([...Object.keys(i),...t.attemptedPaths??[]]),u=new Set(c.facts.dependencies);for(let y of c.relatedReads)y.target.kind==="file"&&u.add(y.target.path);for(let y of t.entries)c.relatedReads.some(h=>h.target.kind==="directory"&&Le(h,y.path))&&u.add(y.path);let b=(y,h)=>{let a=R(e,y,{purpose:h,route:"local-folder"});return a.admitted||a.reason==="too-large"},p=[...new Set(t.entries.filter(y=>!l.has(y.path)&&(u.has(y.path)?b(y,"pointer"):D(y.path,r.root)===null&&Q(y.path)!==null&&b(y,"code-support"))).map(y=>y.path))],v=X(r.root)??"",m=y=>Re.parse(y).name===(v?xo(v):r.fallbackName)?0:vt.test(xo(y))?1:2,f=y=>Re.relative(v||".",Re.dirname(y)).split("/").filter(h=>h&&h!==".").length;return p.sort((y,h)=>Number(u.has(h))-Number(u.has(y))||m(y)-m(h)||f(y)-f(h)||(y<h?-1:y>h?1:0)),{kind:"search",paths:p,ownedPaths:c.ownedPaths}}function Le(e,t){return e.target.kind==="file"?e.target.path===t:Re.dirname(t)===e.target.path&&(!e.target.extension||t.endsWith(e.target.extension))}function ot(e,t,o){if(!Oe(e)||t.codeAgentsFound||t.explicitPrompt!==void 0||o.agents.length||t.listedPaths&&G(e,[...t.listedPaths],X(t.root)).configPath)return null;let r=G(e,Object.keys(t.files),X(t.root)).templatePaths;if(!r.length)return null;let i=Object.fromEntries(Object.entries(t.files).filter(([s])=>D(s,t.root)!==null&&R(e,{path:s},{purpose:"override",route:"github"}).admitted));return Be(e,i).reads.some(s=>r.some(c=>Le(s,c)))?null:r}function nt(e,t,o){let r=Object.fromEntries(Object.entries(t.files).filter(([m])=>R(e,{path:m},{purpose:"override",route:"github"}).admitted)),i=Be(e,r),s=i.reads.filter(m=>D(m.sourcePath,t.root)===null&&o.some(f=>Le(m,f))),c=o.filter(m=>s.some(f=>Le(f,m))).sort(),l=[...new Set(s.map(m=>m.sourcePath))].sort(),u=i.reads.filter(m=>l.includes(m.sourcePath)),b=u.flatMap(m=>m.target.kind==="file"&&Object.hasOwn(r,m.target.path)&&D(m.target.path,t.root)!==null&&!o.includes(m.target.path)?[m.target.path]:[]).sort(),p=s.flatMap(m=>m.consumerPaths).sort(),v=c.length?[...new Set([c[0],...o.filter(m=>m!==c[0]),...b,...l,...p])]:[];return{facts:i,relatedReads:u,provenTemplates:c,ownedPaths:v}}function si(e,t,o={}){return Te(e)&&!t.agentConfigurations&&(t={...t,agentConfigurations:Wt(e,t.listedPaths??Object.keys(t.files),t.root)}),ho(e,t,Zo(e,t,o))}function Zo(e,t,o){let r=jo(e,t),{answer:i,scopeProof:s}=Ho(e,t,r),c=Ce(e);if(!c&&!i.agents.some(a=>a.crewCall||a.layoutCall))return Ke(e,t,i);let l=[...new Set([...Object.keys(t.files),...t.listedPaths??[],...i.scopePaths??[]])],u=fe(e,l,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),b=i.agents.filter(a=>c||a.crewCall||a.layoutCall).map(a=>{let d=r.agents.find(M=>M.key===a.key),S=st(d?.files??[]),k=i.agentScopes?.find(M=>M.key===a.key)?.folder,P=u.scopes.find(M=>k===void 0?M.key===a.key:M.folder===k)??u.scopes[0],n=G(e,l.filter(M=>u.ownerOf(M)===P),P.folder),g=new Set([...a.files.filter(M=>M.role!=="reference"||M.label!==null).map(M=>M.path),...a.subagents.flatMap(M=>[M.path,...d?.subagents.find(E=>E.path===M.path)?.skillPaths??M.skillPaths]),...i.notes.filter(M=>M.code==="orphan-skill").map(M=>M.path)]),w=n.scoped.filter(M=>!g.has(M)&&te(M)).sort(),x=`convention:${JSON.stringify(a.key)}`,C=a.files.map(M=>a.prompt.kind!=="none"&&a.prompt.path===M.path&&"span"in a.prompt?{...M,span:M.span??a.prompt.span}:M),A=a.subagents.map(M=>{let E=d?.subagents.find(_=>_.path===M.path),j=M.files??M.skillPaths.map(_=>({path:_,role:n.skillNames[_]?"skill":"reference",label:n.skillNames[_]??n.skillRefNames[_]??null})),N=le(e)?st(E?.files??[]):j.map(_=>_.path),$=M.files&&!n.subagentPaths.includes(M.path)?[]:se(w,[M.path,...N].map(_=>t.files[_]??""),n.stripRoot),O=$.filter(_=>!j.some(ie=>ie.path===_)).map(_=>({path:_,role:"reference",label:null})),z=i.agents.find(_=>"key"in M&&_.key===M.key);return{child:M,id:`${x}:${JSON.stringify("key"in M?M.key:M.path)}`,scopeProof:z?.layoutProof??s,toolCall:z?.layoutCall,independentReferences:[...st(E?.files??[]),...$],ownFiles:"key"in M?[...j,...O]:[{path:M.path,role:"system prompt",label:null},...j,...O]}});return{agent:a,id:x,scope:P,ownFiles:C,independentReferences:S,children:A,scopeProof:a.layoutProof??s,toolCall:a.crewCall??a.layoutCall}}),p=b.flatMap(({agent:a,id:d,scope:S,ownFiles:k,independentReferences:P,children:n,scopeProof:g,toolCall:w})=>[{id:d,scope:S,ownFiles:k,independentReferences:P,scopeProof:g,toolCall:w,sharedReferencePaths:a.sharedReferencePaths,fileProfile:a.crewCall||a.layoutCall?"layout":"convention",skillManifests:a.skills.flatMap(x=>x.manifest?[x.manifest]:[])},...n.map(({child:x,id:C,ownFiles:A,independentReferences:M,scopeProof:E,toolCall:j})=>({id:C,scope:S,ownFiles:A,independentReferences:M,scopeProof:E,toolCall:j,fileProfile:"key"in x?"layout":"convention",skillManifests:x.skillManifests}))]),v=eo(e,p,{files:t.files,sizes:o.sizes??new Map(Object.entries(t.files).map(([a,d])=>[a,Buffer.byteLength(d)])),total:o.total,root:t.root,scopes:u}),m=new Map(v.map(a=>[a.agentId,a])),{complete:f,...y}=i,h=new Map(b.map(({agent:a,id:d,children:S})=>{let k=m.get(d);return[a.key,{...a,manifest:k,files:Mo(k,a.files),skills:a.skills.filter(P=>k.files.some(n=>n.path===P.path)),subagents:S.flatMap(({child:P,id:n,ownFiles:g})=>{let w=m.get(n);if(!w.files.some(A=>A.path===P.path))return[];let x=Mo(w,g),C="key"in P?x:x.filter(A=>A.path!==P.path);return[{...P,files:C,skillPaths:P.skillPaths.filter(A=>C.some(M=>M.path===A))}]})}]}));return Ke(e,t,{...y,...f&&!v.some(a=>a.refused.length)?{complete:f}:{},scopePaths:l,manifests:v,agents:i.agents.map(a=>h.get(a.key)??a)})}function Mo(e,t){return e.files.flatMap(o=>t.some(r=>r.path===o.path)?t.filter(r=>r.path===o.path):[{path:o.path,role:o.roles.includes("config")?"config":"tools",label:null,...o.spans.length===1?{span:o.spans[0]}:{}}])}function st(e){return e.filter(t=>t.role==="reference"&&t.label===null).map(t=>t.path)}function Ho(e,t,o){let r=mo(e,t,o);if(!q(e)&&t.codeAgentsFound)return{answer:{...r,projection:"code"}};let i=ot(e,t,r);if(!i)return{answer:r};let s=nt(e,t,i);if(!s.provenTemplates.length)return{answer:r};let c=s.provenTemplates[0],l=new Set(r.agentScopes?.find(b=>b.key===null)?.notes),u=b=>!(b.code==="no-prompt"&&b.detail==="no-conventions"&&b.path===(X(t.root)??""));return{scopeProof:{kind:"outside-loader",paths:s.ownedPaths},answer:{...r,projection:"conventions",notes:r.notes.filter(u),...r.agentScopes?{agentScopes:r.agentScopes.map(b=>({...b,notes:b.notes.filter(u)}))}:{},...r.unassignedNotes?{unassignedNotes:r.unassignedNotes.filter(b=>!l.has(b))}:{},agents:[{key:null,name:t.fallbackName,model:null,description:null,prompt:{kind:"dedicated",path:c},files:s.ownedPaths.map(b=>({path:b,role:b===c?"system prompt":i.includes(b)?"template":"reference",label:null})),skills:[],subagents:[]}]}}}function ri(e,t){return Oe(e)?Co(e,t,jo(e,t.selected)):{kind:"none"}}function jo(e,t){if(!ve(e)){let{agents:n,notes:g}=rt(e,t,null);return{agents:n,notes:g}}let o=yt(e,t.listedPaths??[]).flatMap(n=>[...n.agents,...n.configs]),r=[...new Set([...Object.keys(t.files),...o,...K(e)?t.listedPaths??[]:[]])],{scopes:i,ownerOf:s,ignoredPaths:c,pluginFolders:l}=fe(e,r,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),u=new Set(c),b=new Map(i.map(n=>[n,{}]));for(let[n,g]of Object.entries(t.files)){if(u.has(n))continue;let w=s(n);w&&(b.get(w)[n]=g)}let p=i.map(n=>{let g=b.get(n),w={...t,files:g,root:n.folder,fallbackName:n.key===null?t.fallbackName:Ao(n.folder),explicitPrompt:n.key===null?t.explicitPrompt:void 0,...t.pointerFiles?{pointerFiles:Object.fromEntries(Object.entries(t.pointerFiles).filter(([x])=>!u.has(x)&&s(x)===n))}:{}};return{scope:n,input:w,answer:$o(e,n,w,!1,t.files)}}),v=[],m=new Map,f=p.filter(({scope:n,input:g,answer:w})=>{let x=w.agents[0];if(!x)return!0;let C=Object.entries(g.files).map(([E,j])=>[D(E,n.folder),j]).sort(([E],[j])=>E<j?-1:E>j?1:0),A=JSON.stringify([x.name,C,...n.managed||K(e)&&(n.kind==="crew"||l.includes(n.folder))?[n.folder]:[]]),M=m.get(A);return M!==void 0?(v.push({code:"duplicate-agent",path:n.folder,detail:M}),!1):(m.set(A,n.folder),!0)}),y=f.find(({scope:n})=>n.key===null),h=y.answer.agents[0];f.some(({scope:n,answer:g})=>n.key!==null&&g.agents.length)&&(y.answer=$o(e,y.scope,y.input,!0,t.files),y.answer.notes=y.answer.notes.filter(n=>n.detail!=="no-conventions"));for(let{scope:n,answer:g}of q(e)?[]:f)l.includes(n.folder)&&(g.agents=g.agents.map(w=>({...w,plugin:!0})));let{kept:a,leftOut:d}=Po(e,f.flatMap(({answer:n})=>n.agents));Yt(a,h,{settings:e,files:t.files,root:t.root});let S=[...v,...d.length?[{code:"agent-cap",detail:vo({kind:"layout",leftOut:d.length})}]:[]],k=new Set(a.map(n=>n.key));return{...!t.definitionsOmitted&&f.some(({scope:n})=>n.kind==="crew")&&f.every(({scope:n,answer:g})=>g.notes.length===0&&!g.refused?.length&&(n.kind==="crew"?g.agents.length>0&&g.agents.every(w=>et(w.key??"")):g.agents.length===0))&&(!t.listedPaths||fe(e,t.listedPaths,t.root,{agentConfigurations:t.agentConfigurations}).files.every(n=>Object.hasOwn(t.files,n.path)))?{complete:!0}:{},...f.some(({scope:n,answer:g})=>n.miniSwe&&g.agents.length)&&!t.codeAgentsFound?{projection:"conventions"}:{},agents:a.map(n=>n.layoutCall?{...n,subagents:n.subagents.filter(g=>"key"in g&&k.has(g.key))}:n),notes:[...f.flatMap(({answer:n})=>n.notes),...S],...o.length?{scopePaths:r}:{},...f.some(({answer:n})=>n.refused?.length)?{refused:f.flatMap(({answer:n})=>n.refused??[])}:{},...i.length>1||i.some(n=>n.kind==="crew"||n.managed||n.miniSwe)||f.some(({answer:n})=>n.agents.some(g=>g.layoutCall))?{agentScopes:f.flatMap(({scope:n,answer:g})=>(g.agents.length?g.agents:[{key:n.key}]).map((w,x)=>({key:w.key,folder:n.folder,registry:g.registry&&!et(w.key??""),notes:g.notes.filter(C=>C.code!=="unreadable-crew"||x===0)}))),unassignedNotes:[...f.filter(({answer:n})=>!n.agents.some(g=>k.has(g.key))).flatMap(({answer:n})=>n.notes),...S]}:{}}}function $o(e,t,o,r=!1,i){if(t.managed)return co(e,t,o);if(t.miniSwe&&o.explicitPrompt===void 0)return po(e,t,o);if(t.kind!=="crew"&&!K(e))return rt(e,o,t.key,r);let s=so(e,o,i),c=en(e,t,o.files,o.listedPaths),l=rt(e,o,t.key,r||t.key===null&&(c.agents.length>0||s.agents.length>0));return{agents:[...l.agents,...c.agents,...s.agents],notes:[...l.notes.filter(u=>u.detail!=="no-conventions"||t.kind!=="crew"&&c.agents.length===0&&s.agents.length===0),...c.notes],registry:l.registry,...c.refused?.length||s.refused.length?{refused:[...c.refused??[],...s.refused]}:{}}}function en(e,t,o,r){let i=So(t,o,e,r),{agents:s,notes:c,registry:l}=i;return{agents:s.map(({entry:u,...b})=>({...b,prompt:Eo(e,{entry:u},c)})),notes:c,registry:l,...i.refused?.length?{refused:i.refused}:{}}}function rt(e,t,o,r=!1){let{files:i,skills:s,fallbackName:c}=t,l=X(t.root),u=G(e,Object.keys(i),l,t.listedPaths),b=[],p=typeof t.explicitPrompt=="string"&&!Pe(e,t.explicitPrompt);p&&b.push({code:"explicit-guide",path:t.explicitPrompt});let v=p?null:t.explicitPrompt,m=typeof v=="string"&&Object.hasOwn(i,v)&&R(e,{path:v},{purpose:"override",route:"github"}).admitted?v:null,f={...u,skillPaths:s?u.skillPaths:[]},y=Bt(f),h=tn(i,u.configPath,b),a=!q(e)&&!h?.prompt&&!h?.agents?.length?Dt(e,t):null,d=ct({codeAgentsFound:!q(e)&&!!t.codeAgentsFound,folderAgentsFound:r,otherDefinitions:y,agentConfiguration:a!==null},e);if(a&&d==="prompt"&&(u=a),!(v===null||m!==null||zt({...f,claudePath:u.claudePath},d)))return Fo(De(u),s,b),{agents:[],notes:[...b,{code:"no-prompt",path:l??"",detail:"no-conventions"}],registry:u.registry};let k=Eo(e,{files:i,c:u,guideRole:d,folderAgentsFound:r,root:l,config:h,explicitPath:v===null?null:m??void 0,pointerFiles:t.pointerFiles},b);k.kind==="none"&&(u=De(u));let P=s?u.skillPaths.map(w=>{let x=be(e,`${u.skillNames[w]}.md`,i[w]);return b.push(...(x.warnings??[]).map(C=>({code:"frontmatter",path:w,detail:C}))),{path:w,name:x.name,description:x.description??"",body:x.prompt??""}}):[];Fo(u,s,b);let n=s?[...u.subagentSkillPaths,...u.subagentSkillRefPaths]:[],g=u.subagentPaths.map(w=>{let x=be(e,Ao(w),i[w],{preserveToolAbsence:!0});return b.push(...(x.warnings??[]).map(C=>({code:"frontmatter",path:w,detail:C}))),{path:w,name:x.name,description:x.description??null,prompt:x.prompt??"",...x.tools!==void 0?{tools:x.tools}:{},...x.model!==void 0?{model:x.model}:{},skillPaths:n.filter(C=>u.subagentSkillOwners[C]===w)}});return{agents:[{key:o,name:h?.name??c,model:h?.model??null,description:h?.description??null,prompt:k,files:on(e,i,u,k,s),skills:P,subagents:g}],notes:b,registry:u.registry}}function ii(e,t,o,r){let i=G(e,Object.keys(o),X(r));return Object.hasOwn(i.subagentSkillOwners,t)?!0:ge(e,{skillPaths:i.subagentSkillPaths,paths:i.scoped,files:o,root:r})?.some(s=>s.files.some(c=>c.path===t))??!1}function tn(e,t,o){if(!t)return null;let r=Ve(e[t]);if(r.invalid)try{JSON.parse(e[t])}catch{o.push({code:"invalid-config",path:t})}return r.config}function Eo(e,t,o){if("entry"in t)return t.entry.text?{kind:"entry",...t.entry,text:t.entry.text}:(o.push({code:"no-prompt",path:t.entry.path}),{kind:"none"});let{files:r,c:i,guideRole:s,folderAgentsFound:c,root:l,config:u,explicitPath:b,pointerFiles:p}=t;if(b===null)return{kind:"none"};if(b!==void 0)return{kind:"explicit",path:b};let v=u?je(u)[0]?.prompt:void 0,m=u?go(e,u,l??"")[0]:void 0,f=v?Qe(e,v,{repoKey:"",markerDir:l??"",files:p??r}):null,y=m!==void 0&&Object.hasOwn(r,m),h=y&&!!r[m];if(y&&(h||p!==void 0)&&Object.hasOwn(i.subagentSkillOwners,m))o.push({code:"pointer-owned-by-subagent",path:m});else if(y&&(p===void 0?h:f?.kind==="resolved")){let a=f?.kind==="resolved"?f.prompt:null;return{kind:"pointer",path:m,...a&&a.kind!=="file"?{span:{...a.span},site:{kind:a.kind,start:a.start,symbol:a.symbol}}:{}}}else v&&o.push(p!==void 0&&f?.kind==="secret"?{code:"secret-file",path:f.path}:{code:"pointer-missed",...m?{path:m}:{},detail:v});return i.promptPath?{kind:"dedicated",path:i.promptPath}:i.registry&&i.soulPath?{kind:"registry",path:i.soulPath}:i.claudePath&&s==="prompt"?(o.push({code:"claude-fallback",...Te(e)?{path:i.claudePath}:{}}),{kind:"fallback",path:i.claudePath}):(o.push({code:"no-prompt",path:l??"",...c?{folderAgentsFound:!0}:{}}),{kind:"none"})}function Fo(e,t,o){if(t)for(let r of[...e.subagentSkillPaths,...e.subagentSkillRefPaths])e.subagentSkillOwners[r]||o.push({code:"orphan-skill",path:r})}function on(e,t,o,r,i){let s=[],c=(p,v,m=null)=>({role:p,label:m,path:v});if(r.kind!=="none"&&r.kind!=="registry"&&s.push(c("system prompt",r.path)),o.soulPath&&s.push(c("soul",o.soulPath)),o.knowledgePath&&s.push(c("knowledge",o.knowledgePath)),i)for(let p of o.skillPaths)s.push(c("skill",p,o.skillNames[p]));for(let p of o.templatePaths)s.push(c("template",p));if(i)for(let p of o.skillRefPaths)s.push(c("reference",p,o.skillRefNames[p]));let l=[];o.configPath&&l.push(c("config",o.configPath));for(let p of[o.toolsPath,o.toolsTsPath,o.cliPath])p&&l.push(c("tools",p));o.mcpPath&&l.push(c("mcp",o.mcpPath));let u=new Set([...s.map(p=>p.path),...l.map(p=>p.path),...o.subagentPaths,...Object.keys(o.subagentSkillOwners),...o.skillPaths,...o.skillRefPaths]),b=o.scoped.filter(p=>!u.has(p)&&te(p)).sort();return s.push(...se(b,s.map(p=>t[p.path]),o.stripRoot).map(p=>c("reference",p)),...l),s}export{se as a,yn as b,No as c,Xt as d,Ce as e,ge as f,Qt as g,qe as h,_o as i,qn as j,Un as k,Yn as l,Ht as m,eo as n,Bo as o,Ss as p,Ye as q,Cs as r,be as s,uo as t,Jo as u,Qs as v,Ve as w,sr as x,Xe as y,go as z,yo as A,rr as B,Xo as C,pr as D,bo as E,Po as F,vo as G,si as H,ri as I,ii as J};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as p,b as m}from"./6U2IR4XB.js";import{a as u}from"./MJGB25S5.js";import{j as c,k as d}from"./X7WZAA7S.js";import{z as n}from"zod";var l=n.lazy(()=>n.union([n.string(),n.number(),n.boolean(),n.null(),n.array(l),n.record(n.string(),l)])),g=n.object({data:n.record(n.string(),l),settings:d,maxInputBytes:n.number().int().positive().optional()}).strict(),h=n.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]*$/),w=n.object({maxTokens:n.number().int().positive().optional(),effort:n.enum(["low","medium","high","max"]).optional(),thinking:n.literal("disabled").optional(),promptCache:n.boolean().optional()}).strict(),b=n.object({template:n.string().min(1),inputs:g,answerFormat:n.string().min(1),model:h,limits:w.optional()}).strict();function A(e,i={},r){let o={data:e.inputs,settings:c(i),...r===void 0?{}:{maxInputBytes:r}};return b.parse({...e,answerFormat:Object.hasOwn(s,e.template)?x(e.template,e.answerFormat,i):e.answerFormat,limits:{...e.limits,promptCache:u(i,{template:e.template},e.model).enabled},inputs:JSON.parse(JSON.stringify(o))})}var t=(e,...i)=>Object.freeze({role:e,answerFormats:Object.freeze(i)}),a=m().map(e=>e.name),s=Object.freeze({"derive-findings":t("required",...a),"derive-findings-legacy":t("required",...a),"derive-findings-no-outcome":t("required",...a),"derive-findings-legacy-no-outcome":t("required",...a),"benchmark-judge":t("required","judge"),"judge-code-prompt":t("optional","codeJudge"),"derive-structure":t("optional","structures"),"structure-recheck":t("optional","recheck"),"derive-shape":t("optional","shape"),"scope-items":t("optional","structureScope"),"scope-findings":t("optional","scope"),"check-findings":t("optional","check"),"check-findings-precision-v1":t("optional","check"),"second-opinion":t("optional","opinion"),"explain-sources":t("optional","sourceNotes"),"finding-headlines":t("optional","findingHeadlines")});function S(){return s}function z(e,i,r){let o=r??(e==="derive"?"derive-findings":"check-findings");if(!Object.keys(s).filter(f=>s[f].answerFormats.includes(e==="derive"?"findings":"check")).includes(o))throw new Error("Unknown analysis template");return e==="derive"&&!p(i).switches.expectedOutcome&&!o.endsWith("-no-outcome")?`${o}-no-outcome`:o}function x(e,i,r){let o=i==="findings"?p(r).name:i;if(!Object.hasOwn(s,e)||!s[e].answerFormats.includes(o))throw new Error("Unsupported template answer format");return o}function N(e,i,r){if(r(i),!Object.hasOwn(s,e)||s[e].role!=="optional")throw i}export{g as a,h as b,w as c,b as d,A as e,S as f,z as g,x as h,N as i};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as c,c as l,d as s,e as m,g as i}from"./SKVEBOGA.js";import{c as u,d as p}from"./FSLWD2PE.js";function n(a,d={}){return JSON.stringify({bundleDescription:a,inputs:d})}import{z as e}from"zod";import{z as t}from"zod";var r=t.object({motivation:t.array(t.object({kind:t.string(),reason:t.string(),evidence:t.string()})),outcomes:t.array(t.object({improvement:t.string(),measurement:t.string()}))}),O=r.extend({motivation:r.shape.motivation.default([]),outcomes:r.shape.outcomes.default([])});var h=e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}),f=e.object({label:e.string(),source:e.literal("mcp").optional(),brand:e.string().nullable().default(()=>null)}),x=["system prompt","soul","knowledge","skill","config","tools","mcp","template","reference","code"],y=e.object({filledAtRunTime:e.boolean().optional(),role:e.enum(x),label:e.string().nullable().default(()=>null),path:e.string().min(1),span:e.object({from:e.number().int(),to:e.number().int()}).optional()}),S=e.object({id:e.string().min(1),label:e.string().min(1),kind:e.enum(["entry","agent","tool","store","exit"]),desc:e.string(),meta:e.string().nullable(),sourceRef:h.nullable(),sourcePaths:e.array(e.string()).optional(),files:e.array(y).default(()=>[]),tools:e.array(f).default(()=>[])}),j=e.object({from:e.string().min(1),to:e.string().min(1),kind:e.enum(["invokes","delegates","reads","writes","emits"]),label:e.string().nullable(),sourceRef:h.nullable()}),_=e.object({nodes:e.array(S),edges:e.array(j),warnings:e.array(e.string())}),v=e.object({...r.shape,title:e.string().min(1).describe(n("analysis-wire-schemas-1")),approach:e.string().min(1).describe(n("analysis-wire-schemas-2")),kind:e.enum(["code","prompt"]),targetFiles:e.array(e.object({path:e.string().min(1),create:e.boolean().nullable()})),...i.shape});function o(a){return e.string().describe(n("analysis-wire-schemas-3",{v0:Object.values(a.enum).join(", ")}))}var w=e.object({nodes:e.array(e.object({id:e.string().min(1),change:o(s),label:e.string().nullable()})),edges:e.array(e.object({from:e.string().min(1),to:e.string().min(1),kind:o(m),change:o(s),detail:e.string().nullable()}))}),k=v.omit({motivation:!0,outcomes:!0}).extend({expectedOutcome:e.string().describe(n("analysis-wire-schemas-4")),summary:i.shape.summary.catch(null),impact:i.shape.impact.catch(null),objective:i.shape.objective.catch(null),blockedBy:i.shape.blockedBy.catch(null),confidence:o(l).nullable().catch(null),status:o(c).nullable().catch(null),alsoFixes:e.array(e.string()).nullable().default([]).catch(()=>[]),delta:w.nullable().catch(null)}),q=e.object({path:e.string().min(1),line:e.number().int().positive(),excerpt:e.string().trim().min(1)}),F=e.object({path:e.string(),line:e.number(),excerpt:e.string()}),b=a=>e.string().describe(n("analysis-wire-schemas-5",{v0:u(a).join(", ")})).nullable().catch(null),g=e.object({kind:e.enum(["ordering","reliability","coverage","cost","safety","correctness"]),severity:e.enum(["low","medium","high","critical"]),title:e.string().min(1).describe(n("analysis-wire-schemas-6")),cause:e.string().min(1),summary:e.string().describe(n("analysis-wire-schemas-7")).catch(""),site:e.object({path:e.string().min(1),line:e.number().int().positive().nullable()}).nullable(),excerpt:e.string().nullable(),category:b({}),otherSites:e.array(F).nullable().default([]).catch(()=>[]),question:e.string().describe(n("analysis-wire-schemas-8")).catch(""),fixes:e.array(k).min(1)}),E=e.object({findings:e.array(g)});function A(a){return p(a)?E:e.object({findings:e.array(g.extend({category:b(a)}))})}export{n as a,_ as b,k as c,q as d,g as e,E as f,A as g};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{a as A}from"./Y7JGSUOA.js";import{d as M}from"./3MTXB4MK.js";import{j as U}from"./K2GNDX3W.js";import{a as P}from"./HTLIRVP7.js";import{a as K}from"./QDYMR6KS.js";import{b}from"./E7TFIHC5.js";import{d as S}from"./ZTOVBAG7.js";import{a as C}from"./74FPPPIG.js";import{d as L,e as N,f as v,g as D,h as $}from"./5DGPLXYB.js";import{a as w,b as E}from"./MJGB25S5.js";import{c as j}from"./FSLWD2PE.js";var J=Object.freeze({"benchmark-judge":"score_match","judge-code-prompt":"judge-code-prompt","derive-findings":"derive_findings","derive-findings-legacy":"derive_findings","derive-findings-no-outcome":"derive_findings","derive-findings-legacy-no-outcome":"derive_findings","derive-structure":"derive_structure","structure-recheck":"structure_recheck","derive-shape":"derive_shape","scope-items":"scope_check_structure","scope-findings":"scope_check","explain-sources":"explain_sources","finding-headlines":"finding_headlines","check-findings":"finding_check","check-findings-precision-v1":"finding_check","second-opinion":"finding_second_opinion"});function re(t){if(!Object.hasOwn(J,t))throw new Error("Unknown analysis template");return J[t]}function z(t){return Object.fromEntries(Object.entries(t).map(([e,o])=>[e,{...o,route:re(e)}]))}import{z as T}from"zod";function F(t,e){if(Buffer.byteLength(t)<=e)return t;let o=0,r=Math.min(t.length,e);for(;o<r;){let a=Math.ceil((o+r)/2);Buffer.byteLength(t.slice(0,a))<=e?o=a:r=a-1}return r>0&&/[\uD800-\uDBFF]/.test(t[r-1])&&r--,t.slice(0,r)}function G(t){let{bundleText:e}=t,o=i=>Buffer.byteLength(JSON.stringify(i));function r(i){let n=[];for(let s of i){if(o([...n,""])>4e3)break;let d=0,l=Buffer.byteLength(s);for(;d<l;){let m=Math.ceil((d+l)/2);o([...n,F(s,m)])<=4e3?d=m:l=m-1}n.push(F(s,d))}return n}function a(i,n=!1){return i.map(s=>typeof s!="string"&&s.kind==="no-core"&&n?e("analysis-check-input-1"):P([s])[0])}function p(i){let n=i.citedFiles===void 0?"":',"citedFiles":'+JSON.stringify(i.citedFiles),s=a(i.diagnostics,!0),d=i.citedFiles===void 0?s:r(s),l=[{text:'{"coreFiles":'+JSON.stringify(i.coreFiles)},{text:n+',"findings":'+JSON.stringify(i.findings)+',"diagnostics":'+JSON.stringify(d)+"}"}];return E(l,w({},{template:"check-findings"}).breakpoints)}function c(i){return Buffer.byteLength(p(i).map(n=>n.text).join(""))}return{checkDiagnosticsText:a,checkPromptBlocks:p,checkPayloadBytes:c}}function R(t,e={}){return t.length?t.map(o=>{let r=e.includeFiles===!1?"":`; files ${o.files.join(", ")||"none"}`;return`${o.ref} "${o.title}" (${o.subKind}): frozen ${o.frozen.join(", ")||"none"}; declined ${o.declined.join(", ")||"none"}${r}`}).join(`
|
|
2
|
-
`):"none"}function _(t){let{bundleText:e}=t,o=e("analysis-scope-check-1"),r=e("analysis-split-check-scope-rule-1"),a=[e("analysis-derive-structures-1"),e("analysis-derive-structures-2"),e("analysis-derive-structures-3"),e("analysis-derive-structures-4"),e("analysis-derive-structures-5"),e("analysis-derive-structures-6"),e("analysis-derive-structures-7"),e("analysis-derive-structures-8")].join(`
|
|
3
|
-
`),p=e("analysis-derive-structures-10");function c(n){return n.map(s=>({unit:JSON.stringify(s.unitKey),kind:s.kind,name:JSON.stringify(s.name),location:JSON.stringify(`${s.sourcePath}:${s.sourceLine}${s.sourceEndLine?`\u2013${s.sourceEndLine}`:""}`)}))}function i(n){return e("code-finding-note",{codeSources:c(n)})}return{RULE:o,SPLIT_SCOPE_RULE:r,SUB_KIND_DEFS:a,STRUCTURE_SCOPE_RULE:p,codeSourceLabels:c,codeFindingNote:i}}import{posix as V}from"node:path";function Q(t){let{bundleText:e}=t,o=.25,r=4;function a(c){let i=new Set(c.map(l=>l.name)),n=new Map(c.map(l=>[l.name,new Set(l.skills.filter(m=>m!==l.name&&i.has(m)))])),s=new Map;for(let l of n.values())for(let m of l)s.set(m,(s.get(m)??0)+1);let d=Math.max(r,(c.length-1)*o);return c.map(l=>({name:l.name,linkedFrom:s.get(l.name)??0,linksTo:n.get(l.name).size})).filter(l=>l.linkedFrom>=d||l.linksTo>=d)}function p(c){let i=a(c);if(!i.length)return null;let n=i.map(s=>e("shape-shared-skill",s));return e("analysis-split-check-shared-skills-1",{v0:n.join(`
|
|
4
|
-
`)})}return{sharedSkillsOf:a,sharedSkillsText:p}}function W(t){let{bundleText:e}=t,{shapeFindingsText:o}=M(t),{sharedSkillsText:r}=Q(t);function a(c){let i=new Map(c.map((n,s)=>[n.name,`s${s+1}`]));return e("shape-skills",{skills:c.map(n=>({...n,id:i.get(n.name),refs:n.references.map(s=>V.relative(V.dirname(n.path),s)).join(","),tools:n.tools.join(","),links:n.skills.map(s=>i.get(s)).join(","),hasRefs:n.references.length>0,hasTools:n.tools.length>0,hasLinks:n.skills.length>0,hasDetails:n.references.length>0||n.tools.length>0||n.skills.length>0}))})}function p(c){return e("shape-inventory",{agent:c.agent,v0:a(c.skills),shared:r(c.skills),tools:c.tools.map(i=>({...i,skills:i.skills.join(", ")})),subAgents:c.subAgents.map(i=>({...i,tools:i.tools.join(", "),skills:a(i.skills)})),prompts:c.prompts,knowledge:c.knowledge.map(i=>({...i,headings:i.sections.map(n=>`${n.startLine}-${n.endLine} ${n.heading}`).join(`
|
|
5
|
-
`)})),findings:o(c.findings)})}return{inventoryText:p}}function X(t){let{SPLIT_SCOPE_RULE:e}=_(t),{inventoryText:o}=W(t);function r(a){return{scopeRule:e,open:R(a.open),inventory:o(a)}}return{shapeInputs:r,SPLIT_SCOPE_RULE:e}}function O(t){let{bundleText:e}=t,o={contradiction:{def:e("analysis-categories-1"),evidence:e("analysis-categories-2")},ambiguity:{def:e("analysis-categories-3"),evidence:e("analysis-categories-4")},bypassable_requirement:{def:e("analysis-categories-5"),evidence:e("analysis-categories-6")},stale_fact:{def:e("analysis-categories-7"),evidence:e("analysis-categories-8")},description_mismatch:{def:e("analysis-categories-9"),evidence:e("analysis-categories-10")},ungoverned_tool:{def:e("analysis-categories-11"),evidence:e("analysis-categories-12")},untrusted_instructions:{def:e("analysis-categories-13"),evidence:e("analysis-categories-14")},better_as_code:{def:e("analysis-categories-15"),evidence:e("analysis-categories-16")}},r={untrusted_instructions:{derive:"analysis-categories-17",check:"analysis-categories-18"},better_as_code:{derive:"analysis-categories-19",check:"analysis-categories-20"}};function a(i){return j(i).map(n=>{let s=o[n];return e("category-entry",{category:n,definition:s.def,evidence:s.evidence})}).join(`
|
|
6
|
-
`)}function p(i,n){return j(i).map(s=>{let d=r[s]?.[n];return d?`
|
|
7
|
-
|
|
8
|
-
${e(d,{promptAgreement:S(i)})}`:""}).join("")}function c(){return[e("analysis-categories-21"),e("analysis-categories-22"),e("analysis-categories-23"),e("analysis-categories-24"),e("analysis-categories-25"),e("analysis-categories-26")].join(`
|
|
9
|
-
`)}return{categoryBlock:a,categoryRules:p,impactBlock:c}}function Y(t){let{checkPromptBlocks:e}=G(t),{shapeInputs:o}=X(t),{templates:r}=t,{categoryBlock:a,categoryRules:p}=O(t);function c(i,n,s,d={}){if(i==="derive-shape")return{...n,...o(n.inventoryData)};if(i.startsWith("check-findings")||i==="second-opinion"){let l=e(n.checkInput),m=a(s),u=p(s,"check"),x=S(s),h={...n,promptAgreement:x,categories:m,categoryRules:u,core:l[0].text,claims:l[1].text};if(i!=="second-opinion")return h;let g;try{if(typeof n.checkTemplate!="string")throw new Error;g=D("check",s,n.checkTemplate)}catch{throw new Error("Unknown check template")}let y=typeof g=="string"&&Object.hasOwn(d,g)?d[g]:void 0;if(y?.route!=="finding_check"||y.system===void 0)throw new Error("Unknown check template");return{...h,checkSystem:b(y.system,{promptAgreement:x,categories:m,categoryRules:u},r)}}return n}return{stageInputs:c}}var Z="<<<BEGIN REPOSITORY TEXT>>>",q="<<<END REPOSITORY TEXT>>>";function I(t){let e=t;for(let o="";o!==e;)o=e,e=e.replaceAll(Z,"").replaceAll(q,"");return`${Z}
|
|
10
|
-
${e.replaceAll("{{","{ {")}
|
|
11
|
-
${q}`}function ee(t,e){return{location:I(String(t.location)),text:I(String(t.text)),usage:I(t.usage===null?e.bundleText("code-check-no-usage"):String(t.usage))}}function te(t){let{categoryBlock:e,categoryRules:o,impactBlock:r}=O(t),{codeSourceLabels:a,codeFindingNote:p,RULE:c,SPLIT_SCOPE_RULE:i,STRUCTURE_SCOPE_RULE:n,SUB_KIND_DEFS:s}=_(t),{bundleText:d}=t;function l(m,u,x){if(m==="finding-headlines")return{data:JSON.stringify(u.evidence),choiceCategories:C.join(", ")};if(m==="judge-code-prompt")return ee(u,t);if(m.startsWith("derive-findings"))return{...u,promptAgreement:S(x),pass:u.pass??null,codeSources:a(u.codeSources??[]),categories:e(x),categoryRules:o(x,"derive"),impacts:r()};if(m==="derive-structure"){let h=u.loadModesData,g=u.openStructuresData,y=u.findingsData;return{...u,findings:(y??[]).map(f=>({...f,category:f.category??"\u2014",excerpt:f.excerpt??"",site:f.site?{...f.site,line:f.site.line??"?"}:null,otherSites:(f.otherSites??[]).map(k=>({...k,line:k.line??"?",excerpt:k.excerpt??""})),question:f.question??"",options:f.fixes.map(k=>k.title)})),subKinds:s,scopeRule:n,open:R(g,{includeFiles:!1}),loadModes:h.map(f=>{let k=f.evidenceKind?d("load-evidence-skill-frontmatter"):f.evidence;return d("analysis-derive-structures-11",{v0:f.path,v1:f.mode,v2:f.unit??"no unit",v3:f.via,v4:k?` (${k})`:""})}).join(`
|
|
12
|
-
`)}}if(m==="scope-items"){let h=u.scopeRuleId==="structure"?n:u.scopeRuleId==="split"?i:"";return{items:u.items??[],scopeRule:h}}if(m==="scope-findings"){let h=u.codeSources,g=u.codeFiles,y=p(h);return{...u,system:y?d("scope-system-code")+`
|
|
13
|
-
|
|
14
|
-
`+y:c,code:g.length?d("code-evidence",{files:JSON.stringify(g)}):""}}return u}return{enrichRequestInputs:l,headlineFallbackQuestion:()=>t.description("finding-headlines-fallback-question")}}function ne(t,e){if(!Object.hasOwn(e.templates,t.template))throw new Error(`Unknown template: ${t.template}`);if(!Object.hasOwn(e.answerFormats,t.answerFormat))throw new Error(`Unknown answer format: ${t.answerFormat}`);let o=e.templates[t.template],r=t.limits??{};if(r.maxTokens!==void 0&&(!Number.isSafeInteger(r.maxTokens)||r.maxTokens<=0))throw new Error("Invalid maxTokens");let a=b(o.prompt,t.inputs,e.includes),p=o.promptBlocks?.map(c=>({text:b(c.text,t.inputs,e.includes),...c.cache?{cache:!0}:{}}));if(p&&p.map(c=>c.text).join("")!==a)throw new Error("Registered blocks must match the prompt");return{route:o.route??t.template,model:t.model,...o.system===void 0?{}:{system:b(o.system,t.inputs,e.includes)},prompt:a,...p?{promptBlocks:p}:{},schema:e.answerFormats[t.answerFormat],...r.maxTokens===void 0?{}:{maxTokens:r.maxTokens},...r.effort===void 0?{}:{effort:r.effort},...r.thinking===void 0?{}:{thinking:r.thinking}}}var B=class extends Error{name="InputBudgetError"};function nt(t){let{templates:e,descriptions:o}=t,{withDescriptions:r}=A(t),a=U(r,t.description);function p(){let s={prompt:e["check-evidence"],promptBlocks:[{text:"{{core}}"},{text:"{{claims}}"}]},d=z({"benchmark-judge":{system:e["benchmark-judge"],prompt:"{{data}}"},"judge-code-prompt":{prompt:e["judge-code-prompt"]},"derive-findings":{prompt:e["derive-findings"]},"derive-findings-legacy":{prompt:e["derive-findings-legacy"]},"derive-findings-no-outcome":{prompt:e["derive-findings-no-outcome"]},"derive-findings-legacy-no-outcome":{prompt:e["derive-findings-legacy-no-outcome"]},"derive-structure":{prompt:e["derive-structure"]},"structure-recheck":{system:e["structure-recheck-system"],prompt:e["structure-recheck"]},"derive-shape":{prompt:e["derive-shape"]},"scope-items":{prompt:e["scope-items"],system:e["scope-system"]},"scope-findings":{prompt:e["scope-findings"],system:"{{system}}"},"check-findings":{...s,system:e["check-findings"]},"check-findings-precision-v1":{...s,system:e["check-findings-precision-v1"]},"second-opinion":{...s,system:e["opinion-system"]},"explain-sources":{prompt:e["source-evidence"],system:e["explain-sources"]},"finding-headlines":{system:e["finding-headlines"],prompt:"{{data}}"}});return Object.fromEntries(Object.entries(d).map(([l,m])=>[l,{...m,...m.promptBlocks?{promptBlocks:E(m.promptBlocks,w({},{template:l}).breakpoints)}:{}}]))}function c(){return{templates:p(),includes:e,answerFormats:a,descriptions:o,policy:v()}}function i(s,d={}){let l=Object.hasOwn(v(),s.template)?$(s.template,s.answerFormat,d):s.answerFormat;return ie({...s,answerFormat:l},c(),d)}function n(s,d={}){let l=se(N(s,d),c());return{...l,schema:l.schema}}return{instructionRegistry:c,analysisModelRequest:i,analysisRequest:n,buildAnalysisCall:s=>se(s,c()),withDescriptions:r,callInputBytes:oe}}function oe(t){return Buffer.byteLength(t.prompt)+Buffer.byteLength(t.system??"")}function ie(t,e,o){let r=e.policy??v();if(!Object.hasOwn(r,t.template)||!r[t.template].answerFormats.includes(t.answerFormat))throw new Error("Unsupported template answer format");if(!Object.hasOwn(v(),t.template))return{...t,inputs:t.inputs};let a=K({templates:e.includes??{},descriptions:e.descriptions??{}}),{stageInputs:p}=Y(a),{enrichRequestInputs:c}=te(a);return{...t,inputs:c(t.template,p(t.template,t.inputs,o,e.templates),o)}}function se(t,e){let o=L.parse({template:t.template,inputs:t.inputs,answerFormat:t.answerFormat,model:t.model,...t.limits?{limits:t.limits}:{}}),{data:r,settings:a,maxInputBytes:p}=o.inputs,c=ne(ie({...o,inputs:r},e,a),e);if(p!==void 0&&oe(c)>p)throw new B("serialized evidence exceeds the priced input budget");let i=o.template==="judge-code-prompt"?T.object({path:T.string(),line:T.number()}).parse(r.at):o.template==="structure-recheck"?T.object({childId:T.string()}).parse(r):{};return{...c,...Object.hasOwn(v(),o.template)&&o.template!=="benchmark-judge"?{context:i}:{}}}export{ne as a,re as b,F as c,G as d,_ as e,Q as f,W as g,X as h,O as i,Y as j,te as k,B as l,nt as m,oe as n,se as o};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as f,c as r,e as m,g as p}from"./6B2HILSY.js";import{b as o}from"./SKVEBOGA.js";import{a as c}from"./A7WJJMRY.js";import{e as x}from"./KWECQJ6X.js";import{a as d,b as u}from"./FSLWD2PE.js";import{z as s}from"zod";var g={expectedOutcome:{setting:"CF_FIX_EXPECTED_OUTCOME",enabled:e=>e.CF_FIX_EXPECTED_OUTCOME!=="0",suffix:"-no-outcome",suffixWhen:!1},untrustedContent:{setting:"CF_UNTRUSTED_CONTENT_CHECK",enabled:d,suffix:"-no-untrusted",suffixWhen:!1},betterAsCode:{setting:"CF_FINDING_BETTER_AS_CODE",enabled:u,suffix:"-better-as-code",suffixWhen:!0},audience:{setting:"CF_FINDING_AUDIENCE",enabled:c,suffix:"-audience",suffixWhen:!0}};function h(e){let t=Object.entries(g).map(([n,i])=>({key:n,rule:i,enabled:i.enabled(e)}));return{name:`findings${t.map(({rule:n,enabled:i})=>i===n.suffixWhen?n.suffix:"").join("")}`,switches:Object.fromEntries(t.map(({key:n,enabled:i})=>[n,i])),settings:Object.fromEntries(t.map(({rule:n,enabled:i})=>[n.setting,i?"1":"0"]))}}function D(){let e=[{}];for(let{setting:t}of Object.values(g))e=e.flatMap(n=>["0","1"].map(i=>({...n,[t]:i})));return e.map(t=>({...h(t),schema:F(t)}))}function b(e){return s.object({findings:s.array(e.shape.findings.element.extend({fixes:s.array(r.omit({expectedOutcome:!0})).min(1)}))})}var E=r.extend({expectedOutcome:s.string().default("")}),C=s.array(m.extend({audience:o.optional().catch(void 0),fixes:s.array(E).min(1),sourceNotes:x.nullable().optional().catch(null)}));function F(e){let t=h(e),n=p(t.settings),a=(t.switches.expectedOutcome?n:b(n)).shape.findings.element,l=o.describe(f("finding-audience"));return s.object({findings:s.array(t.switches.audience?a.extend({audience:l.catch(void 0)}):a)})}function W(e){return O(e.findings)}function O(e){return C.parse(e)}export{h as a,D as b,F as c,W as d,O as e};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as ke,B as ne,C as wt,D as kt,E as ae,F as St,G as bt,H as vt,I as Ft,J as L,K as Rt,L as yt,M as Et,N as Ot,T as xt,V as Mt,Z as Ct,_ as Bt,a as ge,b as nt,c as at,d as it,e as lt,f as oe,g as Pe,h as ct,i as re,j as N,k as q,l as dt,m as U,ma as It,n as G,o as W,oa as At,p as pt,pa as Lt,q as ft,qa as Tt,r as mt,ra as _t,s as Y,t as ht,u as ut,v as we,w as se,x as gt,y as Pt,z as D}from"./QFY6A3MS.js";import{a as rt}from"./OPMA32A6.js";import{i as ot}from"./K2GNDX3W.js";import{a as te}from"./QDYMR6KS.js";import{a as st}from"./4H23CSUM.js";import{a as Ye}from"./SVMEWGD3.js";import{a as qe,g as Ue,h as Ge,i as We,o as Z}from"./FOKDE64Y.js";import{a as tt}from"./3JWEFCTJ.js";import{C as $,e as ee,f as Je,h as Ve,t as Ze,w as et}from"./377MLK4M.js";import{a as K}from"./326F4XNG.js";import{c as Xe,e as Qe}from"./ZTOVBAG7.js";import{n as z}from"./KTNA2KTN.js";import{b as H,c as J}from"./2PSNOSJ2.js";import{A as O,B as Ae,Gb as $e,I as Le,J as he,Ja as Ke,Ua as Q,V,Y as Te,Z as _e,aa as je,ba as X,bb as De,e as Be,l as me,n as A,o as Ie,ra as R,tb as He,wa as ze,xa as Ne}from"./NIOS7U6C.js";import{b as Ee}from"./724WZMYW.js";import{c as I,e as T}from"./C6X5GDG4.js";import{c as ue}from"./MJGB25S5.js";import{f as fe,i as Oe,j as xe,m as Me,n as Ce}from"./JKWTHRUR.js";var jt=(r,e)=>{let{markerToRead:s}=re(e.settings,{paths:r.map(({path:n})=>n),root:e.dir??void 0,scanFlag:e.flags.scan,marker:null});return s?{strength:"partial",wants:[s]}:null};function zt(r,e,s="bare"){let{scan:n}=re(e.settings,{paths:r.map(({path:t})=>t),root:e.dir??void 0,scanFlag:e.flags.scan,marker:s});return n?{strength:"partial",wants:[]}:null}var no=2e3;function ie(r,e,s,n={}){let t=e.filter(P=>I(P.path,s)!=null),i={},a=[],p=new Map,d=n.mode!=="core"&&Ke(r),f=z(r,t.map(P=>P.path),s,{mode:d?"all":"core",files:n.files}),l=new Set([...f.ignoredPaths,...f.ignoredImportPaths]),o=new Map(f.files.filter(P=>P.role!=="reference").map(P=>[P.path,P])),c=new Map(f.scopes.map(P=>[P.key,O.conventionImport.totalBytes])),m=O.conventionImport.skillBytes,u=me(r)?O.codeAgent.importBytes:1/0,g=0,w=P=>I(P.path,f.ownerOf(P.path).folder)??P.path,h=(P,b)=>{p.set(P.path,{path:P.path,reason:b})},S=(P,b)=>{let v=R(r,P,{purpose:b,route:"github",root:s});return v.admitted?!0:(h(P,v.reason),!1)},k=P=>{if(i[P.path])return;let b=d&&o.get(P.path)?.role==="skill"?"skill":"core",v=f.ownerOf(P.path),M=b==="skill"?m:c.get(v.key),y=P.size??0;if(b==="skill"&&g>=O.conventionImport.skillFiles){h(P,"allowance");return}if(y>M||y>u){h(P,"total");return}i[P.path]=P.ref,a.push(P.path),u-=y,b==="skill"?(m-=y,g++):c.set(v.key,M-y)},E=t.filter(P=>o.has(P.path));for(let P of E)S(P,je(o.get(P.path).role))&&k(P);let F=0;if(ee(r))for(let P of De(new Set(t.map(b=>b.path)))){let b=t.find(v=>v.path===P);if(F>=O.conventionImport.extractionFiles){h(b,"allowance");continue}if(S(b,"source")&&S(b,"definition")){let v=a.length;k(b),a.length>v&&F++}}let B=f.needsExtraction;if(B){let P=t.flatMap(v=>{if(l.has(v.path)||i[v.path]||d&&Le(w(v)))return[];if(!S(v,"extraction"))return[];let M=Ne(w(v));return M===null?[]:[{entry:v,rank:M}]}).sort((v,M)=>v.rank-M.rank||(v.entry.size??0)-(M.entry.size??0)),b=F;for(let{entry:v}of P){if(b>=O.conventionImport.extractionFiles){h(v,"allowance");continue}let M=a.length;k(v),a.length>M&&b++}}if(d&&n.files){let P=Se(r,{entries:e,selected:t.filter(b=>Object.hasOwn(i,b.path)),files:n.files,root:s});for(let b of P.paths)Object.hasOwn(i,b)||(a.push(b),i[b]=t.find(v=>v.path===b).ref);for(let b of P.refused)p.set(b.path,b)}return{...me(r)&&E.some(P=>!Object.hasOwn(i,P.path))?{definitionsOmitted:!0}:{},selectedPaths:a,shaByPath:i,treeListing:t.slice(0,no).map(P=>P.path),needsExtraction:B,refused:[...p.values()]}}function Se(r,e){let s=new Set(e.selected.map(i=>i.path)),n=z(r,e.entries.map(i=>i.path),e.root,{files:e.files}).files.filter(i=>i.role==="skill"&&s.has(i.path)).map(i=>i.path),t=Je(r,{skillPaths:n,paths:e.entries.map(i=>i.path),files:e.files,sizes:new Map(e.entries.map(i=>[i.path,i.size])),selected:e.selected,root:e.root,admission:e.admission,referencePaths:e.referencePaths});return{paths:[...new Set(t?.flatMap(i=>i.files.map(a=>a.path))??[])],refused:t?.flatMap(i=>i.refused)??[]}}var Nt=(r,e)=>{let s=ie(e.settings,r,e.dir??void 0,{mode:e.mode});return{strength:"partial",wants:s.selectedPaths,state:{needsExtraction:s.needsExtraction,treeListing:s.treeListing,shaByPath:s.shaByPath,refused:s.refused,...s.definitionsOmitted?{definitionsOmitted:!0}:{}}}};var Kt=["marker","code-scan","conventions"];var ao={marker:jt,"code-scan":zt,conventions:Nt};function be(r,e,s,n,t=ao){let i={...s,settings:r},a={readers:[]};for(let p of Kt)if(!(n&&!n.includes(p)))try{let d=t[p]?.(e,i);d&&a.readers.push({id:p,claim:d,done:!1})}catch{}return a}function Vo(r){return{readers:r.readers.map(({id:e,done:s})=>({id:e,done:s}))}}function Dt(r){let e=r.readers.find(({id:s})=>s==="conventions").claim;return{selectedPaths:e.wants,...e.state}}function _(r,e,s,n){let t=new Set(s.map(h=>I(h.path,n))),i=r.CF_READING_NOTE_AGENT_ONLY!=="0"&&qe(r),a=new Set(e.agents),p=h=>!t.has(h)&&(!i||a.has(h)),d=e.instruction.filter(p),f=e.code.filter(p),l=e.agents.filter(h=>!t.has(h)),o=new Set(Ge(l)),c=[...d,...f].every(h=>o.has(h)),m=d.length,u=f.length,g=[!c&&m>0&&`${m} instruction file${m===1?"":"s"} left out by the ${Math.round(O.sourceFetch.instructionBytes/1e3)}KB instruction budget`,!c&&u>0&&`${u} analyzable file${u===1?"":"s"} left out by the ${Math.round(O.sourceFetch.codeBytes/1e3)}KB/${O.sourceFetch.codeFiles}-file code budget \u2014 the analysis reads the most agent-shaped files first`,We(l,i)].filter(Boolean),w=s.filter(h=>h.readBytes!==void 0).map(h=>I(h.path,n));return w.length&&g.push(`${w.join(", ")}: only the first ${O.sourceFetch.codeFileBytes/1e3} KB was read`),g.length?g.map((h,S)=>S<g.length-1?String(h).replace(/\.$/,""):h).join("; "):void 0}function le(r,e,s,n={}){let{descriptions:t,priority:i,declarations:a}=Ye(r,e,{root:s},n),p=[],d=t.flatMap(k=>k.admission.admitted?[{entry:k.readEntry,rel:k.rel,score:k.score,size:k.readEntry.size,pool:k.pool,...k.tier===void 0?{}:{tier:k.tier}}]:(p.push({path:k.entry.path,reason:k.admission.reason}),[])),f=d.filter(({score:k})=>k===0).sort(Z),l=d.filter(({score:k})=>k>0).sort(Z),o=[],c={instruction:0,code:0},m={instruction:[],code:[]},u=0,g=(i.enabled?[...d].sort(Z):[...f,...l]).sort((k,E)=>Number(a.has(E.entry.path))-Number(a.has(k.entry.path)));for(let{entry:k,rel:E,pool:F}of g){let B=F==="instruction"?O.sourceFetch.instructionBytes:O.sourceFetch.codeBytes;if(c[F]+k.size>B||F==="code"&&u>=O.sourceFetch.codeFiles){m[F].push(E),p.push({path:k.path,reason:c[F]+k.size>B?"total":"allowance"});continue}o.push(k),c[F]+=k.size,F==="code"&&(u+=1)}let w=Ue(i,p.flatMap(k=>{let E=I(k.path,s);return E===null?[]:[{...k,path:E}]})),h={...m,agents:w},S=_(r,h,o,s);return{selected:o,totalBytes:c.instruction+c.code,refused:p,...S?{skippedNote:S}:{},...i.enabled&&S?{readingNotes:h}:{}}}function ce(r,e){let s=Ae(r),n=s.length?{scopeSelections:s}:{},t={dir:e.root??null,mode:e.profile==="hosted-import"?e.mode??"all":"all",flags:e.profile==="hosted-import"?e.flags??W(r):W(r)};if(e.profile==="hosted-import"){let p=be(r,e.listing,t);return{profile:e.profile,...p,...n,selection:Dt(p),...A(r)?{mode:t.mode}:{}}}let i=e.listing.filter(p=>R(r,p,{purpose:"pointer",route:"github",root:e.root}).admitted),a=be(r,i,t,["marker","code-scan"]);return{profile:e.profile,...a,...n,listing:i,selection:e.selection??le(r,e.listing,e.root),context:t,...e.selection&&A(r)?{selectionPaths:e.selection.selected.map(p=>p.path)}:{}}}import{posix as lo}from"node:path";function Ht(r,e,s){let n=new Set(e.entries.map(l=>l.path)),t=new Set(V(r,[...n])),i=Object.fromEntries(Object.entries(e.files).filter(([l])=>e.selected.some(o=>o.path===l&&o.readBytes===void 0))),a=new Set(_e(r,[...n],i)),p=[],d=new Set;return{read:async l=>{if(a.has(l.path)||e.managedReadPaths?.includes(l.path)&&e.files[l.path]===void 0)return e.refused.push({path:l.path,reason:"unreadable"}),null;p.push(l);try{let o=await s(l);if(o!==null){if(d.has(l.path)){let c=R(r,{path:l.path,size:Buffer.byteLength(o),text:o},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:n,managedFiles:e.files});if(!c.admitted)return e.refused.push({path:l.path,reason:c.reason}),null}if(A(r)||Ee(r)){let c=R(r,{path:l.path,text:o},{...e.admission,purpose:"override",route:"github",root:e.root,listing:n,managedFiles:e.files});if(!c.admitted)return e.refused.push({path:l.path,reason:c.reason}),null}if(e.phase==="manifest"){let c=R(r,{path:l.path,size:Buffer.byteLength(o)},{...e.admission,purpose:"pointer",route:"github",root:e.root});if(!c.admitted)return e.refused.push({path:l.path,reason:c.reason}),null}return o}}catch(o){if(o instanceof X&&(o.reason==="secret-content"||A(r)||d.has(l.path)||t.has(l.path)))return e.refused.push({path:l.path,reason:o.reason}),null;if(e.profile==="hosted-import"&&!d.has(l.path)&&!t.has(l.path))throw o}return e.refused.push({path:l.path,reason:"unreadable"}),null},requestedReads:p,skillReads:d}}import{createHash as io}from"node:crypto";function ve(r){return io("sha256").update(JSON.stringify(r.map(({path:e,ref:s,size:n})=>({path:e,ref:s,size:n})))).digest("hex")}function $t(r,e,s){return $(r)?{settings:Qe(r),commit:s??ve(e),revisionKind:s===void 0?"listing":"commit",completed:[]}:void 0}function qt(r,e,s){let n=r.agentPages;if(!n)return;let t=s??n.listingEntries??r.entries,i=n.revisionKind??(n.commit===ve(n.listingEntries??r.entries)?"listing":"commit");if(i==="commit"&&e!==void 0&&n.commit!==e||i==="listing"&&n.commit!==ve(t))throw new Error("stale-agent-page");return n.commit}function Ut(r,e,s){e.ranked??=se(r,e.scan,new Map);let n=new Map([...we(e.scan.plan),...Object.entries(e.agentPages?.actualSizes??{})]),t=ge(r,e.ranked,n,new Map,{files:{},...e.agentPages?{page:{commit:e.agentPages.commit,scope:e.root,continuation:s}}:{}});t.page&&(e.ranked={...e.ranked,agentPage:t.page,strong:t.strong,possible:t.window,notRead:t.notRead,notReadMore:t.notReadMore});let i=[...t.refused,...e.ranked.skippedFiles??[]];if(e.requestedPaths.push(...i.map(a=>a.path)),e.refused.push(...i),e.profile==="hosted-import"&&t.paths.length||t.page){let a=Pt(r,[],t.paths,e.scan.plan);e.refused.push(...a.refused),e.profile==="hosted-import"?bt(e,a.selected):(kt(r,e),ae(e,a.selected))}else ne(r,e,t.paths,e.scan.plan);e.phase=e.selected.length?"files":"done"}function Gt(r,e,s,n){let t={...e.agentPages.actualSizes};s.forEach((o,c)=>{n[c]!==null&&(t[o.path]=Buffer.byteLength(n[c]))}),e.agentPages={...e.agentPages,actualSizes:t};let i=new Map([...we(e.scan.plan),...Object.entries(t)]),a=new Map(Object.entries(e.files).map(([o,c])=>[o,Buffer.byteLength(c)])),p=new Set(e.skillReferencePaths),d=new Set([...e.conventionPaths,...St(e),...p,...e.markerPath?[e.markerPath]:[]]);for(let o of s)if(d.has(o.path)&&t[o.path]!==void 0){let c=R(r,{path:o.path,size:t[o.path]},{purpose:p.has(o.path)?"skill":"pointer",route:"github",root:e.root,listing:new Set(e.entries.map(u=>u.path)),managedFiles:e.files}),m=Ve(a).left+(a.get(o.path)??0);c.admitted&&t[o.path]<=m?a.set(o.path,t[o.path]):e.refused.push({path:o.path,reason:c.admitted?"total":c.reason})}let f=ge(r,e.ranked,i,a),l=new Set(f.paths);s.forEach((o,c)=>{n[c]!==null&&(l.has(o.path)||d.has(o.path)&&a.has(o.path)?e.files[o.path]=n[c]:e.refused.push(f.refused.find(m=>m.path===o.path)??f.skippedFiles?.find(m=>m.path===o.path)??{path:o.path,reason:"total"}))}),e.ranked={...e.ranked,agentPage:f.page,strong:f.strong,possible:f.window}}function Fe(r){let e=r.ranked,s=e?.agentPage;if(!s||r.phase!=="done")return;let n=[...e.agentInventory.strong,...e.agentInventory.possible],t=new Set(s.selected),i=new Set(s.refusals.map(d=>d.id)),a=n.filter(d=>t.has(Q(d.prompt))&&!i.has(Q(d.prompt))&&r.files[d.prompt.path]===void 0),p=[...s.refusals,...a.map(d=>({id:Q(d.prompt),reason:r.refused.find(f=>f.path===d.prompt.path)?.reason??"missing"}))];r.ranked={...e,strong:e.strong.filter(d=>r.files[d.prompt.path]!==void 0),possible:e.possible.filter(d=>r.files[d.prompt.path]!==void 0),agentPage:{...s,refusals:p,partial:p.length>0,estimatedInputBytes:Object.values(r.files).reduce((d,f)=>d+Buffer.byteLength(f),0)}}}async function Wt(r,e,s){if(!A(r))return!1;let n=Te(r,e.entries.map(o=>o.path));if(!n.length)return!1;let t=new Set(n.flatMap(o=>o.agents)),i=new Map(e.selected.map(o=>[o.path,o])),a=new Set(e.selected.filter(o=>o.readBytes===void 0&&e.files[o.path]!==void 0).map(o=>o.path));e.managedReadPaths||(e.managedReadPaths=[],(e.scan||e.ranked)&&(delete e.scan,delete e.ranked,delete e.manifestReadPaths,e.phase!=="marker"&&(e.phase="scan")));let p=new Set([...e.managedReadPaths,...a]),d=e.entries.filter(o=>t.has(o.path)&&i.has(o.path)&&!p.has(o.path)),f=d.slice(0,D);if(!f.length)return!1;let l=await K(f,4,async o=>{let c=R(r,o,{...e.admission,purpose:"pointer",route:"github",root:e.root});return c.admitted?s(o):(e.refused.push({path:o.path,reason:c.reason}),null)});if(f.forEach((o,c)=>{l[c]!==null&&(e.files[o.path]=l[c],e.selected=e.selected.map(m=>m.path===o.path?o:m))}),e.managedReadPaths.push(...f.map(o=>o.path)),d.length>f.length){for(let o of Object.keys(e.files))!t.has(o)&&n.some(c=>I(o,c.folder)!==null)&&delete e.files[o];e.cursor=0,(e.phase==="done"||e.phase==="manifest")&&(e.phase="files")}return!0}async function Yt(r,e,s){if(e.marketplacePlanned)return!1;let n=new Set(V(r,e.entries.map(o=>o.path)));if(!e.selected.some(o=>n.has(o.path)))return!1;let t=new Set(e.marketplaceReadPaths),a=e.selected.filter(o=>n.has(o.path)&&!t.has(o.path)).slice(0,D),p=await K(a,4,async o=>{let c=R(r,o,{...e.admission,purpose:"definition",route:"github",root:e.root});if(!c.admitted)return e.refused.push({path:o.path,reason:c.reason}),null;let u=(o.readBytes===void 0?e.files[o.path]:void 0)??await s({path:o.path,size:o.size,ref:o.ref});if(u===null)return null;let g=R(r,{path:o.path,size:Buffer.byteLength(u),text:u},{...e.admission,purpose:"definition",route:"github",root:e.root});return g.admitted?u:(e.refused.push({path:o.path,reason:g.reason}),null)});a.forEach((o,c)=>{p[c]!==null?e.files[o.path]=p[c]:delete e.files[o.path]}),e.marketplaceReadPaths=[...t,...a.map(o=>o.path)];let d=new Map(a.flatMap((o,c)=>p[c]===null?[]:[[o.path,Buffer.byteLength(p[c])]]));e.agentPages&&d.size&&(e.agentPages={...e.agentPages,listingEntries:e.agentPages.listingEntries??e.entries}),e.entries=e.entries.map(o=>d.has(o.path)?{...o,size:d.get(o.path)}:o);let f,l=e.marketplaceSelection?new Set(e.marketplaceSelection):void 0;do{let o=new Set(e.marketplaceReadPaths.filter(h=>e.files[h]===void 0)),c=e.entries.filter(h=>!o.has(h.path)&&(!l||l.has(h.path))),m=e.profile==="local-analysis"?le(r,c,e.root,{files:e.files}):ie(r,c,e.root,{files:e.files,mode:e.marketplaceMode}),u="selected"in m?m.selected.map(h=>h.path):m.selectedPaths,g=new Set(u),w=new Map(c.map(h=>[h.path,h]));e.selected=u.map(h=>w.get(h)),e.selectionRefused=m.refused,e.hosted&&"selectedPaths"in m&&(e.hosted.fallback=m,e.hosted.codeMode||(e.hosted.needsExtraction=m.needsExtraction)),f=Object.keys(e.files).filter(h=>n.has(h)&&!g.has(h));for(let h of f)e.refused.push(m.refused.find(S=>S.path===h)??{path:h,reason:"total"});for(let h of Object.keys(e.files))g.has(h)||delete e.files[h]}while(f.length);return e.conventionPaths=z(r,e.entries.filter(o=>!n.has(o.path)||e.files[o.path]!==void 0).map(o=>o.path),e.root,{files:e.files}).files.filter(o=>o.role!=="reference").map(o=>o.path),e.cursor=0,e.marketplacePlanned=!e.selected.some(o=>n.has(o.path)&&!e.marketplaceReadPaths.includes(o.path)),a.length>0||!e.marketplacePlanned}function Re(r,e){let{plan:s,entries:n}=e,t=s.profile==="local-analysis"?s.context.dir??"":e.root??"",i=s.readers.find(l=>l.id==="marker")?.claim.wants[0],a=s.readers.some(l=>l.id==="code-scan"),p=new Map(n.map(l=>[l.path,l])),d=s.profile==="local-analysis"?s.selection.selected:s.selection.selectedPaths.flatMap(l=>p.has(l)?[p.get(l)]:[]),f=ct(r)?N(r,{phase:"start",root:t,paths:n.map(l=>l.path),scanFlag:!!i||a}):void 0;return{...$(r)?{agentPages:$t(r,n,e.commit)}:{},version:1,profile:s.profile,root:t,entries:n,selected:[...d],..."mode"in s?{marketplaceMode:s.mode}:{},..."selectionPaths"in s?{marketplaceSelection:s.selectionPaths}:{},conventionPaths:s.profile==="hosted-import"||$(r)?z(r,n.map(l=>l.path),t).files.filter(l=>l.role!=="reference").map(l=>l.path):[],...e.admission?{admission:e.admission}:{},selectionRefused:s.selection.refused,requestedPaths:[],refused:[],files:{},cursor:0,treeTruncated:e.treeTruncated??!1,...s.profile==="hosted-import"?{hosted:{fallback:structuredClone(s.selection),weakCodeFallback:r.CF_IMPORT_WEAK_CODE_FALLBACK!=="0",codeMode:!1,needsExtraction:s.selection.needsExtraction}}:{},decision:f??(i?{kind:"marker",markerPath:i,scanIfBare:a}:{kind:"settled",markerPath:null,markerKind:null,scan:a}),phase:i?"marker":a?"scan":"files"}}async function Jt(r,e,s){if(e.version!==1)throw new Error("unsupported-import-checkpoint");e.agentPages&&(r=e.agentPages.settings,qt(e,s.commit));let n=ke(r,e.profile),t={...e,selected:[...e.selected],files:{...e.files},requestedPaths:[...e.requestedPaths],refused:[...e.refused],...e.hosted?{hosted:{...e.hosted}}:{},...e.managedReadPaths?{managedReadPaths:[...e.managedReadPaths]}:{}},{read:i,requestedReads:a,skillReads:p}=Ht(n,t,o=>s.read(o));if(await Yt(n,t,i))return L(n,t,a);if(await Wt(n,t,i))return L(n,t,a);if(Ft(n,t),t.phase==="done")return s.resolvedCode&&vt(t,s.resolvedCode),L(n,t,a);if(t.phase==="manifest")return await Rt(n,t,i),Fe(t),L(n,t,a);if(t.phase==="marker"&&t.decision.kind==="marker"){let o=t.decision,c=o.markerPath,m=t.entries.find(g=>g.path===c);if(t.profile==="hosted-import"){let g=R(n,m,{purpose:"pointer",route:"github",root:t.root});if(!g.admitted)return t.refused.push({path:c,reason:g.reason}),t.decision={kind:"settled",markerPath:null,markerKind:null,scan:o.scanIfBare},t.phase=o.scanIfBare?"scan":"files",L(n,t,a)}ne(n,t,[c],t.entries);let u=await i(m);if(u!==null&&(t.files[c]=u),t.decision=N(n,{phase:"read",pending:o,text:u}),t.markerPath=c,t.markerKind=t.decision.markerKind,t.markerKind!=="bare"){let g=t.profile==="hosted-import"?await s.listing():{entries:t.entries,truncated:!1};t.treeTruncated||=g.truncated;let w=await yt(n,{config:et(u).config,markerDir:c.split("/").slice(0,-1).join("/"),selected:t.profile==="hosted-import"?[]:t.selected,admission:{...t.admission,root:t.root||void 0},modelReader:!1,priorRefused:t.refused,refusalMode:"append",requestedMode:"kept-and-refused",listing:async()=>g.entries});if(t.requestedPaths.push(...w.requestedPaths),t.refused=w.refused,t.agentPages&&w.selected){let h=new Set(w.requestedPaths);t.conventionPaths=[...new Set([...t.conventionPaths,...w.selected.filter(S=>h.has(S.path)).map(S=>S.path)])]}t.profile==="hosted-import"?ae(t,w.selected??[]):w.selected&&(t.selected=w.selected)}if(t.phase=t.decision.scan?"scan":"files",t.profile!=="hosted-import"||t.markerKind!=="bare"||t.decision.scan)return L(n,t,a)}if(t.phase==="scan"){if(!t.scan){let o=mt(n,t.entries,t.root,!0,t.decision.kind==="settled"?t.decision.scanPaths:void 0);t.scan=o.state,t.refused.push(...o.refused)}if(!Y(t.scan)){let o=await gt(n,t.scan,i,{modelReader:!1,alreadyRead:new Map,size:{batch:pt,parallel:4}});t.scan=o.scan,o.selection&&(t.ranked=o.selection.ranked)}return Y(t.scan)&&Ut(n,t),L(n,t,a)}if(he(n))for(let o of t.skillReferencePaths??[])p.add(o);let d=t.selected.slice(t.cursor,t.cursor+D),f=d.filter(o=>t.files[o.path]===void 0),l=await K(f,4,i);if(t.agentPages&&t.ranked&&t.scan?Gt(n,t,f,l):f.forEach((o,c)=>{l[c]!==null&&(t.files[o.path]=l[c])}),t.cursor+=d.length,he(n)){let o=Object.fromEntries(Object.entries(t.files).filter(([h])=>t.selected.some(S=>S.path===h&&S.readBytes===void 0))),c=Se(n,{entries:t.entries,selected:t.selected,files:o,root:t.root,admission:t.admission,referencePaths:t.skillReferencePaths});t.refused=H(t.refused,c.refused);for(let h of c.refused)p.has(h.path)&&delete t.files[h.path];if(t.cursor<t.selected.length)return L(n,t,a);let m=new Map(t.selected.map(h=>[h.path,h])),u=c.paths.filter(h=>!m.has(h)||m.get(h).readBytes!==void 0),g=new Set(u.filter(h=>m.has(h)));t.cursor-=t.selected.slice(0,t.cursor).filter(h=>g.has(h.path)).length,t.selected=t.selected.filter(h=>!g.has(h.path));for(let h of g)delete t.files[h];t.requestedPaths.push(...u),u.length&&(t.skillReferencePaths=[...t.skillReferencePaths??[],...u]);let w=new Map(t.entries.map(h=>[h.path,h]));t.selected.push(...u.map(h=>{let S=w.get(h);return{path:h,size:S.size,ref:S.ref}})),wt(t,u,"fallback")}return t.cursor>=t.selected.length&&(t.phase=ee(n)&&t.ranked||A(n)?"manifest":"done"),Fe(t),L(n,t,a)}async function de(r,e){let s=Re(r,e),n;do n=await Jt(r,s,{listing:async()=>({entries:e.entries,truncated:!1}),read:e.read}),s=n.state;while(s.phase!=="done");let t={};return s.markerPath!==void 0&&(t.markerPath=s.markerPath,t.markerKind=s.markerKind),s.ranked!==void 0&&(t.ranked=s.ranked,t.scan=s.scan),{files:n.files,settled:n.settled,skippedFiles:n.refused,...t}}function co(r){return r.CF_IMPORT_PROPOSAL!=="0"}var po=new Set(["secret","secret-content","out-of-scope"]);async function fo(r,e,s,n,t,i,a){let p={...e.admission,purpose:"proposal",route:"local-folder"},d=R(r,n??{path:s},p);if(!d.admitted)return{reason:d.reason};if(!n)return{reason:a??"missing"};if(n.size>i)return{reason:"allowance"};try{let f=t??await(e.proposalRead??e.read)({...n,readBytes:void 0});if(f===null)return{reason:a??"unreadable"};let l=Buffer.byteLength(f),o=R(r,{path:s,size:l,text:f},p);return o.admitted?l>i?{reason:"allowance"}:{text:f}:{reason:o.reason}}catch(f){return f instanceof X?{reason:f.reason,invalidates:po.has(f.reason)}:{reason:"unreadable"}}}async function mo(r,e,s,n,t){let i=new Set(n.map(m=>m.path)),a=new Set(t.map(m=>m.path)),p=new Map(e.entries.map(m=>[m.path,m])),d=n.map(m=>({...p.get(m.path),readBytes:void 0})),f=m=>!i.has(m.path)&&!a.has(m.path),l=[...e.selection.selected.filter(f),...d],o=n.length||t.length?{...e.selection,selected:l,totalBytes:l.reduce((m,u)=>m+(u.readBytes??u.size),0),refused:e.selection.refused.filter(m=>!i.has(m.path))}:e.selection,c=e.evidence??{};if(t.length){let m=e.entries.filter(S=>!a.has(S.path)),{ranked:u,scan:g,markerPath:w,markerKind:h}=await de(r,{entries:m,admission:e.admission,read:async S=>Object.hasOwn(s,S.path)?s[S.path]:null,plan:ce(r,{profile:"local-analysis",listing:m,selection:o})});c={ranked:u,scan:g,markerPath:w,markerKind:h}}return{...c,files:s,selection:o,settled:[...e.settled.filter(f),...d],skippedFiles:(e.skippedFiles??[]).filter(m=>!i.has(m.path)),...t.length?{invalidated:t}:{}}}async function Vt(r,e){if(!co(r)||!e.proposal)return;let s={...e.files},n=new Map(e.entries.map(o=>[o.path,o])),t=new Map(e.unavailable?.map(o=>[o.path,o.reason])),i={},a=[],p=[],d=new Set,f=new Set(e.settled.filter(o=>o.readBytes===void 0).map(o=>o.path)),l=Object.values(s).reduce((o,c)=>o+Buffer.byteLength(c),0);for(let o of e.proposal.files){let c=lo.normalize(o.path.replace(/\\/g,"/")),m=Object.hasOwn(s,c)?Buffer.byteLength(s[c]):0,u=!e.proposalRead&&f.has(c)&&Object.hasOwn(s,c)?s[c]:void 0,g=d.has(c)?{reason:"duplicate"}:await fo(r,e,c,n.get(c),u,O.codeAgent.importBytes-l+m,t.get(c));if(d.add(c),"text"in g)l+=Buffer.byteLength(g.text)-m,s={...s,[c]:g.text},p.push({...o,path:c});else{let w=g.reason==="wrong-type"?"coding-guide":g.reason;i[w]=(i[w]??0)+1,g.invalidates&&Object.hasOwn(s,c)&&(l-=m,delete s[c],a.push({path:c,reason:g.reason}))}}return{...await mo(r,e,s,p,a),proposal:{...e.proposal,files:p},rejectedByReason:i}}import{posix as ye}from"node:path";function ho(r,e={}){return(r.CF_CHOOSE_AGENT??e.CF_CHOOSE_AGENT)!=="0"}function Qt(r,{codeAgents:e,conventions:s,root:n}){if(Be(r)||!ho(r))return;let t=new Set(e.map(f=>f.prompt.path)),i=new Map(s.agentScopes?.map(f=>[f.key,f.folder])),a=uo(e);if(a.push(...s.agents.flatMap(f=>Ze(f)?(f.definitionPaths??[]).filter(l=>f.key===null||!t.has(l)).map(l=>({folder:go(f,l,i,n),reason:l})):[])),a.some(f=>a.every(l=>Xt(f.folder,l.folder))))return;let d=a.filter((f,l)=>!a.some((o,c)=>c!==l&&Xt(o.folder,f.folder)&&(o.folder!==f.folder||c<l)));return{kind:d.length?"choose_agent":"no_agent",candidates:d}}function Xt(r,e){return r==="."||e===r||e.startsWith(`${r}/`)}function pe(r){let e=ye.dirname(r[0]);for(let s of r.slice(1))for(;e!=="."&&s!==e&&!s.startsWith(`${e}/`);)e=ye.dirname(e);return e}function uo(r){let e=r.map(()=>new Set),s=new Map(r.map((a,p)=>[a.unitKey,p])),n=new Map,t=(a,p)=>{p!==void 0&&(e[a].add(p),e[p].add(a))};r.forEach((a,p)=>{t(p,n.get(a.prompt.path)),n.set(a.prompt.path,p);for(let d of a.links??[])t(p,s.get(d.to))});let i=new Set;return r.flatMap((a,p)=>{if(i.has(p))return[];let d=[p],f=[];for(;d.length;){let l=d.pop();i.has(l)||(i.add(l),f.push(r[l].prompt.path,...r[l].ownFiles.map(o=>o.path)),d.push(...e[l]))}return[{folder:pe(f),reason:a.prompt.path}]})}function go(r,e,s,n){return r.key!==null?s.get(r.key)||ye.dirname(e):(s.get(null)??n)||"."}function Zt(r,e=[],s){return e.find(n=>at(n.key,s)===r.id)?.folder??pe(r.files.length?r.files.map(n=>n.path):[r.sourceRef?.path??"."])}function Po(r,e,s,n){let t=new Set(r.flatMap(p=>p.files.map(d=>d.path))),i=new Set(e.flatMap(p=>p.files.map(d=>d.path))),a=e.map(p=>Zt(p,s,n));return p=>i.has(p)||!t.has(p)&&a.some(d=>d==="."||d===""||p.startsWith(`${d}/`))}function wo(r,e,s){let n=Object.fromEntries(Object.entries(e.files).filter(([o])=>s(o))),t=e.selection.selected.filter(o=>Object.hasOwn(n,o.path)),i=e.settled.filter(o=>s(o.path)),a=e.selection.refused.filter(o=>s(o.path)),p=e.selection.readingNotes,d=p?{instruction:p.instruction.filter(s),code:p.code.filter(s),agents:p.agents.filter(s)}:void 0,f=_(r,d??{instruction:[],code:[],agents:[]},i),l={...e.selection,selected:t,refused:a,readingNotes:d,skippedNote:f,totalBytes:t.reduce((o,c)=>o+(c.readBytes??c.size),0)};return{files:n,selection:l,settled:i,skippedFiles:e.skippedFiles.filter(o=>s(o.path)),invalidated:e.invalidated?.filter(o=>s(o.path))}}function ko(r,e,s,n=[],t){let i=s??pe([...e]),a=r.filter(l=>l.kind==="agent").map(l=>{let o=Zt(l,n,t),c=o==="."||o===""||i===o||i.startsWith(`${o}/`);return{node:l,overlap:new Set(l.files.filter(m=>e.has(m.path)).map(m=>m.path)).size,containment:c?o.split("/").filter(m=>m&&m!==".").length+1:0}}).filter(l=>l.overlap||l.containment);a.sort((l,o)=>o.overlap-l.overlap||o.containment-l.containment);let[p,d]=a,f=!!p&&p.overlap===d?.overlap&&p.containment===d?.containment;return{target:f?void 0:p?.node,overlapping:a.filter(l=>l.overlap).map(l=>l.node),tied:f?a.filter(l=>l.overlap===p.overlap&&l.containment===p.containment).map(l=>l.node):[]}}function So(r,e,s){let n=new Set(r.map(a=>a.path)),t=!!s&&!r.some(a=>a.path===s.path&&a.role==="system prompt"),i=t?r.filter(a=>a.path!==s.path).map(a=>a.role==="system prompt"||a.role==="soul"?{...a,role:"reference"}:a):[...r];return i.push(...e.filter(a=>!n.has(a.path)&&a.path!==s?.path).map(a=>({path:a.path,role:a.role==="tools"||a.role==="config"?a.role:"reference",label:null}))),t&&i.unshift({path:s.path,role:"system prompt",label:null}),{files:i,promptChanged:t}}function bo(r,e){let s=new Map(r.map(n=>[n.label,n]));for(let n of e)s.has(n.label)||s.set(n.label,n);return[...s.values()]}function vo(r,e,s,n,t){return n.filter(i=>i.role==="tools"&&(/\.json$/i.test(i.path)||Ie(i.path)==="js")).flatMap(i=>He(r,e,s.files,{toolsPath:/\.json$/i.test(i.path)?i.path:null,toolsTsPath:/\.json$/i.test(i.path)?null:i.path,cliPath:null,mcpPath:null},t))}function Fo(r,e,s,n,t,i){let a=So(n?.files??[],s,t),d={...n??{id:nt("",e.ruleResult.fragment.nodes.map(f=>f.id),()=>{})("agent"),kind:"agent",desc:Pe(null,a.files,!1),meta:null,tools:[],sourceRef:null},label:e.proposalSources.proposal.agentName,files:a.files,tools:bo(n?.tools??[],vo(r,e.repoKey,e.proposalSources,s,i))};return a.promptChanged&&t&&(d.desc=Pe(t.path,a.files,!1),d.sourceRef={path:t.path,line:null}),{agent:d,promptChanged:a.promptChanged}}function Ro(r,e,s,n,t){let{target:i,overlapping:a,tied:p}=s,{fragment:d}=r,f=new Set([e.id,...(t?[...a,...p]:d.nodes).map(m=>m.id)]);for(let m=-1;m!==f.size;){m=f.size;for(let u of d.edges)f.has(u.from)&&f.add(u.to)}let l=d.nodes.filter(m=>f.has(m.id)).map(m=>m===i?e:m);i||l.push(e);let o=d.edges.filter(m=>f.has(m.from)&&f.has(m.to)),c=r.codeAgents?.filter(m=>f.has(m.unitKey)).flatMap(m=>m.unitKey!==i?.id?[m]:n?[]:[{...m,name:e.label,ownFiles:e.files}]);return{fragment:{...d,nodes:l,edges:o},...c?{codeAgents:c}:{}}}function yo(r,e,s){let n=new Set(e.map(a=>a.path)),t=new Set([...r.flatMap(a=>a.files.map(p=>p.path)),...n]),i=n.size;return{fromProposal:i,fromRulesOnly:t.size-i,rejected:Object.values(s).reduce((a,p)=>a+p,0),rejectedByReason:s}}function eo(r){return r.files.some(e=>e.role==="system prompt"||e.role==="soul")}function Eo(r,e,s){if(e.some(t=>t.kind==="agent"&&!eo(t)))return new Set;let n=new Set([oe({code:"no-prompt",detail:"no-conventions"},r),oe({code:"no-prompt"},r),oe({code:"no-prompt",folderAgentsFound:!0},r)]);return s!==void 0&&n.add(lt(r,{scanned:s})),n}function to(r,e){let{ruleResult:s,proposalSources:n,root:t,repoKey:i,scopes:a,scanned:p,agentChoice:d}=e,f=s,{files:l,selection:o,settled:c,skippedFiles:m,invalidated:u}=n,g=[...s.warnings],w=n.proposal.files.map(k=>({...k,path:T(k.path,t)})),h=w.find(k=>k.role==="prompt"),S=!1;if(w.length){let k=ko(f.fragment.nodes,new Set(w.map(E=>E.path)),h?.path,a,t);if(k.target||h){let{agent:E,promptChanged:F}=Fo(r,e,w,k.target,h,g),B=d?.kind==="choose_agent";f={...f,...Ro(s,E,k,F,B)},B&&({files:l,selection:o,settled:c,skippedFiles:m,invalidated:u}=wo(r,n,Po(s.fragment.nodes,f.fragment.nodes,a,t))),S=eo(E);let P=Eo(i,f.fragment.nodes,p);g=g.filter(b=>!P.has(b))}}return{...f,files:l,selection:o,settled:c,skippedFiles:m,invalidated:u,...d&&!S?{agentChoice:d}:{},warnings:g,proposalCounts:yo(f.fragment.nodes,w,n.rejectedByReason)}}function nn(r){let e=[],s=!1,n=Promise.resolve();return t=>new Promise((i,a)=>{e.push({entry:t,resolve:i,reject:a}),!s&&(s=!0,queueMicrotask(()=>{let p=e;e=[],s=!1,n=n.then(async()=>{try{let d=await r(p.map(f=>f.entry));if(d.length!==p.length)throw new Error("bad_request");p.forEach((f,l)=>f.resolve(d[l]))}catch(d){p.forEach(f=>f.reject(d))}})}))})}async function an(r,e){let s=y=>e.localListing?y.filter(j=>R(r,j,{purpose:"listing",route:"local-folder",...e.admission}).admitted):y,n=s(e.entries),t=ce(r,{profile:"local-analysis",listing:n,selection:e.selection}),i=await de(r,{entries:n,read:e.read,admission:e.admission,plan:t}),{files:a,settled:p,skippedFiles:d,...f}=i,l=await Vt(r,{proposal:e.proposal,entries:n,read:e.read,proposalRead:e.proposalRead,admission:e.admission,files:a,settled:p,skippedFiles:d,selection:t.selection,unavailable:e.proposalRefusals,evidence:f}),{files:o,settled:c,skippedFiles:m}=l??i,u=q({...l??f,key:e.repoKey,files:o},t.context.flags,void 0,{markerPolicy:"any-read"}),g=l?.selection??t.selection,w;if(Xe(r)&&e.repository){let y=e.repository,j=await tt(r,{selected:{files:o,listedPaths:n.map(x=>x.path),fallbackName:dt(e),skills:!0},selection:g,codeAgentsFound:it(r,u?.resolved,o),port:e.localListing?{context:()=>y.context(),read:(x,C)=>y.read(x,C),finish:x=>y.finish?.(x),list:async()=>{let x=await y.list();return{...x,entries:s(x.entries)}}}:y}),so=new Set(Object.keys(o).map(x=>T(x,j.root)));if(o=j.files,g=j.selection,w=j.root,w!==void 0){m=m.map(C=>({...C,path:T(C.path,w)})),c=c.map(C=>({...C,path:T(C.path,w)}));let x=new Set(c.map(C=>C.path));c.push(...g.selected.filter(C=>!x.has(C.path)&&Object.hasOwn(o,C.path)))}m=H(m,j.skippedFiles).filter(x=>so.has(x.path)||!Object.hasOwn(o,x.path))}let h={repoKey:e.repoKey,files:o,listedPaths:n.map(y=>T(y.path,w)),...w!==void 0?{root:w}:{},forLocal:!0,code:u},S=U(r,h),k=G(r,S),E=Qt(r,{codeAgents:k.codeAgents??[],conventions:S.conventions,root:w}),F=l?to(r,{ruleResult:k,proposalSources:{...l,files:o,selection:g,settled:c,skippedFiles:m,invalidated:l.invalidated?.map(y=>({...y,path:T(y.path,w)}))},root:w,repoKey:e.repoKey,scopes:S.conventions.agentScopes,scanned:u?.resolved?.scanned,agentChoice:E}):void 0,{settled:B,invalidated:P,...b}=F??{...k,settled:c,invalidated:void 0};F&&(o=F.files,g=F.selection,c=B,m=F.skippedFiles);let v=g.readingNotes?_(r,g.readingNotes,c):g.skippedNote,M=F?F.agentChoice:E;return{...b,...M?{agentChoice:M}:{},files:o,...w!==void 0?{root:w}:{},skippedFiles:P?.length?H(m,P):m,...F?{proposalCounts:F.proposalCounts}:{},warnings:[...new Set([...b.warnings,...v?[v]:[],...J(m)])],selection:g}}var Oo=new Set(Et);function dn(r,e){for(let n of[...Object.keys(e.set),...e.clear])if(!Oo.has(n))throw new Error(`Unknown analysis field: ${n}`);let s={...r,...e.set};for(let n of e.clear)s[n]=void 0;return s}async function xo(r,e,s){let n=Object.entries(e).map(([i,a])=>({path:i,size:Buffer.byteLength(a),ref:i})),t=ft(r,n,s.root,!1,s.scanPaths);for(;!Y(t);)t=await ht(t,async i=>e[i.path]??null);return{scan:se(r,t),summary:ut(t)}}async function oo(r,e,s){let{repoKey:n,root:t,agentConfigurations:i,codingGuides:a,forLocal:p}=s,d=s.flags??W(r),f=Object.keys(e),l=N(r,{phase:"start",paths:f,root:t,scanFlag:d.scan}),o=l.kind==="marker"?N(r,{phase:"read",pending:l,text:e[l.markerPath]??null}):l,c=o.kind==="off"?null:o.markerPath,m=o.kind==="off"?null:o.markerKind;if(o.kind==="off"||!o.scan){let k=q({key:n,files:e,markerPath:c,markerKind:m},d,void 0,{markerPolicy:"any-read"});return{...G(r,U(r,{repoKey:n,files:e,root:t,agentConfigurations:i,codingGuides:a,forLocal:p,code:k})),scanned:!1,resolved:null}}let{scan:u,summary:g}=await xo(r,e,{repoKey:n,root:t,scanPaths:o.scanPaths}),w=q({key:n,files:e,ranked:u,scan:g,markerPath:c,markerKind:m},d,void 0,{markerPolicy:"any-read"});return{...G(r,U(r,{repoKey:n,files:e,root:t,agentConfigurations:i,codingGuides:a,forLocal:p,code:w})),scanned:!0,resolved:w.resolved}}async function ro(r,e){let{state:s,settings:n}=r;if(!xt(n,s).splitCheck||!s.splitEstimateBase)return{next:"inspecting",set:{repoCursor:0},clear:[]};let i=r.execution.preparation?.capUsd??s.splitEstimateBase.capUsd,a={...s.splitEstimateBase,capUsd:i};Ce(a,e.progress.log);let p=It(n,s),d={next:"inspecting",set:{repoCursor:0,splitCheckPriced:!0,splitFindingsPriced:!0},clear:["splitEstimateBase"]};if(!p.length)return d;let f=rt(te(await e.instructions())),l=p.reduce((g,{inventory:w})=>g+fe(Buffer.byteLength(Lt({tools:f},{...w,findings:[]}).prompt))+fe(f.SHAPE_FINDINGS_INPUT_BYTES),0),o=a.lines.find(g=>g.label==="Scope check"),c=ue(n,{template:"scope-findings"},"Scope check",st.mechanical,(o?.inputTokens??0)+p.length*_t,(o?.outputTokens??0)+p.length*Tt),m=a.lines.map(g=>g.label==="Scope check"?c:g);o||m.push(c),m.push(ue(n,{template:"derive-shape"},"Split check",At,l,p.length*ot));let u=Oe(m,i);return xe(u)?(d.estimate=a,d.clear.push("splitCheckPriced","splitFindingsPriced"),delete d.set.splitCheckPriced,delete d.set.splitFindingsPriced,e.progress.log({level:"warn",code:"analysis.split_check_over_cap",counts:{totalUsd:u.totalUsd,capUsd:u.capUsd}}),d.set.warnings=[...s.warnings??[],Me]):d.estimate=u,d}var Nn=async(r,e)=>{e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let{state:s,settings:n}=r,t=s.repos??[];await ze(n,s,e.readers);let i=s.repoCursor??0;if(i>=t.length)return ro(r,e);let a=t[i],p=r.execution.forLocal,d=p?s.mapped?.[i]?{fragment:Ot(s,i),warnings:[]}:await oo(n,a.files??{},{repoKey:a.key,root:a.root,agentConfigurations:a.agentConfigurations??{},forLocal:!0}):void 0,f=d?(()=>{let u=$e(d.fragment,a.key);return{...u,warnings:[...d.warnings,...u.warnings]}})():Bt(n,a,Mt(n,s),s.modelReader??!1,s.projectAgents,te(await e.instructions()).bundleText("model-reader-runtime-prompt")),l=!p&&a.sourceReadNotes?_(n,a.sourceReadNotes,a.selected??[],a.root):void 0,o=p?[]:J((a.refused??[]).filter(u=>u.reason==="secret-content")),c="virtualFiles"in f?f.virtualFiles:void 0,m=[...s.mapped??[]];return m[i]=f.fragment,{next:"mapping",clear:[],set:{...c?{repos:t.map((u,g)=>g===i?{...u,files:{...u.files,...c}}:u)}:{},mapped:m,warnings:[...s.warnings??[],...l?[`${a.key}: ${l}`]:[],...o,...f.warnings,...Ct(a)],repoCursor:i+1}}};export{le as a,be as b,Vo as c,Dt as d,ce as e,co as f,nn as g,an as h,dn as i,Nn as j};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as G}from"./KTNA2KTN.js";import{A as T,Ba as I,Ha as F,I as R,Ka as _,La as $,Ma as P,Na as w,Qa as M,Ra as y,h as l,i as N,l as C,lb as D,sa as E}from"./NIOS7U6C.js";import{a as b,c as x}from"./C6X5GDG4.js";var k="Some of this agent's files weren't read, so findings may be missing.";var B=r=>r.CF_READING_PRIORITY!=="0";var U=new Set(["system prompt","soul","knowledge","config","tools","mcp"]);function L(r){let t=new Set;for(let s of r.nodes)for(let f of s.files??[])U.has(f.role)&&t.add(f.path);let n=new Set(r.edges.filter(s=>s.kind==="delegates").map(s=>s.to));for(let s of r.nodes)n.has(s.id)&&s.sourceRef&&t.add(s.sourceRef.path);return t}function V(r){return new Set([...r.nodes,...r.edges].flatMap(t=>t.sourceRef?[t.sourceRef.path]:[]))}var p=6e4,j=r=>{if(r.length<=p)return r;let t=r.endsWith(E)?E:"";return(t?r.slice(0,-t.length):r).slice(0,p)+t};function Z(r,t){let n=[...r].filter(s=>t[s]!==void 0&&j(t[s])!==t[s]).sort();return n.length===0?null:`${n.length} core file${n.length===1?" was":"s were"} longer than ${p/1e3} KB, so only the first ${p/1e3} KB ${n.length===1?"was":"were"} read: ${n.join(", ")}`}var A=r=>r.split("/").slice(0,-1).join("/"),Y=/(agent|prompt|tool|llm|model)/i,z=2.5;function K(r,t){if(!B(r))return{enabled:!1,tierOf:()=>6};if(t.repos?.some(e=>e.kind==="github"&&b(e.root)))return v(r,t,t.repos);let n=t.scopes??(C(r)?G(r,t.paths,void 0,{agentConfigurations:{}}):void 0),s=t.graph?L(t.graph):new Set,f=new Set(t.graph?.nodes.flatMap(e=>(e.files??[]).filter(o=>o.role==="code"&&l(o.path)).map(o=>o.path))??[]),i=new Set(t.graph?.nodes.flatMap(e=>(e.files??[]).filter(o=>o.role==="system prompt").map(o=>o.path))??[]),a=e=>N(e)&&(I.includes(e.split("/").pop().toLowerCase())||/(^|\/)system_prompt_[^/]+\.md$/i.test(e)||y.test(e)),c=e=>{if(s.has(e))return 1;if(f.has(e))return 2;let o=P(r,e,n),d=R(o,{nested:!0});if(d?.reference)return 5;if(d?.definition||F.test(o))return 4;if(d||/(^|\/)(docs?|references)\//i.test(o)||$.test(e.split("/").pop()))return 5;if(_(o)||w(r,e,n)&&_(e.split("/").pop())||a(e))return 1;if(l(e)){if(Y.test(e))return z;if(M.test(e))return 3}return 6};for(let e of t.paths)c(e)===1&&a(e)&&i.add(e);let m=[...i].flatMap(e=>{let o=A(e);return[o,...o?[A(o)]:[]]}),h=e=>l(e)&&m.some(o=>A(e)===o),u=new Map(t.paths.map(e=>{let o=c(e);return[e,o>2&&h(e)?2:o]})),g=[...u].filter(([e,o])=>o<=2&&l(e)).map(([e])=>e),O=D(Object.fromEntries(g.flatMap(e=>t.files?.[e]===void 0?[]:[[e,t.files[e]]])),t.paths);for(let e of O)l(e)&&!R(P(r,e,n),{nested:!0})&&(u.get(e)??6)>2&&u.set(e,2);return{enabled:!0,tierOf:e=>u.get(e)??c(e)}}function v(r,t,n){let s=new Map;for(let f of n){let i=f.kind==="github"?f.root:void 0,a=t.paths.filter(e=>f.files?.[e]!==void 0&&!s.has(e)),c=e=>x(e,i)??(f.files?.[e]!==void 0?e:null),m=e=>{let o=e?c(e.path):null;return o===null?null:{path:o}},h=t.graph&&{nodes:t.graph.nodes.map(e=>({...e,sourceRef:m(e.sourceRef),files:e.files?.flatMap(o=>{let d=c(o.path);return d===null?[]:[{...o,path:d}]})})),edges:t.graph.edges.map(e=>({...e,sourceRef:m(e.sourceRef)}))},u=a.flatMap(e=>{let o=c(e);return o===null?[]:[o]}),g=Object.fromEntries(a.flatMap(e=>{let o=c(e);return o===null||t.files?.[e]===void 0?[]:[[o,t.files[e]]]})),O=K(r,{paths:u,files:g,graph:h});for(let e of a)s.set(e,O.tierOf(c(e)??e))}return{enabled:!0,tierOf:f=>s.get(f)??6}}function H(r,t){return r.enabled?t.filter(n=>["too-large","total","allowance"].includes(n.reason)&&r.tierOf(n.path)<3).map(n=>n.path):[]}function W(r){return r.slice(0,3)}function q(r,t=!1){let n=W(r);if(!n.length)return;let s=t?". "+k:", so some findings may be missing";return`${n.join(", ")} ${n.length===1?"was":"were"} left out${s}`}function ue(r,t){return q(H(r,t))}function de(r,t){return r.enabled&&r.tierOf(t)<3}function me(r,t,n){let s=T.sourceFetch.codeFileBytes;return r.enabled&&r.tierOf(t)<3&&l(t)&&n>s?{size:s,readBytes:s}:{size:n}}function pe(r,t){return r.enabled&&r.tierOf(t)<3&&l(t)}function S(r){return r.split("/").length-1}function he(r,t,n){return w(r,t,n)?0:M.test(t)?1+Math.min(S(t),3)/10:S(t)<=2?2:S(t)<=4?3:4}function ge(r,t){return(r.tier??0)-(t.tier??0)||r.score-t.score||r.size-t.size}function Oe(r,t,n,s){return[...r].sort((f,i)=>(s?.enabled?s.tierOf(f)-s.tierOf(i):0)||Number(n.has(i))-Number(n.has(f))||t[f].length-t[i].length||(f<i?-1:1))}function Re(r,t,n,s){return[...r].sort((f,i)=>(s?.enabled?s.tierOf(f.path)-s.tierOf(i.path):0)||Number(t.has(i.path))-Number(t.has(f.path))||Number(n.has(i.path))-Number(n.has(f.path))||f.text.length-i.text.length)}export{B as a,L as b,V as c,j as d,Z as e,K as f,H as g,W as h,q as i,ue as j,de as k,me as l,pe as m,he as n,ge as o,Oe as p,Re as q};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var r=t=>t.CF_UNTRUSTED_CONTENT_CHECK!=="0";function n(t){return t.CF_FINDING_BETTER_AS_CODE==="1"}var o=["contradiction","ambiguity","bypassable_requirement","stale_fact","description_mismatch","ungoverned_tool","untrusted_instructions","better_as_code"];function i(t){return o.filter(e=>(e!=="untrusted_instructions"||r(t))&&(e!=="better_as_code"||n(t)))}function _(t){return!n(t)&&r(t)}var p={contradiction:"Contradiction",ambiguity:"Ambiguity",bypassable_requirement:"Bypassable requirement",stale_fact:"Stale fact",description_mismatch:"Description mismatch",ungoverned_tool:"Ungoverned tool",untrusted_instructions:"Untrusted instructions",better_as_code:"Better as code",structure:"Structure",prompt_quality:"Prompt quality"};function l(t){return["contradiction","bypassable_requirement","stale_fact","description_mismatch","ungoverned_tool","untrusted_instructions"].includes(t)?2:1}function s(t){return typeof t=="string"&&o.includes(t)}function m(t,e){return s(t)&&i(e).includes(t)}export{r as a,n as b,i as c,_ as d,p as e,l as f,s as g,m as h};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b,c as l}from"./6U2IR4XB.js";import{a as r}from"./6B2HILSY.js";import{a as u,b as o,c as g}from"./KWECQJ6X.js";import{z as _}from"zod";import{z as c}from"zod";function h(a=r){return c.object({rows:c.array(c.object({key:c.string().describe(a("finding-headlines-key")),headline:c.string().nullable().describe(a("finding-headlines-headline")),ifLeft:c.string().nullable().describe(a("finding-headlines-if-left"))}).strict())}).strict()}var A=h();import{z as n}from"zod";var p=n.object({verdicts:n.array(n.object({id:n.string(),inScope:n.boolean(),reason:n.string()}))});import{z as e}from"zod";var z=3,F=64e3,C=8,H=60,E=e.object({subKind:e.string().describe(r("analysis-structure-schema-1")),kind:e.string().describe(r("analysis-structure-schema-2")),severity:e.string().describe(r("analysis-structure-schema-3")),title:e.string(),cause:e.string(),evidence:e.array(e.object({path:e.string(),line:e.number(),excerpt:e.string()})),children:e.array(e.object({ref:e.string().describe(r("analysis-structure-schema-4")),how:e.string()})),files:e.array(e.object({path:e.string(),action:e.string().describe(r("analysis-structure-schema-5")),role:e.string().describe(r("analysis-structure-schema-6")),unit:e.string().describe(r("analysis-structure-schema-7")),loadMode:e.string().describe(r("analysis-structure-schema-8")),loadVia:e.string().describe(r("analysis-structure-schema-9")),purpose:e.string(),fmName:e.string().describe(r("analysis-structure-schema-10")),fmDescription:e.string(),fmTools:e.array(e.string())})),segments:e.array(e.object({path:e.string(),startLine:e.number(),endLine:e.number(),to:e.string().describe(r("analysis-structure-schema-11")),disposition:e.string().describe(r("analysis-structure-schema-12")),intoPath:e.string().describe(r("analysis-structure-schema-13")),intoLine:e.number().describe(r("analysis-structure-schema-14")),childRef:e.string().describe(r("analysis-structure-schema-15")),heading:e.string().describe(r("analysis-structure-schema-16")),reason:e.string()})),additions:e.array(e.object({path:e.string(),text:e.string(),kind:e.string().describe(r("analysis-structure-schema-17")),heading:e.string()})),reorders:e.array(e.object({path:e.string(),startLine:e.number(),endLine:e.number(),order:e.array(e.number()).describe(r("analysis-structure-schema-reorder-order")),reasons:e.array(e.string()).describe(r("analysis-structure-schema-reorder-reasons"))})).describe(r("analysis-structure-schema-18")),toolMoves:e.array(e.object({tool:e.string(),fromUnit:e.string(),toUnit:e.string(),reason:e.string()}))}),y=e.object({structures:e.array(E)}),f=e.object({verdict:e.string().describe(r("structure-recheck-verdict")),reason:e.string()}),S=e.object({verdicts:e.array(e.object({index:e.number(),inScope:e.boolean(),reason:e.string()}))});import{z as t}from"zod";var j=t.object({verdicts:t.array(o.shape.verdicts.element.extend({decisive:t.boolean(),quotes:t.array(t.object({side:t.enum(["against","for"]),repo:t.string(),path:t.string(),line:t.number().int().positive(),quote:t.string()}))}))});import{z as s}from"zod";var q=4,K=1,J=16e3,k=s.object({path:s.string(),startLine:s.number(),endLine:s.number()}),x=s.object({decision:s.string().describe(r("analysis-split-check-schema-1")),reason:s.string(),frontDoor:s.object({job:s.string().describe(r("analysis-split-check-schema-2")),skills:s.array(s.string()).describe(r("analysis-split-check-schema-3"))}),subAgents:s.array(s.object({name:s.string().describe(r("analysis-split-check-schema-4")),job:s.string().describe(r("analysis-split-check-schema-5")),description:s.string().describe(r("analysis-split-check-schema-6")),skills:s.array(s.string()),tools:s.array(s.string()).describe(r("analysis-split-check-schema-7")),promptSections:s.array(k),knowledgeSections:s.array(k).describe(r("analysis-split-check-schema-8")),resolves:s.array(s.string()).describe(r("analysis-split-check-schema-9")),evidence:s.array(s.object({path:s.string(),line:s.number(),excerpt:s.string()})),handoff:s.string().describe(r("analysis-split-check-schema-10"))}))});function ie(a=m=>m,T){let m={codeJudge:u,findings:l({}),scope:p,structures:y,structureScope:S,check:o,opinion:j,sourceNotes:g,shape:x,recheck:f,findingHeadlines:h(i=>T?.(i)??r(i)),judge:_.object({row:_.string().min(1).nullable()}).strict()},U=b().map(({name:i,schema:d})=>[i,d]);return Object.fromEntries([...Object.entries(m),...U].map(([i,d])=>[i,a(d)]))}export{A as a,z as b,F as c,C as d,H as e,j as f,q as g,K as h,J as i,ie as j};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{C as be,Ca as De,D as _e,Da as Ne,E as T,F as Ce,Fa as le,Ga as We,H as Fe,Ha as ce,I as ie,Ja as Te,S as Ee,Sa as G,U as Oe,V as $e,Va as Ue,W as Le,Wa as te,X as Me,Xa as ne,Y as Ie,a as se,c as K,d as q,e as re,g as ge,ga as Q,j as ke,ka as Ae,l as we,la as Re,m as Pe,n as I,p as D,q as E,r as F,ra as B,s as ye,t as ae,u as Se,v as N,w as z,x as xe,ya as ee,z as ve,za as je}from"./NIOS7U6C.js";import{a as U,c as _,e as H}from"./C6X5GDG4.js";function Z(e,o,n,u=o,r={}){let s=G(e,o.filter(t=>B(e,{path:t},{purpose:"override",route:"github"}).admitted),{root:n,...r});return fe(s,e,u.some(t=>{let d=_(t,n);return d!==null&&se(d)}))}function fe(e,o,n=e.scoped.some(u=>se(u.relativePath))){let u=new Map(e.scoped.map(t=>[t.path,t.relativePath])),r=(t,d,g=!1)=>e.files.find(p=>p.role===t&&p.kind!=="background"&&p.preferred!==!1&&(!d||p.kind===d)&&(!g||p.preferred))?.path??null,s=(t,d,g=!1)=>e.files.filter(p=>p.role===t&&(!d||p.kind===d)&&p.ownerPath!==void 0===g).map(p=>p.path).sort();return{scoped:e.scoped.map(t=>t.path),hasRepositoryGuide:n,developerCompanionPaths:!re(o)&&n?e.scoped.filter(t=>tt(t.relativePath)).map(t=>t.path):[],stripRoot:t=>u.get(t)??t,configPath:r("marker"),promptPath:r("prompt","dedicated",!0),claudePath:r("prompt","fallback"),toolsPath:r("tool file","json"),toolsTsPath:r("tool file","sdk"),cliPath:r("tool file","cli"),mcpPath:r("MCP config",void 0,!0),registry:e.registry,soulPath:r("soul"),knowledgePath:r("knowledge"),subagentPaths:s("sub-agent"),skillPaths:s("skill"),skillNames:Object.fromEntries(e.files.filter(t=>t.role==="skill"&&t.name).map(t=>[t.path,t.name])),skillRefNames:Object.fromEntries(e.files.filter(t=>t.role==="reference"&&t.kind==="skill"&&t.name).map(t=>[t.path,t.name])),templatePaths:s("reference","template"),skillRefPaths:s("reference","skill"),subagentSkillPaths:s("skill",void 0,!0),subagentSkillRefPaths:s("reference","skill",!0),subagentSkillOwners:Object.fromEntries(e.files.filter(t=>t.ownerPath!==void 0).map(t=>[t.path,t.ownerPath]))}}function ze(e){let o=new Set(e.developerCompanionPaths),n=u=>!o.has(u);return{...e,mcpPath:e.mcpPath&&n(e.mcpPath)?e.mcpPath:null,subagentPaths:e.subagentPaths.filter(n),skillPaths:e.skillPaths.filter(n),subagentSkillPaths:e.subagentSkillPaths.filter(n),subagentSkillRefPaths:e.subagentSkillRefPaths.filter(n),skillRefPaths:e.skillRefPaths.filter(n)}}function X(e){let o=ze(e);return!!(o.promptPath||o.toolsPath||o.toolsTsPath||o.cliPath||o.mcpPath||o.soulPath||o.knowledgePath||o.subagentPaths.length||o.skillPaths.length)}function et(e){let o=ze(e);return!!(o.promptPath||o.registry&&o.soulPath||o.subagentPaths.length)}function Be(e,o){return re(e)?X(o):et(o)}function tt(e){return e.toLowerCase()===".mcp.json"||/^\.claude\/(agents|skills)\//i.test(e)}function Ge(e,o){return!!e.configPath||!!e.claudePath&&o==="prompt"||X(e)}var nt=/^(evals?|evaluations)\/.*\.(jsonl?|ya?ml|md|csv)$|\.eval\.(json|ya?ml)$/i;function ot(e){return le.exec(e)?.[1]?.toLowerCase()==="commands"&&/\.md$/i.test(e)}function st(e){return nt.test(e)}function J(e,o,n={}){if(!q(e))return!1;if(n.agentConfigurations){if(n.agentConfigurations[U(n.root)]!==!0)return!1;if(n.skills!==!1)return!0}let u=o.flatMap(g=>{let p=_(g,n.root);return p===null?[]:[{path:g,relative:p}]}),r=u.filter(({path:g})=>B(e,{path:g},{purpose:"definition",route:"github",root:n.root}).admitted);if(!r.some(({relative:g})=>K.includes(g.toLowerCase())))return!1;let s=Z(e,r.map(g=>g.path),n.root,o),t=!!(s.subagentPaths.length||s.toolsPath||n.skills!==!1&&s.skillPaths.length),d=r.some(({relative:g})=>ot(g));return!n.agentConfigurations&&u.some(({relative:g})=>{let p=le.exec(g)?.[1]?.toLowerCase();return!(p==="skills"||(p==="commands"?t:ve(g)&&(t||d)))&&!Re.test(g)&&!Ae.test(g)&&g.toLowerCase()!==ee.toolsSource&&ke(g)})?!1:t||d||r.some(({relative:g})=>st(g))}function me(e,o,n){let u=new Map([[U(n),[]]]);for(let r of o)_(r,n)!==null&&K.includes(r.split("/").at(-1).toLowerCase())&&u.set(r.slice(0,Math.max(0,r.lastIndexOf("/"))),[]);for(let r of o){if(_(r,n)===null)continue;let s=r.slice(0,Math.max(0,r.lastIndexOf("/")));for(;u.get(s)?.push(r),!!s;)s=s.slice(0,Math.max(0,s.lastIndexOf("/")))}return Object.fromEntries([...u].map(([r,s])=>[r,J(e,s,{root:r})]))}function $t(e,o){let n=[...new Set([...Object.keys(o.files),...o.listedPaths??[]])],{root:u,skills:r,agentConfigurations:s}=o;if(!J(e,n,{root:u,skills:r,agentConfigurations:s}))return null;let t=Z(e,Object.keys(o.files),u,o.listedPaths,{agentConfiguration:!0});return t.claudePath?t:null}import{posix as Y}from"node:path";import{posix as rt}from"node:path";function ue(e,o=1){let n=new Set,u=[],r=e.replace(/{#[\s\S]*?#}|{%[-+]?\s*raw\s*[-+]?%}[\s\S]*?(?:{%[-+]?\s*endraw\s*[-+]?%}|$)/g,s=>s.replace(/[^\n]/g," "));for(let s of r.matchAll(/{%[-+]?\s*(include|extends|import|from)\s+(.+?)\s*[-+]?%}/g)){let t=s[2].match(/^(["'])([^"']+)\1(?:\s+(?:as\s+\w+|import\s+.+|ignore missing|with context|without context))?$/),d=o+e.slice(0,s.index).split(`
|
|
2
|
-
`).length-1;u.push({source:t?.[2]??s[2],span:{from:d,to:d},...t?{}:{reason:"dynamic"}})}for(let s of r.matchAll(/{{[-+]?\s*([\w]+)|{%[-+]?\s*(?:if|elif|for\s+\w+\s+in|set\s+\w+\s*=)\s+([\w]+)/g)){let t=s[1]??s[2];!["true","false","none"].includes(t.toLowerCase())&&!/^\d/.test(t)&&n.add(t)}return{variables:[...n],loaders:u}}function Ze(e,o={}){let n=e.split(`
|
|
3
|
-
`),u=[],r=[],s=(t,d,g)=>{let p=new Set;for(let k of Oe(t.join(`
|
|
4
|
-
`))){let P=g?`${g}.${k.key}`:k.key,a={from:d+k.span.from,to:d+k.span.to},m=t.slice(k.span.from-1,k.span.to);p.has(k.key)&&r.push({key:P,span:a,reason:"duplicate"}),p.add(k.key);let w=m[0].slice(m[0].indexOf(":")+1).trim();if(!w||w.startsWith("#")){let f=m.slice(1),i=f.find(S=>S.trim()&&!S.trimStart().startsWith("#"))?.match(/^ */)?.[0].length;if(i){s(f.map(S=>S.slice(i)),a.from,P);continue}}let h=Ee(m.join(`
|
|
5
|
-
`))?.[k.key],c=typeof h=="string"?h:null,l=P.endsWith("_template")||Pe(o,"CF_IMPORT_PROMPT_FIELDS")&&P.endsWith("_prompt");(l&&c===null||/^[!&*]/.test(w))&&r.push({key:P,span:a,reason:"invalid"}),u.push({key:P,span:a,text:n.slice(a.from-1,a.to).join(`
|
|
6
|
-
`),value:c,...l&&c!==null?ue(c,a.from+(/^[|>]/.test(w)?1:0)):{variables:[],loaders:[]}})}};s(n,0,"");for(let t of r.filter(d=>d.reason==="duplicate"))for(let d of u.filter(g=>g.key===t.key||g.key.startsWith(`${t.key}.`)))d.value=null;return{fields:u,unresolved:r}}function at(e,o){let{toks:n}=e,u=[],r=new Map;for(let s=0;s<n.length;s++){if(!ae(n,s))continue;let t=Se(e.text,n[s]),d=u.findLast(P=>P.indent===t);for(;u.length&&u.at(-1).indent>=t;)u.pop();if(r.set(n[s].line,u.some(P=>!P.guard)?null:u.map(P=>P.guard)),!["if","elif","else","for","while","try","except","with","match","case"].some(P=>F(n[s],P)))continue;let g=s+1;for(;g<n.length&&n[g].line===n[s].line;)g++;let p=E(n[g-1],":"),k=null;if(p&&F(n[s],"else")&&d?.guard&&(k={...d.guard,value:!d.guard.value}),p&&F(n[s],"if")){let P=F(n[s+1],"not"),a=s+(P?2:1),m=n.slice(a,g-1).map(c=>c.text).join(""),w=o.owner(s),h=/^[A-Za-z_]\w*$/.test(m)?m:null;if(/^self\.[A-Za-z_]\w*$/.test(m)){let l=n.flatMap((f,i)=>i<s&&ae(n,i)&&o.owner(i)===w&&n.slice(i,i+3).map(S=>S.text).join("")===m?[i]:[]).at(-1);h=l!==void 0&&E(n[l+3],"=")&&F(n[l+4])&&n[l+5]?.line!==n[l].line?n[l+4].text:null}if(h&&w?.params?.includes(h)&&!o.binding(h,s)){let c=n.findIndex((S,v)=>w.from<v&&v<s&&E(S,"(")),l=c>=0&&N(n,c)<s?z(n,c).find(S=>F(n[S.from],h)):void 0,f=l&&n.findIndex((S,v)=>l.from<v&&v<l.to&&E(S,"=")),i=f!==void 0&&f>=0&&f+2===l?.to?n[f+1].text:null;k={parameter:h,value:!P,defaultValue:i==="True"?!0:i==="False"?!1:null}}}u.push({indent:t,guard:k}),r.set(n[s].line,null)}return r}function Nt(e,o,n){let u=D(e,o,"py"),r=te(u,{includeMembers:!0}),s=ne(u,r,{enclosingBindings:!0}),{toks:t}=u,d=at(u,s),g=s.assignments.map(h=>["else","try","finally"].includes(h.name)&&F(t[h.from-2])?{...h,name:t[h.from-2].text,at:h.from-2}:h),p=h=>t.slice(h.from,h.to).map(c=>c.kind==="string"?JSON.stringify(c.value):c.text).join(""),k=(h,c,l,f)=>{let i=s.importBinding(h,c);return i?f?!i.namespace&&i.module.source===l&&i.name===f:i.namespace&&i.module.source===l:!1},P=[],a=new Map,m=new Map;for(let h of s.calls.filter(c=>c.callee.endsWith("read_text"))){let c=p(h),l=/^([A-Za-z_]\w*)\.resources\.files\(("(?:[^"\\]|\\.)*")\)\.joinpath\((.*?)\)\.read_text\(\)$/.exec(c)??/^([A-Za-z_]\w*)\.files\(("(?:[^"\\]|\\.)*")\)\.joinpath\((.*?)\)\.read_text\(\)$/.exec(c);if(!l)continue;let f=s.importBinding(l[1],h.from),i=c.startsWith(`${l[1]}.resources.files(`);if(!(f&&(i?f.namespace&&f.name==="importlib"&&["importlib","importlib.resources"].includes(f.module.source):f.namespace&&f.name==="importlib.resources"&&f.module.source==="importlib.resources"||!f.namespace&&f.name==="resources"&&f.module.source==="importlib")))continue;let v=s.calls.find(x=>x.from<h.from&&h.to<x.to&&x.args.length===1&&x.args[0].from===h.from&&x.args[0].to===h.to&&(x.callee.endsWith(".safe_load")&&k(x.callee.split(".")[0],x.from,"yaml")||k(x.callee,x.from,"yaml","safe_load")));if(!v)continue;let y=JSON.parse(l[2]),b;try{b=JSON.parse(l[3])}catch{}let O=null,M;if(typeof b!="string"||!/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*$/.test(y))M="dynamic";else if(rt.isAbsolute(b)||/[\\\0]/.test(b)||b.split("/").includes(".."))M="out-of-scope";else{let x=`${y.replaceAll(".","/")}/${b}`,R=e.indexOf(`${y.split(".")[0]}/`),A=R>=0?e.slice(0,R)+x:null,j=[...n].filter(V=>V===x||V.endsWith(`/${x}`));O=A??(j.length===1?j[0]:null),O?n.has(O)||(M="missing"):M=j.length>1?"dynamic":"missing"}let C=g.find(x=>x.from<=v.from&&v.from<x.to&&s.owner(x.at)===s.owner(v.from)),L={path:O,source:typeof b=="string"?b:l[3],span:{from:t[h.from].line,to:t[h.to-1].endLine},start:t[v.from].start,end:t[v.to-1].end,binding:C?.name??null,forwarded:!1,when:d.get(t[C?.at??h.from].line)??null,className:r.filter(x=>x.kind==="class"&&x.from<h.from&&h.from<x.to).at(-1)?.name??null,...M?{reason:M}:{}};P.push(L),C&&(a.set(L,C),m.set(C,v))}let w=new Set([...a.values()].filter(h=>{let c=m.get(h);return(F(t[h.from],h.name)&&F(t[h.from+1],"or")?h.from+2:h.from)===c.from&&(h.to===c.to||h.to+1===c.to&&E(t[h.to],")"))}));for(let h of P){let c=a.get(h);!c||!w.has(c)||s.owner(c.at)?.name!=="__init__"||(h.forwarded=s.calls.some(l=>s.owner(l.from)===s.owner(c.at)&&t[l.from].start>h.end&&F(t[l.from],"super")&&l.callee.endsWith("__init__")&&l.args.some(f=>F(t[f.from],c.name)&&E(t[f.from+1],"=")&&f.to===f.from+3&&F(t[f.from+2],c.name))&&g.filter(f=>f.name===c.name&&c.at<f.at&&f.at<l.from&&s.owner(f.at)===s.owner(c.at)).every(f=>w.has(f))&&!t.some((f,i)=>i<l.from&&f.start>=h.end&&F(f,c.name)&&s.owner(i)===s.owner(c.at)&&![...w].some(S=>S.at<=i&&i<m.get(S).to))))}return P}function Je(e,o){if(!I(e))return[];let n=new Set(o),u=[];for(let r of[...n].sort()){let s=r.match(/^((?:[^/]+\/)*?)(?:src\/)?minisweagent\/agents\/default\.py$/);if(!s)continue;let t=r.slice(0,-18),d=`${t}/config`,g=`${d}/__init__.py`,p=`${t}/run/mini.py`;if(!n.has(g)||!n.has(p))continue;let k=[...n].filter(P=>_(P,d)!==null&&/\.ya?ml$/.test(P)).sort();k.length&&u.push({folder:s[1].replace(/\/$/,""),configFolder:d,agentPath:r,loaderPath:g,runnerPath:p,configs:k,templates:[...n].filter(P=>_(P,d)!==null&&/\.(?:j2|jinja2?)$/.test(P)).sort()})}return u}function it(e,o){let n=D(e.agentPath,o[e.agentPath]??"","py").toks,u=D(e.loaderPath,o[e.loaderPath]??"","py").toks,r=D(e.runnerPath,o[e.runnerPath]??"","py").toks;if(!["system_template","instance_template"].every(t=>n.some((d,g)=>F(d,t)&&E(n[g-1],".")))||!u.some((t,d)=>F(t,"safe_load")&&E(u[d+1],"("))||!u.some((t,d)=>F(t,"read_text")&&E(u[d+1],"("))||!r.some((t,d)=>F(t,"get_config_from_spec")&&E(r[d+1],"("))||!r.some((t,d)=>F(t,"get_agent")&&E(r[d+1],"("))||!r.some((t,d)=>F(t,"get")&&E(r[d+1],"(")&&r[d+2]?.value==="agent"))return null;let s=r.flatMap((t,d)=>{if(!F(t,"DEFAULT_CONFIG_FILE")||!E(r[d+1],"="))return[];let g=r.slice(d+2).filter(p=>p.line===t.line);return g.flatMap((p,k)=>F(p,"builtin_config_dir")&&E(g[k+1],"/")&&g[k+2]?.kind==="string"?[Y.join(e.configFolder,g[k+2].value)]:[])});return s.length===1?s[0]:null}function Jt(e,o,n,u){let r={variants:[],selectedPaths:[],fields:[],model:null,loaded:[],unresolved:[],edges:[]};if(!I(e))return r;let s=it(o,n);if(!s)return r.unresolved.push({path:o.runnerPath,source:"config",reason:"dynamic"}),r;let t=new Map,d=new Set(Object.keys(n)),g=a=>{let m=B(e,{path:a,text:n[a],size:n[a]===void 0?void 0:Buffer.byteLength(n[a])},{purpose:"pointer",route:"github",root:o.configFolder,listing:d,managedFiles:n});return m.admitted||t.set(a,m.reason),m.admitted},p=new Map([...new Set([...o.configs,...u??[]])].flatMap(a=>g(a)&&Object.hasOwn(n,a)?[[a,Ze(n[a],e)]]:[]));r.variants=o.configs.map(a=>({path:a,fields:(p.get(a)?.fields??[]).map(m=>({...m,path:a}))})),r.selectedPaths=u?[...u]:[s];let k=new Map;for(let a of r.selectedPaths){if(_(a,o.configFolder)===null){r.unresolved.push({path:a,source:a,reason:"out-of-scope"});continue}let m=p.get(a);if(!m){r.unresolved.push({path:a,source:a,reason:t.get(a)??"missing"});continue}r.unresolved.push(...m.unresolved.map(w=>({path:a,source:w.key,span:w.span,reason:w.reason})));for(let w of m.fields)if(/^(?:agent|model|environment)(?:\.|$)/.test(w.key)){for(let h of k.keys())(h.startsWith(`${w.key}.`)||w.key.startsWith(`${h}.`))&&k.delete(h);k.set(w.key,{...w,path:a})}}r.fields=[...k.values()],r.model=k.get("model.model_name")?.value??null;let P=new Set;for(let a of r.fields){let m=new Set([a.path]),w=[{path:a.path,facts:{variables:a.variables,loaders:a.loaders},next:0}];for(;w.length;){let h=w.at(-1),{path:c,facts:l}=h;if(h.next===0)for(let v of l.variables)r.unresolved.push({path:c,source:v,reason:"runtime-variable"});if(h.next>=l.loaders.length){m.delete(c),w.pop();continue}let f=l.loaders[h.next++],i=Y.normalize(Y.join(Y.dirname(c),f.source)),S=f.reason??(Y.isAbsolute(f.source)||_(i,o.configFolder)===null?"out-of-scope":g(i)?m.has(i)?"cycle":Object.hasOwn(n,i)?null:"missing":t.get(i));if(S){r.unresolved.push({path:c,source:f.source,...f.reason?{}:{target:i},span:f.span,reason:S});continue}r.edges.push({from:c,to:i,span:f.span}),!P.has(i)&&(P.add(i),r.loaded.push({path:i}),m.add(i),w.push({path:i,facts:ue(n[i]),next:0}))}}return r}import{posix as oe}from"node:path";function he(e){return/(?:^|\/)(?:(?:[^/]+_)?(?:crew|agents|tasks))\.py$/i.test(e)}function Ve(e,o,n,u=""){let r=D(e,o,"py"),{toks:s}=r,t=te(r,{includeMembers:!0}),d=xe(r),g=ne(r,t,{enclosingBindings:!0}),p={agents:[],tasks:[],refused:[]},k=a=>t.filter(m=>m.from<=a&&a<m.to),P=a=>{if(!F(s[a])||E(s[a-1],".")||!E(s[a+1],"("))return null;let m=g.importBinding(s[a].text,a);return m?.module.source==="crewai"&&["Agent","Task"].includes(m.name)?m.name:null};for(let a=0;a<s.length;a++){let m=P(a);if(!m)continue;let w=N(s,a+1);if(w>=s.length){p.refused.push({path:e,reason:"invalid"});continue}let h=k(a),c=h.filter(C=>C.kind==="class").at(-1),l=h.filter(C=>C.params!==null).at(-1),f=h.filter(C=>C.params===null&&C.kind!=="class"&&C.kind!=="index").at(-1),i=l?.name??f?.name??`line-${s[a].line}`,S=c?`${c.name}.${i}`:i,v=h.some(C=>C.kind==="index")||p.agents.some(C=>C.factory===S)?`${S}@${s[a].start}`:S,y=new Map(z(s,a+1).flatMap(C=>F(s[C.from])&&E(s[C.from+1],"=")?[[s[C.from].text,{from:C.from+2,to:C.to}]]:[])),b={path:e,factory:v,span:{from:s[a].line,to:s[w].endLine},callStart:s[a].start},O=y.get("config");if(O){let C=s.slice(O.from,O.to).map(x=>x.kind==="string"?JSON.stringify(x.value):x.text).join(""),L=/^(?:self\.)?(agents_config|tasks_config)\["([^"\n]+)"\]$/.exec(C);if(L){let x=t.filter($=>$.name===L[1]&&$.params===null&&(c?c.from<$.from&&$.to<=c.to&&!t.some(W=>W.params!==null&&W.from<$.from&&$.from<W.to):!t.some(W=>W.kind==="class"&&W.from<$.from&&$.from<W.to))),R=x.length===1?Ke(r,x[0]):void 0,A=c&&ct(r,c,g),j=R?de(r,R):x.length===0&&A?`config/${L[1]==="agents_config"?"agents":"tasks"}.yaml`:null,V=null;if(j===null||/[\\\0${}*]/.test(j))p.refused.push({path:e,reason:"dynamic"});else{let $=oe.normalize(oe.join(oe.dirname(e),j));j.startsWith("/")||$===".."||$.startsWith("../")||_($,u)===null?p.refused.push({path:$,reason:"out-of-scope"}):n.has($)?V=$:p.refused.push({path:$,reason:"missing"})}b.config={path:V,key:L[2]}}else b.config={path:null,key:""},p.refused.push({path:e,reason:"dynamic"})}let M=pe(r,y.get("tools"),n,t,l,c,p.refused,g);if(m==="Agent"){let C=Object.fromEntries(["role","goal","backstory"].flatMap(L=>{let x=y.get(L)&&de(r,y.get(L));return y.has(L)&&x==null&&p.refused.push({path:e,reason:"dynamic"}),x==null?[]:[[L,x]]}));p.agents.push({...b,instructions:C,tools:M})}else{let C=A=>lt(r,A,c,t,d),L=C(y.get("agent")),x=y.get("context"),R=x&&E(s[x.from],"[")&&N(s,x.from)===x.to-1?z(s,x.from):[];x&&(!E(s[x.from],"[")||R.some(A=>!C(A)))&&p.refused.push({path:e,reason:"dynamic"}),y.has("agent")&&!L&&p.refused.push({path:e,reason:"dynamic"}),p.tasks.push({...b,agent:L,context:R.flatMap(A=>C(A)??[]),tools:M})}a=w}return p}function Ke(e,o){let n=o.from+1;for(;n<o.to&&!E(e.toks[n],"=");)n++;return n<o.to?{from:n+1,to:o.to}:void 0}function de(e,o){let{toks:n}=e;return o.to===o.from+1&&n[o.from]?.kind==="string"&&ye(n[o.from]).closed?n[o.from].value:F(n[o.from],"dedent")&&E(n[o.from+1],"(")&&N(n,o.from+1)===o.to-1?de(e,{from:o.from+2,to:o.to-1}):null}function lt(e,o,n,u,r){if(!o)return null;let s=e.toks.slice(o.from,o.to).map(d=>d.text).join(""),t=/^(self\.)?([A-Za-z_]\w*)(?:\(\))?$/.exec(s);if(t&&!t[1]){let d=u.filter(p=>p.params!==null&&p.from<o.from&&o.from<p.to),g=p=>u.filter(k=>k.params!==null&&k.from<p&&p<k.to).at(-1);if(d.some(p=>p.params?.includes(t[2]))||u.some(p=>p.name===t[2]&&d.includes(g(p.from)))||r.some(p=>p.names.includes(t[2])&&d.includes(g(e.toks.findIndex(k=>k.line===p.line)))))return null}return t?t[1]&&n?`${n.name}.${t[2]}`:t[2]:null}function pe(e,o,n,u,r,s,t,d,g=new Set){if(!o)return[];let{toks:p}=e;if(E(p[o.from],"[")&&N(p,o.from)===o.to-1)return z(p,o.from).flatMap(i=>pe(e,i,n,u,r,s,t,d,new Set(g)));let k=p[o.from];if(!F(k)||g.has(k.text))return t.push({path:e.path,reason:"dynamic"}),[];if(g.add(k.text),r?.params?.includes(k.text))return t.push({path:e.path,reason:"dynamic"}),[];let a=u.filter(i=>i.name===k.text&&i.params===null&&i.kind!=="class"&&i.from<o.from).filter(i=>{let S=u.filter(v=>(v.params!==null||v.kind==="class")&&v.from<i.from&&i.from<v.to).at(-1);return!S||S===r||!r&&S===s}),m=r&&a.filter(i=>r.from<i.from&&i.to<=r.to),w=m&&m.length?m:a;if(w.length===1){let i=Ke(e,w[0]);if(i)return pe(e,i,n,u,r,s,t,d,g)}if(w.length>1)return t.push({path:e.path,reason:"dynamic"}),[];let h=d.importBinding(k.text,o.from),c=h?.module,l=null;if(c){let i=oe.dirname(e.path).split("/"),S=i.lastIndexOf(c.source.split(".")[0]),v=c.source.startsWith(".")?c.source:S<0?`.${c.source}`:".".repeat(i.length-S)+c.source.split(".").slice(1).join(".");l=Ue(e.path,v,[h.name],"py",n)??null,!l&&(c.source.startsWith(".")||S>=0)&&t.push({path:e.path,reason:"missing"})}else if(!u.some(i=>i.name===k.text&&(i.kind==="class"||i.params!==null)))return t.push({path:e.path,reason:"dynamic"}),[];let f=o.from+1;for(;E(p[f],".")&&F(p[f+1]);)f+=2;return f<o.to&&(!E(p[f],"(")||N(p,f)!==o.to-1)?(t.push({path:e.path,reason:"dynamic"}),[]):[{name:p.slice(o.from,f).map(i=>i.text).join(""),path:c?l:e.path}]}function ct(e,o,n){let u=e.text.slice(0,e.toks[o.from].start).trimEnd().split(`
|
|
7
|
-
`);for(let r=u.length-1;r>=0;r--){let s=/^\s*@([A-Za-z_]\w*)(?:\(\))?\s*$/.exec(u[r]);if(!s)break;let t=n.importBinding(s[1],o.from);if(t?.module.source==="crewai.project"&&t.name==="CrewBase")return!0}return!1}var ft=new Set([...je,ee.soul].map(e=>e.toLowerCase())),mt=["templates","default_prompts","prompts/default","docs","evals","benchmarks"],ut=["tests","__tests__","fixtures","test_data","evals","benchmarks","templates","default_prompts","prompts/default","docs"];function Xe(e,o=""){return e===o?null:`folder:${e}`}function Pn(e,o,n){let u=Ye(e,o,n),r=U(n),s=o.filter(m=>!T(e,m,r)),t=s.filter(m=>u.ownerOf(m)?.key===null),d=Z(e,t,r),g=X(d)||!!d.configPath,p=G(e,t,{root:r}).files.filter(m=>m.role!=="reference"&&m.kind!=="background"),k=new Set(p.map(m=>m.relativePath)),P=p.flatMap(m=>m.role==="sub-agent"?[m.relativePath.slice(0,-3)]:m.role==="skill"?[m.relativePath.slice(0,m.relativePath.lastIndexOf("/"))]:[]),a=new Map(u.scopes.map(m=>[m.folder,{scope:m,paths:[]}]));for(let m of[...new Set(s)]){let w=u.ownerOf(m);if(!w)continue;let h=_(m,r),c=h.split("/");if(w.key===null&&g&&c.length>1&&!k.has(h)&&!P.some(l=>_(h,l)!==null)){let l=c.slice(0,-1).findIndex((i,S)=>![...k].some(v=>v.startsWith(`${c.slice(0,S+1).join("/")}/`))),f=H(c.slice(0,l<0?-1:l+1).join("/"),r);a.has(f)||a.set(f,{scope:{key:Xe(f,r),folder:f,kind:"folder"},paths:[]}),w=a.get(f).scope}a.get(w.folder).paths.push(m)}return[...a.values()].sort((m,w)=>m.scope.folder<w.scope.folder?-1:m.scope.folder>w.scope.folder?1:0).map(({scope:m,paths:w})=>{let h=Z(e,w,m.folder),c=u.scopes.includes(m);return{scope:m,paths:w,convention:c&&(!!m.managed||!!m.miniSwe||m.kind==="crew"&&!m.agentsPath.endsWith(".py")||Be(e,h)),markerPath:c?h.configPath:null}})}function Ye(e,o,n,u={},r){let s=U(n);r??=q(e)?me(e,o,n):void 0;let t=we(e),d=Le(e,o,u),{scopes:g,skipped:p,pluginFolders:k}=t?dt(e,o,s,d,r):{scopes:[{key:null,folder:s,kind:"root"}],skipped:[],pluginFolders:[]},P=c=>He(g,c),a=new Set(o),m=o.filter(c=>T(e,c,s)||P(c)&&(t&&Q(e,c,k)||_e(e,c,{root:s,listing:a}))),w=new Set(I(e)?Object.entries(u).filter(([c])=>c.endsWith(".py")&&P(c)).flatMap(([c,l])=>Ve(c,l,new Set(o),s).agents.flatMap(f=>f.tools.flatMap(i=>i.path??[]))):[]),h=t?o.filter(c=>{let l=P(c);return!w.has(c)&&l?.kind==="crew"&&_(c,l.folder)?.toLowerCase().startsWith("tools/")}):[];return{scopes:g,skipped:p,ownerOf:P,pluginFolders:k,ignoredPaths:m,ignoredImportPaths:h,...d.length?{pluginDeclarations:d.filter(c=>k.includes(c.folder))}:{}}}function He(e,o){return e.findLast(n=>_(o,n.folder)!==null)??null}function dt(e,o,n,u,r){let s=[...new Set(o)].filter(a=>!Q(e,a)).sort().flatMap(a=>{let m=_(a,n);return m===null?[]:[{path:a,relativePath:m}]}),t=[],d=new Map,g=s.filter(a=>!T(e,a.path,n)).map(a=>a.path);for(let a of Ie(e,g))d.set(a.folder,a.agents.map(m=>({path:m,plugin:!1,crew:!1,checkPath:`${a.folder}/`,managed:a})));for(let a of Je(e,g))d.set(a.folder,[...d.get(a.folder)??[],{path:a.agentPath,plugin:!1,crew:!1,checkPath:`${a.folder}/`,miniSwe:a}]);for(let{path:a,relativePath:m}of s){let w=m.split("/"),h=w.pop().toLowerCase(),c=H(w.join("/"),n),l=w.length>0&&(ft.has(h)||K.includes(h)&&J(e,o,{root:c,agentConfigurations:r})),f=Me(e,a,u);f===n&&!T(e,a,n)&&!t.includes(n)&&t.push(n);let i=f!==null&&f!==n&&!!_(`${f}/`,n),S=m.toLowerCase()==="config/agents.yaml"||m.toLowerCase().endsWith("/config/agents.yaml"),v=I(e)&&he(a)&&!/(?:^|\/)(?:tasks|[^/]+_tasks)\.py$/i.test(a),y=S||v;if(!l&&!i&&!y)continue;let b=S?a.slice(0,-18).replace(/\/$/,""):v?a.slice(0,Math.max(0,a.lastIndexOf("/"))):i?f:H(w.join("/"),n),O=d.get(b)??[];O.push({path:a,plugin:i,crew:y,checkPath:i?`${b}/`:a}),d.set(b,O)}let p=Fe(e),k={settings:e,folder:n,scoped:s,candidates:d,rootPlugins:t,excludedFolders:p?mt:ut},P=qe(k,new Set);if(p){let a=[...new Set(P.accepted.map(l=>l.folder))].filter(l=>l!==n),m=s.filter(l=>!T(e,l.path,n)&&!a.some(f=>_(l.path,f)!==null)).map(l=>l.path),w=G(e,m,{root:n,folderAgentsFound:a.length>0,agentConfiguration:J(e,o,{root:n,agentConfigurations:r})}),h=Qe(e,w,a.length>0)?[{path:`${n}/`,checkPath:`${n}/`}]:[],c=Ce([...P.accepted,...h],l=>l.checkPath,{root:n,listing:new Set(s.map(l=>l.path)),settings:e});if(P.accepted.some(l=>c(l.checkPath))){let l=new Set([...d.values()].flat().filter(f=>c(f.checkPath)).map(f=>f.path));P=qe(k,l)}}return P.skipped.sort((a,m)=>a.path<m.path?-1:a.path>m.path?1:0),{scopes:P.scopes,skipped:P.skipped,pluginFolders:P.pluginFolders}}function qe({settings:e,folder:o,scoped:n,candidates:u,rootPlugins:r,excludedFolders:s},t){let d=[{key:null,folder:o,kind:"root"}],g=[],p=[...r],k=[],P=new Map;for(let a of[...u.keys()].sort()){let m=u.get(a),w=He(d,m[0].path),h=P.get(w.folder)??pt(n.map(y=>y.path),w.folder);P.set(w.folder,h);let c=[];for(let y of m){let{path:b,checkPath:O}=y;if(Q(e,b,p))continue;let M=T(e,b,o)?"excluded-folder":a===o?null:t.has(b)?"excluded-folder":ht(_(O,o),_(O,w.folder),h,be(e,b,o)?[]:s);M?g.push({path:b,reason:M}):(c.push(y),k.push({path:b,folder:a,checkPath:O}))}if(!c.length)continue;let l=(I(e)?c.find(y=>y.crew&&y.path.endsWith("config/agents.yaml")):void 0)??c.find(y=>y.crew),f=Xe(a,o),i=l?{key:f,folder:a,kind:"crew",agentsPath:l.path,tasksPath:n.find(y=>_(y.path,a)?.toLowerCase()==="config/tasks.yaml")?.path??null}:{key:f,folder:a,kind:"folder"},S=c.find(y=>y.managed)?.managed;S&&(i.managed=S);let v=c.find(y=>y.miniSwe)?.miniSwe;v&&(i.miniSwe=v),a===o?d[0]=i:d.push(i),c.some(y=>y.plugin)&&!p.includes(a)&&p.push(a)}return{scopes:d,skipped:g,pluginFolders:p,accepted:k}}function yn(e,o,n,u={}){let r=u.agentConfigurations??(q(e)?me(e,u.listedPaths??o,n):void 0),s=Ye(e,o,n,u.files,r),{scopes:t,ownerOf:d,ignoredPaths:g}=s,p=new Set(g),k=new Map(t.map(l=>[l,[]]));for(let l of o){if(p.has(l))continue;let f=d(l);f&&k.get(f).push(l)}let P=t.map(l=>G(e,k.get(l),{root:l.folder,mode:u.mode,agentConfiguration:J(e,u.listedPaths??o,{root:l.folder,agentConfigurations:r}),folderAgentsFound:l.key===null&&(t.length>1||l.kind==="crew")})),a=(l,f)=>Qe(e,l,t[f].key===null&&(t.length>1||t[f].kind==="crew")),m=t.length===1?P:P.filter((l,f)=>t[f].managed||t[f].miniSwe||t[f].kind==="crew"||a(l,f)),w=!m.length||m.some(l=>{let f=P.indexOf(l);return t[f].managed||t[f].miniSwe?!1:t[f].kind==="crew"&&!a(l,f)?t[f].agentsPath.endsWith(".py"):!l.registry&&(!l.files.some(i=>i.role==="prompt")||!l.files.some(i=>i.role==="tool file"))}),h=new Set((s.pluginDeclarations??[]).map(l=>l.path));for(let l of $e(e,o))/marketplace\.json$/i.test(l)&&h.add(l);let c=P.flatMap((l,f)=>{let i=t[f],S=[...h].filter(y=>!p.has(y)&&d(y)===i).map(y=>({path:y,relativePath:_(y,i.folder),role:"marker",kind:"entry"}));if(i.miniSwe)return[...l.files,...S,...[...i.miniSwe.configs,...i.miniSwe.templates,i.miniSwe.agentPath,i.miniSwe.loaderPath,i.miniSwe.runnerPath].map(y=>({path:y,relativePath:_(y,i.folder),role:"knowledge",kind:"entry"}))];if(i.managed)return[...[...i.managed.agents,...i.managed.configs].flatMap(y=>{let b=ie(_(y,i.folder))?.definition;if(b&&(u.mode==="core"||!Te(e)))return[];let O=i.managed.agents.includes(y);return[{path:y,relativePath:_(y,i.folder),role:O?"prompt":b?"skill":"knowledge",kind:O?"entry":b?"skill":"json"}]}),...S];if(i.kind!=="crew")return[...l.files,...S];let v=[{path:i.agentsPath,relativePath:_(i.agentsPath,i.folder),role:"prompt",kind:"entry"}];if(I(e))for(let y of k.get(i)){let b=_(y,i.folder);y!==i.agentsPath&&(he(b)&&!b.includes("/")||/^config\/[^/]+\.ya?ml$/i.test(b))&&v.push({path:y,relativePath:b,role:"knowledge",kind:"entry"})}return i.tasksPath&&v.push({path:i.tasksPath,relativePath:_(i.tasksPath,i.folder),role:"knowledge",kind:"entry"}),[...l.files,...v,...S]});return{...s,files:c,needsExtraction:w}}function Qe(e,o,n){let u=fe(o,e),r=ge({codeAgentsFound:!1,folderAgentsFound:n,otherDefinitions:X(u),agentConfiguration:o.files.some(s=>s.role==="prompt"&&s.kind==="fallback")},e);return Ge(u,r)}function pt(e,o){let n=new Set;for(let u of e){let r=_(u,o);r!==null&&ce.test(r)&&n.add(r.slice(0,-3).toLowerCase())}return n}function ht(e,o,n,u){let r=e.toLowerCase();if(u.some(d=>`/${r}`.includes(`/${d}/`)))return"excluded-folder";let s=r.slice(0,r.lastIndexOf("/"));if(ie(e,{nested:!0})||We.some(d=>s===d||s.endsWith(`/${d}`)))return"skill-folder";if(`/${r}`.includes(`/${De}/${Ne}/`)||ce.test(o))return"sub-agent-folder";let t=o.toLowerCase().split("/");return t.some((d,g)=>n.has(t.slice(0,g).join("/")))?"sub-agent-folder":null}export{Z as a,ze as b,X as c,Be as d,Ge as e,me as f,$t as g,Ze as h,Nt as i,Jt as j,Ve as k,Pn as l,Ye as m,yn as n};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as e}from"zod";var o=e.object({isSystemPrompt:e.boolean(),name:e.string(),reason:e.string()}),i=e.object({verdicts:e.array(e.object({id:e.string(),evidenceAgainst:e.string(),evidenceFor:e.string(),verdict:e.enum(["keep","drop"]),reason:e.string()}))}),r=e.object({sites:e.array(e.object({index:e.number(),role:e.string(),meaning:e.string(),keyPhrase:e.string()})),support:e.string(),supportNote:e.string(),counterEvidence:e.array(e.object({repo:e.string(),path:e.string(),line:e.number(),excerpt:e.string(),meaning:e.string()}))});import{z as t}from"zod";var n=["Says","But also says","Unclear","Context","Requirement","What actually happens","Why it's a gap","Evidence"],p=t.object({sites:t.array(t.object({index:t.number().int().nonnegative(),role:t.enum(n),meaning:t.string(),keyPhrase:t.string()})),support:t.enum(["supported","partly","not_supported"]),supportNote:t.string(),counterEvidence:t.array(t.object({repo:t.string(),path:t.string(),line:t.number().int().positive(),excerpt:t.string(),meaning:t.string()}))});export{o as a,i as b,r as c,n as d,p as e};
|