@counterfact-labs/cli 0.2.3 → 0.2.5

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 (154) hide show
  1. package/README.md +7 -1
  2. package/bundle/client-release.json +1 -1
  3. package/dist/adapters/anthropic.js +11 -2
  4. package/dist/adapters/completion.js +3 -0
  5. package/dist/adapters/durable-write.js +9 -2
  6. package/dist/adapters/files.js +29 -13
  7. package/dist/adapters/git-ignore.js +28 -14
  8. package/dist/adapters/git.js +1 -1
  9. package/dist/adapters/gitignore-output.js +41 -0
  10. package/dist/adapters/models.js +1 -6
  11. package/dist/adapters/output-paths.js +5 -2
  12. package/dist/adapters/public-instructions.js +1 -1
  13. package/dist/adapters/relay-plan.js +4 -7
  14. package/dist/adapters/release.js +10 -4
  15. package/dist/adapters/repository-files.js +164 -4
  16. package/dist/adapters/repository-root.js +18 -2
  17. package/dist/adapters/results.js +8 -4
  18. package/dist/adapters/settings.js +27 -1
  19. package/dist/adapters/snapshot.js +86 -15
  20. package/dist/analysis-core/analysis/finding-audience-switch.js +1 -0
  21. package/dist/analysis-core/analysis/schemas.js +1 -1
  22. package/dist/analysis-core/analysis/source-notes/types.js +1 -1
  23. package/dist/analysis-core/chunks/377MLK4M.js +21 -0
  24. package/dist/analysis-core/chunks/3GUKUEEJ.js +1 -0
  25. package/dist/analysis-core/chunks/{Y5AUKKYG.js → 3JWEFCTJ.js} +1 -1
  26. package/dist/analysis-core/chunks/{3227KXHF.js → 4H23CSUM.js} +1 -1
  27. package/dist/analysis-core/chunks/5DGPLXYB.js +1 -0
  28. package/dist/analysis-core/chunks/5TATKWLG.js +1 -0
  29. package/dist/analysis-core/chunks/{EH3QQ3T4.js → 6B2HILSY.js} +1 -1
  30. package/dist/analysis-core/chunks/6QY5BV5B.js +14 -0
  31. package/dist/analysis-core/chunks/6U2IR4XB.js +1 -0
  32. package/dist/analysis-core/chunks/A7WJJMRY.js +1 -0
  33. package/dist/analysis-core/chunks/C6X5GDG4.js +1 -0
  34. package/dist/analysis-core/chunks/DLPVYWHZ.js +1 -0
  35. package/dist/analysis-core/chunks/DZZBQDGO.js +1 -0
  36. package/dist/analysis-core/chunks/F3R4J3ND.js +1 -0
  37. package/dist/analysis-core/chunks/FOKDE64Y.js +1 -0
  38. package/dist/analysis-core/chunks/JKWTHRUR.js +1 -0
  39. package/dist/analysis-core/chunks/K2GNDX3W.js +1 -0
  40. package/dist/analysis-core/chunks/KTNA2KTN.js +7 -0
  41. package/dist/analysis-core/chunks/KWECQJ6X.js +1 -0
  42. package/dist/analysis-core/chunks/{SL27GMEN.js → M6HYSTQD.js} +1 -1
  43. package/dist/analysis-core/chunks/{VFENG4MR.js → MJGB25S5.js} +1 -1
  44. package/dist/analysis-core/chunks/{ZAA44GPI.js → N7U5N42V.js} +1 -1
  45. package/dist/analysis-core/chunks/NIOS7U6C.js +41 -0
  46. package/dist/analysis-core/chunks/{QPXNXMLC.js → OPMA32A6.js} +1 -1
  47. package/dist/analysis-core/chunks/PECX3OXB.js +1 -0
  48. package/dist/analysis-core/chunks/QFY6A3MS.js +66 -0
  49. package/dist/analysis-core/chunks/SKVEBOGA.js +1 -0
  50. package/dist/analysis-core/chunks/{VER355VN.js → STI4JE7L.js} +1 -1
  51. package/dist/analysis-core/chunks/SVMEWGD3.js +1 -0
  52. package/dist/analysis-core/chunks/X7WZAA7S.js +1 -0
  53. package/dist/analysis-core/chunks/YDBO7P4X.js +1 -0
  54. package/dist/analysis-core/chunks/YUY436SM.js +1 -0
  55. package/dist/analysis-core/chunks/ZTOVBAG7.js +1 -0
  56. package/dist/analysis-core/contracts/file-safety.js +1 -0
  57. package/dist/analysis-core/contracts/relay-analysis.js +1 -0
  58. package/dist/analysis-core/contracts/requests.js +1 -1
  59. package/dist/analysis-core/conventions/analysis-fit.js +1 -0
  60. package/dist/analysis-core/conventions/file-admission.js +1 -1
  61. package/dist/analysis-core/data/finding-types.js +1 -1
  62. package/dist/analysis-core/errors.js +1 -1
  63. package/dist/analysis-core/findings/sites.js +1 -0
  64. package/dist/analysis-core/github/repo-key.js +1 -1
  65. package/dist/analysis-core/import/outside-loader-sources.js +1 -1
  66. package/dist/analysis-core/index.js +3 -3
  67. package/dist/analysis-core/llm/cache-policy.js +1 -1
  68. package/dist/analysis-core/llm/cost.js +1 -1
  69. package/dist/analysis-core/llm/output-limit.js +1 -1
  70. package/dist/analysis-core/llm/types.js +1 -0
  71. package/dist/analysis-core/requests/answer-formats.js +1 -1
  72. package/dist/analysis-core/requests/headline-request.js +1 -1
  73. package/dist/analysis-core/requests/local-plan.js +1 -1
  74. package/dist/analysis-core/requests/registry.js +1 -1
  75. package/dist/analysis-core/requests/template-version.js +1 -1
  76. package/dist/analysis-core/requests/tools.js +1 -1
  77. package/dist/analysis-core/settings.js +1 -1
  78. package/dist/analysis-core/stages/engine-entry.js +1 -0
  79. package/dist/analysis-core/stages/execution-ports.js +1 -0
  80. package/dist/bundle/seal/deserialise.js +9 -1
  81. package/dist/bundle/seal/engine.js +76 -0
  82. package/dist/bundle/seal/freeze.js +9 -0
  83. package/dist/bundle/seal/metadata.js +3 -0
  84. package/dist/bundle/seal/open-engine.js +26 -0
  85. package/dist/bundle/seal/open.js +2 -8
  86. package/dist/bundle/seal/signature.js +2 -2
  87. package/dist/cli/commands/analyze.js +39 -5
  88. package/dist/cli/commands/finding.js +9 -3
  89. package/dist/cli/context.js +4 -1
  90. package/dist/cli/development-relay.js +34 -0
  91. package/dist/cli/finding-display.js +39 -0
  92. package/dist/cli/finding-lookup.js +92 -0
  93. package/dist/cli/finding-settings.js +5 -0
  94. package/dist/cli/fix-requests.js +42 -0
  95. package/dist/cli/intake-payload.js +19 -11
  96. package/dist/cli/main.js +9 -4
  97. package/dist/cli/mcp.js +65 -18
  98. package/dist/cli/relay-check.js +47 -14
  99. package/dist/cli/relay-preparation.js +31 -6
  100. package/dist/cli/result-check.js +68 -0
  101. package/dist/cli/summary.js +10 -3
  102. package/dist/contract/agent-choice.js +15 -0
  103. package/dist/contract/agent-proposal.js +38 -0
  104. package/dist/contract/attestation.js +106 -0
  105. package/dist/contract/cli-refusals.js +5 -0
  106. package/dist/contract/cli-version.js +1 -1
  107. package/dist/contract/console.js +41 -16
  108. package/dist/contract/engine.js +44 -0
  109. package/dist/contract/findings.js +28 -0
  110. package/dist/contract/fix-requests.js +30 -0
  111. package/dist/contract/messages.js +6 -94
  112. package/dist/contract/public-report.js +1 -0
  113. package/dist/contract/runtime-environment.js +12 -1
  114. package/dist/core/analysis/run-to-end.js +7 -52
  115. package/dist/gatekeeper/attestation.js +1 -1
  116. package/dist/gatekeeper/channel-binding.js +15 -0
  117. package/dist/gatekeeper/cli-api.js +12 -2
  118. package/dist/gatekeeper/connection-exchange.js +18 -13
  119. package/dist/gatekeeper/console.js +11 -4
  120. package/dist/gatekeeper/model.js +2 -1
  121. package/dist/gatekeeper/production-attestation.js +23 -17
  122. package/dist/gatekeeper/trust/policy.js +4 -1
  123. package/dist/gatekeeper/trust/schema.js +4 -0
  124. package/dist/transport/kms.js +25 -0
  125. package/package.json +4 -3
  126. package/dist/adapters/quality.js +0 -6
  127. package/dist/adapters/report.js +0 -29
  128. package/dist/analysis-core/analysis/analysis-flags.js +0 -1
  129. package/dist/analysis-core/analysis/finding-quality/config.js +0 -1
  130. package/dist/analysis-core/analysis/finding-quality/policy.js +0 -1
  131. package/dist/analysis-core/analysis/headlines/attachment.js +0 -1
  132. package/dist/analysis-core/analysis/headlines/input.js +0 -1
  133. package/dist/analysis-core/chunks/6YCABS5T.js +0 -1
  134. package/dist/analysis-core/chunks/7QDOHWSY.js +0 -27
  135. package/dist/analysis-core/chunks/BZNHHLNP.js +0 -1
  136. package/dist/analysis-core/chunks/DTMHXKP6.js +0 -7
  137. package/dist/analysis-core/chunks/EQTIRIMU.js +0 -37
  138. package/dist/analysis-core/chunks/G322LST6.js +0 -1
  139. package/dist/analysis-core/chunks/IL2KRP3T.js +0 -1
  140. package/dist/analysis-core/chunks/JF4GYMOZ.js +0 -1
  141. package/dist/analysis-core/chunks/KEKTZDIK.js +0 -1
  142. package/dist/analysis-core/chunks/M7MMAUAK.js +0 -1
  143. package/dist/analysis-core/chunks/OFBJNHC6.js +0 -1
  144. package/dist/analysis-core/chunks/ORCYIIHB.js +0 -60
  145. package/dist/analysis-core/chunks/PVPEY7NF.js +0 -1
  146. package/dist/analysis-core/chunks/STZOC7LN.js +0 -1
  147. package/dist/analysis-core/chunks/T5TREZCQ.js +0 -1
  148. package/dist/analysis-core/chunks/TDNTU4TF.js +0 -1
  149. package/dist/analysis-core/chunks/U5HOEVPE.js +0 -1
  150. package/dist/analysis-core/chunks/UEWL3GMQ.js +0 -1
  151. package/dist/analysis-core/chunks/YVDCJN7D.js +0 -14
  152. package/dist/analysis-core/chunks/ZMUBMYWN.js +0 -1
  153. package/dist/core/analysis/finding-quality/config.js +0 -4
  154. package/dist/core/analysis/structural-run.js +0 -16
@@ -1,11 +1,172 @@
1
1
  import { constants } from "node:fs";
2
+ import { createHash } from "node:crypto";
2
3
  import { lstat, open, opendir, realpath, stat } from "node:fs/promises";
3
- import { dirname, join, relative, sep } from "node:path";
4
+ import { join, relative, sep } from "node:path";
4
5
  import { READ_LIMITS } from "../analysis-core/import/outside-loader-sources.js";
5
6
  import { admitFile, FileReadRefusal, readRepoFile, resolveLocalExclusions } from "../analysis-core/conventions/file-admission.js";
6
7
  import { createGitIgnore } from "./git-ignore.js";
7
8
  import { createIgnoredFileCollector } from "./ignored-files.js";
8
- import { searchBaseMatches, searchBoundary } from "./repository-root.js";
9
+ import { readTargetMatches, searchBaseMatches, searchBoundary } from "./repository-root.js";
10
+ import { resolveLocalExclusions as safetyExclusions } from "../analysis-core/contracts/file-safety.js";
11
+ /** The transport lists permitted bytes without deciding their role in an agent. */
12
+ export async function createAnalysisFileSource(settings, root, admission, signal, options = {}) {
13
+ const guarded = { ...settings, CF_LOCAL_SYMLINK_GUARD: "1" };
14
+ const expectedBoundary = (await searchBoundary(root))?.base ?? null;
15
+ const excludedTargets = await safetyExclusions(admission, async (path) => realpath(join(root, path)).catch(() => null));
16
+ const committed = options.committed && new Set([...options.committed].flatMap(path => {
17
+ const parts = path.split("/");
18
+ return parts.map((_, index) => parts.slice(0, index + 1).join("/"));
19
+ }));
20
+ const permission = async (path) => {
21
+ signal?.throwIfAborted();
22
+ if (committed && !committed.has(path))
23
+ return { admitted: false, reason: "out-of-scope" };
24
+ const lexical = admitFile(guarded, { path }, { ...admission, purpose: "listing", route: "local-folder" });
25
+ if (!lexical.admitted)
26
+ return lexical;
27
+ const target = await realpath(join(root, path));
28
+ if (relative(root, target).split(sep).includes(".git"))
29
+ return { admitted: false, reason: "out-of-scope" };
30
+ const currentExclusions = await safetyExclusions(admission, async (path) => realpath(join(root, path)).catch(() => null));
31
+ const canonical = relative(root, target).split(sep).join("/");
32
+ if (committed && !committed.has(canonical))
33
+ return { admitted: false, reason: "out-of-scope" };
34
+ const ask = { ...admission, purpose: "listing", route: "local-folder", localTarget: { root, path: target, excludedTargets: [...excludedTargets, ...currentExclusions] } };
35
+ const lexicalTarget = admitFile(guarded, { path }, ask);
36
+ const allowed = lexicalTarget.admitted ? admitFile(guarded, { path: canonical }, ask) : lexicalTarget;
37
+ return allowed.admitted ? { admitted: true, target } : allowed;
38
+ };
39
+ const admittedCapture = async (file) => {
40
+ try {
41
+ const current = await permission(file.path);
42
+ if (!current.admitted)
43
+ return current;
44
+ if (current.target !== file.target || !await readTargetMatches(file.target, expectedBoundary))
45
+ return { admitted: false, reason: "out-of-scope" };
46
+ const info = await stat(current.target, { bigint: true });
47
+ return info.isFile() && info.dev === file.device && info.ino === file.inode
48
+ ? { admitted: true } : { admitted: false, reason: "out-of-scope" };
49
+ }
50
+ catch {
51
+ signal?.throwIfAborted();
52
+ return { admitted: false, reason: "unreadable" };
53
+ }
54
+ };
55
+ return {
56
+ allowed: admittedCapture,
57
+ async capture(accept, existing = new Map()) {
58
+ let entriesVisited = 0, truncated = false;
59
+ const maxBytes = options.maxBytes ?? READ_LIMITS.archive.bytes;
60
+ const directories = new Set();
61
+ const targets = new Set();
62
+ async function walk(dir, prefix) {
63
+ signal?.throwIfAborted();
64
+ if (directories.has(dir))
65
+ return;
66
+ directories.add(dir);
67
+ const handle = await opendir(dir);
68
+ try {
69
+ while (true) {
70
+ signal?.throwIfAborted();
71
+ if (entriesVisited >= READ_LIMITS.archive.files) {
72
+ truncated = true;
73
+ return;
74
+ }
75
+ const item = await handle.read();
76
+ if (!item)
77
+ return;
78
+ entriesVisited++;
79
+ // Administrative markers are local boundary evidence, never analysis inputs.
80
+ if (item.name === ".git")
81
+ continue;
82
+ const path = prefix ? `${prefix}/${item.name}` : item.name;
83
+ let allowed;
84
+ try {
85
+ allowed = await permission(path);
86
+ }
87
+ catch {
88
+ signal?.throwIfAborted();
89
+ continue;
90
+ }
91
+ if (!allowed.admitted)
92
+ continue;
93
+ const target = allowed.target;
94
+ const info = await stat(target, { bigint: true }).catch(() => null);
95
+ if (!info)
96
+ continue;
97
+ if (info.isDirectory()) {
98
+ if (await lstat(join(target, ".git")).then(() => true, error => error.code !== "ENOENT"))
99
+ continue;
100
+ await walk(target, relative(root, target).split(sep).join("/"));
101
+ if (entriesVisited >= READ_LIMITS.archive.files)
102
+ return;
103
+ }
104
+ else if (info.isFile() && !targets.has(target)) {
105
+ const canonical = relative(root, target).split(sep).join("/");
106
+ const prior = existing.get(target);
107
+ if (prior) {
108
+ const current = { ...prior, path: canonical };
109
+ if (prior.device === info.dev && prior.inode === info.ino && (await admittedCapture(current)).admitted)
110
+ accept(current);
111
+ targets.add(target);
112
+ continue;
113
+ }
114
+ if (info.size > BigInt(maxBytes)) {
115
+ truncated = true;
116
+ continue;
117
+ }
118
+ let input, bytes;
119
+ try {
120
+ input = await open(target, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
121
+ const before = await input.stat({ bigint: true });
122
+ if (!before.isFile() || before.dev !== info.dev || before.ino !== info.ino || before.size !== info.size)
123
+ continue;
124
+ bytes = Buffer.alloc(65_536);
125
+ const hash = createHash("sha256");
126
+ const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
127
+ let offset = 0;
128
+ while (offset < Number(before.size)) {
129
+ signal?.throwIfAborted();
130
+ const { bytesRead } = await input.read(bytes, 0, Math.min(bytes.length, Number(before.size) - offset), offset);
131
+ if (!bytesRead)
132
+ break;
133
+ const part = bytes.subarray(0, bytesRead);
134
+ hash.update(part);
135
+ decoder.decode(part, { stream: true });
136
+ offset += bytesRead;
137
+ }
138
+ decoder.decode();
139
+ const after = await input.stat({ bigint: true });
140
+ if (offset !== Number(before.size) || before.size !== after.size || before.mtimeNs !== after.mtimeNs || before.ctimeNs !== after.ctimeNs)
141
+ continue;
142
+ const file = { path: canonical, target, size: offset, hash: hash.digest("hex"), device: before.dev, inode: before.ino };
143
+ await options.verify?.(file);
144
+ // Git verification can yield while local permissions or checkout boundaries change.
145
+ if (!(await admittedCapture(file)).admitted)
146
+ continue;
147
+ targets.add(target);
148
+ accept(file);
149
+ }
150
+ catch {
151
+ signal?.throwIfAborted();
152
+ }
153
+ finally {
154
+ // Clear source bytes before the buffer's memory is reused; decoded strings are left to garbage collection.
155
+ bytes?.fill(0);
156
+ await input?.close();
157
+ }
158
+ }
159
+ }
160
+ }
161
+ finally {
162
+ await handle.close().catch(() => { });
163
+ }
164
+ }
165
+ await walk(root, "");
166
+ return { entriesVisited, truncated };
167
+ },
168
+ };
169
+ }
9
170
  /** Construction does no I/O. Discovery is initialized only by the owner's request. */
10
171
  export function createRepositoryFiles(settings, folder, admission = {}, options = {}) {
11
172
  const guarded = { ...settings, CF_LOCAL_SYMLINK_GUARD: "1" };
@@ -162,8 +323,7 @@ export function createRepositoryFiles(settings, folder, admission = {}, options
162
323
  const allowed = await admit(ctx, entry.path, target, entry.size);
163
324
  if (!allowed.admitted)
164
325
  return { text: null, bytesRead, refusal: allowed.reason };
165
- const boundary = await searchBoundary(dirname(target));
166
- if (!boundary || !await searchBaseMatches(boundary.base, ctx.base))
326
+ if (!await readTargetMatches(target, ctx.base))
167
327
  return { text: null, bytesRead, refusal: "out-of-scope" };
168
328
  const capacity = Math.min(maxBytes, READ_LIMITS.codeScan.fileBytes + 1);
169
329
  if (!Number.isSafeInteger(capacity) || capacity <= 0)
@@ -1,10 +1,13 @@
1
1
  import { access, constants, lstat, open, realpath, stat } from "node:fs/promises";
2
2
  import { dirname, join, relative, resolve, sep } from "node:path";
3
- export async function gitRepositoryRoot(git) {
3
+ /** Supplying a folder limits failed lookup fallback to confirmed standalone folders. */
4
+ export async function gitRepositoryRoot(git, standaloneFolder) {
4
5
  try {
5
6
  return (await git(["rev-parse", "--show-toplevel"])).replace(/\n$/, "");
6
7
  }
7
- catch {
8
+ catch (error) {
9
+ if (standaloneFolder !== undefined && await usableCheckoutBoundary(standaloneFolder))
10
+ throw error;
8
11
  return null;
9
12
  }
10
13
  }
@@ -118,3 +121,16 @@ export async function searchBaseMatches(base, repoRoot) {
118
121
  return false;
119
122
  }
120
123
  }
124
+ /** A failed repository proof leaves the selected folder available on its own. */
125
+ export async function analysisReadRoots(folder, repoRoot) {
126
+ const selected = await realpath(resolve(folder));
127
+ if (!(await stat(selected)).isDirectory())
128
+ throw new Error("unavailable");
129
+ const boundary = await searchBoundary(selected);
130
+ return { selected, repository: boundary && await searchBaseMatches(boundary.base, repoRoot) ? boundary : null };
131
+ }
132
+ /** A newly introduced checkout marker revokes a previously admitted target. */
133
+ export async function readTargetMatches(target, expectedBase) {
134
+ const boundary = await searchBoundary(dirname(target));
135
+ return expectedBase === null ? boundary === null : boundary !== null && await searchBaseMatches(boundary.base, expectedBase);
136
+ }
@@ -1,9 +1,13 @@
1
1
  import { formatSummary } from "../cli/summary.js";
2
+ import { ignoreDefaultOutput } from "./gitignore-output.js";
2
3
  import { writeOutputFiles } from "./output-paths.js";
3
- export async function saveLocalResults(folder, report, refusedFiles, outputDir) {
4
+ import { projectPublicReport } from "../contract/public-report.js";
5
+ export async function saveLocalResults(folder, report, refusedFiles, outputDir, options) {
6
+ const publicReport = projectPublicReport(report, refusedFiles);
4
7
  const [findingsPath, summaryPath] = await writeOutputFiles(folder, {
5
- "findings.json": `${JSON.stringify({ ...report, refusedFiles }, null, 2)}\n`,
6
- "summary.md": formatSummary(report),
8
+ "findings.json": `${JSON.stringify(publicReport, null, 2)}\n`,
9
+ "summary.md": formatSummary(publicReport, options),
7
10
  }, outputDir);
8
- return { findingsPath, summaryPath };
11
+ const ignoreAdded = await ignoreDefaultOutput(folder, outputDir, options);
12
+ return { findingsPath, summaryPath, ignoreAdded };
9
13
  }
@@ -1,4 +1,10 @@
1
1
  import { snapshotSettings } from "../analysis-core/settings.js";
2
+ // Local startup and retention checks share this profile; snapshots never fill it implicitly.
3
+ export const importerCoverageDefaults = Object.freeze({
4
+ CF_IMPORT_COVERAGE: "1", CF_IMPORT_LAYOUTS: "1", CF_IMPORT_MANIFEST: "1", CF_IMPORT_SCOPED_SCAN: "1",
5
+ CF_IMPORT_AGENT_PAGES: "1", CF_IMPORT_LEXICAL_FACTS: "1", CF_IMPORT_PROMPT_FIELDS: "1", CF_DISCOVERY_SKILLS: "1",
6
+ CF_IMPORT_SCOPES: "[]",
7
+ });
2
8
  // A run keeps its supplied switches even if the process environment later changes.
3
9
  export function readJobSettings(env = process.env) {
4
10
  return snapshotSettings(env);
@@ -13,7 +19,27 @@ export function newRunSettings(caller, env = process.env) {
13
19
  if (choice !== "0" && choice !== "1")
14
20
  throw new Error("CF_FINDING_HEADLINES must be 0 or 1.");
15
21
  const outside = caller?.CF_IMPORT_OUTSIDE_LOADERS || env.CF_IMPORT_OUTSIDE_LOADERS || "0";
16
- return snapshotSettings({ ...(caller ?? env), CF_FINDING_HEADLINES: choice, CF_IMPORT_OUTSIDE_LOADERS: outside });
22
+ const refuseTooLarge = caller?.CF_REFUSE_TOO_LARGE ?? env.CF_REFUSE_TOO_LARGE ?? "1";
23
+ // Inherit operator safety switches when integrations supply only analysis settings.
24
+ const committedOnly = caller?.CF_LOCAL_COMMITTED_ONLY ?? env.CF_LOCAL_COMMITTED_ONLY;
25
+ const gitignoreOutput = caller?.CF_LOCAL_GITIGNORE_OUTPUT ?? env.CF_LOCAL_GITIGNORE_OUTPUT;
26
+ const chooseAgent = caller?.CF_CHOOSE_AGENT ?? env.CF_CHOOSE_AGENT;
27
+ const findingAudience = caller?.CF_FINDING_AUDIENCE ?? env.CF_FINDING_AUDIENCE;
28
+ for (const [name, value] of Object.entries({ CF_LOCAL_COMMITTED_ONLY: committedOnly,
29
+ CF_LOCAL_GITIGNORE_OUTPUT: gitignoreOutput, CF_CHOOSE_AGENT: chooseAgent, CF_FINDING_AUDIENCE: findingAudience })) {
30
+ if (value !== undefined && value !== "0" && value !== "1")
31
+ throw new Error(`${name} must be 0 or 1.`);
32
+ }
33
+ const coverage = caller?.CF_IMPORT_COVERAGE ?? env.CF_IMPORT_COVERAGE ?? importerCoverageDefaults.CF_IMPORT_COVERAGE;
34
+ if (coverage !== "0" && coverage !== "1")
35
+ throw new Error("CF_IMPORT_COVERAGE must be 0 or 1.");
36
+ // Disabling coverage must not introduce feature choices into the earlier importer.
37
+ const importer = coverage === "1" ? Object.fromEntries(Object.entries(importerCoverageDefaults).map(([name, value]) => [name, caller?.[name] || env[name] || value])) : { CF_IMPORT_COVERAGE: coverage };
38
+ return snapshotSettings({ ...(caller ?? env), ...importer, CF_FINDING_HEADLINES: choice, CF_IMPORT_OUTSIDE_LOADERS: outside, CF_REFUSE_TOO_LARGE: refuseTooLarge,
39
+ ...(committedOnly === undefined ? {} : { CF_LOCAL_COMMITTED_ONLY: committedOnly }),
40
+ ...(gitignoreOutput === undefined ? {} : { CF_LOCAL_GITIGNORE_OUTPUT: gitignoreOutput }),
41
+ ...(chooseAgent === undefined ? {} : { CF_CHOOSE_AGENT: chooseAgent }),
42
+ ...(findingAudience === undefined ? {} : { CF_FINDING_AUDIENCE: findingAudience }) });
17
43
  }
18
44
  /** The installed command selects the relay; source-only switches remain on the development runner. */
19
45
  export function readCliSettings(env = process.env, emailSignIn) {
@@ -5,6 +5,11 @@ import { mapLimit } from "../analysis-core/map-limit.js";
5
5
  import { COMMITTED_FILES_MESSAGE } from "../contract/cli-refusals.js";
6
6
  import { gitRepositoryRoot } from "./repository-root.js";
7
7
  import { runGit } from "./git.js";
8
+ const snapshotRepository = async (folder) => `local/${basename(await realpath(resolve(folder)))}`;
9
+ function validateSnapshotPath(path) {
10
+ if (!path || path.includes("\\") || path.startsWith("/") || path.split("/").some(part => !part || part === "." || part === ".."))
11
+ throw new Error();
12
+ }
8
13
  async function snapshotContext(folder, revision = "HEAD", selectionFolder = folder) {
9
14
  const root = await realpath(resolve(folder));
10
15
  const git = (...args) => runGit(root, args, { maxBuffer: 16 * 1024 * 1024, timeout: 10000 });
@@ -15,33 +20,99 @@ async function snapshotContext(folder, revision = "HEAD", selectionFolder = fold
15
20
  const commit = (await git("rev-parse", "--verify", `${revision}^{commit}`)).toString("utf8").trim();
16
21
  if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(commit))
17
22
  throw new Error();
18
- const selection = await realpath(resolve(selectionFolder));
19
- return { repository: `local/${basename(selection)}`, commit, read: async (path, repositoryRelative = false) => {
20
- if (!path || path.includes("\\") || path.startsWith("/") || path.split("/").some(part => !part || part === "." || part === ".."))
21
- throw new Error();
23
+ return { repository: await snapshotRepository(selectionFolder), commit, read: async (path, repositoryRelative = false) => {
24
+ validateSnapshotPath(path);
22
25
  return git("cat-file", "blob", `${commit}:${prefix && !repositoryRelative ? `${prefix}/` : ""}${path}`);
23
26
  } };
24
27
  }
25
- /** Compare captured bytes to Git objects, so upload never rereads a changing working file. */
26
- export async function snapshotProvenance(folder, files, options = {}) {
28
+ const capturedHashes = (files) => Object.entries(files).map(([path, bytes]) => ({ path, hash: createHash("sha256").update(bytes).digest("hex") }));
29
+ export function sameFileHashes(saved, captured) {
30
+ const hashes = new Map(capturedHashes(captured).map(file => [file.path, file.hash]));
31
+ return saved.length > 0 && hashes.size === saved.length && new Set(saved.map(file => file.path)).size === saved.length
32
+ && saved.every(file => hashes.get(file.path) === file.hash.toLowerCase());
33
+ }
34
+ /** One pinned Git commit verifies captures made over several unpaid read batches. */
35
+ export async function createSnapshotVerifier(folder, options = {}) {
36
+ options.signal?.throwIfAborted();
27
37
  try {
28
- const context = await snapshotContext(folder, "HEAD", options.selectionFolder);
29
- if (!Object.keys(files).length)
30
- throw new Error();
31
- const hashes = await mapLimit(Object.entries(files), 4, async ([path, text]) => {
32
- if (!(await context.read(path)).equals(Buffer.from(text)))
33
- throw new Error();
34
- return { path, hash: createHash("sha256").update(text).digest("hex") };
38
+ const root = await realpath(resolve(folder));
39
+ const git = async (...args) => runGit(root, args, {
40
+ maxBuffer: options.maxBytes ?? 16 * 1024 * 1024, timeout: 10000, signal: options.signal,
35
41
  });
36
- return { repository: context.repository, commit: context.commit, files: hashes };
42
+ const found = await gitRepositoryRoot(async (args) => (await git(...args)).toString("utf8"));
43
+ if (found === null)
44
+ throw new Error();
45
+ const top = await realpath(found);
46
+ const prefix = relative(top, root).replaceAll("\\", "/");
47
+ const head = async () => (await git("rev-parse", "--verify", "HEAD^{commit}")).toString("utf8").trim();
48
+ const blob = (path) => {
49
+ validateSnapshotPath(path);
50
+ return git("cat-file", "blob", `${commit}:${path}`);
51
+ };
52
+ const commit = await head();
53
+ if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(commit) || options.expectedCommit !== undefined && commit !== options.expectedCommit)
54
+ throw new Error();
55
+ return { commit, repositoryRoot: top,
56
+ async list() {
57
+ options.signal?.throwIfAborted();
58
+ const paths = (await git("ls-tree", "--full-tree", "-r", "-z", "--name-only", commit)).toString("utf8").split("\0");
59
+ return new Set(paths.filter(Boolean));
60
+ },
61
+ async assertCurrent() {
62
+ options.signal?.throwIfAborted();
63
+ if (await head() !== commit)
64
+ throw new Error(COMMITTED_FILES_MESSAGE);
65
+ },
66
+ async read(path, hash) {
67
+ options.signal?.throwIfAborted();
68
+ const bytes = await blob(path);
69
+ if (createHash("sha256").update(bytes).digest("hex") !== hash)
70
+ throw new Error(COMMITTED_FILES_MESSAGE);
71
+ return bytes;
72
+ },
73
+ async verify(path, bytes) {
74
+ options.signal?.throwIfAborted();
75
+ if (!(await blob(prefix ? `${prefix}/${path}` : path)).equals(Buffer.from(bytes)))
76
+ throw new Error(COMMITTED_FILES_MESSAGE);
77
+ return { path, hash: createHash("sha256").update(bytes).digest("hex") };
78
+ },
79
+ };
37
80
  }
38
81
  catch {
82
+ options.signal?.throwIfAborted();
39
83
  throw new Error(COMMITTED_FILES_MESSAGE);
40
84
  }
41
85
  }
42
- /** Legacy recovery must prove the saved identity and hashes against this checkout, without reading working files. */
86
+ /** Hash captured bytes once; Git only supplies a commit when those exact bytes match HEAD. */
87
+ export async function snapshotProvenance(folder, files, options) {
88
+ const hashes = capturedHashes(files);
89
+ if (!hashes.length)
90
+ throw new Error(COMMITTED_FILES_MESSAGE);
91
+ let repository;
92
+ try {
93
+ repository = await snapshotRepository(options.selectionFolder ?? folder);
94
+ }
95
+ catch {
96
+ throw new Error(COMMITTED_FILES_MESSAGE);
97
+ }
98
+ let commit = null;
99
+ try {
100
+ const context = await snapshotContext(folder, "HEAD", options.selectionFolder);
101
+ const matches = await mapLimit(Object.entries(files), 4, async ([path, bytes]) => (await context.read(path)).equals(Buffer.from(bytes)));
102
+ if (matches.every(Boolean))
103
+ commit = context.commit;
104
+ }
105
+ catch { /* Captured bytes remain valid without a matching Git object. */ }
106
+ if (commit === null && options.committedOnly)
107
+ throw new Error(COMMITTED_FILES_MESSAGE);
108
+ return { repository, commit, files: hashes };
109
+ }
110
+ /** Immutable Git objects keep saved provenance verifiable after folder edits. */
43
111
  export async function matchesSnapshotProvenance(folder, saved) {
44
112
  try {
113
+ // A null-commit record has no immutable objects to check.
114
+ if (saved.commit === null)
115
+ return false;
45
116
  if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(saved.commit) || !saved.files.length)
46
117
  return false;
47
118
  const context = await snapshotContext(folder, saved.commit);
@@ -0,0 +1 @@
1
+ import{a,b}from"../chunks/A7WJJMRY.js";export{a as findingAudienceEnabled,b as findingAudienceSettings};
@@ -1 +1 @@
1
- import{Ab as o,mb as f,nb as g,ob as h,pb as i,vb as j,wb as k,xb as l,yb as m,zb as n}from"../chunks/EQTIRIMU.js";import"../chunks/74FPPPIG.js";import{c as a,d as b,e as c,f as d,g as e}from"../chunks/EH3QQ3T4.js";import"../chunks/KEKTZDIK.js";import"../chunks/FSLWD2PE.js";import"../chunks/JF4GYMOZ.js";import"../chunks/BZNHHLNP.js";import"../chunks/T5TREZCQ.js";import"../chunks/724WZMYW.js";export{j as MAX_FINDINGS,h as attachFiles,k as cleanFindings,m as cleanFixDelta,g as cleanFragment,d as findingsSchema,e as findingsSchemaFor,n as fingerprintOf,l as fixFingerprintOf,a as inspectFixSchema,i as mergeGraphs,f as normaliseBrand,o as numberLines,b as otherSiteSchema,c as rawFindingSchema};
1
+ import{Fb as g,Gb as h,Hb as i,Ib as j,Pb as k,Rb as l,Sb as m,Tb as n,Ub as o,Vb as p,Wb as q}from"../chunks/NIOS7U6C.js";import"../chunks/74FPPPIG.js";import"../chunks/5TATKWLG.js";import"../chunks/724WZMYW.js";import"../chunks/YUY436SM.js";import"../chunks/C6X5GDG4.js";import{c as b,d as c,e as d,f as e,g as f}from"../chunks/6B2HILSY.js";import"../chunks/JKWTHRUR.js";import"../chunks/SKVEBOGA.js";import"../chunks/3GUKUEEJ.js";import{a}from"../chunks/A7WJJMRY.js";import"../chunks/FSLWD2PE.js";export{l as MAX_FINDINGS,i as attachFiles,m as cleanFindings,o as cleanFixDelta,h as cleanFragment,a as findingAudienceEnabled,e as findingsSchema,f as findingsSchemaFor,p as fingerprintOf,n as fixFingerprintOf,k as groupByAudience,b as inspectFixSchema,j as mergeGraphs,g as normaliseBrand,q as numberLines,c as otherSiteSchema,d as rawFindingSchema};
@@ -1 +1 @@
1
- import{a as c}from"../../chunks/PYKAERZZ.js";import{a,c as b}from"../../chunks/UEWL3GMQ.js";import"../../chunks/FSLWD2PE.js";export{a as SOURCE_ROLES,c as rolesForCategory,b as sourceNotesSchema};
1
+ import{a as c}from"../../chunks/PYKAERZZ.js";import{d as a,e as b}from"../../chunks/KWECQJ6X.js";import"../../chunks/FSLWD2PE.js";export{a as SOURCE_ROLES,c as rolesForCategory,b as sourceNotesSchema};
@@ -0,0 +1,21 @@
1
+ import{c as Oe,e as Ut}from"./ZTOVBAG7.js";import{a as G,b as De,c as Bt,e as zt,f as Wt,g as Dt,h as Gt,i as Ge,j as Kt,k as Jt,m as qt,n as fe}from"./KTNA2KTN.js";import{b as de}from"./2PSNOSJ2.js";import{$ as wt,$a as $t,A as Z,C as dt,G as ut,I as Ie,J as le,Ja as St,K as ht,N as gt,O as ue,R as he,T as Se,Va as Ot,Wa as xt,Xa as Ct,Y as yt,Ya as Be,Z as kt,Za as Mt,_ as bt,a as lt,ab as ze,b as ft,bb as Ft,cb as We,d as Te,db as At,e as q,eb as jt,f as Pe,fb as Et,g as ct,gb as Rt,i as te,ia as vt,ib as Lt,jb as Nt,k as pt,kb as _t,l as ve,lb as Tt,m as ee,n as K,o as Q,p as oe,q as T,qb as It,r as B,ra as R,v as J,w as ne,y as mt}from"./NIOS7U6C.js";import{e as Pt}from"./YUY436SM.js";import{b as X,c as D}from"./C6X5GDG4.js";function Ke(e,t,o){if(!ee(e)||!t.filenameReferences?.length)return o;let r=o.agents.flatMap(s=>s.prompt.kind==="dedicated"?[{path:s.prompt.path}]:[]),i=Mt(t.filenameReferences,r);return{...o,agents:o.agents.map(s=>{if(s.prompt.kind!=="dedicated")return s;let c=s.prompt.path,l=i.filter(u=>u.promptPath===c&&!s.files.some(b=>b.path===u.readerPath)&&R(e,{path:u.readerPath},{purpose:"override",route:"github",root:t.root}).admitted);return l.length?{...s,files:[...s.files,...l.map(u=>({path:u.readerPath,role:"reference",label:"prompt filename reference"}))]}:s})}}function se(e,t,o){return e.filter(r=>t.some(i=>i.includes(o(r))))}function Yt(e,t,o){if(!e.length||o&&!K(o.settings))return;let r;if(o&&!q(o.settings)){let i=Object.keys(o.files).filter(l=>D(l,o.root)!==null&&R(o.settings,{path:l},{purpose:"override",route:"github",root:o.root}).admitted),s=i.filter(l=>lt(D(l,o.root))).sort((l,u)=>ft(D(l,o.root),D(u,o.root)));if(!s.length)return;let c=se(i.filter(l=>!s.includes(l)&&te(l)).sort(),s.map(l=>o.files[l]),l=>D(l,o.root));r=[...s.map(l=>({path:l,role:"reference",label:"developer guidance"})),...c.map(l=>({path:l,role:"reference",label:null}))]}else{if(!t||t.prompt.kind!=="fallback")return;let i=t.prompt.path;if(e.some(s=>s.files.some(c=>c.path===i)))return;r=t.files.map(s=>({...s,role:"reference",label:s.role==="system prompt"?"developer guidance":s.label}))}r=r.filter(i=>!e.some(s=>s.files.some(c=>c.path===i.path))),r.length&&(e[0]={...e[0],files:[...e[0].files,...r],sharedReferencePaths:[...e[0].sharedReferencePaths??[],...r.map(i=>i.path)]})}function yn({prompt:e,link:t}){return{path:t?.callPath??e.path,...t?{line:t.callLine}:{},symbol:e.symbol,promptPath:e.path,promptStart:e.start,...t?.kind==="L4"?{loadedPrompt:!0,...t.callStart!==void 0?{callStart:t.callStart}:{}}:{}}}function Vt(e,t,o){return It(e,t,o)}var xe=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).sort().join("-");function No(e,t,o,r={}){let i=new Map(e.map(s=>[xe(s),s]));return t.flatMap(s=>{let c=Object.hasOwn(o,s)?o[s]:void 0;if(c===void 0||!R(r,{path:s},{purpose:"code-support",route:"github"}).admitted)return[];let l=oe(s,c,Q(s)).toks;return l.flatMap((u,b)=>{if(!B(u))return[];let p=i.get(xe(u.text));if(!p)return[];let v=!1;if(B(l[b-1],"function")||B(l[b-1],"def"))v=T(l[b+1],"(");else if(["const","let","var"].some(m=>B(l[b-1],m))){for(let m=b+1;m<l.length&&m<b+80&&!T(l[m],";");m++)if(T(l[m],"=")){let f=B(l[m+1],"async")?m+2:m+1,y=T(l[f],"(")?J(l,f)+1:f+1;v=B(l[f],"function")||T(l[y],"=")&&T(l[y+1],">");break}}return v?[{name:p,sourcePath:s,sourceLine:u.line}]:[]})})}function Xt(e,t,o,r,i={}){let s=new Set(e.map(xe)),c=p=>R(i,{path:p},{purpose:"code-support",route:"github"}).admitted,l=p=>No(e,[p],o,i).length>0,u=t.filter(p=>c(p)&&l(p)),b=r.filter(p=>c(p)&&s.has(xe(p.split("/").at(-1).replace(/\.[^.]+$/,"")))&&(o[p]===void 0||l(p))).sort();return[...new Set([...u,...b])]}function Ce(e){return ee(e,"CF_IMPORT_MANIFEST")}function ge(e,t){if(!le(e))return null;let o=new Set(t.paths),r=ht(e,t),i=new Set(t.skillPaths),s=new Set(t.referencePaths),c=k=>Object.hasOwn(t.files,k)?Buffer.byteLength(t.files[k]):t.sizes?.get(k),l=t.selected??[...new Set([...t.skillPaths,...Object.keys(t.files).filter(k=>Ie(k,{nested:!0})?.reference)])].filter(k=>Object.hasOwn(t.files,k)).map(k=>({path:k,size:c(k)})),u=[...new Map(l.filter(k=>!s.has(k.path)||i.has(k.path)).map(k=>[k.path,k])).values()],b=new Set(u.map(k=>k.path)),p=u.filter(k=>i.has(k.path)),v=new Set(u.filter(k=>Ie(k.path,{nested:!0})?.reference).map(k=>k.path)),m=p.length,f=Z.conventionImport.skillBytes-u.filter(k=>i.has(k.path)||v.has(k.path)).reduce((k,P)=>k+(c(P.path)??P.size),0),y=ve(e)?Z.codeAgent.importBytes-u.reduce((k,P)=>k+(c(P.path)??P.size),0):1/0,h=new Map(p.map(k=>[k.path,null])),a=(k,P=!1)=>{if(h.has(k))return;let n=c(k),g=v.has(k),w=R(e,{path:k,size:n,text:t.files[k]},{...t.admission,purpose:"skill",route:"github",root:t.root,listing:o,managedFiles:t.files}),x=b.has(k)?0:n,C=w.admitted?n===void 0?"missing":!g&&m>=Z.conventionImport.skillFiles?"allowance":!g&&(n>f||x>y)?"total":null:w.reason;h.set(k,C),!g&&(P||!C)&&m++,!g&&!C&&(f-=n,y-=x)};for(let k of s)a(k,!0);let d=[...new Set(t.skillPaths)].sort().filter(k=>Object.hasOwn(t.files,k)).map(k=>{let P={ownerPath:k,files:[],cycles:[],unresolved:[],refused:[]},n=new Set([k]);for(let g of r.references.filter(w=>w.ownerPath===k)){if(!n.has(g.fromPath))continue;a(g.path);let w=h.get(g.path);if(w){P.refused.push({path:g.path,reason:w});continue}n.add(g.path);let x=P.files.find(C=>C.path===g.path);x||(x={path:g.path,evidence:[],sharedOwners:[]},P.files.push(x)),x.evidence.push(g)}return P.cycles=r.cycles.filter(g=>g.ownerPath===k&&n.has(g.fromPath)),P.unresolved=r.unresolved.filter(g=>g.ownerPath===k&&n.has(g.fromPath)),P.refused=de(P.refused),P}),S=new Map;for(let k of d)for(let P of k.files)S.set(P.path,[...S.get(P.path)??[],k.ownerPath]);for(let k of d)for(let P of k.files)P.sharedOwners=S.get(P.path);return d}var Zt="model call";function Qt(e,t){let o=Vt(e.ownPaths,t,e.toolCall);return{tools:o.tools.map(r=>({tool:r,from:o.from[r.name]})),toolWarnings:o.warnings}}function qe(e=new Map,t){return{left:Math.max(0,Z.codeAgent.importBytes-[...e.values()].reduce((o,r)=>o+r,0)),chosen:new Set([...e.keys()].filter(o=>!t?.has(o))),...t?{replacementBytes:t}:{}}}function _o(e,t){return e.modelId??(!e.documentation&&t.length===1?t[0]:null)}function qn(e,t,o){return To(e,_o(e,t),o)}function To(e,t,o){let{prompt:r,link:i}=e,s=[r.kind==="file"?{role:"system prompt",label:null,path:r.path}:{role:"system prompt",label:r.symbol??`line ${r.span.from}`,path:r.path,span:{from:r.span.from,to:r.span.to},...r.filledAtRunTime?{filledAtRunTime:!0}:{}}];for(let l of e.alsoLoads??[])s.push({role:"system prompt",label:"also loaded",path:l});i&&s.push({role:"code",label:Zt,path:i.callPath}),i?.wrapper&&s.push({role:"code",label:"model wrapper",path:i.wrapper.path}),t&&s.push({role:"code",label:"model setting",path:t.path}),e.shape&&s.push({role:"code",label:"answer shape",path:e.shape.path});let c=new Set;return s.filter(l=>!c.has(l.path)&&!!c.add(l.path)).map(l=>Pe(o,l.path,l.path===r.path&&e.promptSource==="marker")?l:{...l,role:"reference"})}function Un(e,t){let{prompt:o}=e,r=t[o.path]??"";return o.kind==="file"?r:r.split(`
2
+ `).slice(o.span.from-1,o.span.to).join(`
3
+ `)}function Yn(e,t){return t?Object.fromEntries(t.files.filter(o=>e[o.path]!==void 0).map(o=>[o.path,e[o.path]])):e}function Ht(e,t,o){let{files:r,sizes:i,root:s,total:c=qe()}=o,l=[...new Set([...t.ownPaths,...o.guides??[]])],u=[],b=new Set(l);l=l.filter(n=>{let g=R(e,{path:n},{purpose:"override",route:"github"});return g.admitted||u.push({path:n,reason:g.reason}),g.admitted});let p=[...i.keys()].filter(n=>{let g=R(e,{path:n},{purpose:"code-support",route:"github",root:s});return!g.admitted&&!b.has(n)&&u.push({path:n,reason:g.reason}),g.admitted}),v=Object.fromEntries(l.filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),m=Tt(v,p).filter(n=>!l.includes(n)),f=Object.fromEntries([...l,...m].filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),y=Qt({ownPaths:l,toolCall:t.toolCall},f).tools.map(({tool:n})=>n.name),h=new Set(Xt(y,m,r,p,e)),a=Je(e,l,{...o,total:c});for(let n of new Set([...l,...m,...h]))a.take(n,h.has(n)&&!l.includes(n));let{paths:d,skipped:S}=a,k=Object.fromEntries(d.filter(n=>r[n]!==void 0).map(n=>[n,r[n]])),P=Qt(t,k);return{paths:d,skipped:S,refused:de(u,a.refused),...P}}function Je(e,t,{sizes:o,total:r=qe(),pool:i},s=[]){let c=[],l=[],u=[],b=Z.codeAgent.extraBytes,p=0;return{paths:c,skipped:l,refused:u,take:(m,f,y=!1)=>{if(c.includes(m))return!0;let h=o.get(m),a=m===t[0],d=s.includes(m),S=[r,...i?[i]:[]],k=w=>Math.max(0,(h??0)-(w.replacementBytes?.get(m)??0)),P=d?"override":t.includes(m)||y?"pointer":"code-support",n=R(e,{path:m,size:h},{purpose:P,route:"github"});n.admitted||u.push({path:m,reason:n.reason});let g=h===void 0?"missing":n.admitted?!d&&!a&&h>b?"allowance":!d&&S.some(w=>!w.chosen.has(m)&&(k(w)>w.left||w.wholeBytesLeft!==void 0&&h>w.wholeBytesLeft))?"total":f&&p>=Z.codeAgent.toolCodeFiles?"tool-limit":null:n.reason;if(g)return l.push({path:m,reason:g}),!1;!a&&!d&&(b-=h),f&&p++;for(let w of S)w.chosen.has(m)||(w.left-=k(w),w.wholeBytesLeft!==void 0&&(w.wholeBytesLeft-=h),w.chosen.add(m));return c.push(m),!0}}}function eo(e,t,o){if(!Ce(e)&&!(ee(e)&&t.some(d=>d.fileProfile==="layout")))return null;let r=o.scopes??qt(e,[...o.sizes.keys()],o.root??void 0,{},o.agentConfigurations??{}),i=o.total??qe(),s=new Set(o.confirmationIds),c=o.selectedIds&&new Set(o.selectedIds),l=t.filter(d=>!c||c.has(d.id));for(let d of l)for(let{path:S}of d.ownFiles.filter(k=>d.fileProfile==="convention"||d.sharedReferencePaths?.includes(k.path))){let k=o.sizes.get(S),P=d.scopeProof?.paths.includes(S)?void 0:o.root;k===void 0||i.chosen.has(S)||!R(e,{path:S},{purpose:"override",route:"github",root:P}).admitted||(i.left-=Math.max(0,k-(i.replacementBytes?.get(S)??0)),i.wholeBytesLeft!==void 0&&(i.wholeBytesLeft-=k),i.chosen.add(S))}let u=(d,S)=>{for(let k of d){let P=k.ownFiles[0]?.path;if(!P)continue;let n=r.ownerOf(P);!n||n.key!==k.scope.key||n.folder!==k.scope.folder||!R(e,{path:P},{purpose:"pointer",route:"github",root:o.root}).admitted||Je(e,[P],{...o,total:S,pool:void 0}).take(P,!1)}};u(l,i);let b,p=new Set,v=new Set(o.sizes.keys()),m=Ft(v).flatMap(d=>o.files[d]===void 0?[]:We(d,o.files[d],v,{root:o.root??void 0})),f=new Map(m.map(d=>[d,d.to&&o.files[d.to]!==void 0?At(d.to,o.files[d.to],d.imported,v,e):[]])),y=new Set(m.filter(d=>{let S=d.to&&Q(d.to),k=d.to&&o.files[d.to];return S&&k!==void 0&&k!==null&&!ze(oe(d.to,k,S),d.imported)})),h=t.map(d=>{let S=[...new Set(d.ownFiles.map($=>$.path))],k=new Set(d.fileProfile==="layout"?d.ownFiles.filter($=>$.role==="tools").map($=>$.path):[]),P={schemaVersion:1,agentId:d.id,scope:{...d.scope},files:[],edges:[],unresolved:[],refused:[]};if(c&&!c.has(d.id))return P;s.has(d.id)&&!b&&(b={left:Z.candidateFetch.check,chosen:new Set(p)},u(l.filter($=>s.has($.id)),b));let n=Je(e,S,{...o,total:i,pool:s.has(d.id)?b:void 0},d.fileProfile==="convention"?S:d.sharedReferencePaths),g=new Set(d.skillManifests?.flatMap($=>$.files.map(O=>O.path))),w=d.ownFiles.filter($=>$.role!=="reference"||!g.has($.path)||d.independentReferences?.includes($.path)).map($=>({path:$.path,symbol:null,role:$.role,evidence:null,span:$.span})),x=m.filter($=>$.to!==null&&S.includes($.to)),C=x.filter($=>new Set(x.filter(O=>O.to===$.to).map(O=>O.imported)).size>1),A=m.filter($=>!y.has($)&&(x.includes($)&&!d.toolCall&&!C.includes($)||f.get($).some(O=>{if(O.kind!=="graph-node"||!O.to||!S.includes(O.to)||!d.toolCall||d.toolCall.path!==O.to)return!1;let z=o.files[O.to];return z!==void 0&&jt(O.to,z,O.imported,d.toolCall)})));P.unresolved.push(...x.filter($=>!A.includes($)).map($=>({...$,reason:y.has($)?"missing":"unlinked"})));for(let $ of A)w.push({path:$.from,symbol:$.symbol,role:"config",evidence:$,explicit:!0});let M=new Set,E=new Map,j=new Set,N=new Set;for(let $=0;$<w.length;$++){let O=w[$],z=JSON.stringify([O.path,O.symbol,O.role]);if(M.has(z)){let F=P.files.find(L=>L.path===O.path);F&&O.span&&!F.spans.some(L=>L.from===O.span.from&&L.to===O.span.to)&&(F.spans.push(O.span),F.evidence.push({kind:"entry",from:O.path,to:O.path,span:O.span})),F&&O.evidence?.kind==="skill-reference"&&!F.evidence.some(L=>JSON.stringify(L)===JSON.stringify(O.evidence))&&F.evidence.push(O.evidence);continue}M.add(z);let _=r.ownerOf(O.path),ie=S.includes(O.path)&&d.scopeProof?.paths.includes(O.path),ce=R(e,{path:O.path},{purpose:S.includes(O.path)||O.explicit?"pointer":"code-support",route:"github",root:ie?void 0:o.root}),Ne=O.role==="reference"&&S.includes(O.path)&&(d.sharedReferencePaths?.includes(O.path)||d.skillManifests?.some(F=>P.files.some(L=>L.path===F.ownerPath)&&F.files.some(L=>L.path===O.path)&&!F.refused.some(L=>L.path===O.path))),it=ce.admitted?!ie&&(!_||!Ne&&(_.key!==d.scope.key||_.folder!==d.scope.folder))?"out-of-scope":!S.includes(O.path)&&t.some(F=>F.id!==d.id&&F.ownFiles.some((L,Y)=>L.path===O.path&&(Y===0||L.label===Zt)))?"other-agent":null:ce.reason;if(it){P.refused.push({path:O.path,reason:it});continue}let ae=o.files[O.path],_e=Q(O.path),pe=ae!==void 0&&_e?oe(O.path,ae,_e):null,me=pe&&O.symbol?ze(pe,O.symbol):null,H=me?.name??O.symbol;if(ae!==void 0&&!E.has(O.path)){let F=m.filter(I=>I.from===O.path),L=[...F.length?F:We(O.path,ae,v,{root:d.scope.folder,call:d.toolCall}),...[...N].filter(I=>I.to===O.path).flatMap(I=>f.get(I))];L.forEach(I=>j.add(I));let Y=$t(O.path,ae,v,S.includes(O.path)?d.toolCall:void 0,e).flatMap(I=>L.some(V=>!V.reason&&V.kind===I.kind&&V.symbol===I.symbol&&V.span.from===I.span.from)?[]:A.some(V=>V.to===O.path)&&!S.includes(O.path)&&(I.kind==="config"||I.kind==="graph-node")&&!I.reason?[{...I,reason:"unlinked"}]:[I]);E.set(O.path,[...Y,...L,...(o.links??[]).filter(I=>I.from===O.path)])}let at=E.get(O.path)??[];if(O.role==="code"&&O.evidence?.kind==="import"&&at.some(F=>F.reason==="external"&&F.usage==="call"&&(F.within===H||F.within===null)&&mt(F.source,_e))){P.refused.push({path:O.path,reason:"provider-transport"});continue}let Ro=k.has(O.path)||O.role==="tool"&&me?.params!=null&&!S.includes(O.path);if(!n.take(O.path,Ro,O.explicit))continue;P.unresolved.push(...m.filter(F=>F.from===O.path&&(F.reason||y.has(F))).map(F=>y.has(F)?{...F,reason:"missing"}:F));let U=P.files.find(F=>F.path===O.path);U||(U={path:O.path,roles:[],spans:[],evidence:[],sharedOwners:[]},P.files.push(U)),U.roles.includes(O.role)||U.roles.push(O.role);let we=O.span??(pe&&me?{from:pe.toks[me.from].line,to:pe.toks[me.to-1].endLine}:void 0);we&&!U.spans.some(F=>F.from===we.from&&F.to===we.to)&&U.spans.push(we),O.evidence?U.evidence.push(O.evidence):U.evidence.push({kind:"entry",from:O.path,to:O.path,...O.span?{span:O.span}:{}});for(let F of d.skillManifests??[])if(P.files.some(L=>L.path===F.ownerPath))for(let L of F.files)for(let Y of L.evidence)Y.fromPath===O.path&&w.push({path:L.path,symbol:null,role:"reference",explicit:!0,evidence:{kind:"skill-reference",from:Y.fromPath,to:L.path,span:Y.span}});if(ae!==void 0)for(let F of at){let L=F.usage==="reexport"&&(F.symbol===H||F.symbol==="*"),Y=F.usage==="call"&&F.within===H;if(!(F.kind!=="import"&&(H===null||F.within===H)||H!==null&&(L||Y)||F.reason==="dynamic"&&(H===null||F.within===H)))continue;if(!F.to||F.reason){P.unresolved.push(F);continue}let V=A.includes(F);V&&(N.add(F),E.delete(F.to)),P.edges.push(F);let Lo=F.kind==="tool-registration"?"tool":F.kind==="config"?"config":F.kind==="graph-node"?"workflow":L?O.role:"code";w.push({path:F.to,symbol:V?null:F.imported==="*"?O.symbol:F.imported,role:Lo,evidence:F,explicit:j.has(F)})}}if(P.refused.push(...de(n.skipped,n.refused)),P.unresolved=P.unresolved.filter($=>$.reason!=="unlinked"||!P.edges.some(O=>O.from===$.from&&O.to===$.to&&O.kind===$.kind&&O.symbol===$.symbol&&O.span.from===$.span.from)),P.unresolved=[...new Map(P.unresolved.map($=>[JSON.stringify($),$])).values()],P.refused=P.refused.filter(($,O,z)=>z.findIndex(_=>_.path===$.path&&_.reason===$.reason)===O),!s.has(d.id))for(let $ of P.files)p.add($.path);return P}),a=new Map;for(let d of h)for(let S of d.files)a.set(S.path,[...a.get(S.path)??[],d.agentId]);for(let d of h)for(let S of d.files)S.sharedOwners=[...new Set(a.get(S.path))].sort();return h}function Ue(e,t){return["[","{"].some(o=>T(e.source.toks[t.from],o))&&J(e.source.toks,t.from)===t.to?{...t,to:t.to+1}:e.calls.find(o=>o.from===t.from&&o.to===t.to+1&&T(e.source.toks[t.to],")"))??t}function W(e,t,o=new Set){let{toks:r}=e.source;if(t.to!==t.from+1||!B(r[t.from])||["True","False","None"].includes(r[t.from].text))return t;let i=e.binding(r[t.from].text,t.from);return!i||i.append||!e.bindingIsCertain(i,t.from)||o.has(i.at)||e.functions.some(s=>s.from<t.from&&t.from<s.to&&s.params?.includes(i.name))?null:W(e,Ue(e,i),new Set([...o,i.at]))}import{posix as to}from"node:path";function oo(e,t,o,r,i){let{source:{path:s,toks:c}}=e,l=[],u=[],b=[],p=[],v=(h,a)=>p.push({path:h,reason:a}),m=(h,a,d,S=null)=>({path:a,role:h,label:S,...d?{span:d}:{}}),f=(h,a)=>{let d=e.importBinding(h,a),S=t.filter(g=>g.name===h&&g.from<a&&(g.params!==null||g.kind==="class")&&(!e.owner(g.from)||e.owner(g.from)===e.owner(a)));if(!d)return S.length===1?{path:s,span:{from:c[S[0].from].line,to:c[S[0].to-1].endLine}}:null;let k=d.module.source,P=i.length===1?to.dirname(to.dirname(i[0])):"",n=Ot(k.startsWith(".")?s:`${P?`${P}/`:""}__root__.py`,k.startsWith(".")?k:`.${k}`,[d.name],"py",r);return n?{path:n}:null},y=o&&W(e,o);if(y&&T(c[y.from],"[")&&J(c,y.from)===y.to-1)for(let h of ne(c,y.from)){let a=h.to===h.from+1&&B(c[h.from])&&!e.binding(c[h.from].text,h.from)?h:W(e,h);if(!a||!B(c[a.from])){v(s,"dynamic");continue}let d=c[a.from].text;if(!(a.to===a.from+1||T(c[a.from+1],"(")&&J(c,a.from+1)===a.to-1)){v(s,"dynamic");continue}if(e.functions.some(P=>P.from<a.from&&a.from<P.to&&P.params?.includes(d))){v(s,"dynamic");continue}if(!e.importBinding(d,a.from)&&!t.some(P=>P.name===d&&(P.params!==null||P.kind==="class")&&P.from<a.from)){v(s,"dynamic");continue}l.push(d);let k=f(d,a.from);k&&(b.push(m("tools",k.path,k.span,d)),u.push(k.path))}else o&&v(s,"dynamic");return{names:l,files:b,proofPaths:u,refused:p}}function no(e,t,o,r,i,s){let c=t.source,{path:l,toks:u}=c,{files:b,paths:p,frameworks:v,defaultsByPath:m}=s,f={prompt:{kind:"none"},files:[]},y=[],h,a=(n,g)=>y.push({path:n,reason:g}),d=(n,g,w,x=null)=>({path:g,role:n,label:x,...w?{span:w}:{}});m.has(l)||m.set(l,Ge(l,c.text,p));let S=m.get(l),k=n=>{f.layoutProof??={kind:"outside-loader",paths:[]},f.layoutProof.paths.push(n);let g=b[n];if(g===void 0){f.files.push(d("template",n)),a(n,"missing");return}let w=Gt(g,e);if(w.unresolved.length||!w.fields.some(x=>x.key==="system_prompt"&&x.value!==null)){a(n,"invalid");return}for(let x of w.fields.filter(C=>C.value!==null))f.files.push(d(x.key==="system_prompt"?"system prompt":"template",n,x.span,x.key)),x.key==="system_prompt"&&(f.prompt={kind:"entry",path:n,span:x.span,text:x.value})},P=o.get("prompt_templates")??o.get("system_prompt");if(P){let n=W(t,P),g=n&&ue(c,n);if(g&&o.has("system_prompt"))f.prompt={kind:"entry",path:l,span:g.span,text:u[n.from].value},h={path:l,start:g.start},f.files.push(d("system prompt",l,g.span));else if(n&&T(u[n.from],"{")&&J(u,n.from)===n.to-1){let w=!1,x=(C,A="")=>{let M=new Set;for(let E of ne(u,C.from)){let j=u[E.from]?.kind==="string"?u[E.from].value:null;if(!j||M.has(j)||!T(u[E.from+1],":")){a(l,"invalid"),w=!0;return}M.add(j);let N=W(t,{from:E.from+2,to:E.to}),$=N&&ue(c,N);$?(f.files.push(d(j==="system_prompt"?"system prompt":"template",l,$.span,A+j)),j==="system_prompt"&&!A&&(f.prompt={kind:"entry",path:l,span:$.span,text:u[N.from].value},h={path:l,start:$.start})):N&&T(u[N.from],"{")?x(N,`${A}${j}.`):a(l,"dynamic")}};x(n),w&&(f.prompt={kind:"none"},f.files=[])}else{let w=n&&S.find(x=>x.start===u[n.from].start&&x.end===u[n.to-1].end);w?.path&&!w.reason?k(w.path):a(l,"dynamic")}}else if(r.args.some(n=>!B(u[n.from])||!T(u[n.from+1],"=")))a(l,"dynamic");else if(v.length===1){let n=v[0],g=b[n];if(g===void 0)f.files.push(d("config",n)),f.layoutProof={kind:"outside-loader",paths:[n]};else{m.has(n)||m.set(n,Ge(n,g,p));let w=m.get(n).filter(j=>j.className===i&&j.binding==="prompt_templates"&&j.forwarded),x=o.get("use_structured_outputs_internally"),C=x?W(t,x):null,A=C&&C.to===C.from+1&&["True","False"].includes(u[C.from].text)?u[C.from].text==="True":null,M=w.filter(j=>j.when?.every(N=>N.parameter==="use_structured_outputs_internally"&&N.value===(x?A:N.defaultValue))),E=M.length===1?M[0]:null;E?.path&&(!E.reason||E.reason==="missing")?k(E.path):a(n,"dynamic")}}else a(l,v.length>1?"dynamic":"missing");return{...f,promptSite:h,refused:y}}function so(e,t,o=t.files){let r={agents:[],refused:[]};if(!K(e))return r;let i={...o,...t.files},s=new Set([...Object.keys(i),...t.listedPaths??[]]),c=new Set(Et(e,[...s],t.root)),l=[...s].filter(p=>/(?:^|\/)smolagents\/agents\.py$/.test(p)),u=new Map,b=(p,v)=>r.refused.push({path:p,reason:v});for(let[p,v]of Object.entries(t.files)){if(!v.includes("smolagents")||ut(p,{listing:s,root:t.root})&&!dt(e,p,t.root)||!/\.py$/i.test(p)&&!c.has(p)||!R(e,{path:p,size:Buffer.byteLength(v)},{purpose:"code-scan",route:"github",root:t.root,listing:s}).admitted)continue;let m=c.has(p)?Rt(p,v).filter(n=>n.lang==="py"):null,f=m?Lt(v,m):v,y=oe(p,f,"py"),h=xt(y,{includeMembers:!0}),a=Ct(y,h,{enclosingBindings:!0}),{toks:d}=y,S=[],k=n=>{let g=n&&W(a,n);return g&&ue(y,g)?d[g.from].value:null},P=(n,g,w,x=null)=>({path:g,role:n,label:x,...w?{span:w}:{}});for(let n of a.calls){let g=a.importBinding(n.callee,n.from);if(!g||!["smolagents","smolagents.agents"].includes(g.module.source)||!["CodeAgent","ToolCallingAgent"].includes(g.name))continue;let w=new Map(n.args.flatMap(O=>B(d[O.from])&&T(d[O.from+1],"=")?[[d[O.from].text,{from:O.from+2,to:O.to}]]:[])),x=m?.find(O=>O.span.from<=d[n.from].line&&d[n.from].line<=O.span.to);if(x&&(g.module.line<x.span.from||x.span.to<g.module.line)){let O=w.get("managed_agents"),z=O&&W(a,O);if(!(z&&T(d[z.from],"[")&&ne(d,z.from).some(ie=>{let ce=W(a,ie);return ce&&S.some(Ne=>Ne.at===ce.from)})))continue}let A=a.assignments.find(O=>O.from===n.from&&Ue(a,O).to===n.to)?.name??`line-${d[n.from].line}`,M=`smolagents:${JSON.stringify([p,d[n.from].start])}`,E={from:d[n.from].line,to:d[n.to-1].endLine},j={key:M,name:k(w.get("name"))??A,model:null,description:k(w.get("description")),prompt:{kind:"none"},files:[],skills:[],tools:[],subagents:[],layoutCall:{path:p,callStart:d[n.from].start,line:E.from,loadedPrompt:!0}},N=no(e,a,w,n,g.name,{files:i,paths:s,frameworks:l,defaultsByPath:u});j.prompt=N.prompt,j.files.push(...N.files),N.layoutProof&&(j.layoutProof=N.layoutProof),N.promptSite&&(j.layoutCall.promptPath=N.promptSite.path,j.layoutCall.promptStart=N.promptSite.start),r.refused.push(...N.refused),j.files.push(P(m?"system prompt":"config",p,E));let $=oo(a,h,w.get("tools"),s,l);j.tools=$.names,j.files.push(...$.files),$.proofPaths.length&&(j.layoutProof??={kind:"outside-loader",paths:[]},j.layoutProof.paths.push(...$.proofPaths)),r.refused.push(...$.refused),r.agents.push(j),S.push({agent:j,name:A,at:n.from,children:w.get("managed_agents")})}for(let n of S){if(!n.children)continue;let g=W(a,n.children);if(!g||!T(d[g.from],"[")||J(d,g.from)!==g.to-1){b(p,"dynamic");continue}for(let w of ne(d,g.from)){let x=W(a,w),C=x&&S.find(M=>M.at===x.from&&x.to===a.calls.find(E=>E.from===M.at)?.to);if(!C||C===n){b(p,"dynamic");continue}let A=C.agent.prompt;n.agent.subagents.push({key:C.agent.key,path:A.kind==="none"?p:A.path,name:C.agent.name,description:C.agent.description,prompt:A.kind==="entry"?A.text:"",tools:C.agent.tools,skillPaths:[],files:C.agent.files})}}}return r}import{basename as Go}from"node:path";import{basename as zo}from"node:path";var io=/^[\w.*:/()-]+$/,ao=/^(?:true|false|null|~|[-+]?(?:\d[\d_.eExXoObB+-]*|\.\d[\d_eE+-]*|\.inf|\.nan)|\d{4}-\d{1,2}-\d{1,2}(?:[Tt].*)?)$/i,$e=e=>io.test(e)&&!e.startsWith("*")&&!ao.test(e);function Me(e){if(e.startsWith('"'))try{return JSON.parse(e)}catch{return e}return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/''/g,"'"):e}function ke(e,t=!1,o=!1){let r=[],i="",s=0,c=-1,l=0,u=()=>{c>=0&&r.push([c,l]),c=-1};for(let b=0;b<e.length;b++){let p=e[b];if(i){i==='"'&&p==="\\"?b++:p===i&&(i==="'"&&e[b+1]==="'"?b++:i=""),l=b+1;continue}if(!o&&p==="#"&&(b===0||/\s/.test(e[b-1]))){if(!t)return u(),{spans:r,end:b,comment:e.slice(b)};let v=e.indexOf(`
4
+ `,b);b=v<0?e.length:v;continue}if(t&&p==="]"&&s===0)return u(),{spans:r,end:b,comment:""};if(p===","&&s===0){u();continue}/\s/.test(p)||(c<0&&(c=b),(p==='"'||p==="'")&&(c===b||s>0)?i=p:p==="("?s++:p===")"&&s>0&&s--,l=b+1)}if(t)throw new Error("Unclosed frontmatter tool list");return u(),{spans:r,end:e.length,comment:""}}function ro(e,t){let o=e.startsWith("["),r=ke(o?e.slice(1):e,o),i=(o?e.slice(1,r.end+1):e.slice(0,r.end)).trimEnd(),s=!o&&r.spans.length===1&&/^["']/.test(i)&&Me(i)!==i?i[0]:"",c=s?Me(i):o?e.slice(1,r.end+1):e.slice(0,r.end).trimEnd(),l=o?r.spans:ke(c,!1,!!s).spans,u=0,b=l.flatMap(([v,m],f)=>{let y=c.slice(v,m),h=Me(y),a=c.slice(u,v).replace(/[^\S\n]*#[^\n]*/g,""),d=o?c.slice(m,l[f+1]?.[0]??c.length):"",S=d.match(/[^\S\n]*#[^\n]*/g)?.join(`
5
+ `)??"";return u=m,h?[{name:h,raw:y,before:a,note:S,noteAfterComma:/^[^\S\n]*,/.test(d)}]:[]}),p=o?e.slice(r.end+2).split(`
6
+ `)[0]:e.slice(i.length);return{style:o?"flow":"comma",outerQuote:s,quote:b.find(v=>/^["']/.test(v.raw))?.raw[0]??"",prefix:"",suffix:p,head:(b[0]?.before??c).replace(/,/g,""),tail:b.length?c.slice(u).replace(/[^\S\n]*#[^\n]*/g,""):"",separator:b[1]?.before.replace(/#[^\n]*/g,"")??(c.includes(`
7
+ `)?`,
8
+ ${c.match(/\n([^\S\n]*)/)[1]}`:", "),entries:b,first:t,last:t+e.slice(0,o?r.end+2:e.length).split(`
9
+ `).length-1,indent:" - ",blockComments:[]}}function Io(e){let t=he(e),o=t?.raw.map(l=>l.replace(/\r$/,""))??null,r=[],i=[],s={},c=[];if(o)for(let l=0;l<o.length;l++){let u=/^([A-Za-z_][\w-]*\s*:[^\S\n]*)(.*)$/.exec(o[l]);if(!u||!/^tools\s*:/i.test(u[1]))continue;let b=ke(u[2]),p;u[2].startsWith("[")?p=ro(o.slice(l).join(`
10
+ `).slice(u[1].length),l):p=ro(u[2],l),p.prefix=u[1];let v=p.style==="flow"?ke(p.suffix).comment:b.comment;if(v&&(s[p.style==="flow"?p.last:l]=v),p.style==="flow")for(let m of p.entries)m.note&&c.push({tool:m.name,comment:m.note.trim()});if(!u[2].slice(0,b.end).trim()){p.style="block",p.suffix=u[2];for(let m=l+1;m<o.length;m++){if(!o[m].trim()||/^\s*#/.test(o[m])){/^\s+#/.test(o[m])&&p.blockComments.push(m);continue}let f=/^(\s*-\s+)(.*)$/.exec(o[m]);if(!f)break;let y=ke(f[2]),h=f[2].slice(0,y.end).trimEnd(),a=Me(h);p.indent=f[1],a&&p.entries.push({name:a,raw:h,before:"",note:"",noteAfterComma:!1,row:o[m]}),y.comment&&a&&c.push({tool:a,comment:y.comment}),i.push(m),p.last=m}p.quote=p.entries.map(m=>m.raw).find(m=>/^["']/.test(m))?.[0]??""}for(let m=l;m<=(p.style==="block"?l:p.last);m++)i.push(m);r.push(p),l=p.last}return{header:t,lists:r,tools:r.length?r.flatMap(l=>l.entries.map(u=>u.name)):null,lines:o,toolLines:i,toolComments:s,itemComments:c}}function lo(e){try{return Io(e)}catch{let t=he(e);return{header:t,lists:[],tools:[],lines:t.raw.map(o=>o.replace(/\r$/,"")),toolLines:[],toolComments:{},itemComments:[],error:"Unclosed frontmatter tool list"}}}function Bo(e){let{tools:t,lines:o,toolLines:r,toolComments:i,itemComments:s,error:c}=lo(e);return{tools:t,lines:o,toolLines:r,toolComments:i,itemComments:s,...c?{error:c}:{}}}function fo(e){let t=Bo(e);if(t.error)throw new Error(t.error);let{tools:o,lines:r,toolLines:i,toolComments:s,itemComments:c}=t;return{tools:o,lines:r,toolLines:i,toolComments:s,itemComments:c}}function Fe(e){return e.every(t=>io.test(t)&&!t.startsWith("*"))&&(e.length!==1||$e(e[0]))?e.join(", "):`[${e.map(t=>JSON.stringify(t)).join(", ")}]`}function ye(e,t){return t==="'"&&!/[\r\n]/.test(e)?`'${e.replace(/'/g,"''")}'`:t==='"'||!$e(e)?JSON.stringify(e):e}function Ss(e,t){let o=lo(e);if(o.error)return e;let r=o.tools??[],i=t([...r]);if(i.length===r.length&&i.every((y,h)=>y===r[h]))return e;if(!o.header){let y=e.startsWith("\uFEFF")?"\uFEFF":"";return`${y}---
11
+ tools: ${Fe(i)}
12
+ ---
13
+ ${e.slice(y.length)}`}let{header:s,lists:c,toolLines:l,toolComments:u}=o,b=new Map,p=c[0];if(p){let y=c.flatMap(d=>d.entries),h=i.map(d=>{let S=y.findIndex(k=>k.name===d);return S<0?{name:d,raw:ye(d,p.quote),before:p.separator,note:"",noteAfterComma:!1}:y.splice(S,1)[0]}),a=p.prefix.endsWith(" ")?p.prefix:`${p.prefix} `;if(!i.length)b.set(p.first,`${a}[]${p.style==="block"&&p.suffix?` ${p.suffix}`:p.suffix}`);else if(p.style==="block"){b.set(p.first,`${p.prefix}${p.suffix}`);let d=l.filter(S=>S>p.first&&S<=p.last).sort((S,k)=>S-k);for(let S=0;S<h.length;S++){let k=h[S],P=p.entries.includes(k)&&k.row?$e(k.raw)||/^["']/.test(k.raw)?k.row:k.row.replace(k.raw,ye(k.name,p.quote)):`${p.indent}${ye(k.name,p.quote)}`,n=d[Math.min(S,d.length-1)]??p.first;b.set(n,`${b.has(n)?`${b.get(n)}${s.newline}`:""}${P}`)}}else{let d=p.style==="flow"||i.length===1&&ao.test(i[0])||i.some(n=>n.includes(",")||n!==n.trim()||/[\r\n]|(?:^|\s)#|:\s|^[[\]{}&*!|>'"%@`]/.test(n)),S=p.head;for(let[n,g]of h.entries()){if(n){let w=g.before||p.separator,x=h[n-1];x.note&&(x.noteAfterComma?(w=w.replace(/,[^\S\n]*/,`,${x.note}`),w.includes(`
14
+ `)||(w+=`
15
+ `)):w=`${x.note}${/^[^\S\n]*\n/.test(w)?"":`
16
+ `}${w}`),S+=w}S+=d?/^["']/.test(g.raw)||$e(g.raw)?g.raw:ye(g.name,p.quote):g.name}let k=h[h.length-1];k.note?(S+=k.noteAfterComma&&!p.tail.includes(",")?",":"",S+=k.noteAfterComma&&p.tail.includes(",")?p.tail.replace(",",`,${k.note}`):`${k.note}${p.tail}`,p.tail.includes(`
17
+ `)||(S+=`
18
+ `)):S+=p.tail;let P=d?`[${S}]`:p.outerQuote?ye(S,p.outerQuote):S;b.set(p.first,`${p.prefix}${P}${p.suffix}`.replace(/\n/g,s.newline))}}let v=new Set(l),m=s.raw.map((y,h)=>b.has(h)?`${b.get(h)}${s.newline}`:v.has(h)?u[h]&&h>p.last?`${u[h]}${s.newline}`:"":`${!i.length&&c.some(d=>d.blockComments.includes(h))?y.trimStart():y}
19
+ `).join(""),f=p?"":`tools: ${Fe(i)}${s.newline}`;return`${e.slice(0,s.start)}${m}${f}${e.slice(s.end)}`}function Ye(e){return e.CF_LEGACY_TOOL_LISTS!=="1"}function Cs(e,t){return Ye(e)?Fe(t):t.join(", ")}var Wo=/^\s*(name|description|tools|model)\s*:\s*(.+?)\s*$/i;function Do(e){if(e.startsWith('"')&&e.endsWith('"'))try{return JSON.parse(e)}catch{}return e.replace(/^["']|["']$/g,"")}function be(e,t,o,r){let i=Ye(e),s=zo(t).replace(/\.md$/i,""),c,l,u=[],b=!1,p=o,v=[],m=he(o,i?void 0:"markdown");if(m){p=o.slice(m.bodyStart).trim();let y=i?m.raw.map(h=>h.replace(/\r$/,"")):m.raw;for(let h=0;h<y.length;h++){let d=y[h].match(Wo);if(!d)continue;let S=d[1].toLowerCase(),k=Do(d[2]);if(S==="name")s=k;else if(S==="description")if(/^[>|][+-]?$/.test(d[2])){let P=[];for(;h+1<y.length&&(/^\s+\S/.test(y[h+1])||y[h+1].trim()==="");)P.push(y[++h].trim());c=P.join(k[0]===">"?" ":`
20
+ `).trim()}else c=k;else S==="model"?l=k:S==="tools"&&!i&&(b=!0,u=k.replace(/^\[|\]$/g,"").split(",").map(P=>P.trim()).filter(Boolean))}}if(i)try{let y=fo(o);u=y.tools??[],b=y.tools!==null}catch{b=!0,v.push("tools could not be read; check the tool list")}let f=p.trim();return{name:s,...c!==void 0?{description:c}:{},...f?{prompt:f}:{},...!r?.preserveToolAbsence||b?{tools:u}:{},...l!==void 0?{model:l}:{},...v.length?{warnings:v}:{}}}function co(e,t,o){let r=t.managed,i=[],s=new Set([...r.agents,...r.configs,...Object.keys(o.files),...o.listedPaths??[]]),c=new Set(kt(e,[...s],o.files)),l=Object.fromEntries(Object.entries(o.files).filter(([m,f])=>{if(c.has(m))return!1;let y=R(e,{path:m,text:f},{purpose:"override",route:"github",root:t.folder,listing:s,managedFiles:o.files});return!y.admitted&&y.reason==="secret"&&i.push({path:m,reason:"secret"}),y.admitted})),u=new Map;for(let m of r.agents){if(l[m]===void 0){i.some(y=>y.path===m)||i.push({path:m,reason:"missing"});continue}let f=bt(m,l[m],r,o.listedPaths??Object.keys(o.files));i.push(...f.refused),u.set(m,f)}let b=new Set([...u.values()].flatMap(m=>m.relationships.filter(f=>f.kind==="agent").map(f=>f.path))),p=[...u.values()].filter(m=>!b.has(m.path));return!p.length&&u.size&&p.push(u.values().next().value),{agents:p.map(m=>{let f=[{path:m.path,role:"system prompt",label:null}],y=[],h=[],a=(d,S,k)=>{for(let P of d.relationships){if(l[P.path]===void 0){i.some(n=>n.path===P.path)||i.push({path:P.path,reason:"missing"});continue}if(P.kind==="agent"){if(S.has(P.path)){i.push({path:P.path,reason:"cycle"});continue}let n=u.get(P.path);if(!n||h.some(w=>w.path===n.path))continue;let g=[];h.push({path:n.path,name:n.name,description:n.description,prompt:n.prompt,...n.model?{model:n.model}:{},tools:[],skillPaths:[],files:g}),a(n,new Set([...S,n.path]),g)}else if(P.kind==="skill"&&o.skills&&St(e)||P.kind==="config"&&wt(l[P.path])){if(k.some(n=>n.path===P.path))continue;if(k.push({path:P.path,role:P.kind==="skill"?"skill":"config",label:null}),P.kind==="skill"&&d===m){let n=be(e,Go(P.path),l[P.path]);y.push({path:P.path,name:n.name,description:n.description??"",body:n.prompt??""})}}}};return a(m,new Set([m.path]),f),{key:`managed:${m.path}`,name:m.name,model:m.model,description:m.description,prompt:{kind:"dedicated",path:m.path},files:f,tools:[],skills:y,subagents:h}}),notes:[],registry:!1,refused:i}}function po(e,t,o){let r=t.miniSwe,i=o.templateSelection?.agentPath===r.agentPath?o.templateSelection.configPaths:void 0,s=Kt(e,r,o.files,i),c=s.unresolved.filter(a=>a.reason!=="runtime-variable").map(a=>({path:a.target??a.path,reason:a.reason==="duplicate"?"invalid":a.reason})),l=s.fields.find(a=>a.key==="agent.system_template"&&a.value!==null),u=s.fields.find(a=>a.key==="agent.instance_template"&&a.value!==null),b=s.unresolved.some(a=>s.selectedPaths.includes(a.path)&&a.source===a.path);if(!l||!u||b||c.some(a=>a.reason==="invalid"))return{agents:[],notes:[],registry:!1,refused:c};let p=[l,...s.fields.filter(a=>a!==l)].map(a=>({path:a.path,span:a.span,label:a.key,role:a===l?"system prompt":a.key.endsWith("_template")?"template":"config"}));p.push(...s.loaded.map(a=>({path:a.path,role:"template",label:null})));let v=[];for(let a of p){let d=v.find(S=>S.path===a.path);d?d.span&&a.span&&(d.span={from:Math.min(d.span.from,a.span.from),to:Math.max(d.span.to,a.span.to)}):v.push({...a})}let m=[...new Set(v.map(a=>a.path))],f=Object.fromEntries(m.map(a=>[a,o.files[a]])),y=new Map(m.map(a=>[a,Buffer.byteLength(f[a])])),h=Ht(e,{ownPaths:m},{files:f,sizes:y,root:t.folder});return c.push(...h.refused,...h.skipped),s.fields.some(a=>!h.paths.includes(a.path))?{agents:[],notes:[],registry:!1,refused:c}:(s.loaded=s.loaded.filter(a=>h.paths.includes(a.path)),s.edges=s.edges.filter(a=>h.paths.includes(a.from)&&h.paths.includes(a.to)),{agents:[{key:t.key,name:o.fallbackName,model:s.model,description:null,prompt:{kind:"entry",path:l.path,span:l.span,text:l.value},files:v.filter(a=>h.paths.includes(a.path)),tools:[],skills:[],subagents:[],templateVariants:s}],notes:[],registry:!1,refused:c})}function mo(e,t,o){if(!t.skills||!le(e))return o;let r=[...new Set([...Object.keys(t.files),...t.listedPaths??[]])],i=fe(e,r,t.root,{files:t.files,listedPaths:t.listedPaths,agentConfigurations:t.agentConfigurations}),s=new Set(i.files.filter(v=>v.role==="skill").map(v=>v.path)),c=v=>[...new Set([...v.skillPaths.filter(m=>s.has(m)),...v.files?.filter(m=>m.role==="skill").map(m=>m.path)??[]])],l=o.agents.flatMap(v=>[...v.skills.map(m=>m.path),...v.subagents.flatMap(c)]),u=ge(e,{skillPaths:l,paths:r,files:t.files,root:t.root});for(let v of u)v.files=v.files.filter(m=>Object.hasOwn(t.files,m.path));let b=new Map(u.map(v=>[v.ownerPath,v])),p=(v,m)=>{let f=new Set(m.flatMap(h=>h.refused.map(a=>a.path))),y=v.filter(h=>h.role!=="reference"||!f.has(h.path));for(let h of m)for(let a of h.files)y.some(d=>d.path===a.path)||y.push({path:a.path,role:"reference",label:null});return y};return{...o,agents:o.agents.map(v=>{let m=v.skills.flatMap(f=>b.has(f.path)?[b.get(f.path)]:[]);return{...v,files:p(v.files,m),skills:v.skills.map(f=>({...f,...b.has(f.path)?{manifest:b.get(f.path)}:{}})),subagents:v.subagents.map(f=>{let y=c(f).flatMap(g=>b.has(g)?[b.get(g)]:[]);if(!y.length)return f;let h=i.ownerOf(f.path),a=G(e,r.filter(g=>i.ownerOf(g)===h),h?.folder),d=f.files??f.skillPaths.map(g=>({path:g,role:s.has(g)?"skill":"reference",label:a.skillNames[g]??a.skillRefNames[g]??null})),S=new Set([...v.files.map(g=>g.path),...a.subagentPaths,...Object.keys(a.subagentSkillOwners)]),k=a.scoped.filter(g=>!S.has(g)&&te(g)&&Object.hasOwn(t.files,g)).sort(),P=f.files?[]:se(k,[t.files[f.path],...d.filter(g=>g.role==="reference").map(g=>t.files[g.path])],a.stripRoot).map(g=>({path:g,role:"reference",label:null})),n=p([...d,...P],y);return{...f,files:n,skillPaths:[...new Set([...f.skillPaths,...c(f),...y.flatMap(g=>g.files.map(w=>w.path))])].filter(g=>n.some(w=>w.path===g)),skillManifests:y}})}})}}import{basename as Ao}from"node:path";function uo(e){return e.prompt.kind!=="none"}function ho(e,t,o){if(q(e))return o;let r=new Map(o.agentScopes?.map(c=>[c.key,c.folder])),i=Object.keys(t.files),s=new Map;return{...o,agents:o.agents.map(c=>{let l=r.get(c.key)??t.root,u=s.get(l);return u||(u=G(e,i,l,t.listedPaths??i),s.set(l,u)),{...c,definitionPaths:Ko(c,u)}})}}function Ko(e,t){if(uo(e))return[e.prompt.path];let o=s=>!t.developerCompanionPaths.includes(s),r=e.subagents.filter(s=>o(s.path));if(r.length)return r.map(s=>s.path);let i=e.files.filter(s=>["skill","tools","mcp"].includes(s.role)&&o(s.path));return e.key!==null||e.plugin||i.some(s=>s.role==="tools"||s.role==="mcp")||!t.hasRepositoryGuide?i.map(s=>s.path):[]}function Jo(e){return!!e.definitionPaths?.length}function Qs(e,t,o,r){return q(e)?o!==r:(t.key!==null||uo(t))&&Jo(t)}function Ve(e){let t;try{t=JSON.parse(e)}catch{return{config:null,invalid:!0}}if(typeof t!="object"||t===null||Array.isArray(t))return{config:null,invalid:!0};let o=t,r={};for(let i of["name","model","description","prompt"]){let s=Ae(o[i]);s&&(r[i]=s)}if(Array.isArray(o.agents)){let i=o.agents.flatMap(s=>{let c=qo(s);return c?[c]:[]});i.length>0?r.agents=i:r.invalidAgents=!0}return{config:r,invalid:!1}}function sr(e){let{config:t}=Ve(e);return t?Xe(t):"bare"}function Xe(e){return e.agents?.length?"agents":e.prompt?"prompt":"bare"}function je(e){let t=Xe(e);return t==="agents"?e.agents:t==="prompt"?[{name:e.name,model:e.model,prompt:e.prompt}]:[]}function go(e,t,o){return yo(e,t,o).paths}function yo(e,t,o,r={}){let i=je(t).map(l=>l.prompt),s=[],c=[];for(let l of i){let u=Ze(l).path,b=He(o,u);if(b===null){c.push({path:u,reason:"out-of-scope"});continue}let p=R(e,{path:b},{purpose:"pointer",route:"github",...r});p.admitted?s.push(b):c.push({path:b,reason:p.reason})}return{paths:s,refused:c}}function Qe(e,t,o){let r=He(o.markerDir,Ze(t).path),i=r!==null?R(e,{path:r},{purpose:"pointer",route:"github"}):null;if(i&&!i.admitted&&i.reason==="secret")return{kind:"secret",path:r};let s=Uo(t,o,_t(e));return s?{kind:"resolved",prompt:s}:{kind:"missed"}}function rr(e,t,o){let r=[],i=[];t.invalidAgents&&i.push(`${o.repoKey}: counterfact.json "agents" has no entry with a prompt pointer; ignored`);let s=Xe(t);for(let c of je(t)){let l=Qe(e,c.prompt,o);if(l.kind==="secret"){i.push(Pt(l.path));continue}if(l.kind==="missed"){i.push(`${o.repoKey}: counterfact.json points at ${c.prompt}, which was not found; ignored`);continue}r.push({name:c.name??null,model:c.model??null,description:s==="prompt"?t.description??null:null,prompt:l.prompt})}return{agents:r,warnings:i,refused:yo(e,t,o.markerDir).refused}}function Ae(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function qo(e){if(typeof e!="object"||e===null)return null;let t=e,o=Ae(t.prompt);if(!o)return null;let r={prompt:o},i=Ae(t.name),s=Ae(t.model);return i&&(r.name=i),s&&(r.model=s),r}function Ze(e){let t=e.replace(/\\/g,"/"),o=t.indexOf("#");if(o>=0)return{path:t.slice(0,o),symbol:t.slice(o+1),line:null};let r=/^(.*):(\d+)$/.exec(t);return r?{path:r[1],symbol:null,line:Number(r[2])}:{path:t,symbol:null,line:null}}function He(e,t){let o=[];for(let r of[...e.split("/"),...t.split("/")])if(r===".."){if(o.pop()===void 0)return null}else r!=="."&&r!==""&&o.push(r);return o.join("/")}function Uo(e,t,o){let{path:r,symbol:i,line:s}=Ze(e),c=He(t.markerDir,r);if(c===null||!Object.hasOwn(t.files,c))return null;let l=t.files[c];if(l===void 0)return null;if(i===null&&s===null)return Q(c)?null:gt(c,l);let{sites:u}=Nt(c,l,{minChars:1,promptFunctions:o});return i!==null?u.find(b=>b.symbol===i)??null:Yo(u,s)}function Yo(e,t){let o=i=>Math.min(i.line,i.span.from),r=e.filter(i=>o(i)<=t&&t<=i.span.to);return r.sort((i,s)=>i.span.to-o(i)-(s.span.to-o(s))),r[0]??null}import{createHash as Vo}from"node:crypto";var ko=25,Xo=e=>ee(e,"CF_IMPORT_AGENT_PAGES");function pr(e,t,o,r,i=ko,s){if(!Xo(e))return null;let c=r?.pageSize??i,l=r?.offset??0;if(![8,25,400].includes(c)||!Number.isSafeInteger(l)||l<0)throw new Error("invalid-agent-page");let u=[...new Map(t.map(w=>[w.id,w])).values()],b=Vo("sha256").update(JSON.stringify({version:1,context:{commit:o.commit,scope:o.scope},size:c,budgets:s,settings:Object.entries(Ut(e)).filter(([,w])=>w!==void 0).sort(([w],[x])=>w.localeCompare(x)),rows:u.map(({id:w,path:x,groupKey:C,pool:A})=>({id:w,path:x,groupKey:C,pool:A}))})).digest("hex");if(r&&(r.version!==1||r.binding!==b))throw new Error("stale-agent-page");let p=u.map((w,x)=>{let C=wo(e,w,x);return typeof C=="string"?`group:${C}`:`agent:${w.id}`}),v=[...new Set(p)];if(l>0&&l>=v.length)throw new Error("invalid-agent-page");let m=r?.end;if(m!==void 0&&(!Number.isSafeInteger(m)||m<l||m>v.length||m>l+c||m===l&&v.length>0))throw new Error("invalid-agent-page");let f=new Set,y=new Set,h=s?{...s}:null,a=l,d=!1;for(let w of v.slice(l,m??l+c)){let x=new Map(u.filter((A,M)=>p[M]===w&&!y.has(u[M].path)).map(A=>[A.path,A])),C={strong:0,possible:0};for(let A of x.values())C[A.pool??"strong"]+=A.bytes;if(m===void 0&&h&&f.size&&(C.strong>h.strong||C.possible>h.possible)){d=!0;break}f.add(w),a++;for(let A of x.keys())y.add(A);h&&(h.strong=Math.max(0,h.strong-C.strong),h.possible=Math.max(0,h.possible-C.possible))}m!==void 0&&(d=a<v.length&&a-l<c);let S=new Set(v.slice(a)),k=u.filter((w,x)=>f.has(p[x])),P=u.filter((w,x)=>S.has(p[x])).map(w=>w.id),n={version:1,binding:b,offset:l,pageSize:c,end:a},g=new Map(k.map(w=>[w.path,w.bytes]));return{context:{...o},current:n,continuation:P.length?{version:1,binding:b,offset:a,pageSize:c}:null,detected:u.length,detectedGroups:v.length,selected:k.map(w=>w.id),remaining:P,refusals:P.map(w=>({id:w,reason:d?"prompt-over-limit":"page"})),partial:P.length>0,estimatedInputBytes:[...g.values()].reduce((w,x)=>w+x,0)}}function bo(){return ko}function wo(e,t,o){return pt(e)&&t!==null&&typeof t=="object"&&"groupKey"in t&&typeof t.groupKey=="string"&&t.groupKey?t.groupKey:o}function Po(e,t){let o=bo(),r=new Set,i=[],s=[];return t.forEach((c,l)=>{let u=wo(e,c,l);r.has(u)||r.size<o?(r.add(u),i.push(c)):s.push(c)}),{kept:i,leftOut:s}}function vo(e){let t=bo();if(e.kind==="layout")return`Only ${t} agents can be added per import, so ${e.leftOut} were left out.`;if(e.kind==="scan"){let r=e.found-t;return`${r} ${r===1?"agent wasn't":"agents weren't"} read because the repository is large.`}let o=e.kind==="import"?`Not added: this import already has ${t} agents.`:`Only the ${t} strongest agents of a repository are added.`;return e.kind==="model"?`${e.name}: ${o}`:o}var Ee="crew:";function et(e){return e.startsWith(Ee)}function tt(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Object.entries(e);return!t.length||t.some(([,o])=>typeof o!="string"||o.length>=2e3)?null:t.map(([o,r])=>`${o}: ${r}`).join(`
21
+ `)}function So(e,t,o={},r=Object.keys(t)){return K(o)?Qo(e,t,r):e.kind!=="crew"?{agents:[],notes:[],registry:!1}:Oo(e,t)}function Oo(e,t){let o=[],r=[],i=(l,u)=>r.push({code:"unreadable-crew",path:l,detail:u?`${u} could not be read; some instructions may be missing.`:"could not be read; some instructions may be missing."}),s=Se(t[e.agentsPath]??""),c=e.tasksPath?Se(t[e.tasksPath]??""):[];s?.length||i(e.agentsPath),c===null&&i(e.tasksPath);for(let{key:l,value:u,span:b}of s??[]){if(!re(u)){i(e.agentsPath,l);continue}let{llm:p,tools:v,...m}=u,f=tt(m);if(f===null&&Object.keys(m).length){i(e.agentsPath,l);continue}let y=[{role:"system prompt",path:e.agentsPath,label:l,span:b}];for(let h of c??[])re(h.value)&&h.value.agent===l&&y.push({role:"knowledge",path:e.tasksPath,label:h.key,span:h.span});o.push({key:`${Ee}${e.agentsPath}#${l}`,name:l,model:typeof p=="string"?p:null,description:typeof u.goal=="string"?u.goal:null,entry:{path:e.agentsPath,span:b,text:f},files:y,tools:Array.isArray(v)?[...new Set(v.filter(h=>typeof h=="string"&&!!h.trim()))]:[],skills:[],subagents:[]})}return{agents:o,notes:r,registry:!1}}function re(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Qo(e,t,o){let r=new Set([...o,...Object.keys(t)]),i=Object.entries(t).filter(([f])=>f.endsWith(".py")).map(([f,y])=>Jt(f,y,r,e.folder)),s=i.flatMap(f=>f.agents),c=i.flatMap(f=>f.refused);if(!s.length)return e.kind==="crew"&&/\.ya?ml$/i.test(e.agentsPath)?{...Oo(e,t),refused:c}:{agents:[],notes:[],refused:c,registry:!1};let l=new Map,u=f=>{if(!l.has(f)){let y=t[f]===void 0?null:Se(t[f]);l.set(f,y),y===null&&c.push({path:f,reason:t[f]===void 0?"missing":"invalid"})}return l.get(f)??[]},b=i.flatMap(f=>f.tasks).flatMap(f=>{let y=f.config?.path?u(f.config.path).find(d=>d.key===f.config.key):void 0;if(f.config&&(!f.config.path||!y||!re(y.value)))return f.config.path&&c.push({path:f.config.path,reason:y?"invalid":"missing"}),[];let h=re(y?.value)?y.value:{},a=f.factory.includes(".")?f.factory.slice(0,f.factory.lastIndexOf(".")):null;return[{fact:f,path:f.config?.path??f.path,key:f.config?.key??f.factory,span:y?.span??f.span,agent:f.agent??(typeof h.agent=="string"?a?`${a}.${h.agent}`:h.agent:null),context:[...f.context,...Array.isArray(h.context)?h.context.filter(d=>typeof d=="string"):[]],tools:f.tools}]}),p=i.flatMap(f=>f.tasks).filter(f=>f.config),v=p.flatMap(f=>f.config?.path?[{path:f.config.path,source:f.path,owner:f.factory.includes(".")?f.factory.slice(0,f.factory.lastIndexOf(".")):null}]:[]);!p.length&&e.kind==="crew"&&e.tasksPath&&v.push({path:e.tasksPath,source:e.tasksPath,owner:null});for(let{path:f,source:y,owner:h}of v)for(let a of u(f)){if(b.some(S=>S.path===f&&S.key===a.key&&S.fact.path===y&&(S.fact.factory.includes(".")?S.fact.factory.slice(0,S.fact.factory.lastIndexOf(".")):null)===h)||!re(a.value))continue;let d=a.value;b.push({fact:{path:y,factory:h?`${h}.${a.key}`:a.key,span:a.span,callStart:0,agent:null,context:[],tools:[]},path:f,key:a.key,span:a.span,agent:typeof d.agent=="string"?h?`${h}.${d.agent}`:d.agent:null,context:Array.isArray(d.context)?d.context.filter(S=>typeof S=="string"):[],tools:[]})}let m=[];for(let f of s){let y=f.config?.path?u(f.config.path).find(C=>C.key===f.config.key):void 0;if(f.config&&(!f.config.path||!y||!re(y.value))){f.config.path&&c.push({path:f.config.path,reason:y?"invalid":"missing"});continue}let h=re(y?.value)?y.value:{},a={...Object.fromEntries(Object.entries(h).filter(([C,A])=>!["llm","tools"].includes(C)&&typeof A=="string")),...f.instructions},d=tt(a);if(!d){c.push({path:f.path,reason:"dynamic"});continue}let S=f.config?.key??f.factory.split(".").at(-1),k=f.config?.path??f.path,P=y?.span??f.span,n=[{path:k,role:"system prompt",label:S,span:P}];k!==f.path&&n.push({path:f.path,role:"config",label:f.factory,span:f.span});let g=b.filter(C=>C.fact.path===f.path?C.agent===f.factory||C.agent===S:/\.ya?ml$/i.test(C.fact.path)&&C.agent===S&&s.filter(A=>(A.config?.key??A.factory)===S).length===1),w=new Set,x=[...f.tools];for(let C=0;C<g.length;C++){let A=g[C];if(!w.has(A)&&(w.add(A),!(A.fact.config&&!A.fact.config.path))){n.push({path:A.path,role:"knowledge",label:A.key,span:A.span}),x.push(...A.tools);for(let M of A.context){let E=b.filter(j=>j.fact.path===A.fact.path&&j.fact.factory===M||j.path===A.path&&j.key===M);E.length===1?g.push(E[0]):c.push({path:A.path,reason:E.length?"dynamic":"missing"})}}}for(let C of x)C.path&&C.path!==f.path&&!n.some(A=>A.path===C.path)&&(t[C.path]===void 0&&c.push({path:C.path,reason:"missing"}),n.push({path:C.path,role:"tools",label:C.name}));m.push({key:`${Ee}${f.path}#${f.factory}`,name:S,model:typeof h.llm=="string"?h.llm:null,description:typeof a.goal=="string"?a.goal:null,entry:{path:k,span:P,text:d},files:n,tools:[...new Set([...x.map(C=>C.name),...Array.isArray(h.tools)?h.tools.filter(C=>typeof C=="string"):[]])],skills:[],subagents:[],crewCall:{path:f.path,callStart:f.callStart}})}return{agents:m,notes:[],refused:c,registry:!1}}import{basename as xo,posix as Re}from"node:path";function Co(e,t,o){let r={...t.selected,codeAgentsFound:t.codeAgentsFound||t.selected.codeAgentsFound};if(!ot(e,r,o))return{kind:"none"};let i={...t.bodies,...r.files},s=G(e,Object.keys(i),X(r.root)).templatePaths,c=nt(e,{...r,files:i},s);if(!t.entries)return{kind:"search",paths:[],ownedPaths:c.ownedPaths};let l=new Set([...Object.keys(i),...t.attemptedPaths??[]]),u=new Set(c.facts.dependencies);for(let y of c.relatedReads)y.target.kind==="file"&&u.add(y.target.path);for(let y of t.entries)c.relatedReads.some(h=>h.target.kind==="directory"&&Le(h,y.path))&&u.add(y.path);let b=(y,h)=>{let a=R(e,y,{purpose:h,route:"local-folder"});return a.admitted||a.reason==="too-large"},p=[...new Set(t.entries.filter(y=>!l.has(y.path)&&(u.has(y.path)?b(y,"pointer"):D(y.path,r.root)===null&&Q(y.path)!==null&&b(y,"code-support"))).map(y=>y.path))],v=X(r.root)??"",m=y=>Re.parse(y).name===(v?xo(v):r.fallbackName)?0:vt.test(xo(y))?1:2,f=y=>Re.relative(v||".",Re.dirname(y)).split("/").filter(h=>h&&h!==".").length;return p.sort((y,h)=>Number(u.has(h))-Number(u.has(y))||m(y)-m(h)||f(y)-f(h)||(y<h?-1:y>h?1:0)),{kind:"search",paths:p,ownedPaths:c.ownedPaths}}function Le(e,t){return e.target.kind==="file"?e.target.path===t:Re.dirname(t)===e.target.path&&(!e.target.extension||t.endsWith(e.target.extension))}function ot(e,t,o){if(!Oe(e)||t.codeAgentsFound||t.explicitPrompt!==void 0||o.agents.length||t.listedPaths&&G(e,[...t.listedPaths],X(t.root)).configPath)return null;let r=G(e,Object.keys(t.files),X(t.root)).templatePaths;if(!r.length)return null;let i=Object.fromEntries(Object.entries(t.files).filter(([s])=>D(s,t.root)!==null&&R(e,{path:s},{purpose:"override",route:"github"}).admitted));return Be(e,i).reads.some(s=>r.some(c=>Le(s,c)))?null:r}function nt(e,t,o){let r=Object.fromEntries(Object.entries(t.files).filter(([m])=>R(e,{path:m},{purpose:"override",route:"github"}).admitted)),i=Be(e,r),s=i.reads.filter(m=>D(m.sourcePath,t.root)===null&&o.some(f=>Le(m,f))),c=o.filter(m=>s.some(f=>Le(f,m))).sort(),l=[...new Set(s.map(m=>m.sourcePath))].sort(),u=i.reads.filter(m=>l.includes(m.sourcePath)),b=u.flatMap(m=>m.target.kind==="file"&&Object.hasOwn(r,m.target.path)&&D(m.target.path,t.root)!==null&&!o.includes(m.target.path)?[m.target.path]:[]).sort(),p=s.flatMap(m=>m.consumerPaths).sort(),v=c.length?[...new Set([c[0],...o.filter(m=>m!==c[0]),...b,...l,...p])]:[];return{facts:i,relatedReads:u,provenTemplates:c,ownedPaths:v}}function si(e,t,o={}){return Te(e)&&!t.agentConfigurations&&(t={...t,agentConfigurations:Wt(e,t.listedPaths??Object.keys(t.files),t.root)}),ho(e,t,Zo(e,t,o))}function Zo(e,t,o){let r=jo(e,t),{answer:i,scopeProof:s}=Ho(e,t,r),c=Ce(e);if(!c&&!i.agents.some(a=>a.crewCall||a.layoutCall))return Ke(e,t,i);let l=[...new Set([...Object.keys(t.files),...t.listedPaths??[],...i.scopePaths??[]])],u=fe(e,l,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),b=i.agents.filter(a=>c||a.crewCall||a.layoutCall).map(a=>{let d=r.agents.find(M=>M.key===a.key),S=st(d?.files??[]),k=i.agentScopes?.find(M=>M.key===a.key)?.folder,P=u.scopes.find(M=>k===void 0?M.key===a.key:M.folder===k)??u.scopes[0],n=G(e,l.filter(M=>u.ownerOf(M)===P),P.folder),g=new Set([...a.files.filter(M=>M.role!=="reference"||M.label!==null).map(M=>M.path),...a.subagents.flatMap(M=>[M.path,...d?.subagents.find(E=>E.path===M.path)?.skillPaths??M.skillPaths]),...i.notes.filter(M=>M.code==="orphan-skill").map(M=>M.path)]),w=n.scoped.filter(M=>!g.has(M)&&te(M)).sort(),x=`convention:${JSON.stringify(a.key)}`,C=a.files.map(M=>a.prompt.kind!=="none"&&a.prompt.path===M.path&&"span"in a.prompt?{...M,span:M.span??a.prompt.span}:M),A=a.subagents.map(M=>{let E=d?.subagents.find(_=>_.path===M.path),j=M.files??M.skillPaths.map(_=>({path:_,role:n.skillNames[_]?"skill":"reference",label:n.skillNames[_]??n.skillRefNames[_]??null})),N=le(e)?st(E?.files??[]):j.map(_=>_.path),$=M.files&&!n.subagentPaths.includes(M.path)?[]:se(w,[M.path,...N].map(_=>t.files[_]??""),n.stripRoot),O=$.filter(_=>!j.some(ie=>ie.path===_)).map(_=>({path:_,role:"reference",label:null})),z=i.agents.find(_=>"key"in M&&_.key===M.key);return{child:M,id:`${x}:${JSON.stringify("key"in M?M.key:M.path)}`,scopeProof:z?.layoutProof??s,toolCall:z?.layoutCall,independentReferences:[...st(E?.files??[]),...$],ownFiles:"key"in M?[...j,...O]:[{path:M.path,role:"system prompt",label:null},...j,...O]}});return{agent:a,id:x,scope:P,ownFiles:C,independentReferences:S,children:A,scopeProof:a.layoutProof??s,toolCall:a.crewCall??a.layoutCall}}),p=b.flatMap(({agent:a,id:d,scope:S,ownFiles:k,independentReferences:P,children:n,scopeProof:g,toolCall:w})=>[{id:d,scope:S,ownFiles:k,independentReferences:P,scopeProof:g,toolCall:w,sharedReferencePaths:a.sharedReferencePaths,fileProfile:a.crewCall||a.layoutCall?"layout":"convention",skillManifests:a.skills.flatMap(x=>x.manifest?[x.manifest]:[])},...n.map(({child:x,id:C,ownFiles:A,independentReferences:M,scopeProof:E,toolCall:j})=>({id:C,scope:S,ownFiles:A,independentReferences:M,scopeProof:E,toolCall:j,fileProfile:"key"in x?"layout":"convention",skillManifests:x.skillManifests}))]),v=eo(e,p,{files:t.files,sizes:o.sizes??new Map(Object.entries(t.files).map(([a,d])=>[a,Buffer.byteLength(d)])),total:o.total,root:t.root,scopes:u}),m=new Map(v.map(a=>[a.agentId,a])),{complete:f,...y}=i,h=new Map(b.map(({agent:a,id:d,children:S})=>{let k=m.get(d);return[a.key,{...a,manifest:k,files:Mo(k,a.files),skills:a.skills.filter(P=>k.files.some(n=>n.path===P.path)),subagents:S.flatMap(({child:P,id:n,ownFiles:g})=>{let w=m.get(n);if(!w.files.some(A=>A.path===P.path))return[];let x=Mo(w,g),C="key"in P?x:x.filter(A=>A.path!==P.path);return[{...P,files:C,skillPaths:P.skillPaths.filter(A=>C.some(M=>M.path===A))}]})}]}));return Ke(e,t,{...y,...f&&!v.some(a=>a.refused.length)?{complete:f}:{},scopePaths:l,manifests:v,agents:i.agents.map(a=>h.get(a.key)??a)})}function Mo(e,t){return e.files.flatMap(o=>t.some(r=>r.path===o.path)?t.filter(r=>r.path===o.path):[{path:o.path,role:o.roles.includes("config")?"config":"tools",label:null,...o.spans.length===1?{span:o.spans[0]}:{}}])}function st(e){return e.filter(t=>t.role==="reference"&&t.label===null).map(t=>t.path)}function Ho(e,t,o){let r=mo(e,t,o);if(!q(e)&&t.codeAgentsFound)return{answer:{...r,projection:"code"}};let i=ot(e,t,r);if(!i)return{answer:r};let s=nt(e,t,i);if(!s.provenTemplates.length)return{answer:r};let c=s.provenTemplates[0],l=new Set(r.agentScopes?.find(b=>b.key===null)?.notes),u=b=>!(b.code==="no-prompt"&&b.detail==="no-conventions"&&b.path===(X(t.root)??""));return{scopeProof:{kind:"outside-loader",paths:s.ownedPaths},answer:{...r,projection:"conventions",notes:r.notes.filter(u),...r.agentScopes?{agentScopes:r.agentScopes.map(b=>({...b,notes:b.notes.filter(u)}))}:{},...r.unassignedNotes?{unassignedNotes:r.unassignedNotes.filter(b=>!l.has(b))}:{},agents:[{key:null,name:t.fallbackName,model:null,description:null,prompt:{kind:"dedicated",path:c},files:s.ownedPaths.map(b=>({path:b,role:b===c?"system prompt":i.includes(b)?"template":"reference",label:null})),skills:[],subagents:[]}]}}}function ri(e,t){return Oe(e)?Co(e,t,jo(e,t.selected)):{kind:"none"}}function jo(e,t){if(!ve(e)){let{agents:n,notes:g}=rt(e,t,null);return{agents:n,notes:g}}let o=yt(e,t.listedPaths??[]).flatMap(n=>[...n.agents,...n.configs]),r=[...new Set([...Object.keys(t.files),...o,...K(e)?t.listedPaths??[]:[]])],{scopes:i,ownerOf:s,ignoredPaths:c,pluginFolders:l}=fe(e,r,t.root,{files:t.files,agentConfigurations:t.agentConfigurations,listedPaths:t.listedPaths}),u=new Set(c),b=new Map(i.map(n=>[n,{}]));for(let[n,g]of Object.entries(t.files)){if(u.has(n))continue;let w=s(n);w&&(b.get(w)[n]=g)}let p=i.map(n=>{let g=b.get(n),w={...t,files:g,root:n.folder,fallbackName:n.key===null?t.fallbackName:Ao(n.folder),explicitPrompt:n.key===null?t.explicitPrompt:void 0,...t.pointerFiles?{pointerFiles:Object.fromEntries(Object.entries(t.pointerFiles).filter(([x])=>!u.has(x)&&s(x)===n))}:{}};return{scope:n,input:w,answer:$o(e,n,w,!1,t.files)}}),v=[],m=new Map,f=p.filter(({scope:n,input:g,answer:w})=>{let x=w.agents[0];if(!x)return!0;let C=Object.entries(g.files).map(([E,j])=>[D(E,n.folder),j]).sort(([E],[j])=>E<j?-1:E>j?1:0),A=JSON.stringify([x.name,C,...n.managed||K(e)&&(n.kind==="crew"||l.includes(n.folder))?[n.folder]:[]]),M=m.get(A);return M!==void 0?(v.push({code:"duplicate-agent",path:n.folder,detail:M}),!1):(m.set(A,n.folder),!0)}),y=f.find(({scope:n})=>n.key===null),h=y.answer.agents[0];f.some(({scope:n,answer:g})=>n.key!==null&&g.agents.length)&&(y.answer=$o(e,y.scope,y.input,!0,t.files),y.answer.notes=y.answer.notes.filter(n=>n.detail!=="no-conventions"));for(let{scope:n,answer:g}of q(e)?[]:f)l.includes(n.folder)&&(g.agents=g.agents.map(w=>({...w,plugin:!0})));let{kept:a,leftOut:d}=Po(e,f.flatMap(({answer:n})=>n.agents));Yt(a,h,{settings:e,files:t.files,root:t.root});let S=[...v,...d.length?[{code:"agent-cap",detail:vo({kind:"layout",leftOut:d.length})}]:[]],k=new Set(a.map(n=>n.key));return{...!t.definitionsOmitted&&f.some(({scope:n})=>n.kind==="crew")&&f.every(({scope:n,answer:g})=>g.notes.length===0&&!g.refused?.length&&(n.kind==="crew"?g.agents.length>0&&g.agents.every(w=>et(w.key??"")):g.agents.length===0))&&(!t.listedPaths||fe(e,t.listedPaths,t.root,{agentConfigurations:t.agentConfigurations}).files.every(n=>Object.hasOwn(t.files,n.path)))?{complete:!0}:{},...f.some(({scope:n,answer:g})=>n.miniSwe&&g.agents.length)&&!t.codeAgentsFound?{projection:"conventions"}:{},agents:a.map(n=>n.layoutCall?{...n,subagents:n.subagents.filter(g=>"key"in g&&k.has(g.key))}:n),notes:[...f.flatMap(({answer:n})=>n.notes),...S],...o.length?{scopePaths:r}:{},...f.some(({answer:n})=>n.refused?.length)?{refused:f.flatMap(({answer:n})=>n.refused??[])}:{},...i.length>1||i.some(n=>n.kind==="crew"||n.managed||n.miniSwe)||f.some(({answer:n})=>n.agents.some(g=>g.layoutCall))?{agentScopes:f.flatMap(({scope:n,answer:g})=>(g.agents.length?g.agents:[{key:n.key}]).map((w,x)=>({key:w.key,folder:n.folder,registry:g.registry&&!et(w.key??""),notes:g.notes.filter(C=>C.code!=="unreadable-crew"||x===0)}))),unassignedNotes:[...f.filter(({answer:n})=>!n.agents.some(g=>k.has(g.key))).flatMap(({answer:n})=>n.notes),...S]}:{}}}function $o(e,t,o,r=!1,i){if(t.managed)return co(e,t,o);if(t.miniSwe&&o.explicitPrompt===void 0)return po(e,t,o);if(t.kind!=="crew"&&!K(e))return rt(e,o,t.key,r);let s=so(e,o,i),c=en(e,t,o.files,o.listedPaths),l=rt(e,o,t.key,r||t.key===null&&(c.agents.length>0||s.agents.length>0));return{agents:[...l.agents,...c.agents,...s.agents],notes:[...l.notes.filter(u=>u.detail!=="no-conventions"||t.kind!=="crew"&&c.agents.length===0&&s.agents.length===0),...c.notes],registry:l.registry,...c.refused?.length||s.refused.length?{refused:[...c.refused??[],...s.refused]}:{}}}function en(e,t,o,r){let i=So(t,o,e,r),{agents:s,notes:c,registry:l}=i;return{agents:s.map(({entry:u,...b})=>({...b,prompt:Eo(e,{entry:u},c)})),notes:c,registry:l,...i.refused?.length?{refused:i.refused}:{}}}function rt(e,t,o,r=!1){let{files:i,skills:s,fallbackName:c}=t,l=X(t.root),u=G(e,Object.keys(i),l,t.listedPaths),b=[],p=typeof t.explicitPrompt=="string"&&!Pe(e,t.explicitPrompt);p&&b.push({code:"explicit-guide",path:t.explicitPrompt});let v=p?null:t.explicitPrompt,m=typeof v=="string"&&Object.hasOwn(i,v)&&R(e,{path:v},{purpose:"override",route:"github"}).admitted?v:null,f={...u,skillPaths:s?u.skillPaths:[]},y=Bt(f),h=tn(i,u.configPath,b),a=!q(e)&&!h?.prompt&&!h?.agents?.length?Dt(e,t):null,d=ct({codeAgentsFound:!q(e)&&!!t.codeAgentsFound,folderAgentsFound:r,otherDefinitions:y,agentConfiguration:a!==null},e);if(a&&d==="prompt"&&(u=a),!(v===null||m!==null||zt({...f,claudePath:u.claudePath},d)))return Fo(De(u),s,b),{agents:[],notes:[...b,{code:"no-prompt",path:l??"",detail:"no-conventions"}],registry:u.registry};let k=Eo(e,{files:i,c:u,guideRole:d,folderAgentsFound:r,root:l,config:h,explicitPath:v===null?null:m??void 0,pointerFiles:t.pointerFiles},b);k.kind==="none"&&(u=De(u));let P=s?u.skillPaths.map(w=>{let x=be(e,`${u.skillNames[w]}.md`,i[w]);return b.push(...(x.warnings??[]).map(C=>({code:"frontmatter",path:w,detail:C}))),{path:w,name:x.name,description:x.description??"",body:x.prompt??""}}):[];Fo(u,s,b);let n=s?[...u.subagentSkillPaths,...u.subagentSkillRefPaths]:[],g=u.subagentPaths.map(w=>{let x=be(e,Ao(w),i[w],{preserveToolAbsence:!0});return b.push(...(x.warnings??[]).map(C=>({code:"frontmatter",path:w,detail:C}))),{path:w,name:x.name,description:x.description??null,prompt:x.prompt??"",...x.tools!==void 0?{tools:x.tools}:{},...x.model!==void 0?{model:x.model}:{},skillPaths:n.filter(C=>u.subagentSkillOwners[C]===w)}});return{agents:[{key:o,name:h?.name??c,model:h?.model??null,description:h?.description??null,prompt:k,files:on(e,i,u,k,s),skills:P,subagents:g}],notes:b,registry:u.registry}}function ii(e,t,o,r){let i=G(e,Object.keys(o),X(r));return Object.hasOwn(i.subagentSkillOwners,t)?!0:ge(e,{skillPaths:i.subagentSkillPaths,paths:i.scoped,files:o,root:r})?.some(s=>s.files.some(c=>c.path===t))??!1}function tn(e,t,o){if(!t)return null;let r=Ve(e[t]);if(r.invalid)try{JSON.parse(e[t])}catch{o.push({code:"invalid-config",path:t})}return r.config}function Eo(e,t,o){if("entry"in t)return t.entry.text?{kind:"entry",...t.entry,text:t.entry.text}:(o.push({code:"no-prompt",path:t.entry.path}),{kind:"none"});let{files:r,c:i,guideRole:s,folderAgentsFound:c,root:l,config:u,explicitPath:b,pointerFiles:p}=t;if(b===null)return{kind:"none"};if(b!==void 0)return{kind:"explicit",path:b};let v=u?je(u)[0]?.prompt:void 0,m=u?go(e,u,l??"")[0]:void 0,f=v?Qe(e,v,{repoKey:"",markerDir:l??"",files:p??r}):null,y=m!==void 0&&Object.hasOwn(r,m),h=y&&!!r[m];if(y&&(h||p!==void 0)&&Object.hasOwn(i.subagentSkillOwners,m))o.push({code:"pointer-owned-by-subagent",path:m});else if(y&&(p===void 0?h:f?.kind==="resolved")){let a=f?.kind==="resolved"?f.prompt:null;return{kind:"pointer",path:m,...a&&a.kind!=="file"?{span:{...a.span},site:{kind:a.kind,start:a.start,symbol:a.symbol}}:{}}}else v&&o.push(p!==void 0&&f?.kind==="secret"?{code:"secret-file",path:f.path}:{code:"pointer-missed",...m?{path:m}:{},detail:v});return i.promptPath?{kind:"dedicated",path:i.promptPath}:i.registry&&i.soulPath?{kind:"registry",path:i.soulPath}:i.claudePath&&s==="prompt"?(o.push({code:"claude-fallback",...Te(e)?{path:i.claudePath}:{}}),{kind:"fallback",path:i.claudePath}):(o.push({code:"no-prompt",path:l??"",...c?{folderAgentsFound:!0}:{}}),{kind:"none"})}function Fo(e,t,o){if(t)for(let r of[...e.subagentSkillPaths,...e.subagentSkillRefPaths])e.subagentSkillOwners[r]||o.push({code:"orphan-skill",path:r})}function on(e,t,o,r,i){let s=[],c=(p,v,m=null)=>({role:p,label:m,path:v});if(r.kind!=="none"&&r.kind!=="registry"&&s.push(c("system prompt",r.path)),o.soulPath&&s.push(c("soul",o.soulPath)),o.knowledgePath&&s.push(c("knowledge",o.knowledgePath)),i)for(let p of o.skillPaths)s.push(c("skill",p,o.skillNames[p]));for(let p of o.templatePaths)s.push(c("template",p));if(i)for(let p of o.skillRefPaths)s.push(c("reference",p,o.skillRefNames[p]));let l=[];o.configPath&&l.push(c("config",o.configPath));for(let p of[o.toolsPath,o.toolsTsPath,o.cliPath])p&&l.push(c("tools",p));o.mcpPath&&l.push(c("mcp",o.mcpPath));let u=new Set([...s.map(p=>p.path),...l.map(p=>p.path),...o.subagentPaths,...Object.keys(o.subagentSkillOwners),...o.skillPaths,...o.skillRefPaths]),b=o.scoped.filter(p=>!u.has(p)&&te(p)).sort();return s.push(...se(b,s.map(p=>t[p.path]),o.stripRoot).map(p=>c("reference",p)),...l),s}export{se as a,yn as b,No as c,Xt as d,Ce as e,ge as f,Qt as g,qe as h,_o as i,qn as j,Un as k,Yn as l,Ht as m,eo as n,Bo as o,Ss as p,Ye as q,Cs as r,be as s,uo as t,Jo as u,Qs as v,Ve as w,sr as x,Xe as y,go as z,yo as A,rr as B,Xo as C,pr as D,bo as E,Po as F,vo as G,si as H,ri as I,ii as J};
@@ -0,0 +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};