@counterfact-labs/cli 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +4 -5
  2. package/bundle/client-release.json +1 -1
  3. package/dist/adapters/analysis-results.js +10 -5
  4. package/dist/adapters/completion.js +75 -41
  5. package/dist/adapters/config-directory.js +5 -0
  6. package/dist/adapters/files.js +25 -10
  7. package/dist/adapters/legacy-reports.js +48 -0
  8. package/dist/adapters/output-paths.js +85 -5
  9. package/dist/adapters/result-receipt.js +78 -0
  10. package/dist/adapters/results.js +5 -8
  11. package/dist/adapters/settings.js +10 -4
  12. package/dist/adapters/storage-identity.js +27 -0
  13. package/dist/analysis-core/analysis/code-agents/skipped-files.js +1 -1
  14. package/dist/analysis-core/analysis/file-analysis-plan.js +1 -1
  15. package/dist/analysis-core/analysis/file-dependencies.js +1 -1
  16. package/dist/analysis-core/analysis/finding-quality/policy.js +1 -1
  17. package/dist/analysis-core/analysis/folder-analysis-plan.js +1 -1
  18. package/dist/analysis-core/analysis/passes/full-file-passes.js +1 -1
  19. package/dist/analysis-core/analysis/schemas.js +1 -1
  20. package/dist/analysis-core/chunks/{5VQ4VYIP.js → 2IQN26TC.js} +1 -1
  21. package/dist/analysis-core/chunks/{N2L4JMJE.js → 2J3PWUPG.js} +1 -1
  22. package/dist/analysis-core/chunks/{3GUKUEEJ.js → 5JG3ZRNJ.js} +1 -1
  23. package/dist/analysis-core/chunks/{LFJQ4YLP.js → 6E4K7JTI.js} +1 -1
  24. package/dist/analysis-core/chunks/{66JRJPJC.js → 6W6B7VSP.js} +1 -1
  25. package/dist/analysis-core/chunks/{P253B344.js → AIS3FHQR.js} +7 -7
  26. package/dist/analysis-core/chunks/{YWL52FVW.js → EJ2IZUN2.js} +2 -2
  27. package/dist/analysis-core/chunks/{5UWDUYHF.js → GOBOE2SC.js} +1 -1
  28. package/dist/analysis-core/chunks/GYXDN5W4.js +1 -0
  29. package/dist/analysis-core/chunks/GZSUTDGX.js +1 -0
  30. package/dist/analysis-core/chunks/HB5BTGTI.js +6 -0
  31. package/dist/analysis-core/chunks/HH3HDT5K.js +73 -0
  32. package/dist/analysis-core/chunks/{TA2NIQAY.js → I5F7S63K.js} +1 -1
  33. package/dist/analysis-core/chunks/ICJV6KIZ.js +11 -0
  34. package/dist/analysis-core/chunks/{2CWULBP2.js → JCVB6IC4.js} +1 -1
  35. package/dist/analysis-core/chunks/{DHVEGIU6.js → JLW44GIU.js} +1 -1
  36. package/dist/analysis-core/chunks/JS6HTVYX.js +1 -0
  37. package/dist/analysis-core/chunks/{UKX3A6AX.js → JWQXG5RB.js} +1 -1
  38. package/dist/analysis-core/chunks/LOODGUMW.js +1 -0
  39. package/dist/analysis-core/chunks/{XVGLY4EO.js → NWYNJHY4.js} +1 -1
  40. package/dist/analysis-core/chunks/{KBTM5MBC.js → OHDC3L6V.js} +1 -1
  41. package/dist/analysis-core/chunks/OXGKALKM.js +1 -0
  42. package/dist/analysis-core/chunks/{MJGB25S5.js → P5FCHJ7W.js} +1 -1
  43. package/dist/analysis-core/chunks/PISOGSJF.js +1 -0
  44. package/dist/analysis-core/chunks/{6VHZNBII.js → QENYFKG3.js} +8 -8
  45. package/dist/analysis-core/chunks/{W73WF226.js → QY57UR6E.js} +1 -1
  46. package/dist/analysis-core/chunks/QYYN4YKB.js +35 -0
  47. package/dist/analysis-core/chunks/UYG422QR.js +0 -0
  48. package/dist/analysis-core/chunks/V7GZHSVR.js +1 -0
  49. package/dist/analysis-core/chunks/{VWRFSVLI.js → VBGQKYIT.js} +1 -1
  50. package/dist/analysis-core/chunks/{5BTATES5.js → VVSHUUWX.js} +1 -1
  51. package/dist/analysis-core/chunks/{JKWTHRUR.js → YDSB7UOR.js} +1 -1
  52. package/dist/analysis-core/chunks/ZLUI3EHB.js +1 -0
  53. package/dist/analysis-core/contracts/execution-request.js +1 -1
  54. package/dist/analysis-core/contracts/model-errors.js +1 -0
  55. package/dist/analysis-core/contracts/relay-analysis.js +1 -1
  56. package/dist/analysis-core/contracts/requests.js +1 -1
  57. package/dist/analysis-core/conventions/analysis-fit.js +1 -1
  58. package/dist/analysis-core/conventions/file-admission.js +1 -1
  59. package/dist/analysis-core/errors.js +1 -1
  60. package/dist/analysis-core/import/calls/modules.js +1 -1
  61. package/dist/analysis-core/import/entry-selection.js +1 -1
  62. package/dist/analysis-core/import/outside-loader-sources.js +1 -1
  63. package/dist/analysis-core/index.js +1 -1
  64. package/dist/analysis-core/llm/cache-policy.js +1 -1
  65. package/dist/analysis-core/llm/cost.js +1 -1
  66. package/dist/analysis-core/llm/structured-output-error.js +1 -1
  67. package/dist/analysis-core/requests/frame-budget.js +1 -0
  68. package/dist/analysis-core/requests/local-plan.js +1 -1
  69. package/dist/analysis-core/requests/planned-limits.js +1 -1
  70. package/dist/analysis-core/requests/registry.js +1 -1
  71. package/dist/analysis-core/requests/template-version.js +1 -1
  72. package/dist/analysis-core/requests/tools.js +1 -1
  73. package/dist/analysis-core/settings.js +1 -1
  74. package/dist/analysis-core/stages/engine-entry.js +1 -1
  75. package/dist/analysis-core/wording.js +1 -0
  76. package/dist/cli/analysis-preview.js +22 -0
  77. package/dist/cli/analysis-selection.js +6 -8
  78. package/dist/cli/commands/analyze.js +27 -21
  79. package/dist/cli/commands/login.js +5 -0
  80. package/dist/cli/compatibility.js +39 -0
  81. package/dist/cli/completion-delivery.js +4 -3
  82. package/dist/cli/completion-recovery.js +25 -23
  83. package/dist/cli/credentials.js +3 -2
  84. package/dist/cli/finding-display.js +3 -2
  85. package/dist/cli/git.js +5 -2
  86. package/dist/cli/main.js +8 -2
  87. package/dist/cli/mcp.js +35 -10
  88. package/dist/cli/prior-completion.js +1 -1
  89. package/dist/cli/relay-check.js +85 -23
  90. package/dist/cli/relay-failure.js +19 -11
  91. package/dist/cli/relay-preparation.js +6 -3
  92. package/dist/cli/scope-choices.js +5 -4
  93. package/dist/cli/skipped-files.js +2 -1
  94. package/dist/cli/suggested-email.js +6 -1
  95. package/dist/cli/summary.js +2 -1
  96. package/dist/contract/agent-choice.js +2 -0
  97. package/dist/contract/cli-refusals.js +105 -9
  98. package/dist/contract/cli-version.js +1 -1
  99. package/dist/contract/console.js +2 -1
  100. package/dist/contract/email-sign-in-messages.js +2 -1
  101. package/dist/contract/scope-choice.js +4 -1
  102. package/dist/gatekeeper/client.js +11 -2
  103. package/dist/gatekeeper/connection-exchange.js +19 -4
  104. package/dist/gatekeeper/connection.js +15 -6
  105. package/dist/gatekeeper/console.js +8 -4
  106. package/dist/gatekeeper/model.js +13 -3
  107. package/package.json +1 -1
  108. package/dist/adapters/gitignore-output.js +0 -41
  109. package/dist/analysis-core/chunks/2M55DR2J.js +0 -35
  110. package/dist/analysis-core/chunks/34NVU26H.js +0 -1
  111. package/dist/analysis-core/chunks/C77LGCKF.js +0 -1
  112. package/dist/analysis-core/chunks/HCPO6QPU.js +0 -1
  113. package/dist/analysis-core/chunks/J4AXGE5W.js +0 -1
  114. package/dist/analysis-core/chunks/M5YWJY7P.js +0 -1
  115. package/dist/analysis-core/chunks/NCW5LJ5O.js +0 -6
  116. package/dist/analysis-core/chunks/QPIBHTON.js +0 -67
  117. package/dist/analysis-core/chunks/SJESFYBA.js +0 -10
  118. package/dist/analysis-core/chunks/VC3PYT2B.js +0 -1
@@ -14,7 +14,8 @@ export function readJobSettings(env = process.env) {
14
14
  export function readSelectionSettings(env = process.env, options = {}) {
15
15
  const localImportResolution = env.CF_LOCAL_IMPORT_RESOLUTION;
16
16
  const saved = Object.freeze({ CF_FILE_SCOPE: env.CF_FILE_SCOPE ?? (localImportResolution === "0" ? "0" : "1"), CF_SCOPE_CHOICES: env.CF_SCOPE_CHOICES ?? "1",
17
- CF_LOCAL_IMPORT_RESOLUTION: localImportResolution, ...(env.CF_MULTI_ENTRY === undefined ? {} : { CF_MULTI_ENTRY: env.CF_MULTI_ENTRY }) });
17
+ CF_LOCAL_IMPORT_RESOLUTION: localImportResolution, ...(env.CF_MULTI_ENTRY === undefined ? {} : { CF_MULTI_ENTRY: env.CF_MULTI_ENTRY }),
18
+ ...(env.CF_PYTHON_SRC_IMPORTS === undefined ? {} : { CF_PYTHON_SRC_IMPORTS: env.CF_PYTHON_SRC_IMPORTS }) });
18
19
  if (options.validate !== false)
19
20
  for (const [name, value] of Object.entries(saved)) {
20
21
  if (value !== undefined && value !== "0" && value !== "1")
@@ -24,7 +25,7 @@ export function readSelectionSettings(env = process.env, options = {}) {
24
25
  }
25
26
  export function readTransportSettings(env = process.env) {
26
27
  return Object.freeze({ CF_LOCAL_RELAY: env.CF_LOCAL_RELAY, CF_RELAY_DEV: env.CF_RELAY_DEV, ANTHROPIC_API_KEY: env.ANTHROPIC_API_KEY,
27
- ...Object.fromEntries(["CF_CLI_TRANSPORT_ERRORS", "CF_LOCAL_RESULTS_RETRY", "CF_RELAY_URL", "CF_CONSOLE_URL", "CF_CONSOLE_TOKEN", "CF_RELAY_DEV_TRUST", "CF_RELAY_DEV_BUNDLE", "CF_RELAY_DEV_RELEASE"].filter(key => env[key] !== undefined).map(key => [key, env[key]])) });
28
+ ...Object.fromEntries(["CF_FILES_PREVIEW", "CF_CLI_TRANSPORT_ERRORS", "CF_LOCAL_RESULTS_RETRY", "CF_LOCAL_RESULTS_KEEP", "CF_RELAY_URL", "CF_CONSOLE_URL", "CF_CONSOLE_TOKEN", "CF_RELAY_DEV_TRUST", "CF_RELAY_DEV_BUNDLE", "CF_RELAY_DEV_RELEASE"].filter(key => env[key] !== undefined).map(key => [key, env[key]])) });
28
29
  }
29
30
  export function readSkippedFilesSetting(value) {
30
31
  const choice = value ?? "1";
@@ -48,6 +49,9 @@ export function captureArchitectureSettings(settings, transport) {
48
49
  }
49
50
  /** Only creation fills defaults; continuation consumes its saved snapshot unchanged. */
50
51
  export function newRunSettings(caller, env = process.env) {
52
+ const scanPriority = caller?.CF_CODE_SCAN_PRIORITY ?? env.CF_CODE_SCAN_PRIORITY ?? "1";
53
+ if (scanPriority !== "0" && scanPriority !== "1")
54
+ throw new Error("CF_CODE_SCAN_PRIORITY must be 0 or 1.");
51
55
  const choice = caller?.CF_FINDING_HEADLINES || env.CF_FINDING_HEADLINES || "0";
52
56
  if (choice !== "0" && choice !== "1")
53
57
  throw new Error("CF_FINDING_HEADLINES must be 0 or 1.");
@@ -66,6 +70,7 @@ export function newRunSettings(caller, env = process.env) {
66
70
  const costFindings = caller?.CF_COST_FINDINGS ?? env.CF_COST_FINDINGS;
67
71
  const selection = readSelectionSettings({ CF_FILE_SCOPE: caller?.CF_FILE_SCOPE ?? env.CF_FILE_SCOPE,
68
72
  CF_SCOPE_CHOICES: caller?.CF_SCOPE_CHOICES ?? env.CF_SCOPE_CHOICES,
73
+ CF_PYTHON_SRC_IMPORTS: caller?.CF_PYTHON_SRC_IMPORTS ?? env.CF_PYTHON_SRC_IMPORTS,
69
74
  CF_MULTI_ENTRY: caller?.CF_MULTI_ENTRY ?? env.CF_MULTI_ENTRY,
70
75
  CF_LOCAL_IMPORT_RESOLUTION: caller?.CF_LOCAL_IMPORT_RESOLUTION ?? env.CF_LOCAL_IMPORT_RESOLUTION });
71
76
  for (const [name, value] of Object.entries({ CF_LOCAL_COMMITTED_ONLY: committedOnly,
@@ -78,7 +83,7 @@ export function newRunSettings(caller, env = process.env) {
78
83
  throw new Error("CF_IMPORT_COVERAGE must be 0 or 1.");
79
84
  // Disabling coverage must not introduce feature choices into the earlier importer.
80
85
  const importer = coverage === "1" ? Object.fromEntries(Object.entries(importerCoverageDefaults).map(([name, value]) => [name, caller?.[name] || env[name] || value])) : { CF_IMPORT_COVERAGE: coverage };
81
- return snapshotSettings(captureArchitectureSettings({ ...(caller ?? env), ...importer, CF_FINDING_HEADLINES: choice, CF_IMPORT_OUTSIDE_LOADERS: outside, CF_REFUSE_TOO_LARGE: refuseTooLarge, CF_SKIPPED_FILES: skippedFiles,
86
+ return snapshotSettings(captureArchitectureSettings({ ...(caller ?? env), ...importer, CF_CODE_SCAN_PRIORITY: scanPriority, CF_FINDING_HEADLINES: choice, CF_IMPORT_OUTSIDE_LOADERS: outside, CF_REFUSE_TOO_LARGE: refuseTooLarge, CF_SKIPPED_FILES: skippedFiles,
82
87
  ...(architecture === undefined ? {} : { CF_LOCAL_ARCHITECTURE: architecture }),
83
88
  ...(committedOnly === undefined ? {} : { CF_LOCAL_COMMITTED_ONLY: committedOnly }),
84
89
  ...(gitignoreOutput === undefined ? {} : { CF_LOCAL_GITIGNORE_OUTPUT: gitignoreOutput }),
@@ -92,7 +97,8 @@ export function newRunSettings(caller, env = process.env) {
92
97
  /** The installed command selects the relay; source-only switches remain on the development runner. */
93
98
  export function readCliSettings(env = process.env, emailSignIn) {
94
99
  return Object.freeze({ settings: newRunSettings(undefined, env), transport: readTransportSettings(env),
95
- baseUrl: env.COUNTERFACT_URL ?? env.CF_CONSOLE_URL, emailSignIn: emailSignIn ?? readEmailSignIn(env) });
100
+ baseUrl: env.COUNTERFACT_URL ?? env.CF_CONSOLE_URL, emailSignIn: emailSignIn ?? readEmailSignIn(env),
101
+ signInVersionCheck: env.CF_CLI_SIGN_IN_VERSION_CHECK !== "0" });
96
102
  }
97
103
  export function readEmailSignIn(env = process.env) {
98
104
  return env.CF_EMAIL_SIGN_IN !== "0";
@@ -0,0 +1,27 @@
1
+ import { realpath } from "node:fs/promises";
2
+ import { resolveFolderPath } from "./folder-path.js";
3
+ import { runGit } from "./git.js";
4
+ import { standaloneGitFailure } from "./repository-root.js";
5
+ /** Reports and pending results belong to this folder and checkout, independently of its current commit. */
6
+ export async function storageIdentity(folder) {
7
+ const root = await resolveFolderPath(folder);
8
+ let common;
9
+ try {
10
+ common = (await runGit(root, ["rev-parse", "--path-format=absolute", "--git-common-dir"])).toString("utf8").trim();
11
+ }
12
+ catch (error) {
13
+ if (!await standaloneGitFailure(root, error))
14
+ throw error;
15
+ }
16
+ if (common === undefined)
17
+ return [root, null];
18
+ let origin = "";
19
+ try {
20
+ origin = (await runGit(root, ["config", "--get", "remote.origin.url"])).toString("utf8").trim();
21
+ }
22
+ catch (error) {
23
+ if (error.code !== 1)
24
+ throw error;
25
+ }
26
+ return [root, [await realpath(common), origin]];
27
+ }
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h}from"../../chunks/HCPO6QPU.js";import"../../chunks/724WZMYW.js";export{e as ANALYZE_SKIPPED_FILES_OFFER,h as analysisSkippedFiles,b as mergeSkippedFiles,d as mergeUnlistedFileWarnings,a as scanSkippedFiles,f as sizeSkippedFiles,c as skippedFileWarnings,g as skippedFilesNotice};
1
+ import{a,b,c,d,e,f,g,h}from"../../chunks/PISOGSJF.js";import"../../chunks/724WZMYW.js";import"../../chunks/JS6HTVYX.js";export{e as ANALYZE_SKIPPED_FILES_OFFER,h as analysisSkippedFiles,b as mergeSkippedFiles,d as mergeUnlistedFileWarnings,a as scanSkippedFiles,f as sizeSkippedFiles,c as skippedFileWarnings,g as skippedFilesNotice};
@@ -1 +1 @@
1
- import{a,b}from"../chunks/5UWDUYHF.js";import"../chunks/VC3PYT2B.js";import"../chunks/P253B344.js";import"../chunks/W73WF226.js";import"../chunks/6YCABS5T.js";import"../chunks/M5YWJY7P.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VWRFSVLI.js";import"../chunks/VX6LYNXV.js";import"../chunks/MJGB25S5.js";import"../chunks/TA2NIQAY.js";import"../chunks/34NVU26H.js";import"../chunks/CNQZLSAP.js";import"../chunks/QVXARKP7.js";import"../chunks/2M55DR2J.js";import"../chunks/74FPPPIG.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/JKWTHRUR.js";import"../chunks/3GUKUEEJ.js";import"../chunks/JAPVLU4Z.js";import"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/YWL52FVW.js";import"../chunks/SJESFYBA.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import"../chunks/INVTU73D.js";import"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";export{a as fileScopeOf,b as planFileAnalyses};
1
+ import{a,b}from"../chunks/GOBOE2SC.js";import"../chunks/AIS3FHQR.js";import"../chunks/QY57UR6E.js";import"../chunks/6YCABS5T.js";import"../chunks/GZSUTDGX.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VBGQKYIT.js";import"../chunks/VX6LYNXV.js";import"../chunks/P5FCHJ7W.js";import"../chunks/I5F7S63K.js";import"../chunks/QVXARKP7.js";import"../chunks/QYYN4YKB.js";import"../chunks/74FPPPIG.js";import"../chunks/LOODGUMW.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/YDSB7UOR.js";import"../chunks/5JG3ZRNJ.js";import"../chunks/ZLUI3EHB.js";import"../chunks/JAPVLU4Z.js";import"../chunks/OXGKALKM.js";import"../chunks/CNQZLSAP.js";import"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/JS6HTVYX.js";import"../chunks/EJ2IZUN2.js";import"../chunks/ICJV6KIZ.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import"../chunks/INVTU73D.js";import"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";export{a as fileScopeOf,b as planFileAnalyses};
@@ -1 +1 @@
1
- import{y as l}from"../chunks/YWL52FVW.js";import{a as m,h as i,j as f}from"../chunks/SJESFYBA.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";function g(r){let s=new Set(r.entries.map(e=>e.path)),a=new f({files:new Map([...s].map(e=>[e,r.files[e]??""]))},r.settings);return Object.fromEntries(Object.entries(r.files).flatMap(([e,c])=>{let n=m(e);if(!n||!s.has(e))return[];let p=l(e,c,n,!0).flatMap(t=>{let d=t.names.map(o=>t.renamed?.[o]??o);return i(e,t.source,d,n,s,a)});return[[e,[...new Set(p)]]]}))}export{g as fileDependencies};
1
+ import{y as f}from"../chunks/EJ2IZUN2.js";import{b as a,i as m,k as i}from"../chunks/ICJV6KIZ.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";function O(s){let r=new Set(s.entries.map(e=>e.path)),l=new i({files:new Map([...r].map(e=>[e,s.files[e]??""])),metadata:new Map(Object.entries(s.files))},s.settings);return Object.fromEntries(Object.entries(s.files).flatMap(([e,c])=>{let t=a(e);if(!t||!r.has(e))return[];let p=f(e,c,t,!0).flatMap(n=>{let d=n.names.map(o=>n.renamed?.[o]??o);return m(e,n.source,d,t,r,l)});return[[e,[...new Set(p)]]]}))}export{O as fileDependencies};
@@ -1 +1 @@
1
- import{g as a,h as b}from"../../chunks/NCW5LJ5O.js";import"../../chunks/QVXARKP7.js";import"../../chunks/2M55DR2J.js";import"../../chunks/74FPPPIG.js";import"../../chunks/MKYLK6DB.js";import"../../chunks/5TATKWLG.js";import"../../chunks/JKWTHRUR.js";import"../../chunks/3GUKUEEJ.js";import"../../chunks/JAPVLU4Z.js";import"../../chunks/I4F56VMG.js";import"../../chunks/33EUZF25.js";import"../../chunks/YUY436SM.js";import"../../chunks/C6X5GDG4.js";import"../../chunks/724WZMYW.js";import"../../chunks/YWL52FVW.js";import"../../chunks/SJESFYBA.js";import"../../chunks/RUVMFAST.js";import"../../chunks/S27VIQMZ.js";import"../../chunks/INVTU73D.js";import"../../chunks/A7WJJMRY.js";import"../../chunks/Q5WR6B2H.js";import"../../chunks/VDUFPTDD.js";export{a as assessFindings,b as rankFindings};
1
+ import{g as a,h as b}from"../../chunks/HB5BTGTI.js";import"../../chunks/QVXARKP7.js";import"../../chunks/QYYN4YKB.js";import"../../chunks/74FPPPIG.js";import"../../chunks/LOODGUMW.js";import"../../chunks/MKYLK6DB.js";import"../../chunks/5TATKWLG.js";import"../../chunks/YDSB7UOR.js";import"../../chunks/5JG3ZRNJ.js";import"../../chunks/ZLUI3EHB.js";import"../../chunks/JAPVLU4Z.js";import"../../chunks/OXGKALKM.js";import"../../chunks/CNQZLSAP.js";import"../../chunks/I4F56VMG.js";import"../../chunks/33EUZF25.js";import"../../chunks/YUY436SM.js";import"../../chunks/C6X5GDG4.js";import"../../chunks/724WZMYW.js";import"../../chunks/JS6HTVYX.js";import"../../chunks/EJ2IZUN2.js";import"../../chunks/ICJV6KIZ.js";import"../../chunks/RUVMFAST.js";import"../../chunks/S27VIQMZ.js";import"../../chunks/INVTU73D.js";import"../../chunks/A7WJJMRY.js";import"../../chunks/Q5WR6B2H.js";import"../../chunks/VDUFPTDD.js";export{a as assessFindings,b as rankFindings};
@@ -1 +1 @@
1
- import{c as S,d as O}from"../chunks/DHVEGIU6.js";import"../chunks/2CWULBP2.js";import{b as q}from"../chunks/5UWDUYHF.js";import{i as x}from"../chunks/VC3PYT2B.js";import"../chunks/P253B344.js";import"../chunks/W73WF226.js";import"../chunks/6YCABS5T.js";import"../chunks/M5YWJY7P.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VWRFSVLI.js";import"../chunks/VX6LYNXV.js";import"../chunks/MJGB25S5.js";import"../chunks/TA2NIQAY.js";import"../chunks/34NVU26H.js";import"../chunks/CNQZLSAP.js";import"../chunks/QVXARKP7.js";import"../chunks/2M55DR2J.js";import"../chunks/74FPPPIG.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/JKWTHRUR.js";import"../chunks/3GUKUEEJ.js";import"../chunks/JAPVLU4Z.js";import"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/YWL52FVW.js";import"../chunks/SJESFYBA.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import"../chunks/INVTU73D.js";import"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";import{posix as j}from"node:path";function H(y,f){if(!x(y))return[];let b=[],p=new Set,v=new Set,a=[...new Set(f.paths)],i=new Set(a),d=new Set(f.agentPromptPaths.filter(e=>i.has(e))),r=f.fragment.nodes.filter(e=>e.kind==="agent"),E=new Set(r.flatMap(e=>e.files.map(t=>t.path).filter(t=>i.has(t)))),u=new Map(r.map(e=>[e.id,f.fragment.edges.filter(t=>t.from===e.id&&t.kind==="delegates").map(t=>t.to)])),F=e=>{let t=new Set,s=[e];for(;s.length;){let n=s.pop();t.has(n)||(t.add(n),s.push(...u.get(n)??[]))}return r.filter(n=>t.has(n.id)).flatMap(n=>n.files.map(o=>o.path).filter(o=>i.has(o)))},g=Object.assign(Object.create(null),f.dependencies),P=(e,t)=>{for(let s of e)g[s]=[...new Set([...g[s]??[],...t])]},R=e=>{let t=new Map;for(let s of e)for(let n of new Set(s.files))t.set(n,(t.get(n)??0)+1);return s=>t.get(s)===1},W=r.map(e=>({files:e.files.map(t=>t.path).filter(t=>i.has(t))})),$=R(W),A=e=>[...e.files.map(t=>t.path).filter(t=>i.has(t)).filter($),...e.sourceRef&&i.has(e.sourceRef.path)?[e.sourceRef.path]:[]],C=e=>e.sourceRef&&d.has(e.sourceRef.path)?e.sourceRef.path:e.files.find(t=>d.has(t.path))?.path;for(let e of r)P(A(e),F(e.id));let M=O(f.codeAgents??[]).map(e=>({...e,files:e.files.filter(t=>i.has(t))})),J=R(M);for(let e of M)P(e.files.filter(J),e.files);let k=(e,t,s)=>{if(!t.length)return!1;let n=q(y,{...f,dependencies:g,paths:t});if(n.groups.length!==1||n.tooLarge.length||n.unavailable.length||n.missingContext?.length)return!1;let o=[...n.groups[0].files].sort(),l=d.has(s)&&o.includes(s)?s:o.find(h=>d.has(h));if(!l||a.every(h=>o.includes(h)))return!1;let c=JSON.stringify(o);return v.has(c)||(v.add(c),o.forEach(h=>p.add(h)),b.push({label:e??S(o),files:o,reason:l})),!0},m=new Set,w=e=>{if(m.has(e))return;m.add(e);let t=r.find(n=>n.id===e);if(!t)return;let s=F(e);if(s.length){let n=A(t);if(n.length){let l=S(n);s.push(...a.filter(c=>!E.has(c)&&(l==="."||c.startsWith(`${l}/`))))}let o=C(t);if(o&&k(t.label,s,o))return}for(let n of u.get(e)??[])w(n)},L=new Set([...u.values()].flat());for(let e of r.filter(t=>!L.has(t.id)))w(e.id);for(let e of r)!m.has(e.id)&&!e.files.every(t=>p.has(t.path))&&w(e.id);let N=new Set(a.flatMap(e=>{let t=[];for(let s=j.dirname(e);s!==".";s=j.dirname(s))t.push(s);return t}));for(let e of[...N].sort()){let t=a.filter(s=>s.startsWith(`${e}/`));t.some(s=>p.has(s))||k(void 0,t,t[0])}return b}export{H as planFolderAnalyses};
1
+ import{c as S,d as O}from"../chunks/JLW44GIU.js";import"../chunks/JCVB6IC4.js";import{b as q}from"../chunks/GOBOE2SC.js";import"../chunks/AIS3FHQR.js";import"../chunks/QY57UR6E.js";import"../chunks/6YCABS5T.js";import"../chunks/GZSUTDGX.js";import"../chunks/M6HYSTQD.js";import"../chunks/4H23CSUM.js";import"../chunks/VBGQKYIT.js";import"../chunks/VX6LYNXV.js";import"../chunks/P5FCHJ7W.js";import"../chunks/I5F7S63K.js";import"../chunks/QVXARKP7.js";import"../chunks/QYYN4YKB.js";import"../chunks/74FPPPIG.js";import{m as x}from"../chunks/LOODGUMW.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/YDSB7UOR.js";import"../chunks/5JG3ZRNJ.js";import"../chunks/ZLUI3EHB.js";import"../chunks/JAPVLU4Z.js";import"../chunks/OXGKALKM.js";import"../chunks/CNQZLSAP.js";import"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/JS6HTVYX.js";import"../chunks/EJ2IZUN2.js";import"../chunks/ICJV6KIZ.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import"../chunks/INVTU73D.js";import"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";import{posix as j}from"node:path";function H(y,f){if(!x(y))return[];let b=[],p=new Set,v=new Set,a=[...new Set(f.paths)],i=new Set(a),d=new Set(f.agentPromptPaths.filter(e=>i.has(e))),r=f.fragment.nodes.filter(e=>e.kind==="agent"),E=new Set(r.flatMap(e=>e.files.map(t=>t.path).filter(t=>i.has(t)))),u=new Map(r.map(e=>[e.id,f.fragment.edges.filter(t=>t.from===e.id&&t.kind==="delegates").map(t=>t.to)])),F=e=>{let t=new Set,s=[e];for(;s.length;){let n=s.pop();t.has(n)||(t.add(n),s.push(...u.get(n)??[]))}return r.filter(n=>t.has(n.id)).flatMap(n=>n.files.map(o=>o.path).filter(o=>i.has(o)))},g=Object.assign(Object.create(null),f.dependencies),P=(e,t)=>{for(let s of e)g[s]=[...new Set([...g[s]??[],...t])]},R=e=>{let t=new Map;for(let s of e)for(let n of new Set(s.files))t.set(n,(t.get(n)??0)+1);return s=>t.get(s)===1},W=r.map(e=>({files:e.files.map(t=>t.path).filter(t=>i.has(t))})),$=R(W),A=e=>[...e.files.map(t=>t.path).filter(t=>i.has(t)).filter($),...e.sourceRef&&i.has(e.sourceRef.path)?[e.sourceRef.path]:[]],C=e=>e.sourceRef&&d.has(e.sourceRef.path)?e.sourceRef.path:e.files.find(t=>d.has(t.path))?.path;for(let e of r)P(A(e),F(e.id));let M=O(f.codeAgents??[]).map(e=>({...e,files:e.files.filter(t=>i.has(t))})),J=R(M);for(let e of M)P(e.files.filter(J),e.files);let k=(e,t,s)=>{if(!t.length)return!1;let n=q(y,{...f,dependencies:g,paths:t});if(n.groups.length!==1||n.tooLarge.length||n.unavailable.length||n.missingContext?.length)return!1;let o=[...n.groups[0].files].sort(),l=d.has(s)&&o.includes(s)?s:o.find(h=>d.has(h));if(!l||a.every(h=>o.includes(h)))return!1;let c=JSON.stringify(o);return v.has(c)||(v.add(c),o.forEach(h=>p.add(h)),b.push({label:e??S(o),files:o,reason:l})),!0},m=new Set,w=e=>{if(m.has(e))return;m.add(e);let t=r.find(n=>n.id===e);if(!t)return;let s=F(e);if(s.length){let n=A(t);if(n.length){let l=S(n);s.push(...a.filter(c=>!E.has(c)&&(l==="."||c.startsWith(`${l}/`))))}let o=C(t);if(o&&k(t.label,s,o))return}for(let n of u.get(e)??[])w(n)},L=new Set([...u.values()].flat());for(let e of r.filter(t=>!L.has(t.id)))w(e.id);for(let e of r)!m.has(e.id)&&!e.files.every(t=>p.has(t.path))&&w(e.id);let N=new Set(a.flatMap(e=>{let t=[];for(let s=j.dirname(e);s!==".";s=j.dirname(s))t.push(s);return t}));for(let e of[...N].sort()){let t=a.filter(s=>s.startsWith(`${e}/`));t.some(s=>p.has(s))||k(void 0,t,t[0])}return b}export{H as planFolderAnalyses};
@@ -1 +1 @@
1
- import{b as a,c as b,d as c}from"../../chunks/W73WF226.js";import"../../chunks/6YCABS5T.js";import"../../chunks/M5YWJY7P.js";import"../../chunks/M6HYSTQD.js";import"../../chunks/4H23CSUM.js";import"../../chunks/VWRFSVLI.js";import"../../chunks/VX6LYNXV.js";import"../../chunks/MJGB25S5.js";import"../../chunks/TA2NIQAY.js";import"../../chunks/34NVU26H.js";import"../../chunks/CNQZLSAP.js";import"../../chunks/QVXARKP7.js";import"../../chunks/2M55DR2J.js";import"../../chunks/74FPPPIG.js";import"../../chunks/MKYLK6DB.js";import"../../chunks/5TATKWLG.js";import"../../chunks/JKWTHRUR.js";import"../../chunks/3GUKUEEJ.js";import"../../chunks/JAPVLU4Z.js";import"../../chunks/I4F56VMG.js";import"../../chunks/33EUZF25.js";import"../../chunks/YUY436SM.js";import"../../chunks/C6X5GDG4.js";import"../../chunks/724WZMYW.js";import"../../chunks/YWL52FVW.js";import"../../chunks/SJESFYBA.js";import"../../chunks/RUVMFAST.js";import"../../chunks/S27VIQMZ.js";import"../../chunks/INVTU73D.js";import"../../chunks/A7WJJMRY.js";import"../../chunks/Q5WR6B2H.js";import"../../chunks/VDUFPTDD.js";export{b as fileEvidenceBytes,a as fileSearchBudget,c as fullFilePasses};
1
+ import{b as a,c as b,d as c}from"../../chunks/QY57UR6E.js";import"../../chunks/6YCABS5T.js";import"../../chunks/GZSUTDGX.js";import"../../chunks/M6HYSTQD.js";import"../../chunks/4H23CSUM.js";import"../../chunks/VBGQKYIT.js";import"../../chunks/VX6LYNXV.js";import"../../chunks/P5FCHJ7W.js";import"../../chunks/I5F7S63K.js";import"../../chunks/QVXARKP7.js";import"../../chunks/QYYN4YKB.js";import"../../chunks/74FPPPIG.js";import"../../chunks/LOODGUMW.js";import"../../chunks/MKYLK6DB.js";import"../../chunks/5TATKWLG.js";import"../../chunks/YDSB7UOR.js";import"../../chunks/5JG3ZRNJ.js";import"../../chunks/ZLUI3EHB.js";import"../../chunks/JAPVLU4Z.js";import"../../chunks/OXGKALKM.js";import"../../chunks/CNQZLSAP.js";import"../../chunks/I4F56VMG.js";import"../../chunks/33EUZF25.js";import"../../chunks/YUY436SM.js";import"../../chunks/C6X5GDG4.js";import"../../chunks/724WZMYW.js";import"../../chunks/JS6HTVYX.js";import"../../chunks/EJ2IZUN2.js";import"../../chunks/ICJV6KIZ.js";import"../../chunks/RUVMFAST.js";import"../../chunks/S27VIQMZ.js";import"../../chunks/INVTU73D.js";import"../../chunks/A7WJJMRY.js";import"../../chunks/Q5WR6B2H.js";import"../../chunks/VDUFPTDD.js";export{b as fileEvidenceBytes,a as fileSearchBudget,c as fullFilePasses};
@@ -1 +1 @@
1
- import{Ba as g,Ca as h,Da as i,Ea as j,Fa as l,Ka as o,Ma as p,Na as q,Oa as r,Pa as s,Qa as t,Ra as u}from"../chunks/2M55DR2J.js";import"../chunks/74FPPPIG.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/JKWTHRUR.js";import"../chunks/3GUKUEEJ.js";import{f as b,g as c,h as d,i as e,j as f}from"../chunks/JAPVLU4Z.js";import{a}from"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/YWL52FVW.js";import"../chunks/SJESFYBA.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import{a as m,b as n}from"../chunks/INVTU73D.js";import{a as k}from"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";export{p as MAX_FINDINGS,i as attachFiles,q as cleanFindings,s as cleanFixDelta,h as cleanFragment,a as findingActivitySchema,n as findingActivitySettings,k as findingAudienceEnabled,e as findingsSchema,f as findingsSchemaFor,t as fingerprintOf,r as fixFingerprintOf,o as groupByActivity,l as groupByAudience,b as inspectFixSchema,j as mergeGraphs,g as normaliseBrand,m as notActiveEnabled,u as numberLines,c as otherSiteSchema,d as rawFindingSchema};
1
+ import{Ba as g,Ca as h,Da as i,Ea as j,Fa as l,Ka as o,Ma as p,Na as q,Oa as r,Pa as s,Qa as t,Ra as u}from"../chunks/QYYN4YKB.js";import"../chunks/74FPPPIG.js";import"../chunks/LOODGUMW.js";import"../chunks/MKYLK6DB.js";import"../chunks/5TATKWLG.js";import"../chunks/YDSB7UOR.js";import"../chunks/5JG3ZRNJ.js";import"../chunks/ZLUI3EHB.js";import{f as b,g as c,h as d,i as e,j as f}from"../chunks/JAPVLU4Z.js";import"../chunks/OXGKALKM.js";import"../chunks/CNQZLSAP.js";import{a}from"../chunks/I4F56VMG.js";import"../chunks/33EUZF25.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import"../chunks/724WZMYW.js";import"../chunks/JS6HTVYX.js";import"../chunks/EJ2IZUN2.js";import"../chunks/ICJV6KIZ.js";import"../chunks/RUVMFAST.js";import"../chunks/S27VIQMZ.js";import{a as m,b as n}from"../chunks/INVTU73D.js";import{a as k}from"../chunks/A7WJJMRY.js";import"../chunks/Q5WR6B2H.js";import"../chunks/VDUFPTDD.js";export{p as MAX_FINDINGS,i as attachFiles,q as cleanFindings,s as cleanFixDelta,h as cleanFragment,a as findingActivitySchema,n as findingActivitySettings,k as findingAudienceEnabled,e as findingsSchema,f as findingsSchemaFor,t as fingerprintOf,r as fixFingerprintOf,o as groupByActivity,l as groupByAudience,b as inspectFixSchema,j as mergeGraphs,g as normaliseBrand,m as notActiveEnabled,u as numberLines,c as otherSiteSchema,d as rawFindingSchema};
@@ -1 +1 @@
1
- import{c as i,d as n,e as c,f as l,g as a,h as u,i as f,j as h,l as d}from"./KBTM5MBC.js";import{d as s}from"./3MTXB4MK.js";import{a as S}from"./N2L4JMJE.js";import{z as y}from"zod";function Q(e){let t=d(e),m=h(e);return{...t,headlinePlan(o){let r=t.analysisRequest(o),p=m.headlineFallbackQuestion();return{inputBytes:t.callInputBytes(r),fallbackQuestion:p,identity:{system:r.system,data:r.prompt,schema:y.toJSONSchema(r.schema),fallbackQuestion:p}}},modelReaderPrompt:()=>e.bundleText("model-reader-runtime-prompt"),validateShapeInput:o=>{a(e).shapeInputs(o)},...u(e),...n(e),...i(e),...s(e),...c(e),...l(e),...a(e),...f(e),...m,...S(e)}}export{Q as a};
1
+ import{c as i,d as n,e as c,f as l,g as a,h as u,i as f,j as h,l as d}from"./OHDC3L6V.js";import{d as s}from"./3MTXB4MK.js";import{a as S}from"./2J3PWUPG.js";import{z as y}from"zod";function Q(e){let t=d(e),m=h(e);return{...t,headlinePlan(o){let r=t.analysisRequest(o),p=m.headlineFallbackQuestion();return{inputBytes:t.callInputBytes(r),fallbackQuestion:p,identity:{system:r.system,data:r.prompt,schema:y.toJSONSchema(r.schema),fallbackQuestion:p}}},modelReaderPrompt:()=>e.bundleText("model-reader-runtime-prompt"),validateShapeInput:o=>{a(e).shapeInputs(o)},...u(e),...n(e),...i(e),...s(e),...c(e),...l(e),...a(e),...f(e),...m,...S(e)}}export{Q as a};
@@ -1 +1 @@
1
- import{a as s}from"./E7TFIHC5.js";import{f as p}from"./VC3PYT2B.js";import{a}from"./INVTU73D.js";import{createHash as d}from"node:crypto";function x(e){function r(t){if(!("includes"in e)||!Object.hasOwn(e.includes,t))throw new Error(`Unknown template: ${t}`);return e.includes[t]}function m(t){return"templateText"in e?Buffer.byteLength(e.templateText(t)):r(t).expandedSize}function i(t,n={}){return{name:t,hash:"templateText"in e?d("sha256").update(s(e.templateText(t),{promptAgreement:p(n),notActiveGroup:a(n)})).digest("hex"):r(t).expandedFingerprint}}function f(t,n={}){for(let o of t)if(i(o.name,n).hash!==o.hash)throw new Error("Counterfact's instructions changed since this analysis started. Start a new analysis.")}return{templateBytes:m,promptVersion:i,assertPromptVersions:f}}export{x as a};
1
+ import{a as s}from"./E7TFIHC5.js";import{j as p}from"./LOODGUMW.js";import{a}from"./INVTU73D.js";import{createHash as d}from"node:crypto";function x(e){function r(t){if(!("includes"in e)||!Object.hasOwn(e.includes,t))throw new Error(`Unknown template: ${t}`);return e.includes[t]}function m(t){return"templateText"in e?Buffer.byteLength(e.templateText(t)):r(t).expandedSize}function i(t,n={}){return{name:t,hash:"templateText"in e?d("sha256").update(s(e.templateText(t),{promptAgreement:p(n),notActiveGroup:a(n)})).digest("hex"):r(t).expandedFingerprint}}function f(t,n={}){for(let o of t)if(i(o.name,n).hash!==o.hash)throw new Error("Counterfact's instructions changed since this analysis started. Start a new analysis.")}return{templateBytes:m,promptVersion:i,assertPromptVersions:f}}export{x as a};
@@ -1 +1 @@
1
- var l="This folder has more than one analysis can read. Choose a smaller folder, such as one agent's folder.",s=class extends Error{code;retryable;constructor(n,t,a){super(t),this.code=n,this.name="JobError",this.retryable=a?.retryable??!1}};function o(e){if(e instanceof s&&["org_spend_limit","lease_lost","cancelled","canceled","replay_miss"].includes(e.code)||e instanceof Error&&e.name==="AbortError"||e&&typeof e=="object"&&"kind"in e&&["spending_stop","lease_lost","cancelled"].includes(String(e.kind)))throw e}export{l as a,s as b,o as c};
1
+ var l="This folder has more than one analysis can read. Choose a smaller folder, such as one agent's folder.",s=class extends Error{code;retryable;constructor(t,n,a){super(n),this.code=t,this.name="JobError",this.retryable=a?.retryable??!1}};function c(e){if(e instanceof s&&["org_spend_limit","lease_lost","cancelled","canceled","replay_miss"].includes(e.code)||e instanceof Error&&e.name==="AbortError"||e&&typeof e=="object"&&"kind"in e&&["spending_stop","lease_lost","cancelled"].includes(String(e.kind)))throw e}export{l as a,s as b,c};
@@ -1,3 +1,3 @@
1
- import{a as _,b as de,k as mt}from"./SP6XFHNH.js";import{b as ae}from"./HCPO6QPU.js";import{a as Be,g as Ne}from"./VC3PYT2B.js";import{C as ht,a as Pe,c as it,d as at,l as lt,m as ct,n as Oe,o as ft,u as pt,v as dt,w as ut,z as ge}from"./P253B344.js";import{Fb as B,K as Ye,W as We,Y as qe,ea as He,f as ze,fa as ve,g as je,ga as me,h as oe,ha as be,i as ke,ia as Ze,ja as Qe,l as ce,m as $e,n as Je,ob as rt,pa as et,qa as tt,ra as ot,t as fe,u as Ke,wa as nt,x as Ge,y as Ve}from"./2M55DR2J.js";import{a as C}from"./MKYLK6DB.js";import{e as st}from"./YUY436SM.js";import{a as De,c as G}from"./C6X5GDG4.js";import{a as le,b as H,c as Z,k as Te,p as _e}from"./YWL52FVW.js";import{a as X,c as pe}from"./SJESFYBA.js";import{e as Xe}from"./RUVMFAST.js";import{a as Ue}from"./S27VIQMZ.js";function Me(t){let e;try{e=JSON.parse(t)}catch{return{config:null,invalid:!0}}if(typeof e!="object"||e===null||Array.isArray(e))return{config:null,invalid:!0};let o=e,n={};for(let r of["name","model","description","prompt"]){let i=ye(o[r]);i&&(n[r]=i)}if(Array.isArray(o.agents)){let r=o.agents.flatMap(i=>{let c=Dt(i);return c?[c]:[]});r.length>0?n.agents=r:n.invalidAgents=!0}return{config:n,invalid:!1}}function gt(t){let{config:e}=Me(t);return e?Ee(e):"bare"}function Ee(t){return t.agents?.length?"agents":t.prompt?"prompt":"bare"}function yt(t){let e=Ee(t);return e==="agents"?t.agents:e==="prompt"?[{name:t.name,model:t.model,prompt:t.prompt}]:[]}function wt(t,e,o){return St(t,e,o).paths}function St(t,e,o,n={}){let r=yt(e).map(l=>l.prompt),i=[],c=[];for(let l of r){let f=Fe(l).path,y=Ie(o,f);if(y===null){c.push({path:f,reason:"out-of-scope"});continue}let k=B(t,{path:y},{purpose:"pointer",route:"github",...n});k.admitted?i.push(y):c.push({path:y,reason:k.reason})}return{paths:i,refused:c}}function _t(t,e,o){let n=Ie(o.markerDir,Fe(e).path),r=n!==null?B(t,{path:n},{purpose:"pointer",route:"github"}):null;if(r&&!r.admitted&&r.reason==="secret")return{kind:"secret",path:n};let i=$t(e,o,tt(t));return i?{kind:"resolved",prompt:i}:{kind:"missed"}}function lo(t,e,o){let n=[],r=[];e.invalidAgents&&r.push(`${o.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let i=Ee(e);for(let c of yt(e)){let l=_t(t,c.prompt,o);if(l.kind==="secret"){r.push(st(l.path));continue}if(l.kind==="missed"){r.push(`${o.repoKey}: counterfact.json points at ${c.prompt}, which was not found; ignored`);continue}n.push({name:c.name??null,model:c.model??null,description:i==="prompt"?e.description??null:null,prompt:l.prompt})}return{agents:n,warnings:r,refused:St(t,e,o.markerDir).refused}}function ye(t){return typeof t=="string"&&t.trim()?t.trim():void 0}function Dt(t){if(typeof t!="object"||t===null)return null;let e=t,o=ye(e.prompt);if(!o)return null;let n={prompt:o},r=ye(e.name),i=ye(e.model);return r&&(n.name=r),i&&(n.model=i),n}function Fe(t){let e=t.replace(/\\/g,"/"),o=e.indexOf("#");if(o>=0)return{path:e.slice(0,o),symbol:e.slice(o+1),line:null};let n=/^(.*):(\d+)$/.exec(e);return n?{path:n[1],symbol:null,line:Number(n[2])}:{path:e,symbol:null,line:null}}function Ie(t,e){let o=[];for(let n of[...t.split("/"),...e.split("/")])if(n===".."){if(o.pop()===void 0)return null}else n!=="."&&n!==""&&o.push(n);return o.join("/")}function $t(t,e,o){let{path:n,symbol:r,line:i}=Fe(t),c=Ie(e.markerDir,n);if(c===null||!Object.hasOwn(e.files,c))return null;let l=e.files[c];if(l===void 0)return null;if(r===null&&i===null)return X(c)?null:We(c,l);let{sites:f}=et(c,l,{minChars:1,promptFunctions:o});return r!==null?f.find(y=>y.symbol===r)??null:Jt(f,i)}function Jt(t,e){let o=r=>Math.min(r.line,r.span.from),n=t.filter(r=>o(r)<=e&&e<=r.span.to);return n.sort((r,i)=>r.span.to-o(r)-(i.span.to-o(i))),n[0]??null}function Kt(t){return oe(t,"CF_IMPORT_SCOPED_SCAN")}function kt(t,e,o,n="bare"){let r=e.filter(y=>Je(t,y,o)),i=Kt(t);if(!i&&!r.length)return;if(!i&&(n==="agents"||n==="prompt"))return[];let c=i?lt(t,e,o).filter(y=>!y.convention&&(!y.markerPath||y.scope.key===null&&n!=="agents"&&n!=="prompt")).flatMap(y=>y.paths):vt(t,e,o,n)?e:[];if(!c.length&&!r.length)return c;let l=De(o),f=new Set([...c,...r]);for(let y of e){let k=G(y,l);k!==null&&!k.includes("/")&&qe(y)&&f.add(y)}return[...f]}function ne(t,{paths:e,root:o,scanFlag:n,marker:r}){let i={scan:!1,markerToRead:null};if(!n)return i;let c=Pe(t,e,o);if(c.configPath&&r===null)return{scan:!1,markerToRead:c.configPath};let l=kt(t,e,o,r);return l?{scan:l.length>0,markerToRead:null,scanPaths:l}:{scan:vt(t,e,o,r),markerToRead:null}}function vt(t,e,o,n){let r=Pe(t,e,o);return je({usage:"scan",codeAgentsFound:!1,otherDefinitions:it(r)},t)!=="prompt"&&!at(t,r)&&n!=="agents"&&n!=="prompt"}function So(t,e){if(e.phase==="read"){let c=gt(e.text??"");if(e.pending.scanPaths){let l=Me(e.text??"").config,f=e.pending.markerPath.split("/").slice(0,-1).join("/"),y=new Set(l?wt(t,l,f):[]),k=c==="bare"?e.pending.scanPaths:(e.pending.scanPathsIfExplicit??[]).filter(E=>!y.has(E));return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:k.length>0,scanPaths:k}}return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:e.pending.scanIfBare&&c==="bare"}}let{paths:o,root:n,scanFlag:r}=e,i=ne(t,{paths:o,root:n,scanFlag:r,marker:null});if(!r)return{kind:"off"};if(i.markerToRead){let c=ne(t,{paths:o,root:n,scanFlag:r,marker:"bare"});return{kind:"marker",markerPath:i.markerToRead,scanIfBare:c.scan,...c.scanPaths?{scanPaths:c.scanPaths,scanPathsIfExplicit:kt(t,o,n,"agents")}:{}}}return{kind:"settled",markerPath:null,markerKind:null,scan:i.scan,...i.scanPaths?{scanPaths:i.scanPaths}:{}}}var bt=(t,e)=>{let{markerToRead:o}=ne(e.settings,{paths:t.map(({path:n})=>n),root:e.dir??void 0,scanFlag:e.flags.scan,marker:null});return o?{strength:"partial",wants:[o]}:null};function Pt(t,e,o="bare"){let{scan:n}=ne(e.settings,{paths:t.map(({path:r})=>r),root:e.dir??void 0,scanFlag:e.flags.scan,marker:o});return n?{strength:"partial",wants:[]}:null}function we(t){return oe(t,"CF_IMPORT_MANIFEST")}function xe(t,e){if(!Ke(t))return null;let o=new Set(e.paths),n=Ge(t,e),r=new Set(e.skillPaths),i=new Set(e.referencePaths),c=a=>Object.hasOwn(e.files,a)?Buffer.byteLength(e.files[a]):e.sizes?.get(a),l=e.selected??[...new Set([...e.skillPaths,...Object.keys(e.files).filter(a=>fe(a,{nested:!0})?.reference)])].filter(a=>Object.hasOwn(e.files,a)).map(a=>({path:a,size:c(a)})),f=[...new Map(l.filter(a=>!i.has(a.path)||r.has(a.path)).map(a=>[a.path,a])).values()],y=new Set(f.map(a=>a.path)),k=f.filter(a=>r.has(a.path)),E=new Set(f.filter(a=>fe(a.path,{nested:!0})?.reference).map(a=>a.path)),S=k.length,x=C.conventionImport.skillBytes-f.filter(a=>r.has(a.path)||E.has(a.path)).reduce((a,m)=>a+(c(m.path)??m.size),0),A=ce(t)?C.codeAgent.importBytes-f.reduce((a,m)=>a+(c(m.path)??m.size),0):1/0,I=new Map(k.map(a=>[a.path,null])),R=(a,m=!1)=>{if(I.has(a))return;let h=c(a),M=E.has(a),u=B(t,{path:a,size:h,text:e.files[a]},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:o,managedFiles:e.files}),P=y.has(a)?0:h,F=u.admitted?h===void 0?"missing":!M&&S>=C.conventionImport.skillFiles?"allowance":!M&&(h>x||P>A)?"total":null:u.reason;I.set(a,F),!M&&(m||!F)&&S++,!M&&!F&&(x-=h,A-=P)};for(let a of i)R(a,!0);let s=[...new Set(e.skillPaths)].sort().filter(a=>Object.hasOwn(e.files,a)).map(a=>{let m={ownerPath:a,files:[],cycles:[],unresolved:[],refused:[]},h=new Set([a]);for(let M of n.references.filter(u=>u.ownerPath===a)){if(!h.has(M.fromPath))continue;R(M.path);let u=I.get(M.path);if(u){m.refused.push({path:M.path,reason:u});continue}h.add(M.path);let P=m.files.find(F=>F.path===M.path);P||(P={path:M.path,evidence:[],sharedOwners:[]},m.files.push(P)),P.evidence.push(M)}return m.cycles=n.cycles.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.unresolved=n.unresolved.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.refused=ae(m.refused),m}),p=new Map;for(let a of s)for(let m of a.files)p.set(m.path,[...p.get(m.path)??[],a.ownerPath]);for(let a of s)for(let m of a.files)m.sharedOwners=p.get(m.path);return s}var Gt=2e3;function Ot(t,e,o,n={}){let r=e.filter(u=>G(u.path,o)!=null),i={},c=[],l=new Map,f=n.mode!=="core"&&Ye(t),y=Oe(t,r.map(u=>u.path),o,{mode:f?"all":"core",files:n.files}),k=new Set([...y.ignoredPaths,...y.ignoredImportPaths]),E=new Map(y.files.filter(u=>u.role!=="reference").map(u=>[u.path,u])),S=new Map(y.scopes.map(u=>[u.key,C.conventionImport.totalBytes])),x=C.conventionImport.skillBytes,A=ce(t)?C.codeAgent.importBytes:1/0,I=0,R=u=>G(u.path,y.ownerOf(u.path).folder)??u.path,s=(u,P)=>{l.set(u.path,{path:u.path,reason:P})},p=(u,P)=>{let F=B(t,u,{purpose:P,route:"github",root:o});return F.admitted?!0:(s(u,F.reason),!1)},a=u=>{if(i[u.path])return;let P=f&&E.get(u.path)?.role==="skill"?"skill":"core",F=y.ownerOf(u.path),N=P==="skill"?x:S.get(F.key),j=u.size??0;if(P==="skill"&&I>=C.conventionImport.skillFiles){s(u,"allowance");return}if(j>N||j>A){s(u,"total");return}i[u.path]=u.ref,c.push(u.path),A-=j,P==="skill"?(x-=j,I++):S.set(F.key,N-j)},m=r.filter(u=>E.has(u.path));for(let u of m)p(u,rt(E.get(u.path).role))&&a(u);let h=0;if(we(t))for(let u of me(new Set(r.map(P=>P.path)))){let P=r.find(F=>F.path===u);if(h>=C.conventionImport.extractionFiles){s(P,"allowance");continue}if(p(P,"source")&&p(P,"definition")){let F=c.length;a(P),c.length>F&&h++}}let M=y.needsExtraction;if(M){let u=r.flatMap(F=>{if(k.has(F.path)||i[F.path]||f&&fe(R(F)))return[];if(!p(F,"extraction"))return[];let N=Ve(R(F));return N===null?[]:[{entry:F,rank:N}]}).sort((F,N)=>F.rank-N.rank||(F.entry.size??0)-(N.entry.size??0)),P=h;for(let{entry:F}of u){if(P>=C.conventionImport.extractionFiles){s(F,"allowance");continue}let N=c.length;a(F),c.length>N&&P++}}if(f&&n.files){let u=Vt(t,{entries:e,selected:r.filter(P=>Object.hasOwn(i,P.path)),files:n.files,root:o});for(let P of u.paths)Object.hasOwn(i,P)||(c.push(P),i[P]=r.find(F=>F.path===P).ref);for(let P of u.refused)l.set(P.path,P)}return{...ce(t)&&m.some(u=>!Object.hasOwn(i,u.path))?{definitionsOmitted:!0}:{},selectedPaths:c,shaByPath:i,treeListing:r.slice(0,Gt).map(u=>u.path),needsExtraction:M,refused:[...l.values()]}}function Vt(t,e){let o=new Set(e.selected.map(i=>i.path)),n=Oe(t,e.entries.map(i=>i.path),e.root,{files:e.files}).files.filter(i=>i.role==="skill"&&o.has(i.path)).map(i=>i.path),r=xe(t,{skillPaths:n,paths:e.entries.map(i=>i.path),files:e.files,sizes:new Map(e.entries.map(i=>[i.path,i.size])),selected:e.selected,root:e.root,admission:e.admission,referencePaths:e.referencePaths});return{paths:[...new Set(r?.flatMap(i=>i.files.map(c=>c.path))??[])],refused:r?.flatMap(i=>i.refused)??[]}}var Mt=(t,e)=>{let o=Ot(e.settings,t,e.dir??void 0,{mode:e.mode});return{strength:"partial",wants:o.selectedPaths,state:{needsExtraction:o.needsExtraction,treeListing:o.treeListing,shaByPath:o.shaByPath,refused:o.refused,...o.definitionsOmitted?{definitionsOmitted:!0}:{}}}};var Et=["marker","code-scan","conventions"];var Yt={marker:bt,"code-scan":Pt,conventions:Mt};function Ae(t,e,o,n,r=Yt){let i={...o,settings:t},c={readers:[]};for(let l of Et)if(!(n&&!n.includes(l)))try{let f=r[l]?.(e,i);f&&c.readers.push({id:l,claim:f,done:!1})}catch{}return c}function Xo(t){return{readers:t.readers.map(({id:e,done:o})=>({id:e,done:o}))}}function Ft(t){let e=t.readers.find(({id:o})=>o==="conventions").claim;return{selectedPaths:e.wants,...e.state}}var Wt={files:200,bytes:C.codeAgent.importBytes,depth:32,edges:_.edges,entries:pe.inventoryEntries};function It(t={}){return Object.fromEntries(Object.entries(Wt).map(([e,o])=>{let n=t[e]??o;return[e,Number.isFinite(n)?Math.max(0,Math.min(o,Math.floor(n))):0]}))}function xt(t,e,o,n){let r=new Set(o.map(s=>G(s.path,n))),i=t.CF_READING_NOTE_AGENT_ONLY!=="0"&&ft(t),c=new Set(e.agents),l=s=>!r.has(s)&&(!i||c.has(s)),f=e.instruction.filter(l),y=e.code.filter(l),k=e.agents.filter(s=>!r.has(s)),E=new Set(dt(k)),S=[...f,...y].every(s=>E.has(s)),x=f.length,A=y.length,I=[!S&&x>0&&`${x} instruction file${x===1?"":"s"} left out by the ${Math.round(C.sourceFetch.instructionBytes/1e3)}KB instruction budget`,!S&&A>0&&`${A} analyzable file${A===1?"":"s"} left out by the ${Math.round(C.sourceFetch.codeBytes/1e3)}KB/${C.sourceFetch.codeFiles}-file code budget \u2014 the analysis reads the most agent-shaped files first`,ut(k,i)].filter(Boolean),R=o.filter(s=>s.readBytes!==void 0).map(s=>G(s.path,n));return R.length&&I.push(`${R.join(", ")}: only the first ${C.sourceFetch.codeFileBytes/1e3} KB was read`),I.length?I.map((s,p)=>p<I.length-1?String(s).replace(/\.$/,""):s).join("; "):void 0}function At(t,e,o,n={}){let{descriptions:r,priority:i,declarations:c}=ht(t,e,{root:o},n),l=[],f=r.flatMap(a=>a.admission.admitted?[{entry:a.readEntry,rel:a.rel,score:a.score,size:a.readEntry.size,pool:a.pool,...a.tier===void 0?{}:{tier:a.tier}}]:(l.push({path:a.entry.path,reason:a.admission.reason}),[])),y=f.filter(({score:a})=>a===0).sort(ge),k=f.filter(({score:a})=>a>0).sort(ge),E=[],S={instruction:0,code:0},x={instruction:[],code:[]},A=0,I=(i.enabled?[...f].sort(ge):[...y,...k]).sort((a,m)=>Number(c.has(m.entry.path))-Number(c.has(a.entry.path)));for(let{entry:a,rel:m,pool:h}of I){let M=h==="instruction"?C.sourceFetch.instructionBytes:C.sourceFetch.codeBytes;if(S[h]+a.size>M||h==="code"&&A>=C.sourceFetch.codeFiles){x[h].push(m),l.push({path:a.path,reason:S[h]+a.size>M?"total":"allowance"});continue}E.push(a),S[h]+=a.size,h==="code"&&(A+=1)}let R=pt(i,l.flatMap(a=>{let m=G(a.path,o);return m===null?[]:[{...a,path:m}]})),s={...x,agents:R},p=xt(t,s,E,o);return{selected:E,totalBytes:S.instruction+S.code,refused:l,...p?{skippedNote:p}:{},...i.enabled&&p?{readingNotes:s}:{}}}function Re(t){let e=t.CF_CODE_AGENTS!=="0";return{scan:e,model:e&&t.CF_CODE_AGENTS_MODEL!=="0"}}function Rt(t,e){if(e.profile==="entry-analysis"){let l=It(e.limits),f=e.listing.find(k=>k.path===e.selection.entry),y=[...f?[f]:[],...e.listing.filter(k=>k.path!==e.selection.entry)].slice(0,l.entries);return{profile:e.profile,request:e.selection,entries:y,limits:l,inventoryIncomplete:e.listing.length-y.length}}let o=$e(t),n=o.length?{scopeSelections:o}:{},r={dir:e.root??null,mode:e.profile==="hosted-import"?e.mode??"all":"all",flags:e.profile==="hosted-import"?e.flags??Re(t):Re(t)};if(e.profile==="hosted-import"){let l=Ae(t,e.listing,r);return{profile:e.profile,...l,...n,selection:Ft(l),...ke(t)?{mode:r.mode}:{}}}let i=e.listing.filter(l=>B(t,l,{purpose:"pointer",route:"github",root:e.root}).admitted),c=Ae(t,i,r,["marker","code-scan"]);return{profile:e.profile,...c,...n,listing:i,selection:e.selection??At(t,e.listing,e.root),context:r,...e.selection&&ke(t)?{selectionPaths:e.selection.selected.map(l=>l.path)}:{}}}import{createHash as qt}from"node:crypto";var Q=t=>qt("sha256").update(t).digest("hex");function Cn(t,e){let o=s=>({kind:"refused",reason:s,pending:[]}),n=t.entries,r=new Map;for(let s of e)for(let p of s.files){let a=r.get(p.path);if(a&&(a.hash!==p.hash||a.size!==p.size))return o("stale-snapshot");r.set(p.path,{...p,role:n.includes(p.path)?"entry":"imported-helper"})}let i=[...r.values()],c=Q(JSON.stringify([n,e.map(s=>s.snapshot)])),l=[],f=new Set,y=(s,p,a=!1)=>{p=[...new Set(p)];let m=JSON.stringify([...p].sort());f.has(m)||p.length===i.length&&n.every(h=>r.has(h))||p.filter(h=>n.includes(h)).length>de||p.length>_.scopeImports+1||l.length>=_.choices||(f.add(m),l.push({id:Q(m),scope:{snapshot:c,entry:s,entries:n,imports:p.length===1?"none":p.filter(h=>h!==s)},includes:p,omitted:i.filter(h=>!p.includes(h.path)).map(h=>h.path),...a&&p.length>1?{coverage:"entry-imports"}:{}}))};for(let s=0;s<e.length;s+=de){let p=e.slice(s,s+de);y(p[0].kind==="file"?p[0].entry:n[s],p.flatMap(a=>a.files.map(m=>m.path)),!0)}for(let s of n.filter(p=>r.has(p)))y(s,[s]);for(let s of e)y(s.kind==="file"?s.entry:n[0],s.files.map(p=>p.path),!0);for(let s of e)for(let p of s.choices)y(p.scope.entry,p.includes);let k=s=>[...new Map(s.map(p=>[JSON.stringify(p),p])).values()],E=k(e.flatMap(s=>s.refusedEdges)),S=k(e.flatMap(s=>s.edges)),x=E.slice(0,_.edges),I=n.length-e.length+E.length-x.length+Math.max(0,S.length-_.edges)+e.reduce((s,p)=>s+p.completeness.frontierCount,0),R={schemaVersion:1,kind:"file",launchRoot:t.launchRoot,entry:t.entry,entries:n,snapshot:c,resolverVersion:e[0].resolverVersion,files:i,entrySets:e.map(s=>({entry:s.kind==="file"?s.entry:n[0],includes:s.files.map(p=>p.path)})),edges:S.slice(0,_.edges),refusedEdges:x,completeness:{complete:I===0&&e.every(s=>s.completeness.complete),frontierCount:I},choices:l};if(t.scope){if(t.scope.snapshot!==c)return o("stale-snapshot");let s=t.scope,p=Xt(R,s);return p?{kind:"ready",pending:[],selection:{...R,entrySets:void 0,...Ct(R,p.includes),choices:[]}}:o("invalid-scope")}return{kind:"ready",pending:[],selection:mt.parse(R)}}function Ut(t,e){if(t.kind!=="file"||!t.entries||!t.entrySets||!e.length)return;let o=e.map(c=>t.entrySets.find(l=>l.entry===c));if(o.some(c=>!c))return;let n=new Set(o.flatMap(c=>c.includes)),r=t.files.filter(c=>n.has(c.path)).map(c=>c.path);if(t.entries.filter(c=>n.has(c)).length>de||r.length>_.scopeImports+1)return;let i=e[0];return{id:Q(JSON.stringify([...r].sort())),scope:{snapshot:t.snapshot,entry:i,entries:t.entries,imports:r.length===1?"none":r.filter(c=>c!==i)},includes:r,omitted:t.files.filter(c=>!n.has(c.path)).map(c=>c.path),...r.length>1?{coverage:"entry-imports"}:{}}}function Xt(t,e){let o=f=>JSON.stringify([f.snapshot,f.entry,f.imports==="none"?[]:Array.isArray(f.imports)?[...f.imports].sort():f.imports,f.entries]),n=t.choices.find(f=>o(f.scope)===o(e));if(n)return n;if(t.kind!=="file"||!t.entries||e.imports==="all")return;let r=new Set([e.entry,...e.imports==="none"?[]:e.imports]),i=t.entrySets?.filter(f=>f.includes.every(y=>r.has(y))).map(f=>f.entry)??[];if(!i.includes(e.entry))return;let c=[e.entry,...i.filter(f=>f!==e.entry)],l=Ut(t,c);return l&&o(l.scope)===o(e)?l:void 0}function Ct(t,e,o=!0){let n=new Set(e),r=new Set(t.files.map(f=>f.path)),i=t.edges.filter(f=>n.has(f.from)&&!n.has(f.path)&&r.has(f.path)).map(f=>({from:f.from,specifier:f.specifier,status:"refused",provenance:f.provenance,reason:"not-selected"})),c=o?[...new Map([...t.refusedEdges.filter(f=>n.has(f.from)),...i].map(f=>[JSON.stringify(f),f])).values()]:[...t.refusedEdges,...i].slice(0,_.edges).filter(f=>n.has(f.from)),l=t.completeness.frontierCount+(o?Math.max(0,c.length-_.edges):0);return{files:t.files.filter(f=>n.has(f.path)),edges:t.edges.filter(f=>n.has(f.from)&&n.has(f.path)),refusedEdges:c.slice(0,_.edges),completeness:{complete:l===0&&c.every(f=>f.reason==="external"),frontierCount:l}}}function Ht(t,e){let o=new Set(e.map(r=>r.path)),n=new Set(e.filter(r=>r.role==="entry").map(r=>r.path));return!t?.files.some(r=>!o.has(r.path)||r.role==="prompt"&&!n.has(r.path))}function Zt(t){return t.unavailable?t.unavailable:t.entry?!Number.isSafeInteger(t.entry.size)||t.entry.size<0?"over-limit":Ue.safeParse(t.path).success?t.depth>t.limits.depth||!t.spentPaths.has(t.path)&&(t.spentPaths.size>=t.limits.files||t.bytes+t.size>t.limits.bytes)?"over-limit":null:"out-of-scope":"missing"}function Lt(t,e){let o=b=>({kind:"refused",reason:b,pending:[]});if(!Be(t))return o("disabled");let{request:n,files:r,resolutions:i,unavailable:c={}}=e,l=Rt(t,{profile:"entry-analysis",listing:[...e.entries],selection:n,limits:e.limits}),{limits:f}=l,y=new Map(l.entries.map(b=>[b.path,b])),k={},E=[],S=[],x=[],A=[],I=new Set,R=new Set,s=[{path:n.entry,depth:0,settings:!1},...(e.settingsFiles??[]).map(b=>({path:b,depth:0,settings:!0}))],p=new Set,a=new Map,m=new Map,h=new Set(e.attempted?.paths),M=new Set(e.settingsAttempted?.paths),u={files:pe.settingsFiles,bytes:pe.settingsBytes,depth:f.depth},P=e.settingsAttempted?.bytes??0,F=e.attempted?.bytes??0,N=0,j=e.inventoryIncomplete??0;j+=l.inventoryIncomplete;let J=(b,v)=>{A.length<_.edges&&A.push({from:b.from,specifier:b.specifier,status:"refused",provenance:b.provenance,reason:v})};for(let b=0;b<s.length;b++){let v=s[b],T=`${v.settings}:${v.path}`;if(p.has(T))continue;p.add(T);let D=y.get(v.path),$=Object.hasOwn(r,v.path)?r[v.path]:void 0,te=$===void 0?D?.size??0:Buffer.byteLength($),ie=v.settings?M:h,z=Zt({...v,entry:D,size:te,unavailable:Object.hasOwn(c,v.path)?c[v.path]:void 0,spentPaths:ie,bytes:v.settings?P:F,limits:v.settings?u:f});if(z){if(v.path===n.entry&&!v.settings)return o(z);if(v.settings&&Object.defineProperty(k,v.path,{value:z,enumerable:!0}),!v.settings){m.set(v.path,z);for(let g of a.get(v.path)??[])J(g,z);z==="over-limit"&&j++}continue}if(ie.has(v.path)||(v.settings?P+=te:F+=te,ie.add(v.path)),$===void 0){S.push(v.path),(v.settings?I:R).add(v.path);continue}if(v.settings)continue;if(E.push(v.path),!Object.hasOwn(i,v.path)){S.push(v.path);continue}let q=i[v.path];for(let g=0;g<q.length;g++){let O=q[g];if(N++>=f.edges){J(O,"over-limit"),j+=q.length-g;break}if(!Xe.safeParse(O).success||O.from!==v.path){J({from:v.path,specifier:"?",status:"refused",provenance:null,reason:"unsupported"},"unsupported");continue}if(O.status==="refused"){J(O,O.reason);continue}x.push(O),a.set(O.path,[...a.get(O.path)??[],O]);let L=m.get(O.path);if(L){J(O,L);continue}s.push({path:O.path,depth:v.depth+1,settings:!1})}}if(S.length)return{kind:"pending",pending:[...new Set(S)],pendingSettings:[...I].filter(b=>!R.has(b)),...Object.keys(k).length?{unavailable:k}:{}};let se=E.map(b=>({path:b,role:b===n.entry?"entry":"imported-helper",hash:Q(r[b]),size:Buffer.byteLength(r[b])})),ee=Q(JSON.stringify({request:{...n,scope:void 0},files:se,inventory:[...y.values()].map(({path:b,size:v,ref:T})=>({path:b,size:v,ref:T})).sort((b,v)=>b.path.localeCompare(v.path)),metadata:(e.settingsFiles??[]).map(b=>[b,Object.hasOwn(r,b)?Q(r[b]):c[b]??"over-limit"]),edges:x,refusedEdges:A,frontierCount:j,limits:f,resolverVersion:e.resolverVersion,resolverIdentity:e.resolverIdentity,targetIdentity:e.targetIdentity,settings:Object.entries(Ne(t)).sort(([b],[v])=>b.localeCompare(v))})),w=n.scope;if(w&&w.snapshot!==ee)return o("stale-snapshot");let d=E.filter(b=>b!==n.entry);if(w&&(w.entry!==n.entry||Array.isArray(w.imports)&&w.imports.some(b=>!d.includes(b))))return o("invalid-scope");let V=new Set(!w||w.imports==="all"?E:[n.entry,...w.imports==="none"?[]:w.imports]),Y=Ct({files:se,edges:x,refusedEdges:A,completeness:{complete:!1,frontierCount:j}},[...V],!1),U=Y.files;if(!Ht(e.proposal,U))return o("invalid-scope");let re=[],ue=(b,v)=>{let T=[n.entry,...v==="none"?[]:v];T.length!==U.length&&re.push({id:b,scope:{snapshot:ee,entry:n.entry,imports:v},includes:T,omitted:U.filter(D=>!T.includes(D.path)).map(D=>D.path)})};ue("entry-only","none");for(let b of U.filter(v=>v.role==="imported-helper").slice(0,_.choices-1))ue(Q(b.path),[b.path]);let he={schemaVersion:1,kind:"file",launchRoot:n.launchRoot,entry:n.entry,snapshot:ee,resolverVersion:e.resolverVersion,...Y,choices:re};return{kind:"ready",pending:[],selection:he}}function Nn({prompt:t,link:e}){return{path:e?.callPath??t.path,...e?{line:e.callLine}:{},symbol:t.symbol,promptPath:t.path,promptStart:t.start,...e?.kind==="L4"?{loadedPrompt:!0,...e.callStart!==void 0?{callStart:e.callStart}:{}}:{}}}function Bt(t,e,o){return nt(t,e,o)}var Se=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function Qt(t,e,o,n={}){let r=new Map(t.map(i=>[Se(i),i]));return e.flatMap(i=>{let c=Object.hasOwn(o,i)?o[i]:void 0;if(c===void 0||!B(n,{path:i},{purpose:"code-support",route:"github"}).admitted)return[];let l=le(i,c,X(i)).toks;return l.flatMap((f,y)=>{if(!Z(f))return[];let k=r.get(Se(f.text));if(!k)return[];let E=!1;if(Z(l[y-1],"function")||Z(l[y-1],"def"))E=H(l[y+1],"(");else if(["const","let","var"].some(S=>Z(l[y-1],S))){for(let S=y+1;S<l.length&&S<y+80&&!H(l[S],";");S++)if(H(l[S],"=")){let x=Z(l[S+1],"async")?S+2:S+1,A=H(l[x],"(")?Te(l,x)+1:x+1;E=Z(l[x],"function")||H(l[A],"=")&&H(l[A+1],">");break}}return E?[{name:k,sourcePath:i,sourceLine:f.line}]:[]})})}function Nt(t,e,o,n,r={}){let i=new Set(t.map(Se)),c=k=>B(r,{path:k},{purpose:"code-support",route:"github"}).admitted,l=k=>Qt(t,[k],o,r).length>0,f=e.filter(k=>c(k)&&l(k)),y=n.filter(k=>c(k)&&i.has(Se(k.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(o[k]===void 0||l(k))).sort();return[...new Set([...f,...y])]}var jt="model call";function zt(t,e){let o=Bt(t.ownPaths,e,t.toolCall);return{tools:o.tools.map(n=>({tool:n,from:o.from[n.name]})),toolWarnings:o.warnings}}function Le(t=new Map,e){return{left:Math.max(0,C.codeAgent.importBytes-[...t.values()].reduce((o,n)=>o+n,0)),chosen:new Set([...t.keys()].filter(o=>!e?.has(o))),...e?{replacementBytes:e}:{}}}function eo(t,e){return t.modelId??(!t.documentation&&e.length===1?e[0]:null)}function ns(t,e,o){return to(t,eo(t,e),o)}function to(t,e,o){let{prompt:n,link:r}=t,i=[n.kind==="file"?{role:"system prompt",label:null,path:n.path}:{role:"system prompt",label:n.symbol??`line ${n.span.from}`,path:n.path,span:{from:n.span.from,to:n.span.to},...n.filledAtRunTime?{filledAtRunTime:!0}:{}}];for(let l of t.alsoLoads??[])i.push({role:"system prompt",label:"also loaded",path:l});r&&i.push({role:"code",label:jt,path:r.callPath}),r?.wrapper&&i.push({role:"code",label:"model wrapper",path:r.wrapper.path}),e&&i.push({role:"code",label:"model setting",path:e.path}),t.shape&&i.push({role:"code",label:"answer shape",path:t.shape.path});let c=new Set;return i.filter(l=>!c.has(l.path)&&!!c.add(l.path)).map(l=>ze(o,l.path,l.path===n.path&&t.promptSource==="marker")?l:{...l,role:"reference"})}function ss(t,e){let{prompt:o}=t,n=e[o.path]??"";return o.kind==="file"?n:n.split(`
1
+ import{a as _,b as de,k as mt}from"./SP6XFHNH.js";import{b as ae}from"./PISOGSJF.js";import{C as ht,a as Pe,c as it,d as at,l as lt,m as ct,n as Oe,o as ft,u as pt,v as dt,w as ut,z as ge}from"./AIS3FHQR.js";import{Fb as B,K as Ye,W as We,Y as qe,f as ze,fa as He,g as je,ga as ve,h as oe,ha as me,i as ke,ia as be,ja as Ze,ka as Qe,l as ce,m as $e,n as Je,ob as rt,pa as et,qa as tt,ra as ot,t as fe,u as Ke,wa as nt,x as Ge,y as Ve}from"./QYYN4YKB.js";import{c as Be,k as Ne}from"./LOODGUMW.js";import{a as C}from"./MKYLK6DB.js";import{e as st}from"./YUY436SM.js";import{a as De,c as G}from"./C6X5GDG4.js";import{a as le,b as H,c as Z,k as Te,p as _e}from"./EJ2IZUN2.js";import{b as X,d as pe}from"./ICJV6KIZ.js";import{e as Xe}from"./RUVMFAST.js";import{a as Ue}from"./S27VIQMZ.js";function Me(t){let e;try{e=JSON.parse(t)}catch{return{config:null,invalid:!0}}if(typeof e!="object"||e===null||Array.isArray(e))return{config:null,invalid:!0};let o=e,n={};for(let r of["name","model","description","prompt"]){let i=ye(o[r]);i&&(n[r]=i)}if(Array.isArray(o.agents)){let r=o.agents.flatMap(i=>{let c=Dt(i);return c?[c]:[]});r.length>0?n.agents=r:n.invalidAgents=!0}return{config:n,invalid:!1}}function gt(t){let{config:e}=Me(t);return e?Ee(e):"bare"}function Ee(t){return t.agents?.length?"agents":t.prompt?"prompt":"bare"}function yt(t){let e=Ee(t);return e==="agents"?t.agents:e==="prompt"?[{name:t.name,model:t.model,prompt:t.prompt}]:[]}function wt(t,e,o){return St(t,e,o).paths}function St(t,e,o,n={}){let r=yt(e).map(l=>l.prompt),i=[],c=[];for(let l of r){let f=Fe(l).path,y=Ie(o,f);if(y===null){c.push({path:f,reason:"out-of-scope"});continue}let k=B(t,{path:y},{purpose:"pointer",route:"github",...n});k.admitted?i.push(y):c.push({path:y,reason:k.reason})}return{paths:i,refused:c}}function _t(t,e,o){let n=Ie(o.markerDir,Fe(e).path),r=n!==null?B(t,{path:n},{purpose:"pointer",route:"github"}):null;if(r&&!r.admitted&&r.reason==="secret")return{kind:"secret",path:n};let i=$t(e,o,tt(t));return i?{kind:"resolved",prompt:i}:{kind:"missed"}}function lo(t,e,o){let n=[],r=[];e.invalidAgents&&r.push(`${o.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let i=Ee(e);for(let c of yt(e)){let l=_t(t,c.prompt,o);if(l.kind==="secret"){r.push(st(l.path));continue}if(l.kind==="missed"){r.push(`${o.repoKey}: counterfact.json points at ${c.prompt}, which was not found; ignored`);continue}n.push({name:c.name??null,model:c.model??null,description:i==="prompt"?e.description??null:null,prompt:l.prompt})}return{agents:n,warnings:r,refused:St(t,e,o.markerDir).refused}}function ye(t){return typeof t=="string"&&t.trim()?t.trim():void 0}function Dt(t){if(typeof t!="object"||t===null)return null;let e=t,o=ye(e.prompt);if(!o)return null;let n={prompt:o},r=ye(e.name),i=ye(e.model);return r&&(n.name=r),i&&(n.model=i),n}function Fe(t){let e=t.replace(/\\/g,"/"),o=e.indexOf("#");if(o>=0)return{path:e.slice(0,o),symbol:e.slice(o+1),line:null};let n=/^(.*):(\d+)$/.exec(e);return n?{path:n[1],symbol:null,line:Number(n[2])}:{path:e,symbol:null,line:null}}function Ie(t,e){let o=[];for(let n of[...t.split("/"),...e.split("/")])if(n===".."){if(o.pop()===void 0)return null}else n!=="."&&n!==""&&o.push(n);return o.join("/")}function $t(t,e,o){let{path:n,symbol:r,line:i}=Fe(t),c=Ie(e.markerDir,n);if(c===null||!Object.hasOwn(e.files,c))return null;let l=e.files[c];if(l===void 0)return null;if(r===null&&i===null)return X(c)?null:We(c,l);let{sites:f}=et(c,l,{minChars:1,promptFunctions:o});return r!==null?f.find(y=>y.symbol===r)??null:Jt(f,i)}function Jt(t,e){let o=r=>Math.min(r.line,r.span.from),n=t.filter(r=>o(r)<=e&&e<=r.span.to);return n.sort((r,i)=>r.span.to-o(r)-(i.span.to-o(i))),n[0]??null}function Kt(t){return oe(t,"CF_IMPORT_SCOPED_SCAN")}function kt(t,e,o,n="bare"){let r=e.filter(y=>Je(t,y,o)),i=Kt(t);if(!i&&!r.length)return;if(!i&&(n==="agents"||n==="prompt"))return[];let c=i?lt(t,e,o).filter(y=>!y.convention&&(!y.markerPath||y.scope.key===null&&n!=="agents"&&n!=="prompt")).flatMap(y=>y.paths):vt(t,e,o,n)?e:[];if(!c.length&&!r.length)return c;let l=De(o),f=new Set([...c,...r]);for(let y of e){let k=G(y,l);k!==null&&!k.includes("/")&&qe(y)&&f.add(y)}return[...f]}function ne(t,{paths:e,root:o,scanFlag:n,marker:r}){let i={scan:!1,markerToRead:null};if(!n)return i;let c=Pe(t,e,o);if(c.configPath&&r===null)return{scan:!1,markerToRead:c.configPath};let l=kt(t,e,o,r);return l?{scan:l.length>0,markerToRead:null,scanPaths:l}:{scan:vt(t,e,o,r),markerToRead:null}}function vt(t,e,o,n){let r=Pe(t,e,o);return je({usage:"scan",codeAgentsFound:!1,otherDefinitions:it(r)},t)!=="prompt"&&!at(t,r)&&n!=="agents"&&n!=="prompt"}function So(t,e){if(e.phase==="read"){let c=gt(e.text??"");if(e.pending.scanPaths){let l=Me(e.text??"").config,f=e.pending.markerPath.split("/").slice(0,-1).join("/"),y=new Set(l?wt(t,l,f):[]),k=c==="bare"?e.pending.scanPaths:(e.pending.scanPathsIfExplicit??[]).filter(E=>!y.has(E));return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:k.length>0,scanPaths:k}}return{kind:"settled",markerPath:e.pending.markerPath,markerKind:c,scan:e.pending.scanIfBare&&c==="bare"}}let{paths:o,root:n,scanFlag:r}=e,i=ne(t,{paths:o,root:n,scanFlag:r,marker:null});if(!r)return{kind:"off"};if(i.markerToRead){let c=ne(t,{paths:o,root:n,scanFlag:r,marker:"bare"});return{kind:"marker",markerPath:i.markerToRead,scanIfBare:c.scan,...c.scanPaths?{scanPaths:c.scanPaths,scanPathsIfExplicit:kt(t,o,n,"agents")}:{}}}return{kind:"settled",markerPath:null,markerKind:null,scan:i.scan,...i.scanPaths?{scanPaths:i.scanPaths}:{}}}var bt=(t,e)=>{let{markerToRead:o}=ne(e.settings,{paths:t.map(({path:n})=>n),root:e.dir??void 0,scanFlag:e.flags.scan,marker:null});return o?{strength:"partial",wants:[o]}:null};function Pt(t,e,o="bare"){let{scan:n}=ne(e.settings,{paths:t.map(({path:r})=>r),root:e.dir??void 0,scanFlag:e.flags.scan,marker:o});return n?{strength:"partial",wants:[]}:null}function we(t){return oe(t,"CF_IMPORT_MANIFEST")}function xe(t,e){if(!Ke(t))return null;let o=new Set(e.paths),n=Ge(t,e),r=new Set(e.skillPaths),i=new Set(e.referencePaths),c=a=>Object.hasOwn(e.files,a)?Buffer.byteLength(e.files[a]):e.sizes?.get(a),l=e.selected??[...new Set([...e.skillPaths,...Object.keys(e.files).filter(a=>fe(a,{nested:!0})?.reference)])].filter(a=>Object.hasOwn(e.files,a)).map(a=>({path:a,size:c(a)})),f=[...new Map(l.filter(a=>!i.has(a.path)||r.has(a.path)).map(a=>[a.path,a])).values()],y=new Set(f.map(a=>a.path)),k=f.filter(a=>r.has(a.path)),E=new Set(f.filter(a=>fe(a.path,{nested:!0})?.reference).map(a=>a.path)),S=k.length,x=C.conventionImport.skillBytes-f.filter(a=>r.has(a.path)||E.has(a.path)).reduce((a,m)=>a+(c(m.path)??m.size),0),A=ce(t)?C.codeAgent.importBytes-f.reduce((a,m)=>a+(c(m.path)??m.size),0):1/0,I=new Map(k.map(a=>[a.path,null])),R=(a,m=!1)=>{if(I.has(a))return;let h=c(a),M=E.has(a),u=B(t,{path:a,size:h,text:e.files[a]},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:o,managedFiles:e.files}),P=y.has(a)?0:h,F=u.admitted?h===void 0?"missing":!M&&S>=C.conventionImport.skillFiles?"allowance":!M&&(h>x||P>A)?"total":null:u.reason;I.set(a,F),!M&&(m||!F)&&S++,!M&&!F&&(x-=h,A-=P)};for(let a of i)R(a,!0);let s=[...new Set(e.skillPaths)].sort().filter(a=>Object.hasOwn(e.files,a)).map(a=>{let m={ownerPath:a,files:[],cycles:[],unresolved:[],refused:[]},h=new Set([a]);for(let M of n.references.filter(u=>u.ownerPath===a)){if(!h.has(M.fromPath))continue;R(M.path);let u=I.get(M.path);if(u){m.refused.push({path:M.path,reason:u});continue}h.add(M.path);let P=m.files.find(F=>F.path===M.path);P||(P={path:M.path,evidence:[],sharedOwners:[]},m.files.push(P)),P.evidence.push(M)}return m.cycles=n.cycles.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.unresolved=n.unresolved.filter(M=>M.ownerPath===a&&h.has(M.fromPath)),m.refused=ae(m.refused),m}),p=new Map;for(let a of s)for(let m of a.files)p.set(m.path,[...p.get(m.path)??[],a.ownerPath]);for(let a of s)for(let m of a.files)m.sharedOwners=p.get(m.path);return s}var Gt=2e3;function Ot(t,e,o,n={}){let r=e.filter(u=>G(u.path,o)!=null),i={},c=[],l=new Map,f=n.mode!=="core"&&Ye(t),y=Oe(t,r.map(u=>u.path),o,{mode:f?"all":"core",files:n.files}),k=new Set([...y.ignoredPaths,...y.ignoredImportPaths]),E=new Map(y.files.filter(u=>u.role!=="reference").map(u=>[u.path,u])),S=new Map(y.scopes.map(u=>[u.key,C.conventionImport.totalBytes])),x=C.conventionImport.skillBytes,A=ce(t)?C.codeAgent.importBytes:1/0,I=0,R=u=>G(u.path,y.ownerOf(u.path).folder)??u.path,s=(u,P)=>{l.set(u.path,{path:u.path,reason:P})},p=(u,P)=>{let F=B(t,u,{purpose:P,route:"github",root:o});return F.admitted?!0:(s(u,F.reason),!1)},a=u=>{if(i[u.path])return;let P=f&&E.get(u.path)?.role==="skill"?"skill":"core",F=y.ownerOf(u.path),N=P==="skill"?x:S.get(F.key),j=u.size??0;if(P==="skill"&&I>=C.conventionImport.skillFiles){s(u,"allowance");return}if(j>N||j>A){s(u,"total");return}i[u.path]=u.ref,c.push(u.path),A-=j,P==="skill"?(x-=j,I++):S.set(F.key,N-j)},m=r.filter(u=>E.has(u.path));for(let u of m)p(u,rt(E.get(u.path).role))&&a(u);let h=0;if(we(t))for(let u of me(new Set(r.map(P=>P.path)))){let P=r.find(F=>F.path===u);if(h>=C.conventionImport.extractionFiles){s(P,"allowance");continue}if(p(P,"source")&&p(P,"definition")){let F=c.length;a(P),c.length>F&&h++}}let M=y.needsExtraction;if(M){let u=r.flatMap(F=>{if(k.has(F.path)||i[F.path]||f&&fe(R(F)))return[];if(!p(F,"extraction"))return[];let N=Ve(R(F));return N===null?[]:[{entry:F,rank:N}]}).sort((F,N)=>F.rank-N.rank||(F.entry.size??0)-(N.entry.size??0)),P=h;for(let{entry:F}of u){if(P>=C.conventionImport.extractionFiles){s(F,"allowance");continue}let N=c.length;a(F),c.length>N&&P++}}if(f&&n.files){let u=Vt(t,{entries:e,selected:r.filter(P=>Object.hasOwn(i,P.path)),files:n.files,root:o});for(let P of u.paths)Object.hasOwn(i,P)||(c.push(P),i[P]=r.find(F=>F.path===P).ref);for(let P of u.refused)l.set(P.path,P)}return{...ce(t)&&m.some(u=>!Object.hasOwn(i,u.path))?{definitionsOmitted:!0}:{},selectedPaths:c,shaByPath:i,treeListing:r.slice(0,Gt).map(u=>u.path),needsExtraction:M,refused:[...l.values()]}}function Vt(t,e){let o=new Set(e.selected.map(i=>i.path)),n=Oe(t,e.entries.map(i=>i.path),e.root,{files:e.files}).files.filter(i=>i.role==="skill"&&o.has(i.path)).map(i=>i.path),r=xe(t,{skillPaths:n,paths:e.entries.map(i=>i.path),files:e.files,sizes:new Map(e.entries.map(i=>[i.path,i.size])),selected:e.selected,root:e.root,admission:e.admission,referencePaths:e.referencePaths});return{paths:[...new Set(r?.flatMap(i=>i.files.map(c=>c.path))??[])],refused:r?.flatMap(i=>i.refused)??[]}}var Mt=(t,e)=>{let o=Ot(e.settings,t,e.dir??void 0,{mode:e.mode});return{strength:"partial",wants:o.selectedPaths,state:{needsExtraction:o.needsExtraction,treeListing:o.treeListing,shaByPath:o.shaByPath,refused:o.refused,...o.definitionsOmitted?{definitionsOmitted:!0}:{}}}};var Et=["marker","code-scan","conventions"];var Yt={marker:bt,"code-scan":Pt,conventions:Mt};function Ae(t,e,o,n,r=Yt){let i={...o,settings:t},c={readers:[]};for(let l of Et)if(!(n&&!n.includes(l)))try{let f=r[l]?.(e,i);f&&c.readers.push({id:l,claim:f,done:!1})}catch{}return c}function Xo(t){return{readers:t.readers.map(({id:e,done:o})=>({id:e,done:o}))}}function Ft(t){let e=t.readers.find(({id:o})=>o==="conventions").claim;return{selectedPaths:e.wants,...e.state}}var Wt={files:200,bytes:C.codeAgent.importBytes,depth:32,edges:_.edges,entries:pe.inventoryEntries};function It(t={}){return Object.fromEntries(Object.entries(Wt).map(([e,o])=>{let n=t[e]??o;return[e,Number.isFinite(n)?Math.max(0,Math.min(o,Math.floor(n))):0]}))}function xt(t,e,o,n){let r=new Set(o.map(s=>G(s.path,n))),i=t.CF_READING_NOTE_AGENT_ONLY!=="0"&&ft(t),c=new Set(e.agents),l=s=>!r.has(s)&&(!i||c.has(s)),f=e.instruction.filter(l),y=e.code.filter(l),k=e.agents.filter(s=>!r.has(s)),E=new Set(dt(k)),S=[...f,...y].every(s=>E.has(s)),x=f.length,A=y.length,I=[!S&&x>0&&`${x} instruction file${x===1?"":"s"} left out by the ${Math.round(C.sourceFetch.instructionBytes/1e3)}KB instruction budget`,!S&&A>0&&`${A} analyzable file${A===1?"":"s"} left out by the ${Math.round(C.sourceFetch.codeBytes/1e3)}KB/${C.sourceFetch.codeFiles}-file code budget \u2014 the analysis reads the most agent-shaped files first`,ut(k,i)].filter(Boolean),R=o.filter(s=>s.readBytes!==void 0).map(s=>G(s.path,n));return R.length&&I.push(`${R.join(", ")}: only the first ${C.sourceFetch.codeFileBytes/1e3} KB was read`),I.length?I.map((s,p)=>p<I.length-1?String(s).replace(/\.$/,""):s).join("; "):void 0}function At(t,e,o,n={}){let{descriptions:r,priority:i,declarations:c}=ht(t,e,{root:o},n),l=[],f=r.flatMap(a=>a.admission.admitted?[{entry:a.readEntry,rel:a.rel,score:a.score,size:a.readEntry.size,pool:a.pool,...a.tier===void 0?{}:{tier:a.tier}}]:(l.push({path:a.entry.path,reason:a.admission.reason}),[])),y=f.filter(({score:a})=>a===0).sort(ge),k=f.filter(({score:a})=>a>0).sort(ge),E=[],S={instruction:0,code:0},x={instruction:[],code:[]},A=0,I=(i.enabled?[...f].sort(ge):[...y,...k]).sort((a,m)=>Number(c.has(m.entry.path))-Number(c.has(a.entry.path)));for(let{entry:a,rel:m,pool:h}of I){let M=h==="instruction"?C.sourceFetch.instructionBytes:C.sourceFetch.codeBytes;if(S[h]+a.size>M||h==="code"&&A>=C.sourceFetch.codeFiles){x[h].push(m),l.push({path:a.path,reason:S[h]+a.size>M?"total":"allowance"});continue}E.push(a),S[h]+=a.size,h==="code"&&(A+=1)}let R=pt(i,l.flatMap(a=>{let m=G(a.path,o);return m===null?[]:[{...a,path:m}]})),s={...x,agents:R},p=xt(t,s,E,o);return{selected:E,totalBytes:S.instruction+S.code,refused:l,...p?{skippedNote:p}:{},...i.enabled&&p?{readingNotes:s}:{}}}function Re(t){let e=t.CF_CODE_AGENTS!=="0";return{scan:e,model:e&&t.CF_CODE_AGENTS_MODEL!=="0"}}function Rt(t,e){if(e.profile==="entry-analysis"){let l=It(e.limits),f=e.listing.find(k=>k.path===e.selection.entry),y=[...f?[f]:[],...e.listing.filter(k=>k.path!==e.selection.entry)].slice(0,l.entries);return{profile:e.profile,request:e.selection,entries:y,limits:l,inventoryIncomplete:e.listing.length-y.length}}let o=$e(t),n=o.length?{scopeSelections:o}:{},r={dir:e.root??null,mode:e.profile==="hosted-import"?e.mode??"all":"all",flags:e.profile==="hosted-import"?e.flags??Re(t):Re(t)};if(e.profile==="hosted-import"){let l=Ae(t,e.listing,r);return{profile:e.profile,...l,...n,selection:Ft(l),...ke(t)?{mode:r.mode}:{}}}let i=e.listing.filter(l=>B(t,l,{purpose:"pointer",route:"github",root:e.root}).admitted),c=Ae(t,i,r,["marker","code-scan"]);return{profile:e.profile,...c,...n,listing:i,selection:e.selection??At(t,e.listing,e.root),context:r,...e.selection&&ke(t)?{selectionPaths:e.selection.selected.map(l=>l.path)}:{}}}import{createHash as qt}from"node:crypto";var Q=t=>qt("sha256").update(t).digest("hex");function Cn(t,e){let o=s=>({kind:"refused",reason:s,pending:[]}),n=t.entries,r=new Map;for(let s of e)for(let p of s.files){let a=r.get(p.path);if(a&&(a.hash!==p.hash||a.size!==p.size))return o("stale-snapshot");r.set(p.path,{...p,role:n.includes(p.path)?"entry":"imported-helper"})}let i=[...r.values()],c=Q(JSON.stringify([n,e.map(s=>s.snapshot)])),l=[],f=new Set,y=(s,p,a=!1)=>{p=[...new Set(p)];let m=JSON.stringify([...p].sort());f.has(m)||p.length===i.length&&n.every(h=>r.has(h))||p.filter(h=>n.includes(h)).length>de||p.length>_.scopeImports+1||l.length>=_.choices||(f.add(m),l.push({id:Q(m),scope:{snapshot:c,entry:s,entries:n,imports:p.length===1?"none":p.filter(h=>h!==s)},includes:p,omitted:i.filter(h=>!p.includes(h.path)).map(h=>h.path),...a&&p.length>1?{coverage:"entry-imports"}:{}}))};for(let s=0;s<e.length;s+=de){let p=e.slice(s,s+de);y(p[0].kind==="file"?p[0].entry:n[s],p.flatMap(a=>a.files.map(m=>m.path)),!0)}for(let s of n.filter(p=>r.has(p)))y(s,[s]);for(let s of e)y(s.kind==="file"?s.entry:n[0],s.files.map(p=>p.path),!0);for(let s of e)for(let p of s.choices)y(p.scope.entry,p.includes);let k=s=>[...new Map(s.map(p=>[JSON.stringify(p),p])).values()],E=k(e.flatMap(s=>s.refusedEdges)),S=k(e.flatMap(s=>s.edges)),x=E.slice(0,_.edges),I=n.length-e.length+E.length-x.length+Math.max(0,S.length-_.edges)+e.reduce((s,p)=>s+p.completeness.frontierCount,0),R={schemaVersion:1,kind:"file",launchRoot:t.launchRoot,entry:t.entry,entries:n,snapshot:c,resolverVersion:e[0].resolverVersion,files:i,entrySets:e.map(s=>({entry:s.kind==="file"?s.entry:n[0],includes:s.files.map(p=>p.path)})),edges:S.slice(0,_.edges),refusedEdges:x,completeness:{complete:I===0&&e.every(s=>s.completeness.complete),frontierCount:I},choices:l};if(t.scope){if(t.scope.snapshot!==c)return o("stale-snapshot");let s=t.scope,p=Xt(R,s);return p?{kind:"ready",pending:[],selection:{...R,entrySets:void 0,...Ct(R,p.includes),choices:[]}}:o("invalid-scope")}return{kind:"ready",pending:[],selection:mt.parse(R)}}function Ut(t,e){if(t.kind!=="file"||!t.entries||!t.entrySets||!e.length)return;let o=e.map(c=>t.entrySets.find(l=>l.entry===c));if(o.some(c=>!c))return;let n=new Set(o.flatMap(c=>c.includes)),r=t.files.filter(c=>n.has(c.path)).map(c=>c.path);if(t.entries.filter(c=>n.has(c)).length>de||r.length>_.scopeImports+1)return;let i=e[0];return{id:Q(JSON.stringify([...r].sort())),scope:{snapshot:t.snapshot,entry:i,entries:t.entries,imports:r.length===1?"none":r.filter(c=>c!==i)},includes:r,omitted:t.files.filter(c=>!n.has(c.path)).map(c=>c.path),...r.length>1?{coverage:"entry-imports"}:{}}}function Xt(t,e){let o=f=>JSON.stringify([f.snapshot,f.entry,f.imports==="none"?[]:Array.isArray(f.imports)?[...f.imports].sort():f.imports,f.entries]),n=t.choices.find(f=>o(f.scope)===o(e));if(n)return n;if(t.kind!=="file"||!t.entries||e.imports==="all")return;let r=new Set([e.entry,...e.imports==="none"?[]:e.imports]),i=t.entrySets?.filter(f=>f.includes.every(y=>r.has(y))).map(f=>f.entry)??[];if(!i.includes(e.entry))return;let c=[e.entry,...i.filter(f=>f!==e.entry)],l=Ut(t,c);return l&&o(l.scope)===o(e)?l:void 0}function Ct(t,e,o=!0){let n=new Set(e),r=new Set(t.files.map(f=>f.path)),i=t.edges.filter(f=>n.has(f.from)&&!n.has(f.path)&&r.has(f.path)).map(f=>({from:f.from,specifier:f.specifier,status:"refused",provenance:f.provenance,reason:"not-selected"})),c=o?[...new Map([...t.refusedEdges.filter(f=>n.has(f.from)),...i].map(f=>[JSON.stringify(f),f])).values()]:[...t.refusedEdges,...i].slice(0,_.edges).filter(f=>n.has(f.from)),l=t.completeness.frontierCount+(o?Math.max(0,c.length-_.edges):0);return{files:t.files.filter(f=>n.has(f.path)),edges:t.edges.filter(f=>n.has(f.from)&&n.has(f.path)),refusedEdges:c.slice(0,_.edges),completeness:{complete:l===0&&c.every(f=>f.reason==="external"),frontierCount:l}}}function Ht(t,e){let o=new Set(e.map(r=>r.path)),n=new Set(e.filter(r=>r.role==="entry").map(r=>r.path));return!t?.files.some(r=>!o.has(r.path)||r.role==="prompt"&&!n.has(r.path))}function Zt(t){return t.unavailable?t.unavailable:t.entry?!Number.isSafeInteger(t.entry.size)||t.entry.size<0?"over-limit":Ue.safeParse(t.path).success?t.depth>t.limits.depth||!t.spentPaths.has(t.path)&&(t.spentPaths.size>=t.limits.files||t.bytes+t.size>t.limits.bytes)?"over-limit":null:"out-of-scope":"missing"}function Lt(t,e){let o=b=>({kind:"refused",reason:b,pending:[]});if(!Be(t))return o("disabled");let{request:n,files:r,resolutions:i,unavailable:c={}}=e,l=Rt(t,{profile:"entry-analysis",listing:[...e.entries],selection:n,limits:e.limits}),{limits:f}=l,y=new Map(l.entries.map(b=>[b.path,b])),k={},E=[],S=[],x=[],A=[],I=new Set,R=new Set,s=[{path:n.entry,depth:0,settings:!1},...(e.settingsFiles??[]).map(b=>({path:b,depth:0,settings:!0}))],p=new Set,a=new Map,m=new Map,h=new Set(e.attempted?.paths),M=new Set(e.settingsAttempted?.paths),u={files:pe.settingsFiles,bytes:pe.settingsBytes,depth:f.depth},P=e.settingsAttempted?.bytes??0,F=e.attempted?.bytes??0,N=0,j=e.inventoryIncomplete??0;j+=l.inventoryIncomplete;let J=(b,v)=>{A.length<_.edges&&A.push({from:b.from,specifier:b.specifier,status:"refused",provenance:b.provenance,reason:v})};for(let b=0;b<s.length;b++){let v=s[b],T=`${v.settings}:${v.path}`;if(p.has(T))continue;p.add(T);let D=y.get(v.path),$=Object.hasOwn(r,v.path)?r[v.path]:void 0,te=$===void 0?D?.size??0:Buffer.byteLength($),ie=v.settings?M:h,z=Zt({...v,entry:D,size:te,unavailable:Object.hasOwn(c,v.path)?c[v.path]:void 0,spentPaths:ie,bytes:v.settings?P:F,limits:v.settings?u:f});if(z){if(v.path===n.entry&&!v.settings)return o(z);if(v.settings&&Object.defineProperty(k,v.path,{value:z,enumerable:!0}),!v.settings){m.set(v.path,z);for(let g of a.get(v.path)??[])J(g,z);z==="over-limit"&&j++}continue}if(ie.has(v.path)||(v.settings?P+=te:F+=te,ie.add(v.path)),$===void 0){S.push(v.path),(v.settings?I:R).add(v.path);continue}if(v.settings)continue;if(E.push(v.path),!Object.hasOwn(i,v.path)){S.push(v.path);continue}let q=i[v.path];for(let g=0;g<q.length;g++){let O=q[g];if(N++>=f.edges){J(O,"over-limit"),j+=q.length-g;break}if(!Xe.safeParse(O).success||O.from!==v.path){J({from:v.path,specifier:"?",status:"refused",provenance:null,reason:"unsupported"},"unsupported");continue}if(O.status==="refused"){J(O,O.reason);continue}x.push(O),a.set(O.path,[...a.get(O.path)??[],O]);let L=m.get(O.path);if(L){J(O,L);continue}s.push({path:O.path,depth:v.depth+1,settings:!1})}}if(S.length)return{kind:"pending",pending:[...new Set(S)],pendingSettings:[...I].filter(b=>!R.has(b)),...Object.keys(k).length?{unavailable:k}:{}};let se=E.map(b=>({path:b,role:b===n.entry?"entry":"imported-helper",hash:Q(r[b]),size:Buffer.byteLength(r[b])})),ee=Q(JSON.stringify({request:{...n,scope:void 0},files:se,inventory:[...y.values()].map(({path:b,size:v,ref:T})=>({path:b,size:v,ref:T})).sort((b,v)=>b.path.localeCompare(v.path)),metadata:(e.settingsFiles??[]).map(b=>[b,Object.hasOwn(r,b)?Q(r[b]):c[b]??"over-limit"]),edges:x,refusedEdges:A,frontierCount:j,limits:f,resolverVersion:e.resolverVersion,resolverIdentity:e.resolverIdentity,targetIdentity:e.targetIdentity,settings:Object.entries(Ne(t)).sort(([b],[v])=>b.localeCompare(v))})),w=n.scope;if(w&&w.snapshot!==ee)return o("stale-snapshot");let d=E.filter(b=>b!==n.entry);if(w&&(w.entry!==n.entry||Array.isArray(w.imports)&&w.imports.some(b=>!d.includes(b))))return o("invalid-scope");let V=new Set(!w||w.imports==="all"?E:[n.entry,...w.imports==="none"?[]:w.imports]),Y=Ct({files:se,edges:x,refusedEdges:A,completeness:{complete:!1,frontierCount:j}},[...V],!1),U=Y.files;if(!Ht(e.proposal,U))return o("invalid-scope");let re=[],ue=(b,v)=>{let T=[n.entry,...v==="none"?[]:v];T.length!==U.length&&re.push({id:b,scope:{snapshot:ee,entry:n.entry,imports:v},includes:T,omitted:U.filter(D=>!T.includes(D.path)).map(D=>D.path)})};ue("entry-only","none");for(let b of U.filter(v=>v.role==="imported-helper").slice(0,_.choices-1))ue(Q(b.path),[b.path]);let he={schemaVersion:1,kind:"file",launchRoot:n.launchRoot,entry:n.entry,snapshot:ee,resolverVersion:e.resolverVersion,...Y,choices:re};return{kind:"ready",pending:[],selection:he}}function Nn({prompt:t,link:e}){return{path:e?.callPath??t.path,...e?{line:e.callLine}:{},symbol:t.symbol,promptPath:t.path,promptStart:t.start,...e?.kind==="L4"?{loadedPrompt:!0,...e.callStart!==void 0?{callStart:e.callStart}:{}}:{}}}function Bt(t,e,o){return nt(t,e,o)}var Se=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function Qt(t,e,o,n={}){let r=new Map(t.map(i=>[Se(i),i]));return e.flatMap(i=>{let c=Object.hasOwn(o,i)?o[i]:void 0;if(c===void 0||!B(n,{path:i},{purpose:"code-support",route:"github"}).admitted)return[];let l=le(i,c,X(i)).toks;return l.flatMap((f,y)=>{if(!Z(f))return[];let k=r.get(Se(f.text));if(!k)return[];let E=!1;if(Z(l[y-1],"function")||Z(l[y-1],"def"))E=H(l[y+1],"(");else if(["const","let","var"].some(S=>Z(l[y-1],S))){for(let S=y+1;S<l.length&&S<y+80&&!H(l[S],";");S++)if(H(l[S],"=")){let x=Z(l[S+1],"async")?S+2:S+1,A=H(l[x],"(")?Te(l,x)+1:x+1;E=Z(l[x],"function")||H(l[A],"=")&&H(l[A+1],">");break}}return E?[{name:k,sourcePath:i,sourceLine:f.line}]:[]})})}function Nt(t,e,o,n,r={}){let i=new Set(t.map(Se)),c=k=>B(r,{path:k},{purpose:"code-support",route:"github"}).admitted,l=k=>Qt(t,[k],o,r).length>0,f=e.filter(k=>c(k)&&l(k)),y=n.filter(k=>c(k)&&i.has(Se(k.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(o[k]===void 0||l(k))).sort();return[...new Set([...f,...y])]}var jt="model call";function zt(t,e){let o=Bt(t.ownPaths,e,t.toolCall);return{tools:o.tools.map(n=>({tool:n,from:o.from[n.name]})),toolWarnings:o.warnings}}function Le(t=new Map,e){return{left:Math.max(0,C.codeAgent.importBytes-[...t.values()].reduce((o,n)=>o+n,0)),chosen:new Set([...t.keys()].filter(o=>!e?.has(o))),...e?{replacementBytes:e}:{}}}function eo(t,e){return t.modelId??(!t.documentation&&e.length===1?e[0]:null)}function ns(t,e,o){return to(t,eo(t,e),o)}function to(t,e,o){let{prompt:n,link:r}=t,i=[n.kind==="file"?{role:"system prompt",label:null,path:n.path}:{role:"system prompt",label:n.symbol??`line ${n.span.from}`,path:n.path,span:{from:n.span.from,to:n.span.to},...n.filledAtRunTime?{filledAtRunTime:!0}:{}}];for(let l of t.alsoLoads??[])i.push({role:"system prompt",label:"also loaded",path:l});r&&i.push({role:"code",label:jt,path:r.callPath}),r?.wrapper&&i.push({role:"code",label:"model wrapper",path:r.wrapper.path}),e&&i.push({role:"code",label:"model setting",path:e.path}),t.shape&&i.push({role:"code",label:"answer shape",path:t.shape.path});let c=new Set;return i.filter(l=>!c.has(l.path)&&!!c.add(l.path)).map(l=>ze(o,l.path,l.path===n.path&&t.promptSource==="marker")?l:{...l,role:"reference"})}function ss(t,e){let{prompt:o}=t,n=e[o.path]??"";return o.kind==="file"?n:n.split(`
2
2
  `).slice(o.span.from-1,o.span.to).join(`
3
3
  `)}function rs(t,e){return e?Object.fromEntries(e.files.filter(o=>t[o.path]!==void 0).map(o=>[o.path,t[o.path]])):t}function is(t,e,o){let{files:n,sizes:r,root:i,total:c=Le()}=o,l=[...new Set([...e.ownPaths,...o.guides??[]])],f=[],y=new Set(l);l=l.filter(h=>{let M=B(t,{path:h},{purpose:"override",route:"github"});return M.admitted||f.push({path:h,reason:M.reason}),M.admitted});let k=[...r.keys()].filter(h=>{let M=B(t,{path:h},{purpose:"code-support",route:"github",root:i});return!M.admitted&&!y.has(h)&&f.push({path:h,reason:M.reason}),M.admitted}),E=Object.fromEntries(l.filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),S=ot(E,k).filter(h=>!l.includes(h)),x=Object.fromEntries([...l,...S].filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),A=zt({ownPaths:l,toolCall:e.toolCall},x).tools.map(({tool:h})=>h.name),I=new Set(Nt(A,S,n,k,t)),R=Ce(t,l,{...o,total:c});for(let h of new Set([...l,...S,...I]))R.take(h,I.has(h)&&!l.includes(h));let{paths:s,skipped:p}=R,a=Object.fromEntries(s.filter(h=>n[h]!==void 0).map(h=>[h,n[h]])),m=zt(e,a);return{paths:s,skipped:p,refused:ae(f,R.refused),...m}}function Ce(t,e,{sizes:o,total:n=Le(),pool:r},i=[]){let c=[],l=[],f=[],y=C.codeAgent.extraBytes,k=0;return{paths:c,skipped:l,refused:f,take:(S,x,A=!1)=>{if(c.includes(S))return!0;let I=o.get(S),R=S===e[0],s=i.includes(S),p=[n,...r?[r]:[]],a=u=>Math.max(0,(I??0)-(u.replacementBytes?.get(S)??0)),m=s?"override":e.includes(S)||A?"pointer":"code-support",h=B(t,{path:S,size:I},{purpose:m,route:"github"});h.admitted||f.push({path:S,reason:h.reason});let M=I===void 0?"missing":h.admitted?!s&&!R&&I>y?"allowance":!s&&p.some(u=>!u.chosen.has(S)&&(a(u)>u.left||u.wholeBytesLeft!==void 0&&I>u.wholeBytesLeft))?"total":x&&k>=C.codeAgent.toolCodeFiles?"tool-limit":null:h.reason;if(M)return l.push({path:S,reason:M}),!1;!R&&!s&&(y-=I),x&&k++;for(let u of p)u.chosen.has(S)||(u.left-=a(u),u.wholeBytesLeft!==void 0&&(u.wholeBytesLeft-=I),u.chosen.add(S));return c.push(S),!0}}}function as(t,e,o){return"request"in e?Lt(t,e):oo(t,e,o)}function oo(t,e,o){if(!we(t)&&!(oe(t)&&e.some(s=>s.fileProfile==="layout")))return null;let n=o.scopes??ct(t,[...o.sizes.keys()],o.root??void 0,{},o.agentConfigurations??{}),r=o.total??Le(),i=new Set(o.confirmationIds),c=o.selectedIds&&new Set(o.selectedIds),l=e.filter(s=>!c||c.has(s.id));for(let s of l)for(let{path:p}of s.ownFiles.filter(a=>s.fileProfile==="convention"||s.sharedReferencePaths?.includes(a.path))){let a=o.sizes.get(p),m=s.scopeProof?.paths.includes(p)?void 0:o.root;a===void 0||r.chosen.has(p)||!B(t,{path:p},{purpose:"override",route:"github",root:m}).admitted||(r.left-=Math.max(0,a-(r.replacementBytes?.get(p)??0)),r.wholeBytesLeft!==void 0&&(r.wholeBytesLeft-=a),r.chosen.add(p))}let f=(s,p)=>{for(let a of s){let m=a.ownFiles[0]?.path;if(!m)continue;let h=n.ownerOf(m);!h||h.key!==a.scope.key||h.folder!==a.scope.folder||!B(t,{path:m},{purpose:"pointer",route:"github",root:o.root}).admitted||Ce(t,[m],{...o,total:p,pool:void 0}).take(m,!1)}};f(l,r);let y,k=new Set,E=new Set(o.sizes.keys()),S=me(E).flatMap(s=>o.files[s]===void 0?[]:be(s,o.files[s],E,{root:o.root??void 0})),x=new Map(S.map(s=>[s,s.to&&o.files[s.to]!==void 0?Ze(s.to,o.files[s.to],s.imported,E,t):[]])),A=new Set(S.filter(s=>{let p=s.to&&X(s.to),a=s.to&&o.files[s.to];return p&&a!==void 0&&a!==null&&!ve(le(s.to,a,p),s.imported)})),I=e.map(s=>{let p=[...new Set(s.ownFiles.map(w=>w.path))],a=new Set(s.fileProfile==="layout"?s.ownFiles.filter(w=>w.role==="tools").map(w=>w.path):[]),m={schemaVersion:1,agentId:s.id,scope:{...s.scope},files:[],edges:[],unresolved:[],refused:[]};if(c&&!c.has(s.id))return m;i.has(s.id)&&!y&&(y={left:C.candidateFetch.check,chosen:new Set(k)},f(l.filter(w=>i.has(w.id)),y));let h=Ce(t,p,{...o,total:r,pool:i.has(s.id)?y:void 0},s.fileProfile==="convention"?p:s.sharedReferencePaths),M=new Set(s.skillManifests?.flatMap(w=>w.files.map(d=>d.path))),u=s.ownFiles.filter(w=>w.role!=="reference"||!M.has(w.path)||s.independentReferences?.includes(w.path)).map(w=>({path:w.path,symbol:null,role:w.role,evidence:null,span:w.span})),P=S.filter(w=>w.to!==null&&p.includes(w.to)),F=P.filter(w=>new Set(P.filter(d=>d.to===w.to).map(d=>d.imported)).size>1),N=S.filter(w=>!A.has(w)&&(P.includes(w)&&!s.toolCall&&!F.includes(w)||x.get(w).some(d=>{if(d.kind!=="graph-node"||!d.to||!p.includes(d.to)||!s.toolCall||s.toolCall.path!==d.to)return!1;let V=o.files[d.to];return V!==void 0&&Qe(d.to,V,d.imported,s.toolCall)})));m.unresolved.push(...P.filter(w=>!N.includes(w)).map(w=>({...w,reason:A.has(w)?"missing":"unlinked"})));for(let w of N)u.push({path:w.from,symbol:w.symbol,role:"config",evidence:w,explicit:!0});let j=new Set,J=new Map,se=new Set,ee=new Set;for(let w=0;w<u.length;w++){let d=u[w],V=JSON.stringify([d.path,d.symbol,d.role]);if(j.has(V)){let g=m.files.find(O=>O.path===d.path);g&&d.span&&!g.spans.some(O=>O.from===d.span.from&&O.to===d.span.to)&&(g.spans.push(d.span),g.evidence.push({kind:"entry",from:d.path,to:d.path,span:d.span})),g&&d.evidence?.kind==="skill-reference"&&!g.evidence.some(O=>JSON.stringify(O)===JSON.stringify(d.evidence))&&g.evidence.push(d.evidence);continue}j.add(V);let Y=n.ownerOf(d.path),U=p.includes(d.path)&&s.scopeProof?.paths.includes(d.path),re=B(t,{path:d.path},{purpose:p.includes(d.path)||d.explicit?"pointer":"code-support",route:"github",root:U?void 0:o.root}),ue=d.role==="reference"&&p.includes(d.path)&&(s.sharedReferencePaths?.includes(d.path)||s.skillManifests?.some(g=>m.files.some(O=>O.path===g.ownerPath)&&g.files.some(O=>O.path===d.path)&&!g.refused.some(O=>O.path===d.path))),he=re.admitted?!U&&(!Y||!ue&&(Y.key!==s.scope.key||Y.folder!==s.scope.folder))?"out-of-scope":!p.includes(d.path)&&e.some(g=>g.id!==s.id&&g.ownFiles.some((O,K)=>O.path===d.path&&(K===0||O.label===jt)))?"other-agent":null:re.reason;if(he){m.refused.push({path:d.path,reason:he});continue}let b=o.files[d.path],v=X(d.path),T=b!==void 0&&v?le(d.path,b,v):null,D=T&&d.symbol?ve(T,d.symbol):null,$=D?.name??d.symbol;if(b!==void 0&&!J.has(d.path)){let g=S.filter(L=>L.from===d.path),O=[...g.length?g:be(d.path,b,E,{root:s.scope.folder,call:s.toolCall}),...[...ee].filter(L=>L.to===d.path).flatMap(L=>x.get(L))];O.forEach(L=>se.add(L));let K=He(d.path,b,E,p.includes(d.path)?s.toolCall:void 0,t).flatMap(L=>O.some(W=>!W.reason&&W.kind===L.kind&&W.symbol===L.symbol&&W.span.from===L.span.from)?[]:N.some(W=>W.to===d.path)&&!p.includes(d.path)&&(L.kind==="config"||L.kind==="graph-node")&&!L.reason?[{...L,reason:"unlinked"}]:[L]);J.set(d.path,[...K,...O,...(o.links??[]).filter(L=>L.from===d.path)])}let te=J.get(d.path)??[];if(d.role==="code"&&d.evidence?.kind==="import"&&te.some(g=>g.reason==="external"&&g.usage==="call"&&(g.within===$||g.within===null)&&_e(g.source,v))){m.refused.push({path:d.path,reason:"provider-transport"});continue}let ie=a.has(d.path)||d.role==="tool"&&D?.params!=null&&!p.includes(d.path);if(!h.take(d.path,ie,d.explicit))continue;m.unresolved.push(...S.filter(g=>g.from===d.path&&(g.reason||A.has(g))).map(g=>A.has(g)?{...g,reason:"missing"}:g));let z=m.files.find(g=>g.path===d.path);z||(z={path:d.path,roles:[],spans:[],evidence:[],sharedOwners:[]},m.files.push(z)),z.roles.includes(d.role)||z.roles.push(d.role);let q=d.span??(T&&D?{from:T.toks[D.from].line,to:T.toks[D.to-1].endLine}:void 0);q&&!z.spans.some(g=>g.from===q.from&&g.to===q.to)&&z.spans.push(q),d.evidence?z.evidence.push(d.evidence):z.evidence.push({kind:"entry",from:d.path,to:d.path,...d.span?{span:d.span}:{}});for(let g of s.skillManifests??[])if(m.files.some(O=>O.path===g.ownerPath))for(let O of g.files)for(let K of O.evidence)K.fromPath===d.path&&u.push({path:O.path,symbol:null,role:"reference",explicit:!0,evidence:{kind:"skill-reference",from:K.fromPath,to:O.path,span:K.span}});if(b!==void 0)for(let g of te){let O=g.usage==="reexport"&&(g.symbol===$||g.symbol==="*"),K=g.usage==="call"&&g.within===$;if(!(g.kind!=="import"&&($===null||g.within===$)||$!==null&&(O||K)||g.reason==="dynamic"&&($===null||g.within===$)))continue;if(!g.to||g.reason){m.unresolved.push(g);continue}let W=N.includes(g);W&&(ee.add(g),J.delete(g.to)),m.edges.push(g);let Tt=g.kind==="tool-registration"?"tool":g.kind==="config"?"config":g.kind==="graph-node"?"workflow":O?d.role:"code";u.push({path:g.to,symbol:W?null:g.imported==="*"?d.symbol:g.imported,role:Tt,evidence:g,explicit:se.has(g)})}}if(m.refused.push(...ae(h.skipped,h.refused)),m.unresolved=m.unresolved.filter(w=>w.reason!=="unlinked"||!m.edges.some(d=>d.from===w.from&&d.to===w.to&&d.kind===w.kind&&d.symbol===w.symbol&&d.span.from===w.span.from)),m.unresolved=[...new Map(m.unresolved.map(w=>[JSON.stringify(w),w])).values()],m.refused=m.refused.filter((w,d,V)=>V.findIndex(Y=>Y.path===w.path&&Y.reason===w.reason)===d),!i.has(s.id))for(let w of m.files)k.add(w.path);return m}),R=new Map;for(let s of I)for(let p of s.files)R.set(p.path,[...R.get(p.path)??[],s.agentId]);for(let s of I)for(let p of s.files)p.sharedOwners=[...new Set(R.get(p.path))].sort();return I}export{Nn as a,Qt as b,Nt as c,we as d,xt as e,At as f,Re as g,Me as h,Ee as i,yt as j,wt as k,St as l,_t as m,lo as n,Kt as o,kt as p,So as q,xe as r,Ot as s,Vt as t,Ae as u,Xo as v,Ft as w,Wt as x,Rt as y,Cn as z,Ut as A,Xt as B,Ht as C,zt as D,Le as E,eo as F,ns as G,ss as H,rs as I,is as J,as as K};
@@ -1 +1 @@
1
- import{A as Z,B as dt,C as pt,D as ct,E as ft,F as O,G as mt,H as ht,I as ut,J as gt,P as Pt,R as wt,V as kt,W as St,a as ie,b as Je,c as Ve,d as Qe,e as Xe,f as V,g as le,h as z,i as Ze,j as K,ja as bt,k as N,l as et,la as vt,m as tt,ma as Rt,n as ot,na as Ft,o as q,oa as Et,p as st,q as at,r as de,s as Q,t as rt,u as nt,v as A,w as pe,x as X,y as it,z as lt}from"./QPIBHTON.js";import{a as Ye}from"./5VQ4VYIP.js";import{i as $e}from"./6JTHFDH3.js";import{a as J}from"./QDYMR6KS.js";import{a as We}from"./XVGLY4EO.js";import{g as _}from"./6VHZNBII.js";import{E as Ge,d as ze,e as M,f as Ke,g as Ne,h as qe,o as He,q as C,s as Ue,t as De,y as Y}from"./LFJQ4YLP.js";import{a as L}from"./326F4XNG.js";import{b as T,c as U}from"./HCPO6QPU.js";import{a as Te,b as _e,c as ne}from"./DHVEGIU6.js";import{a as je,b as re}from"./5UWDUYHF.js";import{e as ke,g as Se}from"./VC3PYT2B.js";import{n as $}from"./P253B344.js";import{c as Ie}from"./W73WF226.js";import{a as Ae}from"./4H23CSUM.js";import{c as ae}from"./MJGB25S5.js";import{$ as D,Ca as ye,Fb as k,Lb as Le,Ta as Ce,hb as G,i as y,kb as Be,lb as Me,pb as W,u as oe}from"./2M55DR2J.js";import{a as ve}from"./MKYLK6DB.js";import{f as se,i as Fe,j as Ee,m as Oe,n as xe}from"./JKWTHRUR.js";import{c as Re,e as x}from"./C6X5GDG4.js";import{b as we}from"./724WZMYW.js";import{a as be}from"./SJESFYBA.js";import{posix as Ut}from"node:path";function Ot(r,e,a){let s=new Set(e.entries.map(l=>l.path)),t=new Set(G(r,[...s])),d=Object.fromEntries(Object.entries(e.files).filter(([l])=>e.selected.some(o=>o.path===l&&o.readBytes===void 0))),n=new Set(Me(r,[...s],d)),f=[],c=new Set;return{read:async l=>{if(n.has(l.path)||e.managedReadPaths?.includes(l.path)&&e.files[l.path]===void 0)return e.refused.push({path:l.path,reason:"unreadable"}),null;f.push(l);try{let o=await a(l);if(o!==null){if(c.has(l.path)){let p=k(r,{path:l.path,size:Buffer.byteLength(o),text:o},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(y(r)||we(r)){let p=k(r,{path:l.path,text:o},{...e.admission,purpose:"override",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(e.phase==="manifest"){let p=k(r,{path:l.path,size:Buffer.byteLength(o)},{...e.admission,purpose:"pointer",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}return o}}catch(o){if(o instanceof W&&(o.reason==="secret-content"||y(r)||c.has(l.path)||t.has(l.path)))return e.refused.push({path:l.path,reason:o.reason}),null;if(e.profile==="hosted-import"&&!c.has(l.path)&&!t.has(l.path))throw o}return e.refused.push({path:l.path,reason:"unreadable"}),null},requestedReads:f,skillReads:c}}import{createHash as Ht}from"node:crypto";function ce(r){return Ht("sha256").update(JSON.stringify(r.map(({path:e,ref:a,size:s})=>({path:e,ref:a,size:s})))).digest("hex")}function xt(r,e,a){return _(r)?{settings:Se(r),commit:a??ce(e),revisionKind:a===void 0?"listing":"commit",completed:[]}:void 0}function yt(r,e,a){let s=r.agentPages;if(!s)return;let t=a??s.listingEntries??r.entries,d=s.revisionKind??(s.commit===ce(s.listingEntries??r.entries)?"listing":"commit");if(d==="commit"&&e!==void 0&&s.commit!==e||d==="listing"&&s.commit!==ce(t))throw new Error("stale-agent-page");return s.commit}function Ct(r,e,a){e.ranked??=Q(r,e.scan,new Map);let s=new Map([...de(e.scan.plan),...Object.entries(e.agentPages?.actualSizes??{})]),t=ie(r,e.ranked,s,new Map,{files:{},...e.agentPages?{page:{commit:e.agentPages.commit,scope:e.root,continuation:a}}:{}});t.page&&(e.ranked={...e.ranked,agentPage:t.page,strong:t.strong,possible:t.window,notRead:t.notRead,notReadMore:t.notReadMore});let d=[...t.refused,...e.ranked.skippedFiles??[]];if(e.requestedPaths.push(...d.map(n=>n.path)),e.refused.push(...d),e.profile==="hosted-import"&&t.paths.length||t.page){let n=nt(r,[],t.paths,e.scan.plan);e.refused.push(...n.refused),e.profile==="hosted-import"?pt(e,n.selected):(lt(r,e),Z(e,n.selected))}else X(r,e,t.paths,e.scan.plan);e.phase=e.selected.length?"files":"done"}function Bt(r,e,a,s){let t={...e.agentPages.actualSizes};a.forEach((o,p)=>{s[p]!==null&&(t[o.path]=Buffer.byteLength(s[p]))}),e.agentPages={...e.agentPages,actualSizes:t};let d=new Map([...de(e.scan.plan),...Object.entries(t)]),n=new Map(Object.entries(e.files).map(([o,p])=>[o,Buffer.byteLength(p)])),f=new Set(e.skillReferencePaths),c=new Set([...e.conventionPaths,...dt(e),...f,...e.markerPath?[e.markerPath]:[]]);for(let o of a)if(c.has(o.path)&&t[o.path]!==void 0){let p=k(r,{path:o.path,size:t[o.path]},{purpose:f.has(o.path)?"skill":"pointer",route:"github",root:e.root,listing:new Set(e.entries.map(u=>u.path)),managedFiles:e.files}),i=Ge(n).left+(n.get(o.path)??0);p.admitted&&t[o.path]<=i?n.set(o.path,t[o.path]):e.refused.push({path:o.path,reason:p.admitted?"total":p.reason})}let m=ie(r,e.ranked,d,n),l=new Set(m.paths);a.forEach((o,p)=>{s[p]!==null&&(l.has(o.path)||c.has(o.path)&&n.has(o.path)?e.files[o.path]=s[p]:e.refused.push(m.refused.find(i=>i.path===o.path)??m.skippedFiles?.find(i=>i.path===o.path)??{path:o.path,reason:"total"}))}),e.ranked={...e.ranked,agentPage:m.page,strong:m.strong,possible:m.window}}function fe(r){let e=r.ranked,a=e?.agentPage;if(!a||r.phase!=="done")return;let s=[...e.agentInventory.strong,...e.agentInventory.possible],t=new Set(a.selected),d=new Set(a.refusals.map(c=>c.id)),n=s.filter(c=>t.has(D(c.prompt))&&!d.has(D(c.prompt))&&r.files[c.prompt.path]===void 0),f=[...a.refusals,...n.map(c=>({id:D(c.prompt),reason:r.refused.find(m=>m.path===c.prompt.path)?.reason??"missing"}))];r.ranked={...e,strong:e.strong.filter(c=>r.files[c.prompt.path]!==void 0),possible:e.possible.filter(c=>r.files[c.prompt.path]!==void 0),agentPage:{...a,refusals:f,partial:f.length>0,estimatedInputBytes:Object.values(r.files).reduce((c,m)=>c+Buffer.byteLength(m),0)}}}async function Mt(r,e,a){if(!y(r))return!1;let s=Be(r,e.entries.map(o=>o.path));if(!s.length)return!1;let t=new Set(s.flatMap(o=>o.agents)),d=new Map(e.selected.map(o=>[o.path,o])),n=new Set(e.selected.filter(o=>o.readBytes===void 0&&e.files[o.path]!==void 0).map(o=>o.path));e.managedReadPaths||(e.managedReadPaths=[],(e.scan||e.ranked)&&(delete e.scan,delete e.ranked,delete e.manifestReadPaths,e.phase!=="marker"&&(e.phase="scan")));let f=new Set([...e.managedReadPaths,...n]),c=e.entries.filter(o=>t.has(o.path)&&d.has(o.path)&&!f.has(o.path)),m=c.slice(0,A);if(!m.length)return!1;let l=await L(m,4,async o=>{let p=k(r,o,{...e.admission,purpose:"pointer",route:"github",root:e.root});return p.admitted?a(o):(e.refused.push({path:o.path,reason:p.reason}),null)});if(m.forEach((o,p)=>{l[p]!==null&&(e.files[o.path]=l[p],e.selected=e.selected.map(i=>i.path===o.path?o:i))}),e.managedReadPaths.push(...m.map(o=>o.path)),c.length>m.length){for(let o of Object.keys(e.files))!t.has(o)&&s.some(p=>Re(o,p.folder)!==null)&&delete e.files[o];e.cursor=0,(e.phase==="done"||e.phase==="manifest")&&(e.phase="files")}return!0}async function Lt(r,e,a){if(e.marketplacePlanned)return!1;let s=new Set(G(r,e.entries.map(o=>o.path)));if(!e.selected.some(o=>s.has(o.path)))return!1;let t=new Set(e.marketplaceReadPaths),n=e.selected.filter(o=>s.has(o.path)&&!t.has(o.path)).slice(0,A),f=await L(n,4,async o=>{let p=k(r,o,{...e.admission,purpose:"definition",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:o.path,reason:p.reason}),null;let u=(o.readBytes===void 0?e.files[o.path]:void 0)??await a({path:o.path,size:o.size,ref:o.ref});if(u===null)return null;let g=k(r,{path:o.path,size:Buffer.byteLength(u),text:u},{...e.admission,purpose:"definition",route:"github",root:e.root});return g.admitted?u:(e.refused.push({path:o.path,reason:g.reason}),null)});n.forEach((o,p)=>{f[p]!==null?e.files[o.path]=f[p]:delete e.files[o.path]}),e.marketplaceReadPaths=[...t,...n.map(o=>o.path)];let c=new Map(n.flatMap((o,p)=>f[p]===null?[]:[[o.path,Buffer.byteLength(f[p])]]));e.agentPages&&c.size&&(e.agentPages={...e.agentPages,listingEntries:e.agentPages.listingEntries??e.entries}),e.entries=e.entries.map(o=>c.has(o.path)?{...o,size:c.get(o.path)}:o);let m,l=e.marketplaceSelection?new Set(e.marketplaceSelection):void 0;do{let o=new Set(e.marketplaceReadPaths.filter(h=>e.files[h]===void 0)),p=e.entries.filter(h=>!o.has(h.path)&&(!l||l.has(h.path))),i=e.profile==="local-analysis"?Ke(r,p,e.root,{files:e.files}):Ue(r,p,e.root,{files:e.files,mode:e.marketplaceMode}),u="selected"in i?i.selected.map(h=>h.path):i.selectedPaths,g=new Set(u),P=new Map(p.map(h=>[h.path,h]));e.selected=u.map(h=>P.get(h)),e.selectionRefused=i.refused,e.hosted&&"selectedPaths"in i&&(e.hosted.fallback=i,e.hosted.codeMode||(e.hosted.needsExtraction=i.needsExtraction)),m=Object.keys(e.files).filter(h=>s.has(h)&&!g.has(h));for(let h of m)e.refused.push(i.refused.find(w=>w.path===h)??{path:h,reason:"total"});for(let h of Object.keys(e.files))g.has(h)||delete e.files[h]}while(m.length);return e.conventionPaths=$(r,e.entries.filter(o=>!s.has(o.path)||e.files[o.path]!==void 0).map(o=>o.path),e.root,{files:e.files}).files.filter(o=>o.role!=="reference").map(o=>o.path),e.cursor=0,e.marketplacePlanned=!e.selected.some(o=>s.has(o.path)&&!e.marketplaceReadPaths.includes(o.path)),n.length>0||!e.marketplacePlanned}function me(r,e){let{plan:a,entries:s}=e,t=a.profile==="local-analysis"?a.context.dir??"":e.root??"",d=a.readers.find(l=>l.id==="marker")?.claim.wants[0],n=a.readers.some(l=>l.id==="code-scan"),f=new Map(s.map(l=>[l.path,l])),c=a.profile==="local-analysis"?a.selection.selected:a.selection.selectedPaths.flatMap(l=>f.has(l)?[f.get(l)]:[]),m=He(r)?C(r,{phase:"start",root:t,paths:s.map(l=>l.path),scanFlag:!!d||n}):void 0;return{..._(r)?{agentPages:xt(r,s,e.commit)}:{},version:1,profile:a.profile,root:t,entries:s,selected:[...c],..."mode"in a?{marketplaceMode:a.mode}:{},..."selectionPaths"in a?{marketplaceSelection:a.selectionPaths}:{},conventionPaths:a.profile==="hosted-import"||_(r)?$(r,s.map(l=>l.path),t).files.filter(l=>l.role!=="reference").map(l=>l.path):[],...e.admission?{admission:e.admission}:{},selectionRefused:a.selection.refused,requestedPaths:[],refused:[],files:{},cursor:0,treeTruncated:e.treeTruncated??!1,...a.profile==="hosted-import"?{hosted:{fallback:structuredClone(a.selection),weakCodeFallback:r.CF_IMPORT_WEAK_CODE_FALLBACK!=="0",codeMode:!1,needsExtraction:a.selection.needsExtraction}}:{},decision:m??(d?{kind:"marker",markerPath:d,scanIfBare:n}:{kind:"settled",markerPath:null,markerKind:null,scan:n}),phase:d?"marker":n?"scan":"files"}}async function At(r,e,a){if(e.version!==1)throw new Error("unsupported-import-checkpoint");e.agentPages&&(r=e.agentPages.settings,yt(e,a.commit));let s=pe(r,e.profile),t={...e,selected:[...e.selected],files:{...e.files},requestedPaths:[...e.requestedPaths],refused:[...e.refused],...e.hosted?{hosted:{...e.hosted}}:{},...e.managedReadPaths?{managedReadPaths:[...e.managedReadPaths]}:{}},{read:d,requestedReads:n,skillReads:f}=Ot(s,t,o=>a.read(o));if(await Lt(s,t,d))return O(s,t,n);if(await Mt(s,t,d))return O(s,t,n);if(ft(s,t),t.phase==="done")return a.resolvedCode&&ct(t,a.resolvedCode),O(s,t,n);if(t.phase==="manifest")return await mt(s,t,d),fe(t),O(s,t,n);if(t.phase==="marker"&&t.decision.kind==="marker"){let o=t.decision,p=o.markerPath,i=t.entries.find(g=>g.path===p);if(t.profile==="hosted-import"){let g=k(s,i,{purpose:"pointer",route:"github",root:t.root});if(!g.admitted)return t.refused.push({path:p,reason:g.reason}),t.decision={kind:"settled",markerPath:null,markerKind:null,scan:o.scanIfBare},t.phase=o.scanIfBare?"scan":"files",O(s,t,n)}X(s,t,[p],t.entries);let u=await d(i);if(u!==null&&(t.files[p]=u),t.decision=C(s,{phase:"read",pending:o,text:u}),t.markerPath=p,t.markerKind=t.decision.markerKind,t.markerKind!=="bare"){let g=t.profile==="hosted-import"?await a.listing():{entries:t.entries,truncated:!1};t.treeTruncated||=g.truncated;let P=await ht(s,{config:qe(u).config,markerDir:p.split("/").slice(0,-1).join("/"),selected:t.profile==="hosted-import"?[]:t.selected,admission:{...t.admission,root:t.root||void 0},modelReader:!1,priorRefused:t.refused,refusalMode:"append",requestedMode:"kept-and-refused",listing:async()=>g.entries});if(t.requestedPaths.push(...P.requestedPaths),t.refused=P.refused,t.agentPages&&P.selected){let h=new Set(P.requestedPaths);t.conventionPaths=[...new Set([...t.conventionPaths,...P.selected.filter(w=>h.has(w.path)).map(w=>w.path)])]}t.profile==="hosted-import"?Z(t,P.selected??[]):P.selected&&(t.selected=P.selected)}if(t.phase=t.decision.scan?"scan":"files",t.profile!=="hosted-import"||t.markerKind!=="bare"||t.decision.scan)return O(s,t,n)}if(t.phase==="scan"){if(!t.scan){let o=ot(s,t.entries,t.root,!0,t.decision.kind==="settled"?t.decision.scanPaths:void 0);t.scan=o.state,t.refused.push(...o.refused)}if(!q(t.scan)){let o=await rt(s,t.scan,d,{modelReader:!1,alreadyRead:new Map,size:{batch:et,parallel:4}});t.scan=o.scan,o.selection&&(t.ranked=o.selection.ranked)}return q(t.scan)&&Ct(s,t),O(s,t,n)}if(oe(s))for(let o of t.skillReferencePaths??[])f.add(o);let c=t.selected.slice(t.cursor,t.cursor+A),m=c.filter(o=>t.files[o.path]===void 0),l=await L(m,4,d);if(t.agentPages&&t.ranked&&t.scan?Bt(s,t,m,l):m.forEach((o,p)=>{l[p]!==null&&(t.files[o.path]=l[p])}),t.cursor+=c.length,oe(s)){let o=Object.fromEntries(Object.entries(t.files).filter(([h])=>t.selected.some(w=>w.path===h&&w.readBytes===void 0))),p=De(s,{entries:t.entries,selected:t.selected,files:o,root:t.root,admission:t.admission,referencePaths:t.skillReferencePaths});t.refused=T(t.refused,p.refused);for(let h of p.refused)f.has(h.path)&&delete t.files[h.path];if(t.cursor<t.selected.length)return O(s,t,n);let i=new Map(t.selected.map(h=>[h.path,h])),u=p.paths.filter(h=>!i.has(h)||i.get(h).readBytes!==void 0),g=new Set(u.filter(h=>i.has(h)));t.cursor-=t.selected.slice(0,t.cursor).filter(h=>g.has(h.path)).length,t.selected=t.selected.filter(h=>!g.has(h.path));for(let h of g)delete t.files[h];t.requestedPaths.push(...u),u.length&&(t.skillReferencePaths=[...t.skillReferencePaths??[],...u]);let P=new Map(t.entries.map(h=>[h.path,h]));t.selected.push(...u.map(h=>{let w=P.get(h);return{path:h,size:w.size,ref:w.ref}})),it(t,u,"fallback")}return t.cursor>=t.selected.length&&(t.phase=ze(s)&&t.ranked||y(s)?"manifest":"done"),fe(t),O(s,t,n)}async function ee(r,e){let a=me(r,e),s;do s=await At(r,a,{listing:async()=>({entries:e.entries,truncated:!1}),read:e.read}),a=s.state;while(a.phase!=="done");let t={};return a.markerPath!==void 0&&(t.markerPath=a.markerPath,t.markerKind=a.markerKind),a.ranked!==void 0&&(t.ranked=a.ranked,t.scan=a.scan),{files:s.files,settled:s.settled,skippedFiles:s.refused,...t}}function Dt(r){return r.CF_IMPORT_PROPOSAL!=="0"}var Gt=new Set(["secret","secret-content","out-of-scope"]);async function Wt(r,e,a,s,t,d,n){let f={...e.admission,purpose:"proposal",route:"local-folder"},c=k(r,s??{path:a},f);if(!c.admitted)return{reason:c.reason};if(!s)return{reason:n??"missing"};if(s.size>d)return{reason:"allowance"};try{let m=t??await(e.proposalRead??e.read)({...s,readBytes:void 0});if(m===null)return{reason:n??"unreadable"};let l=Buffer.byteLength(m),o=k(r,{path:a,size:l,text:m},f);return o.admitted?l>d?{reason:"allowance"}:{text:m}:{reason:o.reason}}catch(m){return m instanceof W?{reason:m.reason,invalidates:Gt.has(m.reason)}:{reason:"unreadable"}}}async function $t(r,e,a,s,t){let d=new Set(s.map(i=>i.path)),n=new Set(t.map(i=>i.path)),f=new Map(e.entries.map(i=>[i.path,i])),c=s.map(i=>({...f.get(i.path),readBytes:void 0})),m=i=>!d.has(i.path)&&!n.has(i.path),l=[...e.selection.selected.filter(m),...c],o=s.length||t.length?{...e.selection,selected:l,totalBytes:l.reduce((i,u)=>i+(u.readBytes??u.size),0),refused:e.selection.refused.filter(i=>!d.has(i.path))}:e.selection,p=e.evidence??{};if(t.length){let i=e.entries.filter(w=>!n.has(w.path)),{ranked:u,scan:g,markerPath:P,markerKind:h}=await ee(r,{entries:i,admission:e.admission,read:async w=>Object.hasOwn(a,w.path)?a[w.path]:null,plan:Y(r,{profile:"local-analysis",listing:i,selection:o})});p={ranked:u,scan:g,markerPath:P,markerKind:h}}return{...p,files:a,selection:o,settled:[...e.settled.filter(m),...c],skippedFiles:(e.skippedFiles??[]).filter(i=>!d.has(i.path)),...t.length?{invalidated:t}:{}}}async function te(r,e,a={}){if(!a.explicitScope&&!Dt(r)||!e.proposal)return;let s={...e.files},t=new Map(e.entries.map(p=>[p.path,p])),d=new Map(e.unavailable?.map(p=>[p.path,p.reason])),n={},f=[],c=[],m=new Set,l=new Set(e.settled.filter(p=>p.readBytes===void 0).map(p=>p.path)),o=Object.values(s).reduce((p,i)=>p+Buffer.byteLength(i),0);for(let p of e.proposal.files){let i=Ut.normalize(p.path.replace(/\\/g,"/")),u=Object.hasOwn(s,i)?Buffer.byteLength(s[i]):0,g=!e.proposalRead&&l.has(i)&&Object.hasOwn(s,i)?s[i]:void 0,P=m.has(i)?{reason:"duplicate"}:await Wt(r,e,i,t.get(i),g,ve.codeAgent.importBytes-o+u,d.get(i));if(m.add(i),"text"in P)o+=Buffer.byteLength(P.text)-u,s={...s,[i]:P.text},c.push({...p,path:i});else{let h=P.reason==="wrong-type"?"coding-guide":P.reason;n[h]=(n[h]??0)+1,P.invalidates&&Object.hasOwn(s,i)&&(o-=u,delete s[i],f.push({path:i,reason:P.reason}))}}return{...await $t(r,e,s,c,f),proposal:{...e.proposal,files:c},rejectedByReason:n}}function It(r,e=[],a){return e.find(s=>Ve(s.key,a)===r.id)?.folder??ne(r.files.length?r.files.map(s=>s.path):[r.sourceRef?.path??"."])}function Yt(r,e,a,s){let t=new Set(r.flatMap(f=>f.files.map(c=>c.path))),d=new Set(e.flatMap(f=>f.files.map(c=>c.path))),n=e.map(f=>It(f,a,s));return f=>d.has(f)||!t.has(f)&&n.some(c=>c==="."||c===""||f.startsWith(`${c}/`))}function Jt(r,e,a){let s=Object.fromEntries(Object.entries(e.files).filter(([o])=>a(o))),t=e.selection.selected.filter(o=>Object.hasOwn(s,o.path)),d=e.settled.filter(o=>a(o.path)),n=e.selection.refused.filter(o=>a(o.path)),f=e.selection.readingNotes,c=f?{instruction:f.instruction.filter(a),code:f.code.filter(a),agents:f.agents.filter(a)}:void 0,m=M(r,c??{instruction:[],code:[],agents:[]},d),l={...e.selection,selected:t,refused:n,readingNotes:c,skippedNote:m,totalBytes:t.reduce((o,p)=>o+(p.readBytes??p.size),0)};return{files:s,selection:l,settled:d,skippedFiles:e.skippedFiles.filter(o=>a(o.path)),invalidated:e.invalidated?.filter(o=>a(o.path))}}function Vt(r,e,a,s=[],t){let d=a??ne([...e]),n=r.filter(l=>l.kind==="agent").map(l=>{let o=It(l,s,t),p=o==="."||o===""||d===o||d.startsWith(`${o}/`);return{node:l,overlap:new Set(l.files.filter(i=>e.has(i.path)).map(i=>i.path)).size,containment:p?o.split("/").filter(i=>i&&i!==".").length+1:0}}).filter(l=>l.overlap||l.containment);n.sort((l,o)=>o.overlap-l.overlap||o.containment-l.containment);let[f,c]=n,m=!!f&&f.overlap===c?.overlap&&f.containment===c?.containment;return{target:m?void 0:f?.node,overlapping:n.filter(l=>l.overlap).map(l=>l.node),tied:m?n.filter(l=>l.overlap===f.overlap&&l.containment===f.containment).map(l=>l.node):[]}}function Qt(r,e,a){let s=new Set(r.map(n=>n.path)),t=!!a&&!r.some(n=>n.path===a.path&&n.role==="system prompt"),d=t?r.filter(n=>n.path!==a.path).map(n=>n.role==="system prompt"||n.role==="soul"?{...n,role:"reference"}:n):[...r];return d.push(...e.filter(n=>!s.has(n.path)&&n.path!==a?.path).map(n=>({path:n.path,role:n.role==="tools"||n.role==="config"?n.role:"reference",label:null}))),t&&d.unshift({path:a.path,role:"system prompt",label:null}),{files:d,promptChanged:t}}function Xt(r,e){let a=new Map(r.map(s=>[s.label,s]));for(let s of e)a.has(s.label)||a.set(s.label,s);return[...a.values()]}function Zt(r,e,a,s,t){return s.filter(d=>d.role==="tools"&&(/\.json$/i.test(d.path)||be(d.path)==="js")).flatMap(d=>Ce(r,e,a.files,{toolsPath:/\.json$/i.test(d.path)?d.path:null,toolsTsPath:/\.json$/i.test(d.path)?null:d.path,cliPath:null,mcpPath:null},t))}function eo(r,e,a,s,t,d){let n=Qt(s?.files??[],a,t),c={...s??{id:Je("",e.ruleResult.fragment.nodes.map(m=>m.id),()=>{})("agent"),kind:"agent",desc:le(null,n.files,!1),meta:null,tools:[],sourceRef:null},label:e.proposalSources.proposal.agentName,files:n.files,tools:Xt(s?.tools??[],Zt(r,e.repoKey,e.proposalSources,a,d))};return n.promptChanged&&t&&(c.desc=le(t.path,n.files,!1),c.sourceRef={path:t.path,line:null}),{agent:c,promptChanged:n.promptChanged}}function to(r,e,a,s,t){let{target:d,overlapping:n,tied:f}=a,{fragment:c}=r,m=new Set([e.id,...(t?[...n,...f]:c.nodes).map(i=>i.id)]);for(let i=-1;i!==m.size;){i=m.size;for(let u of c.edges)m.has(u.from)&&m.add(u.to)}let l=c.nodes.filter(i=>m.has(i.id)).map(i=>i===d?e:i);d||l.push(e);let o=c.edges.filter(i=>m.has(i.from)&&m.has(i.to)),p=r.codeAgents?.filter(i=>m.has(i.unitKey)).flatMap(i=>i.unitKey!==d?.id?[i]:s?[]:[{...i,name:e.label,ownFiles:e.files}]);return{fragment:{...c,nodes:l,edges:o},...p?{codeAgents:p}:{}}}function oo(r,e,a){let s=new Set(e.map(n=>n.path)),t=new Set([...r.flatMap(n=>n.files.map(f=>f.path)),...s]),d=s.size;return{fromProposal:d,fromRulesOnly:t.size-d,rejected:Object.values(a).reduce((n,f)=>n+f,0),rejectedByReason:a}}function jt(r){return r.files.some(e=>e.role==="system prompt"||e.role==="soul")}function so(r,e,a){if(e.some(t=>t.kind==="agent"&&!jt(t)))return new Set;let s=new Set([V({code:"no-prompt",detail:"no-conventions"},r),V({code:"no-prompt"},r),V({code:"no-prompt",folderAgentsFound:!0},r)]);return a!==void 0&&s.add(Xe(r,{scanned:a})),s}function Tt(r,e){let{ruleResult:a,proposalSources:s,root:t,repoKey:d,scopes:n,scanned:f,agentChoice:c}=e,m=a,{files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=s,g=[...a.warnings],P=s.proposal.files.map(v=>({...v,path:x(v.path,t)})),h=P.find(v=>v.role==="prompt"),w=!1;if(P.length){let v=Vt(m.fragment.nodes,new Set(P.map(E=>E.path)),h?.path,n,t);if(v.target||h||e.explicitScope){let{agent:E,promptChanged:B}=eo(r,e,P,v.target,h,g),I=c?.kind==="choose_agent";m={...m,...to(a,E,v,B,I)},I&&({files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=Jt(r,s,Yt(a.fragment.nodes,m.fragment.nodes,n,t))),w=jt(E);let H=so(d,m.fragment.nodes,f);g=g.filter(F=>!H.has(F))}}return{...m,files:l,selection:o,settled:p,skippedFiles:i,invalidated:u,...c&&!w&&!e.explicitScope?{agentChoice:c}:{},warnings:g,proposalCounts:oo(m.fragment.nodes,P,s.rejectedByReason)}}async function _t(r,e){let a=re(r,{entries:e.entries,paths:e.scope});if(a.tooLarge.length||a.unavailable.length||a.groups.length>1)throw new Error("bad_request");let s=new Map(e.proposal?.files.map(f=>[f.path,f])),t={agentName:e.proposal?.agentName??e.repoKey,files:e.scope.map(f=>s.get(f)??{path:f,role:"other"})},d=await te(r,{...e,proposal:t,files:{},settled:[],skippedFiles:[],selection:{selected:[],refused:[],totalBytes:0}},{explicitScope:!0});if(!d)throw new Error("bad_request");if(d.proposal.files.length!==new Set(e.scope).size)throw new Error("unavailable");let n=re(r,{entries:e.entries.map(f=>Object.hasOwn(d.files,f.path)?{...f,size:Buffer.byteLength(d.files[f.path])}:f),paths:Object.keys(d.files),inputBytes:Object.fromEntries(Object.entries(d.files).map(([f,c])=>[f,Ie(f,c)]))});if(n.tooLarge.length||n.unavailable.length||n.groups.length>1)throw new Error("bad_request");return d}function ao(r,e,a){return e.filter(s=>k(r,s,{purpose:"listing",route:"local-folder",...a}).admitted)}function Qs(r){let e=[],a=!1,s=Promise.resolve();return t=>new Promise((d,n)=>{e.push({entry:t,resolve:d,reject:n}),!a&&(a=!0,queueMicrotask(()=>{let f=e;e=[],a=!1,s=s.then(async()=>{try{let c=await r(f.map(m=>m.entry));if(c.length!==f.length)throw new Error("bad_request");f.forEach((m,l)=>m.resolve(c[l]))}catch(c){f.forEach(m=>m.reject(c))}})}))})}async function Xs(r,e){let a=je(r),s=a===void 0?void 0:new Set(a),t=S=>e.localListing?ao(r,S,e.admission):S,d=a===void 0?t(e.entries):e.entries.filter(S=>s.has(S.path)),n=Y(r,{profile:"local-analysis",listing:d,selection:e.selection}),f=a===void 0?await ee(r,{entries:d,read:e.read,admission:e.admission,plan:n}):{files:{},settled:[],skippedFiles:[]},{files:c,settled:m,skippedFiles:l,...o}=f,p=a!==void 0?await _t(r,{...e,entries:e.entries,scope:a}):await te(r,{proposal:e.proposal,entries:d,read:e.read,proposalRead:e.proposalRead,admission:e.admission,files:c,settled:m,skippedFiles:l,selection:n.selection,unavailable:e.proposalRefusals,evidence:o}),{files:i,settled:u,skippedFiles:g}=p??f,P=z({...p??o,key:e.repoKey,files:i},n.context.flags,void 0,{markerPolicy:"any-read"}),h=p?.selection??n.selection,w;if(a===void 0&&ke(r)&&e.repository){let S=e.repository,j=await We(r,{selected:{files:i,listedPaths:d.map(b=>b.path),fallbackName:Ze(e),skills:!0},selection:h,codeAgentsFound:Qe(r,P?.resolved,i),port:e.localListing?{context:()=>S.context(),read:(b,R)=>S.read(b,R),finish:b=>S.finish?.(b),list:async()=>{let b=await S.list();return{...b,entries:t(b.entries)}}}:S}),qt=new Set(Object.keys(i).map(b=>x(b,j.root)));if(i=j.files,h=j.selection,w=j.root,w!==void 0){g=g.map(R=>({...R,path:x(R.path,w)})),u=u.map(R=>({...R,path:x(R.path,w)}));let b=new Set(u.map(R=>R.path));u.push(...h.selected.filter(R=>!b.has(R.path)&&Object.hasOwn(i,R.path)))}g=T(g,j.skippedFiles).filter(b=>qt.has(b.path)||!Object.hasOwn(i,b.path))}let v={repoKey:e.repoKey,files:i,listedPaths:d.map(S=>x(S.path,w)),...w!==void 0?{root:w}:{},forLocal:!0,code:P},E=K(r,v),B=N(r,E),I=e.includeAgentPromptPaths?Te({codeAgents:B.codeAgents??[],conventions:E.conventions,root:w}):void 0,H=_e(r,{codeAgents:B.codeAgents??[],conventions:E.conventions,root:w,selection:e.membership}),F=p?Tt(r,{ruleResult:B,proposalSources:{...p,files:i,selection:h,settled:u,skippedFiles:g,invalidated:p.invalidated?.map(S=>({...S,path:x(S.path,w)}))},root:w,repoKey:e.repoKey,scopes:E.conventions.agentScopes,scanned:P?.resolved?.scanned,agentChoice:H,explicitScope:a!==void 0}):void 0,{settled:Nt,invalidated:he,...ue}=F??{...B,settled:u,invalidated:void 0};F&&(i=F.files,h=F.selection,u=Nt,g=F.skippedFiles);let ge=h.readingNotes?M(r,h.readingNotes,u):h.skippedNote,Pe=F?F.agentChoice:H;return{...ue,...Pe?{agentChoice:Pe}:{},...I?{agentPromptPaths:I}:{},files:i,...w!==void 0?{root:w}:{},skippedFiles:he?.length?T(g,he):g,...F?{proposalCounts:F.proposalCounts}:{},warnings:[...new Set([...ue.warnings,...ge?[ge]:[],...U(g)])],selection:h}}var ro=new Set(ut);function ta(r,e){for(let s of[...Object.keys(e.set),...e.clear])if(!ro.has(s))throw new Error(`Unknown analysis field: ${s}`);let a={...r,...e.set};for(let s of e.clear)a[s]=void 0;return a}async function no(r,e,a){let s=Object.entries(e).map(([d,n])=>({path:d,size:Buffer.byteLength(n),ref:d})),t=tt(r,s,a.root,!1,a.scanPaths);for(;!q(t);)t=await st(t,async d=>e[d.path]??null);return{scan:Q(r,t),summary:at(t)}}async function zt(r,e,a){let{repoKey:s,root:t,agentConfigurations:d,codingGuides:n,forLocal:f}=a,c=a.flags??Ne(r),m=Object.keys(e),l=C(r,{phase:"start",paths:m,root:t,scanFlag:c.scan}),o=l.kind==="marker"?C(r,{phase:"read",pending:l,text:e[l.markerPath]??null}):l,p=o.kind==="off"?null:o.markerPath,i=o.kind==="off"?null:o.markerKind;if(o.kind==="off"||!o.scan){let v=z({key:s,files:e,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:v})),scanned:!1,resolved:null}}let{scan:u,summary:g}=await no(r,e,{repoKey:s,root:t,scanPaths:o.scanPaths}),P=z({key:s,files:e,ranked:u,scan:g,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:P})),scanned:!0,resolved:P.resolved}}async function Kt(r,e){let{state:a,settings:s}=r;if(!Pt(s,a).splitCheck||!a.splitEstimateBase)return{next:"inspecting",set:{repoCursor:0},clear:[]};let d=r.execution.preparation?.capUsd??a.splitEstimateBase.capUsd,n={...a.splitEstimateBase,capUsd:d};xe(n,e.progress.log);let f=bt(s,a),c={next:"inspecting",set:{repoCursor:0,splitCheckPriced:!0,splitFindingsPriced:!0},clear:["splitEstimateBase"]};if(!f.length)return c;let m=Ye(J(await e.instructions())),l=f.reduce((g,{inventory:P})=>g+se(Buffer.byteLength(Rt({tools:m},{...P,findings:[]}).prompt))+se(m.SHAPE_FINDINGS_INPUT_BYTES),0),o=n.lines.find(g=>g.label==="Scope check"),p=ae(s,{template:"scope-findings"},"Scope check",Ae.mechanical,(o?.inputTokens??0)+f.length*Et,(o?.outputTokens??0)+f.length*Ft),i=n.lines.map(g=>g.label==="Scope check"?p:g);o||i.push(p),i.push(ae(s,{template:"derive-shape"},"Split check",vt,l,f.length*$e));let u=Fe(i,d);return Ee(u)?(c.estimate=n,c.clear.push("splitCheckPriced","splitFindingsPriced"),delete c.set.splitCheckPriced,delete c.set.splitFindingsPriced,e.progress.log({level:"warn",code:"analysis.split_check_over_cap",counts:{totalUsd:u.totalUsd,capUsd:u.capUsd}}),c.set.warnings=[...a.warnings??[],Oe]):c.estimate=u,c}var Ba=async(r,e)=>{e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let{state:a,settings:s}=r,t=a.repos??[];await Le(s,a,e.readers);let d=a.repoCursor??0;if(d>=t.length)return Kt(r,e);let n=t[d],f=r.execution.forLocal,c=f?a.mapped?.[d]?{fragment:gt(a,d),warnings:[]}:await zt(s,n.files??{},{repoKey:n.key,root:n.root,agentConfigurations:n.agentConfigurations??{},forLocal:!0}):void 0,m=c?(()=>{let u=ye(c.fragment,n.key);return{...u,warnings:[...c.warnings,...u.warnings]}})():St(s,n,wt(s,a),a.modelReader??!1,a.projectAgents,J(await e.instructions()).bundleText("model-reader-runtime-prompt")),l=!f&&n.sourceReadNotes?M(s,n.sourceReadNotes,n.selected??[],n.root):void 0,o=f?[]:U((n.refused??[]).filter(u=>u.reason==="secret-content")),p="virtualFiles"in m?m.virtualFiles:void 0,i=[...a.mapped??[]];return i[d]=m.fragment,{next:"mapping",clear:[],set:{...p?{repos:t.map((u,g)=>g===d?{...u,files:{...u.files,...p}}:u)}:{},mapped:i,warnings:[...a.warnings??[],...l?[`${n.key}: ${l}`]:[],...o,...m.warnings,...kt(n)],repoCursor:d+1}}};export{Dt as a,ao as b,Qs as c,Xs as d,ta as e,Ba as f};
1
+ import{A as Z,B as dt,C as pt,D as ct,E as ft,F as O,G as mt,H as ht,I as ut,J as gt,P as Pt,R as wt,V as kt,W as St,a as ie,b as Je,c as Ve,d as Qe,e as Xe,f as V,g as le,h as z,i as Ze,j as K,ja as bt,k as N,l as et,la as vt,m as tt,ma as Rt,n as ot,na as Ft,o as q,oa as Et,p as st,q as at,r as de,s as Q,t as rt,u as nt,v as A,w as pe,x as X,y as it,z as lt}from"./HH3HDT5K.js";import{a as Ye}from"./2IQN26TC.js";import{i as $e}from"./6JTHFDH3.js";import{a as J}from"./QDYMR6KS.js";import{a as We}from"./NWYNJHY4.js";import{g as _}from"./QENYFKG3.js";import{E as Ge,d as ze,e as M,f as Ke,g as Ne,h as qe,o as He,q as C,s as Ue,t as De,y as Y}from"./6E4K7JTI.js";import{a as L}from"./326F4XNG.js";import{b as T,c as U}from"./PISOGSJF.js";import{a as Te,b as _e,c as ne}from"./JLW44GIU.js";import{a as je,b as re}from"./GOBOE2SC.js";import{n as $}from"./AIS3FHQR.js";import{c as Ie}from"./QY57UR6E.js";import{a as Ae}from"./4H23CSUM.js";import{c as ae}from"./P5FCHJ7W.js";import{$ as D,Ca as ye,Fb as k,Lb as Le,Ta as Ce,hb as G,i as y,kb as Be,lb as Me,pb as W,u as oe}from"./QYYN4YKB.js";import{h as ke,k as Se}from"./LOODGUMW.js";import{a as ve}from"./MKYLK6DB.js";import{f as se,i as Fe,j as Ee,m as Oe,n as xe}from"./YDSB7UOR.js";import{c as Re,e as x}from"./C6X5GDG4.js";import{b as we}from"./724WZMYW.js";import{b as be}from"./ICJV6KIZ.js";import{posix as Ut}from"node:path";function Ot(r,e,a){let s=new Set(e.entries.map(l=>l.path)),t=new Set(G(r,[...s])),d=Object.fromEntries(Object.entries(e.files).filter(([l])=>e.selected.some(o=>o.path===l&&o.readBytes===void 0))),n=new Set(Me(r,[...s],d)),f=[],c=new Set;return{read:async l=>{if(n.has(l.path)||e.managedReadPaths?.includes(l.path)&&e.files[l.path]===void 0)return e.refused.push({path:l.path,reason:"unreadable"}),null;f.push(l);try{let o=await a(l);if(o!==null){if(c.has(l.path)){let p=k(r,{path:l.path,size:Buffer.byteLength(o),text:o},{...e.admission,purpose:"skill",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(y(r)||we(r)){let p=k(r,{path:l.path,text:o},{...e.admission,purpose:"override",route:"github",root:e.root,listing:s,managedFiles:e.files});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}if(e.phase==="manifest"){let p=k(r,{path:l.path,size:Buffer.byteLength(o)},{...e.admission,purpose:"pointer",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:l.path,reason:p.reason}),null}return o}}catch(o){if(o instanceof W&&(o.reason==="secret-content"||y(r)||c.has(l.path)||t.has(l.path)))return e.refused.push({path:l.path,reason:o.reason}),null;if(e.profile==="hosted-import"&&!c.has(l.path)&&!t.has(l.path))throw o}return e.refused.push({path:l.path,reason:"unreadable"}),null},requestedReads:f,skillReads:c}}import{createHash as Ht}from"node:crypto";function ce(r){return Ht("sha256").update(JSON.stringify(r.map(({path:e,ref:a,size:s})=>({path:e,ref:a,size:s})))).digest("hex")}function xt(r,e,a){return _(r)?{settings:Se(r),commit:a??ce(e),revisionKind:a===void 0?"listing":"commit",completed:[]}:void 0}function yt(r,e,a){let s=r.agentPages;if(!s)return;let t=a??s.listingEntries??r.entries,d=s.revisionKind??(s.commit===ce(s.listingEntries??r.entries)?"listing":"commit");if(d==="commit"&&e!==void 0&&s.commit!==e||d==="listing"&&s.commit!==ce(t))throw new Error("stale-agent-page");return s.commit}function Ct(r,e,a){e.ranked??=Q(r,e.scan,new Map);let s=new Map([...de(e.scan.plan),...Object.entries(e.agentPages?.actualSizes??{})]),t=ie(r,e.ranked,s,new Map,{files:{},...e.agentPages?{page:{commit:e.agentPages.commit,scope:e.root,continuation:a}}:{}});t.page&&(e.ranked={...e.ranked,agentPage:t.page,strong:t.strong,possible:t.window,notRead:t.notRead,notReadMore:t.notReadMore});let d=[...t.refused,...e.ranked.skippedFiles??[]];if(e.requestedPaths.push(...d.map(n=>n.path)),e.refused.push(...d),e.profile==="hosted-import"&&t.paths.length||t.page){let n=nt(r,[],t.paths,e.scan.plan);e.refused.push(...n.refused),e.profile==="hosted-import"?pt(e,n.selected):(lt(r,e),Z(e,n.selected))}else X(r,e,t.paths,e.scan.plan);e.phase=e.selected.length?"files":"done"}function Bt(r,e,a,s){let t={...e.agentPages.actualSizes};a.forEach((o,p)=>{s[p]!==null&&(t[o.path]=Buffer.byteLength(s[p]))}),e.agentPages={...e.agentPages,actualSizes:t};let d=new Map([...de(e.scan.plan),...Object.entries(t)]),n=new Map(Object.entries(e.files).map(([o,p])=>[o,Buffer.byteLength(p)])),f=new Set(e.skillReferencePaths),c=new Set([...e.conventionPaths,...dt(e),...f,...e.markerPath?[e.markerPath]:[]]);for(let o of a)if(c.has(o.path)&&t[o.path]!==void 0){let p=k(r,{path:o.path,size:t[o.path]},{purpose:f.has(o.path)?"skill":"pointer",route:"github",root:e.root,listing:new Set(e.entries.map(u=>u.path)),managedFiles:e.files}),i=Ge(n).left+(n.get(o.path)??0);p.admitted&&t[o.path]<=i?n.set(o.path,t[o.path]):e.refused.push({path:o.path,reason:p.admitted?"total":p.reason})}let m=ie(r,e.ranked,d,n),l=new Set(m.paths);a.forEach((o,p)=>{s[p]!==null&&(l.has(o.path)||c.has(o.path)&&n.has(o.path)?e.files[o.path]=s[p]:e.refused.push(m.refused.find(i=>i.path===o.path)??m.skippedFiles?.find(i=>i.path===o.path)??{path:o.path,reason:"total"}))}),e.ranked={...e.ranked,agentPage:m.page,strong:m.strong,possible:m.window}}function fe(r){let e=r.ranked,a=e?.agentPage;if(!a||r.phase!=="done")return;let s=[...e.agentInventory.strong,...e.agentInventory.possible],t=new Set(a.selected),d=new Set(a.refusals.map(c=>c.id)),n=s.filter(c=>t.has(D(c.prompt))&&!d.has(D(c.prompt))&&r.files[c.prompt.path]===void 0),f=[...a.refusals,...n.map(c=>({id:D(c.prompt),reason:r.refused.find(m=>m.path===c.prompt.path)?.reason??"missing"}))];r.ranked={...e,strong:e.strong.filter(c=>r.files[c.prompt.path]!==void 0),possible:e.possible.filter(c=>r.files[c.prompt.path]!==void 0),agentPage:{...a,refusals:f,partial:f.length>0,estimatedInputBytes:Object.values(r.files).reduce((c,m)=>c+Buffer.byteLength(m),0)}}}async function Mt(r,e,a){if(!y(r))return!1;let s=Be(r,e.entries.map(o=>o.path));if(!s.length)return!1;let t=new Set(s.flatMap(o=>o.agents)),d=new Map(e.selected.map(o=>[o.path,o])),n=new Set(e.selected.filter(o=>o.readBytes===void 0&&e.files[o.path]!==void 0).map(o=>o.path));e.managedReadPaths||(e.managedReadPaths=[],(e.scan||e.ranked)&&(delete e.scan,delete e.ranked,delete e.manifestReadPaths,e.phase!=="marker"&&(e.phase="scan")));let f=new Set([...e.managedReadPaths,...n]),c=e.entries.filter(o=>t.has(o.path)&&d.has(o.path)&&!f.has(o.path)),m=c.slice(0,A);if(!m.length)return!1;let l=await L(m,4,async o=>{let p=k(r,o,{...e.admission,purpose:"pointer",route:"github",root:e.root});return p.admitted?a(o):(e.refused.push({path:o.path,reason:p.reason}),null)});if(m.forEach((o,p)=>{l[p]!==null&&(e.files[o.path]=l[p],e.selected=e.selected.map(i=>i.path===o.path?o:i))}),e.managedReadPaths.push(...m.map(o=>o.path)),c.length>m.length){for(let o of Object.keys(e.files))!t.has(o)&&s.some(p=>Re(o,p.folder)!==null)&&delete e.files[o];e.cursor=0,(e.phase==="done"||e.phase==="manifest")&&(e.phase="files")}return!0}async function Lt(r,e,a){if(e.marketplacePlanned)return!1;let s=new Set(G(r,e.entries.map(o=>o.path)));if(!e.selected.some(o=>s.has(o.path)))return!1;let t=new Set(e.marketplaceReadPaths),n=e.selected.filter(o=>s.has(o.path)&&!t.has(o.path)).slice(0,A),f=await L(n,4,async o=>{let p=k(r,o,{...e.admission,purpose:"definition",route:"github",root:e.root});if(!p.admitted)return e.refused.push({path:o.path,reason:p.reason}),null;let u=(o.readBytes===void 0?e.files[o.path]:void 0)??await a({path:o.path,size:o.size,ref:o.ref});if(u===null)return null;let g=k(r,{path:o.path,size:Buffer.byteLength(u),text:u},{...e.admission,purpose:"definition",route:"github",root:e.root});return g.admitted?u:(e.refused.push({path:o.path,reason:g.reason}),null)});n.forEach((o,p)=>{f[p]!==null?e.files[o.path]=f[p]:delete e.files[o.path]}),e.marketplaceReadPaths=[...t,...n.map(o=>o.path)];let c=new Map(n.flatMap((o,p)=>f[p]===null?[]:[[o.path,Buffer.byteLength(f[p])]]));e.agentPages&&c.size&&(e.agentPages={...e.agentPages,listingEntries:e.agentPages.listingEntries??e.entries}),e.entries=e.entries.map(o=>c.has(o.path)?{...o,size:c.get(o.path)}:o);let m,l=e.marketplaceSelection?new Set(e.marketplaceSelection):void 0;do{let o=new Set(e.marketplaceReadPaths.filter(h=>e.files[h]===void 0)),p=e.entries.filter(h=>!o.has(h.path)&&(!l||l.has(h.path))),i=e.profile==="local-analysis"?Ke(r,p,e.root,{files:e.files}):Ue(r,p,e.root,{files:e.files,mode:e.marketplaceMode}),u="selected"in i?i.selected.map(h=>h.path):i.selectedPaths,g=new Set(u),P=new Map(p.map(h=>[h.path,h]));e.selected=u.map(h=>P.get(h)),e.selectionRefused=i.refused,e.hosted&&"selectedPaths"in i&&(e.hosted.fallback=i,e.hosted.codeMode||(e.hosted.needsExtraction=i.needsExtraction)),m=Object.keys(e.files).filter(h=>s.has(h)&&!g.has(h));for(let h of m)e.refused.push(i.refused.find(w=>w.path===h)??{path:h,reason:"total"});for(let h of Object.keys(e.files))g.has(h)||delete e.files[h]}while(m.length);return e.conventionPaths=$(r,e.entries.filter(o=>!s.has(o.path)||e.files[o.path]!==void 0).map(o=>o.path),e.root,{files:e.files}).files.filter(o=>o.role!=="reference").map(o=>o.path),e.cursor=0,e.marketplacePlanned=!e.selected.some(o=>s.has(o.path)&&!e.marketplaceReadPaths.includes(o.path)),n.length>0||!e.marketplacePlanned}function me(r,e){let{plan:a,entries:s}=e,t=a.profile==="local-analysis"?a.context.dir??"":e.root??"",d=a.readers.find(l=>l.id==="marker")?.claim.wants[0],n=a.readers.some(l=>l.id==="code-scan"),f=new Map(s.map(l=>[l.path,l])),c=a.profile==="local-analysis"?a.selection.selected:a.selection.selectedPaths.flatMap(l=>f.has(l)?[f.get(l)]:[]),m=He(r)?C(r,{phase:"start",root:t,paths:s.map(l=>l.path),scanFlag:!!d||n}):void 0;return{..._(r)?{agentPages:xt(r,s,e.commit)}:{},version:1,profile:a.profile,root:t,entries:s,selected:[...c],..."mode"in a?{marketplaceMode:a.mode}:{},..."selectionPaths"in a?{marketplaceSelection:a.selectionPaths}:{},conventionPaths:a.profile==="hosted-import"||_(r)?$(r,s.map(l=>l.path),t).files.filter(l=>l.role!=="reference").map(l=>l.path):[],...e.admission?{admission:e.admission}:{},selectionRefused:a.selection.refused,requestedPaths:[],refused:[],files:{},cursor:0,treeTruncated:e.treeTruncated??!1,...a.profile==="hosted-import"?{hosted:{fallback:structuredClone(a.selection),weakCodeFallback:r.CF_IMPORT_WEAK_CODE_FALLBACK!=="0",codeMode:!1,needsExtraction:a.selection.needsExtraction}}:{},decision:m??(d?{kind:"marker",markerPath:d,scanIfBare:n}:{kind:"settled",markerPath:null,markerKind:null,scan:n}),phase:d?"marker":n?"scan":"files"}}async function At(r,e,a){if(e.version!==1)throw new Error("unsupported-import-checkpoint");e.agentPages&&(r=e.agentPages.settings,yt(e,a.commit));let s=pe(r,e.profile),t={...e,selected:[...e.selected],files:{...e.files},requestedPaths:[...e.requestedPaths],refused:[...e.refused],...e.hosted?{hosted:{...e.hosted}}:{},...e.managedReadPaths?{managedReadPaths:[...e.managedReadPaths]}:{}},{read:d,requestedReads:n,skillReads:f}=Ot(s,t,o=>a.read(o));if(await Lt(s,t,d))return O(s,t,n);if(await Mt(s,t,d))return O(s,t,n);if(ft(s,t),t.phase==="done")return a.resolvedCode&&ct(t,a.resolvedCode),O(s,t,n);if(t.phase==="manifest")return await mt(s,t,d),fe(t),O(s,t,n);if(t.phase==="marker"&&t.decision.kind==="marker"){let o=t.decision,p=o.markerPath,i=t.entries.find(g=>g.path===p);if(t.profile==="hosted-import"){let g=k(s,i,{purpose:"pointer",route:"github",root:t.root});if(!g.admitted)return t.refused.push({path:p,reason:g.reason}),t.decision={kind:"settled",markerPath:null,markerKind:null,scan:o.scanIfBare},t.phase=o.scanIfBare?"scan":"files",O(s,t,n)}X(s,t,[p],t.entries);let u=await d(i);if(u!==null&&(t.files[p]=u),t.decision=C(s,{phase:"read",pending:o,text:u}),t.markerPath=p,t.markerKind=t.decision.markerKind,t.markerKind!=="bare"){let g=t.profile==="hosted-import"?await a.listing():{entries:t.entries,truncated:!1};t.treeTruncated||=g.truncated;let P=await ht(s,{config:qe(u).config,markerDir:p.split("/").slice(0,-1).join("/"),selected:t.profile==="hosted-import"?[]:t.selected,admission:{...t.admission,root:t.root||void 0},modelReader:!1,priorRefused:t.refused,refusalMode:"append",requestedMode:"kept-and-refused",listing:async()=>g.entries});if(t.requestedPaths.push(...P.requestedPaths),t.refused=P.refused,t.agentPages&&P.selected){let h=new Set(P.requestedPaths);t.conventionPaths=[...new Set([...t.conventionPaths,...P.selected.filter(w=>h.has(w.path)).map(w=>w.path)])]}t.profile==="hosted-import"?Z(t,P.selected??[]):P.selected&&(t.selected=P.selected)}if(t.phase=t.decision.scan?"scan":"files",t.profile!=="hosted-import"||t.markerKind!=="bare"||t.decision.scan)return O(s,t,n)}if(t.phase==="scan"){if(!t.scan){let o=ot(s,t.entries,t.root,!0,t.decision.kind==="settled"?t.decision.scanPaths:void 0);t.scan=o.state,t.refused.push(...o.refused)}if(!q(t.scan)){let o=await rt(s,t.scan,d,{modelReader:!1,alreadyRead:new Map,size:{batch:et,parallel:4}});t.scan=o.scan,o.selection&&(t.ranked=o.selection.ranked)}return q(t.scan)&&Ct(s,t),O(s,t,n)}if(oe(s))for(let o of t.skillReferencePaths??[])f.add(o);let c=t.selected.slice(t.cursor,t.cursor+A),m=c.filter(o=>t.files[o.path]===void 0),l=await L(m,4,d);if(t.agentPages&&t.ranked&&t.scan?Bt(s,t,m,l):m.forEach((o,p)=>{l[p]!==null&&(t.files[o.path]=l[p])}),t.cursor+=c.length,oe(s)){let o=Object.fromEntries(Object.entries(t.files).filter(([h])=>t.selected.some(w=>w.path===h&&w.readBytes===void 0))),p=De(s,{entries:t.entries,selected:t.selected,files:o,root:t.root,admission:t.admission,referencePaths:t.skillReferencePaths});t.refused=T(t.refused,p.refused);for(let h of p.refused)f.has(h.path)&&delete t.files[h.path];if(t.cursor<t.selected.length)return O(s,t,n);let i=new Map(t.selected.map(h=>[h.path,h])),u=p.paths.filter(h=>!i.has(h)||i.get(h).readBytes!==void 0),g=new Set(u.filter(h=>i.has(h)));t.cursor-=t.selected.slice(0,t.cursor).filter(h=>g.has(h.path)).length,t.selected=t.selected.filter(h=>!g.has(h.path));for(let h of g)delete t.files[h];t.requestedPaths.push(...u),u.length&&(t.skillReferencePaths=[...t.skillReferencePaths??[],...u]);let P=new Map(t.entries.map(h=>[h.path,h]));t.selected.push(...u.map(h=>{let w=P.get(h);return{path:h,size:w.size,ref:w.ref}})),it(t,u,"fallback")}return t.cursor>=t.selected.length&&(t.phase=ze(s)&&t.ranked||y(s)?"manifest":"done"),fe(t),O(s,t,n)}async function ee(r,e){let a=me(r,e),s;do s=await At(r,a,{listing:async()=>({entries:e.entries,truncated:!1}),read:e.read}),a=s.state;while(a.phase!=="done");let t={};return a.markerPath!==void 0&&(t.markerPath=a.markerPath,t.markerKind=a.markerKind),a.ranked!==void 0&&(t.ranked=a.ranked,t.scan=a.scan),{files:s.files,settled:s.settled,skippedFiles:s.refused,...t}}function Dt(r){return r.CF_IMPORT_PROPOSAL!=="0"}var Gt=new Set(["secret","secret-content","out-of-scope"]);async function Wt(r,e,a,s,t,d,n){let f={...e.admission,purpose:"proposal",route:"local-folder"},c=k(r,s??{path:a},f);if(!c.admitted)return{reason:c.reason};if(!s)return{reason:n??"missing"};if(s.size>d)return{reason:"allowance"};try{let m=t??await(e.proposalRead??e.read)({...s,readBytes:void 0});if(m===null)return{reason:n??"unreadable"};let l=Buffer.byteLength(m),o=k(r,{path:a,size:l,text:m},f);return o.admitted?l>d?{reason:"allowance"}:{text:m}:{reason:o.reason}}catch(m){return m instanceof W?{reason:m.reason,invalidates:Gt.has(m.reason)}:{reason:"unreadable"}}}async function $t(r,e,a,s,t){let d=new Set(s.map(i=>i.path)),n=new Set(t.map(i=>i.path)),f=new Map(e.entries.map(i=>[i.path,i])),c=s.map(i=>({...f.get(i.path),readBytes:void 0})),m=i=>!d.has(i.path)&&!n.has(i.path),l=[...e.selection.selected.filter(m),...c],o=s.length||t.length?{...e.selection,selected:l,totalBytes:l.reduce((i,u)=>i+(u.readBytes??u.size),0),refused:e.selection.refused.filter(i=>!d.has(i.path))}:e.selection,p=e.evidence??{};if(t.length){let i=e.entries.filter(w=>!n.has(w.path)),{ranked:u,scan:g,markerPath:P,markerKind:h}=await ee(r,{entries:i,admission:e.admission,read:async w=>Object.hasOwn(a,w.path)?a[w.path]:null,plan:Y(r,{profile:"local-analysis",listing:i,selection:o})});p={ranked:u,scan:g,markerPath:P,markerKind:h}}return{...p,files:a,selection:o,settled:[...e.settled.filter(m),...c],skippedFiles:(e.skippedFiles??[]).filter(i=>!d.has(i.path)),...t.length?{invalidated:t}:{}}}async function te(r,e,a={}){if(!a.explicitScope&&!Dt(r)||!e.proposal)return;let s={...e.files},t=new Map(e.entries.map(p=>[p.path,p])),d=new Map(e.unavailable?.map(p=>[p.path,p.reason])),n={},f=[],c=[],m=new Set,l=new Set(e.settled.filter(p=>p.readBytes===void 0).map(p=>p.path)),o=Object.values(s).reduce((p,i)=>p+Buffer.byteLength(i),0);for(let p of e.proposal.files){let i=Ut.normalize(p.path.replace(/\\/g,"/")),u=Object.hasOwn(s,i)?Buffer.byteLength(s[i]):0,g=!e.proposalRead&&l.has(i)&&Object.hasOwn(s,i)?s[i]:void 0,P=m.has(i)?{reason:"duplicate"}:await Wt(r,e,i,t.get(i),g,ve.codeAgent.importBytes-o+u,d.get(i));if(m.add(i),"text"in P)o+=Buffer.byteLength(P.text)-u,s={...s,[i]:P.text},c.push({...p,path:i});else{let h=P.reason==="wrong-type"?"coding-guide":P.reason;n[h]=(n[h]??0)+1,P.invalidates&&Object.hasOwn(s,i)&&(o-=u,delete s[i],f.push({path:i,reason:P.reason}))}}return{...await $t(r,e,s,c,f),proposal:{...e.proposal,files:c},rejectedByReason:n}}function It(r,e=[],a){return e.find(s=>Ve(s.key,a)===r.id)?.folder??ne(r.files.length?r.files.map(s=>s.path):[r.sourceRef?.path??"."])}function Yt(r,e,a,s){let t=new Set(r.flatMap(f=>f.files.map(c=>c.path))),d=new Set(e.flatMap(f=>f.files.map(c=>c.path))),n=e.map(f=>It(f,a,s));return f=>d.has(f)||!t.has(f)&&n.some(c=>c==="."||c===""||f.startsWith(`${c}/`))}function Jt(r,e,a){let s=Object.fromEntries(Object.entries(e.files).filter(([o])=>a(o))),t=e.selection.selected.filter(o=>Object.hasOwn(s,o.path)),d=e.settled.filter(o=>a(o.path)),n=e.selection.refused.filter(o=>a(o.path)),f=e.selection.readingNotes,c=f?{instruction:f.instruction.filter(a),code:f.code.filter(a),agents:f.agents.filter(a)}:void 0,m=M(r,c??{instruction:[],code:[],agents:[]},d),l={...e.selection,selected:t,refused:n,readingNotes:c,skippedNote:m,totalBytes:t.reduce((o,p)=>o+(p.readBytes??p.size),0)};return{files:s,selection:l,settled:d,skippedFiles:e.skippedFiles.filter(o=>a(o.path)),invalidated:e.invalidated?.filter(o=>a(o.path))}}function Vt(r,e,a,s=[],t){let d=a??ne([...e]),n=r.filter(l=>l.kind==="agent").map(l=>{let o=It(l,s,t),p=o==="."||o===""||d===o||d.startsWith(`${o}/`);return{node:l,overlap:new Set(l.files.filter(i=>e.has(i.path)).map(i=>i.path)).size,containment:p?o.split("/").filter(i=>i&&i!==".").length+1:0}}).filter(l=>l.overlap||l.containment);n.sort((l,o)=>o.overlap-l.overlap||o.containment-l.containment);let[f,c]=n,m=!!f&&f.overlap===c?.overlap&&f.containment===c?.containment;return{target:m?void 0:f?.node,overlapping:n.filter(l=>l.overlap).map(l=>l.node),tied:m?n.filter(l=>l.overlap===f.overlap&&l.containment===f.containment).map(l=>l.node):[]}}function Qt(r,e,a){let s=new Set(r.map(n=>n.path)),t=!!a&&!r.some(n=>n.path===a.path&&n.role==="system prompt"),d=t?r.filter(n=>n.path!==a.path).map(n=>n.role==="system prompt"||n.role==="soul"?{...n,role:"reference"}:n):[...r];return d.push(...e.filter(n=>!s.has(n.path)&&n.path!==a?.path).map(n=>({path:n.path,role:n.role==="tools"||n.role==="config"?n.role:"reference",label:null}))),t&&d.unshift({path:a.path,role:"system prompt",label:null}),{files:d,promptChanged:t}}function Xt(r,e){let a=new Map(r.map(s=>[s.label,s]));for(let s of e)a.has(s.label)||a.set(s.label,s);return[...a.values()]}function Zt(r,e,a,s,t){return s.filter(d=>d.role==="tools"&&(/\.json$/i.test(d.path)||be(d.path)==="js")).flatMap(d=>Ce(r,e,a.files,{toolsPath:/\.json$/i.test(d.path)?d.path:null,toolsTsPath:/\.json$/i.test(d.path)?null:d.path,cliPath:null,mcpPath:null},t))}function eo(r,e,a,s,t,d){let n=Qt(s?.files??[],a,t),c={...s??{id:Je("",e.ruleResult.fragment.nodes.map(m=>m.id),()=>{})("agent"),kind:"agent",desc:le(null,n.files,!1),meta:null,tools:[],sourceRef:null},label:e.proposalSources.proposal.agentName,files:n.files,tools:Xt(s?.tools??[],Zt(r,e.repoKey,e.proposalSources,a,d))};return n.promptChanged&&t&&(c.desc=le(t.path,n.files,!1),c.sourceRef={path:t.path,line:null}),{agent:c,promptChanged:n.promptChanged}}function to(r,e,a,s,t){let{target:d,overlapping:n,tied:f}=a,{fragment:c}=r,m=new Set([e.id,...(t?[...n,...f]:c.nodes).map(i=>i.id)]);for(let i=-1;i!==m.size;){i=m.size;for(let u of c.edges)m.has(u.from)&&m.add(u.to)}let l=c.nodes.filter(i=>m.has(i.id)).map(i=>i===d?e:i);d||l.push(e);let o=c.edges.filter(i=>m.has(i.from)&&m.has(i.to)),p=r.codeAgents?.filter(i=>m.has(i.unitKey)).flatMap(i=>i.unitKey!==d?.id?[i]:s?[]:[{...i,name:e.label,ownFiles:e.files}]);return{fragment:{...c,nodes:l,edges:o},...p?{codeAgents:p}:{}}}function oo(r,e,a){let s=new Set(e.map(n=>n.path)),t=new Set([...r.flatMap(n=>n.files.map(f=>f.path)),...s]),d=s.size;return{fromProposal:d,fromRulesOnly:t.size-d,rejected:Object.values(a).reduce((n,f)=>n+f,0),rejectedByReason:a}}function jt(r){return r.files.some(e=>e.role==="system prompt"||e.role==="soul")}function so(r,e,a){if(e.some(t=>t.kind==="agent"&&!jt(t)))return new Set;let s=new Set([V({code:"no-prompt",detail:"no-conventions"},r),V({code:"no-prompt"},r),V({code:"no-prompt",folderAgentsFound:!0},r)]);return a!==void 0&&s.add(Xe(r,{scanned:a})),s}function Tt(r,e){let{ruleResult:a,proposalSources:s,root:t,repoKey:d,scopes:n,scanned:f,agentChoice:c}=e,m=a,{files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=s,g=[...a.warnings],P=s.proposal.files.map(v=>({...v,path:x(v.path,t)})),h=P.find(v=>v.role==="prompt"),w=!1;if(P.length){let v=Vt(m.fragment.nodes,new Set(P.map(E=>E.path)),h?.path,n,t);if(v.target||h||e.explicitScope){let{agent:E,promptChanged:B}=eo(r,e,P,v.target,h,g),I=c?.kind==="choose_agent";m={...m,...to(a,E,v,B,I)},I&&({files:l,selection:o,settled:p,skippedFiles:i,invalidated:u}=Jt(r,s,Yt(a.fragment.nodes,m.fragment.nodes,n,t))),w=jt(E);let H=so(d,m.fragment.nodes,f);g=g.filter(F=>!H.has(F))}}return{...m,files:l,selection:o,settled:p,skippedFiles:i,invalidated:u,...c&&!w&&!e.explicitScope?{agentChoice:c}:{},warnings:g,proposalCounts:oo(m.fragment.nodes,P,s.rejectedByReason)}}async function _t(r,e){let a=re(r,{entries:e.entries,paths:e.scope});if(a.tooLarge.length||a.unavailable.length||a.groups.length>1)throw new Error("bad_request");let s=new Map(e.proposal?.files.map(f=>[f.path,f])),t={agentName:e.proposal?.agentName??e.repoKey,files:e.scope.map(f=>s.get(f)??{path:f,role:"other"})},d=await te(r,{...e,proposal:t,files:{},settled:[],skippedFiles:[],selection:{selected:[],refused:[],totalBytes:0}},{explicitScope:!0});if(!d)throw new Error("bad_request");if(d.proposal.files.length!==new Set(e.scope).size)throw new Error("unavailable");let n=re(r,{entries:e.entries.map(f=>Object.hasOwn(d.files,f.path)?{...f,size:Buffer.byteLength(d.files[f.path])}:f),paths:Object.keys(d.files),inputBytes:Object.fromEntries(Object.entries(d.files).map(([f,c])=>[f,Ie(f,c)]))});if(n.tooLarge.length||n.unavailable.length||n.groups.length>1)throw new Error("bad_request");return d}function ao(r,e,a){return e.filter(s=>k(r,s,{purpose:"listing",route:"local-folder",...a}).admitted)}function Qs(r){let e=[],a=!1,s=Promise.resolve();return t=>new Promise((d,n)=>{e.push({entry:t,resolve:d,reject:n}),!a&&(a=!0,queueMicrotask(()=>{let f=e;e=[],a=!1,s=s.then(async()=>{try{let c=await r(f.map(m=>m.entry));if(c.length!==f.length)throw new Error("bad_request");f.forEach((m,l)=>m.resolve(c[l]))}catch(c){f.forEach(m=>m.reject(c))}})}))})}async function Xs(r,e){let a=je(r),s=a===void 0?void 0:new Set(a),t=S=>e.localListing?ao(r,S,e.admission):S,d=a===void 0?t(e.entries):e.entries.filter(S=>s.has(S.path)),n=Y(r,{profile:"local-analysis",listing:d,selection:e.selection}),f=a===void 0?await ee(r,{entries:d,read:e.read,admission:e.admission,plan:n}):{files:{},settled:[],skippedFiles:[]},{files:c,settled:m,skippedFiles:l,...o}=f,p=a!==void 0?await _t(r,{...e,entries:e.entries,scope:a}):await te(r,{proposal:e.proposal,entries:d,read:e.read,proposalRead:e.proposalRead,admission:e.admission,files:c,settled:m,skippedFiles:l,selection:n.selection,unavailable:e.proposalRefusals,evidence:o}),{files:i,settled:u,skippedFiles:g}=p??f,P=z({...p??o,key:e.repoKey,files:i},n.context.flags,void 0,{markerPolicy:"any-read"}),h=p?.selection??n.selection,w;if(a===void 0&&ke(r)&&e.repository){let S=e.repository,j=await We(r,{selected:{files:i,listedPaths:d.map(b=>b.path),fallbackName:Ze(e),skills:!0},selection:h,codeAgentsFound:Qe(r,P?.resolved,i),port:e.localListing?{context:()=>S.context(),read:(b,R)=>S.read(b,R),finish:b=>S.finish?.(b),list:async()=>{let b=await S.list();return{...b,entries:t(b.entries)}}}:S}),qt=new Set(Object.keys(i).map(b=>x(b,j.root)));if(i=j.files,h=j.selection,w=j.root,w!==void 0){g=g.map(R=>({...R,path:x(R.path,w)})),u=u.map(R=>({...R,path:x(R.path,w)}));let b=new Set(u.map(R=>R.path));u.push(...h.selected.filter(R=>!b.has(R.path)&&Object.hasOwn(i,R.path)))}g=T(g,j.skippedFiles).filter(b=>qt.has(b.path)||!Object.hasOwn(i,b.path))}let v={repoKey:e.repoKey,files:i,listedPaths:d.map(S=>x(S.path,w)),...w!==void 0?{root:w}:{},forLocal:!0,code:P},E=K(r,v),B=N(r,E),I=e.includeAgentPromptPaths?Te({codeAgents:B.codeAgents??[],conventions:E.conventions,root:w}):void 0,H=_e(r,{codeAgents:B.codeAgents??[],conventions:E.conventions,root:w,selection:e.membership}),F=p?Tt(r,{ruleResult:B,proposalSources:{...p,files:i,selection:h,settled:u,skippedFiles:g,invalidated:p.invalidated?.map(S=>({...S,path:x(S.path,w)}))},root:w,repoKey:e.repoKey,scopes:E.conventions.agentScopes,scanned:P?.resolved?.scanned,agentChoice:H,explicitScope:a!==void 0}):void 0,{settled:Nt,invalidated:he,...ue}=F??{...B,settled:u,invalidated:void 0};F&&(i=F.files,h=F.selection,u=Nt,g=F.skippedFiles);let ge=h.readingNotes?M(r,h.readingNotes,u):h.skippedNote,Pe=F?F.agentChoice:H;return{...ue,...Pe?{agentChoice:Pe}:{},...I?{agentPromptPaths:I}:{},files:i,...w!==void 0?{root:w}:{},skippedFiles:he?.length?T(g,he):g,...F?{proposalCounts:F.proposalCounts}:{},warnings:[...new Set([...ue.warnings,...ge?[ge]:[],...U(g)])],selection:h}}var ro=new Set(ut);function ta(r,e){for(let s of[...Object.keys(e.set),...e.clear])if(!ro.has(s))throw new Error(`Unknown analysis field: ${s}`);let a={...r,...e.set};for(let s of e.clear)a[s]=void 0;return a}async function no(r,e,a){let s=Object.entries(e).map(([d,n])=>({path:d,size:Buffer.byteLength(n),ref:d})),t=tt(r,s,a.root,!1,a.scanPaths);for(;!q(t);)t=await st(t,async d=>e[d.path]??null);return{scan:Q(r,t),summary:at(t)}}async function zt(r,e,a){let{repoKey:s,root:t,agentConfigurations:d,codingGuides:n,forLocal:f}=a,c=a.flags??Ne(r),m=Object.keys(e),l=C(r,{phase:"start",paths:m,root:t,scanFlag:c.scan}),o=l.kind==="marker"?C(r,{phase:"read",pending:l,text:e[l.markerPath]??null}):l,p=o.kind==="off"?null:o.markerPath,i=o.kind==="off"?null:o.markerKind;if(o.kind==="off"||!o.scan){let v=z({key:s,files:e,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:v})),scanned:!1,resolved:null}}let{scan:u,summary:g}=await no(r,e,{repoKey:s,root:t,scanPaths:o.scanPaths}),P=z({key:s,files:e,ranked:u,scan:g,markerPath:p,markerKind:i},c,void 0,{markerPolicy:"any-read"});return{...N(r,K(r,{repoKey:s,files:e,root:t,agentConfigurations:d,codingGuides:n,forLocal:f,code:P})),scanned:!0,resolved:P.resolved}}async function Kt(r,e){let{state:a,settings:s}=r;if(!Pt(s,a).splitCheck||!a.splitEstimateBase)return{next:"inspecting",set:{repoCursor:0},clear:[]};let d=r.execution.preparation?.capUsd??a.splitEstimateBase.capUsd,n={...a.splitEstimateBase,capUsd:d};xe(n,e.progress.log);let f=bt(s,a),c={next:"inspecting",set:{repoCursor:0,splitCheckPriced:!0,splitFindingsPriced:!0},clear:["splitEstimateBase"]};if(!f.length)return c;let m=Ye(J(await e.instructions())),l=f.reduce((g,{inventory:P})=>g+se(Buffer.byteLength(Rt({tools:m},{...P,findings:[]}).prompt))+se(m.SHAPE_FINDINGS_INPUT_BYTES),0),o=n.lines.find(g=>g.label==="Scope check"),p=ae(s,{template:"scope-findings"},"Scope check",Ae.mechanical,(o?.inputTokens??0)+f.length*Et,(o?.outputTokens??0)+f.length*Ft),i=n.lines.map(g=>g.label==="Scope check"?p:g);o||i.push(p),i.push(ae(s,{template:"derive-shape"},"Split check",vt,l,f.length*$e));let u=Fe(i,d);return Ee(u)?(c.estimate=n,c.clear.push("splitCheckPriced","splitFindingsPriced"),delete c.set.splitCheckPriced,delete c.set.splitFindingsPriced,e.progress.log({level:"warn",code:"analysis.split_check_over_cap",counts:{totalUsd:u.totalUsd,capUsd:u.capUsd}}),c.set.warnings=[...a.warnings??[],Oe]):c.estimate=u,c}var Ba=async(r,e)=>{e.progress.assertHeld(),e.progress.signal?.throwIfAborted();let{state:a,settings:s}=r,t=a.repos??[];await Le(s,a,e.readers);let d=a.repoCursor??0;if(d>=t.length)return Kt(r,e);let n=t[d],f=r.execution.forLocal,c=f?a.mapped?.[d]?{fragment:gt(a,d),warnings:[]}:await zt(s,n.files??{},{repoKey:n.key,root:n.root,agentConfigurations:n.agentConfigurations??{},forLocal:!0}):void 0,m=c?(()=>{let u=ye(c.fragment,n.key);return{...u,warnings:[...c.warnings,...u.warnings]}})():St(s,n,wt(s,a),a.modelReader??!1,a.projectAgents,J(await e.instructions()).bundleText("model-reader-runtime-prompt")),l=!f&&n.sourceReadNotes?M(s,n.sourceReadNotes,n.selected??[],n.root):void 0,o=f?[]:U((n.refused??[]).filter(u=>u.reason==="secret-content")),p="virtualFiles"in m?m.virtualFiles:void 0,i=[...a.mapped??[]];return i[d]=m.fragment,{next:"mapping",clear:[],set:{...p?{repos:t.map((u,g)=>g===d?{...u,files:{...u.files,...p}}:u)}:{},mapped:i,warnings:[...a.warnings??[],...l?[`${n.key}: ${l}`]:[],...o,...m.warnings,...kt(n)],repoCursor:d+1}}};export{Dt as a,ao as b,Qs as c,Xs as d,ta as e,Ba as f};