@cyclonedx/cdxgen 12.3.0 → 12.3.2

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 (121) hide show
  1. package/README.md +15 -5
  2. package/bin/audit.js +7 -0
  3. package/bin/cdxgen.js +241 -81
  4. package/bin/repl.js +138 -0
  5. package/data/rules/ai-agent-governance.yaml +249 -0
  6. package/data/rules/dependency-sources.yaml +41 -0
  7. package/data/rules/mcp-servers.yaml +304 -0
  8. package/data/rules/package-integrity.yaml +123 -0
  9. package/lib/audit/index.js +353 -29
  10. package/lib/audit/index.poku.js +247 -7
  11. package/lib/audit/reporters.js +26 -0
  12. package/lib/audit/scoring.js +262 -13
  13. package/lib/audit/scoring.poku.js +179 -0
  14. package/lib/audit/targets.js +391 -2
  15. package/lib/audit/targets.poku.js +416 -3
  16. package/lib/cli/index.js +588 -45
  17. package/lib/cli/index.poku.js +735 -1
  18. package/lib/evinser/evinser.js +8 -5
  19. package/lib/helpers/agentFormulationParser.js +318 -0
  20. package/lib/helpers/aiInventory.js +262 -0
  21. package/lib/helpers/aiInventory.poku.js +111 -0
  22. package/lib/helpers/analyzer.js +1769 -0
  23. package/lib/helpers/analyzer.poku.js +284 -3
  24. package/lib/helpers/auditCategories.js +76 -0
  25. package/lib/helpers/ciParsers/githubActions.js +140 -16
  26. package/lib/helpers/ciParsers/githubActions.poku.js +110 -0
  27. package/lib/helpers/communityAiConfigParser.js +672 -0
  28. package/lib/helpers/communityAiConfigParser.poku.js +63 -0
  29. package/lib/helpers/depsUtils.js +108 -0
  30. package/lib/helpers/depsUtils.poku.js +72 -1
  31. package/lib/helpers/display.js +325 -3
  32. package/lib/helpers/display.poku.js +301 -0
  33. package/lib/helpers/formulationParsers.js +28 -0
  34. package/lib/helpers/formulationParsers.poku.js +504 -1
  35. package/lib/helpers/jsonLike.js +102 -0
  36. package/lib/helpers/jsonLike.poku.js +34 -0
  37. package/lib/helpers/mcp.js +248 -0
  38. package/lib/helpers/mcp.poku.js +101 -0
  39. package/lib/helpers/mcpConfigParser.js +656 -0
  40. package/lib/helpers/mcpConfigParser.poku.js +126 -0
  41. package/lib/helpers/mcpDiscovery.js +84 -0
  42. package/lib/helpers/mcpDiscovery.poku.js +21 -0
  43. package/lib/helpers/protobom.js +3 -3
  44. package/lib/helpers/provenanceUtils.js +29 -4
  45. package/lib/helpers/provenanceUtils.poku.js +29 -3
  46. package/lib/helpers/registryProvenance.js +210 -0
  47. package/lib/helpers/registryProvenance.poku.js +144 -0
  48. package/lib/helpers/rustFormulationParser.js +330 -0
  49. package/lib/helpers/source.js +21 -2
  50. package/lib/helpers/source.poku.js +38 -0
  51. package/lib/helpers/utils.js +1331 -83
  52. package/lib/helpers/utils.poku.js +599 -188
  53. package/lib/helpers/vsixutils.js +12 -4
  54. package/lib/helpers/vsixutils.poku.js +34 -0
  55. package/lib/managers/binary.js +36 -12
  56. package/lib/managers/binary.poku.js +68 -0
  57. package/lib/managers/docker.js +59 -9
  58. package/lib/managers/docker.poku.js +61 -0
  59. package/lib/managers/piptree.js +12 -7
  60. package/lib/managers/piptree.poku.js +44 -0
  61. package/lib/stages/postgen/annotator.js +2 -1
  62. package/lib/stages/postgen/annotator.poku.js +15 -0
  63. package/lib/stages/postgen/auditBom.js +20 -6
  64. package/lib/stages/postgen/auditBom.poku.js +694 -1
  65. package/lib/stages/postgen/postgen.js +262 -11
  66. package/lib/stages/postgen/postgen.poku.js +306 -2
  67. package/lib/stages/postgen/ruleEngine.js +49 -1
  68. package/lib/stages/postgen/spdxConverter.poku.js +70 -0
  69. package/lib/stages/pregen/pregen.js +6 -4
  70. package/package.json +1 -1
  71. package/types/bin/repl.d.ts.map +1 -1
  72. package/types/lib/audit/index.d.ts.map +1 -1
  73. package/types/lib/audit/reporters.d.ts.map +1 -1
  74. package/types/lib/audit/scoring.d.ts.map +1 -1
  75. package/types/lib/audit/targets.d.ts +12 -0
  76. package/types/lib/audit/targets.d.ts.map +1 -1
  77. package/types/lib/cli/index.d.ts +2 -8
  78. package/types/lib/cli/index.d.ts.map +1 -1
  79. package/types/lib/evinser/evinser.d.ts.map +1 -1
  80. package/types/lib/helpers/agentFormulationParser.d.ts +19 -0
  81. package/types/lib/helpers/agentFormulationParser.d.ts.map +1 -0
  82. package/types/lib/helpers/aiInventory.d.ts +23 -0
  83. package/types/lib/helpers/aiInventory.d.ts.map +1 -0
  84. package/types/lib/helpers/analyzer.d.ts +10 -0
  85. package/types/lib/helpers/analyzer.d.ts.map +1 -1
  86. package/types/lib/helpers/auditCategories.d.ts +12 -0
  87. package/types/lib/helpers/auditCategories.d.ts.map +1 -0
  88. package/types/lib/helpers/ciParsers/githubActions.d.ts.map +1 -1
  89. package/types/lib/helpers/communityAiConfigParser.d.ts +29 -0
  90. package/types/lib/helpers/communityAiConfigParser.d.ts.map +1 -0
  91. package/types/lib/helpers/depsUtils.d.ts +8 -0
  92. package/types/lib/helpers/depsUtils.d.ts.map +1 -1
  93. package/types/lib/helpers/display.d.ts +17 -1
  94. package/types/lib/helpers/display.d.ts.map +1 -1
  95. package/types/lib/helpers/formulationParsers.d.ts.map +1 -1
  96. package/types/lib/helpers/jsonLike.d.ts +4 -0
  97. package/types/lib/helpers/jsonLike.d.ts.map +1 -0
  98. package/types/lib/helpers/mcp.d.ts +29 -0
  99. package/types/lib/helpers/mcp.d.ts.map +1 -0
  100. package/types/lib/helpers/mcpConfigParser.d.ts +30 -0
  101. package/types/lib/helpers/mcpConfigParser.d.ts.map +1 -0
  102. package/types/lib/helpers/mcpDiscovery.d.ts +5 -0
  103. package/types/lib/helpers/mcpDiscovery.d.ts.map +1 -0
  104. package/types/lib/helpers/provenanceUtils.d.ts +5 -3
  105. package/types/lib/helpers/provenanceUtils.d.ts.map +1 -1
  106. package/types/lib/helpers/registryProvenance.d.ts +9 -0
  107. package/types/lib/helpers/registryProvenance.d.ts.map +1 -1
  108. package/types/lib/helpers/rustFormulationParser.d.ts +17 -0
  109. package/types/lib/helpers/rustFormulationParser.d.ts.map +1 -0
  110. package/types/lib/helpers/source.d.ts.map +1 -1
  111. package/types/lib/helpers/utils.d.ts +31 -1
  112. package/types/lib/helpers/utils.d.ts.map +1 -1
  113. package/types/lib/helpers/vsixutils.d.ts.map +1 -1
  114. package/types/lib/managers/binary.d.ts.map +1 -1
  115. package/types/lib/managers/docker.d.ts.map +1 -1
  116. package/types/lib/managers/piptree.d.ts.map +1 -1
  117. package/types/lib/stages/postgen/annotator.d.ts.map +1 -1
  118. package/types/lib/stages/postgen/auditBom.d.ts.map +1 -1
  119. package/types/lib/stages/postgen/postgen.d.ts.map +1 -1
  120. package/types/lib/stages/postgen/ruleEngine.d.ts.map +1 -1
  121. package/types/lib/stages/pregen/pregen.d.ts.map +1 -1
@@ -0,0 +1,672 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { basename, dirname, extname } from "node:path";
3
+
4
+ import { parse as loadYaml } from "yaml";
5
+
6
+ import { parseJsonLike } from "./jsonLike.js";
7
+ import {
8
+ credentialIndicatorsForText,
9
+ sanitizeMcpRefToken,
10
+ } from "./mcpDiscovery.js";
11
+ import { scanTextForHiddenUnicode } from "./unicodeScan.js";
12
+
13
+ const COMMUNITY_AI_PATTERNS = [
14
+ "opencode.json",
15
+ "**/opencode.json",
16
+ "opencode.jsonc",
17
+ "**/opencode.jsonc",
18
+ ".opencode/agents/*.md",
19
+ "**/.opencode/agents/*.md",
20
+ ".nanocoder/agents/*.md",
21
+ "**/.nanocoder/agents/*.md",
22
+ ".opencode/{tool,tools}/*.{js,ts,mjs,cjs}",
23
+ "**/.opencode/{tool,tools}/*.{js,ts,mjs,cjs}",
24
+ ".opencode/{skill,skills}/*/SKILL.md",
25
+ "**/.opencode/{skill,skills}/*/SKILL.md",
26
+ ".claude/skills/*/SKILL.md",
27
+ "**/.claude/skills/*/SKILL.md",
28
+ ".agents/skills/*/SKILL.md",
29
+ "**/.agents/skills/*/SKILL.md",
30
+ ".nanocoder/commands/**/*.md",
31
+ "**/.nanocoder/commands/**/*.md",
32
+ ".nanocoder/skills/**/*.md",
33
+ "**/.nanocoder/skills/**/*.md",
34
+ "langgraph.json",
35
+ "**/langgraph.json",
36
+ "agents.py",
37
+ "**/agents.py",
38
+ "tasks.py",
39
+ "**/tasks.py",
40
+ "config/agents.yaml",
41
+ "**/config/agents.yaml",
42
+ "config/tasks.yaml",
43
+ "**/config/tasks.yaml",
44
+ "config/tools.yaml",
45
+ "**/config/tools.yaml",
46
+ ];
47
+
48
+ function addUniqueProperty(properties, name, value) {
49
+ if (value === undefined || value === null || value === "") {
50
+ return;
51
+ }
52
+ if (properties.some((prop) => prop.name === name && prop.value === value)) {
53
+ return;
54
+ }
55
+ properties.push({ name, value: String(value) });
56
+ }
57
+
58
+ function normalizeFilePath(filePath) {
59
+ return filePath.replaceAll("\\", "/");
60
+ }
61
+
62
+ function syntaxForFile(filePath) {
63
+ const extension = extname(filePath).toLowerCase();
64
+ if ([".json", ".jsonc"].includes(extension)) {
65
+ return "json";
66
+ }
67
+ if ([".yaml", ".yml"].includes(extension)) {
68
+ return "yaml";
69
+ }
70
+ if ([".md", ".markdown"].includes(extension)) {
71
+ return "markdown";
72
+ }
73
+ return "text";
74
+ }
75
+
76
+ function parseFrontmatter(raw) {
77
+ const match = raw.match(/^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/u);
78
+ if (!match) {
79
+ return { body: raw.trim(), metadata: {} };
80
+ }
81
+ let metadata = {};
82
+ try {
83
+ metadata = loadYaml(match[1]) || {};
84
+ } catch {
85
+ metadata = {};
86
+ }
87
+ return { body: match[2].trim(), metadata };
88
+ }
89
+
90
+ function frameworkForFile(filePath, raw = "") {
91
+ const lowerPath = normalizeFilePath(filePath).toLowerCase();
92
+ if (
93
+ lowerPath.includes("/.opencode/") ||
94
+ lowerPath.endsWith("opencode.json") ||
95
+ lowerPath.endsWith("opencode.jsonc")
96
+ ) {
97
+ return "opencode";
98
+ }
99
+ if (lowerPath.includes("/.nanocoder/") || lowerPath.endsWith(".mcp.json")) {
100
+ return "nanocoder";
101
+ }
102
+ if (lowerPath.endsWith("langgraph.json")) {
103
+ return "langgraph";
104
+ }
105
+ if (
106
+ lowerPath.endsWith("agents.py") ||
107
+ lowerPath.endsWith("tasks.py") ||
108
+ lowerPath.includes("/config/agents.yaml") ||
109
+ lowerPath.includes("/config/tasks.yaml") ||
110
+ lowerPath.includes("/config/tools.yaml") ||
111
+ /\bcrewai\b/u.test(raw)
112
+ ) {
113
+ return "crewai";
114
+ }
115
+ if (lowerPath.includes("/.claude/skills/")) {
116
+ return "claude-compatible";
117
+ }
118
+ if (lowerPath.includes("/.agents/skills/")) {
119
+ return "agent-compatible";
120
+ }
121
+ return "community-ai";
122
+ }
123
+
124
+ function baseProperties(filePath, framework, kind) {
125
+ return [
126
+ { name: "SrcFile", value: filePath },
127
+ { name: "cdx:file:kind", value: kind },
128
+ { name: "cdx:agent:inventorySource", value: "community-config" },
129
+ { name: "cdx:agent:framework", value: framework },
130
+ ];
131
+ }
132
+
133
+ function createComponent(
134
+ filePath,
135
+ framework,
136
+ kind,
137
+ name,
138
+ type = "application",
139
+ ) {
140
+ return {
141
+ "bom-ref": `urn:component:${framework}:${kind}:${sanitizeMcpRefToken(name)}:${sanitizeMcpRefToken(basename(filePath))}`,
142
+ name,
143
+ properties: baseProperties(filePath, framework, kind),
144
+ type,
145
+ version: type === "file" ? undefined : "configured",
146
+ };
147
+ }
148
+
149
+ function createService(filePath, framework, kind, name, properties = []) {
150
+ return {
151
+ "bom-ref": `urn:service:${framework}:${kind}:${sanitizeMcpRefToken(name)}`,
152
+ group: framework,
153
+ name,
154
+ properties: baseProperties(filePath, framework, kind).concat(properties),
155
+ version: "configured",
156
+ };
157
+ }
158
+
159
+ function maybeAddFileSignals(properties, filePath, raw) {
160
+ const hiddenUnicodeScan = scanTextForHiddenUnicode(raw, {
161
+ syntax: syntaxForFile(filePath),
162
+ });
163
+ if (hiddenUnicodeScan.hasHiddenUnicode) {
164
+ addUniqueProperty(properties, "cdx:file:hasHiddenUnicode", "true");
165
+ addUniqueProperty(
166
+ properties,
167
+ "cdx:file:hiddenUnicodeCodePoints",
168
+ hiddenUnicodeScan.codePoints.join(","),
169
+ );
170
+ addUniqueProperty(
171
+ properties,
172
+ "cdx:file:hiddenUnicodeLineNumbers",
173
+ hiddenUnicodeScan.lineNumbers.join(","),
174
+ );
175
+ }
176
+ const credentialIndicators = credentialIndicatorsForText(raw);
177
+ if (credentialIndicators.length) {
178
+ addUniqueProperty(properties, "cdx:agent:credentialExposure", "true");
179
+ addUniqueProperty(
180
+ properties,
181
+ "cdx:agent:credentialRiskIndicators",
182
+ credentialIndicators.join(","),
183
+ );
184
+ }
185
+ }
186
+
187
+ function parseSkillFile(filePath, raw) {
188
+ const framework = frameworkForFile(filePath, raw);
189
+ const { metadata } = parseFrontmatter(raw);
190
+ if (!metadata?.name && !metadata?.description) {
191
+ return [];
192
+ }
193
+ const component = createComponent(
194
+ filePath,
195
+ framework,
196
+ "skill-file",
197
+ metadata?.name || basename(dirname(filePath)),
198
+ "file",
199
+ );
200
+ addUniqueProperty(component.properties, "cdx:skill:name", metadata?.name);
201
+ addUniqueProperty(
202
+ component.properties,
203
+ "cdx:skill:description",
204
+ metadata?.description,
205
+ );
206
+ addUniqueProperty(
207
+ component.properties,
208
+ "cdx:skill:license",
209
+ metadata?.license,
210
+ );
211
+ addUniqueProperty(
212
+ component.properties,
213
+ "cdx:skill:compatibility",
214
+ metadata?.compatibility,
215
+ );
216
+ if (metadata?.metadata && typeof metadata.metadata === "object") {
217
+ addUniqueProperty(
218
+ component.properties,
219
+ "cdx:skill:metadata",
220
+ JSON.stringify(metadata.metadata),
221
+ );
222
+ }
223
+ maybeAddFileSignals(component.properties, filePath, raw);
224
+ return [component];
225
+ }
226
+
227
+ function parseAgentMarkdown(filePath, raw) {
228
+ const framework = frameworkForFile(filePath, raw);
229
+ const { metadata } = parseFrontmatter(raw);
230
+ if (!metadata?.description && !metadata?.name) {
231
+ return [];
232
+ }
233
+ const component = createComponent(
234
+ filePath,
235
+ framework,
236
+ "agent-definition",
237
+ metadata?.name || basename(filePath, extname(filePath)),
238
+ );
239
+ addUniqueProperty(
240
+ component.properties,
241
+ "cdx:agent:description",
242
+ metadata?.description,
243
+ );
244
+ addUniqueProperty(component.properties, "cdx:agent:mode", metadata?.mode);
245
+ addUniqueProperty(component.properties, "cdx:agent:model", metadata?.model);
246
+ addUniqueProperty(
247
+ component.properties,
248
+ "cdx:agent:providerOverride",
249
+ metadata?.provider,
250
+ );
251
+ if (Array.isArray(metadata?.tools)) {
252
+ addUniqueProperty(
253
+ component.properties,
254
+ "cdx:agent:tools",
255
+ metadata.tools.join(","),
256
+ );
257
+ }
258
+ if (Array.isArray(metadata?.disallowedTools)) {
259
+ addUniqueProperty(
260
+ component.properties,
261
+ "cdx:agent:disallowedTools",
262
+ metadata.disallowedTools.join(","),
263
+ );
264
+ }
265
+ maybeAddFileSignals(component.properties, filePath, raw);
266
+ return [component];
267
+ }
268
+
269
+ function parseNanocoderCommand(filePath, raw) {
270
+ const { metadata } = parseFrontmatter(raw);
271
+ const component = createComponent(
272
+ filePath,
273
+ "nanocoder",
274
+ "custom-command",
275
+ basename(filePath, extname(filePath)),
276
+ );
277
+ addUniqueProperty(
278
+ component.properties,
279
+ "cdx:tool:description",
280
+ metadata?.description,
281
+ );
282
+ addUniqueProperty(
283
+ component.properties,
284
+ "cdx:tool:category",
285
+ metadata?.category,
286
+ );
287
+ addUniqueProperty(component.properties, "cdx:tool:author", metadata?.author);
288
+ addUniqueProperty(
289
+ component.properties,
290
+ "cdx:tool:version",
291
+ metadata?.version,
292
+ );
293
+ if (Array.isArray(metadata?.aliases)) {
294
+ addUniqueProperty(
295
+ component.properties,
296
+ "cdx:tool:aliases",
297
+ metadata.aliases.join(","),
298
+ );
299
+ }
300
+ if (Array.isArray(metadata?.tags)) {
301
+ addUniqueProperty(
302
+ component.properties,
303
+ "cdx:tool:tags",
304
+ metadata.tags.join(","),
305
+ );
306
+ }
307
+ if (Array.isArray(metadata?.triggers)) {
308
+ addUniqueProperty(
309
+ component.properties,
310
+ "cdx:tool:triggers",
311
+ metadata.triggers.join(","),
312
+ );
313
+ }
314
+ maybeAddFileSignals(component.properties, filePath, raw);
315
+ return [component];
316
+ }
317
+
318
+ function parseOpencodeTools(filePath, raw) {
319
+ if (!/\btool\s*\(/u.test(raw)) {
320
+ return [];
321
+ }
322
+ const components = [];
323
+ const baseName = basename(filePath, extname(filePath));
324
+ const exportMatches = [
325
+ ...raw.matchAll(/export\s+const\s+([A-Za-z0-9_]+)\s*=\s*tool\s*\(/gu),
326
+ ];
327
+ if (!exportMatches.length && /export\s+default\s+tool\s*\(/u.test(raw)) {
328
+ const component = createComponent(
329
+ filePath,
330
+ "opencode",
331
+ "custom-tool",
332
+ baseName,
333
+ );
334
+ const descriptionMatch = raw.match(/description:\s*["'`](.+?)["'`]/u);
335
+ addUniqueProperty(
336
+ component.properties,
337
+ "cdx:tool:description",
338
+ descriptionMatch?.[1],
339
+ );
340
+ maybeAddFileSignals(component.properties, filePath, raw);
341
+ components.push(component);
342
+ return components;
343
+ }
344
+ for (const [index, match] of exportMatches.entries()) {
345
+ const nextIndex =
346
+ index < exportMatches.length - 1
347
+ ? exportMatches[index + 1].index
348
+ : raw.length;
349
+ const block = raw.slice(match.index, nextIndex);
350
+ const component = createComponent(
351
+ filePath,
352
+ "opencode",
353
+ "custom-tool",
354
+ `${baseName}_${match[1]}`,
355
+ );
356
+ const descriptionMatch = block.match(/description:\s*["'`](.+?)["'`]/u);
357
+ addUniqueProperty(
358
+ component.properties,
359
+ "cdx:tool:description",
360
+ descriptionMatch?.[1],
361
+ );
362
+ maybeAddFileSignals(component.properties, filePath, block);
363
+ components.push(component);
364
+ }
365
+ return components;
366
+ }
367
+
368
+ function parseOpencodeConfig(filePath, raw) {
369
+ let config;
370
+ try {
371
+ config = parseJsonLike(raw);
372
+ } catch {
373
+ return [];
374
+ }
375
+ const components = [];
376
+ for (const [agentName, agentConfig] of Object.entries(config?.agent || {})) {
377
+ const component = createComponent(
378
+ filePath,
379
+ "opencode",
380
+ "agent-config",
381
+ agentName,
382
+ );
383
+ addUniqueProperty(
384
+ component.properties,
385
+ "cdx:agent:description",
386
+ agentConfig?.description,
387
+ );
388
+ addUniqueProperty(
389
+ component.properties,
390
+ "cdx:agent:mode",
391
+ agentConfig?.mode,
392
+ );
393
+ addUniqueProperty(
394
+ component.properties,
395
+ "cdx:agent:model",
396
+ agentConfig?.model,
397
+ );
398
+ if (agentConfig?.permission) {
399
+ addUniqueProperty(
400
+ component.properties,
401
+ "cdx:agent:permission",
402
+ JSON.stringify(agentConfig.permission),
403
+ );
404
+ }
405
+ components.push(component);
406
+ }
407
+ return components;
408
+ }
409
+
410
+ function parseLanggraphConfig(filePath, raw) {
411
+ let config;
412
+ try {
413
+ config = parseJsonLike(raw);
414
+ } catch {
415
+ return { components: [], services: [] };
416
+ }
417
+ const components = [];
418
+ const services = [];
419
+ for (const [graphName, graphRef] of Object.entries(config?.graphs || {})) {
420
+ const component = createComponent(
421
+ filePath,
422
+ "langgraph",
423
+ "graph-definition",
424
+ graphName,
425
+ );
426
+ addUniqueProperty(
427
+ component.properties,
428
+ "cdx:agent:role",
429
+ "langgraph-graph",
430
+ );
431
+ addUniqueProperty(
432
+ component.properties,
433
+ "cdx:langgraph:graphEntryPoint",
434
+ graphRef,
435
+ );
436
+ addUniqueProperty(
437
+ component.properties,
438
+ "cdx:langgraph:envFile",
439
+ config?.env,
440
+ );
441
+ if (Array.isArray(config?.dependencies)) {
442
+ addUniqueProperty(
443
+ component.properties,
444
+ "cdx:langgraph:dependencies",
445
+ config.dependencies.join(","),
446
+ );
447
+ }
448
+ maybeAddFileSignals(component.properties, filePath, raw);
449
+ components.push(component);
450
+ services.push(
451
+ createService(filePath, "langgraph", "graph-service", graphName, [
452
+ { name: "cdx:agent:inventorySource", value: "community-config" },
453
+ { name: "cdx:agent:framework", value: "langgraph" },
454
+ { name: "cdx:agent:role", value: "langgraph-graph" },
455
+ { name: "cdx:langgraph:graphEntryPoint", value: String(graphRef) },
456
+ ]),
457
+ );
458
+ }
459
+ return { components, services };
460
+ }
461
+
462
+ function parseCrewAiYaml(filePath, raw) {
463
+ let config;
464
+ try {
465
+ config = loadYaml(raw);
466
+ } catch {
467
+ return [];
468
+ }
469
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
470
+ return [];
471
+ }
472
+ const kind = filePath.toLowerCase().includes("tasks.yaml")
473
+ ? "crew-task"
474
+ : filePath.toLowerCase().includes("tools.yaml")
475
+ ? "crew-tool"
476
+ : "crew-agent";
477
+ const components = [];
478
+ for (const [entryName, entryConfig] of Object.entries(config)) {
479
+ if (!entryConfig || typeof entryConfig !== "object") {
480
+ continue;
481
+ }
482
+ const component = createComponent(filePath, "crewai", kind, entryName);
483
+ addUniqueProperty(component.properties, "cdx:agent:role", kind);
484
+ addUniqueProperty(
485
+ component.properties,
486
+ "cdx:crewai:role",
487
+ entryConfig?.role,
488
+ );
489
+ addUniqueProperty(
490
+ component.properties,
491
+ "cdx:crewai:goal",
492
+ entryConfig?.goal,
493
+ );
494
+ addUniqueProperty(
495
+ component.properties,
496
+ "cdx:crewai:backstory",
497
+ entryConfig?.backstory,
498
+ );
499
+ addUniqueProperty(
500
+ component.properties,
501
+ "cdx:crewai:expectedOutput",
502
+ entryConfig?.expected_output,
503
+ );
504
+ if (Array.isArray(entryConfig?.tools)) {
505
+ addUniqueProperty(
506
+ component.properties,
507
+ "cdx:crewai:tools",
508
+ entryConfig.tools.join(","),
509
+ );
510
+ }
511
+ if (entryConfig?.agent) {
512
+ addUniqueProperty(
513
+ component.properties,
514
+ "cdx:crewai:assignedAgent",
515
+ entryConfig.agent,
516
+ );
517
+ }
518
+ maybeAddFileSignals(component.properties, filePath, raw);
519
+ components.push(component);
520
+ }
521
+ return components;
522
+ }
523
+
524
+ function captureQuotedValue(block, key) {
525
+ const patterns = [
526
+ new RegExp(`${key}\\s*=\\s*["'\`]([^"'\`]+)["'\`]`, "u"),
527
+ new RegExp(`${key}\\s*=\\s*dedent\\([^\\n]*?["'\`]([\\s\\S]*?)["'\`]`, "u"),
528
+ ];
529
+ for (const pattern of patterns) {
530
+ const match = block.match(pattern);
531
+ if (match?.[1]) {
532
+ return match[1].replace(/\s+/gu, " ").trim();
533
+ }
534
+ }
535
+ return undefined;
536
+ }
537
+
538
+ function parseCrewAiPython(filePath, raw) {
539
+ if (!/\bfrom\s+crewai\s+import\s+(Agent|Task)\b/u.test(raw)) {
540
+ return [];
541
+ }
542
+ const isTaskFile = /\bfrom\s+crewai\s+import\s+Task\b/u.test(raw);
543
+ const constructorName = isTaskFile ? "Task" : "Agent";
544
+ const matches = [
545
+ ...raw.matchAll(
546
+ new RegExp(
547
+ `def\\s+([A-Za-z0-9_]+)\\s*\\([^)]*\\):[\\s\\S]*?return\\s+${constructorName}\\(([\\s\\S]*?)\\n\\s*\\)`,
548
+ "gu",
549
+ ),
550
+ ),
551
+ ];
552
+ const components = [];
553
+ for (const match of matches) {
554
+ const component = createComponent(
555
+ filePath,
556
+ "crewai",
557
+ isTaskFile ? "crew-task" : "crew-agent",
558
+ match[1],
559
+ );
560
+ addUniqueProperty(
561
+ component.properties,
562
+ "cdx:agent:role",
563
+ isTaskFile ? "crew-task" : "crew-agent",
564
+ );
565
+ addUniqueProperty(
566
+ component.properties,
567
+ "cdx:crewai:role",
568
+ captureQuotedValue(match[2], "role"),
569
+ );
570
+ addUniqueProperty(
571
+ component.properties,
572
+ "cdx:crewai:goal",
573
+ captureQuotedValue(match[2], "goal"),
574
+ );
575
+ addUniqueProperty(
576
+ component.properties,
577
+ "cdx:crewai:backstory",
578
+ captureQuotedValue(match[2], "backstory"),
579
+ );
580
+ addUniqueProperty(
581
+ component.properties,
582
+ "cdx:crewai:description",
583
+ captureQuotedValue(match[2], "description"),
584
+ );
585
+ addUniqueProperty(
586
+ component.properties,
587
+ "cdx:crewai:expectedOutput",
588
+ captureQuotedValue(match[2], "expected_output"),
589
+ );
590
+ const toolsMatch = match[2].match(/tools\s*=\s*\[([^\]]+)\]/u);
591
+ if (toolsMatch?.[1]) {
592
+ addUniqueProperty(
593
+ component.properties,
594
+ "cdx:crewai:tools",
595
+ toolsMatch[1].replace(/\s+/gu, ""),
596
+ );
597
+ }
598
+ maybeAddFileSignals(component.properties, filePath, match[2]);
599
+ components.push(component);
600
+ }
601
+ return components;
602
+ }
603
+
604
+ export const communityAiConfigParser = {
605
+ id: "community-ai-config",
606
+ patterns: COMMUNITY_AI_PATTERNS,
607
+ parse(files, _options = {}) {
608
+ const components = [];
609
+ const services = [];
610
+ for (const filePath of [...new Set(files || [])]) {
611
+ let raw;
612
+ try {
613
+ raw = readFileSync(filePath, "utf-8");
614
+ } catch {
615
+ continue;
616
+ }
617
+ const lowerPath = normalizeFilePath(filePath).toLowerCase();
618
+ if (
619
+ lowerPath.endsWith("opencode.json") ||
620
+ lowerPath.endsWith("opencode.jsonc")
621
+ ) {
622
+ components.push(...parseOpencodeConfig(filePath, raw));
623
+ continue;
624
+ }
625
+ if (lowerPath.endsWith("langgraph.json")) {
626
+ const parsed = parseLanggraphConfig(filePath, raw);
627
+ components.push(...parsed.components);
628
+ services.push(...parsed.services);
629
+ continue;
630
+ }
631
+ if (
632
+ lowerPath.includes("/.opencode/agents/") ||
633
+ lowerPath.includes("/.nanocoder/agents/")
634
+ ) {
635
+ components.push(...parseAgentMarkdown(filePath, raw));
636
+ continue;
637
+ }
638
+ if (
639
+ lowerPath.includes("/.opencode/skills/") ||
640
+ lowerPath.includes("/.claude/skills/") ||
641
+ lowerPath.includes("/.agents/skills/") ||
642
+ lowerPath.includes("/.nanocoder/skills/")
643
+ ) {
644
+ components.push(...parseSkillFile(filePath, raw));
645
+ continue;
646
+ }
647
+ if (
648
+ lowerPath.includes("/.opencode/tools/") ||
649
+ lowerPath.includes("/.opencode/tool/")
650
+ ) {
651
+ components.push(...parseOpencodeTools(filePath, raw));
652
+ continue;
653
+ }
654
+ if (lowerPath.includes("/.nanocoder/commands/")) {
655
+ components.push(...parseNanocoderCommand(filePath, raw));
656
+ continue;
657
+ }
658
+ if (lowerPath.endsWith("agents.py") || lowerPath.endsWith("tasks.py")) {
659
+ components.push(...parseCrewAiPython(filePath, raw));
660
+ continue;
661
+ }
662
+ if (
663
+ lowerPath.includes("/config/agents.yaml") ||
664
+ lowerPath.includes("/config/tasks.yaml") ||
665
+ lowerPath.includes("/config/tools.yaml")
666
+ ) {
667
+ components.push(...parseCrewAiYaml(filePath, raw));
668
+ }
669
+ }
670
+ return { components, services };
671
+ },
672
+ };